ddemidov / vexcl

VexCL is a C++ vector expression template library for OpenCL/CUDA/OpenMP
http://vexcl.readthedocs.org
MIT License
702 stars 82 forks source link

Copying Memory location of an OpenCl backend using VexCL and using that location with Boost.compute #284

Open kafi350 opened 3 years ago

kafi350 commented 3 years ago

Is it possible to Copy Memory location of an OpenCl backend using VexCL and using that location with Boost.compute? As Boost.compute uses vector type..

ddemidov commented 3 years ago

Something like this? https://vexcl.readthedocs.io/en/latest/interop.html

kafi350 commented 3 years ago

I will try this and let you know. Btw, Thank you.

kafi350 commented 3 years ago

Hi,for Boost.compute i can convert the boost vector into vexcl vector but I am also trying to convert the opencl (Cl mem object) to a vexcl vector. Is it possible?

ddemidov commented 3 years ago

Yes, vex::vector may be initialized with vex::device_vector<T>: https://vexcl.readthedocs.io/en/latest/memory.html#_CPPv4N3vex6vector6vectorERKN7backend13command_queueERKN7backend13device_vectorI1TEE6size_t

and vex::device_vector<T> may be constructed from cl::Buffer: https://github.com/ddemidov/vexcl/blob/5097dc6b6614235dcf2ce59f402e63618dfbaab1/vexcl/backend/opencl/device_vector.hpp#L66

kafi350 commented 3 years ago

vex::vector a(&queue, &buffer, data_size);

When I was trying to create the inline vector it doesn't work. It shows the error. I have the parameters to pass on to the inline vector but it doesn't work. Is there any problem in declaring the function?

ddemidov commented 3 years ago

The following works for me:

#include <vexcl/vexcl.hpp>

int main() {
    vex::Context ctx(vex::Filter::Env && vex::Filter::Count(1));
    std::cout << ctx << std::endl;

    const int n = 1024;

    // Raw OpenCL buffer
    cl::Buffer raw(ctx.context(0), CL_MEM_READ_WRITE, n * sizeof(float));

    // vex::vector wrapping the buffer
    vex::vector<float> vec(ctx.queue(0), raw, n);

    vec = 42.0f;
}