Skip to content

Commit 85f807d

Browse files
committed
add support for CUDAPinnedPlace.
1 parent 51c49ac commit 85f807d

File tree

4 files changed

+135
-159
lines changed

4 files changed

+135
-159
lines changed

paddle/fluid/memory/allocation/cuda_ipc_allocator.cc

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6868
CudaIpcAllocation::~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

paddle/fluid/memory/allocation/cuda_ipc_allocator.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,6 @@ class CudaIpcAllocation : public Allocation {
4848
std::shared_ptr<void> shared_ptr_;
4949
};
5050

51-
class CudaIpcHandleSet {
52-
public:
53-
static CudaIpcHandleSet &Instance(); // NOLINT
54-
55-
void Insert(const std::string &ipc_handle);
56-
57-
void Remove(const std::string &ipc_handle);
58-
59-
void Clear();
60-
61-
~CudaIpcHandleSet();
62-
63-
private:
64-
CudaIpcHandleSet() = default;
65-
66-
std::unordered_set<std::string> handle_set_;
67-
std::mutex mtx_;
68-
};
69-
7051
} // namespace allocation
7152
} // namespace memory
7253
} // namespace paddle

0 commit comments

Comments
 (0)