You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Operating System / Platform => Windows 10 64-Bit , CUDA 8.0
Compiler => Visual Studio 2015
Detailed description
If I call cv::cuda::Stream::Null() in my code, it seems it calls cudaMalloc() without freeing the allocated memory, resulting in a memory leak error when tested with the command line memory checker cuda-memcheck --leak-check full.
The GPU memory allocated with cudaMalloc is intended to be destroyed in the destructor of DefaultDeviceInitializer, which, in turn, calls MemoryPool::release().
Experiment
When I added cudaSafeCall to cudaFree in MemoryPool::release(), which is responsible for deallocating the GPU memory, it returned driver shutting down (cudaErrorCudartUnloading = 29) error code.
Reasoning
With help from this and this, it seems that cuda runtime environment has been shut down before the destructor of DefaultDeviceInitializer is called. This should be the reason why driver shutting down (cudaErrorCudartUnloading = 29) error was returned in the experiment.
CUDA context being destroyed before cudaFree is called, cuda-memcheck may assume this situation as memory leak.
Solutions
(Option 1) Do not use a global instance that de-allocates CUDA memory in its destructor. This is already mentioned in the OpenCV doc for GpuMat, that says:
You are not recommended to leave static or global GpuMat variables allocated, that is, to rely on its destructor. The destruction order of such variables and CUDA context is undefined. GPU memory release function returns error if the CUDA context has been destroyed before.
(Option 2) Do not pre-allocate CUDA memory for each Stream object, so that the de-allocation does not happen at the destructor of a global instance. The merged PR that fixes this issue takes this path.
System information (version)
Detailed description
If I call
cv::cuda::Stream::Null()
in my code, it seems it callscudaMalloc()
without freeing the allocated memory, resulting in a memory leak error when tested with the command line memory checkercuda-memcheck --leak-check full
.Steps to reproduce
If you profile above code with
nvprof
then it callscudaMalloc()
without anycudaFree()
followed.The text was updated successfully, but these errors were encountered: