From cf60736d0dad56d0ff64e41549ba53fbf9e51d98 Mon Sep 17 00:00:00 2001 From: Dean Prichard Date: Thu, 20 Oct 2016 09:51:02 -0600 Subject: [PATCH 1/4] realm: add configfile support --- CMakeLists.txt | 11 ++ cmake/FindLuaJIT.cmake | 70 +++++++++++++ runtime/CMakeLists.txt | 9 ++ runtime/realm/cuda/cuda_module.cc | 4 +- runtime/realm/hdf5/hdf5_module.cc | 4 +- runtime/realm/logging.cc | 4 +- runtime/realm/numa/numa_module.cc | 5 +- runtime/realm/options.cc | 129 ++++++++++++++++++++++++ runtime/realm/options.h | 78 ++++++++++++++ runtime/realm/options.inl | 69 +++++++++++++ runtime/realm/procset/procset_module.cc | 5 +- runtime/realm/runtime_impl.cc | 6 +- runtime/realm/sampling_impl.cc | 4 +- runtime/runtime.mk | 14 ++- 14 files changed, 395 insertions(+), 17 deletions(-) create mode 100644 cmake/FindLuaJIT.cmake create mode 100644 runtime/realm/options.cc create mode 100644 runtime/realm/options.h create mode 100644 runtime/realm/options.inl diff --git a/CMakeLists.txt b/CMakeLists.txt index 54cd1ae966..4e5f8f943f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,17 @@ if(Legion_USE_HWLOC) ) endif() +#------------------------------------------------------------------------------# +# LuaJIT configuration +#------------------------------------------------------------------------------# +option(Legion_USE_LuaJIT "Use LuaJIT for config file" OFF) +if(Legion_USE_LuaJIT) + find_package(LuaJIT REQUIRED) + install(FILES ${Legion_SOURCE_DIR}/cmake/FindLuaJIT.cmake + DESTINATION lib/cmake/Legion + ) +endif() + #------------------------------------------------------------------------------# # GASNet configuration #------------------------------------------------------------------------------# diff --git a/cmake/FindLuaJIT.cmake b/cmake/FindLuaJIT.cmake new file mode 100644 index 0000000000..4ce8488802 --- /dev/null +++ b/cmake/FindLuaJIT.cmake @@ -0,0 +1,70 @@ +#------------------------------------------------------------------------------# +# Copyright 2016 Kitware, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------# + +find_path(LUA_INCLUDE_DIR luajit.h + HINTS + ENV LUAJIT + PATH_SUFFIXES include/luajit-2.0 include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +find_library(LUA_LIBRARY + NAMES luajit-5.1 + HINTS + ENV LUAJIT + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw + /opt/local + /opt/csw + /opt +) + +if(LUA_LIBRARY) + # include the math library for Unix + if(UNIX AND NOT APPLE) + find_library(LUA_MATH_LIBRARY m) + set( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries") + # For Windows and Mac, don't need to explicitly include the math library + else() + set( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries") + endif() +endif() + +if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/luajit.h") + file(STRINGS "${LUA_INCLUDE_DIR}/luajit.h" luajit_version_str REGEX "^#define[ \t]+LUAJIT_VERSION[ \t]+\"LuaJIT .+\"") + + string(REGEX REPLACE "^#define[ \t]+LUAJIT_VERSION[ \t]+\"LuaJIT ([^\"]+)\".*" "\\1" LUAJIT_VERSION_STRING "${luajit_version_str}") + unset(luajit_version_str) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaJIT + REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR + VERSION_VAR LUAJIT_VERSION_STRING) + +mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY) + diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 12e909fb1c..775619efb2 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -76,6 +76,9 @@ else() if(Legion_USE_GASNet) list(APPEND LOW_RUNTIME_SRC activemsg.h activemsg.cc) endif() + if(Legion_USE_LuaJIT) + list(APPEND LOW_RUNTIME_SRC realm/options.h realm/options.cc) + endif() endif() list(APPEND LOW_RUNTIME_SRC accessor.h @@ -162,6 +165,12 @@ if(Legion_USE_CUDA) target_link_libraries(LowLevelRuntime PRIVATE ${CUDA_CUDA_LIBRARY}) endif() +if(Legion_USE_LuaJIT) + target_compile_definitions(LowLevelRuntime PUBLIC REALM_USE_LUAJIT) + target_include_directories(LowLevelRuntime PRIVATE ${LUA_INCLUDE_DIR}) + target_link_libraries(LowLevelRuntime PRIVATE ${LUA_LIBRARIES}) +endif() + if(Legion_USE_SHARED_LOWLEVEL) set_target_properties(LowLevelRuntime PROPERTIES OUTPUT_NAME sharedllr) else() diff --git a/runtime/realm/cuda/cuda_module.cc b/runtime/realm/cuda/cuda_module.cc index 48eb303e26..0fbc39f818 100644 --- a/runtime/realm/cuda/cuda_module.cc +++ b/runtime/realm/cuda/cuda_module.cc @@ -17,7 +17,7 @@ #include "realm/tasks.h" #include "realm/logging.h" -#include "realm/cmdline.h" +#include "realm/options.h" #include "lowlevel_dma.h" @@ -2172,7 +2172,7 @@ namespace Realm { // first order of business - read command line parameters { - CommandLineParser cp; + OptionParser cp(cmdline); cp.add_option_int("-ll:fsize", m->cfg_fb_mem_size_in_mb) .add_option_int("-ll:zsize", m->cfg_zc_mem_size_in_mb) diff --git a/runtime/realm/hdf5/hdf5_module.cc b/runtime/realm/hdf5/hdf5_module.cc index b3b89f1a98..6dc7ecc835 100644 --- a/runtime/realm/hdf5/hdf5_module.cc +++ b/runtime/realm/hdf5/hdf5_module.cc @@ -18,7 +18,7 @@ #include "hdf5_internal.h" #include "logging.h" -#include "cmdline.h" +#include "options.h" #include "threads.h" #include "runtime_impl.h" #include "utils.h" @@ -60,7 +60,7 @@ namespace Realm { // first order of business - read command line parameters { - CommandLineParser cp; + OptionParser cp(cmdline); cp.add_option_bool("-hdf5:showerrors", m->cfg_showerrors); diff --git a/runtime/realm/logging.cc b/runtime/realm/logging.cc index 030a754de5..85bd521811 100644 --- a/runtime/realm/logging.cc +++ b/runtime/realm/logging.cc @@ -24,7 +24,7 @@ #include "activemsg.h" #endif -#include "cmdline.h" +#include "options.h" #include #include @@ -294,7 +294,7 @@ namespace Realm { { std::string logname; - bool ok = CommandLineParser() + bool ok = OptionParser(cmdline) .add_option_string("-cat", cats_enabled) .add_option_string("-logfile", logname) .add_option_method("-level", this, &LoggerConfig::parse_level_argument) diff --git a/runtime/realm/numa/numa_module.cc b/runtime/realm/numa/numa_module.cc index a746e2f09b..7cbed61e9a 100644 --- a/runtime/realm/numa/numa_module.cc +++ b/runtime/realm/numa/numa_module.cc @@ -17,7 +17,7 @@ #include "numasysif.h" #include "logging.h" -#include "cmdline.h" +#include "options.h" #include "proc_impl.h" #include "threads.h" #include "runtime_impl.h" @@ -105,8 +105,7 @@ namespace Realm { // first order of business - read command line parameters { - CommandLineParser cp; - + OptionParser cp(cmdline); cp.add_option_int("-ll:nsize", m->cfg_numa_mem_size_in_mb) .add_option_int("-ll:ncpu", m->cfg_num_numa_cpus) .add_option_bool("-numa:pin", m->cfg_pin_memory); diff --git a/runtime/realm/options.cc b/runtime/realm/options.cc new file mode 100644 index 0000000000..4aab065fe5 --- /dev/null +++ b/runtime/realm/options.cc @@ -0,0 +1,129 @@ +/* Copyright 2016 Stanford University, NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "options.h" +#include "logging.h" + +namespace Realm { + + Logger log_config("config"); + + + // convert command line options to lua variable names + // -level -> opt_level + // -ll:cpu -> opt_ll_cpu + // etc + std::string luaName(const std::string& optname) + { + std::string name = optname; + + // replace : w/ _ + size_t cidx = name.find(":"); + if (cidx != std::string::npos) { + name.replace(cidx, 1, "_"); + } + return "opt_" + name.substr(1); // replace dash w/ opt_ + } + + OptionParser::OptionParser(std::vector& cmdline) + { + std::string luaConfig; + CommandLineParser cpf; + cpf.add_option_string("-ll:lua_config", luaConfig); + cpf.parse_command_line(cmdline); + + luaState = luaL_newstate(); + if(!luaState) { + log_config.fatal("could not get lua state"); + } + + // Open standard libraries + luaL_openlibs(luaState); + // Load config file + if(!luaConfig.empty()) { + if (luaL_loadfile(luaState, luaConfig.c_str()) == 0) { + int ret = lua_pcall(luaState, 0, 0, 0); + if (ret != 0) { + log_config.fatal(lua_tostring(luaState, -1)); + } + } else { + log_config.fatal("invalid lua config file"); + } + } else { + luaConfig = "config.lua"; + log_config.info("using default config.lua"); + if (luaL_loadfile(luaState, luaConfig.c_str()) == 0) { + int ret = lua_pcall(luaState, 0, 0, 0); + if (ret != 0) { + log_config.fatal(lua_tostring(luaState, -1)); + } + } else { + log_config.info("invalid or missing config.lua"); + luaState = NULL; + } + } + } + + OptionParser::~OptionParser(void) + { + if (luaState) lua_close(luaState); + } + + void OptionParser::parse_configfile_option(const std::string& optname, int& target) + { + if (luaState) { + std::string name = luaName(optname); + lua_getglobal(luaState, name.c_str()); + if (lua_isnumber(luaState, -1 )) { + target = lua_tointeger(luaState, -1 ); + } + lua_settop(luaState, 0); + } + } + + void OptionParser::parse_configfile_option(const std::string& optname, bool& target) + { + if (luaState) { + std::string name = luaName(optname); + lua_getglobal(luaState, name.c_str()); + // accept 0/1 or true/false + if (lua_isnumber(luaState, -1 )) { + if (lua_tointeger(luaState, -1 ) == 1) { + target = true; + } + } else if (lua_isboolean(luaState, -1 )) { + if (lua_toboolean(luaState, -1 ) == 1) { + target = true; + } + } + lua_settop(luaState, 0); + } + } + + void OptionParser::parse_configfile_option(const std::string& optname, std::string& target) + { + if (luaState) { + std::string name = luaName(optname); + lua_getglobal(luaState, name.c_str()); + const char *str = lua_tostring(luaState, -1); + if (str != NULL) { + target = std::string(str); + } + lua_settop(luaState, 0); + } + } + +}; // namespace Realm diff --git a/runtime/realm/options.h b/runtime/realm/options.h new file mode 100644 index 0000000000..97a04dd535 --- /dev/null +++ b/runtime/realm/options.h @@ -0,0 +1,78 @@ +/* Copyright 2016 Stanford University, NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef REALM_CONFIGFILE_H +#define REALM_CONFIGFILE_H + +#include "cmdline.h" + +#ifdef REALM_USE_LUAJIT + +#include +#include + +extern "C" { +#include +#include +#include + +} + +namespace Realm { + + class OptionParser : public CommandLineParser { + public: + OptionParser(std::vector& cmdline); + ~OptionParser(void); + + template + OptionParser& add_option_int(const std::string& optname, T& target, bool keep = false); + + template + OptionParser& add_option_string(const std::string& optname, T& target, bool keep = false); + + OptionParser& add_option_bool(const std::string& optname, bool& target, bool keep = false); + + template + OptionParser& add_option_method(const std::string& optname, T *target, + bool (T::*method)(const std::string&), bool keep = false); + + void parse_configfile_option(const std::string& optname, bool& target); + void parse_configfile_option(const std::string& optname, int& target); + void parse_configfile_option(const std::string& optname, std::string& target); + + protected: + lua_State *luaState; + }; + + +}; // namespace Realm + +#include "options.inl" + +#else + +// no luajit just use CommandLineParser +namespace Realm { + class OptionParser : public CommandLineParser { + public: + OptionParser(std::vector& cmdline) {} + }; +}; + +#endif + +#endif + diff --git a/runtime/realm/options.inl b/runtime/realm/options.inl new file mode 100644 index 0000000000..b0032e8cf4 --- /dev/null +++ b/runtime/realm/options.inl @@ -0,0 +1,69 @@ +/* Copyright 2016 Stanford University, NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +namespace Realm { + + // command line options will override those in config file as + // config file parsing is done in the parse_configfile_option functions + // and command line is done in parse_command_line + + template + OptionParser& OptionParser::add_option_int(const std::string& optname, + T& target, + bool keep /*= false*/) + { + CommandLineParser::add_option_int(optname, target, keep); + int x = static_cast(target); + parse_configfile_option(optname, x); + target = static_cast(x); + return *this; + } + + + template + OptionParser& OptionParser::add_option_string(const std::string& optname, + T& target, + bool keep /*= false*/) + { + CommandLineParser::add_option_string(optname, target, keep); + parse_configfile_option(optname, target); + return *this; + } + + inline OptionParser& OptionParser::add_option_bool(const std::string& optname, + bool& target, + bool keep /*= false*/) + { + CommandLineParser::add_option_bool(optname, target, keep); + parse_configfile_option(optname, target); + return *this; + } + + template + OptionParser& OptionParser::add_option_method(const std::string& optname, + T *target, + bool (T::*method)(const std::string&), + bool keep /*= false*/) + { + CommandLineParser::add_option_method(optname, target, method, keep); + std::string str; + parse_configfile_option(optname, str); + (target->*method)(str); + + return *this; + } + +}; // namespace Realm diff --git a/runtime/realm/procset/procset_module.cc b/runtime/realm/procset/procset_module.cc index 4105d69e2a..aef4fed643 100644 --- a/runtime/realm/procset/procset_module.cc +++ b/runtime/realm/procset/procset_module.cc @@ -16,7 +16,7 @@ #include "procset_module.h" #include "logging.h" -#include "cmdline.h" +#include "options.h" #include "proc_impl.h" #include "threads.h" #include "runtime_impl.h" @@ -97,7 +97,7 @@ namespace Realm { ProcSetModule *m = new ProcSetModule; // read command line parameters - CommandLineParser cp; + OptionParser cp(cmdline); cp.add_option_int("-ll:mp_threads", m->cfg_num_mp_threads) .add_option_int("-ll:mp_nodes", m->cfg_num_mp_procs) @@ -108,6 +108,7 @@ namespace Realm { log_procset.fatal() << "error reading ProcSet command line parameters"; assert(false); } + return m; } diff --git a/runtime/realm/runtime_impl.cc b/runtime/realm/runtime_impl.cc index 35b5d6486c..e6c96d418b 100644 --- a/runtime/realm/runtime_impl.cc +++ b/runtime/realm/runtime_impl.cc @@ -23,7 +23,7 @@ #include "activemsg.h" -#include "cmdline.h" +#include "options.h" #include "codedesc.h" @@ -289,7 +289,7 @@ namespace Realm { CoreModule *m = new CoreModule; // parse command line arguments - CommandLineParser cp; + OptionParser cp(cmdline); cp.add_option_int("-ll:cpu", m->num_cpu_procs) .add_option_int("-ll:util", m->num_util_procs) .add_option_int("-ll:io", m->num_io_procs) @@ -657,7 +657,7 @@ namespace Realm { // are hyperthreads considered to share a physical core bool hyperthread_sharing = true; - CommandLineParser cp; + OptionParser cp(cmdline); cp.add_option_int("-ll:gsize", gasnet_mem_size_in_mb) .add_option_int("-ll:rsize", reg_mem_size_in_mb) .add_option_int("-ll:dsize", disk_mem_size_in_mb) diff --git a/runtime/realm/sampling_impl.cc b/runtime/realm/sampling_impl.cc index 0217e1c7f5..ce81f26ecd 100644 --- a/runtime/realm/sampling_impl.cc +++ b/runtime/realm/sampling_impl.cc @@ -16,7 +16,7 @@ // sampling profiler implementation for Realm #include "sampling_impl.h" -#include "cmdline.h" +#include "options.h" #include "timers.h" #include @@ -471,7 +471,7 @@ namespace Realm { #ifndef NDEBUG bool ok = #endif - CommandLineParser() + OptionParser(cmdline) .add_option_int("-realm:prof", nodes_profiled) .add_option_string("-realm:prof_file", logfile) .add_option_int("-realm:prof_buffer_size", cfg_buffer_size) diff --git a/runtime/runtime.mk b/runtime/runtime.mk index 1109dfc314..b0336405ab 100644 --- a/runtime/runtime.mk +++ b/runtime/runtime.mk @@ -125,6 +125,15 @@ ifeq ($(strip $(USE_HWLOC)),1) LEGION_LD_FLAGS += -L$(HWLOC)/lib -lhwloc endif +ifeq ($(strip $(USE_LUAJIT)),1) + ifndef LUAJIT + $(error LUAJIT variable is not defined, aborting build) + endif + CC_FLAGS += -DREALM_USE_LUAJIT + INC_FLAGS += -I$(LUAJIT)/include/luajit-2.0 + LEGION_LD_FLAGS += -L$(LUAJIT)/lib -lluajit-5.1 +endif + ifeq ($(strip $(USE_PAPI)),1) ifndef PAPI_ROOT ifdef PAPI @@ -358,6 +367,9 @@ endif ifeq ($(strip $(USE_GASNET)),1) LOW_RUNTIME_SRC += $(LG_RT_DIR)/activemsg.cc endif +ifeq ($(strip $(USE_LUAJIT)),1) +LOW_RUNTIME_SRC += $(LG_RT_DIR)/realm/options.cc +endif GPU_RUNTIME_SRC += else CC_FLAGS += -DSHARED_LOWLEVEL @@ -367,7 +379,7 @@ LOW_RUNTIME_SRC += $(LG_RT_DIR)/realm/logging.cc \ $(LG_RT_DIR)/realm/cmdline.cc \ $(LG_RT_DIR)/realm/profiling.cc \ $(LG_RT_DIR)/realm/codedesc.cc \ - $(LG_RT_DIR)/realm/timers.cc + $(LG_RT_DIR)/realm/timers.cc MAPPER_SRC += $(LG_RT_DIR)/mappers/default_mapper.cc \ $(LG_RT_DIR)/mappers/mapping_utilities.cc \ From e4c9f94b7e70dc7fc216c00ec381f7ea10ac0813 Mon Sep 17 00:00:00 2001 From: Dean Prichard Date: Thu, 20 Oct 2016 09:52:02 -0600 Subject: [PATCH 2/4] shared_lowlevel: add configfile support --- runtime/shared_lowlevel.cc | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/runtime/shared_lowlevel.cc b/runtime/shared_lowlevel.cc index 4e3e911332..2c3f810024 100644 --- a/runtime/shared_lowlevel.cc +++ b/runtime/shared_lowlevel.cc @@ -19,6 +19,7 @@ #include "realm/profiling.h" #include "realm/timers.h" #include "realm/custom_serdez.h" +#include "realm/options.h" #ifndef __GNUC__ #include "atomics.h" // for __sync_fetch_and_add @@ -6853,22 +6854,22 @@ namespace LegionRuntime { PTHREAD_SAFE_CALL( pthread_key_create(&local_thread_key, NULL) ); DetailedTimer::init_timers(); - for (int i=1; i < *argc; i++) - { -#define INT_ARG(argname, varname) do { \ - if(!strcmp((*argv)[i], argname)) { \ - varname = atoi((*argv)[++i]); \ - continue; \ - } } while(0) - - INT_ARG("-ll:csize", cpu_mem_size_in_mb); - INT_ARG("-ll:l1size", cpu_l1_size_in_kb); - INT_ARG("-ll:cpu", num_cpus); - INT_ARG("-ll:util", num_utility_cpus); - INT_ARG("-ll:dma", num_dma_threads); - INT_ARG("-ll:stack",cpu_stack_size); -#undef INT_ARG + std::vector cmdline; + if(argc > 1) { + cmdline.resize(argc - 1); + for(int i = 1; i < argc; i++) + cmdline[i - 1] = argv[i]; } + Realm::OptionParser cp(cmdline); + + cp.add_option_int("-ll:csize", cpu_mem_size_in_mb); + cp.add_option_int("-ll:l1size", cpu_l1_size_in_kb); + cp.add_option_int("-ll:cpu", num_cpus); + cp.add_option_int("-ll:util", num_utility_cpus); + cp.add_option_int("-ll:dma", num_dma_threads); + cp.add_option_int("-ll:stack", cpu_stack_size); + cp.parse_command_line(cmdline); + cpu_stack_size = cpu_stack_size * (1 << 20); if (num_utility_cpus > num_cpus) From 100123cba64afe4ecc886ac73ed0aa29233cc97e Mon Sep 17 00:00:00 2001 From: Dean Prichard Date: Thu, 20 Oct 2016 09:53:11 -0600 Subject: [PATCH 3/4] legion: add configfile support --- runtime/CMakeLists.txt | 4 ++ runtime/legion/runtime.cc | 143 ++++++++++++++++++++------------------ 2 files changed, 80 insertions(+), 67 deletions(-) diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 775619efb2..85d08cb52e 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -257,6 +257,10 @@ target_include_directories(HighLevelRuntime PRIVATE legion realm mappers ) +if(Legion_USE_LuaJIT) + target_include_directories(HighLevelRuntime PRIVATE ${LUA_INCLUDE_DIR}) +endif() + install(TARGETS HighLevelRuntime EXPORT LegionTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/runtime/legion/runtime.cc b/runtime/legion/runtime.cc index 75ece6fd39..416ec38ebc 100644 --- a/runtime/legion/runtime.cc +++ b/runtime/legion/runtime.cc @@ -32,6 +32,7 @@ #include "replay_mapper.h" #include "debug_mapper.h" #include // sleep for warnings +#include "realm/options.h" namespace Legion { namespace Internal { @@ -19812,7 +19813,7 @@ namespace Legion { #endif realm.init(&argc, &argv); assert(ok); - + { const ReductionOpTable& red_table = get_reduction_table(); for(ReductionOpTable::const_iterator it = red_table.begin(); @@ -19828,17 +19829,13 @@ namespace Legion { // Parse any inputs for the high level runtime { -#define INT_ARG(argname, varname) do { \ - if(!strcmp((argv)[i], argname)) { \ - varname = atoi((argv)[++i]); \ - continue; \ - } } while(0) - -#define BOOL_ARG(argname, varname) do { \ - if(!strcmp((argv)[i], argname)) { \ - varname = true; \ - continue; \ - } } while(0) + std::vector cmdline; + if(argc > 1) { + cmdline.resize(argc - 1); + for(int i = 1; i < argc; i++) + cmdline[i - 1] = argv[i]; + } + Realm::OptionParser cp(cmdline); // Set these values here before parsing the input arguments // so that we don't need to trust the C runtime to do @@ -19889,66 +19886,77 @@ namespace Legion { bit_mask_logging = false; #endif unsigned delay_start = 0; - for (int i = 1; i < argc; i++) - { - BOOL_ARG("-hl:separate",separate_runtime_instances); - BOOL_ARG("-hl:registration",record_registration); - BOOL_ARG("-hl:nosteal",stealing_disabled); - BOOL_ARG("-hl:resilient",resilient_mode); - BOOL_ARG("-hl:unsafe_launch",unsafe_launch); - BOOL_ARG("-hl:unsafe_mapper",unsafe_mapper); - if (!strcmp(argv[i],"-hl:safe_mapper")) - unsafe_mapper = false; - BOOL_ARG("-hl:inorder",program_order_execution); - INT_ARG("-hl:window", initial_task_window_size); - INT_ARG("-hl:hysteresis", initial_task_window_hysteresis); - INT_ARG("-hl:sched", initial_tasks_to_schedule); - INT_ARG("-hl:width", superscalar_width); - INT_ARG("-hl:message",max_message_size); - INT_ARG("-hl:epoch", gc_epoch_size); - if (!strcmp(argv[i],"-hl:no_dyn")) - dynamic_independence_tests = false; - BOOL_ARG("-hl:spy",legion_spy_enabled); - BOOL_ARG("-hl:test",enable_test_mapper); - INT_ARG("-hl:delay", delay_start); - if (!strcmp(argv[i],"-hl:replay")) - { - replay_file = argv[++i]; - continue; - } - if (!strcmp(argv[i],"-hl:ldb")) - { - replay_file = argv[++i]; - legion_ldb_enabled = true; - continue; - } -#ifdef DEBUG_LEGION - BOOL_ARG("-hl:tree",logging_region_tree_state); - BOOL_ARG("-hl:verbose",verbose_logging); - BOOL_ARG("-hl:logical_only",logical_logging_only); - BOOL_ARG("-hl:physical_only",physical_logging_only); - BOOL_ARG("-hl:disjointness",verify_disjointness); - BOOL_ARG("-hl:bit_masks",bit_mask_logging); + + cp.add_option_bool("-hl:separate", separate_runtime_instances); + cp.add_option_bool("-hl:registration", record_registration); + cp.add_option_bool("-hl:nosteal", stealing_disabled); + cp.add_option_bool("-hl:resilient", resilient_mode); + cp.add_option_bool("-hl:unsafe_launch", unsafe_launch); + cp.add_option_bool("-hl:unsafe_mapper", unsafe_mapper); + bool safe_mapper = false; + cp.add_option_bool("-hl:safe_mapper", safe_mapper); + cp.add_option_bool("-hl:inorder", program_order_execution); + cp.add_option_int("-hl:window", initial_task_window_size); + cp.add_option_int("-hl:hysteresis", initial_task_window_hysteresis); + cp.add_option_int("-hl:sched", initial_tasks_to_schedule); + cp.add_option_int("-hl:width", superscalar_width); + cp.add_option_int("-hl:message",max_message_size); + cp.add_option_int("-hl:epoch", gc_epoch_size); + bool nodyn = false; + cp.add_option_bool("-hl:no_dyn", nodyn); + cp.add_option_bool("-hl:spy", legion_spy_enabled); + cp.add_option_bool("-hl:test", enable_test_mapper); + cp.add_option_int("-hl:delay", delay_start); + std::string replay; + cp.add_option_string("-hl:replay", replay); + std::string ldb; + cp.add_option_string("-hl:ldb", ldb); +#ifdef DEBUG_LEGION + cp.add_option_bool("-hl:tree", logging_region_tree_state); + cp.add_option_bool("-hl:verbose", verbose_logging); + cp.add_option_bool("-hl:logical_only", logical_logging_only); + cp.add_option_bool("-hl:physical_only", physical_logging_only); + cp.add_option_bool("-hl:disjointness", verify_disjointness); + cp.add_option_bool("-hl:bit_masks", bit_mask_logging); #else - if (!strcmp(argv[i],"-hl:tree")) - { - log_run.warning("WARNING: Region tree state logging is " - "disabled. To enable region tree state logging " - "compile in debug mode."); - } - if (!strcmp(argv[i],"-hl:disjointness")) - { - log_run.warning("WARNING: Disjointness verification for " - "partition creation is disabled. To enable dynamic " - "disjointness testing compile in debug mode."); - } + bool tree = false; + cp.add_option_bool("-hl:tree", tree); + bool disjoint = false; + cp.add_option_bool("-hl:disjointness", disjoint); #endif - INT_ARG("-hl:prof", num_profiling_nodes); + cp.add_option_int("-hl:prof", num_profiling_nodes); + cp.parse_command_line(cmdline); + + if (safe_mapper == true) unsafe_mapper = false; + + if (nodyn == true) dynamic_independence_tests = false; + + if (!replay.empty()) replay_file = replay.c_str(); + + if (!ldb.empty()) + { + replay_file = ldb.c_str(); + legion_ldb_enabled = true; + } + +#ifndef DEBUG_LEGION + if (tree) + { + log_run.warning("WARNING: Region tree state logging is " + "disabled. To enable region tree state logging " + "compile in debug mode."); + } + + if (disjoint) + { + log_run.warning("WARNING: Disjointness verification for " + "partition creation is disabled. To enable dynamic " + "disjointness testing compile in debug mode."); } +#endif + if (delay_start > 0) sleep(delay_start); -#undef INT_ARG -#undef BOOL_ARG #ifdef DEBUG_LEGION assert(initial_task_window_hysteresis <= 100); #endif @@ -20080,6 +20088,7 @@ namespace Legion { // Now we can set out input args Runtime::get_input_args().argv = argv; Runtime::get_input_args().argc = argc; + // For the moment, we only need to register our runtime tasks // We'll register everything else once the Legion runtime starts RtEvent tasks_registered = register_runtime_tasks(realm); From 227654b13be8725c432c0ef79847950dd9bd9272 Mon Sep 17 00:00:00 2001 From: Dean Prichard Date: Thu, 20 Oct 2016 09:54:38 -0600 Subject: [PATCH 4/4] mappers: add configfile support --- runtime/mappers/default_mapper.cc | 35 +++++++++++------------- runtime/mappers/shim_mapper.cc | 45 +++++++++++++++---------------- runtime/mappers/test_mapper.cc | 22 ++++++++------- runtime/realm/cmdline.cc | 12 +++++++++ runtime/realm/cmdline.inl | 3 +++ 5 files changed, 63 insertions(+), 54 deletions(-) diff --git a/runtime/mappers/default_mapper.cc b/runtime/mappers/default_mapper.cc index 23ca03e9d8..37c5b26fbc 100644 --- a/runtime/mappers/default_mapper.cc +++ b/runtime/mappers/default_mapper.cc @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "realm/options.h" #include "legion.h" #include "default_mapper.h" @@ -75,27 +76,21 @@ namespace Legion { { int argc = HighLevelRuntime::get_input_args().argc; char **argv = HighLevelRuntime::get_input_args().argv; - // Parse the input arguments looking for ones for the default mapper - for (int i=1; i < argc; i++) - { -#define INT_ARG(argname, varname) do { \ - if (!strcmp(argv[i], argname)) { \ - varname = atoi(argv[++i]); \ - continue; \ - } } while(0); -#define BOOL_ARG(argname, varname) do { \ - if (!strcmp(argv[i], argname)) { \ - varname = (atoi(argv[++i]) != 0); \ - continue; \ - } } while(0); - INT_ARG("-dm:thefts", max_steals_per_theft); - INT_ARG("-dm:count", max_steal_count); - BOOL_ARG("-dm:steal", stealing_enabled); - BOOL_ARG("-dm:bft", breadth_first_traversal); - INT_ARG("-dm:sched", max_schedule_count); -#undef BOOL_ARG -#undef INT_ARG + std::vector cmdline; + if(argc > 1) { + cmdline.resize(argc - 1); + for(int i = 1; i < argc; i++) + cmdline[i - 1] = argv[i]; } + Realm::OptionParser cp(cmdline); + // Parse the input arguments looking for ones for the default mapper + + cp.add_option_int("-dm:thefts", max_steals_per_theft); + cp.add_option_int("-dm:count", max_steal_count); + cp.add_option_bool("-dm:steal", stealing_enabled); + cp.add_option_bool("-dm:bft", breadth_first_traversal); + cp.add_option_int("-dm:sched", max_schedule_count); + cp.parse_command_line(cmdline); } if (stealing_enabled) { diff --git a/runtime/mappers/shim_mapper.cc b/runtime/mappers/shim_mapper.cc index fc7daf1922..ee5a10d685 100644 --- a/runtime/mappers/shim_mapper.cc +++ b/runtime/mappers/shim_mapper.cc @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "realm/options.h" #include "legion.h" #include "shim_mapper.h" @@ -415,31 +416,27 @@ namespace Legion { int argc = Runtime::get_input_args().argc; char **argv = Runtime::get_input_args().argv; unsigned num_profiling_samples = STATIC_NUM_PROFILE_SAMPLES; - // Parse the input arguments looking for ones for the shim mapper - for (int i=1; i < argc; i++) - { -#define INT_ARG(argname, varname) do { \ - if (!strcmp(argv[i], argname)) { \ - varname = atoi(argv[++i]); \ - continue; \ - } } while(0); -#define BOOL_ARG(argname, varname) do { \ - if (!strcmp(argv[i], argname)) { \ - varname = (atoi(argv[++i]) != 0); \ - continue; \ - } } while(0); - INT_ARG("-dm:thefts", max_steals_per_theft); - INT_ARG("-dm:count", max_steal_count); - INT_ARG("-dm:split", splitting_factor); - BOOL_ARG("-dm:war", war_enabled); - BOOL_ARG("-dm:steal", stealing_enabled); - BOOL_ARG("-dm:bft", breadth_first_traversal); - INT_ARG("-dm:sched", max_schedule_count); - INT_ARG("-dm:prof",num_profiling_samples); - INT_ARG("-dm:fail",max_failed_mappings); -#undef BOOL_ARG -#undef INT_ARG + + std::vector cmdline; + if(argc > 1) { + cmdline.resize(argc - 1); + for(int i = 1; i < argc; i++) + cmdline[i - 1] = argv[i]; } + Realm::OptionParser cp(cmdline); + + // Parse the input arguments looking for ones for the shim mapper + cp.add_option_int("-dm:thefts", max_steals_per_theft); + cp.add_option_int("-dm:count", max_steal_count); + cp.add_option_int("-dm:split", splitting_factor); + cp.add_option_bool("-dm:war", war_enabled); + cp.add_option_bool("-dm:steal", stealing_enabled); + cp.add_option_bool("-dm:bft", breadth_first_traversal); + cp.add_option_int("-dm:sched", max_schedule_count); + cp.add_option_int("-dm:prof", num_profiling_samples); + cp.add_option_int("-dm:fail", max_failed_mappings); + cp.parse_command_line(cmdline); + profiler.set_needed_profiling_samples(num_profiling_samples); } } diff --git a/runtime/mappers/test_mapper.cc b/runtime/mappers/test_mapper.cc index 8f313f7b9e..1df9ce9042 100644 --- a/runtime/mappers/test_mapper.cc +++ b/runtime/mappers/test_mapper.cc @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "realm/options.h" #include "test_mapper.h" #include @@ -50,17 +51,18 @@ namespace Legion { { int argc = HighLevelRuntime::get_input_args().argc; char **argv = HighLevelRuntime::get_input_args().argv; - // Parse the input arguments looking for ones for the default mapper - for (int i=1; i < argc; i++) - { -#define INT_ARG(argname, varname) do { \ - if (!strcmp(argv[i], argname)) { \ - varname = atoi(argv[++i]); \ - continue; \ - } } while(0); - INT_ARG("-tm:seed", seed); -#undef INT_ARG + + std::vector cmdline; + if(argc > 1) { + cmdline.resize(argc - 1); + for(int i = 1; i < argc; i++) + cmdline[i - 1] = argv[i]; } + Realm::OptionParser cp(cmdline); + // Parse the input arguments looking for ones for the default mapper + + cp.add_option_int("-tm:seed", seed); + cp.parse_command_line(cmdline); } if (seed == -1) { diff --git a/runtime/realm/cmdline.cc b/runtime/realm/cmdline.cc index d00e3705b1..236cae76a1 100644 --- a/runtime/realm/cmdline.cc +++ b/runtime/realm/cmdline.cc @@ -146,6 +146,18 @@ namespace Realm { return false; } + template <> + bool convert_integer_cmdline_argument(const std::string& s, long long& target) + { + errno = 0; // no errors from before + char *pos; + target = strtoul(s.c_str(), &pos, 10); + if((errno == 0) && (*pos == 0)) { + return true; + } else + return false; + } + template <> bool convert_integer_cmdline_argument(const std::string& s, bool& target) { diff --git a/runtime/realm/cmdline.inl b/runtime/realm/cmdline.inl index a4a4405aca..5060590ed2 100644 --- a/runtime/realm/cmdline.inl +++ b/runtime/realm/cmdline.inl @@ -99,6 +99,9 @@ namespace Realm { template <> bool convert_integer_cmdline_argument(const std::string& s, unsigned long& target); + + template <> + bool convert_integer_cmdline_argument(const std::string& s, long long& target); template <> bool convert_integer_cmdline_argument(const std::string& s, bool& target);