Hi forum,
I am allocating a host memory and then i am creating a device memory buffer with the host copy pointer.
Do i have to explicitly copy the contents from host to device then?
If the host pointer is null while creating the device read & write buffer , then i think you need to copy explicitly from host to device later in the program .
What do you guys think?
Regards
Sajjad
Solved! Go to Solution.
You don't need to copy the contents when you create the buffer - you can copy data from host memory in to the buffer later with clEnqueueWriteBuffer. e.g. for some integers in A:
....
int *A = malloc(n*sizeof(int));
cl_uint error;
cl_mem buffer = clCreateBuffer(context, CL_MEM_READ_WRITE, n*sizeof(*A), NULL, &error);
....
error = clEnqueueWriteBuffer(queue, buffer, CL_TRUE, 0, n*sizeof(*A), A, 0 NULL,NULL);
The specification is here: http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clEnqueueWriteBuffer.html
You don't need to copy the contents when you create the buffer - you can copy data from host memory in to the buffer later with clEnqueueWriteBuffer. e.g. for some integers in A:
....
int *A = malloc(n*sizeof(int));
cl_uint error;
cl_mem buffer = clCreateBuffer(context, CL_MEM_READ_WRITE, n*sizeof(*A), NULL, &error);
....
error = clEnqueueWriteBuffer(queue, buffer, CL_TRUE, 0, n*sizeof(*A), A, 0 NULL,NULL);
The specification is here: http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clEnqueueWriteBuffer.html