#include<sys/time.h>structtimevalt1,t2;gettimeofday(&t1,0);kernel_call<<<dimGrid,dimBlock,0>>>();gpuErrchk(cudaThreadSynchronize());gettimeofday(&t2,0);doubletime=(1000000.0*(t2.tv_sec-t1.tv_sec)+t2.tv_usec-t1.tv_usec)/1000000.0;printf("Time to generate: %3.1f ms \n",time);
or:
1234567891011121314
floattime;cudaEvent_tstart,stop;gpuErrchk(cudaEventCreate(&start));gpuErrchk(cudaEventCreate(&stop));gpuErrchk(cudaEventRecord(start,0));kernel_call<<<dimGrid,dimBlock,0>>>();gpuErrchk(cudaEventRecord(stop,0));gpuErrchk(cudaEventSynchronize(stop));gpuErrchk(cudaEventElapsedTime(&time,start,stop));printf("Time to generate: %3.1f ms \n",time);