Skip to content

Commit dc236a0

Browse files
Maxime France-Pilloisreblejulianmi
committed
[SYCL][Graph] Throw exception when creating graph for unsupported backend (#280)
* [SYCL][Graph] Throw exception when creating graph for unsupported backend - Checks backend when creating graphs and throws an exception is the backend is not supported. - Adds an e2e test to verify this exception throwing. - Updates some comments - Improves mock usage in Unitest to avoid having to force emulation mode --------- Co-authored-by: Pablo Reble <[email protected]> Co-authored-by: Julian Miller <[email protected]>
1 parent e578f69 commit dc236a0

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

sycl/source/detail/graph_impl.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,16 @@ class graph_impl {
373373
if (PropList.has_property<property::graph::no_cycle_check>()) {
374374
MSkipCycleChecks = true;
375375
}
376+
if (SyclDevice.get_info<
377+
ext::oneapi::experimental::info::device::graph_support>() ==
378+
info::graph_support_level::unsupported) {
379+
std::stringstream Stream;
380+
Stream << SyclDevice.get_backend();
381+
std::string BackendString = Stream.str();
382+
throw sycl::exception(
383+
sycl::make_error_code(errc::invalid),
384+
BackendString + " backend is not supported by SYCL Graph extension.");
385+
}
376386
}
377387

378388
/// Remove node from list of root nodes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %{build} -o %t.out
2+
// RUN: %{run} %t.out
3+
4+
// Tests the ability to finalize a empty command graph
5+
// The test checks that invalid exception is thrown
6+
// when trying to create a graph with an unsupported backend.
7+
8+
#include "graph_common.hpp"
9+
10+
int GetUnsupportedBackend(const sycl::device &Dev) {
11+
// Return 1 if the device backend is unsupported or 0 else.
12+
// 0 does not prevent another device to be picked as a second choice
13+
return Dev.get_info<
14+
ext::oneapi::experimental::info::device::graph_support>() ==
15+
ext::oneapi::experimental::info::graph_support_level::unsupported;
16+
}
17+
18+
int main() {
19+
sycl::device Dev{GetUnsupportedBackend};
20+
queue Queue{Dev};
21+
22+
if (Dev.get_info<ext::oneapi::experimental::info::device::graph_support>() !=
23+
ext::oneapi::experimental::info::graph_support_level::unsupported)
24+
return 0;
25+
26+
std::error_code ExceptionCode = make_error_code(sycl::errc::success);
27+
try {
28+
exp_ext::command_graph Graph{Queue.get_context(), Dev};
29+
} catch (exception &Exception) {
30+
ExceptionCode = Exception.code();
31+
}
32+
assert(ExceptionCode == sycl::errc::invalid);
33+
34+
return 0;
35+
}

sycl/unittests/Extensions/CommandGraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ TEST_F(CommandGraphTest, Finalize) {
474474
sycl::buffer<int> Buf(1);
475475
auto Node1 = Graph.add([&](sycl::handler &cgh) {
476476
sycl::accessor A(Buf, cgh, sycl::write_only, sycl::no_init);
477-
cgh.single_task<class TestKernel1>([=]() { A[0] = 1; });
477+
cgh.single_task<TestKernel<>>([]() {});
478478
});
479479

480480
// Add independent node
@@ -484,7 +484,7 @@ TEST_F(CommandGraphTest, Finalize) {
484484
// Add a node that depends on Node1 due to the accessor
485485
auto Node3 = Graph.add([&](sycl::handler &cgh) {
486486
sycl::accessor A(Buf, cgh, sycl::write_only, sycl::no_init);
487-
cgh.single_task<class TestKernel2>([=]() { A[0] = 3; });
487+
cgh.single_task<TestKernel<>>([]() {});
488488
});
489489

490490
// Guarantee order of independent nodes 1 and 2

sycl/unittests/helpers/PiMockPlugin.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ inline pi_result mock_piDeviceGetInfo(pi_device device,
163163
size_t *param_value_size_ret) {
164164
constexpr char MockDeviceName[] = "Mock device";
165165
constexpr char MockSupportedExtensions[] =
166-
"cl_khr_fp64 cl_khr_fp16 cl_khr_il_program";
166+
"cl_khr_fp64 cl_khr_fp16 cl_khr_il_program ur_exp_command_buffer";
167167
switch (param_name) {
168168
case PI_DEVICE_INFO_TYPE: {
169169
// Act like any device is a GPU.

0 commit comments

Comments
 (0)