elect
elect

Reputation: 7180

Cuda thread: special mapping/indexing

I have different blocks of 34 threads each (0...33).

I need to find a formula so that in each of these blocks, the first 33 threads (0...32) will point to the correspondent

bases[x]

With x from 0 to 32, while the last one, 33, to 66.

Upvotes: 0

Views: 123

Answers (1)

talonmies
talonmies

Reputation: 72353

I am guessing you want something like this:

int offset = (threadIdx.x == 33) ? threadIdx.x : 0;
int val = bases[threadIdx.x + offset];

so that the last thread gets a non zero offset from the thread index within the block. The ternary operator will be evaluated conditionally and won't cause any branch divergence. I would, however, suggest reconsidering using a block size which is not a multiple of the warp size (32). You will be wasting a lot of cores and cycles by doing so. There wouldn't be anything stopping you using a block with 32 threads and having the last two threads perform extra calculations to cover the required 34 operations per block, for example.

Upvotes: 1

Related Questions