vexcl icon indicating copy to clipboard operation
vexcl copied to clipboard

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

Open kafi350 opened this issue 3 years ago • 6 comments

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..

kafi350 avatar Jun 25 '21 10:06 kafi350

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

ddemidov avatar Jun 25 '21 10:06 ddemidov

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

kafi350 avatar Jun 25 '21 10:06 kafi350

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?

kafi350 avatar Jun 28 '21 08:06 kafi350

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

ddemidov avatar Jun 28 '21 08:06 ddemidov

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?

kafi350 avatar Jul 11 '21 11:07 kafi350

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;
}

ddemidov avatar Jul 11 '21 13:07 ddemidov