cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

spectral
Adept II

How to pass a lot of datas to openCL ?

Hi,

In my application I have an OpenCL kernel that search for intersection between a ray and a set of triangles.

I pass the list of triangles as a pointer, (I have up to 100.000 triangles now and can have more...)

But, is there  a way to avoid to send all the triangles at each kernel call ?

Theses datas are statics for a same object (I have several objects that contains a set of triangles).

 

Thanks

Tags (1)
0 Likes
8 Replies
n0thing
Journeyman III

How to pass a lot of datas to openCL ?

You don't have to send the triangles to the device each time you are executing a kernel.

Create a read-only buffer on device and enqueue write data to it only once, then you can re-use that buffer as your input triangle source as many times as you want.

You can also use a constant buffer which may be cached.

0 Likes
spectral
Adept II

How to pass a lot of datas to openCL ?

Thanks for your answer,

And how can I :

A) create a read-only buffer and access the read only buffer ?
B) create a constant buffer and access the constant buffer ?

 

Thx

0 Likes
n0thing
Journeyman III

How to pass a lot of datas to openCL ?

To create a read-only buffer use flag : CL_MEM_READ_ONLY when using the function clCreateBuffer. See section 5.2.1 of OpenCL spec for more details. You can access buffers allocated inside global memory as constant buffers by using __constant as address space qualifier in your kernel arguments. For example: __kernel void sobel_filter(__constant uchar4* inputImage, __global uchar4* outputImage) The constant qualifier in the first argument to kernel is used to allocate 'inputImage' buffer in constant memory, this memory may be cached so you can get a good speedup if you read sequentially from this memory. See section 6.5 and in particular 6.5.3 for more details.
0 Likes
spectral
Adept II

How to pass a lot of datas to openCL ?

Thanks for the information,

I have try this change and when I allocate the buffer with CL_MEM_READ_ONLY I got an "Invalid Host" error...

When using CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR all is fine.

So, what is the difference ? I use the same pointer !

Thanks

0 Likes
nou
Exemplar

How to pass a lot of datas to openCL ?

you must use CL_MEM_*_PTR if you pass own pointer to CreateBuffer(); when you do not specify pointer (NULL) then you can not use CL_MEM_*_PTR flag. everything is in the spec. so read it.

0 Likes
spectral
Adept II

How to pass a lot of datas to openCL ?

It is what I do, I pass a pointer... to my datas !

It sounds that using "CL_MEM_COPY_HOST_PTR" is mandatory... it is not what the specs tell !

0 Likes
n0thing
Journeyman III

How to pass a lot of datas to openCL ?

When you use CL_MEM_READ_ONLY,CL_MEM_READ_WRITE, CL_MEM_WRITE_ONLY flags, you don't have to specifity a host ptr in clCreateBuffer function. The host_ptr argument should be NULL in that case.

You need to explicitly write data from host_ptr to that buffer by using clEnqueueWriteBuffer function in this case.

The flags which have 'HOST' in it : CL_MEM_USE_HOST_PTR, CL_MEM_COPY_HOST_PTR, CL_MEM_ALLOC_HOST_PTR require a valid data pointer in host memory to allocate a buffer on device.

 

0 Likes
spectral
Adept II

How to pass a lot of datas to openCL ?

Thanks a lot for the information and for your help

Regards

0 Likes