Skip to content

Commit 89193f0

Browse files
author
Ewan Crawford
committed
Reintroduce unittest for range update errors
1 parent e78f249 commit 89193f0

23 files changed

+274
-239
lines changed

sycl/doc/design/CommandGraph.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,17 @@ from a `std::unique_ptr` to a `std::shared_ptr` so that multiple nodes and the
291291
the overhead of having to allocate and free copies of the CG when a new active
292292
CG is selected.
293293

294-
The `dynamic_command_group_impl` class contains weak pointers to the nodes which
295-
have been created with it, so that when a new active CG is selected it can
296-
propagate the change to those nodes. The `node_impl` class also contains a
297-
reference to the dynamic command-group that created it, so that when the graph
298-
is finalized each node can use the list of kernels in its dynamic command-group
299-
as part of the `urCommandBufferAppendKernelLaunchExp` call to pass the possible
300-
alternative kernels.
294+
The `dynamic_command_group_impl` class contains a list of weak pointers to the
295+
nodes which have been created with it, so that when a new active CG is selected
296+
it can propagate the change to those nodes. The `dynamic_parameter_impl` class
297+
also contains a list of weak pointers, but to the `dynamic_command_group_impl`
298+
instances of any dynamic command-groups where they are used. This allows
299+
updating the dynamic parameter to propagate to dynamic command-group nodes.
301300

302301
The `sycl::detail::CGExecKernel` class has been added to, so that if the
303302
object was created from an element in the dynamic command-group list, the class
304303
stores a vector of weak pointers to the other alternative command-groups created
305-
from the same dynamic command-group object. This allows the DPC++ scheduler to
304+
from the same dynamic command-group object. This allows the SYCL runtime to
306305
access the list of alternative kernels when calling the UR API to append a
307306
kernel command to a command-buffer.
308307

sycl/source/detail/graph_impl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ graph_impl::add(std::shared_ptr<dynamic_command_group_impl> &DynCGImpl,
562562

563563
// Track the dynamic command-group used inside the node object
564564
DynCGImpl->MNodes.push_back(NodeImpl);
565-
NodeImpl->MDynCG = DynCGImpl;
566565

567566
return NodeImpl;
568567
}

sycl/source/detail/graph_impl.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
9999
/// Stores the executable graph impl associated with this node if it is a
100100
/// subgraph node.
101101
std::shared_ptr<exec_graph_impl> MSubGraphImpl;
102-
/// Dynamic command-group object used in node, if any.
103-
std::shared_ptr<dynamic_command_group_impl> MDynCG;
104102

105103
/// Used for tracking visited status during cycle checks.
106104
bool MVisited = false;
@@ -158,7 +156,7 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
158156
: enable_shared_from_this(Other), MSuccessors(Other.MSuccessors),
159157
MPredecessors(Other.MPredecessors), MCGType(Other.MCGType),
160158
MNodeType(Other.MNodeType), MCommandGroup(Other.getCGCopy()),
161-
MSubGraphImpl(Other.MSubGraphImpl), MDynCG(Other.MDynCG) {}
159+
MSubGraphImpl(Other.MSubGraphImpl) {}
162160

163161
/// Copy-assignment operator. This will perform a deep-copy of the
164162
/// command group object associated with this node.
@@ -170,7 +168,6 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
170168
MNodeType = Other.MNodeType;
171169
MCommandGroup = Other.getCGCopy();
172170
MSubGraphImpl = Other.MSubGraphImpl;
173-
MDynCG = Other.MDynCG;
174171
}
175172
return *this;
176173
}
@@ -420,7 +417,7 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
420417
throw sycl::exception(sycl::errc::invalid,
421418
"Cannot update execution range of a node with an "
422419
"execution range of different dimensions than what "
423-
"the node was originall created with.");
420+
"the node was original created with.");
424421
}
425422

426423
NDRDesc = sycl::detail::NDRDescT{ExecutionRange};
@@ -441,7 +438,7 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
441438
throw sycl::exception(sycl::errc::invalid,
442439
"Cannot update execution range of a node with an "
443440
"execution range of different dimensions than what "
444-
"the node was originall created with.");
441+
"the node was original created with.");
445442
}
446443

447444
NDRDesc = sycl::detail::NDRDescT{ExecutionRange};

sycl/test-e2e/Graph/Update/dyn_cgf_accessor.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414

1515
int main() {
1616
queue Queue{};
17-
const size_t N = 1024;
18-
std::vector<int> HostData(N, 0);
19-
buffer Buf{HostData};
17+
buffer<int> Buf{sycl::range<1>(Size)};
2018
Buf.set_write_back(false);
2119
auto Acc = Buf.get_access();
2220

@@ -28,22 +26,25 @@ int main() {
2826
int PatternA = 42;
2927
auto CGFA = [&](handler &CGH) {
3028
CGH.require(Acc);
31-
CGH.parallel_for(N, [=](item<1> Item) { Acc[Item.get_id()] = PatternA; });
29+
CGH.parallel_for(Size,
30+
[=](item<1> Item) { Acc[Item.get_id()] = PatternA; });
3231
};
3332

3433
int PatternB = 0xA;
3534
auto CGFB = [&](handler &CGH) {
3635
CGH.require(Acc);
37-
CGH.parallel_for(N, [=](item<1> Item) { Acc[Item.get_id()] = PatternB; });
36+
CGH.parallel_for(Size,
37+
[=](item<1> Item) { Acc[Item.get_id()] = PatternB; });
3838
};
3939

4040
auto DynamicCG = exp_ext::dynamic_command_group(Graph, {CGFA, CGFB});
4141
auto DynamicCGNode = Graph.add(DynamicCG);
4242
auto ExecGraph = Graph.finalize(exp_ext::property::graph::updatable{});
4343

4444
Queue.ext_oneapi_graph(ExecGraph).wait();
45+
std::vector<int> HostData(Size, 0);
4546
Queue.copy(Acc, HostData.data()).wait();
46-
for (size_t i = 0; i < N; i++) {
47+
for (size_t i = 0; i < Size; i++) {
4748
assert(HostData[i] == PatternA);
4849
}
4950

@@ -52,7 +53,7 @@ int main() {
5253
Queue.ext_oneapi_graph(ExecGraph).wait();
5354

5455
Queue.copy(Acc, HostData.data()).wait();
55-
for (size_t i = 0; i < N; i++) {
56+
for (size_t i = 0; i < Size; i++) {
5657
assert(HostData[i] == PatternB);
5758
}
5859

sycl/test-e2e/Graph/Update/dyn_cgf_accessor_deps.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515

1616
int main() {
1717
queue Queue{};
18-
const size_t N = 1024;
19-
int *Ptr = (int *)sycl::malloc_device<int>(N, Queue);
20-
std::vector<int> HostData(N, 0);
21-
buffer Buf{HostData};
18+
int *Ptr = (int *)sycl::malloc_device<int>(Size, Queue);
19+
buffer<int> Buf{sycl::range<1>(Size)};
2220
Buf.set_write_back(false);
2321

2422
exp_ext::command_graph Graph{
@@ -28,19 +26,21 @@ int main() {
2826

2927
auto RootNode = Graph.add([&](handler &CGH) {
3028
auto Acc = Buf.get_access<access::mode::write>(CGH);
31-
CGH.parallel_for(N, [=](item<1> Item) { Acc[Item.get_id()] = 1; });
29+
CGH.parallel_for(Size, [=](item<1> Item) { Acc[Item.get_id()] = 1; });
3230
});
3331

3432
int PatternA = 42;
3533
auto CGFA = [&](handler &CGH) {
3634
auto Acc = Buf.get_access<access::mode::read_write>(CGH);
37-
CGH.parallel_for(N, [=](item<1> Item) { Acc[Item.get_id()] += PatternA; });
35+
CGH.parallel_for(Size,
36+
[=](item<1> Item) { Acc[Item.get_id()] += PatternA; });
3837
};
3938

4039
int PatternB = 0xA;
4140
auto CGFB = [&](handler &CGH) {
4241
auto Acc = Buf.get_access<access::mode::read_write>(CGH);
43-
CGH.parallel_for(N, [=](item<1> Item) { Acc[Item.get_id()] += PatternB; });
42+
CGH.parallel_for(Size,
43+
[=](item<1> Item) { Acc[Item.get_id()] += PatternB; });
4444
};
4545

4646
auto DynamicCG = exp_ext::dynamic_command_group(Graph, {CGFA, CGFB});
@@ -49,23 +49,28 @@ int main() {
4949
auto LeafNode = Graph.add([&](handler &CGH) {
5050
auto Acc = Buf.get_access<access::mode::read>(CGH);
5151
CGH.parallel_for(
52-
N, [=](item<1> Item) { Ptr[Item.get_id()] = Acc[Item.get_id()]; });
52+
Size, [=](item<1> Item) { Ptr[Item.get_id()] = Acc[Item.get_id()]; });
5353
});
5454
auto ExecGraph = Graph.finalize(exp_ext::property::graph::updatable{});
5555

5656
Queue.ext_oneapi_graph(ExecGraph).wait();
57-
Queue.copy(Ptr, HostData.data(), N).wait();
58-
for (size_t i = 0; i < N; i++) {
59-
assert(HostData[i] == (PatternA + 1));
57+
58+
std::vector<int> HostData(Size, 0);
59+
Queue.copy(Ptr, HostData.data(), Size).wait();
60+
61+
int Ref = PatternA + 1;
62+
for (size_t i = 0; i < Size; i++) {
63+
assert(HostData[i] == Ref);
6064
}
6165

6266
DynamicCG.set_active_cgf(1);
6367
ExecGraph.update(DynamicCGNode);
6468

6569
Queue.ext_oneapi_graph(ExecGraph).wait();
66-
Queue.copy(Ptr, HostData.data(), N).wait();
67-
for (size_t i = 0; i < N; i++) {
68-
assert(HostData[i] == (PatternB + 1));
70+
Queue.copy(Ptr, HostData.data(), Size).wait();
71+
Ref = PatternB + 1;
72+
for (size_t i = 0; i < Size; i++) {
73+
assert(HostData[i] == Ref);
6974
}
7075

7176
sycl::free(Ptr, Queue);

sycl/test-e2e/Graph/Update/dyn_cgf_accessor_deps2.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
int main() {
1818
queue Queue{};
19-
const size_t N = 1024;
20-
int *Ptr = (int *)sycl::malloc_device<int>(N, Queue);
21-
std::vector<int> HostData(N, 0);
22-
buffer<int> BufA{sycl::range<1>(N)};
23-
buffer<int> BufB{sycl::range<1>(N)};
19+
int *Ptr = (int *)sycl::malloc_device<int>(Size, Queue);
20+
buffer<int> BufA{sycl::range<1>(Size)};
21+
buffer<int> BufB{sycl::range<1>(Size)};
2422
BufA.set_write_back(false);
2523
BufB.set_write_back(false);
2624

@@ -34,7 +32,7 @@ int main() {
3432
auto RootNode = Graph.add([&](handler &CGH) {
3533
auto AccA = BufA.get_access<access::mode::write>(CGH);
3634
auto AccB = BufB.get_access<access::mode::write>(CGH);
37-
CGH.parallel_for(N, [=](item<1> Item) {
35+
CGH.parallel_for(Size, [=](item<1> Item) {
3836
AccA[Item.get_id()] = InitA;
3937
AccB[Item.get_id()] = InitB;
4038
});
@@ -43,13 +41,15 @@ int main() {
4341
int PatternA = 42;
4442
auto CGFA = [&](handler &CGH) {
4543
auto AccA = BufA.get_access<access::mode::read_write>(CGH);
46-
CGH.parallel_for(N, [=](item<1> Item) { AccA[Item.get_id()] += PatternA; });
44+
CGH.parallel_for(Size,
45+
[=](item<1> Item) { AccA[Item.get_id()] += PatternA; });
4746
};
4847

4948
int PatternB = 0xA;
5049
auto CGFB = [&](handler &CGH) {
5150
auto AccB = BufB.get_access<access::mode::read_write>(CGH);
52-
CGH.parallel_for(N, [=](item<1> Item) { AccB[Item.get_id()] += PatternB; });
51+
CGH.parallel_for(Size,
52+
[=](item<1> Item) { AccB[Item.get_id()] += PatternB; });
5353
};
5454

5555
auto DynamicCG = exp_ext::dynamic_command_group(Graph, {CGFA, CGFB});
@@ -58,25 +58,28 @@ int main() {
5858
auto LeafNode = Graph.add([&](handler &CGH) {
5959
auto AccA = BufA.get_access<access::mode::read>(CGH);
6060
auto AccB = BufB.get_access<access::mode::read>(CGH);
61-
CGH.parallel_for(N, [=](item<1> Item) {
61+
CGH.parallel_for(Size, [=](item<1> Item) {
6262
Ptr[Item.get_id()] = AccA[Item.get_id()] + AccB[Item.get_id()];
6363
});
6464
});
6565
auto ExecGraph = Graph.finalize(exp_ext::property::graph::updatable{});
6666

6767
Queue.ext_oneapi_graph(ExecGraph).wait();
68-
Queue.copy(Ptr, HostData.data(), N).wait();
69-
for (size_t i = 0; i < N; i++) {
68+
69+
std::vector<int> HostData(Size, 0);
70+
Queue.copy(Ptr, HostData.data(), Size).wait();
71+
for (size_t i = 0; i < Size; i++) {
7072
assert(HostData[i] == (InitA + InitB + PatternA));
7173
}
7274

7375
DynamicCG.set_active_cgf(1);
7476
ExecGraph.update(DynamicCGNode);
7577

7678
Queue.ext_oneapi_graph(ExecGraph).wait();
77-
Queue.copy(Ptr, HostData.data(), N).wait();
78-
for (size_t i = 0; i < N; i++) {
79-
assert(HostData[i] == (InitA + InitB + PatternB));
79+
Queue.copy(Ptr, HostData.data(), Size).wait();
80+
int Ref = InitA + InitB + PatternB;
81+
for (size_t i = 0; i < Size; i++) {
82+
assert(HostData[i] == Ref);
8083
}
8184

8285
sycl::free(Ptr, Queue);

sycl/test-e2e/Graph/Update/dyn_cgf_accessor_spv.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,13 @@ int main(int, char **argv) {
2626
kernel kernel = getKernel(
2727
KernelBundle, "_ZTSZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_EUlvE_");
2828

29-
const size_t N = 1024;
30-
3129
exp_ext::command_graph Graph{
3230
Queue.get_context(),
3331
Queue.get_device(),
3432
{exp_ext::property::graph::assume_buffer_outlives_graph{}}};
35-
std::vector<int> HostDataA(N, 0);
36-
std::vector<int> HostDataB(N, 0);
3733

38-
buffer BufA{HostDataA};
39-
buffer BufB{HostDataB};
34+
buffer<int> BufA{sycl::range<1>(Size)};
35+
buffer<int> BufB{sycl::range<1>(Size)};
4036
BufA.set_write_back(false);
4137
BufB.set_write_back(false);
4238

@@ -60,9 +56,12 @@ int main(int, char **argv) {
6056
auto ExecGraph = Graph.finalize(exp_ext::property::graph::updatable{});
6157

6258
Queue.ext_oneapi_graph(ExecGraph).wait();
59+
60+
std::vector<int> HostDataA(Size, 0);
61+
std::vector<int> HostDataB(Size, 0);
6362
Queue.copy(BufA.get_access(), HostDataA.data()).wait();
6463
Queue.copy(BufB.get_access(), HostDataB.data()).wait();
65-
for (size_t i = 0; i < N; i++) {
64+
for (size_t i = 0; i < Size; i++) {
6665
assert(HostDataA[i] == i);
6766
assert(HostDataB[i] == 0);
6867
}
@@ -71,9 +70,10 @@ int main(int, char **argv) {
7170
ExecGraph.update(DynamicCGNode);
7271

7372
Queue.ext_oneapi_graph(ExecGraph).wait();
73+
7474
Queue.copy(BufA.get_access(), HostDataA.data()).wait();
7575
Queue.copy(BufB.get_access(), HostDataB.data()).wait();
76-
for (size_t i = 0; i < N; i++) {
76+
for (size_t i = 0; i < Size; i++) {
7777
assert(HostDataA[i] == i);
7878
assert(HostDataB[i] == i);
7979
}

0 commit comments

Comments
 (0)