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

[CINN] Adjust the code format in cinn #55009

Merged
merged 4 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions paddle/cinn/frontend/decomposer/activation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TEST(Decomposer, relu) {
std::vector<std::string> output_names = {out->id};
std::vector<std::vector<int>> output_shapes = {{20, 10}};
RunAndCheck<float>(
builder, input_names, output_names, output_shapes, relu_cpu, -1, 1);
&builder, input_names, output_names, output_shapes, relu_cpu, -1, 1);
}

TEST(Decomposer, relu_grad) {
Expand All @@ -62,7 +62,7 @@ TEST(Decomposer, relu_grad) {
std::vector<std::string> output_names = {dx->id};
std::vector<std::vector<int>> output_shapes = {{20, 10}};
RunAndCheck<float>(
builder, input_names, output_names, output_shapes, relu_grad_cpu, -1, 1);
&builder, input_names, output_names, output_shapes, relu_grad_cpu, -1, 1);
}

TEST(Decomposer, softmax_decomposer) {
Expand Down
24 changes: 12 additions & 12 deletions paddle/cinn/frontend/decomposer/broadcast_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST(Decomposer, elementwise_add_bcast0) {
std::vector<std::string> input_names = {x.id().data(), y.id().data()};
std::vector<std::string> output_names = {out->id};
std::vector<std::vector<int>> output_shapes = {{4, 10, 20, 10}};
RunAndCheckShape<float>(builder, input_names, output_names, output_shapes);
RunAndCheckShape<float>(&builder, input_names, output_names, output_shapes);
}

TEST(Decomposer, elementwise_add_bcase1) {
Expand All @@ -39,7 +39,7 @@ TEST(Decomposer, elementwise_add_bcase1) {
std::vector<std::string> input_names = {x.id().data(), y.id().data()};
std::vector<std::string> output_names = {out->id};
std::vector<std::vector<int>> output_shapes = {{4, 10, 20, 10}};
RunAndCheckShape<float>(builder, input_names, output_names, output_shapes);
RunAndCheckShape<float>(&builder, input_names, output_names, output_shapes);
}

TEST(Decomposer, elementwise_add_grad_bcast0) {
Expand All @@ -52,7 +52,7 @@ TEST(Decomposer, elementwise_add_grad_bcast0) {
std::vector<std::string> input_names = {dout.id().data()};
std::vector<std::string> output_names = {out_grads[0]->id, out_grads[1]->id};
std::vector<std::vector<int>> output_shapes = {{4, 1, 20, 10}, {10, 20}};
RunAndCheckShape<float>(builder, input_names, output_names, output_shapes);
RunAndCheckShape<float>(&builder, input_names, output_names, output_shapes);
}

TEST(Decomposer, elementwise_add_bcast1) {
Expand Down Expand Up @@ -80,7 +80,7 @@ TEST(Decomposer, elementwise_add_bcast1) {
std::vector<std::string> output_names = {out->id};
std::vector<std::vector<int>> output_shapes = {{32, 64, 32, 32}};
RunAndCheck<float>(
builder, input_names, output_names, output_shapes, add_cpu);
&builder, input_names, output_names, output_shapes, add_cpu);
}

TEST(Decomposer, elementwise_add_bcast1_2) {
Expand Down Expand Up @@ -108,7 +108,7 @@ TEST(Decomposer, elementwise_add_bcast1_2) {
std::vector<std::string> output_names = {out->id};
std::vector<std::vector<int>> output_shapes = {{32, 64, 32, 32}};
RunAndCheck<float>(
builder, input_names, output_names, output_shapes, add_cpu);
&builder, input_names, output_names, output_shapes, add_cpu);
}

TEST(Decomposer, elementwise_add_grad_bcast1) {
Expand Down Expand Up @@ -140,7 +140,7 @@ TEST(Decomposer, elementwise_add_grad_bcast1) {
std::vector<std::string> output_names = {out_grads[0]->id, out_grads[1]->id};
std::vector<std::vector<int>> output_shapes = {{32, 64, 32, 32}, {64}};
RunAndCheck<float>(
builder, input_names, output_names, output_shapes, add_grad_cpu);
&builder, input_names, output_names, output_shapes, add_grad_cpu);
}

TEST(Decomposer, elementwise_add_bcast2) {
Expand All @@ -165,7 +165,7 @@ TEST(Decomposer, elementwise_add_bcast2) {
std::vector<std::string> output_names = {out->id};
std::vector<std::vector<int>> output_shapes = {{32, 16}};
RunAndCheck<float>(
builder, input_names, output_names, output_shapes, add_cpu);
&builder, input_names, output_names, output_shapes, add_cpu);
}

TEST(Decomposer, elementwise_add_bcast2_2) {
Expand All @@ -190,7 +190,7 @@ TEST(Decomposer, elementwise_add_bcast2_2) {
std::vector<std::string> output_names = {out->id};
std::vector<std::vector<int>> output_shapes = {{32, 16}};
RunAndCheck<float>(
builder, input_names, output_names, output_shapes, add_cpu);
&builder, input_names, output_names, output_shapes, add_cpu);
}

TEST(Decomposer, elementwise_add_bcast2_3) {
Expand All @@ -217,7 +217,7 @@ TEST(Decomposer, elementwise_add_bcast2_3) {
std::vector<std::string> output_names = {out->id};
std::vector<std::vector<int>> output_shapes = {{32, 16}};
RunAndCheck<int_ty>(
builder, input_names, output_names, output_shapes, add_cpu);
&builder, input_names, output_names, output_shapes, add_cpu);
}

TEST(Decomposer, elementwise_add_grad_bcast2) {
Expand All @@ -244,7 +244,7 @@ TEST(Decomposer, elementwise_add_grad_bcast2) {
std::vector<std::string> output_names = {out_grads[0]->id, out_grads[1]->id};
std::vector<std::vector<int>> output_shapes = {{32, 16}, {1}};
RunAndCheck<float>(
builder, input_names, output_names, output_shapes, add_grad_cpu);
&builder, input_names, output_names, output_shapes, add_grad_cpu);
}

TEST(Decomposer, elementwise_add_same_dims) {
Expand All @@ -268,7 +268,7 @@ TEST(Decomposer, elementwise_add_same_dims) {
std::vector<std::string> output_names = {out->id};
std::vector<std::vector<int>> output_shapes = {{32, 16}};
RunAndCheck<float>(
builder, input_names, output_names, output_shapes, add_cpu);
&builder, input_names, output_names, output_shapes, add_cpu);
}

TEST(Decomposer, elementwise_add_grad_same_dims) {
Expand All @@ -295,7 +295,7 @@ TEST(Decomposer, elementwise_add_grad_same_dims) {
std::vector<std::string> output_names = {out_grads[0]->id, out_grads[1]->id};
std::vector<std::vector<int>> output_shapes = {{32, 16}, {32, 16}};
RunAndCheck<float>(
builder, input_names, output_names, output_shapes, add_grad_cpu);
&builder, input_names, output_names, output_shapes, add_grad_cpu);
}

} // namespace cinn::frontend
2 changes: 1 addition & 1 deletion paddle/cinn/frontend/decomposer/elementwise_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ TEST(Decomposer, sum) {
std::vector<std::string> output_names = {out->id};
std::vector<std::vector<int>> output_shapes = {{32, 16}};
RunAndCheck<float>(
builder, input_names, output_names, output_shapes, sum_cpu);
&builder, input_names, output_names, output_shapes, sum_cpu);
}

} // namespace cinn::frontend
6 changes: 3 additions & 3 deletions paddle/cinn/frontend/decomposer/test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void RunDecomposer(Program* prog,
const std::vector<std::string>& fetch_ids = {});

template <typename T>
void RunAndCheckShape(NetBuilder& builder,
void RunAndCheckShape(NetBuilder* builder,
const std::vector<std::string>& input_names,
const std::vector<std::string>& output_names,
const std::vector<std::vector<int>>& output_shapes,
Expand All @@ -202,7 +202,7 @@ void RunAndCheckShape(NetBuilder& builder,
T low = 0,
T high = 1,
const std::vector<std::string>& passes = {"Decomposer"}) {
auto prog = builder.Build();
auto prog = builder->Build();
Target target = common::DefaultTarget();
RunDecomposer(&prog, target, passes, output_names);
auto graph = std::make_shared<hlir::framework::Graph>(prog, target);
Expand Down Expand Up @@ -238,7 +238,7 @@ void RunAndCheckShape(NetBuilder& builder,
}

template <typename T>
void RunAndCheck(NetBuilder& builder,
void RunAndCheck(NetBuilder* builder,
const std::vector<std::string>& input_names,
const std::vector<std::string>& output_names,
const std::vector<std::vector<int>>& output_shapes,
Expand Down
12 changes: 6 additions & 6 deletions paddle/cinn/frontend/pass/fill_constant_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ TEST(FillConstantRewriter, remove_reshape_single) {
std::vector<std::string> program_passes = {"FillConstantRewriter",
"RemoveIdentity"};
int num_removed_ops =
tester.RunAndCheck(builder, program_passes, input_names, output_names);
tester.RunAndCheck(&builder, program_passes, input_names, output_names);
ASSERT_EQ(num_removed_ops, 2);
}

Expand All @@ -68,7 +68,7 @@ TEST(FillConstantRewriter, remove_reshape_with_fill_constant) {
std::vector<std::string> program_passes = {"FillConstantRewriter",
"RemoveIdentity"};
int num_removed_ops =
tester.RunAndCheck(builder, program_passes, input_names, output_names);
tester.RunAndCheck(&builder, program_passes, input_names, output_names);
ASSERT_EQ(num_removed_ops, 2);
}

Expand All @@ -93,7 +93,7 @@ TEST(FillConstantRewriter, remove_scale_single) {
std::vector<std::string> program_passes = {"FillConstantRewriter",
"RemoveIdentity"};
int num_removed_ops =
tester.RunAndCheck(builder, program_passes, input_names, output_names);
tester.RunAndCheck(&builder, program_passes, input_names, output_names);
ASSERT_EQ(num_removed_ops, 2);
}

Expand All @@ -118,7 +118,7 @@ TEST(FillConstantRewriter, remove_scale_with_fill_constant) {
std::vector<std::string> program_passes = {"FillConstantRewriter",
"RemoveIdentity"};
int num_removed_ops =
tester.RunAndCheck(builder, program_passes, input_names, output_names);
tester.RunAndCheck(&builder, program_passes, input_names, output_names);
ASSERT_EQ(num_removed_ops, 2);
}

Expand Down Expand Up @@ -150,7 +150,7 @@ TEST(FillConstantRewriter, remove_multi_scale_with_fill_constant) {
std::vector<std::string> program_passes = {"FillConstantRewriter",
"RemoveIdentity"};
int num_removed_ops =
tester.RunAndCheck(builder, program_passes, input_names, output_names);
tester.RunAndCheck(&builder, program_passes, input_names, output_names);
ASSERT_EQ(num_removed_ops, 4);
}

Expand All @@ -167,7 +167,7 @@ TEST(FillConstantRewriter, two_fill_constant) {
std::vector<std::string> program_passes = {"FillConstantRewriter",
"RemoveIdentity"};
int num_removed_ops =
tester.RunAndCheck(builder, program_passes, input_names, output_names);
tester.RunAndCheck(&builder, program_passes, input_names, output_names);
ASSERT_EQ(num_removed_ops, 0);
}

Expand Down
8 changes: 4 additions & 4 deletions paddle/cinn/frontend/pass/remove_identity_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST(RemoveIdentity, remove_single) {
std::vector<std::string> program_passes = {"RemoveIdentity",
"DeadCodeEliminate"};
int num_removed_ops =
tester.RunAndCheck(builder, program_passes, input_names, output_names);
tester.RunAndCheck(&builder, program_passes, input_names, output_names);
ASSERT_EQ(num_removed_ops, 3);
}

Expand All @@ -63,7 +63,7 @@ TEST(RemoveIdentity, remove_branch) {
std::vector<std::string> output_names = {reduce_sum_1->id, reduce_sum_2->id};
std::vector<std::string> program_passes = {"RemoveIdentity"};
int num_removed_ops =
tester.RunAndCheck(builder, program_passes, input_names, output_names);
tester.RunAndCheck(&builder, program_passes, input_names, output_names);
ASSERT_EQ(num_removed_ops, 1);
}

Expand Down Expand Up @@ -92,7 +92,7 @@ TEST(RemoveIdentity, remove_multiple) {
std::vector<std::string> output_names = {mul_1->id};
std::vector<std::string> program_passes = {"RemoveIdentity"};
int num_removed_ops =
tester.RunAndCheck(builder, program_passes, input_names, output_names);
tester.RunAndCheck(&builder, program_passes, input_names, output_names);
ASSERT_EQ(num_removed_ops, 3);
}

Expand Down Expand Up @@ -121,7 +121,7 @@ TEST(RemoveIdentity, cannot_remove_fetch) {
std::vector<std::string> output_names = {identity_2->id, mul_1->id};
std::vector<std::string> program_passes = {"RemoveIdentity"};
int num_removed_ops =
tester.RunAndCheck(builder, program_passes, input_names, output_names);
tester.RunAndCheck(&builder, program_passes, input_names, output_names);
ASSERT_EQ(num_removed_ops, 1);
}

Expand Down
4 changes: 2 additions & 2 deletions paddle/cinn/frontend/pass/test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ class PassTest {
public:
PassTest() { target_ = common::DefaultTarget(); }

int RunAndCheck(NetBuilder& builder,
int RunAndCheck(NetBuilder* builder,
const std::vector<std::string>& program_passes,
const std::vector<std::string>& input_names,
const std::vector<std::string>& output_names) {
auto program = builder.Build();
auto program = builder->Build();
CHECK(IsValid(program)) << "The origin program is not valid.";
int origin_program_size = program.size();
LOG(INFO) << "Run origin program";
Expand Down
Loading