Skip to content

Commit 647249c

Browse files
authored
[SYCL] Add SYCL_PI_TRACE on loadOsLibrary (#5628)
1 parent ebe1f50 commit 647249c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

sycl/source/detail/posix_pi.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <CL/sycl/detail/defines.hpp>
10+
#include <CL/sycl/detail/pi.hpp>
1011

1112
#include <dlfcn.h>
1213
#include <string>
@@ -19,7 +20,12 @@ namespace pi {
1920
void *loadOsLibrary(const std::string &PluginPath) {
2021
// TODO: Check if the option RTLD_NOW is correct. Explore using
2122
// RTLD_DEEPBIND option when there are multiple plugins.
22-
return dlopen(PluginPath.c_str(), RTLD_NOW);
23+
void *so = dlopen(PluginPath.c_str(), RTLD_NOW);
24+
if (!so && trace(TraceLevel::PI_TRACE_ALL)) {
25+
std::cerr << "SYCL_PI_TRACE[-1]: dlopen(" << PluginPath << ") failed with <"
26+
<< dlerror() << ">" << std::endl;
27+
}
28+
return so;
2329
}
2430

2531
int unloadOsLibrary(void *Library) { return dlclose(Library); }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: linux
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
3+
// RUN: env SYCL_PI_TRACE=-1 %t.out 2>&1 | FileCheck %s
4+
5+
// Checks pi traces on library loading
6+
#include <CL/sycl.hpp>
7+
8+
using namespace cl::sycl;
9+
10+
int main() {
11+
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(libpi_cuda.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_cuda.so)}}
12+
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(libpi_hip.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_hip.so)}}
13+
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(libpi_esimd_emulator.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_esimd_emulator.so)}}
14+
queue q;
15+
q.submit([&](handler &cgh) {});
16+
}

0 commit comments

Comments
 (0)