Skip to content

Commit

Permalink
add dtor log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
deekay42 committed Jun 12, 2024
1 parent df60183 commit f3c8a72
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions torchvision/csrc/io/image/cuda/encode_jpegs_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,31 +146,40 @@ 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,
"Failed to destroy nvjpeg encoder state: ",
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) {
Expand Down

0 comments on commit f3c8a72

Please sign in to comment.