Executing Kernels on the Device - 2022.1 English

Vitis Unified Software Platform Documentation: Application Acceleration Development (UG1393)

Document ID
UG1393
Release Date
2022-05-25
Version
2022.1 English

The execution of a kernel is associated with a class called xrt::run that implements methods to start and wait for kernel execution. Most interaction with kernel objects are accomplished through xrt::run objects, created from a kernel to represent an execution of the kernel.

The run object can be explicitly constructed from a kernel object, or implicitly constructed by starting a kernel execution as shown below.

std::cout << "Execution of the kernel\n";
auto run = krnl(bo0, bo1, bo_out, DATA_SIZE);
run.wait();

The above code example demonstrates launching the kernel execution using the xrt::kernel() operator with the list of arguments for the kernel that returns an xrt::run object. This is an asynchronous operator that returns after starting the run. The xrt::run::wait() member function is used to block the current thread until the run is complete.

Tip: Upon finishing the kernel execution, the xrt::run object can be used to relaunch the same kernel function if desired.
An alternative approach to run the kernel is shown in the code below:
auto run = xrt::run(krnl);
run.set_arg(0,bo0); // Arguments are specified starting from 0
run.set_arg(0,bo1); 
run.set_arg(0,bo_out); 
run.start();
run.wait();

In this example, the run object is explicitly constructed from the kernel object, the kernel arguments are specified with run.set_args(), and the run execution is launched by the run.start() command. Finally, the current thread is blocked as it waits for the kernel to finish.

After the kernel has completed its execution, you can sync the kernel results back to the host application using code similar to the following example:

// Get the output;
bo_out.sync(XCL_BO_SYNC_BO_FROM_DEVICE);

// Validate our results
if (std::memcmp(bo_out_map, bufReference, DATA_SIZE))
   throw std::runtime_error("Value read back does not match reference");