boostorg / compute

A C++ GPU Computing Library for OpenCL
http://boostorg.github.io/compute/
Boost Software License 1.0
1.56k stars 333 forks source link

compute::vector<> get/set value using custom queue #643

Closed dPavelDev closed 8 years ago

dPavelDev commented 8 years ago

When I have to get/set some values from some index from vector using custom queue, I forced to use compute::copy function, not [] or at members. I can't use convenient methods to access elements!

I think, it is necessary to provide method "set_default_queue(queue)" and public method get_default_queue() for all containers.

Also, is it right to wright code similar to?

struct my {
    int x, y;
}

BOOST_COMPUTE_ADAPT_STRUCT...
compute::array<my, 42> a;
a[7].x = 6; // this line (get my struct, edit member, set value)
jszuppe commented 8 years ago

IMHO, it's worth considering. However, that would require buffer_value<T> class to store command_queue object.

If we don't want to store command_queue object in vector (and other containers), then we can at least provide at() method which takes command_queue as its 2nd argument. That would also be simpler and introduce less changes to containers.

dPavelDev commented 8 years ago

If we don't want to store command_queue object in vector (and other containers), then we can at least provide at() method which takes command_queue as its 2nd argument.

It's rather good idea for getting value but how to set value? Operator = uses own command queue

jszuppe commented 8 years ago

It's easy. Method at() does not return reference to the value itself but rather a buffer_value<T> object that wraps that value. If we modify buffer_value<T> to store command_queue object then here we can use that queue instead of making a new one.

jszuppe commented 8 years ago

And just because I'm curious: Can you tell me where you use such a small array in GPU computing? I mean, in most cases operator[] is not even needed since in GPGPU you operate on rather large sets of data, not single values.

dPavelDev commented 8 years ago

Yes, you're right, operator[] needs rarely. For example, I have change only one value. When I build BVH-tree on GPU using my own algorithm, tree root value (only tree root) has undefined value. There are two ways: write kernel to modify only the one value or change this from host.

jszuppe commented 8 years ago

OK, thanks. I've just remembered, you can always do this:

compute::array<int_> a(context);
(a.begin() + 7).write(6, queue)
dPavelDev commented 8 years ago

Read and write members with custom queue in buffer_iterator. Excellent! But nothing about it in documentation.