Welcome back to the oneAPI channel.​
In previous video we’ve seen how to ​
detect which platforms exist in my system and which devices are there in each platform​
But how do you actually submit and execute work on these devices?​
How do you exchange data so the host and the device can see the same data or the same memory
space?
In previous video, we chose the device we’d like to use.​
And we assigned a Q to this device using a pre-defined selector​
For example a host-selector
Or a GPU selector​
And you can even build a custom selector
So let’s take a Q, just give me the default device
And now, I can submit work to this Q.​
I’m getting a handler, which I call it here H​
But what I want is to manipulate data, I need data structures or memory accesses that are
coherent to the device and the host.​
There are several ways to exchange data between devices in SYCL
​
Assigning a buffer is one way.​
Here we construct a buffer called A, of 10 integers.​
This buffer is still on the host memory and will be shared with the device only per need..
​
And we got an accessor to Buffer A, with the handler h, ​
Accessor can be write only, read only, and other types ​
I don’t specify the mode, so the default is read-write
And now we are using the handler to dispatch some work​
Here it is a single-task, so only a single instance of this function will be executed
on the device​
I’ll show you in a minute how to run multiple, parallel tasks..
And I’m doing somthing..
Here I’m assigning 5 to the accessor 3rd entry​
This line will be executed on the device,
Now we need to copy back the buffer A from the device to the host, I copied it to an
array called result…​
And we are all done.​
Let’s see it in action
So I’m using SYCL​
I have a Q​
A is a buffer of 10 integers​
And I submit this to the Q.​
A_accessor will access buffer A on h handler, for write-only​
That will assign 5 to the 3rd entry of A​
​
And here I copy the A buffer back to the host into “result”​
And I just print out the results ​
And I’m getting the result, only the 3rd entry is 5​
OK We got heterogenous programming,​
Most of the code executed on the host and some is offloaded to the device​
Now lets make it more interesting..​
After all we are talking about heterogeneous and parallel computing..​
Let’s define a range, ​
A is still a buffer of range, or 10 integers​
A-accessor is still accessing A​
But instead of single task, where only a single execution is done on the device​
We will run parallel-for​
So every iteration of this lambda function could run in parallel​
We need to specify the range​
And we also need the index of the item​
And let’s do something more interesting​
Each entry will have the index number​
Copy the results back to the host and print it out​
And yes, we are getting the expected results..​
Each of the iteration of the lambda function ran independently in parallel,​
And could easily be ran on any device…​
So heterogenous, and parallel and portable.​
So choose a device, construct a Q, use buffers to exchange data​
And submit work to the device..​
There are of course many other things to talk about..​
See you next video​