Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static-link Legion into compiled Regent programs #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bindings/terra/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.a
*.so
*.dylib
link_flags.txt
4 changes: 4 additions & 0 deletions bindings/terra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ endif
CC_FLAGS += -DREALM_ALLOW_MISSING_LLVM_LIBS
$(OUTFILE) : LLVM_LIBS=

# Also static-link all application objects
OUTLIB = liblegion_terra_bindings.a
OUTLINK_FLAGS = link_flags.txt

###########################################################################
#
# Don't change anything below here
Expand Down
15 changes: 14 additions & 1 deletion language/src/regent/std.t
Original file line number Diff line number Diff line change
Expand Up @@ -3455,6 +3455,8 @@ end
function std.start(main_task, extra_setup_thunk)
if std.config["pretty"] then os.exit() end

terralib.linklibrary("liblegion_terra.so")

assert(std.is_task(main_task))
local main = std.setup(main_task, extra_setup_thunk)

Expand All @@ -3476,14 +3478,25 @@ function std.start(main_task, extra_setup_thunk)
wrapper()
end

local function split(str, sep)
local fields = terralib.newlist()
local pattern = string.format("([^%s]+)", sep)
str:gsub(pattern, function(c) fields:insert(c) end)
return fields
end

function std.saveobj(main_task, filename, filetype, extra_setup_thunk, link_flags)
assert(std.is_task(main_task))
local main, names = std.setup(main_task, extra_setup_thunk)
local lib_dir = os.getenv("LG_RT_DIR") .. "/../bindings/terra"

local flags = terralib.newlist()
if link_flags then flags:insertall(link_flags) end
flags:insertall({"-L" .. lib_dir, "-llegion_terra"})
flags:insertall({"-L" .. lib_dir, "-llegion_terra_bindings"})
local legion_flags_cache = io.open(lib_dir .. "/link_flags.txt", "r")
flags:insertall(split(legion_flags_cache:read(), ' '))
legion_flags_cache:close()
flags:insert('-lstdc++')
if filetype ~= nil then
terralib.saveobj(filename, filetype, names, flags)
else
Expand Down
1 change: 0 additions & 1 deletion language/src/regent/std_base.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ base.config, base.args = config.args()
-- ## Legion Bindings
-- #################

terralib.linklibrary("liblegion_terra.so")
local c = terralib.includecstring([[
#include "legion_c.h"
#include "legion_terra.h"
Expand Down
17 changes: 15 additions & 2 deletions runtime/runtime.mk
Original file line number Diff line number Diff line change
Expand Up @@ -581,24 +581,37 @@ endif

# Provide build rules unless the user asks us not to
ifndef NO_BUILD_RULES

# Provide an all unless the user asks us not to
ifndef NO_BUILD_ALL
.PHONY: all
ifdef OUTLIB
all: $(OUTFILE) $(OUTLIB)
else
all: $(OUTFILE)
endif
endif

# If we're using CUDA we have to link with nvcc
$(OUTFILE) : $(GEN_OBJS) $(GEN_GPU_OBJS) $(SLIB_LEGION) $(SLIB_REALM)
@echo "---> Linking objects into one binary: $(OUTFILE)"
$(CXX) -o $(OUTFILE) $(GEN_OBJS) $(GEN_GPU_OBJS) $(LD_FLAGS) $(LEGION_LIBS) $(LEGION_LD_FLAGS) $(GASNET_FLAGS)

ifdef OUTLIB
$(OUTLIB) : $(GEN_OBJS) $(GEN_GPU_OBJS)
@echo "---> Linking application objects into a static archive: $(OUTLIB)"
@echo "---> Required link flags stored in $(OUTLINK_FLAGS)"
$(AR) rcs $(OUTLIB) $(GEN_OBJS) $(GEN_GPU_OBJS)
@echo "-llegion -lrealm $(LEGION_LD_FLAGS) $(GASNET_FLAGS)" > $(OUTLINK_FLAGS)
endif

$(SLIB_LEGION) : $(LEGION_OBJS) $(MAPPER_OBJS)
rm -f $@
$(AR) rc $@ $^
$(AR) rcs $@ $^

$(SLIB_REALM) : $(REALM_OBJS)
rm -f $@
$(AR) rc $@ $^
$(AR) rcs $@ $^

$(GEN_OBJS) : %.cc.o : %.cc
$(CXX) -o $@ -c $< $(CC_FLAGS) $(INC_FLAGS)
Expand Down