Skip to content
thewilsonator edited this page Jul 17, 2016 · 2 revisions

To do anything useful with DCompute a thread need to know it's index, it's position. If you take a look at dcompute.std.index you'll see there are quite a few to choose from. Most of the indices are three dimensional and represent offsets in a "3D" view of memory. Of course not all problems are 3D so the y and z values are not always useful.

extending the previous minimal example to add a constant to an array and assign it to another. We could have also used GlobalLinearId.

@compute module mykernels;
import dcompute.attributes;
import dcompute.types.pointer;
import dcompute.std.index;
alias gf = GlobalPointer!float;
@kernel void mykernel(gf a, gf b, float c)
{
    auto i = GlobalIndex.x;
    a[i] = b[i] + c;
}
Clone this wiki locally