oneDPL
oneDPL copied to clipboard
question about mapping curand to oneDPL random number generation
In a CUDA program, a user can initialize and generate random numbers in the code snipet:
curandGenerator_t gen;
curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT);
curandSetPseudoRandomGeneratorSeed(gen, seed);
for (int i = 0; i < n; i++) {
...
curandGenerateUniform(gen, d_array, N); // each iteration generates N random numbers on a device
}
Can you please advise the codes using oneDPL random function ? The example show that users need to call the oneDPL function for every number.
https://docs.oneapi.io/versions/latest/onedpl/random.html
Please close the issue if the oneMKL interface deals with the mapping.
Hi @zjin-lcf , thank you for your interest in oneDPL RNG.
For oneDPL you need to call RNG routine to generate every single random number as in C++ standard (or up to 16 numbers by the single call if you use sycl::vec). Please note that you can do it in parallel on the particular device by writing your own sycl kernel as shown in the example https://docs.oneapi.io/versions/latest/onedpl/random.html#usage-model-of-onedpl-short-random-number-generation-functionality or directly from the host code. This approach allows you to control parallelization on your own to achieve better performance.
I would like to mention that oneMKL also contains RNG functionality with two types of interfaces: device APIs (the same usage model as in oneDPL) and Host APIs, which can be used in the similar manner as cuRAND:
oneapi::mkl::rng::default_engine engine(sycl_queue, seed); // create and seed generator
oneapi::mkl::rng::uniform distr; // distribution object
oneapi::mkl::rng::generate(engine, distr, N, d_array); // call generate function
oneMKL supports both USM and sycl::buffers. You can find more details here: https://www.intel.com/content/www/us/en/develop/documentation/oneapi-mkl-dpcpp-developer-reference/top/random-number-generators/manual-offload-rng-routines/intel-onemkl-rng-usage-model.html
Please note that there is Intel oneMKL product (https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-download.html), with optimized RNG support for x86 CPUs and Intel’s GPUs, and also oneMKL interfaces open-source project: https://github.com/oneapi-src/oneMKL/issues which you can build with various backends (including cuRAND and rocRAND) to use unified oneMKL DPC++ interfaces for different HW.
Please, fill free to ask any RNG-related questions. I would be glad to help.
Thank you for your descriptions!