Skip to content

Commit 33c193b

Browse files
committed
refine
1 parent ca4c459 commit 33c193b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

paddle/common/flags.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,3 +1820,8 @@ PHI_DEFINE_EXPORTED_double(accuracy_check_atol_bf16,
18201820
PHI_DEFINE_EXPORTED_double(accuracy_check_rtol_bf16,
18211821
1e-3,
18221822
"It controls the rtol of accuracy_check op");
1823+
1824+
PHI_DEFINE_EXPORTED_bool(
1825+
pinned_memory_as_cpu_backend,
1826+
false,
1827+
"Whether use CPU backend, when tensor is pinned_memory.");

paddle/phi/core/compat/convert_utils.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ limitations under the License. */
1414

1515
#include "paddle/phi/core/compat/convert_utils.h"
1616

17+
#include "paddle/common/flags.h"
1718
#include "paddle/phi/backends/gpu/gpu_info.h"
1819
#include "paddle/phi/backends/xpu/xpu_info.h"
1920
#include "paddle/phi/common/place.h"
2021
#include "paddle/phi/core/compat/op_utils.h"
2122
#include "paddle/phi/core/enforce.h"
22-
2323
#ifdef PADDLE_WITH_CUSTOM_DEVICE
2424
#include "paddle/phi/backends/device_manager.h"
2525
#endif
2626

27+
COMMON_DECLARE_bool(pinned_memory_as_cpu_backend);
28+
2729
namespace phi {
2830

2931
Backend TransToPhiBackend(const phi::Place& place) {
@@ -33,8 +35,13 @@ Backend TransToPhiBackend(const phi::Place& place) {
3335
return Backend::GPU;
3436
case AllocationType::CPU:
3537
return Backend::CPU;
36-
case AllocationType::GPUPINNED:
37-
return Backend::CPU;
38+
case AllocationType::GPUPINNED: {
39+
if (FLAGS_pinned_memory_as_cpu_backend) {
40+
return Backend::CPU;
41+
} else {
42+
return Backend::GPU;
43+
}
44+
}
3845
case AllocationType::XPU:
3946
return Backend::XPU;
4047
case AllocationType::IPU:

0 commit comments

Comments
 (0)