Reputation: 41
I am currently trying to build an R-Package which works with CUDA. While the traditional method of creating the package would work, much like the gputools package, I wanted to try Rcpp for the package as it seems more clean and convenient concerning return values.
The package installation works well so far, but the issue is that the first call of a CUDA API function (like cudaMalloc()
for example) crashes my RStudio.
I created a minimal example to illustrate my case.
It is as simple as
#include <Rcpp.h>
#include "cudaTest.h"
using namespace Rcpp;
// [[Rcpp::export]]
Rcpp::NumericMatrix cudaTest()
{
testMalloc();
}
and
#include <cudaTest.h>
#include "cuda_runtime.h"
#include <cuda.h>
void testMalloc()
{
size_t
fbytes = sizeof(double);
double
*d_mat;
cudaMalloc((void**)&d_mat, 200*50*fbytes);
cudaFree(d_mat);
}
Any ideas on what I'm doing wrong? Is the integration supported this way?
EDIT:
Installing the package on the command line (R CMD INSTALL
) and executing it in the R REPL actually gives me the error, which is a common segfault.
Upvotes: 3
Views: 550
Reputation: 41
Thank you @RalfStubner, the mistake generating the error above was indeed just the declaration of a return type that was never returned.
So instead of
// [[Rcpp::export]]
Rcpp::NumericMatrix cudaTest()
{
testMalloc();
}
it should rather be
// [[Rcpp::export]]
void cudaTest()
{
testMalloc();
}
(While this was a rather simple problem, on my original pretty large project the error was the same with a different setup. I thought the cudaMalloc
was the problem because I was only able to debug my way through with printf
statements, which were completely omitted when the erroneous part was introduced. In this larger project, the error was a wrapper around the launch of CUDA kernels, which was simply removed afterwards.)
Upvotes: 1