Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add high-level support for OpenCL.api.clCreateSubBuffer #116

Closed
ericproffitt opened this issue Aug 22, 2016 · 3 comments
Closed

Add high-level support for OpenCL.api.clCreateSubBuffer #116

ericproffitt opened this issue Aug 22, 2016 · 3 comments
Assignees

Comments

@ericproffitt
Copy link

ericproffitt commented Aug 22, 2016

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( ? )
@vchuravy
Copy link
Member

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)

@ericproffitt
Copy link
Author

@vchuravy

Hey awesome! This works, thanks.

@vchuravy vchuravy changed the title How to use OpenCL.api.clCreateSubBuffer Add high-level support for OpenCL.api.clCreateSubBuffer Aug 22, 2016
@vchuravy
Copy link
Member

@SimonDanisch is this of interest for you?

@vchuravy vchuravy self-assigned this Aug 22, 2016
@juliohm juliohm closed this as completed Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants