I was wondering if anyone had any suggestions to go about accessing (via gather) a 1D array (that was a 2D array now flattened to 1D) that is not a direct indexof() access.

For example:

normal code:

for (i = 0 ; i < row ; i++)

for(j = 0 ; j < col ; j++)

newValue = array[i+row*j];

This can be done normally over the domain, no problems:

newValue = array[indexof(out)];

But if we want to translate this:

normal code:

for (i = 0 ; i < row ; i++)

for(j = 0 ; j < col ; j++)

i = i+x;

j = j+y;

newValue = array[i+row*j];

// newValue = array[(i+x)+row*(j+y)];

In Brook+, the indexof() is going to return some value (one value).

There are "two" dimensions here but using a flattened 2D array (1D array) it appears there are going to be problems accessing the correct index in a gather (or scatter for that matter).

For instance, in CUDA you can simply use the x and y dimensions, just like you would in a nested for loop, but with Brook+ indexof() returns only value for a 1D stream.

For example:

normal code:

for (i = 0 ; i < row ; i++)

for(j = 0 ; j < col ; j++)

newValue = array[i+row*j];

This can be done normally over the domain, no problems:

newValue = array[indexof(out)];

But if we want to translate this:

normal code:

for (i = 0 ; i < row ; i++)

for(j = 0 ; j < col ; j++)

i = i+x;

j = j+y;

newValue = array[i+row*j];

// newValue = array[(i+x)+row*(j+y)];

In Brook+, the indexof() is going to return some value (one value).

There are "two" dimensions here but using a flattened 2D array (1D array) it appears there are going to be problems accessing the correct index in a gather (or scatter for that matter).

For instance, in CUDA you can simply use the x and y dimensions, just like you would in a nested for loop, but with Brook+ indexof() returns only value for a 1D stream.

1. Do you really need to flatten the array? On a 2D stream indexof would return a float2 with the coordinates so that problem would be gone

2. With 1D flattened output you still can access a 2D array with array[ float2(pos % col, pos / col) ] // pos is the position returned by indexof(out)

3. With 2D output you can access a 1D flattened array with array[pos.x + pos.y * col] // float2 pos is the position returned by indexof(out)

4. Otherwise, if both the output and the data array are flattened there wouldn't be any problem