Skip to content

[SYCL] Do not select device with a negative score #1751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2020
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
7 changes: 3 additions & 4 deletions sycl/source/device_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ device device_selector::select_device() const {
string_class DeviceName = dev.get_info<info::device::name>();
std::cout << "SYCL_PI_TRACE[all]: "
<< "select_device(): -> score = " << score
<< ((score == REJECT_DEVICE_SCORE) ? "(REJECTED)" : " ")
<< std::endl
<< ((score < 0) ? "(REJECTED)" : " ") << std::endl
<< "SYCL_PI_TRACE[all]: "
<< " platform: " << PlatformVersion << std::endl
<< "SYCL_PI_TRACE[all]: "
<< " device: " << DeviceName << std::endl;
}

// Device is discarded if is marked with REJECT_DEVICE_SCORE
if (dev_score == REJECT_DEVICE_SCORE)
// A negative score means that a device must not be selected.
if (dev_score < 0)
continue;

// SYCL spec says: "If more than one device receives the high score then
Expand Down
28 changes: 28 additions & 0 deletions sycl/test/basic_tests/device_selector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: env SYCL_BE=%sycl_be %t.out
//
// Checks that no device is selected when no device of desired type is
// available.

#include <CL/sycl.hpp>

#include <iostream>

class RejectEverything : public sycl::device_selector {
public:
int operator()(const sycl::device &Device) const final {
// Negative value means that a device must not be selected
return -1;
}
};

int main() {
RejectEverything Selector;
try {
sycl::device Device(Selector);
} catch (sycl::runtime_error &E) {
return 0;
}
std::cerr << "Error. A device is found." << std::endl;
return 1;
}