CUDA學習筆記4:CUDA(英偉達顯卡統一計算架構)代碼運行時間測試

CUDA內核運行時間的測量函數

cudaEvent_t start1; cudaEventCreate(&start1); cudaEvent_t stop1; cudaEventCreate(&stop1); cudaEventRecord(start1, NULL); // 須要測時間的內核函數kernel;
cudaEventRecord(stop1, NULL); cudaEventSynchronize(stop1); float msecTotal1 = 0.0f; cudaEventElapsedTime(&msecTotal1, start1, stop1);

CPU運行時間的測量函數

long start_time = GetTickCount();//記錄程序運行時間 //須要測試時間的代碼
long end_time = GetTickCount();//記錄程序運行時間
cout << "程序段運行時間:" << (end_time - start_time) << "ms!" << endl;
相關文章
相關標籤/搜索