using cudaEvent no elapsed time given

im trying to rework one of the SDK examples to give me the elapsed time using cudaEvent functions

cudaEvent_t start, stop;

cudaEventCreate(&start);

cudaEventCreate(&stop);

cudaEventRecord(start,0);

/*.......*/

/* CODE HERE */

/*.......*/

cudaEventRecord(stop,0);

cudaEventSynchronize(stop);

float elapsedTime;

cudaEventElapsedTime(&elapsedTime, start, stop);

printf("Elapsed time: %f\n",elapsedTime);

But the result is that it always prints

Elapsed time: 0.000000

and yes, the code is executed over a period of time, so no elapsed time should be possible.

Can anyone think as to why it is doing this? how can i get elapsed time to work?

code here means you are calling a kernel?
Cudaevents measure time on GPU.

I think for your purpose this should help:

unsigned int timer = 0;

	CUT_SAFE_CALL(cutCreateTimer(&timer));

	CUT_SAFE_CALL(cutStartTimer(timer));

	// SOME COMPUTATIONS

 // On kernal or host (doesn't matter)

	CUT_SAFE_CALL( cutStopTimer( timer));

	printf( "\nCPU Processing time: %f (ms)\n\n", cutGetTimerValue( timer));

	CUT_SAFE_CALL( cutDeleteTimer( timer));

Cheers