cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

hemantp
Journeyman III

accessing cl_mem buffer elements directly and modifying it.

hi,

is it possoble to directly access the elemts of of a buffer nad modify them ??

if so please list the syntax

Code:

//X is a vector of size M//

//some operations on bufX//

bufX = clCreateBuffer(ctx, CL_MEM_READ_WRITE, M*sizeof(cl_float), NULL, &err);

err = clEnqueueWriteBuffer(queue, bufX, CL_TRUE, 0,

        M * sizeof(cl_float), X, 0, NULL, NULL);

//now,i wish to set the first element of bufx to 0.//

but i have to read buffer to X

set 1 element to zero

and then write to bufX.

is there an easier way around??

i could find any support from the cl_mem struct for this action in the cl.h file.

thank you

0 Likes
1 Solution

How will it be possible to access something from host if it is inside device. You need to incur costs of data transfer. Also you need not transfer a big buffer, just to update a small part of it. Sub-buffer concept can be used in such cases. Also OpenCL 2.0 is out, which may have something for you, but it will take quite a time for vendors to claim OpenCL 2.0 capabilities.

View solution in original post

0 Likes
4 Replies
sinoluck
Adept I

I found you initialized bufX with vector X, why not set index 0 of X to zero before initialization? like that:

float tmp;

tmp = X[0];

X[0] = 0;

err = clEnqueueWriteBuffer(queue, bufX, CL_TRUE, 0,

       M * sizeof(cl_float), X, 0, NULL, NULL);

X[0] = tmp;

0 Likes
himanshu_gautam
Grandmaster

No way around this.

A less expensive way would be to use clEnqueueMapBuffer to get a pointer corresponding to the buffer. If the buffer is already in CPU memory, no copying will be necessary.

0 Likes

so there is no way to access the buffer elements(eg.bufX on device as in the above case) directly.(am i right??)

0 Likes

How will it be possible to access something from host if it is inside device. You need to incur costs of data transfer. Also you need not transfer a big buffer, just to update a small part of it. Sub-buffer concept can be used in such cases. Also OpenCL 2.0 is out, which may have something for you, but it will take quite a time for vendors to claim OpenCL 2.0 capabilities.

0 Likes