void timeIt(void (*fn)(), string name){
float elapsedTime=0.0;
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start,0);
fn();
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);//remember kernels run asynchronously
cudaEventElapsedTime(&elapsedTime, start, stop);
cout<<"Execution of "<<name<<" took "<<elapsedTime<<" milliseconds."<<endl;
}
The method 'timeIt' takes as its input a function pointer and a string with the name of the method to be called. Then the proper cuda events are created, and the method called while the timer runs. While this is straightfoward it is the first time I have actually used function pointers. A more detailed treatment of them can be found here
No comments:
Post a Comment