Intel® FPGA SDK for OpenCL™ Pro Edition: Best Practices Guide

ID 683521
Date 12/19/2022
Document Table of Contents

11.1. Multi-Threaded Host Application

When there are parallel, independent data paths and the host must process the data between kernel executions, consider using a multi-threaded host application.

The figure below illustrates how a single-threaded host application might process parallel, independent data paths between kernel executions:

Figure 90. Kernel Execution by a Single-Threaded Host Application

The OpenCL runtime is thread safe and supports multithreaded applications. Thus, you can perform work tasks on the host in parallel threads while still allowing those threads to access the OpenCL APIs in a thread-safe way.

However, thread safety is enforced at the OpenCL API boundary by synchronizing threads immediately after any OpenCL host API is called, which means, only one thread is ever active in the runtime while the other threads wait. As such, if one thread calls clFlinish on a queue full of work, another thread calling clSetKernelArg may have to wait for all of that work to complete before executing.

If possible, process data on CPU on multiple-threads, and use single dedicated thread to interact with the OpenCL API.

The figure below illustrates how a multi-threaded host application processes parallel, independent data paths between kernel executions:

Figure 91. Kernel Execution by a Multi-Threaded Host Application in a Thread-Safe Runtime Environment

Did you find the information on this page useful?

Characters remaining:

Feedback Message