A simple OpenCL example in R with R code?

Can I use OpenCL, but with R code? I still do not have a good understanding of OpenCL programming and GPU. For example, suppose I have the following R code:

aaa <- function(x) mean(rnorm(1000000)) sapply(1:10, aaa) 

I like that I can use mclapply as a dropin replacement for lapply . Is there a way to do this for OpenCL? Or use OpenCL as a backend for mclapply ? I assume this is not possible because I could not find an example, so I have two questions:

  • Is this possible, and if so, can you give a complete example using my aaa function above?
  • If this is not possible, can you explain why? I don't know much about GPU programming. I view GPUs just like processors, so why can't I run R code in parallel?
+8
r opencl
source share
2 answers

I would like to start by looking at the High Performance Computing CRAN task , in particular Parallel Computing: GPUs section.

Here are a few packages that use GPGPU for specific tasks that lend themselves to massive parallelization (e.g. gputools , HiPLARM ). Most of them use their own NVIDIA CUDA, not OpenCL.

There is also a more general OpenCL package, but it requires you to learn how to write OpenCL code yourself and just provide an interface to this code from R.

+3
source share

This is not possible because GPUs work differently than processors, which means you cannot give them the same instructions as the processor.

Nvidia showcases a good show with this video describing the difference between processor and GPU processing. In fact, the difference is that on a GPU there are usually several orders of magnitude more cores than processors.

Your example is one that can be extended to GPU code as it is very parallel.

Here is some code for generating random numbers (although they are usually not distributed) http://cas.ee.ic.ac.uk/people/dt10/research/rngs-gpu-mwc64x.html

Once you create random numbers, you can split them into pieces, and then sum each of the pieces in parallel, and then add the sums of the pieces to get the total amount. Is it possible to calculate the amount in parallel in OpenCL?

I understand that your code will make a vector of random numbers and its sum in sequential and parallel operation 10 times, but with GPU processing, having only 10 tasks, is not very effective, since you will leave as many inactivity cores.

+2
source share

All Articles