Why printf is not work in 2D blocks?

I tried to print values of parameters. I use kernel as follow:


#include <stdio.h>
__global__ void kernel()
        int x = threadIdx.x;
        int y = threadIdx.y;

        printf("x = %d, y = %d.\n", x, y);

int main()
        dim3 dimBlock(32, 3, 1);
        dim3 dimGrid(1, 0, 0);

        kernel<<<dimGrid, dimBlock>>>();

        return 0;

Compiled code like this:
nvcc x.cu -arch=sm_35

The program printed nothing.

I used K20m + CUDA 5.5 + SLES11 SP2.

BTW: I found the printf can work fine in 1D blocks.

Why not in 2D blocks?


in my experience when the printf is not done it is because it is not executed. Your kernel is very simple and I do not see any reason why it is should not run, so maybe the printf is optimized, because there are not calculations.

The simpler kernel with only one “printf(“Hello”);” statement was tested in 1d block.
It worked fine in my system.

This means your kernel is not executed.

Your grid is invalid:

dim3 dimGrid(1, 0, 0);

should be

dim3 dimGrid(1, 1, 1);