현재 CUDA 이벤트를 사용하는 두 개와 다른 레코딩 시작 및 종료 UNIX를 사용하여 경과 시간을 측정하는 세 가지 방법이 있습니다. CUDA 이벤트를 사용하는 것은 두 가지를 측정합니다. 하나는 전체 외부 루프 시간을 측정하고 다른 하나는 모든 커널 실행 시간을 합한 것입니다.CUDA 프로그램과 CUDA 커널의 경과 시간을 측정하는 데 문제가 있습니다
int64 x1, x2;
cudaEvent_t start;
cudaEvent_t end;
cudaEvent_t s1, s2;
float timeValue;
#define timer_s cudaEventRecord(start, 0);
#define timer_e cudaEventRecord(end, 0); cudaEventSynchronize(end); cudaEventElapsedTime(&timeValue, start, end); printf("time: %f ms \n", timeValue);
cudaEventCreate(&start);
cudaEventCreate(&end);
cudaEventCreate(&s1);
cudaEventCreate(&s2);
cudaEventRecord(s1, 0);
x1 = GetTimeMs64();
for(int r = 0 ; r < 2 ; r++)
{
timer_s
kernel1<<<1, x>>>(gl_devdata_ptr);
cudaThreadSynchronize();
timer_e
sum += timeValue;
for(int j = 0 ; j < 5; j++)
{
timer_s
kernel2<<<1,x>>>(gl_devdata_ptr);
cudaThreadSynchronize();
timer_e
sum += timeValue;
timer_s
kernel3<<<1,x>>>(gl_devdata_ptr);
cudaThreadSynchronize();
timer_e
sum += timeValue;
}
timer_s
kernel4<<<y, x>>> (gl_devdata_ptr);
cudaThreadSynchronize();
timer_e
sum += timeValue;
}
x2 = GetTimeMs64();
cudaEventRecord(s2, 0);
cudaEventSynchronize(s2);
cudaEventElapsedTime(&timeValue, s1, s2);
printf("elapsed cuda : %f ms \n", timeValue);
printf("elapsed sum : %f ms \n", sum);
printf("elapsed win : %d ms \n", x2-x1);
GetTimeMs64는 I에 유래에 여기 뭔가 : 여기
코드의 사람들은 실제 변수 이름도 올바른 커널 이름없는int64 GetTimeMs64()
{
/* Windows */
FILETIME ft;
LARGE_INTEGER li;
uint64 ret;
/* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and copy it
* to a LARGE_INTEGER structure. */
GetSystemTimeAsFileTime(&ft);
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
ret = li.QuadPart;
ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */
ret /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */
return ret;
}
, 난 그냥 제거 어떤 코드를 더 작게 만들 수 있습니다.
문제는 모든 측정 값이 나에게 실제로 다른 총 시간을 제공한다는 것입니다.
몇 가지 예는 그냥 실행 :
elapsed cuda : 21.076832
elapsed sum : 4.177984
elapsed win : 27
왜 그런 엄청난 차이가? 모든 커널 호출의 합계는 약 4ms이며, 다른 18ms는 어디입니까? CPU 시간?
답변을 읽은 후 QueryPerformanceCounter를 시도해 보았고 여기에서 함수를 얻었습니다. http://stackoverflow.com/questions/1739259/how-to-use-queryperformancecounter 감사합니다. – hfingler