Skip to content

Commit 075b717

Browse files
committed
add dtor log messages
1 parent df60183 commit 075b717

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

torchvision/csrc/io/image/cuda/encode_jpegs_cuda.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,31 +146,39 @@ CUDAJpegEncoder::~CUDAJpegEncoder() {
146146
// We run cudaGetDeviceCount as a dummy to test if the CUDA runtime is still
147147
// initialized. If it is not, we can skip the rest of this function as it is
148148
// unsafe to execute.
149+
150+
std::cout << "CUDAJpegEncoder dtor: checking if CUDA runtime is still alive"
151+
<< std::endl;
149152
int deviceCount = 0;
150153
cudaError_t error = cudaGetDeviceCount(&deviceCount);
151-
if (error != cudaSuccess)
154+
if (error != cudaSuccess) {
155+
std::cout << "CUDAJpegEncoder dtor: CUDA already shut down" << std::endl;
152156
return; // CUDA runtime has already shut down. There's nothing we can do
153157
// now.
158+
}
154159

155160
nvjpegStatus_t status;
156161

162+
std::cout << "CUDAJpegEncoder dtor: 1" << std::endl;
163+
157164
status = nvjpegEncoderParamsDestroy(nv_enc_params);
158165
TORCH_CHECK(
159166
status == NVJPEG_STATUS_SUCCESS,
160167
"Failed to destroy nvjpeg encoder params: ",
161168
status);
162-
169+
std::cout << "CUDAJpegEncoder dtor: 2" << std::endl;
163170
status = nvjpegEncoderStateDestroy(nv_enc_state);
164171
TORCH_CHECK(
165172
status == NVJPEG_STATUS_SUCCESS,
166173
"Failed to destroy nvjpeg encoder state: ",
167174
status);
168175

169176
cudaStreamSynchronize(stream);
170-
177+
std::cout << "CUDAJpegEncoder dtor: 3" << std::endl;
171178
status = nvjpegDestroy(nvjpeg_handle);
172179
TORCH_CHECK(
173180
status == NVJPEG_STATUS_SUCCESS, "nvjpegDestroy failed: ", status);
181+
std::cout << "CUDAJpegEncoder dtor: 4" << std::endl;
174182
}
175183

176184
torch::Tensor CUDAJpegEncoder::encode_jpeg(const torch::Tensor& src_image) {

0 commit comments

Comments
 (0)