22 inline namespace _V1 {
23 namespace ext::oneapi::detail {
25 std::vector<std::string>
tokenize(
const std::string &Filter,
26 const std::string &Delim) {
27 std::vector<std::string> Tokens;
29 std::string Input = Filter;
32 while ((Pos = Input.find(Delim)) != std::string::npos) {
33 Tok = Input.substr(0, Pos);
34 Input.erase(0, Pos + Delim.length());
37 Tokens.push_back(std::move(Tok));
43 Tokens.push_back(std::move(Input));
50 constexpr
auto Error =
"Invalid filter string! Valid strings conform to "
51 "BE:DeviceType:DeviceNum, where any are optional";
53 std::vector<std::string> Tokens =
tokenize(Input,
":");
54 std::regex IntegerExpr(
"[[:digit:]]+");
58 if (Tokens.size() > 3)
61 for (
const std::string &Token : Tokens) {
62 if (Token ==
"cpu" && !Result.DeviceType) {
63 Result.DeviceType = sycl::info::device_type::cpu;
64 }
else if (Token ==
"gpu" && !Result.DeviceType) {
65 Result.DeviceType = sycl::info::device_type::gpu;
66 }
else if (Token ==
"accelerator" && !Result.DeviceType) {
67 Result.DeviceType = sycl::info::device_type::accelerator;
68 }
else if (Token ==
"opencl" && !Result.Backend) {
70 }
else if (Token ==
"level_zero" && !Result.Backend) {
72 }
else if (Token ==
"cuda" && !Result.Backend) {
74 }
else if (Token ==
"hip" && !Result.Backend) {
76 }
else if (std::regex_match(Token, IntegerExpr) && !Result.DeviceNum) {
78 Result.DeviceNum = std::stoi(Token);
79 }
catch (std::logic_error &) {
91 : mFilters(), mNumDevicesSeen(0), mMatchFound(false) {
95 for (
const std::string &Filter : Filters) {
97 mFilters.push_back(std::move(F));
102 int Score = REJECT_DEVICE_SCORE;
104 for (
auto &Filter : mFilters) {
105 bool BackendOK =
true;
106 bool DeviceTypeOK =
true;
107 bool DeviceNumOK =
true;
109 if (Filter.Backend) {
115 BackendOK = (BE == Filter.Backend.value());
117 if (Filter.DeviceType) {
121 if (Filter.DeviceType == sycl::info::device_type::all)
124 DeviceTypeOK = (DT == Filter.DeviceType);
126 if (Filter.DeviceNum) {
128 if (BackendOK && DeviceTypeOK) {
130 DeviceNumOK = (Filter.MatchesSeen == Filter.DeviceNum.value());
132 Filter.MatchesSeen++;
135 if (BackendOK && DeviceTypeOK && DeviceNumOK) {
143 if ((mNumDevicesSeen == mNumTotalDevices) && !mMatchFound) {
146 "Could not find a device that matches the specified filter(s)!");
155 for (
auto &Filter : mFilters) {
156 Filter.MatchesSeen = 0;
165 using namespace ext::oneapi;
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
static std::vector< device > get_devices(info::device_type deviceType=info::device_type::all)
Query available SYCL devices.
detail::is_device_info_desc< Param >::return_type get_info() const
Queries this SYCL device for information requested by the template parameter param.
int operator()(const device &dev) const
filter_selector_impl(const std::string &filter)
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
sycl::detail::ods_target filter
filter create_filter(const std::string &Input)
std::vector< std::string > tokenize(const std::string &Filter, const std::string &Delim)
signed char __SYCL2020_DEPRECATED
int default_selector_v(const device &dev)
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()