File tree Expand file tree Collapse file tree 2 files changed +6
-0
lines changed
paddle/fluid/memory/allocation Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ void NPUPinnedAllocator::ProcessEventsAndFree() {
3939}
4040
4141Allocation *NPUPinnedAllocator::AllocateImpl (size_t size) {
42+ std::lock_guard<std::mutex> lock (mtx_);
4243 ProcessEventsAndFree ();
4344 void *ptr;
4445 int error = posix_memalign (&ptr, kAlignment , size);
@@ -50,6 +51,7 @@ Allocation *NPUPinnedAllocator::AllocateImpl(size_t size) {
5051}
5152
5253void NPUPinnedAllocator::FreeImpl (Allocation *allocation) {
54+ std::lock_guard<std::mutex> lock (mtx_);
5355 void *ptr = allocation->ptr ();
5456 auto iter = npu_events_.find (allocation);
5557 aclrtEvent event = iter->second ;
@@ -65,11 +67,14 @@ void NPUPinnedAllocator::FreeImpl(Allocation *allocation) {
6567}
6668
6769uint64_t NPUPinnedAllocator::ReleaseImpl (const platform::Place &place) {
70+ std::lock_guard<std::mutex> lock (mtx_);
71+ // Empty implementation
6872 return static_cast <uint64_t >(0 );
6973}
7074
7175void NPUPinnedAllocator::RecordEvent (Allocation *allocation,
7276 aclrtStream stream) {
77+ std::lock_guard<std::mutex> lock (mtx_);
7378 aclrtEvent event = nullptr ;
7479 PADDLE_ENFORCE_NPU_SUCCESS (aclrtCreateEvent (&event));
7580 PADDLE_ENFORCE_NPU_SUCCESS (aclrtRecordEvent (event, stream));
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ class NPUPinnedAllocator : public Allocator {
4242
4343 private:
4444 std::unordered_map<Allocation *, aclrtEvent> npu_events_;
45+ mutable std::mutex mtx_;
4546};
4647
4748} // namespace allocation
You can’t perform that action at this time.
0 commit comments