对这一问题的回答表明,使用%globaltimer
登记册来衡量在加澳新集团中过久的时间。 我决定尝试:
#define NS_PER_S 1000000000
__global__ void sleepKernel() {
uint64_t start, end;
uint64_t sleepTime = 5 * NS_PER_S; // Sleep for 5 seconds
if (threadIdx.x == 0) {
// Record start time
asm volatile("mov.u64 %0, %%globaltimer;" : "=l"(start));
// Sleep for 5 seconds
__nanosleep(sleepTime);
// Record end time
asm volatile("mov.u64 %0, %%globaltimer;" : "=l"(end));
// Calculate and print the elapsed time in nanoseconds and milliseconds
uint64_t elapsedNs = end - start;
double elapsedMs = (double)elapsedNs / 1000000.0;
printf("Slept for %llu nanoseconds (%.3f milliseconds)
", elapsedNs, elapsedMs);
}
}
但是,当我说这nel的时候,产出就象:
slept for 73728 nanoseconds (0.074 milliseconds)
slept for 471040 nanoseconds (0.471 milliseconds)
两者都小于5秒。 我失踪了吗?
<><>Edit>: do:
uint64_t sleepTime = 5 * (uint64_t)NS_PER_S; // Sleep for 5 seconds
帮助了一条轨道(防止喷气的溢流),但是,它就足够了。