basic example

#include <stdio.h>
__global__ void Hello_from_GPU()
{
if (threadIdx.x == 1 && blockIdx.x ==1)
{
printf("hello_from_gpu");
}
else {printf("threads and blocks have irrelevant values");}
}
int main()
{
Hello_from_GPU<<<1,1>>>();
cudaDeviceSynchronize();
}

The question is why this code will never print hello_from_gpu, but will print threads and blocks have irrelevant values ?

but

#include <stdio.h>
__global__ void Hello_from_GPU()
{
if (threadIdx.x == 1 && blockIdx.x ==1)
{
printf("hello_from_gpu");
}
}
int main()
{
Hello_from_GPU<<<256,1024>>>();
cudaDeviceSynchronize();
}

will do

got it, the answer is because of the numeration 1 stands for 0:

#include <stdio.h>
__global__ void Hello_from_GPU()
{
if (threadIdx.x == 0 && blockIdx.x ==0)
{
printf("hello_from_gpu");
}
}
int main()
{
Hello_from_GPU<<<1,1>>>();
cudaDeviceSynchronize();
}