In my original GPU code using cupy
, I have multiple intermediate functions which do some computation and return the results. As a MWE
, I have the code below in which foo()
requires the variables gc_gpu
and dgc_gpu
to compute the final result. After computing the result, I want to release the device memory hold by the variables gc_gpu
and dgc_gpu
(just like we do in C++ CUDA by calling cudaFree(varName);
). I read the CUPY documentation and tried to use mempool.free_all_blocks()
to release the memory.
QUESTION: Even after using mempool.free_all_blocks()
, the memory is not released (as I verify in the task manager). How can I free the device memory?
import cupy as cp
def foo():
gc_gpu = cp.zeros((51 * 51 * 8 * 101 * 101), dtype=cp.float64)
dgc_gpu = cp.ones((51 * 51 * 8 * 101 * 101), dtype=cp.float64)
result = gc_gpu + dgc_gpu
# free memory
mempool = cp.get_default_memory_pool()
mempool.free_all_blocks()
new_result = result * 2
return new_result
####--------program---------#####
foo = foo()
source https://stackoverflow.com/questions/77341307/cupy-cuda-how-to-free-release-device-memory-using-cupy-python
Comments
Post a Comment