cdeterman / RViennaCL

R package providing ViennaCL header files
19 stars 2 forks source link

Trying to build an R package which imports c++ code that uses RViennaCL #1

Closed ndrubins closed 6 years ago

ndrubins commented 6 years ago

Hi there,

Just installed RViennaCL and trying to develop a package (named gpuUtils) that will import c++ code that makes use of RViennaCL for GPU utilization.

I followed Hadley's guidelines for package development and usage of c++ code, created a c++ file with these lines:

// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
#include "viennacl/ocl/backend.hpp"

using namespace Rcpp;

Then, when running devtools::document I get this error:

g++ -m64 -I/usr/include/R -DNDEBUG  -I/usr/local/include -I"/home/ndr/R/x86_64-redhat-linux-gnu-library/3.3/Rcpp/include" -I"/home/ndr/R/x86_64-redhat-linux-gnu-library/3.3/RcppArmadillo/include" -I"/home/ndr/R/x86_64-redhat-linux-gnu-library/3.3/RViennaCL/include"   -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic  -c gpuUtils.cpp -o gpuUtils.o
In file included from /home/ndr/R/x86_64-redhat-linux-gnu-library/3.3/RViennaCL/include/viennacl/ocl/backend.hpp:26:0,
                 from gpuUtils.cpp:3:
/home/ndr/R/x86_64-redhat-linux-gnu-library/3.3/RViennaCL/include/viennacl/ocl/context.hpp:28:19: fatal error: CL/cl.h: No such file or directory
 #include <CL/cl.h>
                   ^
compilation terminated.
make: *** [gpuUtils.o] Error 1

OpenCL and CUDA are installed and I do see CL/cl.h in my system:

$ ls -1 /usr/local/cuda-9.0/include/CL
cl_egl.h
cl_ext.h
cl_gl_ext.h
cl_gl.h
cl.h
cl.hpp
cl_platform.h
opencl.h

And:

$ ls -1 /usr/include/CL/
cl2.hpp
cl_egl.h
cl_ext.h
cl_gl_ext.h
cl_gl.h
cl.h
cl.hpp
cl_platform.h
opencl.h

Any idea?

Thanks a lot

cdeterman commented 6 years ago

You aren't including either location for the CL directory in your g++ call. You would need either -I/usr/include/ or -I/usr/local/cuda-9.0/include/

cdeterman commented 6 years ago

@ndrubins did my response help you? If I don't hear back I will assume so and close this issue.

ndrubins commented 6 years ago

Thanks a lot @cdeterman. So is the problem that devtools::document does not export either /usr/include/ or /usr/local/cuda-9.0/include/ to my path? If so, would you happen to know how to do that?

cdeterman commented 6 years ago

@ndrubins it has nothing to do with devtools. It is part of the build process that you are likely missing because of nice things like LinkingTo field in your DESCRIPTION file. In this case, you are dealing with OpenCL, which has many backends that could be in multiple places. That is the reason you want a custom Makevars file. You can find further documentation here. In my case, with gpuR I am allowing users to define an environmental variable OPENCL_INC to define where the opencl headers are if they aren't in the default location (note I am also using a configure script as well to write my Makevars).

ndrubins commented 6 years ago

Yes, adding PKG_CPPFLAGS = -I/usr/local/cuda-9.0/include/ to a Makevars file located in the src folder and building the package with R CMD build <pacakge_name> does work. As far as I see the developing an R package with devtools guide doesn't cover usage of Makevars. Thanks a lot for your help

cdeterman commented 6 years ago

@ndrubins glad I could help.