OpenCL.jl
OpenCL.jl copied to clipboard
Add high-level support for OpenCL.api.clCreateSubBuffer
Can someone show me an example of how to create a sub-buffer of an existing buffer, for the purposes of reading only a portion of my buffer back into host memory. Here's what I have:
using OpenCL
device, context, queue = OpenCL.create_compute_context()
a = rand(Float32, 100)
abuf = OpenCL.Buffer(Float32, context, (:rw, :copy), hostbuf=a)
cbuf = OpenCL.api.clCreateSubBuffer( ? )
I haven't tested this, but this should get you started. Let me know if this works for you and we might think about adding high-level support for this in OpenCL.jl
immutable _cl_buffer_region
origin::Csize_t
size::Csize_t
end
offset = ...#
len = ...#
flags = ...# OpenCL.CL_MEM_READ_WRITE
buffer_create_info = Ref(_cl_buffer_region(offset*sizeof(eltype(abuf)), len*sizeof(eltype(abuf))))
errcode = Ref{Cint}(0)
raw_cbuf = OpenCL.api.clCreateSubBuffer(abuf.id, flags, OpenCL.CL_BUFFER_CREATE_TYPE_REGION, buffer_create_info, errcode)
@show errcode[]
OpenCL.Buffer{eltype(abuf)}(raw_cbuf, true, len)
@vchuravy
Hey awesome! This works, thanks.
@SimonDanisch is this of interest for you?