/* * Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include using namespace std; #include "gdrapi.h" #include "common.hpp" using namespace gdrcopy::test; // manually tuned... int num_write_iters = 10000; int num_read_iters = 100; int dev_id = 0; bool do_cumemcpy = false; size_t _size = (size_t)1 << 24; void print_usage(const char *path) { cout << "Usage: " << path << " [-h][-c][-s ][-d ][-w ][-r ][-a ]" << endl; cout << endl; cout << "Options:" << endl; cout << " -h Print this help text" << endl; cout << " -c Also run cuMemcpy (default: no)" << endl; cout << " -s Buffer allocation size (default: " << _size << ")" << endl; cout << " -d GPU ID (default: " << dev_id << ")" << endl; cout << " -w Number of write iterations (default: " << num_write_iters << ")" << endl; cout << " -r Number of read iterations (default: " << num_read_iters << ")" << endl; cout << " -a GPU buffer allocation function (default: cuMemAlloc)" << endl; cout << " Choices: cuMemAlloc, cuMemCreate" << endl; } int main(int argc, char *argv[]) { size_t copy_size = 1; struct timespec beg, end; double lat_us; gpu_memalloc_fn_t galloc_fn = gpu_mem_alloc; gpu_memfree_fn_t gfree_fn = gpu_mem_free; while(1) { int c; c = getopt(argc, argv, "s:d:w:r:a:hc"); if (c == -1) break; switch (c) { case 's': _size = strtol(optarg, NULL, 0); break; case 'd': dev_id = strtol(optarg, NULL, 0); break; case 'w': num_write_iters = strtol(optarg, NULL, 0); break; case 'r': num_read_iters = strtol(optarg, NULL, 0); break; case 'a': if (strcmp(optarg, "cuMemAlloc") == 0) { galloc_fn = gpu_mem_alloc; gfree_fn = gpu_mem_free; } else if (strcmp(optarg, "cuMemCreate") == 0) { galloc_fn = gpu_vmm_alloc; gfree_fn = gpu_vmm_free; } else { cerr << "Unrecognized fn argument" << endl; exit(EXIT_FAILURE); } break; case 'c': do_cumemcpy = true; break; case 'h': print_usage(argv[0]); exit(EXIT_SUCCESS); default: printf("ERROR: invalid option\n"); exit(EXIT_FAILURE); } } size_t size = PAGE_ROUND_UP(_size, GPU_PAGE_SIZE); ASSERTDRV(cuInit(0)); int n_devices = 0; ASSERTDRV(cuDeviceGetCount(&n_devices)); CUdevice dev; for (int n=0; n