Skip to content

Commit 6655435

Browse files
committed
Add example using dynamic CGF and parameters together
1 parent 119ba28 commit 6655435

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

sycl/doc/syclgraph/SYCLGraphUsageGuide.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,67 @@ ExecGraph.update(DynamicCGNode);
497497
Queue.ext_oneapi_graph(ExecGraph).wait();
498498
```
499499
500+
### Dynamic Command Groups With Dynamic Parameters
501+
502+
Example showing how a graph with a dynamic command group that uses dynamic
503+
parameters in a node can be updated.
504+
505+
```cpp
506+
size_t n = 1024;
507+
queue Queue{};
508+
exp_ext::command_graph Graph{Queue.get_context(), Queue.get_device()};
509+
510+
int *PtrA = malloc_device<int>(n, Queue);
511+
int *PtrB = malloc_device<int>(n, Queue)​;
512+
513+
// Kernels loaded from kernel bundle
514+
const std::vector<kernel_id> builtinKernelIds =
515+
myDevice.get_info<info::device::built_in_kernel_ids>();
516+
kernel_bundle<bundle_state::executable> myBundle =
517+
get_kernel_bundle(myContext, { myDevice }, builtinKernelIds);
518+
519+
kernel builtinKernelA = myBundle.get_kernel(builtinKernelIds[0]);
520+
kernel builtinKernelB = myBundle.get_kernel(builtinKernelIds[1]);
521+
522+
// Create a dynamic parameter with an initial value of PtrA
523+
exp_ext::dynamic_parameter DynamicPointerArg{Graph, PtrA};
524+
525+
// Create command groups for both kernels which use DynamicPointerArg
526+
auto CgfA = [&](handler &cgh) {
527+
cgh.set_arg(0, DynamicPointerArg);
528+
cgh.parallel_for(range {n}, builtinKernelA);
529+
};
530+
531+
auto CgfB = [&](handler &cgh) {
532+
cgh.set_arg(0, DynamicPointerArg);
533+
cgh.parallel_for(range {n / 2}, builtinKernelB);
534+
};
535+
536+
// Construct a dynamic command-group with CgfA as the active cgf (index 0).
537+
auto DynamicCG = exp_ext::dynamic_command_group(Graph, {CgfA, CgfB});
538+
539+
// Create a dynamic command-group graph node.
540+
auto DynamicCGNode = Graph.add(DynamicCG);
541+
542+
auto ExecGraph = Graph.finalize(exp_ext::property::graph::updatable{});
543+
544+
// The graph will execute CgfA with PtrA.
545+
Queue.ext_oneapi_graph(ExecGraph).wait();
546+
547+
//Update DynamicPointerArg with a new value
548+
DynamicPointerArg.update(PtrB);
549+
550+
// Sets CgfB as active in the dynamic command-group (index 1).
551+
DynamicCG.set_active_cgf(1);
552+
553+
// Calls update to update the executable graph node with the changes to
554+
// DynamicCG and DynamicPointerArg.
555+
ExecGraph.update(DynamicCGNode);
556+
557+
// The graph will execute CgfB with PtrB.
558+
Queue.ext_oneapi_graph(ExecGraph).wait();
559+
```
560+
500561
### Whole Graph Update
501562

502563
Example that shows recording and updating several nodes with different

0 commit comments

Comments
 (0)