From f3c8a72001e362f816de0191435f1d7e793f2eaa Mon Sep 17 00:00:00 2001 From: Dominik Kallusky Date: Wed, 12 Jun 2024 13:06:57 -0700 Subject: [PATCH] add dtor log messages --- .../csrc/io/image/cuda/encode_jpegs_cuda.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/torchvision/csrc/io/image/cuda/encode_jpegs_cuda.cpp b/torchvision/csrc/io/image/cuda/encode_jpegs_cuda.cpp index 960669554ac..b1826e43900 100644 --- a/torchvision/csrc/io/image/cuda/encode_jpegs_cuda.cpp +++ b/torchvision/csrc/io/image/cuda/encode_jpegs_cuda.cpp @@ -146,20 +146,28 @@ CUDAJpegEncoder::~CUDAJpegEncoder() { // We run cudaGetDeviceCount as a dummy to test if the CUDA runtime is still // initialized. If it is not, we can skip the rest of this function as it is // unsafe to execute. + + std::cout << "CUDAJpegEncoder dtor: checking if CUDA runtime is still alive" + << std::endl; int deviceCount = 0; cudaError_t error = cudaGetDeviceCount(&deviceCount); - if (error != cudaSuccess) + if (error != cudaSuccess) { + std::cout << "CUDAJpegEncoder dtor: CUDA already shut down" << std::endl; return; // CUDA runtime has already shut down. There's nothing we can do // now. + } nvjpegStatus_t status; + std::cout << "CUDAJpegEncoder dtor: 1" << std::endl; + status = nvjpegEncoderParamsDestroy(nv_enc_params); + std::cout << "status: " << status << std::endl; TORCH_CHECK( status == NVJPEG_STATUS_SUCCESS, "Failed to destroy nvjpeg encoder params: ", status); - + std::cout << "CUDAJpegEncoder dtor: 2" << std::endl; status = nvjpegEncoderStateDestroy(nv_enc_state); TORCH_CHECK( status == NVJPEG_STATUS_SUCCESS, @@ -167,10 +175,11 @@ CUDAJpegEncoder::~CUDAJpegEncoder() { status); cudaStreamSynchronize(stream); - + std::cout << "CUDAJpegEncoder dtor: 3" << std::endl; status = nvjpegDestroy(nvjpeg_handle); TORCH_CHECK( status == NVJPEG_STATUS_SUCCESS, "nvjpegDestroy failed: ", status); + std::cout << "CUDAJpegEncoder dtor: 4" << std::endl; } torch::Tensor CUDAJpegEncoder::encode_jpeg(const torch::Tensor& src_image) {