DPC++ Runtime
Runtime libraries for oneAPI DPC++
posix_ur.cpp
Go to the documentation of this file.
1 //==---------------- posix_ur.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 
11 #include <sycl/detail/ur.hpp>
12 
13 #include <dlfcn.h>
14 #include <string>
15 
16 namespace sycl {
17 inline namespace _V1 {
18 namespace detail::ur {
19 
20 void *loadOsLibrary(const std::string &LibraryPath) {
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(LibraryPath.c_str(), RTLD_NOW);
24  if (!so && detail::ur::trace()) {
25  char *Error = dlerror();
26  std::cerr << "SYCL_UR_TRACE: dlopen(" << LibraryPath << ") failed with <"
27  << (Error ? Error : "unknown error") << ">" << std::endl;
28  }
29  return so;
30 }
31 
32 int unloadOsLibrary(void *Library) { return dlclose(Library); }
33 
34 void *getOsLibraryFuncAddress(void *Library, const std::string &FunctionName) {
35  return dlsym(Library, FunctionName.c_str());
36 }
37 
38 } // namespace detail::ur
39 } // namespace _V1
40 } // namespace sycl
__SYCL_EXTERN_STREAM_ATTRS ostream cerr
Linked to standard error (unbuffered)
void * getOsLibraryFuncAddress(void *Library, const std::string &FunctionName)
Definition: posix_ur.cpp:34
void * loadOsLibrary(const std::string &Library)
Definition: posix_ur.cpp:20
int unloadOsLibrary(void *Library)
Definition: posix_ur.cpp:32
Definition: access.hpp:18
C++ utilities for Unified Runtime integration.