I'm not sure this question is correctly formulated, I'm still learning.
I was wondering if there is a way, when I run a sycl program with a cpu_selector
to get if I'm using it as single core or multi core
Asked
Active
Viewed 317 times
1 Answers
2
This is sort of possible using sycl::info::device::max_compute_units
. Here's a minimal example:
#include <CL/sycl.hpp>
#include <iostream>
int main(){
sycl::device d = sycl::cpu_selector().select_device();
std::cout << d.get_info<sycl::info::device::max_compute_units>() << std::endl;
}
On my machine (which has 8 physical cores & 16 hardware threads), this returns 16
.
I think it is generally true that OpenCL considers hardware threads to be 'compute units', but I can't confirm this. Furthermore, it'll only tell you how many hardware threads the OpenCL backend considers are present, not how many you are using.
Edit for follow up question:
I think the OpenCL backend will always use all available resources. However, if you're working on a CPU, you can limit available threads using taskset
. For example, if I set the mask to use only thread 0:
taskset 0x00000001 ./a.out
I get the answer 1
.

Joe Todd
- 814
- 6
- 13
-
Thanks a lot for your answer. So if I'm benchmarking some sycl code to compare the performances on CPU vs GPU vs iGPU there's no way to know how many CPU threads I'm using (or even choosing how many up to hardware_concurrency) ? – Elle Jun 08 '22 at 13:38
-
I've edited my answer to answer this. Perhaps you could add this to your original question so my answer makes more sense? – Joe Todd Jun 09 '22 at 09:56