Hi! I am trying to let different blocks to do different things, so I need several blocks to be active all the time, so is it possible to assign some blocks to be active?
Thank you!!
Hi! I am trying to let different blocks to do different things, so I need several blocks to be active all the time, so is it possible to assign some blocks to be active?
Thank you!!
Like, we assign block 0 to run first. Somehow uses PTX to do it. Can we?
You have no control over block scheduling order. However you can reorder your work based on the scheduled order.
One possible approach is to use your own order by counting blocks as they become scheduled.
At the beginning of your kernel code, do an atomic add to a global variable that is initialized to zero. The return value of the atomic add becomes your block number. Only one thread in the block needs to do this.
You can then condition your code based on this block number, rather than the usual value (e.g. rather than using blockIdx.x
).
__global__ void kernel(int *g_blk, ...){
__shared__ int my_block_number;
if (threadIdx.x == 0) my_block_number = atomicAdd(g_blk, 1);
__syncthreads();
int idx = threadIdx.x+my_block_number*blockDim.x;
... // your kernel code here
}
Very smart!!! You solved my problem!!!
Thanks!!!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.