I’m trying to replicate this tutorial http://www.themattsimpson.com/2012/06/29/writing-cuda-c-extensions-for-r/ to try and learn using cuda with R statistical tool.
This is just a simple addition a+b=c example. I just basically pasted the code there, creating a gpuadd.cu file then compiling it with NVCC and finally creating a wrapper in R.
No errors, but when i call the function, the result is always 0 whatever the parameters a and b I enter.
I have to add that i’m on a laptop with a core I7 and a 870M GTX card, running with ubuntu 14.04 and nvidia prime. Prime basically lets you switch between the intel IGP and the NVDIA card (at least for the X11 side). Strange thing is that when i switch to the IGP, if i do the deviceQuery example (as in CUDA toolkit installation documentation) it tells me that no cuda capable device is detected which is logical (and consequently when i’m on the nvidia the deviceQuery sample runs perfectly) but the R call to “gpuadd” also gives me a 0 result. This led me think perharps the parameters a and b are not passed to the GPU (they stay on the host)?
Could you please help me?
The code in that article has an Rprintf statement in it. What is the output from that Rprintf statement in your gpuadd.cu file?
You mean the output in R right? It reads like, if i do gpuadd(1,7), “1+7=8”
But right now, i didn’t change anything, just switched to IGP then back to GPU and it suddenly works!
The curious thing is that it works also with IGP as graphical server… I seriously do not understand how this suddenly worked, but is it normal that the function works also when the IGP is the X11 device?
I don’t know the answer to your questions, and since it’s working now, probably we need not go any further.
But I was not referring to the output in R. I was referring to the Rprintf line of code here:
Rprintf("%.0f + %.0f = %.0f\n", *a, *b, *c);
If you used the code from the article without changing it, presumably that line of code should be in your gpuadd.cu module.
Yes that line is inside my gpuadd.cu file. is this a problem?
Today, just booting the computer, it doesn’t work anymore !
This is very strange…
I think i’ve identified the problem:
If i run deviceQuery then the functions works in R even if i switch back to IGP for X11. If deviceQuery isn’t run i have 0 as result.
So that means that the cuda device is not accessible until i run deviceQuery…
How could it be?
Maybe you’re running deviceQuery as a root user. In that case it sounds like maybe R is running the GPU code as an ordinary user, so if the device control files are not set up, things don’t work.
Perhaps you should read the linux getting started guide verification section:
That was it! i created the startup script and that works.
Thank you very much!