I’m building a small R package using CUDA and Rcpp as a learning exercise (using Building a tiny R package with CUDA and Rcpp as inspiration). It includes a single function that takes a device ID and returns a few properties for that device.
This package compiles without any issues in WSL2 (Ubuntu 22.04, R 4.4.1, CUDA/nvcc 12.3) and returns the device properties as expected. To do so I’m using the Makevars
files as below:
CUDA_HOME = /usr/local/cuda-12.3
R_HOME = /home/killianmelsen/R/x86_64-pc-linux-gnu-library/4.4
R_INC = /usr/share/R/include
RCPP_INC = $(R_HOME)/Rcpp/include
NVCC = $(CUDA_HOME)/bin/nvcc
CUDA_INC = $(CUDA_HOME)/include
PKG_LIBS = -L$(CUDA_HOME)/lib64 -Wl,-rpath,$(CUDA_HOME)/lib64 -lcudart
NVCC_FLAGS = -x cu -Xcompiler "-fPIC" -gencode arch=compute_86,code=sm_86 -I$(R_INC)
### Define objects
sharedlibs = code.o RcppExports.o
sources = code.cpp RcppExports.cpp
OBJECTS = $(sharedlibs)
all : cudar.so
cudar.so: $(OBJECTS)
%.o: %.cpp $(sources)
$(NVCC) $(NVCC_FLAGS) -I$(CUDA_INC) -I$(R_INC) -I$(RCPP_INC) $< -c
The code.cpp
file includes the C++ as well as CUDA code. I simply tried “translating” the Makevars
to a Makevars.win
version that might work with Windows, but it didn’t:
CUDA_HOME = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.3"
R_HOME = "C:/Users/Killian/AppData/Local/R/win-library/4.2"
R_INC = "C:/Program Files/R/R-4.2.2/include"
RCPP_INC = $(R_HOME)/Rcpp/include
NVCC = $(CUDA_HOME)/bin/nvcc
CUDA_INC = $(CUDA_HOME)/include
PKG_LIBS = -L$(CUDA_HOME)/lib/x64 -Wl,-rpath,$(CUDA_HOME)/lib/x64 -lcudart
NVCC_FLAGS = -x cu -Xcompiler "-fPIC" -gencode arch=compute_86,code=sm_86 -I$(R_INC)
### Define objects
sharedlibs = code.obj RcppExports.obj
sources = code.cpp RcppExports.cpp
OBJECTS = $(sharedlibs)
all : cudar.dll
cudar.dll: $(OBJECTS)
%.obj: %.cpp $(sources)
$(NVCC) $(NVCC_FLAGS) -I$(CUDA_INC) -I$(R_INC) -I$(RCPP_INC) $< -c
At first I got an error that cl.exe
couldn’t be found by nvcc, but it seems I fixed that by adding the folder containing cl.exe
to PATH
. At this point I get the following error:
── R CMD INSTALL ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
─ installing *source* package 'cudar' ...
** using staged installation
** libs
"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.3"/bin/nvcc -x cu -Xcompiler "-fPIC" -gencode arch=compute_86,code=sm_86 -I"C:/Program Files/R/R-4.2.2/include" -I"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.3"/include -I"C:/Program Files/R/R-4.2.2/include" -I"C:/Users/Killian/AppData/Local/R/win-library/4.2"/Rcpp/include code.cpp -c
cl : Command line warning D9002 : ignoring unknown option '-fPIC'
code.cpp
C:/Users/Killian/AppData/Local/R/win-library/4.2/Rcpp/includeRcpp/platform/compiler.h(43): fatal error C1189: #error: "This compiler is not supported"
code.cpp
make: *** [Makevars.win:27: code.obj] Error 2
ERROR: compilation failed for package 'cudar'
─ removing 'C:/Users/Killian/AppData/Local/Temp/Rtmpgnlywh/devtools_install_44583263584d/cudar'
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'Rcmd.exe' failed
---
Exit status: 1
stdout & stderr: <printed>
---
Type .Last.error to see the more details.
I’ve uploaded the package to GitHub in case that helps: https://github.com/KillianMelsen/cudar/tree/main
What’s going wrong here? Ideally I’d like to use CUDA in R within Windows as well.