From e077678c5d7cb5c5c9de6e641dd7d8b2cb95515e Mon Sep 17 00:00:00 2001 From: ronnywang Date: Wed, 10 May 2023 14:09:20 +0800 Subject: [PATCH] [CustomDevice] fix reducer when input on cpu (#53662) --- paddle/fluid/distributed/collective/reducer.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/distributed/collective/reducer.cc b/paddle/fluid/distributed/collective/reducer.cc index 260da509a17..b06ed3578df 100644 --- a/paddle/fluid/distributed/collective/reducer.cc +++ b/paddle/fluid/distributed/collective/reducer.cc @@ -215,7 +215,11 @@ struct ConcatTensorsForAllReduce { const uint8_t *in_data = reinterpret_cast(tensor.data()); auto sz = tensor.numel() * sizeof(T); - device->MemoryCopyD2D(out_data + offset, in_data, sz, &stream); + if (tensor.place().GetType() == phi::AllocationType::CPU) { + device->MemoryCopyH2D(out_data + offset, in_data, sz, &stream); + } else { + device->MemoryCopyD2D(out_data + offset, in_data, sz, &stream); + } offset += sz; } } @@ -237,7 +241,11 @@ struct SplitTensorsForAllReduce { for (auto &tensor : *p_dense_tensors) { uint8_t *out_data = reinterpret_cast(tensor.data()); auto sz = tensor.numel() * sizeof(T); - device->MemoryCopyD2D(out_data, in_data + offset, sz, &stream); + if (tensor.place().GetType() == phi::AllocationType::CPU) { + device->MemoryCopyD2H(out_data, in_data + offset, sz, &stream); + } else { + device->MemoryCopyD2D(out_data, in_data + offset, sz, &stream); + } offset += sz; } } -- GitLab