Skip to content

Commit 3218241

Browse files
authored
[XPU] fix xpu pin_memory stats (PaddlePaddle#76147)
* [xpu] fix_xpu_pin_memory_stats
1 parent 4ddf35b commit 3218241

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

paddle/phi/common/place.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ TEST_API bool is_cpu_place(const Place &p) {
191191
return p.GetType() == phi::AllocationType::CPU;
192192
}
193193

194+
bool is_pinned_place(const Place &p) {
195+
return p.GetType() == phi::AllocationType::GPUPINNED ||
196+
p.GetType() == phi::AllocationType::XPUPINNED;
197+
}
198+
194199
bool is_cuda_pinned_place(const Place &p) {
195200
return p.GetType() == phi::AllocationType::GPUPINNED;
196201
}

paddle/phi/common/place.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ PADDLE_API bool is_gpu_place(const Place&);
225225
PADDLE_API bool is_xpu_place(const Place&);
226226
PADDLE_API bool is_ipu_place(const Place&);
227227
PADDLE_API bool is_cpu_place(const Place&);
228+
PADDLE_API bool is_pinned_place(const Place&);
228229
PADDLE_API bool is_cuda_pinned_place(const Place&);
229230
PADDLE_API bool is_xpu_pinned_place(const Place&);
230231
PADDLE_API bool is_custom_place(const Place& p);

paddle/phi/core/memory/allocation/stat_allocator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class StatAllocator : public Allocator {
3232
protected:
3333
void FreeImpl(phi::Allocation* allocation) override {
3434
if (phi::is_cpu_place(allocation->place()) ||
35-
phi::is_cuda_pinned_place(allocation->place())) {
35+
phi::is_pinned_place(allocation->place())) {
3636
HOST_MEMORY_STAT_UPDATE(
3737
Allocated, allocation->place().GetDeviceId(), -allocation->size());
3838
} else {
@@ -51,7 +51,7 @@ class StatAllocator : public Allocator {
5151
underlying_allocator_->Allocate(size);
5252

5353
const phi::Place& place = allocation->place();
54-
if (phi::is_cpu_place(place) || phi::is_cuda_pinned_place(place)) {
54+
if (phi::is_cpu_place(place) || phi::is_pinned_place(place)) {
5555
HOST_MEMORY_STAT_UPDATE(
5656
Allocated, place.GetDeviceId(), allocation->size());
5757
} else {

0 commit comments

Comments
 (0)