Skip to content

Commit 634cf2a

Browse files
committed
fix conflicts
2 parents 26087f5 + 752f29a commit 634cf2a

File tree

205 files changed

+7581
-3025
lines changed

Some content is hidden

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

205 files changed

+7581
-3025
lines changed

paddle/cinn/auto_schedule/auto_tuner_test.cc

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "paddle/cinn/frontend/syntax.h"
2727
#include "paddle/cinn/hlir/framework/graph.h"
2828
#include "paddle/cinn/hlir/framework/graph_compiler.h"
29+
#include "paddle/cinn/hlir/framework/graph_compiler_util.h"
2930
#include "paddle/cinn/hlir/framework/node.h"
3031
#include "paddle/cinn/hlir/framework/pass.h"
3132
#include "paddle/cinn/ir/ir_base.h"
@@ -37,6 +38,7 @@ namespace cinn {
3738
namespace auto_schedule {
3839

3940
using ::cinn::hlir::framework::BuildScope;
41+
using ::cinn::hlir::framework::CompilationContext;
4042
using ::cinn::hlir::framework::Graph;
4143
using ::cinn::hlir::framework::GraphCompiler;
4244
using ::cinn::hlir::framework::Instruction;
@@ -53,6 +55,7 @@ class TestAutoTuner : public ::testing::Test {
5355

5456
std::shared_ptr<Graph> graph;
5557
std::shared_ptr<Scope> compiled_scope;
58+
CompilationContext context;
5659
std::unique_ptr<GraphCompiler> graph_compiler;
5760
std::unique_ptr<AutoTuner> tuner;
5861

@@ -73,8 +76,10 @@ class TestAutoTuner : public ::testing::Test {
7376
auto program = CreateAddReluProgram();
7477
auto graph = cinn::frontend::Optimize(&program, fetch_ids, target);
7578
compiled_scope = BuildScope(target, graph);
76-
graph_compiler =
77-
std::make_unique<GraphCompiler>(target, compiled_scope, graph);
79+
context.graph = graph;
80+
context.scope = compiled_scope;
81+
context.target = target;
82+
graph_compiler = std::make_unique<GraphCompiler>(context);
7883
tuner = std::make_unique<AutoTuner>(target, graph.get());
7984
}
8085

@@ -99,16 +104,14 @@ class TestAutoTuner : public ::testing::Test {
99104

100105
virtual void ApplyTunedAndRun(const TuningResult& result) {
101106
// build runtime program with tuning result
102-
GraphCompiler::CompileOptions compile_options;
103-
compile_options.with_instantiate_variables = true;
104-
compile_options.Apply(result);
105-
ASSERT_EQ(1, compile_options.groups.size());
106-
ASSERT_EQ(1, compile_options.lowered_funcs.size());
107+
context.with_instantiate_variables = true;
108+
context.ApplyTuningResult(result);
109+
ASSERT_EQ(1, context.groups.size());
110+
ASSERT_EQ(1, context.lowered_funcs.size());
107111
VLOG(6) << "Print lowered_funcs before building";
108-
VLOG(6) << compile_options.lowered_funcs[0][0];
109-
VLOG(6) << compile_options.lowered_funcs[1][0];
110-
auto runtime_program =
111-
graph_compiler->Build(compile_options).runtime_program;
112+
VLOG(6) << context.lowered_funcs[0][0];
113+
VLOG(6) << context.lowered_funcs[1][0];
114+
auto runtime_program = graph_compiler->Build(&context).runtime_program;
112115
ASSERT_EQ(1, runtime_program->size());
113116
runtime_program->Execute();
114117
}

paddle/cinn/auto_schedule/measure/measurer_test.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
#include "paddle/cinn/frontend/optimize.h"
2626
#include "paddle/cinn/frontend/syntax.h"
2727
#include "paddle/cinn/hlir/framework/graph_compiler.h"
28+
#include "paddle/cinn/hlir/framework/graph_compiler_util.h"
2829
#include "paddle/cinn/runtime/flags.h"
2930

3031
namespace cinn {
3132
namespace auto_schedule {
3233

3334
using ::cinn::hlir::framework::BuildScope;
35+
using ::cinn::hlir::framework::CompilationContext;
3436
using ::cinn::hlir::framework::Graph;
3537
using ::cinn::hlir::framework::GraphCompiler;
3638

@@ -62,7 +64,8 @@ class TestMeasurer : public ::testing::Test {
6264
auto program = CreateAddReluProgram();
6365
auto graph = cinn::frontend::Optimize(&program, fetch_ids, target);
6466
auto scope = BuildScope(target, graph);
65-
graph_compiler = std::make_unique<GraphCompiler>(target, scope, graph);
67+
CompilationContext context(graph, scope, target);
68+
graph_compiler = std::make_unique<GraphCompiler>(context);
6669
TaskCreator task_creator;
6770
tasks = task_creator.CreateTuneTaskOpLevel(graph.get());
6871
const auto& dtype_dict =

paddle/cinn/auto_schedule/measure/simple_builder.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
namespace cinn {
1818
namespace auto_schedule {
1919

20+
using hlir::framework::CompilationContext;
21+
using hlir::framework::CompilationResult;
2022
using hlir::framework::GraphCompiler;
2123

2224
SimpleBuilder::SimpleBuilder(hlir::framework::GraphCompiler* graph_compiler)
@@ -25,15 +27,14 @@ SimpleBuilder::SimpleBuilder(hlir::framework::GraphCompiler* graph_compiler)
2527
BuildResult SimpleBuilder::Build(const MeasureInput& input) {
2628
CHECK_NE(graph_compiler_, static_cast<GraphCompiler*>(nullptr))
2729
<< "empty handle to GraphCompiler";
28-
GraphCompiler::CompileOptions compile_options;
29-
compile_options.groups.emplace_back(input.task->subgraph);
30-
compile_options.lowered_funcs.emplace_back(input.lowered_funcs);
31-
compile_options.remove_unused_variables = false;
30+
CompilationContext& context = graph_compiler_->GetCompilationContext();
31+
context.groups.emplace_back(input.task->subgraph);
32+
context.lowered_funcs.emplace_back(input.lowered_funcs);
33+
context.remove_unused_variables = false;
3234
VLOG(5) << "call GraphCompiler to Build with Graph::Group size="
33-
<< compile_options.groups.size() << ", lowered_funcs group size="
34-
<< compile_options.lowered_funcs.size();
35-
GraphCompiler::CompilationResult compiled_result =
36-
graph_compiler_->Build(compile_options);
35+
<< context.groups.size()
36+
<< ", lowered_funcs group size=" << context.lowered_funcs.size();
37+
CompilationResult compiled_result = graph_compiler_->Build(&context);
3738

3839
BuildResult build_result;
3940
build_result.compiled_scope = graph_compiler_->GetScope().get();

paddle/cinn/auto_schedule/measure/simple_builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "paddle/cinn/auto_schedule/measure/measure.h"
1818
#include "paddle/cinn/hlir/framework/graph_compiler.h"
19+
#include "paddle/cinn/hlir/framework/graph_compiler_util.h"
1920

2021
namespace cinn {
2122
namespace auto_schedule {

paddle/cinn/auto_schedule/measure/simple_runner_test.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
#include "paddle/cinn/frontend/optimize.h"
2626
#include "paddle/cinn/frontend/syntax.h"
2727
#include "paddle/cinn/hlir/framework/graph_compiler.h"
28+
#include "paddle/cinn/hlir/framework/graph_compiler_util.h"
2829

2930
namespace cinn {
3031
namespace auto_schedule {
3132

3233
using ::cinn::hlir::framework::BuildScope;
34+
using ::cinn::hlir::framework::CompilationContext;
3335
using ::cinn::hlir::framework::Graph;
3436
using ::cinn::hlir::framework::GraphCompiler;
3537
using ::cinn::hlir::framework::Instruction;
@@ -56,8 +58,8 @@ class TestSimpleRunner : public ::testing::Test {
5658
auto program = CreateAddReluProgram();
5759
auto graph = cinn::frontend::Optimize(&program, fetch_ids, target);
5860
compiled_scope = BuildScope(target, graph);
59-
graph_compiler =
60-
std::make_unique<GraphCompiler>(target, compiled_scope, graph);
61+
CompilationContext context(graph, compiled_scope, target);
62+
graph_compiler = std::make_unique<GraphCompiler>(context);
6163
auto runtime_program = graph_compiler->Build();
6264
const auto& instructions = runtime_program->GetRunInstructions();
6365
ASSERT_EQ(1, instructions.size());
@@ -123,8 +125,8 @@ TEST_F(TestSimpleRunner, TimeMeasured) {
123125
"sleep_fn"));
124126
instructions.back()->SetLoweredFunc(reinterpret_cast<void*>(sleep_fn));
125127
instructions.back()->Finalize();
126-
build_result.runtime_program.reset(
127-
new hlir::framework::Program(nullptr, std::move(instructions)));
128+
build_result.runtime_program = std::make_unique<hlir::framework::Program>(
129+
nullptr, std::move(instructions));
128130

129131
// to skip the condition check of params in Instruction::PreparePodArgs
130132
std::map<std::string, cinn_pod_value_t> preset_args;

paddle/cinn/auto_schedule/tests/performance_comparison_test.cc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "paddle/cinn/frontend/paddle_model_convertor.h"
2626
#include "paddle/cinn/frontend/syntax.h"
2727
#include "paddle/cinn/hlir/framework/graph_compiler.h"
28+
#include "paddle/cinn/hlir/framework/graph_compiler_util.h"
2829
#include "paddle/cinn/hlir/framework/node.h"
2930
#include "paddle/cinn/hlir/framework/pass.h"
3031
#include "paddle/cinn/ir/ir_base.h"
@@ -61,6 +62,7 @@ namespace cinn {
6162
namespace auto_schedule {
6263

6364
using ::cinn::hlir::framework::BuildScope;
65+
using ::cinn::hlir::framework::CompilationContext;
6466
using ::cinn::hlir::framework::Graph;
6567
using ::cinn::hlir::framework::GraphCompiler;
6668
using ::cinn::hlir::framework::Instruction;
@@ -94,8 +96,8 @@ class PerformanceTester : public ::testing::Test {
9496
hlir::framework::ApplyPass(graph.get(), "OpFusionPass");
9597
VLOG(3) << "Build " << schedule_name << " program.";
9698
auto scope = BuildScope(target_, graph);
97-
auto graph_compiler =
98-
std::make_unique<GraphCompiler>(target_, scope, graph);
99+
CompilationContext context(graph, scope, target_);
100+
auto graph_compiler = std::make_unique<GraphCompiler>(context);
99101
auto runtime_program =
100102
(this->*build_fn)(graph.get(), graph_compiler.get());
101103
if (execute) {
@@ -145,32 +147,32 @@ class PerformanceTester : public ::testing::Test {
145147
std::make_unique<hlir::framework::OpLowerer>(
146148
dtype_dict, shape_dict, target_);
147149

148-
GraphCompiler::CompileOptions compile_options;
149-
compile_options.with_instantiate_variables = true;
150+
CompilationContext& context = graph_compiler->GetCompilationContext();
151+
context.with_instantiate_variables = true;
150152

151153
if (graph->fusion_groups.empty()) {
152154
hlir::framework::ApplyPasses(graph, {"BuildNonFusedGroupsPass"});
153155
}
154-
compile_options.groups = graph->fusion_groups;
156+
context.groups = graph->fusion_groups;
155157

156158
for (auto group : graph->fusion_groups) {
157-
compile_options.lowered_funcs.push_back(
159+
context.lowered_funcs.push_back(
158160
op_lowerer->Lower(group,
159161
/*apply_op_schedule = */ false,
160162
/*apply_group_schedule=*/false));
161163
}
162164

163165
VLOG(3) << "===========================No Schedule LoweredFunc "
164166
"Begin===========================";
165-
for (const auto& funcvec : compile_options.lowered_funcs) {
167+
for (const auto& funcvec : context.lowered_funcs) {
166168
for (const auto& func : funcvec) {
167169
VLOG(3) << func;
168170
}
169171
}
170172
VLOG(3) << "===========================No Schedule LoweredFunc "
171173
"End=============================";
172174

173-
return graph_compiler->Build(compile_options).runtime_program;
175+
return graph_compiler->Build();
174176
}
175177

176178
std::unique_ptr<hlir::framework::Program> BuildManualScheduleProgram(
@@ -191,21 +193,21 @@ class PerformanceTester : public ::testing::Test {
191193
tuner->Initialize(tuning_config, graph_compiler);
192194
TuningResult tuning_result = tuner->Tune(tuning_options);
193195

194-
GraphCompiler::CompileOptions compile_options;
195-
compile_options.with_instantiate_variables = true;
196-
compile_options.Apply(tuning_result);
196+
CompilationContext& context = graph_compiler->GetCompilationContext();
197+
context.with_instantiate_variables = true;
198+
context.ApplyTuningResult(tuning_result);
197199

198200
VLOG(3) << "===========================Auto Schedule LoweredFunc "
199201
"Begin===========================";
200-
for (const auto& funcvec : compile_options.lowered_funcs) {
202+
for (const auto& funcvec : context.lowered_funcs) {
201203
for (const auto& func : funcvec) {
202204
VLOG(3) << func;
203205
}
204206
}
205207
VLOG(3) << "===========================Auto Schedule LoweredFunc "
206208
"End=============================";
207209

208-
return graph_compiler->Build(compile_options).runtime_program;
210+
return graph_compiler->Build();
209211
}
210212

211213
#ifdef CINN_WITH_CUDA

paddle/cinn/backends/compiler.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ namespace backends {
4343
*/
4444
class CompilationInfoDumper {
4545
public:
46-
explicit CompilationInfoDumper(
47-
const hlir::framework::ParallelCompiler::CompilationResult& info)
46+
explicit CompilationInfoDumper(const hlir::framework::CompilationResult& info)
4847
: info_(info) {
4948
DumpLoweredFunc();
5049
DumpSourceCode();
@@ -62,7 +61,7 @@ class CompilationInfoDumper {
6261
const std::string& file_name,
6362
const std::string& content);
6463

65-
const hlir::framework::ParallelCompiler::CompilationResult& info_;
64+
const hlir::framework::CompilationResult& info_;
6665
};
6766

6867
class SourceCodePrint {

paddle/cinn/frontend/computation.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,18 @@ std::shared_ptr<ComputationContext> CompileProgram(
7272
}
7373

7474
ctx->scope = hlir::framework::BuildScope(target, ctx->graph, scope);
75-
ctx->graph_compiler.reset(
76-
new hlir::framework::GraphCompiler(target, ctx->scope, ctx->graph));
7775

7876
std::unordered_set<std::string> fetch_var_ids;
7977
for (auto &out : outputs) {
8078
fetch_var_ids.insert(out->id);
8179
}
8280

83-
ctx->program = ctx->graph_compiler->Build(options, std::move(fetch_var_ids))
84-
.runtime_program;
81+
ctx->compile_options.graph = ctx->graph;
82+
ctx->compile_options.scope = ctx->scope;
83+
ctx->compile_options.fetch_var_ids = fetch_var_ids;
84+
ctx->graph_compiler.reset(
85+
new hlir::framework::GraphCompiler(ctx->compile_options));
86+
ctx->program = ctx->graph_compiler->Build();
8587
if (ctx->compile_options.do_prerun) {
8688
ctx->program->PreRun();
8789
}

paddle/cinn/frontend/computation.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ struct ComputationContext;
2727

2828
class CinnComputation {
2929
public:
30-
struct CompileOptions
31-
: public hlir::framework::GraphCompiler::CompileOptions {
30+
struct CompileOptions : public hlir::framework::CompilationContext {
3231
bool use_decomposer = false;
3332
bool do_prerun = true;
3433
bool use_default_passes = true;

paddle/cinn/frontend/decomposer/activation_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ TEST(Decomposer, softmax_decomposer) {
8686
hlir::framework::ApplyPass(graph.get(), "FusionMergePass");
8787

8888
auto scope = BuildScope(target, graph);
89-
hlir::framework::GraphCompiler gc(target, scope, graph);
89+
hlir::framework::CompilationContext context(graph, scope, target);
90+
hlir::framework::GraphCompiler gc(context);
9091
auto run_program = gc.Build();
9192

9293
std::vector<float> x(n * c * h * w);

paddle/cinn/frontend/decomposer/batch_norm_test.cc

100755100644
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ TEST(Decomposer, BatchNormTrain) {
200200
hlir::framework::ApplyPass(graph.get(), "FusionMergePass");
201201

202202
auto scope = BuildScope(target, graph);
203-
hlir::framework::GraphCompiler gc(target, scope, graph);
203+
hlir::framework::CompilationContext context(graph, scope, target);
204+
hlir::framework::GraphCompiler gc(context);
204205
auto run_program = gc.Build();
205206

206207
// set input
@@ -399,7 +400,8 @@ TEST(Decomposer, BatchNormGrad) {
399400
hlir::framework::ApplyPass(graph.get(), "FusionMergePass");
400401

401402
auto scope = BuildScope(target, graph);
402-
hlir::framework::GraphCompiler gc(target, scope, graph);
403+
hlir::framework::CompilationContext context(graph, scope, target);
404+
hlir::framework::GraphCompiler gc(context);
403405
auto run_program = gc.Build();
404406

405407
// set input

paddle/cinn/frontend/decomposer/test_helper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "paddle/cinn/frontend/program_pass.h"
2828
#include "paddle/cinn/hlir/framework/graph.h"
2929
#include "paddle/cinn/hlir/framework/graph_compiler.h"
30+
#include "paddle/cinn/hlir/framework/graph_compiler_util.h"
3031
#include "paddle/cinn/hlir/framework/pass.h"
3132
#include "paddle/cinn/hlir/framework/tensor.h"
3233
#include "paddle/cinn/hlir/op/use_ops.h"
@@ -208,7 +209,8 @@ void RunAndCheckShape(NetBuilder* builder,
208209
auto graph = std::make_shared<hlir::framework::Graph>(prog, target);
209210
hlir::framework::ApplyPasses(graph.get(), DefaultOpFusionPasses());
210211
auto scope = BuildScope(target, graph);
211-
hlir::framework::GraphCompiler gc(target, scope, graph);
212+
hlir::framework::CompilationContext context(graph, scope, target);
213+
hlir::framework::GraphCompiler gc(context);
212214

213215
auto runtime_program = gc.Build();
214216
std::vector<std::vector<T>> input_vecs_internal;

paddle/cinn/frontend/decomposer/top_k_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ TEST(Decomposer, top_k_decomposer) {
3838
hlir::framework::ApplyPass(graph.get(), "FusionMergePass");
3939

4040
auto scope = BuildScope(target, graph);
41-
hlir::framework::GraphCompiler gc(target, scope, graph);
41+
hlir::framework::CompilationContext context(graph, scope, target);
42+
hlir::framework::GraphCompiler gc(context);
4243
auto run_program = gc.Build();
4344

4445
std::vector<float> x(10 * 5);

0 commit comments

Comments
 (0)