matlab mex-file timing kernel i need to know the time

Hi,
i’m writing a matlab mex-file in cuda. I havo to optimize a kernel execution, so i need to know the time that some parts of the kernel take to execute.
In wich way i can do this?
Thanks

Hi,

You can try the even-based time measuring

/ * initialization */
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
float elapsedTime;

/* Call function on GPU */
cudaEventRecord(start, 0);

Put your kernel call here

cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&elapsedTime, start, stop);

/* Print time */

printf("GPU execution time with event = %f ms\n", elapsedTime );

OR, using a timer:

unsigned int timer = 0;
CUT_SAFE_CALL( cutCreateTimer( &timer ) );
CUT_SAFE_CALL( cutResetTimer( timer ) );


CUT_SAFE_CALL( cutStartTimer( timer ) );

    /* Call function on GPU */
   Put your kernel call here

   CUT_SAFE_CALL( cutStopTimer( timer ) );

   printf("GPU execution time = %f ms\n",cutGetTimerValue( timer ) );

Thanks a lot