Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.

Random numbers in kernel scope.

Niko_
Employee
509 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
457 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-refere...

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

MRajesh_intel
Moderator
411 Views

Hi,


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


Regards

Rajesh.


Niko_
Employee
404 Views

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

MRajesh_intel
Moderator
400 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.


Reply