Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 87a75bd

Browse files
authored
[SYCL] Change library loading and fix esimd selector function (#1312)
The esimd_test_utils.hpp file has been changed to provide a correct esimd_emulator selector and the library_loading.cpp has been changed to only check for esimd_emulator loading if the filter is set to esimd_emulator. This checks the functionality introduced in the following PR: intel/llvm#6870
1 parent cfe4813 commit 87a75bd

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

SYCL/Basic/library_loading.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
// REQUIRES: linux
22
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
3-
// RUN: env SYCL_PI_TRACE=-1 %t.out &> %t_trace.txt || true
4-
// RUN: FileCheck --input-file=%t_trace.txt %s
5-
3+
// RUN: env SYCL_PI_TRACE=-1 %t.out &> %t_trace_no_filter.txt || true
4+
// RUN: FileCheck --input-file=%t_trace_no_filter.txt --check-prefix=CHECK-NO-FILTER %s
5+
// RUN: env SYCL_PI_TRACE=-1 SYCL_DEVICE_FILTER=esimd_emulator %t.out &> %t_trace_esimd_filter.txt || true
6+
// RUN: FileCheck --input-file=%t_trace_esimd_filter.txt --check-prefix=CHECK-ESIMD-FILTER %s
67
// Checks pi traces on library loading
8+
79
#include <sycl/sycl.hpp>
810

911
using namespace sycl;
1012

1113
int main() {
12-
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_cuda.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_cuda.so)}}
13-
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_hip.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_hip.so)}}
14-
// 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+
// CHECK-NO-FILTER: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_cuda.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_cuda.so)}}
15+
// CHECK-NO-FILTER-NOT: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_esimd_emulator.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_esimd_emulator.so)}}
16+
// CHECK-NO-FILTER: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_hip.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_hip.so)}}
17+
// CHECK-ESIMD-FILTER: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_esimd_emulator.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_esimd_emulator.so)}}
1518
queue q;
1619
q.submit([&](handler &cgh) {});
1720
}

SYCL/ESIMD/esimd_test_utils.hpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,28 @@ using namespace sycl;
2626

2727
namespace esimd_test {
2828

29-
// This is function provided to SYCL runtime by the application to decide
29+
// This is the function provided to SYCL runtime by the application to decide
3030
// on which device to run, or whether to run at all.
3131
// When selecting a device, SYCL runtime first takes (1) a selector provided by
3232
// the program or a default one and (2) the set of all available devices. Then
33-
// it passes each device to the selector. A device for which the highest number
34-
// is returned is selected. If a negative number was returned for all devices,
35-
// then the selection process will cause an exception.
33+
// it passes each device to the '()' operator of the selector. Device, for
34+
// which '()' returned the highest number, is selected. If a negative number
35+
// was returned for all devices, then the selection process will cause an
36+
// exception.
37+
// Require GPU device
3638
inline int ESIMDSelector(const device &device) {
37-
if (const char *dev_filter = getenv("SYCL_DEVICE_FILTER")) {
38-
std::string filter_string(dev_filter);
39-
if (filter_string.find("gpu") != std::string::npos)
40-
return device.is_gpu() ? 1000 : -1;
41-
42-
std::cerr
43-
<< "Supported 'SYCL_DEVICE_FILTER' env var device type is 'gpu' and "
44-
<< filter_string << "' does not contain that.\n";
39+
const std::string intel{"Intel(R) Corporation"};
40+
if (device.get_backend() == backend::ext_intel_esimd_emulator) {
41+
return 1000;
42+
} else if (device.is_gpu() &&
43+
(device.get_info<info::device::vendor>() == intel)) {
44+
// pick gpu device if esimd not available but give it a lower score in
45+
// order not to compete with the esimd in environments where both are
46+
// present
47+
return 900;
48+
} else {
4549
return -1;
4650
}
47-
// If "SYCL_DEVICE_FILTER" not defined, only allow gpu device
48-
return device.is_gpu() ? 1000 : -1;
4951
}
5052

5153
inline auto createExceptionHandler() {

0 commit comments

Comments
 (0)