Intel® oneAPI Base Toolkit
Support for the core tools and libraries within the base toolkit that are used to build and deploy high-performance data-centric applications.
419 Discussions

Parallel_for with single thread

eug
Beginner
2,054 Views

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
1,960 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-reference/top/compilation/supported-environment-variables.html


Please let us know if the provided information helped.


Thanks & Regards

Goutham


View solution in original post

0 Kudos
8 Replies
GouthamK_Intel
Moderator
2,034 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/oneapi-programming-model/kernel-programming-model/c-language-requirements.html

 

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

0 Kudos
eug
Beginner
2,029 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.

0 Kudos
GouthamK_Intel
Moderator
1,998 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


0 Kudos
GouthamK_Intel
Moderator
1,961 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-reference/top/compilation/supported-environment-variables.html


Please let us know if the provided information helped.


Thanks & Regards

Goutham


0 Kudos
eug
Beginner
1,952 Views

Yes, this solve my problem.

Thank you.

0 Kudos
GouthamK_Intel
Moderator
1,939 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


0 Kudos
eug
Beginner
1,935 Views
0 Kudos
RahulV_intel
Moderator
1,913 Views

Thanks for the confirmation.


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


0 Kudos
Reply