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

Commit e03f8ac

Browse files
[SYCL] tests for aspect_selector (#1327)
tests for aspect_selector
1 parent 7dd12a2 commit e03f8ac

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

SYCL/Basic/device-selectors.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,69 @@ int main() {
117117
} catch (exception &e) {
118118
}
119119

120+
// ------ aspect_selectors --------
121+
122+
// Unrestrained selection, equivalent to default_selector.
123+
device dev0 = device{aspect_selector()};
124+
assert(dev0 == default_queue.get_device() &&
125+
"unrestrained aspect selector should result in same device as "
126+
"default_selector");
127+
128+
// -- Individual test runs may or may not have desired device available.
129+
// Ignore any exception.
130+
131+
// Pass aspects in a vector.
132+
try {
133+
device dev1 =
134+
device{aspect_selector(std::vector{aspect::cpu, aspect::image})};
135+
assert(dev1.is_cpu() && "Incorrect device, expected CPU.");
136+
assert(dev1.has(aspect::image) && "Device should support aspect::image.");
137+
} catch (exception &e) {
138+
}
139+
140+
// Pass aspects without a vector.
141+
try {
142+
device dev2 = device{aspect_selector(aspect::gpu, aspect::image)};
143+
assert(dev2.is_gpu() && "Incorrect device, expected GPU.");
144+
assert(dev2.has(aspect::image) && "Device should support aspect::image.");
145+
} catch (exception &e) {
146+
}
147+
148+
// Pass aspects as compile-time parameters
149+
try {
150+
device dev3 = device{aspect_selector<aspect::cpu, aspect::fp64>()};
151+
assert(dev3.is_cpu() && "Incorrect device, expected CPU.");
152+
assert(dev3.has(aspect::fp64) && "Device should support aspect::fp64.");
153+
} catch (exception &e) {
154+
}
155+
156+
// Pass aspects in an allowlist and a denylist.
157+
try {
158+
device dev4 = device{aspect_selector(std::vector{aspect::accelerator},
159+
std::vector{aspect::image})};
160+
assert(dev4.is_accelerator() && "Incorrect device, expected accelerator.");
161+
assert(!dev4.has(aspect::image) &&
162+
"Device should NOT support aspect::image.");
163+
} catch (exception &e) {
164+
}
165+
166+
// Validate errors.
167+
try {
168+
device dev5 = device{aspect_selector<aspect::cpu, aspect::gpu>()};
169+
assert(
170+
"We should not be here. No known device that is both a CPU and a GPU.");
171+
} catch (exception &e) {
172+
assert(e.code() == sycl::errc::runtime && "Incorrect error code.");
173+
}
174+
175+
try {
176+
device dev6 = device{
177+
aspect_selector(std::vector{aspect::cpu}, std::vector{aspect::cpu})};
178+
assert("We should not be here. RequireList and DenyList impossible to "
179+
"fulfill.");
180+
} catch (exception &e) {
181+
assert(e.code() == sycl::errc::runtime && "Incorrect error code.");
182+
}
183+
120184
return 0;
121185
}

0 commit comments

Comments
 (0)