The first inruction in cuda

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:

  1. int i=threadIdx.x;
  2. dim3 dimBlock(N,N);
    I’m sorry I know that this questions are very elementary but I need your help.

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.

block thread

0 0

0 1

0 2

. .

. .

0 99

1 0

1 1

1 2

1 3

. .

. .

1 99

. .

. .

99 0

99 1

99 2

. .

. .

99 99