Developer Guide

Intel® oneAPI DPC++/C++ Compiler Handbook for FPGAs

ID 785441
Date 10/24/2024
Public
Document Table of Contents

task_sequence Use Cases

Using a task_sequence in your kernel enables a variety of design structures that you can implement. Common uses for the task_sequence class include executing multiple loops in parallel, as described in the following section.

Executing Multiple Loops in Parallel

Using the task_sequence class, you can run sequential loops in a pipelined manner within the context of the loop nest.

For example, in the following code sample, the first and second loops cannot be executed in parallel by the same invocation of the kernel they are contained in:

// first loop
for (int i = 0; i < n; i++) {
  // Do something
}
// second loop
for (int i = 0; i < m; i++) { 
  // Do something else
}
// program scope
void firstLoop() {
  for (int i = 0; i < n; i++) {
    // Do something
  }
}
void secondLoop() {
  for (int i = 0; i < m; i++) {
    // Do something else
  }
}

// in kernel code
using namespace sycl::ext::intel::experimental;
task_sequence<firstLoop> firstTask;
task_sequence<secondLoop> secondTask;
firstTask.async();
secondTask.async();
firstTask.get();
secondTask.get();
TIP:

For additional information, refer to the Parallel Loops sample on GitHub.