OpenCL.jl icon indicating copy to clipboard operation
OpenCL.jl copied to clipboard

Add high-level support for OpenCL.api.clCreateSubBuffer

Open ericproffitt opened this issue 9 years ago • 3 comments

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( ? )

ericproffitt avatar Aug 22 '16 19:08 ericproffitt

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 avatar Aug 22 '16 21:08 vchuravy

@vchuravy

Hey awesome! This works, thanks.

ericproffitt avatar Aug 22 '16 21:08 ericproffitt

@SimonDanisch is this of interest for you?

vchuravy avatar Aug 22 '16 21:08 vchuravy