tree creation code problem something wrong in the code?

I’m trying to build a tree on my GEForce GT 525M device (supports version 2.0) using the following logic.

The problem is that it doesn’t seem to “get into” the kernel function itself. A blank screen is displayed at output console.

(In a different n simpler code, I’m able to use printf inside the kernel function.)

What might be the problem? Shouldn’t it atleast execute the simple printf statement?

P.S. : I’m a beginner.



using namespace std;

struct node


	int data;

	node *left,*right;


__global__ void build(node * root)


	int arr[]={5,3,8,2,6,7,1,9,4};

	printf("Control in 1st kernel function!");

	root->data = arr[1];

	root->left = root->right=NULL;


__global__ void print(node * root)




int main()


	node *n_h,*n_d;

	size_t size9 = sizeof(node)*9;

	size_t size = sizeof(node);






return 0;


CUDA kernel launches are asynchronous, so one needs to make sure that the device-side printf() buffer is flushed before the app exits. Try putting a call to cudaThreadSynchronize() after the print() kernel launch.

thanks a lot for the quick reply!
using cudaThreadSynchronize() worked for printing!
thanks again.