Skip to content

Commit d2ff468

Browse files
authored
[SYCL] Improve Graphs testing
* Extend testing * Fix reduction test * Add test to verify node ordering * Update sycl include * Switch to assertions in graph tests * Formatting
1 parent 068dd95 commit d2ff468

8 files changed

+151
-31
lines changed

sycl/test/graph/graph-explicit-dotp.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2-
#include <CL/sycl.hpp>
32
#include <iostream>
3+
#include <sycl/sycl.hpp>
44

55
#include <sycl/ext/oneapi/experimental/graph.hpp>
66

@@ -83,16 +83,12 @@ int main() {
8383
// Using shortcut for executing a graph of commands
8484
q.ext_oneapi_graph(executable_graph).wait();
8585

86-
if (*dotp != host_gold_result()) {
87-
std::cout << "Error unexpected result!\n";
88-
}
86+
assert(*dotp == host_gold_result());
8987

9088
sycl::free(dotp, q);
9189
sycl::free(x, q);
9290
sycl::free(y, q);
9391
sycl::free(z, q);
9492

95-
std::cout << "done.\n";
96-
9793
return 0;
9894
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
#include <iostream>
3+
#include <sycl/sycl.hpp>
4+
5+
#include <sycl/ext/oneapi/experimental/graph.hpp>
6+
7+
int main() {
8+
9+
sycl::property_list properties{
10+
sycl::property::queue::in_order{},
11+
sycl::ext::oneapi::property::queue::lazy_execution{}};
12+
13+
sycl::queue q{sycl::gpu_selector_v, properties};
14+
15+
sycl::ext::oneapi::experimental::command_graph g;
16+
17+
const size_t n = 10;
18+
float *x = sycl::malloc_shared<float>(n, q);
19+
20+
auto init = g.add([&](sycl::handler &h) {
21+
h.parallel_for(sycl::range<1>{n}, [=](sycl::id<1> idx) {
22+
size_t i = idx;
23+
x[i] = 2.0f;
24+
});
25+
});
26+
27+
auto add = g.add([&](sycl::handler &h) {
28+
h.parallel_for(sycl::range<1>{n}, [=](sycl::id<1> idx) {
29+
size_t i = idx;
30+
x[i] += 2.0f;
31+
});
32+
});
33+
34+
auto mult = g.add([&](sycl::handler &h) {
35+
h.parallel_for(sycl::range<1>{n}, [=](sycl::id<1> idx) {
36+
size_t i = idx;
37+
x[i] *= 3.0f;
38+
});
39+
});
40+
41+
g.make_edge(init, mult);
42+
g.make_edge(mult, add);
43+
44+
auto executable_graph = g.finalize(q.get_context());
45+
46+
q.submit([&](sycl::handler &h) {
47+
h.ext_oneapi_graph(executable_graph);
48+
}).wait();
49+
50+
for (int i = 0; i < n; i++)
51+
assert(x[i] == 8.0f);
52+
53+
sycl::free(x, q);
54+
55+
return 0;
56+
}

sycl/test/graph/graph-explicit-queue-shortcuts.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2-
#include <CL/sycl.hpp>
32
#include <iostream>
3+
#include <sycl/sycl.hpp>
44

55
#include <sycl/ext/oneapi/experimental/graph.hpp>
66

@@ -33,9 +33,10 @@ int main() {
3333
auto e3 = q.ext_oneapi_graph(executable_graph, e1);
3434
q.ext_oneapi_graph(executable_graph, {e2, e3}).wait();
3535

36-
sycl::free(arr, q);
36+
for (int i = 0; i < n; i++)
37+
assert(arr[i] == 1);
3738

38-
std::cout << "done " << arr[0] << std::endl;
39+
sycl::free(arr, q);
3940

4041
return 0;
4142
}

sycl/test/graph/graph-explicit-reduction.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2-
#include <CL/sycl.hpp>
32
#include <iostream>
3+
#include <sycl/sycl.hpp>
44

55
#include <sycl/ext/oneapi/experimental/graph.hpp>
66

@@ -26,12 +26,13 @@ int main() {
2626
[=](sycl::id<1> idx, auto &sum) { sum += input[idx]; });
2727
});
2828

29-
e.wait();
29+
auto executable_graph = g.finalize(q.get_context());
30+
q.ext_oneapi_graph(executable_graph).wait();
31+
32+
assert(*output == 45);
3033

3134
sycl::free(input, q);
3235
sycl::free(output, q);
3336

34-
std::cout << "done\n";
35-
3637
return 0;
3738
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
#include <iostream>
3+
#include <sycl/sycl.hpp>
4+
5+
#include <sycl/ext/oneapi/experimental/graph.hpp>
6+
7+
int main() {
8+
9+
sycl::property_list properties{
10+
sycl::property::queue::in_order{},
11+
sycl::ext::oneapi::property::queue::lazy_execution{}};
12+
13+
sycl::queue q{sycl::gpu_selector_v, properties};
14+
15+
sycl::ext::oneapi::experimental::command_graph g;
16+
17+
const size_t n = 10;
18+
float *arr = sycl::malloc_shared<float>(n, q);
19+
for (int i = 0; i < n; i++) {
20+
arr[i] = 0;
21+
}
22+
23+
g.add([&](sycl::handler &h) {
24+
h.parallel_for(sycl::range<1>{n}, [=](sycl::id<1> idx) {
25+
size_t i = idx;
26+
arr[i] += 1;
27+
});
28+
});
29+
30+
bool check = true;
31+
for (int i = 0; i < n; i++) {
32+
if (arr[i] != 0)
33+
check = false;
34+
}
35+
36+
auto executable_graph = g.finalize(q.get_context());
37+
38+
for (int i = 0; i < n; i++) {
39+
if (arr[i] != 0)
40+
check = false;
41+
}
42+
43+
q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(executable_graph); });
44+
45+
for (int i = 0; i < n; i++) {
46+
if (arr[i] != 1)
47+
check = false;
48+
}
49+
50+
q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(executable_graph); });
51+
52+
for (int i = 0; i < n; i++)
53+
assert(arr[i] == 2);
54+
55+
sycl::free(arr, q);
56+
57+
return 0;
58+
}

sycl/test/graph/graph-explicit-saxpy.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2-
#include <sycl/sycl.hpp>
32
#include <iostream>
3+
#include <sycl/sycl.hpp>
44

55
#include <sycl/ext/oneapi/experimental/graph.hpp>
66

@@ -38,12 +38,15 @@ int main() {
3838

3939
auto executable_graph = g.finalize(q.get_context());
4040

41-
q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(executable_graph); }).wait();
41+
q.submit([&](sycl::handler &h) {
42+
h.ext_oneapi_graph(executable_graph);
43+
}).wait();
44+
45+
for (int i = 0; i < n; i++)
46+
assert(y[i] == 5.0f);
4247

4348
sycl::free(x, q);
4449
sycl::free(y, q);
4550

46-
std::cout << "done.\n";
47-
4851
return 0;
4952
}

sycl/test/graph/graph-explicit-single-node.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2-
#include <CL/sycl.hpp>
32
#include <iostream>
3+
#include <sycl/sycl.hpp>
44

55
#include <sycl/ext/oneapi/experimental/graph.hpp>
66

@@ -16,6 +16,9 @@ int main() {
1616

1717
const size_t n = 10;
1818
float *arr = sycl::malloc_shared<float>(n, q);
19+
for (int i = 0; i < n; i++) {
20+
arr[i] = 0;
21+
}
1922

2023
g.add([&](sycl::handler &h) {
2124
h.parallel_for(sycl::range<1>{n}, [=](sycl::id<1> idx) {
@@ -24,19 +27,25 @@ int main() {
2427
});
2528
});
2629

27-
auto result_before_exec1 = arr[0];
30+
bool check = true;
31+
for (int i = 0; i < n; i++) {
32+
if (arr[i] != 0)
33+
check = false;
34+
}
2835

2936
auto executable_graph = g.finalize(q.get_context());
3037

31-
auto result_before_exec2 = arr[0];
38+
for (int i = 0; i < n; i++) {
39+
if (arr[i] != 0)
40+
check = false;
41+
}
3242

3343
q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(executable_graph); });
3444

35-
auto result = arr[0];
45+
for (int i = 0; i < n; i++)
46+
assert(arr[i] == 1);
3647

3748
sycl::free(arr, q);
3849

39-
std::cout << "done.\n";
40-
4150
return 0;
4251
}

sycl/test/graph/graph-explicit-subgraph.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// Modified version of the dotp example which submits part of the graph as a
44
// sub-graph
5-
#include <CL/sycl.hpp>
65
#include <iostream>
6+
#include <sycl/sycl.hpp>
77

88
#include <sycl/ext/oneapi/experimental/graph.hpp>
99

@@ -70,7 +70,7 @@ int main() {
7070
auto subGraphExec = subGraph.finalize(q.get_context());
7171

7272
auto node_sub =
73-
g.add([&](sycl::handler &h) { h.exec_graph(subGraphExec); }, {n_i});
73+
g.add([&](sycl::handler &h) { h.ext_oneapi_graph(subGraphExec); }, {n_i});
7474

7575
auto node_c = g.add(
7676
[&](sycl::handler &h) {
@@ -86,18 +86,14 @@ int main() {
8686
auto executable_graph = g.finalize(q.get_context());
8787

8888
// Using shortcut for executing a graph of commands
89-
q.exec_graph(executable_graph).wait();
89+
q.ext_oneapi_graph(executable_graph).wait();
9090

91-
if (*dotp != host_gold_result()) {
92-
std::cout << "Error unexpected result!\n";
93-
}
91+
assert(*dotp == host_gold_result());
9492

9593
sycl::free(dotp, q);
9694
sycl::free(x, q);
9795
sycl::free(y, q);
9896
sycl::free(z, q);
9997

100-
std::cout << "done.\n";
101-
10298
return 0;
10399
}

0 commit comments

Comments
 (0)