CUDA Access violation in cudaDeviceReset after calling cudaFreeAsync

Viewed 57

During experimenting with CUDA streams and asynchronous memory operations, I stumbled over some weird behavior.

Calling cudaDeviceReset throws an Unhandled exception at 0x0000000000000000 in test.exe: 0xC0000005: Access violation reading location 0x0000000000000000., if previously cudaFreeAsync was called, to free allocated memory by cudaMallocAsync using NSight next-gen debugger. Without calling cudaFreeAsync there is no error thrown in cudaDeviceReset. It feels wrong to not free allocated memory and think I made a mistake I oversee.

A simple example to reproduce this behavior

cudaStream_t stream;
cudaStreamCreate(&stream);
void* some_data;
cudaMallocAsync(&some_data, 123, stream);
cudaFreeAsync(some_data, stream);
cudaStreamSynchronize(stream);
cudaStreamDestroy(stream);
cudaDeviceReset(); // <-- Unhandled exception at 0x0000000000000000 in test.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

Without freeing memory, no error occurs

cudaStream_t stream;
cudaStreamCreate(&stream);
void* some_data;
cudaMallocAsync(&some_data, 123, stream);
//cudaFreeAsync(some_data, stream);
cudaStreamSynchronize(stream);
cudaStreamDestroy(stream);
cudaDeviceReset(); // no error

Using cudaFree works without any exception, but I would like to use non-blocking version, to avoid to sequentially sum up blocking times in a multi streams scenario.

0 Answers
Related