question about mapped memory

Since I am using cuda on matlab, I want to make the input pointer to be mapped memory.
Dose anybody know how?

For example:
void mexFunction(int nlhs, mxArray *plhs,int nrhs, const mxArray *prhs)
{
int m,n;
float *data1, *data2;

float *data2f;
float *data1f_gpu, *data2f_gpu;
const mwSize *dims;
m = mxGetM(prhs[0]);
n = mxGetN(prhs[0]);
dims = mxGetDimensions(prhs[0]);
plhs[0] = mxCreateNumericArray(2, dims, mxSINGLE_CLASS, mxREAL);
data2=(float *)mxGetData(plhs[0]);
data1=(float *)mxGetData(prhs[0]);
cudaSetDeviceFlags(cudaDeviceMapHost);

}

How can I set the data1 to be mapped memory?

Pinned memory is what should suit you

[url=“http://forums.nvidia.com/index.php?showtopic=98502&hl=pinned+memory”]http://forums.nvidia.com/index.php?showtop...l=pinned+memory[/url]

I have read it. But it still cannot solve my problem. It only tells me how to allocate a pinned memory. My problem is that if I have already allocated a memory space (see data1 in my example), how can I define it to be a pinned memory?

To define a pinned memory you need to use interface for allocating pinned memory type. You can’t change memory type dynamically (i.e. the same way you can’t make shared variable be changed to a global memory type in the kernel)

Thank you very much!