Skip to content

Commit 499f0bc

Browse files
committed
[SYCL] Update to execute graph through the handler
Will require reble/llvm#42 to be encorporated into the `sycl-graphs-record-and-replay` branch to work Also added a new test `graph_record_queue_shortcuts.cpp` to test the various graph execution queue shortcuts.
1 parent 48da3bd commit 499f0bc

19 files changed

+107
-41
lines changed

SYCL/CommandGraph/graph_finalize_empty.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ int main() {
1818
graph;
1919
auto graphExec = graph.finalize(testQueue.get_context());
2020

21-
testQueue.submit(graphExec);
21+
testQueue.submit([&](handler &cgh) { cgh.exec_graph(graphExec); });
2222
testQueue.wait();
2323

2424
return 0;
25-
}
25+
}

SYCL/CommandGraph/graph_record_after_finalize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ int main() {
7373

7474
// Execute several iterations of the graph
7575
for (unsigned n = 0; n < iterations; n++) {
76-
testQueue.submit(graphExec);
76+
testQueue.submit([&](handler &cgh) { cgh.exec_graph(graphExec); });
7777
}
7878
// Execute the extended graph.
7979
for (unsigned n = 0; n < iterations; n++) {
80-
testQueue.submit(graphExecAdditional);
80+
testQueue.submit([&](handler &cgh) { cgh.exec_graph(graphExecAdditional); });
8181
}
8282
// Perform a wait on all graph submissions.
8383
testQueue.wait_and_throw();
@@ -88,4 +88,4 @@ int main() {
8888
failed |= referenceOut != dataOut;
8989

9090
return failed;
91-
}
91+
}

SYCL/CommandGraph/graph_record_after_use.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int main() {
5050
// Execute several iterations of the graph (first iteration has already run
5151
// before graph recording)
5252
for (unsigned n = 1; n < iterations; n++) {
53-
testQueue.submit(graphExec);
53+
testQueue.submit([&](handler &cgh) { cgh.exec_graph(graphExec); });
5454
}
5555
// Perform a wait on all graph submissions.
5656
testQueue.wait();
@@ -62,4 +62,4 @@ int main() {
6262
failed |= referenceC != dataC;
6363

6464
return failed;
65-
}
65+
}

SYCL/CommandGraph/graph_record_basic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int main() {
4646

4747
// Execute several iterations of the graph
4848
for (unsigned n = 0; n < iterations; n++) {
49-
testQueue.submit(graphExec);
49+
testQueue.submit([&](handler &cgh) { cgh.exec_graph(graphExec); });
5050
}
5151
// Perform a wait on all graph submissions.
5252
testQueue.wait();
@@ -58,4 +58,4 @@ int main() {
5858
failed |= referenceC != dataC;
5959

6060
return failed;
61-
}
61+
}

SYCL/CommandGraph/graph_record_basic_usm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int main() {
4949

5050
// Execute several iterations of the graph
5151
for (unsigned n = 0; n < iterations; n++) {
52-
testQueue.submit(graphExec);
52+
testQueue.submit([&](handler &cgh) { cgh.exec_graph(graphExec); });
5353
}
5454
// Perform a wait on all graph submissions.
5555
testQueue.wait();
@@ -69,4 +69,4 @@ int main() {
6969
failed |= referenceC != dataC;
7070

7171
return failed;
72-
}
72+
}

SYCL/CommandGraph/graph_record_double_buffer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ int main() {
6060
testQueue.end_recording();
6161

6262
for (size_t i = 0; i < iterations; i++) {
63-
testQueue.submit(execGraph);
63+
testQueue.submit([&](handler &cgh) { cgh.exec_graph(graphExec); });
6464
// Update to second set of buffers
6565
execGraph.update(graphUpdate);
66-
testQueue.submit(execGraph);
66+
testQueue.submit([&](handler &cgh) { cgh.exec_graph(graphExec); });
6767
// Reset back to original buffers
6868
execGraph.update(graph);
6969
}
@@ -81,4 +81,4 @@ int main() {
8181
failed |= referenceC2 != dataC2;
8282

8383
return failed;
84-
}
84+
}

SYCL/CommandGraph/graph_record_host_task.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int main() {
7878

7979
// Execute several iterations of the graph
8080
for (unsigned n = 0; n < iterations; n++) {
81-
testQueue.submit(graphExec);
81+
testQueue.submit([&](handler &cgh) { cgh.exec_graph(graphExec); });
8282
}
8383
// Perform a wait on all graph submissions.
8484
testQueue.wait();
@@ -88,4 +88,4 @@ int main() {
8888
failed |= referenceC != dataC;
8989

9090
return failed;
91-
}
91+
}

SYCL/CommandGraph/graph_record_multiple_exec_graphs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int main() {
5050
// before graph recording)
5151
for (unsigned n = 1; n < iterations; n++) {
5252
auto graphExec = graph.finalize(testQueue.get_context());
53-
testQueue.submit(graphExec);
53+
testQueue.submit([&](handler &cgh) { cgh.exec_graph(graphExec); });
5454
}
5555
// Perform a wait on all graph submissions.
5656
testQueue.wait();
@@ -62,4 +62,4 @@ int main() {
6262
failed |= referenceC != dataC;
6363

6464
return failed;
65-
}
65+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// REQUIRES: level_zero, gpu
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
5+
/** Tests queue shortcuts for executing a graph */
6+
7+
#include "graph_common.hpp"
8+
9+
using namespace sycl;
10+
11+
int main() {
12+
queue testQueue;
13+
14+
using T = int;
15+
16+
std::vector<T> dataA(size), dataB(size), dataC(size);
17+
18+
// Initialize the data
19+
std::iota(dataA.begin(), dataA.end(), 1);
20+
std::iota(dataB.begin(), dataB.end(), 10);
21+
std::iota(dataC.begin(), dataC.end(), 1000);
22+
23+
// Create reference data for output
24+
std::vector<T> referenceA(dataA), referenceB(dataB), referenceC(dataC);
25+
calculate_reference_data(iterations, size, referenceA, referenceB,
26+
referenceC);
27+
28+
{
29+
ext::oneapi::experimental::command_graph<
30+
ext::oneapi::experimental::graph_state::modifiable>
31+
graph;
32+
buffer<T> bufferA{dataA.data(), range<1>{dataA.size()}};
33+
buffer<T> bufferB{dataB.data(), range<1>{dataB.size()}};
34+
buffer<T> bufferC{dataC.data(), range<1>{dataC.size()}};
35+
36+
testQueue.begin_recording(graph);
37+
38+
// Record commands to graph
39+
40+
run_kernels(testQueue, size, bufferA, bufferB, bufferC);
41+
42+
testQueue.end_recording();
43+
auto graphExec = graph.finalize(testQueue.get_context());
44+
45+
// Execute several iterations of the graph using the different shortcuts
46+
event e = testQueue.exec_graph(graphExec);
47+
48+
assert(iterations > 2);
49+
const unsigned loop_iterations = iterations - 2;
50+
std::vector<event> events(loop_iterations);
51+
for (unsigned n = 0; n < loop_iterations; n++) {
52+
events[n] = testQueue.exec_graph(graphExec, e);
53+
}
54+
55+
testQueue.exec_graph(graphExec, events).wait();
56+
}
57+
58+
bool failed = false;
59+
failed |= referenceA != dataA;
60+
failed |= referenceB != dataB;
61+
failed |= referenceC != dataC;
62+
63+
return failed;
64+
}

SYCL/CommandGraph/graph_record_stream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ int main() {
4444

4545
auto graphExec = graph.finalize(testQueue.get_context());
4646

47-
testQueue.submit(graphExec);
47+
testQueue.submit([&](handler &cgh) { cgh.exec_graph(graphExec); });
4848

4949
// Perform a wait on all graph submissions.
5050
testQueue.wait();
5151
}
5252

5353
return 0;
54-
}
54+
}

0 commit comments

Comments
 (0)