cdeterman / RViennaCL

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

RViennaCL example #2

Closed ndrubins closed 6 years ago

ndrubins commented 6 years ago

For a newbie using RViennaCL, any chance you can provide an example of matrix multiplication using RViennaCL?

In my naive attempt I created a cpp file inside the src folder within my package (gpuUtils), with the code:

// [[Rcpp::depends(RViennaCL)]]
#include "viennacl/ocl/backend.hpp"

//' eigenMatMult version of matrix multiplication
//'
//' @export
// [[Rcpp::export]]
SEXP eigenMatMult(viennacl::matrix const& A, viennacl::matrix const& B){
  viennacl::matrix C = prod(A,B);

  return Rcpp::wrap(C);
}

Then,

$ R CMD build gpuUtils
* checking for file ‘gpuUtils/DESCRIPTION’ ... OK
* preparing ‘gpuUtils’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘gpuUtils_0.0.0.9000.tar.gz’

But then,

$ R CMD INSTALL gpuUtils_0.0.0.9000.tar.gz
* installing to library ‘/home/ndrubins/R’
* installing *source* package ‘gpuUtils’ ...
** libs
g++  -I/opt/ohpc/pub/libs/gnu7/R/3.4.2/lib64/R/include -DNDEBUG -I/usr/local/cuda-9.0/include/ -I"/home/ndrubins/R/Rcpp/include" -I"/home/ndrubins/R/RViennaCL/include" -I/usr/local/include   -fpic  -g -O2  -c gpuUtils.cpp -o gpuUtils.o
gpuUtils.cpp:9:36: error: missing template arguments before ‘const’
 SEXP eigenMatMult(viennacl::matrix const& A, viennacl::matrix const& B){
                                    ^~~~~
gpuUtils.cpp:9:63: error: missing template arguments before ‘const’
 SEXP eigenMatMult(viennacl::matrix const& A, viennacl::matrix const& B){
                                                               ^~~~~
gpuUtils.cpp:9:71: error: expression list treated as compound expression in initializer [-fpermissive]
 SEXP eigenMatMult(viennacl::matrix const& A, viennacl::matrix const& B){
                                                                       ^
make: *** [gpuUtils.o] Error 1
ERROR: compilation failed for package ‘gpuUtils’
* removing ‘/home/ndrubins/R/gpuUtils’
* restoring previous ‘/home/ndrubins/R/gpuUtils’

I can move this request to stackoverflow if you think this location is not appropriate.

Thanks a lot