├── README.md └── cudaprofile.py /README.md: -------------------------------------------------------------------------------- 1 | Wrapper for CUDA profiler start/stop API functions. Zero dependencies. 2 | 3 | Example: 4 | ```python 5 | import cudaprofile 6 | 7 | cudaprofile.start() 8 | # ... do expensive cuda stuff ... 9 | cudaprofile.stop() 10 | ``` 11 | and run the script from `nvprof` or `nvvp`. 12 | 13 | You may want to use `nvprof` with `--profile-from-start-off` and only call `start()` when desired. 14 | -------------------------------------------------------------------------------- /cudaprofile.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | 3 | _cudart = ctypes.CDLL('libcudart.so') 4 | 5 | 6 | def start(): 7 | # As shown at http://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__PROFILER.html, 8 | # the return value will unconditionally be 0. This check is just in case it changes in 9 | # the future. 10 | ret = _cudart.cudaProfilerStart() 11 | if ret != 0: 12 | raise Exception("cudaProfilerStart() returned %d" % ret) 13 | 14 | def stop(): 15 | ret = _cudart.cudaProfilerStop() 16 | if ret != 0: 17 | raise Exception("cudaProfilerStop() returned %d" % ret) 18 | 19 | 20 | --------------------------------------------------------------------------------