I would like to map a thread_id. This in C/CUDA but it is more an algebraic problem that I am trying to solve.
So the mapping I am trying to achieve is along the lines:
- Threads 0-15: read value array[0]
- Threads 16-31: read value [3]
- Threads 32-47: read value [0]
- Threads 48-63: read value [3]
- Threads 64-79: read value array[6]
- Threads 80-95: read value array[9]
- Threads 96-111: read value array[6]
- Threads 112-127: read value array[9]
and so on..
Note this is a simplification of the mapping, in reality there are more than 128 threads but the sequence is as shown and threads would always map to a multiple of three.
What formula can I use that each thread can run to find out what array position it should look at?
I would like to use some kind of formula as I have in the following example and not an explicit map or any if-statements.
To illustrate how I have solved this for a different case which required a different mapping, i.e.:
- Threads 0-31: read value array[0]
- Threads 32-63: read value [3]
I used the code
rintf(float(tid)/96.0)*3
Thanks