Skip to content

Commit 3edf870

Browse files
author
Ewan Crawford
committed
Update get/setters to "index" rather than "cgf"
Also refine spec wording based on PR feedback
1 parent ae58d31 commit 3edf870

24 files changed

+165
-81
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_graph.asciidoc

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -562,17 +562,20 @@ public:
562562
command_graph<graph_state::modifiable> &graph,
563563
const std::vector<std::function<void(handler &)>>& cgfList);
564564
565-
size_t get_active_cgf() const;
566-
void set_active_cgf(size_t cgfIndex);
565+
size_t get_active_index() const;
566+
void set_active_index(size_t cgfIndex);
567567
};
568568
----
569569

570-
Dynamic command-groups can be added as nodes to a graph. They provide a mechanism that
571-
allows updating the command-group function of a node after the graph is finalized.
572-
There is always one command-group function in the dynamic command-group that is set
573-
as active. When a dynamic command-group node is executed, the kernel of the active
574-
command-group function will be run and all the other command-group functions in
575-
`cgfList` will be ignored.
570+
Dynamic command-groups can be added as nodes to a graph. They provide a
571+
mechanism that allows updating the command-group function of a node after the
572+
graph is finalized. There is always one command-group function in the dynamic
573+
command-group that is set as active, this is the kernel which will execute for
574+
the node when the graph is finalized into an executable state `command_graph`,
575+
and all the other command-group functions in `cgfList` will be ignored. The
576+
executable `command_graph` node can then be updated to a different kernel in
577+
`cgfList`, by selecting a new active index on the dynamic command-group object
578+
and calling the `update(node& node)` method on the executable `command_graph`.
576579

577580
The `dynamic_command_group` class provides the {crs}[common reference semantics].
578581

@@ -581,8 +584,9 @@ about updating command-groups.
581584

582585
===== Limitations
583586

584-
Dynamic command-groups can only be used to update kernels. Trying to update a command-group
585-
function that contains other operations will result in an error.
587+
Dynamic command-groups can only contain kernel operations. Trying to construct
588+
a dynamic command-group with functions that contain other operations will
589+
result in an error.
586590

587591
All the command-group functions in a dynamic command-group must have identical dependencies.
588592
It is not allowed for a dynamic command-group to have command-group functions that would
@@ -628,15 +632,15 @@ Exceptions:
628632
|
629633
[source,c++]
630634
----
631-
size_t get_active_cgf() const;
635+
size_t get_active_index() const;
632636
----
633637
|Returns the index of the currently active command-group function in this
634638
`dynamic_command_group`.
635639

636640
|
637641
[source,c++]
638642
----
639-
void set_active_cgf(size_t cgfIndex);
643+
void set_active_index(size_t cgfIndex);
640644
----
641645
| Sets the command-group function with index `cgfIndex` as active. The index of the
642646
command-group function in a `dynamic_command_group` is identical to its index in the
@@ -902,20 +906,22 @@ Command-group updates are performed by creating an instance of the
902906
`dynamic_command_group` class. A dynamic command-group is created with a modifiable
903907
state graph and a list of possible command-group functions. Command-group functions
904908
within a dynamic command-group can then be set to active by using the member function
905-
`dynamic_command_group::set_active_cgf()`.
909+
`dynamic_command_group::set_active_index()`.
906910

907911
Dynamic command-groups are compatible with dynamic parameters. This means that
908912
dynamic parameters can be used in command-group functions that are part of
909913
dynamic command-groups. Updates to such dynamic parameters will be reflected
910914
in the command-group functions once they are activated.
911915

912916
Note that the execution range is tied to the command-group, therefore updating
913-
the range of a node which uses a dynamic command-group shared by another node
914-
will also update the execution range of the nodes sharing the dynamic
915-
command-group. Activating a command-group with `set_active_cgf` to a
916-
command-group that previously had its execution range updated with
917-
`node::update_range()` or `node::update_nd_range()` will not reset the execution
918-
range to the original, but instead use the most recently updated value.
917+
the range of a node which uses a dynamic command-group will update the
918+
execution range of the currently active command-group. If the dynamic
919+
command-group is shared by another node, it will also update the execution
920+
range of the other nodes sharing that dynamic command-group. Activating a
921+
command-group with `set_active_index` to a command-group that previously had
922+
its execution range updated with `node::update_range()` or
923+
`node::update_nd_range()` will not reset the execution range to the original
924+
value, but instead use the most recently updated value.
919925

920926
====== Committing Updates
921927

sycl/doc/syclgraph/SYCLGraphUsageGuide.md

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -458,15 +458,19 @@ dynParamAccessor.update(bufferB.get_access());
458458
Example showing how a graph with a dynamic command group node can be updated.
459459

460460
```cpp
461+
...
462+
using namespace sycl;
463+
namespace sycl_ext = sycl::ext::oneapi::experimental;
464+
461465
queue Queue{};
462-
exp_ext::command_graph Graph{Queue.get_context(), Queue.get_device()};
466+
sycl_ext::command_graph Graph{Queue.get_context(), Queue.get_device()};
463467

464468
int *PtrA = malloc_device<int>(1024, Queue);
465-
int *PtrB = malloc_device<int>(1024, Queue);
469+
int *PtrB = malloc_device<int>(1024, Queue);
466470

467471
auto CgfA = [&](handler &cgh) {
468472
cgh.parallel_for(1024, [=](item<1> Item) {
469-
PtrA[Item.get_id()] = 1;
473+
PtrA[Item.get_id()] = 1;
470474
});
471475
};
472476

@@ -477,18 +481,18 @@ auto CgfB = [&](handler &cgh) {
477481
};
478482

479483
// Construct a dynamic command-group with CgfA as the active cgf (index 0).
480-
auto DynamicCG = exp_ext::dynamic_command_group(Graph, {CgfA, CgfB});
484+
auto DynamicCG = sycl_ext::dynamic_command_group(Graph, {CgfA, CgfB});
481485

482486
// Create a dynamic command-group graph node.
483487
auto DynamicCGNode = Graph.add(DynamicCG);
484488

485-
auto ExecGraph = Graph.finalize(exp_ext::property::graph::updatable{});
489+
auto ExecGraph = Graph.finalize(sycl_ext::property::graph::updatable{});
486490

487491
// The graph will execute CgfA.
488492
Queue.ext_oneapi_graph(ExecGraph).wait();
489493

490494
// Sets CgfB as active in the dynamic command-group (index 1).
491-
DynamicCG.set_active_cgf(1);
495+
DynamicCG.set_active_index(1);
492496

493497
// Calls update to update the executable graph node with the changes to DynamicCG.
494498
ExecGraph.update(DynamicCGNode);
@@ -503,45 +507,49 @@ Example showing how a graph with a dynamic command group that uses dynamic
503507
parameters in a node can be updated.
504508
505509
```cpp
506-
size_t n = 1024;
510+
...
511+
using namespace sycl;
512+
namespace sycl_ext = sycl::ext::oneapi::experimental;
513+
514+
size_t N = 1024;
507515
queue Queue{};
508-
auto myContext = Queue.get_context();
509-
auto myDevice = Queue.get_device();
510-
exp_ext::command_graph Graph{myContext, myDevice};
516+
auto MyContext = Queue.get_context();
517+
auto MyDevice = Queue.get_device();
518+
sycl_ext::command_graph Graph{MyContext, MyDevice};
511519
512-
int *PtrA = malloc_device<int>(n, Queue);
513-
int *PtrB = malloc_device<int>(n, Queue);
520+
int *PtrA = malloc_device<int>(N, Queue);
521+
int *PtrB = malloc_device<int>(N, Queue);
514522
515523
// Kernels loaded from kernel bundle
516-
const std::vector<kernel_id> builtinKernelIds =
517-
myDevice.get_info<info::device::built_in_kernel_ids>();
518-
kernel_bundle<bundle_state::executable> myBundle =
519-
get_kernel_bundle<sycl::bundle_state::executable>(myContext, { myDevice }, builtinKernelIds);
524+
const std::vector<kernel_id> BuiltinKernelIds =
525+
MyDevice.get_info<info::device::built_in_kernel_ids>();
526+
kernel_bundle<bundle_state::executable> MyBundle =
527+
get_kernel_bundle<sycl::bundle_state::executable>(MyContext, { MyDevice }, BuiltinKernelIds);
520528
521-
kernel builtinKernelA = myBundle.get_kernel(builtinKernelIds[0]);
522-
kernel builtinKernelB = myBundle.get_kernel(builtinKernelIds[1]);
529+
kernel BuiltinKernelA = MyBundle.get_kernel(BuiltinKernelIds[0]);
530+
kernel BuiltinKernelB = MyBundle.get_kernel(BuiltinKernelIds[1]);
523531
524532
// Create a dynamic parameter with an initial value of PtrA
525-
exp_ext::dynamic_parameter DynamicPointerArg{Graph, PtrA};
533+
sycl_ext::dynamic_parameter DynamicPointerArg{Graph, PtrA};
526534
527535
// Create command groups for both kernels which use DynamicPointerArg
528536
auto CgfA = [&](handler &cgh) {
529537
cgh.set_arg(0, DynamicPointerArg);
530-
cgh.parallel_for(range {n}, builtinKernelA);
538+
cgh.parallel_for(range {N}, BuiltinKernelA);
531539
};
532540
533541
auto CgfB = [&](handler &cgh) {
534542
cgh.set_arg(0, DynamicPointerArg);
535-
cgh.parallel_for(range {n / 2}, builtinKernelB);
543+
cgh.parallel_for(range {N / 2}, BuiltinKernelB);
536544
};
537545
538546
// Construct a dynamic command-group with CgfA as the active cgf (index 0).
539-
auto DynamicCG = exp_ext::dynamic_command_group(Graph, {CgfA, CgfB});
547+
auto DynamicCG = sycl_ext::dynamic_command_group(Graph, {CgfA, CgfB});
540548
541549
// Create a dynamic command-group graph node.
542550
auto DynamicCGNode = Graph.add(DynamicCG);
543551
544-
auto ExecGraph = Graph.finalize(exp_ext::property::graph::updatable{});
552+
auto ExecGraph = Graph.finalize(sycl_ext::property::graph::updatable{});
545553
546554
// The graph will execute CgfA with PtrA.
547555
Queue.ext_oneapi_graph(ExecGraph).wait();
@@ -550,7 +558,7 @@ Queue.ext_oneapi_graph(ExecGraph).wait();
550558
DynamicPointerArg.update(PtrB);
551559
552560
// Sets CgfB as active in the dynamic command-group (index 1).
553-
DynamicCG.set_active_cgf(1);
561+
DynamicCG.set_active_index(1);
554562
555563
// Calls update to update the executable graph node with the changes to
556564
// DynamicCG and DynamicPointerArg.

sycl/include/sycl/ext/oneapi/experimental/graph.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ class __SYCL_EXPORT dynamic_command_group {
223223
const command_graph<graph_state::modifiable> &Graph,
224224
const std::vector<std::function<void(handler &)>> &CGFList);
225225

226-
size_t get_active_cgf() const;
227-
void set_active_cgf(size_t Index);
226+
size_t get_active_index() const;
227+
void set_active_index(size_t Index);
228228

229229
private:
230230
template <class Obj>

sycl/source/detail/graph_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,10 +2075,10 @@ dynamic_command_group::dynamic_command_group(
20752075
impl->finalizeCGFList(CGFList);
20762076
}
20772077

2078-
size_t dynamic_command_group::get_active_cgf() const {
2078+
size_t dynamic_command_group::get_active_index() const {
20792079
return impl->getActiveIndex();
20802080
}
2081-
void dynamic_command_group::set_active_cgf(size_t Index) {
2081+
void dynamic_command_group::set_active_index(size_t Index) {
20822082
return impl->setActiveIndex(Index);
20832083
}
20842084
} // namespace experimental

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int main() {
4545
assert(HostData[i] == PatternA);
4646
}
4747

48-
DynamicCG.set_active_cgf(1);
48+
DynamicCG.set_active_index(1);
4949
ExecGraph.update(DynamicCGNode);
5050
Queue.ext_oneapi_graph(ExecGraph).wait();
5151

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int main() {
6060
assert(HostData[i] == Ref);
6161
}
6262

63-
DynamicCG.set_active_cgf(1);
63+
DynamicCG.set_active_index(1);
6464
ExecGraph.update(DynamicCGNode);
6565

6666
Queue.ext_oneapi_graph(ExecGraph).wait();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main() {
6969
assert(HostData[i] == (InitA + InitB + PatternA));
7070
}
7171

72-
DynamicCG.set_active_cgf(1);
72+
DynamicCG.set_active_index(1);
7373
ExecGraph.update(DynamicCGNode);
7474

7575
Queue.ext_oneapi_graph(ExecGraph).wait();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int main(int, char **argv) {
7373
assert(check_value(i, 0, HostDataB[i], "HostDataB"));
7474
}
7575

76-
DynamicCG.set_active_cgf(1);
76+
DynamicCG.set_active_index(1);
7777
ExecGraph.update(DynamicCGNode);
7878

7979
Queue.ext_oneapi_graph(ExecGraph).wait();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ int main() {
9090
// CHECK-SAME: .argIndex = 0
9191
// CHECK-SAME: .stype = UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_VALUE_ARG_DESC
9292
// CHECK-SAME: .argIndex = 1
93-
DynamicCG.set_active_cgf(1);
93+
DynamicCG.set_active_index(1);
9494
ExecGraph.update(DynamicCGNode);
9595
Queue.ext_oneapi_graph(ExecGraph).wait();
9696
Queue.copy(Ptr, HostData.data(), Size).wait();
@@ -107,7 +107,7 @@ int main() {
107107
// CHECK-SAME: .numNewValueArgs = 0
108108
// CHECK-SAME: .stype = UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_POINTER_ARG_DESC
109109
// CHECK-SAME: .argIndex = 0
110-
DynamicCG.set_active_cgf(2);
110+
DynamicCG.set_active_index(2);
111111
ExecGraph.update(DynamicCGNode);
112112
Queue.ext_oneapi_graph(ExecGraph).wait();
113113
Queue.copy(Ptr, HostData.data(), Size).wait();
@@ -130,7 +130,7 @@ int main() {
130130
// CHECK-SAME: .argIndex = 2
131131
// CHECK-SAME: .stype = UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_VALUE_ARG_DESC
132132
// CHECK-SAME: .argIndex = 3
133-
DynamicCG.set_active_cgf(3);
133+
DynamicCG.set_active_index(3);
134134
ExecGraph.update(DynamicCGNode);
135135
Queue.ext_oneapi_graph(ExecGraph).wait();
136136
Queue.copy(Ptr, HostData.data(), Size).wait();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int main() {
5252
assert(HostData[i] == PatternA * PatternB);
5353
}
5454

55-
DynamicCG.set_active_cgf(1);
55+
DynamicCG.set_active_index(1);
5656
ExecGraph.update(DynamicCGNode);
5757

5858
Queue.ext_oneapi_graph(ExecGraph).wait();

0 commit comments

Comments
 (0)