simple_builder.cc 1.82 KB
Newer Older
“yuguo”'s avatar
2.5  
“yuguo” committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Copyright (c) 2022 CINN Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/cinn/auto_schedule/measure/simple_builder.h"

namespace cinn {
namespace auto_schedule {

yuguo-Jack's avatar
yuguo-Jack committed
20
21
using hlir::framework::CompilationContext;
using hlir::framework::CompilationResult;
“yuguo”'s avatar
2.5  
“yuguo” committed
22
23
24
25
26
27
28
29
using hlir::framework::GraphCompiler;

SimpleBuilder::SimpleBuilder(hlir::framework::GraphCompiler* graph_compiler)
    : graph_compiler_(graph_compiler) {}

BuildResult SimpleBuilder::Build(const MeasureInput& input) {
  CHECK_NE(graph_compiler_, static_cast<GraphCompiler*>(nullptr))
      << "empty handle to GraphCompiler";
yuguo-Jack's avatar
yuguo-Jack committed
30
31
32
33
  CompilationContext& context = graph_compiler_->GetCompilationContext();
  context.groups.emplace_back(input.task->subgraph);
  context.lowered_funcs.emplace_back(input.lowered_funcs);
  context.remove_unused_variables = false;
“yuguo”'s avatar
2.5  
“yuguo” committed
34
  VLOG(5) << "call GraphCompiler to Build with Graph::Group size="
yuguo-Jack's avatar
yuguo-Jack committed
35
36
37
          << context.groups.size()
          << ", lowered_funcs group size=" << context.lowered_funcs.size();
  CompilationResult compiled_result = graph_compiler_->Build(&context);
“yuguo”'s avatar
2.5  
“yuguo” committed
38
39
40

  BuildResult build_result;
  build_result.compiled_scope = graph_compiler_->GetScope().get();
yuguo-Jack's avatar
yuguo-Jack committed
41
  build_result.runtime_program = std::move(compiled_result.RuntimeProgram());
“yuguo”'s avatar
2.5  
“yuguo” committed
42
43
44
45
46
  return build_result;
}

}  // namespace auto_schedule
}  // namespace cinn