vendredi 30 novembre 2018

Compiling Rcpp package that uses CUDA on Windows 10 and RStudio

I have a program which essentially has 3 parts. R code is used to gather data, which it then processes using a .cpp file and Rcpp, and then the data is analyzed using custom CUDA C++ code.

At this point my analysis is done using C++ code in the .cpp file, and I'm having a lot of difficulty understanding how to compile CUDA with Rcpp in a way that R recognizes and that works on Windows 10.

Rcpp requires the use of g++ to build, and CUDA requires nvcc as far as I'm aware.

I'm basically looking for a simple "hello world" or barebone example of using Rcpp + CUDA.

I've found a few examples on StackOverflow, but they do not seem to work, either due to their age, or maybe because I'm using Windows.

The best example I could find was from 2015, but with help they reported success. I downloaded their most recent repo which contained CUDA files, and then edited the Makevars to fit my system, as you'll find below, but when I tried to run the "check package" command through RStudio, the error log reports:

* installing *source* package 'rcppcuda' ...
** libs
Makevars:35: *** multiple target patterns.  Stop.
ERROR: compilation failed for package 'rcppcuda'

Below you'll find my Makevars, with paths updated for my system.

I would appreciate any help to make Rcpp and CUDA compile, whether your answer uses the code I've mentioned here, or if you have another solution.

Thanks!

CUDA_HOME = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0"
R_HOME = "C:\Program Files\Microsoft\R Open\R-3.5.1"
CXX = "C:\Rtools\mingw_64\bin\g++.exe"

# This defines what the shared object libraries will be
PKG_LIBS= -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64" -Wl,-rpath,"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64" -lcudart -d


#########################################

R_INC = "C:\Program Files\Microsoft\R Open\R-3.5.1\include"
RCPP_INC = "Z:\Documents\R\win-library\3.5\Rcpp\include"

NVCC = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin\nvcc.exe"
CUDA_INC = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include"
CUDA_LIB = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64"

LIBS = -lcudart -d
NVCC_FLAGS = -Xcompiler "-fPIC" -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -I$(R_INC)

### Define objects
cu_sources := $(wildcard *cu)
cu_sharedlibs := $(patsubst %.cu, %.o,$(cu_sources))

cpp_sources := $(wildcard *.cpp)
cpp_sharedlibs := $(patsubst %.cpp, %.o, $(cpp_sources))

OBJECTS = $(cu_sharedlibs) $(cpp_sharedlibs)

all : rcppcuda.so

rcppcuda.so: $(OBJECTS)

%.o: %.cpp $(cpp_sources)
        $(CXX) $< -c -fPIC -I$(R_INC) -I$(RCPP_INC)

%.o: %.cu $(cu_sources)
        $(NVCC) $(NVCC_FLAGS) -I$(CUDA_INC) $< -c

Aucun commentaire:

Enregistrer un commentaire