I’m trying to set up Matlab mex files that copy data to the device memory and return a pointer to the data (I’m doing estimations that operate on the same data many times, so want to avoid transferring the data with each call). My problem is I am unsure of how to return the pointer to Matlab (and then back again).
So far I have:
[codebox]#include <cuda.h>
#include “mex.h”
#include “matrix.h”
void mexFunction(int nargout, mxArray *argout, int nargin, const mxArray *argin)
{
float *input, *cuda_mem;
size_t size;
input = (float *)mxGetPr(argin[0]);
size = mxGetM(argin[0]) * mxGetN(argin[0]) * sizeof(float);
cudaMalloc((void **) &cuda_mem, size);
cudaMemcpy(cuda_mem, input, size, cudaMemcpyHostToDevice);
/* Now return the pointer to the data.*/
argout[0] = mxCreateNumericMatrix(1, 1, mxSINGLE_CLASS, mxREAL);
}[/codebox]
but I don’t know the type that the pointer to the single array on the device will be. Any “pointers” would be greatly appreciated.