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::pi {
18 
19 void *loadOsPluginLibrary(const std::string &PluginPath) {
20  // TODO: Check if the option RTLD_NOW is correct. Explore using
21  // RTLD_DEEPBIND option when there are multiple plugins.
22  void *so = dlopen(PluginPath.c_str(), RTLD_NOW);
23  if (!so && trace(TraceLevel::PI_TRACE_ALL)) {
24  char *Error = dlerror();
25  std::cerr << "SYCL_PI_TRACE[-1]: dlopen(" << PluginPath << ") failed with <"
26  << (Error ? Error : "unknown error") << ">" << std::endl;
27  }
28  return so;
29 }
30 
31 int unloadOsPluginLibrary(void *Library) {
32  // The mock plugin does not have an associated library, so we allow nullptr
33  // here to avoid it trying to free a non-existent library.
34  if (!Library)
35  return 0;
36  return dlclose(Library);
37 }
38 
39 void *getOsLibraryFuncAddress(void *Library, const std::string &FunctionName) {
40  return dlsym(Library, FunctionName.c_str());
41 }
42 
43 } // namespace detail::pi
44 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
45 } // namespace sycl
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::detail::pi::unloadOsPluginLibrary
int unloadOsPluginLibrary(void *Library)
Definition: posix_pi.cpp:31
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
pi.hpp
defines.hpp
std::cerr
__SYCL_EXTERN_STREAM_ATTRS ostream cerr
Linked to standard error (unbuffered)
sycl::_V1::detail::pi::loadOsPluginLibrary
void * loadOsPluginLibrary(const std::string &Library)
Definition: posix_pi.cpp:19
sycl::_V1::detail::pi::getOsLibraryFuncAddress
void * getOsLibraryFuncAddress(void *Library, const std::string &FunctionName)
Definition: posix_pi.cpp:39
sycl::_V1::detail::pi::PI_TRACE_ALL
@ PI_TRACE_ALL
Definition: pi.hpp:58
sycl::_V1::detail::pi::trace
bool trace(TraceLevel level)
Definition: pi.cpp:391