What will happen if I create interprocess memory by cudaIpcGetMemHandle while no other program process it?

will GPU recycle the interprocess memory in kind of GC?

cudaIpcGetMemHandle is part of a C++ api/library. There is no inherent garbage collection or ref counting.

A principal purpose of the CUDA IPC API is to allow for one process to allocate device memory and then to share that allocation with another process. Therefore we will consider two processes A and B. Process A allocates device memory via cudaMalloc and then prepares to share it with another process (B) via a handle retrieved via cudaIpcGetMemHandle.

Those resources (the handle, and the underlying memory allocation) will exist until process A does something explicit to eliminate them:

  • call cudaFree on the underlying allocation created by cudaMalloc
  • terminate

When either one of those occurs, the resources are no longer usable by process B. If process A doesn’t take either one of those steps, the resources will remain, whether another process actually uses them, or not.

Do you mean that only process A can call cudafree to free
memory ? can process B call cudafree to free the shared memory ?

If process A did the cudaMalloc operation, then process A needs to do the cudaFree operation. If process A terminates for any reason, and the cudaFree operation has not been performed yet, then the cudaFree operation will be done, automatically, at that point of process A termination.

ok ,thanks