Skip to content
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: 15 additions & 0 deletions sycl/include/sycl/detail/device_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ struct ods_target {
ods_target(backend be) { Backend = be; };
ods_target(){};
friend std::ostream &operator<<(std::ostream &Out, const ods_target &Target);

#if __cplusplus >= 202002L
bool operator==(const ods_target &Other) const = default;
#else
bool operator==(const ods_target &Other) const {
return Backend == Other.Backend && DeviceType == Other.DeviceType &&
HasDeviceWildCard == Other.HasDeviceWildCard &&
DeviceNum == Other.DeviceNum &&
HasSubDeviceWildCard == Other.HasSubDeviceWildCard &&
HasSubSubDeviceWildCard == Other.HasSubSubDeviceWildCard &&
SubSubDeviceNum == Other.SubSubDeviceNum &&
IsNegativeTarget == Other.IsNegativeTarget &&
MatchesSeen == Other.MatchesSeen;
}
#endif
};

class ods_target_list {
Expand Down
6 changes: 0 additions & 6 deletions sycl/test-e2e/OneapiDeviceSelector/backendonly_error.cpp

This file was deleted.

8 changes: 0 additions & 8 deletions sycl/test-e2e/OneapiDeviceSelector/case_sensitivity.cpp

This file was deleted.

1 change: 1 addition & 0 deletions sycl/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ if (NOT WIN32)
endif()
add_subdirectory(sampler)
add_subdirectory(reduction)
add_subdirectory(OneAPIDeviceSelector)
3 changes: 3 additions & 0 deletions sycl/unittests/OneAPIDeviceSelector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_sycl_unittest(OneAPIDeviceSelectorTests OBJECT
Tests.cpp
)
57 changes: 57 additions & 0 deletions sycl/unittests/OneAPIDeviceSelector/Tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//===---------------------------- Tests.cpp -------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <sycl/detail/device_filter.hpp>
#include <sycl/exception.hpp>

#include <gtest/gtest.h>

#include <vector>
#include <utility>
#include <string>

TEST(OneAPIDeviceSelector, IsCaseInsensitive) {
ASSERT_EQ(sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("OPENCL:*"),
sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("opencl:*"))
<< " backend should be case-insensitive";

ASSERT_EQ(sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("*:GPU"),
sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("*:gpu"))
<< " device type should be case-insensitive";
}

TEST(OneAPIDeviceSelector, EmitsErrorIfOnlyBackendIsSpecified) {
try {
std::ignore = sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("level_zero");
FAIL() << "An exception was expected";
} catch (const sycl::exception &e) {
ASSERT_EQ(e.code(), sycl::errc::invalid);
ASSERT_EQ(std::string(e.what()),
"Incomplete selector! Try 'level_zero:*' if all "
"devices under the backend was original intention.");
}
}

TEST(OneAPIDeviceSelector, EmitsErrorIfBackendStringIsInvalid) {
try {
std::ignore = sycl::detail::Parse_ONEAPI_DEVICE_SELECTOR("macaroni:*");
FAIL() << "An exception was expected";
} catch (const sycl::exception &e) {
ASSERT_EQ(e.code(), sycl::errc::invalid);
// FIXME: the error below could be better
ASSERT_EQ(std::string(e.what()),
"ONEAPI_DEVICE_SELECTOR parsing error. Backend is required but "
"missing from \"macaroni:*\"");
}
}

// TODO: test case ":"
// TODO: test case ":cpu"
// TODO: test case "level_zero:cpu:cpu"
// TODO: test case "opencl:"
// TODO: other positive test cases for parsing device, sub-devices, etc.
Loading