OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1664 Discussions

Random Numbers in OpenCL CPU kernel.

Juan_G_1
Beginner
419 Views

Hello everyone! 

I'm a new OpenCL developer. I'm trying to solve a problem using a genetic algorithm and a very importan part of this kind of heuristic algorithms is the randomness. To solve my problem I need to generate randomly an initial population and then some genetic operators will be selected in a random way too.  I want to solve my problem using heterogeneous computing, but the issue is that I cannot find a function to generate random numbers in the GPU. I was thinking that will be useful put this work into a CPU kernel.

 

Is there an allowed OpenCL function to generate random numbers in a kernel where the target is the CPU? 

 

 

 

Thanks!

 

M.C Juan Garcia.

0 Kudos
1 Reply
Andrey_P_Intel
Employee
419 Views

The OpenCL standard doesn't provide a built-in function to generate pseudorandom numbers. There are several ways to solve the problem, and for example, you can generate an array of random numbers on a host and pass the pointer to the array to a kernel, or, alternatively, use libraries like clRNG that provides streams of random numbers from the host. There are a lot of scientific papers and libraries that might also solve the problem in another way, but the selection will depend on your requirements for them. Unfortunately, I am not able to suggest any of them.

- Andrey

Reply