I am actively working on an R package that will incorporate some CUDA code for using NVIDIA GPU devices. I am quite familiar with Rcpp for C++ code and accustomed to using a Makevars file for specifying compiler options. However I am stumped currently about how to use the NVCC compiler for the .cu files. Typically, a CUDA program will first be compiled with NVCC and the linked with any other .o files. # very simplified example nvcc my_cuda_function.cu -o my_cuda_function.o g++ -o my_program.so other_cpp_function.o my_cuda_function.o I have seem some older packages using a Makefile but I have also read that this is currently recommended against because of the need for multiarch builds. Does anyone know how I can tell R to compile .cu files with NVCC and 'proceed as normal' with the resulting .o files? Regards, Charles
[R-pkg-devel] Package with multiple compilers?
3 messages · Charles Determan, Duncan Murdoch, Kevin Ushey
On 29/05/2015 9:52 AM, Charles Determan wrote:
I am actively working on an R package that will incorporate some CUDA code for using NVIDIA GPU devices. I am quite familiar with Rcpp for C++ code and accustomed to using a Makevars file for specifying compiler options. However I am stumped currently about how to use the NVCC compiler for the .cu files. Typically, a CUDA program will first be compiled with NVCC and the linked with any other .o files. # very simplified example nvcc my_cuda_function.cu -o my_cuda_function.o g++ -o my_program.so other_cpp_function.o my_cuda_function.o I have seem some older packages using a Makefile but I have also read that this is currently recommended against because of the need for multiarch builds. Does anyone know how I can tell R to compile .cu files with NVCC and 'proceed as normal' with the resulting .o files?
You can include the recipes for those .o files in your Makevars file. It is essentially a fragment of the full Makefile needed by your package. I forget if you'll need to give an explicit recipe for the library, or whether the standard file will link them in. Try it! Duncan Murdoch
The GitHub search feature is also quite useful for seeing how other package authors have constructed Makevars (or Makevars.win) when compiling with custom targets. For example, a quick search of how some authors manipulate OBJECTS in Makevars.win: https://github.com/search?utf8=%E2%9C%93&q=OBJECTS+extension%3Awin&type=Code&ref=advsearch&l= Of course, not all examples are good examples, but it definitely provides examples to learn from -- and personally, my Makefile-fu is pretty weak. Here's an example from 'gpusim' using 'nvcc' in their own Makevars.win: https://github.com/rforge/gpusim/blob/d07dd509be5d414d3f4add66db8c841146813544/pkg/src/Makefile.win Hopefully this gives you some more direction... Kevin On Fri, May 29, 2015 at 10:49 AM Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
On 29/05/2015 9:52 AM, Charles Determan wrote:
I am actively working on an R package that will incorporate some CUDA
code
for using NVIDIA GPU devices. I am quite familiar with Rcpp for C++ code and accustomed to using a Makevars file for specifying compiler options. However I am stumped currently about how to use the NVCC compiler for the .cu files. Typically, a CUDA program will first be compiled with NVCC and the linked with any other .o files. # very simplified example nvcc my_cuda_function.cu -o my_cuda_function.o g++ -o my_program.so other_cpp_function.o my_cuda_function.o I have seem some older packages using a Makefile but I have also read
that
this is currently recommended against because of the need for multiarch builds. Does anyone know how I can tell R to compile .cu files with NVCC and 'proceed as normal' with the resulting .o files?
You can include the recipes for those .o files in your Makevars file. It is essentially a fragment of the full Makefile needed by your package. I forget if you'll need to give an explicit recipe for the library, or whether the standard file will link them in. Try it! Duncan Murdoch
______________________________________________ R-package-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel