Skip to content

Commit 3e08d67

Browse files
authored
optimize phi::CPUPlace() in paddle/fluid/framework/ir/ (#77198)
* optimize phi::CPUPlace() in paddle/fluid/framework/ir/ * fix * fix
1 parent c66ad3e commit 3e08d67

File tree

54 files changed

+153
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+153
-165
lines changed

paddle/fluid/framework/ir/attention_lstm_fuse_pass.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void PrepareLSTMWeight(const phi::DenseTensor& W_forget_w0,
297297
out->Resize(common::make_ddim({D + M, 4 * D}));
298298
VLOG(3) << "LSTMWeight resized to " << out->dims();
299299

300-
float* out_data = out->mutable_data<float>(phi::CPUPlace());
300+
float* out_data = out->mutable_data<float>(CPUPlace());
301301
std::array<const float*, 4> tensors{W_forget_w0.data<float>(),
302302
W_input_w0.data<float>(),
303303
W_output_w0.data<float>(),
@@ -342,7 +342,7 @@ void PrepareLSTMBias(const phi::DenseTensor& B_forget,
342342
B_forget.dims().size()));
343343
int D = static_cast<int>(B_forget.dims()[0]);
344344
out->Resize(common::make_ddim({1, 4 * D}));
345-
auto* out_data = out->mutable_data<float>(phi::CPUPlace());
345+
auto* out_data = out->mutable_data<float>(CPUPlace());
346346
for (size_t i = 0; i < tensors.size(); i++) {
347347
memcpy(out_data + D * i, tensors[i], D * sizeof(float));
348348
}

paddle/fluid/framework/ir/auto_mixed_precision_pass.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,7 @@ void AutoMixedPrecisionPass::ConvertWeightsData() const {
948948

949949
if (low_precision_ == phi::DataType::FLOAT16) {
950950
auto* low_precision_data =
951-
low_precision_tensor.mutable_data<phi::dtype::float16>(
952-
phi::CPUPlace{});
951+
low_precision_tensor.mutable_data<phi::dtype::float16>(CPUPlace{});
953952
for (int64_t i = 0; i < origin_tensor->numel(); i++) {
954953
if (origin_tensor->dtype() == phi::DataType::FLOAT64) {
955954
auto* origin_data = origin_tensor->data<double>();
@@ -963,8 +962,7 @@ void AutoMixedPrecisionPass::ConvertWeightsData() const {
963962
}
964963
} else if (low_precision_ == phi::DataType::BFLOAT16) {
965964
auto* low_precision_data =
966-
low_precision_tensor.mutable_data<phi::dtype::bfloat16>(
967-
phi::CPUPlace{});
965+
low_precision_tensor.mutable_data<phi::dtype::bfloat16>(CPUPlace{});
968966
for (int64_t i = 0; i < origin_tensor->numel(); i++) {
969967
if (origin_tensor->dtype() == phi::DataType::FLOAT64) {
970968
auto* origin_data = origin_tensor->data<double>();
@@ -979,7 +977,7 @@ void AutoMixedPrecisionPass::ConvertWeightsData() const {
979977
}
980978
origin_tensor->clear();
981979
paddle::framework::TensorCopySync(
982-
low_precision_tensor, phi::CPUPlace{}, origin_tensor);
980+
low_precision_tensor, CPUPlace{}, origin_tensor);
983981
}
984982
}
985983
}

paddle/fluid/framework/ir/constant_folding_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void ConstantFoldingPass::ApplyImpl(ir::Graph *graph) const {
173173
// useless out_node can be removed, not need set it persistable !
174174
if (out_node->outputs.empty()) remove_nodes.emplace(out_node);
175175
}
176-
op->Run(*local_scope, phi::CPUPlace());
176+
op->Run(*local_scope, CPUPlace());
177177
folded_op_num++;
178178
for (auto out_node : op_node->outputs) {
179179
// this out_node is useless, do not set it persistable

paddle/fluid/framework/ir/conv2d_trans_filter_dilations_nxn_to_1x1_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void Conv2dTransFilterDilationsNxNTo1x1Pass::conv2d_dilation_trans(
125125
scope->Var(new_weights_name)->GetMutable<phi::DenseTensor>();
126126
new_weights->Resize({weights_shape[0], weights_shape[1], new_kh, new_kw});
127127
auto* cpu_ctx = static_cast<phi::CPUContext*>(
128-
phi::DeviceContextPool::Instance().Get(phi::CPUPlace()));
128+
phi::DeviceContextPool::Instance().Get(CPUPlace()));
129129
if (weights->dtype() == phi::DataType::FLOAT32) {
130130
auto weights_data = weights->data<float>();
131131
auto* new_weights_data = cpu_ctx->Alloc<float>(new_weights);

paddle/fluid/framework/ir/cost_model.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ CostData CostModel::ProfileMeasure(
226226
std::string device_lower_case = ToLowerCopy(device);
227227
if (device_lower_case == "cpu") {
228228
profiler_state = platform::ProfilerState::kCPU;
229-
place = phi::CPUPlace();
229+
place = CPUPlace();
230230
} else if (device_lower_case == "gpu") {
231231
profiler_state = platform::ProfilerState::kAll;
232232
place = phi::GPUPlace();

paddle/fluid/framework/ir/delete_cast_op_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ int DeleteCastOpPass::ApplyCastLookupTablePass(ir::Graph* graph) const {
692692
lookup_table_w->Var()->SetDataType(proto::VarType::FP16);
693693
if (w_tensor->dtype() != phi::DataType::FLOAT16) {
694694
auto* cpu_ctx = static_cast<phi::CPUContext*>(
695-
phi::DeviceContextPool::Instance().Get(phi::CPUPlace()));
695+
phi::DeviceContextPool::Instance().Get(CPUPlace()));
696696
phi::DenseTensor w_fp32_tensor;
697697
w_fp32_tensor.Resize(w_tensor->dims());
698698
w_fp32_tensor.set_type(w_tensor->dtype());

paddle/fluid/framework/ir/delete_quant_dequant_filter_op_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void DeleteQuantDequantFilterOpPass::ApplyImpl(ir::Graph* graph) const {
128128
auto w_dims = weight_tensor->dims();
129129

130130
float* quantized_weight_data =
131-
weight_tensor->mutable_data<float>(phi::CPUPlace());
131+
weight_tensor->mutable_data<float>(CPUPlace());
132132

133133
// Get weight scale
134134
if (dequant_type == "fake_channel_wise_quantize_dequantize_abs_max") {

paddle/fluid/framework/ir/embedding_fc_lstm_fuse_pass.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ static int BuildFusion(Graph* graph,
9696
// Multiply embeddings via WeightsX and add bias
9797
auto embedding_data = embedding_tensor.data<float>();
9898
auto weightx_data = weightx_tensor.data<float>();
99-
auto embeddings_data =
100-
embeddings_tensor->mutable_data<float>(phi::CPUPlace());
99+
auto embeddings_data = embeddings_tensor->mutable_data<float>(CPUPlace());
101100

102101
// Adding biases to GEMM result to be
103102
auto* lstm_bias_var = scope->FindVar(bias->Name());

paddle/fluid/framework/ir/fc_fuse_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int FCFusePass::ApplyFCPattern(Graph* graph, bool with_relu) const {
210210
w_w * sizeof(float));
211211
}
212212
w_tensor->Resize(DDim{weight_dims[0] + 4, weight_dims[1] + 4});
213-
auto* weight_data_new = w_tensor->mutable_data<float>(phi::CPUPlace());
213+
auto* weight_data_new = w_tensor->mutable_data<float>(CPUPlace());
214214
for (int i = 0; i < w_h; i++) {
215215
memcpy(weight_data_new + i * (w_w + 4),
216216
weight_data_tmp + i * w_w,

paddle/fluid/framework/ir/fc_gru_fuse_pass.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ int FCGRUFusePass::BuildFusion(Graph* graph,
232232
common::errors::PreconditionNotMet(
233233
"GRU and FC biases have to have equal number of elements."));
234234

235-
auto gru_bias_data =
236-
gru_bias_tensor->mutable_data<float>(phi::CPUPlace());
235+
auto gru_bias_data = gru_bias_tensor->mutable_data<float>(CPUPlace());
237236
auto* fc_bias_data = fc_bias_tensor->data<float>();
238237

239238
// Recompute GRU bias

0 commit comments

Comments
 (0)