cogciprocate / ocl

OpenCL for Rust
Other
721 stars 75 forks source link

Shared Virtual Memory (SVM) support? #214

Closed itayw closed 11 months ago

itayw commented 1 year ago

Thanks for this library, awesome work!

I've been using it for a while now and one of the features I wanted to use is shared virtual memory. I'm currently already using host memory for my buffer, but writing and reading it pose an overhead. From what I read and some examples I understand SVM may offer a higher efficiency due to removing this need (depending on the actual capabilities of the device).

I'm not sure my understanding is correct, but does this library offer such capabilities?

c0gent commented 1 year ago

To be honest my memory of the details of this is a bit foggy but anything provided by the OpenCL API should be supported by this library (depending on OpenCL version of course).

The buffer creation options are where you want to look. The memory options are passed as part of the 'flags' parameter when constructing a buffer.

https://registry.khronos.org/OpenCL/sdk/1.2/docs/man/xhtml/clCreateBuffer.html https://registry.khronos.org/OpenCL/specs/opencl-2.1.pdf#page=104 https://docs.rs/ocl/latest/ocl/builders/struct.BufferBuilder.html#method.flags

c0gent commented 1 year ago

The CL_MEM_USE_HOST_PTR, CL_MEM_ALLOC_HOST_PTR flags are basically what you want. From what I remember their exact behavior varies from device to device but on CPU based systems it would be the equivalent of shared virtual memory.