Welcome back to the oneAPI channel.
I have the latest Xeon machine or a new accelerator, Am I getting 100% of the potential?
Can I make my program run faster?
Is there an easy way for me to Exploit more parallelism?
And how difficult is it to program all of this?
Well, it’s easier than you think..
Let me tell you about oneTBB, oneAPI Threading Building Blocks
oneTBB is a natural and flexible way for C++ programmers to express parallelism on the
CPU
I think this figure behind me tell the whole story.
The performance scaling with multiple threads, not far from the theoretical limit, that you
see here, is very difficult to achieve
In previous videos we have talked about the oneAPI components.
We mentioned the multi-device multi-vendor open spec libraries..
One of them is the oneTBB..
The oneAPI Threading Building blocks
oneTBB is targeted to work on CPU but it can facilitate the work with other devices,
oneTBB library provides interfaces, functions and classes for thread parallelism
You can just use these ready templates for doing so,
Here’s a simple example.
I have a loop And another internal nested loop
To do something This code is implicitly parallel because there
are no dependencies between the iterations and the Complex-function has no side effects,
meaning it is thread-safe
Let’s assume I’d like to optimize the external loop.
All I have to do is to use the oneTBB parallel loop
So I can use oneTBB parallel_for to express this parallel algorithm
And inside the parallel-for we have a C++ lambda function.
So now each of the iterations could be theoretically executed in a different thread..
In parallel To be scheduled and managed by the run-time..
Parallal_for is one example of generic parallel algorithms included in TBB but there are many
more You can create flow graphs, pipelines, queues,
hash tables and more.
And this is why oneTBB was chosen to be the default threading model
for Intel’s implementations of DPC++, oneDPL, oneDAL, oneMKL, oneDNN, oneVPL and more
So if you are using one of these libraries you are already enjoying oneTBB.
But you can also use it directly.
If you navigate to oneapi.com you can find the full spec of oneAPI
Here is the oneTBB spec.
You can find here all the explanations on the various interfaces,
If you google oneTBB, you can get to the github
page and find the open source implementation Or you could jump to the intel implementation
of oneTBB to get the programming guide to get you started.
And maybe the easiest way to get started is to run a code sample on the intel devcloud.
I’m looking for the oneAPI dev-cloud Get-started
And I’m interested in the Base toolkit, which has the oneTBB inside
Just follow the instructions, it’s a very
simple installation.
And then connection using SSH Just choose your preferred way to connect
I’m getting a terminal
Navigate to the samples directory I’ll take a look at the tbb-task-sycl example,
I’ll leave you the link in a minute
This is the sample page And I’ll follow the instructions to build
it, And to run the sample…
We are basically generating a new vector from
a combination of two other vectors.
And it is running on the CPU and in parallel on the GPU and we can compare the results.
The TBB code is executed on the host, it is built on C++ 11,
So it works seamlessly with DPC++ code SYCL and many others, as you can see in the sample
code.
In addition, there are mechanisms to synchronize tasks offloaded to the accelerators, in this
example you can see how we offload a task to the GPU
So in this example we have a CPU, the host and an accelerator, a GPU
The main function is running on the CPU.
You can see that we are launching two tasks to run
TBB is managing the tasks asynchronously, we just have to wait for them to finish
The first task is running on the CPU, And you can see that this task is also using
TBB parallel-loop for its execution.
The second task is a SYCL code running mostly on the CPU,
And you can see that it is also using parallel-for
But inside that parallel-for, the kernel function is running on the GPU
So you could see here oneTBB working in 3 levels,
First, the flow graph of the full program Second, the parallel-loops inside the CPU
And third, the handling of the offloading to the accelerator.
oneTBB, one of the foundations of oneAPI libraries and APIs and a stand alone mechanism to parallelize
and scale your code.
There are lots of information and tutorials online,
And you can download for free this excellent book and read the relevant chapter..
Enjoy Thnx you