OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RuntimeLibManager Class Reference

#include <RuntimeLibManager.h>

Static Public Member Functions

static void loadRuntimeLibs (const std::string &torch_lib_path=std::string())
 
static void loadTestRuntimeLibs ()
 
static bool is_libtorch_loaded ()
 

Static Private Attributes

static bool is_libtorch_loaded_
 

Detailed Description

Definition at line 4 of file RuntimeLibManager.h.

Member Function Documentation

bool RuntimeLibManager::is_libtorch_loaded ( )
static

Definition at line 146 of file RuntimeLibManager.cpp.

References is_libtorch_loaded_.

146  {
147  return is_libtorch_loaded_;
148 }
static bool is_libtorch_loaded_
void RuntimeLibManager::loadRuntimeLibs ( const std::string &  torch_lib_path = std::string())
static

Definition at line 52 of file RuntimeLibManager.cpp.

References logger::FATAL, get_torch_table_functions_path(), is_libtorch_loaded_, libtorch, libTorchTFs, LOG, and logger::WARNING.

Referenced by DBHandler::initialize(), and QueryRunner::QueryRunner::QueryRunner().

52  {
53  is_libtorch_loaded_ = false;
54 #ifdef HAVE_TORCH_TFS
55  // Third party libraries must be loaded with the RTLD_GLOBAL flag set, so their symbols
56  // can be available for resolution by further dynamic loads
57  // They must also be loaded using RTLD_DEEPBIND, in case they have statically linked
58  // symbols from common libraries that conflict with symbols also statically linked with
59  // heavydb. For instance, LibTorch also statically links with LLVM, so not using
60  // RTLD_DEEPBIND will cause issues with LibTorch referring to heavy's LLVM symbols or
61  // vice-versa.
62  if (!torch_lib_path.empty()) {
63  boost::dll::fs::path lib_path(torch_lib_path);
64  libtorch = boost::dll::shared_library(
65  lib_path,
66  boost::dll::load_mode::rtld_global | boost::dll::load_mode::rtld_deepbind);
67  } else {
68  libtorch = boost::dll::shared_library("libtorch",
69  boost::dll::load_mode::search_system_folders |
70  boost::dll::load_mode::append_decorations |
71  boost::dll::load_mode::rtld_global |
72  boost::dll::load_mode::rtld_deepbind);
73  }
74 
75  if (!libtorch.is_loaded()) {
76  throw(std::runtime_error(
77  "Failed to load runtime library LibTorch. Support for library is disabled!"));
78  }
79 
80  LOG(WARNING) << "This HeavyDB was built against LibTorch version " << TORCH_VERSION
81  << ". Using a different version of LibTorch may cause breaking behavior!";
82 
83  // Shared libraries containing table function implementations must also be loaded
84  // using RTLD_GLOBAL, as the JIT-ed LLVM code needs to resolve the symbols at runtime.
85  // They must also be loaded using RTLD_DEEPBIND, which makes sure name binding favors
86  // symbols local to the library before considering global ones. This makes sure the
87  // TableFunctionsFactory::init() calls within the library call its own init() function
88  // rather than the server's main one.
89  // TODO: This behavior may not be supported in Windows, we should test symbol
90  // resolution in Windows platforms to make sure this works.
91  boost::dll::fs::path torch_tfs_lib_path(get_torch_table_functions_path());
92  libTorchTFs = boost::dll::shared_library(
93  torch_tfs_lib_path,
94  boost::dll::load_mode::rtld_lazy | boost::dll::load_mode::search_system_folders |
95  boost::dll::load_mode::rtld_global | boost::dll::load_mode::append_decorations |
96  boost::dll::load_mode::rtld_deepbind);
97  if (!libTorchTFs.is_loaded()) {
98  throw(
99  std::runtime_error("Failed to load LibTorch table function module. LibTorch "
100  "table function support is disabled!"));
101  }
102 
103  if (!libTorchTFs.has("init_table_functions")) {
104  LOG(FATAL) << "Load-time table function module does not contain "
105  "'init_table_functions' symbol!";
106  }
107 
108  // calls the module's TableFunctionsFactory::init() to register table functions
109  auto initFunction = libTorchTFs.get<void(void)>("init_table_functions");
110  initFunction();
111  is_libtorch_loaded_ = true;
112 #endif
113 }
#define LOG(tag)
Definition: Logger.h:285
boost::dll::shared_library libtorch
static bool is_libtorch_loaded_
boost::filesystem::path get_torch_table_functions_path()
boost::dll::shared_library libTorchTFs

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RuntimeLibManager::loadTestRuntimeLibs ( )
static

Definition at line 118 of file RuntimeLibManager.cpp.

References logger::FATAL, get_runtime_test_lib_path(), get_runtime_test_lib_tfs_path(), LOG, testLib, and testLibTFs.

Referenced by QueryRunner::QueryRunner::QueryRunner().

118  {
119  testLib = boost::dll::shared_library(get_runtime_test_lib_path(),
120  boost::dll::load_mode::append_decorations |
121  boost::dll::load_mode::rtld_global |
122  boost::dll::load_mode::search_system_folders |
123  boost::dll::load_mode::rtld_deepbind);
124 
125  if (!testLib.is_loaded()) {
126  throw(std::runtime_error("Failed to load test runtime library!"));
127  }
128 
129  testLibTFs = boost::dll::shared_library(
131  boost::dll::load_mode::rtld_lazy | boost::dll::load_mode::search_system_folders |
132  boost::dll::load_mode::rtld_global | boost::dll::load_mode::append_decorations |
133  boost::dll::load_mode::rtld_deepbind);
134  if (!testLibTFs.is_loaded()) {
135  throw(std::runtime_error("Failed to load test runtime library table functions!!"));
136  }
137 
138  if (!testLibTFs.has("init_table_functions")) {
139  LOG(FATAL)
140  << "Test runtime table function library has no init_table_functions symbol!";
141  }
142  auto initFunction = testLibTFs.get<void(void)>("init_table_functions");
143  initFunction();
144 }
boost::filesystem::path get_runtime_test_lib_path()
#define LOG(tag)
Definition: Logger.h:285
boost::dll::shared_library testLib
boost::dll::shared_library testLibTFs
boost::filesystem::path get_runtime_test_lib_tfs_path()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

bool RuntimeLibManager::is_libtorch_loaded_
staticprivate

Definition at line 11 of file RuntimeLibManager.h.

Referenced by is_libtorch_loaded(), and loadRuntimeLibs().


The documentation for this class was generated from the following files: