[Rd] Segmentation Fault when using CUDA
Andrew Redd
amredd at gmail.com
Mon Nov 8 22:02:18 CET 2010
I'm developing packages with CUDA, and I'm running into a problem with
memory allocation. Since CUDA involves memory on the GPU device it
requires that the program handle memory allocation and deallocation
separately from R.
The simplest case of allocating a char and then deallocating causes a
segmentation fault when R closes. Not on garbage collection but only
on exit. Is there anything in the R internals that explain why this
is happening?
The relevant C++ code is
---
void gpualloctest(){
char * _a;
cudaMalloc(&_a,sizeof(char));
cudaFree(_a);
_a=NULL;
}
--- from gpu.cu
gputest<-function(){
cat("testing allocation on gpu\n")
Module('test','gputest')$gpualloctest()
cat("Test successful\n")
cat("Collecting Garbage\n")
gc()
cat("done.\n")
}
--- from gputest.R
As you can see Rcpp is used to interface with the C++ code, but the
Rcpp is not the problem, but happened to be convenient to use to get
the configure scripts right for the CUDA cu files.
The results from running "valgrind Rscript testgpu.R" are linked to in
testgpu.log but do not show anything interesting.
Can anyone give any insight?
Thanks,
Andrew Redd
Links to files:
http://andrewredd.us/gputest/testgpu.R
http://andrewredd.us/gputest/testgpu.Rout
http://andrewredd.us/gputest/gputest_1.0.tar.gz
http://andrewredd.us/gputest/testgpu.log
More information about the R-devel
mailing list