@@ -41,16 +41,16 @@ std::shared_ptr<void> GetIpcBasePtr(std::string handle) {
4141 auto baseptr = iter->second .lock ();
4242 if (baseptr) return baseptr;
4343 }
44- // The IpcMemHandle can only open once for the same handle, so here we cache
45- // it .
44+ // The IpcMemHandle can only open once for the same handle,
45+ // so here we cache it here .
4646 void *baseptr = nullptr ;
4747 auto ipc_handle =
4848 reinterpret_cast <const cudaIpcMemHandle_t *>(handle.c_str ());
4949 PADDLE_ENFORCE_GPU_SUCCESS (cudaIpcOpenMemHandle (
5050 &baseptr, *ipc_handle, cudaIpcMemLazyEnablePeerAccess));
5151 // Close ipc handle on the same device.
5252 int device_id = platform::GetCurrentDeviceId ();
53- // Add hooks on deleter ptr .
53+ // Add deleter to close ipc handle .
5454 auto sp = std::shared_ptr<void >(baseptr, [handle, device_id](void *ptr) {
5555 platform::CUDADeviceGuard guard (device_id);
5656 std::lock_guard<std::mutex> lock (ipc_mutex_);
@@ -66,47 +66,11 @@ std::shared_ptr<void> GetIpcBasePtr(std::string handle) {
6666}
6767
6868CudaIpcAllocation::~CudaIpcAllocation () {
69- // platform::CUDADeviceGuard guard(device_id_);
70- // PADDLE_ENFORCE_GPU_SUCCESS(cudaIpcCloseMemHandle(this->ptr()));
7169 shared_ptr_.reset ();
7270 VLOG (6 ) << " tensor deleted cudaIpcCloseMemHandle for ptr:"
7371 << " \t " << this ->ptr ();
7472}
7573
76- CudaIpcHandleSet &CudaIpcHandleSet::Instance () { // NOLINT
77- static CudaIpcHandleSet set;
78- return set;
79- }
80-
81- void CudaIpcHandleSet::Insert (const std::string &ipc_handle) {
82- std::lock_guard<std::mutex> guard (mtx_);
83- handle_set_.emplace (ipc_handle);
84- VLOG (3 ) << " PID: " << getpid () << " , CudaIpcHandleSet: insert " << ipc_handle
85- << " , set size: " << handle_set_.size ();
86- }
87-
88- void CudaIpcHandleSet::Remove (const std::string &ipc_handle) {
89- std::lock_guard<std::mutex> guard (mtx_);
90- handle_set_.erase (ipc_handle);
91- VLOG (3 ) << " PID: " << getpid () << " , CudaIpcHandleSet: erase " << ipc_handle
92- << " , set size: " << handle_set_.size ();
93- }
94-
95- void CudaIpcHandleSet::Clear () {
96- VLOG (3 ) << " PID: " << getpid () << " , CudaIpcHandleSet: set size - "
97- << handle_set_.size ();
98- std::lock_guard<std::mutex> guard (mtx_);
99- for (auto fd : handle_set_) {
100- int rlt = shm_unlink (fd.c_str ());
101- if (rlt == 0 ) {
102- VLOG (3 ) << " PID: " << getpid () << " , CudaIpcHandleSet: clear " << fd;
103- }
104- }
105- handle_set_.clear ();
106- }
107-
108- CudaIpcHandleSet::~CudaIpcHandleSet () { Clear (); }
109-
11074} // namespace allocation
11175} // namespace memory
11276} // namespace paddle
0 commit comments