richeek.arya

Copying Data over to GPU

Discussion created by richeek.arya on Jun 7, 2011
Latest reply on Jun 8, 2011 by himanshu.gautam
Conceptual Question

Hi,

I have question regarding copyign data over to GPU, the way I am doing is is like this:

it is a 4 step process:

1. clCreateBuffer

2. Get a ptr usign clEnqeueuMapBuffer

3. Copy the data to this ptr using memcpy --- input data is supplied from the user

4. Unmap the data

In the end free the memory using this:

status = clReleaseMemObject(s_re_d);

 

Is it correct that I do not need to free s_re_p since I never allocated memory to it?? Could someone please let me know if all these steps are following OpenCL guidelines?

with regadrs,

Richeek

cl_mem s_re_d; size = nT * nSym * sizeof(float); total_size += size; s_re_d = clCreateBuffer(context, CL_MEM_READ_WRITE, size, NULL, &status); if(status != CL_SUCCESS) { mexPrintf("Error: Setting kernel argument. \n"); return; } float *s_re_p; s_re_p = (float *)clEnqueueMapBuffer(commandQueue,s_re_d,CL_FALSE,CL_MAP_WRITE,0,size,0,NULL,NULL,&status); if(status != CL_SUCCESS) { mexPrintf("Error: clEnqueueMapBuffer \n"); return; } memcpy(s_re_p, s_re, size); /* Load the data back on the GPU */ status = clEnqueueUnmapMemObject(commandQueue,s_re_d,(void*)s_re_p,0,NULL,&ev); if(status != CL_SUCCESS) { mexPrintf("clEnqueueUnmapMemObject() failed\n"); return; } status = clWaitForEvents(1, &ev); if(status != CL_SUCCESS) { mexPrintf("clEnqueueUnmapMemObject() Release failed s_re_d\n"); return; }

Outcomes