Could I use the `mxGPUArray` format data in the cuda kernel function?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I am new in compiling the mexcuda. I am trying to use the mxGPUArray as inputs of cuda kernel. My sample.cu code is as below. It is a simple plus function. The inputs are two vectors in CPU. The output is one vector in CPU.
But it gives the error at the line of
% z[row] = x[row] * y[row] line error
error: expression must be a pointer to a complete object type
Must I use the cudaMemcpy function, with transfering the mxGPUArray* data to a double* format?
#include "mex.h"
#include "gpu/mxGPUArray.h"
__global__ void plus(mxGPUArray*x, mxGPUArray* y, mxGPUArray* z, int N)
{
int row = blockIdx.x*blockDim.x + threadIdx.x;
if (row < N)
{
z[row] = x[row] * y[row];% error is here
}
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, mxArray const *prhs[])
{
mxGPUArray* d_x = mxGPUCopyFromMxArray(prhs[0]);
mxGPUArray* d_y = mxGPUCopyFromMxArray(prhs[1]);
int N = (int)(mxGPUGetNumberOfElements(d_x));
mxGPUArray* d_z = mxGPUCreateGPUArray(mxGPUGetNumberOfDimensions(d_x),
mxGPUGetDimensions(d_x),
mxGPUGetClassID(d_x),
mxGPUGetComplexity(d_x),
MX_GPU_DO_NOT_INITIALIZE);
// =========================================================================
// gpu computing
// =========================================================================
int const threadsPerBlock = 256;
int blocksPerGrid;
blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
plus <<<blocksPerGrid, threadsPerBlock>>>(d_x, d_y, d_z,N);
plhs[0] = mxGPUCreateMxArrayOnCPU(d_z);
mxGPUDestroyGPUArray(d_x);
mxGPUDestroyGPUArray(d_y);
mxGPUDestroyGPUArray(d_z);
}
I don't want to do many copy steps. So I did not transfer the mxGPUArray into another double array. Any suggestion would be appreciated. Thank you.
0 Kommentare
Antworten (1)
Siehe auch
Kategorien
Mehr zu GPU CUDA and MEX Programming finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!