Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Random numbers in kernel scope.

Niko_
Employee
936 Views

Is there any way to initialize data to random values inside a kernel? I need all the values to be different, and since this is for porting a C++ application to DPC++ I am using USM on my data.

 

As a side note since I am new to DPC++. When I call a function from within a kernel it's executed on the device that kernel belongs to right?

0 Kudos
4 Replies
Alina_E_Intel
Employee
884 Views

Hello @Niko_,

 

For a generation of random numbers inside of a kernel, there is a special device APIs: https://software.intel.com/content/www/us/en/develop/documentation/oneapi-mkl-dpcpp-developer-reference/top/random-number-generators/random-number-generators-device-routines/intel-onemkl-rng-device-usage-model.html

These APIs produce scalar (similar to C++) or vector (by sycl::vec) output and you may store it in both USM or buffer-based memory or post-process it without saving it to global memory. You will need to add #include "oneapi/mkl/rng/device.hpp" only to use it, as it's header-based. Also, please, note, that you will need to add -fno-sycl-early-optimizations flag to your link line (it's a temporary known limitation, will be removed in future library releases).

Yes, you are right, that all functions, which are called within a kernel are executed on the device that kernels belong to, that's why the definition of these functions should be available in the same translation unit or it should be marked as SYCL_EXTERNAL.

 

Please, fill free to ask any other RNG-related questions.

 

Best regards,
Alina

0 Kudos
MRajesh_intel
Moderator
838 Views

Hi,


Can you please let us know if your query has been resolved or not?


Regards

Rajesh.


0 Kudos
Niko_
Employee
831 Views

Yes, I did manage to make it work that way. Thank you.

0 Kudos
MRajesh_intel
Moderator
827 Views

Hi,


Glad to know that your issue is resolved. If you need any additional information, please submit a new question as this thread will no longer be monitored.


Regards

Rajesh.


0 Kudos
Reply