DPC++ Runtime
Runtime libraries for oneAPI DPC++
posix_pi.cpp
Go to the documentation of this file.
1 //==---------------- posix_pi.cpp ------------------------------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include <sycl/detail/pi.hpp>
11 
12 #include <dlfcn.h>
13 #include <string>
14 
15 namespace sycl {
17 namespace detail {
18 namespace pi {
19 
20 void *loadOsLibrary(const std::string &PluginPath) {
21  // TODO: Check if the option RTLD_NOW is correct. Explore using
22  // RTLD_DEEPBIND option when there are multiple plugins.
23  void *so = dlopen(PluginPath.c_str(), RTLD_NOW);
24  if (!so && trace(TraceLevel::PI_TRACE_ALL)) {
25  char *Error = dlerror();
26  std::cerr << "SYCL_PI_TRACE[-1]: dlopen(" << PluginPath << ") failed with <"
27  << (Error ? Error : "unknown error") << ">" << std::endl;
28  }
29  return so;
30 }
31 
32 int unloadOsLibrary(void *Library) {
33  // The mock plugin does not have an associated library, so we allow nullptr
34  // here to avoid it trying to free a non-existent library.
35  if (!Library)
36  return 0;
37  return dlclose(Library);
38 }
39 
40 void *getOsLibraryFuncAddress(void *Library, const std::string &FunctionName) {
41  return dlsym(Library, FunctionName.c_str());
42 }
43 
44 } // namespace pi
45 } // namespace detail
46 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
47 } // namespace sycl
#define __SYCL_INLINE_VER_NAMESPACE(X)
__SYCL_EXTERN_STREAM_ATTRS ostream cerr
Linked to standard error (unbuffered)
int unloadOsLibrary(void *Library)
Definition: posix_pi.cpp:32
bool trace(TraceLevel level)
Definition: pi.cpp:394
void * loadOsLibrary(const std::string &Library)
Definition: posix_pi.cpp:20
void * getOsLibraryFuncAddress(void *Library, const std::string &FunctionName)
Definition: posix_pi.cpp:40
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
C++ wrapper of extern "C" PI interfaces.