new_exec_test.cc 3.0 KB
Newer Older
W
wanghuancoder 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright (c) 2021 PaddlePaddle 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 <gperftools/profiler.h>
P
phlrain 已提交
15

W
wanghuancoder 已提交
16 17
#include <chrono>
#include <iostream>
P
phlrain 已提交
18 19 20 21 22 23 24 25
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include "paddle/fluid/framework/executor_gc_helper.h"
#include "paddle/fluid/framework/garbage_collector.h"
W
wanghuancoder 已提交
26
#include "paddle/fluid/framework/new_exec.h"
P
phlrain 已提交
27
#include "paddle/fluid/framework/op_info.h"
W
wanghuancoder 已提交
28 29
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/operator.h"
P
phlrain 已提交
30 31 32 33
#include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/framework/variable.h"
W
wanghuancoder 已提交
34
#include "paddle/fluid/platform/device_context.h"
P
phlrain 已提交
35
#include "paddle/fluid/platform/init.h"
W
wanghuancoder 已提交
36
#include "paddle/fluid/pybind/pybind.h"
P
phlrain 已提交
37

W
wanghuancoder 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
int main() {
  paddle::framework::InitDevices();
  paddle::framework::VariableScope global_scope;
  auto place = paddle::platform::CUDAPlace(0);
  {
    auto test_prog = paddle::framework::load_from_file("lm_startup_program");
    paddle::framework::build_variable_scope(test_prog, &global_scope);
    std::vector<paddle::framework::OpFuncNode> vec_func_list;
    std::vector<paddle::framework::OperatorBase*> op_list;
    paddle::framework::build_op_func_list(test_prog, op_list, vec_func_list,
                                          &global_scope, place);
    paddle::framework::exec_op_func_list(vec_func_list, op_list, global_scope,
                                         place);
  }

  std::cerr << "run main" << std::endl;
  auto main_prog = paddle::framework::load_from_file("lm_main_program");

  paddle::framework::build_variable_scope(main_prog, &global_scope);

  std::vector<paddle::framework::OpFuncNode> vec_main_func_list;
  std::vector<paddle::framework::OperatorBase*> op_main_list;
  paddle::framework::build_op_func_list(
      main_prog, op_main_list, vec_main_func_list, &global_scope, place);

  auto start = std::chrono::steady_clock::now();
  // ProfilerStart("new_executor.prof");
  for (size_t i = 0; i < 2320; ++i) {
    if (i % 200 == 0) {
      std::cerr << i << std::endl;
P
phlrain 已提交
68
    }
W
wanghuancoder 已提交
69 70 71 72 73 74
    paddle::framework::exec_op_func_list(vec_main_func_list, op_main_list,
                                         global_scope, place);
  }
  // ProfilerStop();
  auto end = std::chrono::steady_clock::now();
  std::chrono::duration<double> diff = end - start;
P
phlrain 已提交
75

W
wanghuancoder 已提交
76
  std::cerr << "time cost " << diff.count() << std::endl;
P
phlrain 已提交
77

W
wanghuancoder 已提交
78
  return 1;
P
phlrain 已提交
79
}