Improved CUDA resource handling.

Per
https://developer.nvidia.com/content/cuda-pro-tip-clean-after-yourself-ensure-correct-profiling