I'm building CUDA-accelerated R packages, and I want to debug with cuda-memcheck
. So in this minimal example (in the deliberate_memory_leak
GitHub branch), I create a memory leak in someCUDAcode.c
by commenting out a necessary call to cudaFree
. Then, I see if cuda-memcheck
can find the leak.
$ cuda-memcheck --leak-check full Rscript -e 'library(rcppcuda); hello()'
========= CUDA-MEMCHECK
An object of class "MyClass"
Slot "x":
[1] 1 2 3 4 5 6 7 8 9 10
Slot "y":
[1] 1 2 3 4 5 6 7 8 9 10
[1] "Object changed."
An object of class "MyClass"
Slot "x":
[1] 500 2 3 4 5 6 7 8 9 10
Slot "y":
[1] 1 1000 3 4 5 6 7 8 9 10
========= LEAK SUMMARY: 0 bytes leaked in 0 allocations
========= ERROR SUMMARY: 0 errors
$
No luck. Then I saw in the R extensions manual that R -d "valgrind --tool=memcheck --leak-check=full" --vanilla < mypkg-Ex.R
is the right way to use valgrind
. So I created a test.R
file with library(rcppcuda); hello()
and tried this.
R -d "cuda-memcheck --leak-check full" --vanilla < test.R
*** Further command line arguments ('--vanilla ') disregarded
*** (maybe use 'run --vanilla ' from *inside* cuda-memcheck --leak-check full)
========= CUDA-MEMCHECK
Fatal error: you must specify '--save', '--no-save' or '--vanilla'
========= LEAK SUMMARY: 0 bytes leaked in 0 allocations
========= ERROR SUMMARY: 0 errors
And finally,
$ cuda-memcheck --leak-check full R --vanilla < test.R
========= CUDA-MEMCHECK
R version 3.2.0 (2015-04-16) -- "Full of Ingredients"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(rcppcuda); hello()
An object of class "MyClass"
Slot "x":
[1] 1 2 3 4 5 6 7 8 9 10
Slot "y":
[1] 1 2 3 4 5 6 7 8 9 10
[1] "Object changed."
An object of class "MyClass"
Slot "x":
[1] 500 2 3 4 5 6 7 8 9 10
Slot "y":
[1] 1 1000 3 4 5 6 7 8 9 10
>
========= LEAK SUMMARY: 0 bytes leaked in 0 allocations
========= ERROR SUMMARY: 0 errors
$
Is it possible to make cuda-memcheck
work for R packages? I know I thought I had figured it out here, but back then, I didn't actually verify the answers that cuda-memcheck
was giving me.
This is not valid CUDA code:
When we want to do a
cudaMalloc
operation, we use pointers in C, not ordinary variables, like this:When we want to free a previously allocated pointer, we pass just the pointer, not the address of it:
Finally, the command line help for cuda-memcheck (
cuda-memcheck --help
) indicates:(A similar note is in the documentation as well.)
I think item 3 is the key missing ingredient in your code. The following modification to your code produces a proper report for me: