分析之前肯定得有需要分析的代码,这里以fft为例:
1、fft的C-mex cuda代码如下所示:
#include "mex.h"
#include <cuda_runtime.h>
#include <cufft.h>
void mexFunction (int nlhs,mxArray *plhs[],int nrhs,mxArray *prhs[])
{
if(nrhs != 1)
mexErrMsgTxt("Invaid number of input arguments");
if(! mxIsSingle(prhs[0])&&!mxIsSingle(prhs[1]))
mexErrMsgTxt("input data type must be single");
float* A=(float*)mxGetData(prhs[0]);
int numARows = mxGetM(prhs[0]);
int numACols =mxGetN(prhs[0]);
float *deviceA;
cudaMalloc(&deviceA,sizeof(float)*numARows*numACols);
cudaMemcpy(deviceA,A,numARows*numACols*sizeof(float),cudaMemcpyHostToDevice);