Skip to content

Commit d020f1f

Browse files
co63oclixcli
authored andcommitted
Replace platform::DeviceContextPool [fluid_ops] (PaddlePaddle#65981)
1 parent 24a2330 commit d020f1f

22 files changed

+95
-97
lines changed

paddle/fluid/framework/details/all_reduce_op_handle.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ void AllReduceOpHandle::AllReduceImpl(
143143
in_var_handles[i]->name(),
144144
numel));
145145
dtype = framework::TransToProtoVarType(lod_tensor.dtype());
146-
is_gpu_place = platform::is_gpu_place(lod_tensor.place());
146+
is_gpu_place = phi::is_gpu_place(lod_tensor.place());
147147
#if defined(PADDLE_WITH_XPU_BKCL)
148-
is_xpu_place = platform::is_xpu_place(lod_tensor.place());
148+
is_xpu_place = phi::is_xpu_place(lod_tensor.place());
149149
#endif
150150
}
151151
PADDLE_ENFORCE_EQ(
@@ -162,13 +162,13 @@ void AllReduceOpHandle::AllReduceImpl(
162162
"scopes should be equal."));
163163
#if defined(PADDLE_WITH_XPU_BKCL)
164164
PADDLE_ENFORCE_EQ(is_xpu_place,
165-
platform::is_xpu_place(lod_tensor.place()),
165+
phi::is_xpu_place(lod_tensor.place()),
166166
platform::errors::PreconditionNotMet(
167167
"The place type of tensors of the same variable "
168168
"in different local scopes should be equal."));
169169
#endif
170170
PADDLE_ENFORCE_EQ(is_gpu_place,
171-
platform::is_gpu_place(lod_tensor.place()),
171+
phi::is_gpu_place(lod_tensor.place()),
172172
platform::errors::PreconditionNotMet(
173173
"The place type of tensors of the same variable "
174174
"in different local scopes should be equal."));
@@ -204,7 +204,7 @@ void AllReduceOpHandle::AllReduceFunc(
204204
int64_t numel,
205205
const std::vector<phi::Place> &places,
206206
const std::vector<std::string> &out_var_names) {
207-
if (platform::is_gpu_place(places[0])) {
207+
if (phi::is_gpu_place(places[0])) {
208208
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
209209
PADDLE_ENFORCE_NOT_NULL(nccl_ctxs_,
210210
platform::errors::InvalidArgument(
@@ -223,7 +223,7 @@ void AllReduceOpHandle::AllReduceFunc(
223223
PADDLE_THROW(
224224
platform::errors::PreconditionNotMet("Not compiled with GPU."));
225225
#endif
226-
} else if (platform::is_xpu_place(places[0])) {
226+
} else if (phi::is_xpu_place(places[0])) {
227227
#if defined(PADDLE_WITH_XPU_BKCL)
228228
PADDLE_ENFORCE_NOT_NULL(bkcl_ctxs_,
229229
platform::errors::InvalidArgument(

paddle/fluid/framework/details/broadcast_op_handle.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void BroadcastOpHandle::BroadcastOneVar(
6868

6969
InitOutputValue(in_var_handle, out_var_handles);
7070

71-
if (platform::is_cpu_place(in_tensor.place())) {
71+
if (phi::is_cpu_place(in_tensor.place())) {
7272
WaitInputVarGenerated();
7373
for (auto *out_var_handle : out_var_handles) {
7474
if (out_var_handle->IsTheSameVar(in_var_handle)) {
@@ -85,7 +85,7 @@ void BroadcastOpHandle::BroadcastOneVar(
8585
&VariableVisitor::GetMutableTensor(out_var));
8686
});
8787
}
88-
} else if (platform::is_gpu_place(in_tensor.place())) {
88+
} else if (phi::is_gpu_place(in_tensor.place())) {
8989
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
9090
VarHandle *out_handle = nullptr;
9191
int root_id = in_tensor.place().device; // NOLINT
@@ -249,8 +249,8 @@ void BroadcastOpHandle::InitOutputValue(
249249
out_var,
250250
platform::errors::NotFound("Variable %s is not found in scopes.",
251251
out_var_handle->name()));
252-
if (platform::is_gpu_place(in_tensor.place())) {
253-
PADDLE_ENFORCE_EQ(platform::is_gpu_place(t_out_p),
252+
if (phi::is_gpu_place(in_tensor.place())) {
253+
PADDLE_ENFORCE_EQ(phi::is_gpu_place(t_out_p),
254254
true,
255255
platform::errors::PreconditionNotMet(
256256
"Places of input and output must be all on GPU."));

paddle/fluid/framework/details/eager_deletion_op_handle.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ EagerDeletionOpHandle::EagerDeletionOpHandle(
4242
gc_(gc),
4343
vars_() {
4444
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
45-
if (platform::is_gpu_place(place)) {
45+
if (phi::is_gpu_place(place)) {
4646
dev_ctx_ = reinterpret_cast<phi::GPUContext *>(
47-
platform::DeviceContextPool::Instance().Get(place));
47+
phi::DeviceContextPool::Instance().Get(place));
4848
if (dynamic_cast<StreamGarbageCollector *>(gc_)) {
4949
platform::CUDADeviceGuard guard(place.device);
5050
#ifdef PADDLE_WITH_HIP

paddle/fluid/framework/details/fused_all_reduce_op_handle.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void FusedAllReduceOpHandle::RunImpl() {
9191
platform::errors::Unimplemented(
9292
"FLAGS_allreduce_record_one_event=true is only valid "
9393
"when using one GPU device per process."));
94-
PADDLE_ENFORCE_EQ(platform::is_gpu_place(places_[0]),
94+
PADDLE_ENFORCE_EQ(phi::is_gpu_place(places_[0]),
9595
true,
9696
platform::errors::Unimplemented(
9797
"FLAGS_allreduce_record_one_event=true is only valid "
@@ -116,7 +116,7 @@ void FusedAllReduceOpHandle::RunImpl() {
116116
if (FLAGS_allreduce_record_one_event) {
117117
auto gpu_place = phi::GPUPlace(places_[0].GetDeviceId());
118118
compute_stream =
119-
platform::DeviceContextPool::Instance().GetByPlace(gpu_place)->stream();
119+
phi::DeviceContextPool::Instance().GetByPlace(gpu_place)->stream();
120120
auto flat_nccl_ctxs = nccl_ctxs_->GetFlatCtx(run_order_);
121121
auto &nccl_ctx = flat_nccl_ctxs->at(gpu_place.device);
122122
nccl_stream = nccl_ctx.stream();
@@ -320,7 +320,7 @@ bool FusedAllReduceOpHandle::InputIsInDifferentPlace(
320320
platform::errors::NotFound(
321321
"The variable '%s' is not found in local scope.", var_name));
322322
auto &lod_tensor = var->Get<phi::DenseTensor>();
323-
if (!platform::is_same_place(lod_tensor.place(), places_.at(scope_idx))) {
323+
if (!phi::is_same_place(lod_tensor.place(), places_.at(scope_idx))) {
324324
return true;
325325
}
326326
}
@@ -355,7 +355,7 @@ void FusedAllReduceOpHandle::GetGradLoDTensor(
355355
auto &lod_tensor = var->Get<phi::DenseTensor>();
356356

357357
PADDLE_ENFORCE_EQ(
358-
platform::is_same_place(lod_tensor.place(), places_.at(scope_idx)),
358+
phi::is_same_place(lod_tensor.place(), places_.at(scope_idx)),
359359
true,
360360
platform::errors::InvalidArgument(
361361
"The variable '%s' at scope %d is not in the right place.",

paddle/fluid/framework/details/nan_inf_utils_detail.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void CheckVarHasNanOrInf(const std::string& op_type,
182182
VLOG(10) << "begin check " << op_type << " var_name:" << var_name
183183
<< ", place:" << tensor->place() << ", numel:" << tensor->numel();
184184

185-
if (platform::is_gpu_place(tensor->place())) {
185+
if (phi::is_gpu_place(tensor->place())) {
186186
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
187187
tensor_check<phi::GPUContext>(op_type, var_name, *tensor, place);
188188
#else
@@ -192,7 +192,7 @@ void CheckVarHasNanOrInf(const std::string& op_type,
192192
var_name));
193193
#endif
194194
return;
195-
} else if (platform::is_xpu_place(tensor->place())) {
195+
} else if (phi::is_xpu_place(tensor->place())) {
196196
#ifdef PADDLE_WITH_XPU
197197
if (framework::TransToProtoVarType(tensor->dtype()) !=
198198
proto::VarType::FP32) {

paddle/fluid/framework/details/nan_inf_utils_detail.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct TensorCheckerVisitor {
5959
std::is_same<T, ::paddle::platform::complex<double>>::value>::type* =
6060
0) const {
6161
auto* dev_ctx = reinterpret_cast<Context*>(
62-
platform::DeviceContextPool::Instance().Get(tensor.place()));
62+
phi::DeviceContextPool::Instance().Get(tensor.place()));
6363

6464
phi::DenseTensor stats;
6565
phi::DenseTensor values;

paddle/fluid/framework/details/op_handle_base.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void OpHandleBase::InitCUDA() {
7979
auto *out_var_handle = dynamic_cast<VarHandle *>(out_var);
8080
if (out_var_handle) {
8181
PADDLE_ENFORCE_EQ(
82-
platform::is_same_place(place, out_var_handle->place()),
82+
phi::is_same_place(place, out_var_handle->place()),
8383
true,
8484
platform::errors::InvalidArgument(
8585
"The place of output(%s) is not consistent with the "
@@ -118,7 +118,7 @@ void OpHandleBase::InitXPU() {
118118
auto *out_var_handle = dynamic_cast<VarHandle *>(out_var);
119119
if (out_var_handle) {
120120
PADDLE_ENFORCE_EQ(
121-
platform::is_same_place(place, out_var_handle->place()),
121+
phi::is_same_place(place, out_var_handle->place()),
122122
true,
123123
platform::errors::InvalidArgument(
124124
"The place of output(%s) is not consistent with the "
@@ -176,7 +176,7 @@ void OpHandleBase::RecordWaitEventOnCtx(platform::DeviceContext *waited_ctx) {
176176
PADDLE_ENFORCE_NOT_NULL(
177177
waited_ctx,
178178
platform::errors::InvalidArgument("Argument waited_ctx is NULL."));
179-
if (platform::is_cpu_place(waited_ctx->GetPlace()) || events_.empty()) {
179+
if (phi::is_cpu_place(waited_ctx->GetPlace()) || events_.empty()) {
180180
for (auto &dev_ctx : dev_ctxes_) {
181181
PADDLE_ENFORCE_NOT_NULL(
182182
dev_ctx.second,
@@ -220,7 +220,7 @@ void OpHandleBase::WaitInputVarGenerated(bool wait_for_feed) {
220220
auto *in_var_handle = dynamic_cast<VarHandle *>(in_var);
221221
if (in_var_handle) {
222222
auto &place = in_var_handle->place();
223-
if (platform::is_gpu_place(place)) {
223+
if (phi::is_gpu_place(place)) {
224224
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
225225
auto stream =
226226
static_cast<phi::GPUContext *>(dev_ctxes_.at(place))->stream();
@@ -247,10 +247,9 @@ void OpHandleBase::WaitInputVarGenerated(bool wait_for_feed) {
247247
auto *in_var_handle = dynamic_cast<VarHandle *>(in_var);
248248
if (in_var_handle) {
249249
auto &place = in_var_handle->place();
250-
if (platform::is_gpu_place(place)) {
250+
if (phi::is_gpu_place(place)) {
251251
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
252-
platform::DeviceContextPool &pool =
253-
platform::DeviceContextPool::Instance();
252+
phi::DeviceContextPool &pool = phi::DeviceContextPool::Instance();
254253
auto stream =
255254
static_cast<phi::GPUContext *>(pool.Get(place))->stream();
256255
platform::GpuStreamSync(stream);
@@ -272,7 +271,7 @@ void OpHandleBase::WaitInputVarGenerated(const phi::Place &place) {
272271
// so there doesn't add event for it.
273272
auto *in_var_handle = dynamic_cast<VarHandle *>(in_var);
274273
if (in_var_handle) {
275-
if (platform::is_gpu_place(in_var_handle->place())) {
274+
if (phi::is_gpu_place(in_var_handle->place())) {
276275
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
277276
auto stream = static_cast<phi::GPUContext *>(
278277
dev_ctxes_.at(in_var_handle->place()))
@@ -332,7 +331,7 @@ void OpHandleBase::RunAndRecordEvent(const std::function<void()> &callback) {
332331
void OpHandleBase::RunAndRecordEvent(phi::Place p,
333332
const std::function<void()> &callback) {
334333
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
335-
if (platform::is_cpu_place(p) || events_.empty()) {
334+
if (phi::is_cpu_place(p) || events_.empty()) {
336335
callback();
337336
} else {
338337
auto *ctx = dev_ctxes_.at(p);

paddle/fluid/framework/details/reduce_op_handle.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ void ReduceOpHandle::RunImpl() {
112112
// CPU.
113113
auto in_p = VariableVisitor::GetMutableTensor(pre_in_var).place();
114114
phi::Place t_out_p;
115-
if (platform::is_gpu_place(in_p)) {
116-
PADDLE_ENFORCE_EQ(platform::is_gpu_place(out_var_handle->place()),
115+
if (phi::is_gpu_place(in_p)) {
116+
PADDLE_ENFORCE_EQ(phi::is_gpu_place(out_var_handle->place()),
117117
true,
118118
platform::errors::PreconditionNotMet(
119119
"Places of input and output must be all on GPU."));
@@ -134,8 +134,7 @@ void ReduceOpHandle::RunImpl() {
134134

135135
// TODO(gongwb): add cpu support
136136
if (collective_context.endpoints_.size() <= 1 ||
137-
platform::is_cpu_place(in_places[0]) ||
138-
platform::is_cpu_place(t_out_p)) {
137+
phi::is_cpu_place(in_places[0]) || phi::is_cpu_place(t_out_p)) {
139138
GatherLocalSelectedRowsFunctor functor(
140139
in_selected_rows,
141140
in_places,
@@ -151,7 +150,7 @@ void ReduceOpHandle::RunImpl() {
151150
std::vector<const phi::DenseTensor *> lod_tensors =
152151
GetInputValues<phi::DenseTensor>(in_var_handles, var_scopes);
153152

154-
if (paddle::platform::is_cpu_place(lod_tensors[0]->place())) {
153+
if (phi::is_cpu_place(lod_tensors[0]->place())) {
155154
WaitInputVarGenerated();
156155
this->RunAndRecordEvent([&] {
157156
// FIXME(zcd): The order of summing is important,
@@ -179,7 +178,7 @@ void ReduceOpHandle::RunImpl() {
179178
}
180179
}
181180
});
182-
} else if (paddle::platform::is_gpu_place(lod_tensors[0]->place())) {
181+
} else if (phi::is_gpu_place(lod_tensors[0]->place())) {
183182
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
184183
auto pre_in = pre_in_var->Get<phi::DenseTensor>();
185184
VariableVisitor::ShareDimsAndLoD(*pre_in_var, out_var);
@@ -231,7 +230,7 @@ void ReduceOpHandle::RunImpl() {
231230
PADDLE_THROW(
232231
platform::errors::PreconditionNotMet("Not compiled with CUDA."));
233232
#endif
234-
} else if (paddle::platform::is_xpu_place(lod_tensors[0]->place())) {
233+
} else if (phi::is_xpu_place(lod_tensors[0]->place())) {
235234
#if defined(PADDLE_WITH_XPU_BKCL)
236235
auto pre_in = pre_in_var->Get<phi::DenseTensor>();
237236
VariableVisitor::ShareDimsAndLoD(*pre_in_var, out_var);

paddle/fluid/framework/details/scale_loss_grad_op_handle.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ struct ScaleLossGradFunctor {
5757
template <typename OutT>
5858
void apply() const {
5959
auto *out_data = out_->mutable_data<OutT>(place_);
60-
if (platform::is_cpu_place(place_)) {
60+
if (phi::is_cpu_place(place_)) {
6161
*out_data = static_cast<OutT>(coeff_);
62-
} else if (platform::is_xpu_place(place_)) {
62+
} else if (phi::is_xpu_place(place_)) {
6363
#if defined(PADDLE_WITH_XPU)
6464
OutT cast_coeff = static_cast<OutT>(coeff_);
6565
memory::Copy(place_,

paddle/fluid/framework/details/sparse_all_reduce_op_handle.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ void SparseAllReduceOpHandle::RunImplEncoded() {
133133
}
134134

135135
PADDLE_ENFORCE_EQ(
136-
platform::is_gpu_place(ins[0]->place()),
136+
phi::is_gpu_place(ins[0]->place()),
137137
true,
138138
platform::errors::InvalidArgument(
139139
"The place of input variable should be CUDAPlace, but got %s.",
140140
ins[0]->place()));
141141
PADDLE_ENFORCE_EQ(
142-
platform::is_gpu_place(outs[0]->place()),
142+
phi::is_gpu_place(outs[0]->place()),
143143
true,
144144
platform::errors::InvalidArgument(
145145
"The place of input variable should be CUDAPlace, but got %s.",

0 commit comments

Comments
 (0)