Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHI decoupling] Remove fluid imports from MKLDNN code #48981

Merged
merged 13 commits into from
Dec 15, 2022
4 changes: 2 additions & 2 deletions paddle/fluid/framework/ir/mkldnn/batch_norm_act_fuse_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#include "paddle/fluid/framework/ir/graph_pattern_detector.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "paddle/fluid/framework/op_desc.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/platform/errors.h"

namespace paddle {
namespace framework {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ir {
void ComputePropagateScalesMkldnnPass::GetTensorFromVector(
const std::vector<float>& data_v, phi::DenseTensor* tensor) const {
const int size = static_cast<int>(data_v.size());
auto* data = tensor->mutable_data<float>({size}, platform::CPUPlace());
auto* data = tensor->mutable_data<float>({size}, phi::CPUPlace());
for (int i = 0; i < size; i++) {
data[i] = data_v[i];
}
Expand Down Expand Up @@ -123,7 +123,7 @@ void ComputePropagateScalesMkldnnPass::ComputeVarScales(
std::vector<int64_t> reshape_dims = {dims[0], volume};
tmp_tensor.Resize(phi::make_ddim(reshape_dims));
auto* weight_data = weight_tensor->data<float>();
auto* tmp_data = tmp_tensor.mutable_data<float>(platform::CPUPlace());
auto* tmp_data = tmp_tensor.mutable_data<float>(phi::CPUPlace());
for (int i = 0; i < weight_tensor->numel(); i++) {
tmp_data[i] = std::abs(weight_data[i]);
}
Expand Down Expand Up @@ -365,7 +365,7 @@ void ComputePropagateScalesMkldnnPass::UpdateScaleOpInOutScales(
auto pair = iter->second;
const auto tensor = pair.second;
tmp_tensor.Resize(tensor.dims());
auto* data = tmp_tensor.mutable_data<float>(platform::CPUPlace());
auto* data = tmp_tensor.mutable_data<float>(phi::CPUPlace());
auto* src_data = tensor.data<float>();
for (int i = 0; i < tensor.numel(); i++) {
if (out_iter != var_quant_scales->end()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "paddle/fluid/framework/ir/mkldnn/compute_propagate_scales_mkldnn_pass.h"
#include "paddle/fluid/framework/naive_executor.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/phi/common/place.h"

namespace paddle {
namespace framework {
Expand Down Expand Up @@ -119,7 +119,7 @@ class ComputePropagateScalesMkldnnPassTest : public testing::Test {
const ProgramDesc& prog,
Scope* scope,
const std::initializer_list<std::string>& variable_names) {
auto place = paddle::platform::CPUPlace();
auto place = phi::CPUPlace();
NaiveExecutor exe{place};
exe.CreateVariables(prog, 0, true, scope);

Expand Down Expand Up @@ -148,19 +148,19 @@ class ComputePropagateScalesMkldnnPassTest : public testing::Test {
auto* wx_tensor = wx_var->GetMutable<phi::DenseTensor>();
wx_tensor->Resize(phi::make_dim(wx.size(), wx[0].size()));
for (size_t i = 0; i < wx.size(); i++)
std::copy(begin(wx[i]),
end(wx[i]),
wx_tensor->mutable_data<float>(platform::CPUPlace()) +
i * wx[0].size());
std::copy(
begin(wx[i]),
end(wx[i]),
wx_tensor->mutable_data<float>(phi::CPUPlace()) + i * wx[0].size());

auto* wh_var = scope.FindVar(wh_var_names);
auto* wh_tensor = wh_var->GetMutable<phi::DenseTensor>();
wh_tensor->Resize(phi::make_dim(wh.size(), wh[0].size()));
for (size_t i = 0; i < wh.size(); i++)
std::copy(begin(wh[i]),
end(wh[i]),
wh_tensor->mutable_data<float>(platform::CPUPlace()) +
i * wh[0].size());
std::copy(
begin(wh[i]),
end(wh[i]),
wh_tensor->mutable_data<float>(phi::CPUPlace()) + i * wh[0].size());
if (type == "gru") {
ComputeGruWeightScales(
graph, &scope, wx_name, wh_name, &var_quant_scales);
Expand Down Expand Up @@ -283,7 +283,7 @@ TEST_F(ComputePropagateScalesMkldnnPassTest, get_scales_function) {
var_tensor.Resize(phi::make_dim(values.size(), 1));
std::copy(begin(values),
end(values),
var_tensor.mutable_data<float>(platform::CPUPlace()));
var_tensor.mutable_data<float>(phi::CPUPlace()));
std::vector<float> results = GetScales(&var_tensor, 0);

ASSERT_EQ(results.size(), std::size_t(1));
Expand All @@ -310,7 +310,7 @@ TEST_F(ComputePropagateScalesMkldnnPassTest, compute_var_scales) {
weight_tensor->Resize(phi::make_dim(1, values.size()));
std::copy(begin(values),
end(values),
weight_tensor->mutable_data<float>(platform::CPUPlace()));
weight_tensor->mutable_data<float>(phi::CPUPlace()));

auto max_val = *std::max_element(values.begin(), values.end());

Expand Down Expand Up @@ -338,7 +338,7 @@ TEST_F(ComputePropagateScalesMkldnnPassTest, update_relu_output_scales) {
StringPairMap var_quant_scales;
for (auto& var_name : conv_variable_names) {
phi::DenseTensor tensor;
auto* data = tensor.mutable_data<float>({1}, platform::CPUPlace());
auto* data = tensor.mutable_data<float>({1}, phi::CPUPlace());
data[0] = 10;
auto pair = std::make_pair(false, tensor);
var_quant_scales.insert(std::make_pair(var_name, pair));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "paddle/fluid/framework/ir/mkldnn/conv_activation_mkldnn_fuse_pass.h"

#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/platform/mkldnn_reuse.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/phi/backends/onednn/onednn_reuse.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void recompute_bias_and_weights(const Scope* scope,
ac_bias_tensor.data<float>(), ac_bias_tensor.numel(), 1);

EigenVectorArrayMap eltwise_y_in_array(
eltwise_y_in_tensor->mutable_data<float>(platform::CPUPlace()),
eltwise_y_in_tensor->mutable_data<float>(phi::CPUPlace()),
eltwise_y_in_tensor->numel(),
1);

Expand All @@ -91,7 +91,7 @@ void recompute_bias_and_weights(const Scope* scope,
scope->FindVar(conv_weight->Name())->GetMutable<phi::DenseTensor>();
auto weights_shape = weights->dims();
auto weights_shape_2d = phi::flatten_to_2d(weights_shape, 1);
auto* weights_data = weights->mutable_data<float>(platform::CPUPlace());
auto* weights_data = weights->mutable_data<float>(phi::CPUPlace());

EigenMatrixArrayMap weights_array_2d(
weights_data, weights_shape_2d[0], weights_shape_2d[1]);
Expand Down Expand Up @@ -233,7 +233,7 @@ void ConvAffineChannelFusePass::ApplyImpl(ir::Graph* graph) const {
auto* eltwise_y_in_tensor =
scope->Var(eltwise_y_in_node->Name())->GetMutable<phi::DenseTensor>();
eltwise_y_in_tensor->Resize(ac_bias_tensor->dims());
std::fill_n(eltwise_y_in_tensor->mutable_data<float>(platform::CPUPlace()),
std::fill_n(eltwise_y_in_tensor->mutable_data<float>(phi::CPUPlace()),
eltwise_y_in_tensor->numel(),
0.0f);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down Expand Up @@ -263,7 +263,7 @@ phi::DenseTensor tensor_apply_eltwise(const phi::DenseTensor& vec_a,
vec_y.Resize(vec_a.dims());
const float* a = vec_a.data<float>();
const float* b = vec_b.data<float>();
float* y = vec_y.mutable_data<float>(platform::CPUPlace());
float* y = vec_y.mutable_data<float>(phi::CPUPlace());
for (int i = 0; i < vec_a.numel(); i++) {
y[i] = f(a[i], b[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "paddle/fluid/framework/op_proto_maker.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/imperative/type_defs.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/phi/common/place.h"

namespace paddle {
namespace framework {
Expand Down Expand Up @@ -112,7 +112,7 @@ void InitTensorHolder(Scope* scope,
void MainTest(bool convWithExistingBias) {
auto prog = BuildProgramDesc(convWithExistingBias);
std::unique_ptr<ir::Graph> graph(new ir::Graph(prog));
auto place = paddle::platform::CPUPlace();
auto place = phi::CPUPlace();
NaiveExecutor exe{place};
Scope scope;
// Init scope, as it is used in pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "paddle/fluid/framework/ir/graph_traits.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/ir/mkldnn/cpu_bfloat16_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License. */

#include "paddle/fluid/framework/ir/graph_pattern_detector.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down
18 changes: 5 additions & 13 deletions paddle/fluid/framework/ir/mkldnn/cpu_bfloat16_pass_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "paddle/fluid/framework/ir/mkldnn/cpu_bfloat16_pass.h"
#include "paddle/fluid/framework/naive_executor.h"
#include "paddle/fluid/imperative/type_defs.h"
#include "paddle/fluid/platform/place.h"

namespace paddle {
namespace framework {
Expand Down Expand Up @@ -68,23 +67,16 @@ void SetOp(ProgramDesc* prog,
static const std::initializer_list<std::string> variable_names{
"z", "a", "b", "c", "d", "e", "f", "g", "h", "i"};

void PreparePass(std::unique_ptr<ir::Graph>& graph,
int* original_nodes_num,
int* current_nodes_num) {
auto pass = PassRegistry::Instance().Get("cpu_bfloat16_pass");

*original_nodes_num = graph->Nodes().size();
graph.reset(pass->Apply(graph.release()));
*current_nodes_num = graph->Nodes().size();
}

void MainTest(const ProgramDesc& prog,
const int& quant_count,
const int& dequant_count,
const int& added_nodes_count) {
auto graph = std::make_unique<ir::Graph>(prog);
int original_nodes_num, current_nodes_num;
PreparePass(graph, &original_nodes_num, &current_nodes_num);
auto pass = PassRegistry::Instance().Get("cpu_bfloat16_pass");

int original_nodes_num = graph->Nodes().size();
graph.reset(pass->Apply(graph.release()));
int current_nodes_num = graph->Nodes().size();

int quantize_nodes_count = 0;
int dequantize_nodes_count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License. */

#include "paddle/fluid/framework/ir/graph_pattern_detector.h"
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down
5 changes: 2 additions & 3 deletions paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "paddle/fluid/framework/ir/mkldnn/mkldnn_pass_util.h"
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down Expand Up @@ -1204,8 +1204,7 @@ void CPUQuantizePass::QuantizeMultiGru(Graph* graph) const {
auto* w_scale_tensor_dst =
scope->Var(w_scale_node->Name())->GetMutable<phi::DenseTensor>();
w_scale_tensor_dst->Resize(scale_tensor_src.dims());
auto* dst_data =
w_scale_tensor_dst->mutable_data<float>(platform::CPUPlace());
auto* dst_data = w_scale_tensor_dst->mutable_data<float>(phi::CPUPlace());
EigenVectorArrayMapFloat eigen_tensor_dst{dst_data,
w_scale_tensor_dst->numel()};
eigen_tensor_dst =
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass.h" // NOLINT
#include "paddle/fluid/framework/naive_executor.h"
#include "paddle/fluid/imperative/type_defs.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/phi/common/place.h"

namespace paddle {
namespace framework {
Expand Down Expand Up @@ -146,7 +146,7 @@ void PreparePass(std::unique_ptr<ir::Graph>* graph,
int* current_nodes_num,
std::string var_without_scale = "",
std::string var_signed = "") {
auto place = paddle::platform::CPUPlace();
auto place = phi::CPUPlace();
NaiveExecutor exe{place};
Scope scope;
exe.CreateVariables(prog, 0, true, &scope);
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/ir/mkldnn/cpu_quantize_squash_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include <string>
#include <vector>

#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "paddle/fluid/framework/ir/mkldnn/cpu_quantize_squash_pass.h"
#include "paddle/fluid/framework/naive_executor.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/phi/common/place.h"

namespace paddle {
namespace framework {
Expand Down Expand Up @@ -722,7 +722,7 @@ void InitTensorHolder(Scope* scope,
}

void PrepareGraph(std::unique_ptr<ir::Graph>* graph, const ProgramDesc& prog) {
auto place = paddle::platform::CPUPlace();
auto place = phi::CPUPlace();
NaiveExecutor exe{place};
Scope scope;
exe.CreateVariables(prog, 0, true, &scope);
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/framework/ir/mkldnn/elt_act_mkldnn_fuse_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

#include "paddle/fluid/framework/ir/graph_pattern_detector.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/mkldnn_reuse.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/phi/backends/onednn/onednn_reuse.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/ir/mkldnn/fc_act_mkldnn_fuse_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "paddle/fluid/framework/ir/mkldnn/fc_act_mkldnn_fuse_pass.h"

#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/platform/mkldnn_reuse.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/phi/backends/onednn/onednn_reuse.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "paddle/fluid/framework/ir/graph_traits.h"
#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/ir/mkldnn/fc_mkldnn_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include "paddle/fluid/framework/ir/mkldnn/fc_mkldnn_pass.h"

#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/string/pretty_log.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/utils/string/pretty_log.h"

namespace paddle {
namespace framework {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "paddle/fluid/framework/ir/mkldnn/int8_scale_calculation_mkldnn_pass.h"

#include "paddle/fluid/framework/op_version_registry.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/mkldnn_helper.h"
#include "paddle/phi/core/enforce.h"

namespace paddle {
namespace framework {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <string>
#include <vector>

#include "paddle/fluid/platform/enforce.h"
#include "paddle/phi/core/enforce.h"

namespace paddle {
namespace framework {
Expand Down
Loading