File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -14,22 +14,21 @@ class NanosleepKernel:
1414 Manages a kernel that sleeps for a specified duration using clock64().
1515 """
1616
17- def __init__ (self , device , sleep_duration_ms = 20 ):
17+ def __init__ (self , device , sleep_duration_ms : int = 20 ):
1818 """
1919 Initialize the nanosleep kernel.
2020
2121 Args:
2222 device: CUDA device to compile the kernel for
2323 sleep_duration_ms: Duration to sleep in milliseconds (default: 20)
2424 """
25- # clock_rate is in kHz
26- sleep_cycles = int (sleep_duration_ms * device .properties .clock_rate ) + 1
2725 code = f"""
2826 extern "C"
2927 __global__ void nanosleep_kernel() {{
30- long long int start = clock64();
31- while (clock64() - start < { sleep_cycles } ) {{
32- __nanosleep(1000000); // 1 ms yield to avoid 100% spin
28+ // The maximum sleep duration is approximately 1 millisecond.
29+ unsigned int one_ms = 1000000U;
30+ for (unsigned int i = 0; i < { sleep_duration_ms } ; ++i) {{
31+ __nanosleep(one_ms);
3332 }}
3433 }}
3534 """
You can’t perform that action at this time.
0 commit comments