Community
cancel
Showing results for 
Search instead for 
Did you mean: 
eug
Beginner
390 Views

Parallel_for with single thread

Jump to solution

Hello, 

I'd like to know if there is a way to execute a parallel_for kernel with a single thread in the case of cpu device, or in general if it was possible to specify the degree of parallelism.

Thanks

0 Kudos
1 Solution
GouthamK_Intel
Moderator
295 Views

Hi,

--" Is it possible to set the number of actual cpu threads/core on which these work-item will be executed?"


yes, it is possible to set the number of CPU cores to be used for kernel execution. Export the below mentioned environmental variable and launch your application.


export DPCPP_CPU_NUM_CUS=<no. of CPU core to be used>

> export DPCPP_CPU_NUM_CUS=5


Please refer to the below developer guide for more details. Check the flags under DPC++ Environment Variables Section at the end.

https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-oneapi-dev-guide-and...


Please let us know if the provided information helped.


Thanks & Regards

Goutham


View solution in original post

8 Replies
GouthamK_Intel
Moderator
370 Views

Hi,

In SYCL, kernels can be invoked using either of the below SYCL functions.

·      single_task

·      parallel_for

·      parallel_for_work_group

 

As per the query which you have asked, i.e “I'd like to know if there is a way to execute a parallel_for kernel with a single thread”.

Yes, it is very much possible to execute a kernel with a single instance. You can do it using either one of the following methods.

1. Using single_task: Only one instance of the kernel will be executed with a single work item.

myQueue.submit([&](handler & cgh) {
 cgh.single_task<class kernel_name>([=] () {
       // [kernel code]
 });
 });

 

2. Using parallel_for: Execute a kernel in parallel across a range of specified processing elements.

myQueue.submit([&](handler & cgh) {
 cgh.parallel_for<class myKernel>(range<1>(numWorkItems),[=](id<1> myID) {
       //[kernel code]
 });
 });

Here, if you want to invoke the kernel with only one thread then specify the numWorkItems=1

 

You can refer to the below oneapi-programming guide for more information.

https://software.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/onea...

 

And, regarding “in general if it was possible to specify the degree of parallelism”. Could you please elaborate on what exactly you are looking for?

 

Regards

Goutham

eug
Beginner
365 Views

What I mean is: I have my kernel with a certain range (greater than 1) that is executed on cpu device. Is it possible to set the number of actual cpu threads/core on which these work-item will be executed? For example, if I have a cpu with 12 threads, can I specify to use only 1 thread or 4 threads ( or in general n of these threads) to execute my kernel? Something like "tbb::global_control::max_allowed_parallelism" of TBB but that works also in the "parallel_for" case.

GouthamK_Intel
Moderator
333 Views

Hi,

Apologies for the delay!

We are looking into your query with the internal engineering team. We will get back to you soon.


Thanks & Regards

Goutham


GouthamK_Intel
Moderator
296 Views

Hi,

--" Is it possible to set the number of actual cpu threads/core on which these work-item will be executed?"


yes, it is possible to set the number of CPU cores to be used for kernel execution. Export the below mentioned environmental variable and launch your application.


export DPCPP_CPU_NUM_CUS=<no. of CPU core to be used>

> export DPCPP_CPU_NUM_CUS=5


Please refer to the below developer guide for more details. Check the flags under DPC++ Environment Variables Section at the end.

https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-oneapi-dev-guide-and...


Please let us know if the provided information helped.


Thanks & Regards

Goutham


View solution in original post

eug
Beginner
287 Views

Yes, this solve my problem.

Thank you.

GouthamK_Intel
Moderator
274 Views

Hi,

Glad to know that your issue is resolved!

Could you please confirm, if we can close this thread from our side?


Regards

Goutham


eug
Beginner
270 Views

Yes, you can close it.

Thank you.

RahulV_intel
Moderator
248 Views

Thanks for the confirmation.


Intel will no longer monitor this thread. However, it will remain open, to allow community members to participate.


Reply