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

[SYCL] Change library loading and fix esimd selector function #1312

Merged
merged 18 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions SYCL/Basic/library_loading.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// REQUIRES: linux
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: env SYCL_PI_TRACE=-1 %t.out &> %t_trace.txt || true
// RUN: FileCheck --input-file=%t_trace.txt %s

// RUN: env SYCL_PI_TRACE=-1 %t.out &> %t_trace_no_filter.txt || true
// RUN: FileCheck --input-file=%t_trace_no_filter.txt --check-prefix=CHECK-NO-FILTER %s
// RUN: env SYCL_PI_TRACE=-1 SYCL_DEVICE_FILTER=esimd_emulator %t.out &> %t_trace_esimd_filter.txt || true
// RUN: FileCheck --input-file=%t_trace_esimd_filter.txt --check-prefix=CHECK-ESIMD-FILTER %s
// Checks pi traces on library loading

#include <sycl/sycl.hpp>

using namespace sycl;

int main() {
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_cuda.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_cuda.so)}}
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_hip.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_hip.so)}}
// 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)}}
// 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)}}
// 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)}}
// 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)}}
// 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)}}
queue q;
q.submit([&](handler &cgh) {});
}
30 changes: 16 additions & 14 deletions SYCL/ESIMD/esimd_test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,28 @@ using namespace sycl;

namespace esimd_test {

// This is function provided to SYCL runtime by the application to decide
// This is the function provided to SYCL runtime by the application to decide
// on which device to run, or whether to run at all.
// When selecting a device, SYCL runtime first takes (1) a selector provided by
// the program or a default one and (2) the set of all available devices. Then
// it passes each device to the selector. A device for which the highest number
// is returned is selected. If a negative number was returned for all devices,
// then the selection process will cause an exception.
// it passes each device to the '()' operator of the selector. Device, for
// which '()' returned the highest number, is selected. If a negative number
// was returned for all devices, then the selection process will cause an
// exception.
// Require GPU device
inline int ESIMDSelector(const device &device) {
if (const char *dev_filter = getenv("SYCL_DEVICE_FILTER")) {
std::string filter_string(dev_filter);
if (filter_string.find("gpu") != std::string::npos)
return device.is_gpu() ? 1000 : -1;

std::cerr
<< "Supported 'SYCL_DEVICE_FILTER' env var device type is 'gpu' and "
<< filter_string << "' does not contain that.\n";
const std::string intel{"Intel(R) Corporation"};
if (device.get_backend() == backend::ext_intel_esimd_emulator) {
return 1000;
} else if (device.is_gpu() &&
(device.get_info<info::device::vendor>() == intel)) {
// pick gpu device if esimd not available but give it a lower score in
// order not to compete with the esimd in environments where both are
// present
return 900;
} else {
return -1;
}
// If "SYCL_DEVICE_FILTER" not defined, only allow gpu device
return device.is_gpu() ? 1000 : -1;
}

inline auto createExceptionHandler() {
Expand Down