Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Host Setup and SYCL Queue

This exercise is a slightly modified version of the vector addition we did in the previous example. You are going to take over in this one and complete the code for this application by yourself. Instructions are provided on each step of completion, so you should be able to do it. Let's begin.

By now, you should know that you need to include the SYCL header file in order to use SYCL in your application. It is already included at the top of the source file - #include <CL/sycl.hpp>.

Host Setup


The first step is to initialize the vector data on the host.

We will be using:


which is a type alias for

cl::sycl::vec<float, 4>

It is a SYCL type struct that provides OpenCL vector functionality for host and device.


Define 2 input vectors and 1 output vector.


  • vector a: {1.0, 1.0, 1.0, 1.0}
  • vector b: {1.0, 1.0, 1.0, 1.0}


  • vector c: {0.0, 0.0, 0.0, 0.0}

Location in the source code:

// <<Setup host memory>>

sycl::float4 a = { 1.0f, 1.0f, 1.0f, 1.0f }; // input 1

Initialize SYCL Queue


SYCL queue is constructed from the selection of a supported device.

The system is set to always force the execution of the SYCL examples on the CPU device. Thus, the default selector will select the CPU because of its heuristics to identify the supported platforms and device on our system.


Initialize a SYCL queue with either a CPU or default device selector.

Location in the source code:

// <<Setup SYCL queue>>

sycl::queue myQueue(sycl::default_selector{}); 
// explicitly target the CPU: sycl::cpu_selector{}

Run it!

Hello World from SYCL
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content