MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / openDynLibrary

Function openDynLibrary

src/api/unified/symbol_manager.cpp:104–172  ·  view source on GitHub ↗

flag parameter is not used on windows platform */

Source from the content-addressed store, hash-verified

102
103/*flag parameter is not used on windows platform */
104LibHandle openDynLibrary(const af_backend bknd_idx) {
105 // The default search path is the colon separated list of paths stored in
106 // the environment variables:
107 string bkndLibName = getBkndLibName(bknd_idx);
108 string show_flag = getEnvVar("AF_SHOW_LOAD_PATH");
109 bool show_load_path = show_flag == "1";
110
111 // FIXME(umar): avoid this if at all possible
112 auto getLogger = [&] { return spdlog::get("unified"); };
113
114 string pathPrefixes[] = {
115 "", // empty prefix i.e. just the library name will enable search in
116 // system default paths such as LD_LIBRARY_PATH, Program
117 // Files(Windows) etc.
118 ".", // Shared libraries in current directory
119 // Running from the CMake Build directory
120 join_path(".", "src", "backend", getBackendDirectoryName(bknd_idx)),
121 // Running from the test directory
122 join_path("..", "src", "backend", getBackendDirectoryName(bknd_idx)),
123 // Environment variable PATHS
124 join_path(getEnvVar("AF_BUILD_PATH"), "src", "backend",
125 getBackendDirectoryName(bknd_idx)),
126 join_path(getEnvVar("AF_PATH"), "lib"),
127 join_path(getEnvVar("AF_PATH"), "lib64"),
128 getEnvVar("AF_BUILD_LIB_CUSTOM_PATH"),
129
130 // Common install paths
131#if !defined(OS_WIN)
132 "/opt/arrayfire-3/lib/",
133 "/opt/arrayfire/lib/",
134 "/usr/local/lib/",
135 "/usr/local/arrayfire/lib/"
136#else
137 join_path(getEnvVar("ProgramFiles"), "ArrayFire", "lib"),
138 join_path(getEnvVar("ProgramFiles"), "ArrayFire", "v3", "lib")
139#endif
140 };
141 typedef af_err (*func)(int*);
142
143 LibHandle retVal = nullptr;
144
145 for (auto& pathPrefixe : pathPrefixes) {
146 AF_TRACE("Attempting: {}",
147 (pathPrefixe.empty() ? "Default System Paths" : pathPrefixe));
148 if ((retVal =
149 loadLibrary(join_path(pathPrefixe, bkndLibName).c_str()))) {
150 AF_TRACE("Found: {}", join_path(pathPrefixe, bkndLibName));
151
152 func count_func = reinterpret_cast<func>(
153 getFunctionPointer(retVal, "af_get_device_count"));
154 if (count_func) {
155 int count = 0;
156 count_func(&count);
157 AF_TRACE("Device Count: {}.", count);
158 if (count == 0) {
159 AF_TRACE("Skipping: No devices found for {}", bkndLibName);
160 retVal = nullptr;
161 continue;

Callers 1

AFSymbolManagerMethod · 0.85

Calls 8

getBkndLibNameFunction · 0.85
getEnvVarFunction · 0.85
join_pathFunction · 0.85
getBackendDirectoryNameFunction · 0.85
getFunction · 0.50
loadLibraryFunction · 0.50
getFunctionPointerFunction · 0.50
getErrorMessageFunction · 0.50

Tested by

no test coverage detected