diff options
author | ztong <ztong@cs.unc.edu> | 2021-06-12 17:08:01 -0400 |
---|---|---|
committer | ztong <ztong@cs.unc.edu> | 2021-06-12 17:08:01 -0400 |
commit | bbaa2b43b6efdd175b26bced3b0d95315b4dcdc1 (patch) | |
tree | 69bb17150df6ffc34727df0c5dbb382db8345dbf /bin/cuda_loop.cu | |
parent | cd4c9a86e447690fe1b66545b9c141432f017237 (diff) |
Added GPU spinning in critical sections for rtspinecrts21
Diffstat (limited to 'bin/cuda_loop.cu')
-rw-r--r-- | bin/cuda_loop.cu | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/bin/cuda_loop.cu b/bin/cuda_loop.cu new file mode 100644 index 0000000..0ddbf9c --- /dev/null +++ b/bin/cuda_loop.cu | |||
@@ -0,0 +1,29 @@ | |||
1 | #include <inttypes.h> | ||
2 | #include <cuda_runtime_api.h> | ||
3 | |||
4 | __device__ inline uint64_t GlobalTimer64(void) { | ||
5 | volatile uint64_t time; | ||
6 | asm volatile("mov.u64 %0, %%globaltimer;" : "=l"(time)); | ||
7 | return time; | ||
8 | } | ||
9 | |||
10 | __global__ void cuda_loop(int cs_length) { | ||
11 | uint64_t start_time = GlobalTimer64(); | ||
12 | int ms2ns = 1000000; | ||
13 | while (GlobalTimer64() - start_time < cs_length * ms2ns) { | ||
14 | continue; | ||
15 | } | ||
16 | } | ||
17 | |||
18 | extern "C" void gpu_loop_start(int cs_length) { | ||
19 | cuda_loop<<<1, 1>>>(0.95 * cs_length); | ||
20 | } | ||
21 | |||
22 | extern "C" void wait_for_gpu_loop_end(void) { | ||
23 | cudaDeviceSynchronize(); | ||
24 | } | ||
25 | |||
26 | extern "C" void init_gpu_context(int* dev_mem) { | ||
27 | cudaSetDeviceFlags(2); | ||
28 | cudaMalloc(&dev_mem, 8); | ||
29 | } | ||