cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

sajis997
Adept I

explicit copy from host to device

Jump to solution

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

0 Kudos
Reply
1 Solution

Accepted Solutions
jberry
Adept I

Re: explicit copy from host to device

Jump 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

View solution in original post

0 Kudos
Reply
1 Reply
jberry
Adept I

Re: explicit copy from host to device

Jump 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

View solution in original post

0 Kudos
Reply