to _range or not to _range . . .

to _range or not to _range . . .

I'm completely new to this arbb and have been looking at the tutorials and the online docs.
I had a basic question, in tutorial0 there are these lines

bind(vec_out, out, vec_length);
call(sum_kernel)(vec_a, vec_b, vec_out);

and later

dense out_only;
call(sum_kernel)(vec_a, vec_b, out_only);
const arbb::const_range output = out_only.read_only_range();
float result[vec_length];
for (unsigned int i = 0; i < vec_length; ++i) {
result[i] = output[i];

So my question is, in the second case we have to use a const_range and call read_only_range()
but in the first case we don't? Wahy is that? The documentation says

"// You must call a read range function before reading the values"

Is this always required ? Is it just good luck that the first case works ?


3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi Jason,

Thanks for your post. It is a good catch!

In ArBB, there are two ways to create and manage dense objects. First, if you've got a C/C++ array then you can bind a dense object to it. The bound dense object can be passed to ArBB functions. This is the case in tutorial0. Second, you can create a new dense entirely in the ArBB memory space. This is the case in your second example.

No matter how a dense object was created, if it was modified by a function then a read_only_range must be obtained before you can safely access the content of the dense object. A read_only_range is like a synchronization point telling the ArBB runtime to complete all pending data copying for this container and bring it up to the latest state.

The example in tutorial0 is missing a read_only_range. It just happens to work because the current beta version of ArBB performs frequent synchronizations for bound dense objects. But this is not a behavior that you should rely on.



Thanks for the clarification, just trying to get it sorted out in my own mind how things should work.


Leave a Comment

Please sign in to add a comment. Not a member? Join today