Hi, I’m starting to use CUDA not long since.
I’m reading the programming guide but I have some problems to understand the meaning of following instructions:
int i=threadIdx.x;
dim3 dimBlock(N,N);
I’m sorry I know that this questions are very elementary but I need your help.
Thanks.
Re-read the first few chapters. threadIdx is the intrinsic to identify which element in a block a thread is, and dim3 dimBlock is used to set up the dimensions of the block from the host side code.
threadIdx.x stands for the thread-ID of the thread that is executing the statement.
Thus when threadId 0 executes the code, it initializes “i” to 0.
When threadId 1 executes the code, it initialies it to 1 and so on.
Thus if “i” is a common variable to all threads, the statement “i=threadIdx.x” does NOT make any sense. Usually, “i” would be a local variable – which would be local to the thread that executes. Hope that clarifies.
threadID is NOT fully qualified. To fully qualify a threadId, you need to specify blockId as well as the threadId. Thus <blockId, threadId> forms a fully qualified identifier for a thread.
Say you spawn 100 blocks with 100 threads each… the threads can be enumerated like this.