diff options
| author | Joshua Bakita <bakitajoshua@gmail.com> | 2024-02-19 20:39:39 -0500 |
|---|---|---|
| committer | Joshua Bakita <bakitajoshua@gmail.com> | 2024-02-19 20:39:39 -0500 |
| commit | cd9ee070e2fcaa49fe35944ea0fd60ed5d197ba2 (patch) | |
| tree | cb31473e1793e383a06dd0b560c7ab83374040ff /copy_experiments/mon_cross_ctx_copies.cu | |
| parent | 18641058a2d60e172f18176b41d51baa706ffd85 (diff) | |
Split SAFE() macro into API-specific typed variants
Avoids incorrectly interpreting CUDA Driver Library error codes as
though they were CUDA Runtime Library error codes (the numbering is
similar, but not identical).
Also cleans up how we initialize and terminate a context for
capability checking in `mon_cross_ctx_copies`.
Diffstat (limited to 'copy_experiments/mon_cross_ctx_copies.cu')
| -rw-r--r-- | copy_experiments/mon_cross_ctx_copies.cu | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/copy_experiments/mon_cross_ctx_copies.cu b/copy_experiments/mon_cross_ctx_copies.cu index d9749e0..93d0e4c 100644 --- a/copy_experiments/mon_cross_ctx_copies.cu +++ b/copy_experiments/mon_cross_ctx_copies.cu | |||
| @@ -92,7 +92,6 @@ void cpu_copy_mon(int loops, char* cpu_mem) { | |||
| 92 | void* copy_thread(void* args_raw) { | 92 | void* copy_thread(void* args_raw) { |
| 93 | CUcontext ctx; | 93 | CUcontext ctx; |
| 94 | int dev, i; | 94 | int dev, i; |
| 95 | cudaError_t err; | ||
| 96 | int *barrier; | 95 | int *barrier; |
| 97 | int *barrier_dev_ptr; // On Pascal+ this will be the same as *barrier | 96 | int *barrier_dev_ptr; // On Pascal+ this will be the same as *barrier |
| 98 | char *pinned_hostmem, *devmem; | 97 | char *pinned_hostmem, *devmem; |
| @@ -106,8 +105,8 @@ void* copy_thread(void* args_raw) { | |||
| 106 | // Explictly create a context (avoids creating a primary context implictly) | 105 | // Explictly create a context (avoids creating a primary context implictly) |
| 107 | // This has been verified on CUDA 11.1 to give each thread a different context | 106 | // This has been verified on CUDA 11.1 to give each thread a different context |
| 108 | // handle | 107 | // handle |
| 109 | cudaGetDevice(&dev); | 108 | SAFE(cudaGetDevice(&dev)); |
| 110 | SAFE(cuCtxCreate(&ctx, 0, dev)); | 109 | SAFE_D(cuCtxCreate(&ctx, 0, dev)); |
| 111 | 110 | ||
| 112 | uint64_t dev_ns, dev_ns2; | 111 | uint64_t dev_ns, dev_ns2; |
| 113 | double host_s, host_s2; | 112 | double host_s, host_s2; |
| @@ -249,21 +248,27 @@ static error_t arg_parser(int key, char* arg, struct argp_state *state) { | |||
| 249 | } | 248 | } |
| 250 | 249 | ||
| 251 | int main(int argc, char**argv) { | 250 | int main(int argc, char**argv) { |
| 252 | int tmp, dev; | 251 | int tmp, dev = 0; |
| 252 | CUdevice dev_itrl; | ||
| 253 | uint64_t *ctx_times[MAX_THREADS] = {0}; | 253 | uint64_t *ctx_times[MAX_THREADS] = {0}; |
| 254 | pthread_t t[MAX_THREADS]; | 254 | pthread_t t[MAX_THREADS]; |
| 255 | global_args_t g_args = {0}; | 255 | global_args_t g_args = {0}; |
| 256 | 256 | ||
| 257 | // Temporarially initialize CUDA to query device attributes | ||
| 258 | SAFE_D(cuInit(0)); | ||
| 259 | SAFE_D(cuDeviceGet(&dev_itrl, dev)); | ||
| 257 | // Due to some laziness in how we handle barriers, this flag needs to be true | 260 | // Due to some laziness in how we handle barriers, this flag needs to be true |
| 258 | /// XXX: Still seems to work fine if it isn't??? | 261 | /// XXX: Still seems to work fine if it isn't??? |
| 259 | cudaGetDevice(&dev); | 262 | SAFE_D(cuDeviceGetAttribute(&tmp, CU_DEVICE_ATTRIBUTE_CAN_MAP_HOST_MEMORY, dev_itrl)); |
| 260 | cudaDeviceGetAttribute(&tmp, cudaDevAttrCanMapHostMemory, dev); | ||
| 261 | if (!tmp) { | 263 | if (!tmp) { |
| 262 | fprintf(stderr, "Unsupported platform. It must be possible to map host (CPU)" | 264 | fprintf(stderr, "Unsupported platform. It must be possible to map host (CPU)" |
| 263 | "DRAM into the GPU virtual address space for accurate clock" | 265 | " DRAM into the GPU virtual address space for accurate clock " |
| 264 | "synchronization. Exiting...\n"); | 266 | "synchronization. Exiting...\n"); |
| 265 | return 1; | 267 | return 1; |
| 266 | } | 268 | } |
| 269 | // Terminate the context used for attrib check so it's not accidentially | ||
| 270 | // reused in subprocesses | ||
| 271 | SAFE_D(cuDevicePrimaryCtxRelease(dev_itrl)); | ||
| 267 | 272 | ||
| 268 | struct argp argp = {opts, arg_parser, 0, desc}; | 273 | struct argp argp = {opts, arg_parser, 0, desc}; |
| 269 | argp_parse(&argp, argc, argv, 0, 0, &g_args); | 274 | argp_parse(&argp, argc, argv, 0, 0, &g_args); |
