Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about 02_variable_addition_reference.cu #8

Open
tangyipeng100 opened this issue Sep 15, 2021 · 0 comments
Open

Questions about 02_variable_addition_reference.cu #8

tangyipeng100 opened this issue Sep 15, 2021 · 0 comments

Comments

@tangyipeng100
Copy link

I have tested this code. When I remove the blockIdx, such as the code as follows:

__global__ void myfirstkernel(void) {
	//blockIdx.x gives the block number of current kernel
	//printf("Hello!!!I'm thread in block: %d\n", blockIdx.x);
	printf("Hello!!!I'm thread in block: %d\n");
}

int main(void) {
	//A kernel call with 16 blocks and 1 thread per block
	myfirstkernel << <16, 1 >> > ();
	//Function used for waiting for all kernels to finish
	cudaDeviceSynchronize();
	printf("All threads are finished!\n");
	return 0;
}

I can not get the kernel running results as the book shows. Just as:
1111
If add blockIdx back, as printf("Hello!!!I'm thread in block: %d\n", blockIdx.x) then I get the right results.
Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant