forked from torch/cutorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a CUDA "sleep" kernel which spins for the given number of iterations. This is useful for testing correct synchronization with streams.
- Loading branch information
Showing
5 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "THCSleep.h" | ||
|
||
|
||
__global__ void spin_kernel(long long cycles) | ||
{ | ||
// see concurrentKernels CUDA sampl | ||
long long start_clock = clock64(); | ||
long long clock_offset = 0; | ||
while (clock_offset < cycles) | ||
{ | ||
clock_offset = clock64() - start_clock; | ||
} | ||
} | ||
|
||
THC_API void THC_sleep(THCState* state, long long cycles) | ||
{ | ||
dim3 grid(1); | ||
dim3 block(1); | ||
spin_kernel<<<grid, block, 0, THCState_getCurrentStream(state)>>>(cycles); | ||
THCudaCheck(cudaGetLastError()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef THC_SPIN_INC | ||
#define THC_SPIN_INC | ||
|
||
#include "THCGeneral.h" | ||
#include <time.h> | ||
|
||
// enqueues a kernel that spins for the specified number of cycles | ||
THC_API void THC_sleep(THCState* state, long long cycles); | ||
|
||
#endif |