From b3fba17ed55a872cd673ccefe891864234b90c16 Mon Sep 17 00:00:00 2001 From: liuyi39 Date: Fri, 31 Oct 2025 13:07:46 +0800 Subject: [PATCH 1/2] [xpu] fix_xpu_pin_memory_stats --- paddle/phi/common/place.cc | 5 +++++ paddle/phi/common/place.h | 1 + paddle/phi/core/memory/allocation/stat_allocator.h | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/paddle/phi/common/place.cc b/paddle/phi/common/place.cc index 0ccfb5f5deea3a..b3648f517c179e 100644 --- a/paddle/phi/common/place.cc +++ b/paddle/phi/common/place.cc @@ -182,6 +182,11 @@ TEST_API bool is_cpu_place(const Place &p) { return p.GetType() == phi::AllocationType::CPU; } +PADDLE_API bool is_pinned_place(const Place &p) { + return p.GetType() == phi::AllocationType::GPUPINNED || + p.GetType() == phi::AllocationType::XPUPINNED; +} + bool is_cuda_pinned_place(const Place &p) { return p.GetType() == phi::AllocationType::GPUPINNED; } diff --git a/paddle/phi/common/place.h b/paddle/phi/common/place.h index 73adc0db949c8d..eca61685859d10 100644 --- a/paddle/phi/common/place.h +++ b/paddle/phi/common/place.h @@ -223,6 +223,7 @@ PADDLE_API bool is_gpu_place(const Place&); PADDLE_API bool is_xpu_place(const Place&); PADDLE_API bool is_ipu_place(const Place&); PADDLE_API bool is_cpu_place(const Place&); +PADDLE_API bool is_pinned_place(const Place&); PADDLE_API bool is_cuda_pinned_place(const Place&); PADDLE_API bool is_xpu_pinned_place(const Place&); PADDLE_API bool is_custom_place(const Place& p); diff --git a/paddle/phi/core/memory/allocation/stat_allocator.h b/paddle/phi/core/memory/allocation/stat_allocator.h index 227cb105d25e87..1a62cfdef7d85d 100644 --- a/paddle/phi/core/memory/allocation/stat_allocator.h +++ b/paddle/phi/core/memory/allocation/stat_allocator.h @@ -32,7 +32,7 @@ class StatAllocator : public Allocator { protected: void FreeImpl(phi::Allocation* allocation) override { if (phi::is_cpu_place(allocation->place()) || - phi::is_cuda_pinned_place(allocation->place())) { + phi::is_pinned_place(allocation->place())) { HOST_MEMORY_STAT_UPDATE( Allocated, allocation->place().GetDeviceId(), -allocation->size()); } else { @@ -51,7 +51,7 @@ class StatAllocator : public Allocator { underlying_allocator_->Allocate(size); const phi::Place& place = allocation->place(); - if (phi::is_cpu_place(place) || phi::is_cuda_pinned_place(place)) { + if (phi::is_cpu_place(place) || phi::is_pinned_place(place)) { HOST_MEMORY_STAT_UPDATE( Allocated, place.GetDeviceId(), allocation->size()); } else { From f1cbc4d8257541ca7248144e9af156169de55c1f Mon Sep 17 00:00:00 2001 From: liuyi39 Date: Thu, 6 Nov 2025 09:47:47 +0000 Subject: [PATCH 2/2] [xpu] fix --- paddle/phi/common/place.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/phi/common/place.cc b/paddle/phi/common/place.cc index b3648f517c179e..f9ab4aed2cf143 100644 --- a/paddle/phi/common/place.cc +++ b/paddle/phi/common/place.cc @@ -182,7 +182,7 @@ TEST_API bool is_cpu_place(const Place &p) { return p.GetType() == phi::AllocationType::CPU; } -PADDLE_API bool is_pinned_place(const Place &p) { +bool is_pinned_place(const Place &p) { return p.GetType() == phi::AllocationType::GPUPINNED || p.GetType() == phi::AllocationType::XPUPINNED; }