new_exec_test.cc 2.3 KB
Newer Older
P
phlrain 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 68 69 70 71 72 73 74 75 76 77
#include <iostream>
#include <string>

#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"
#include "paddle/fluid/framework/op_info.h"
#include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/framework/variable.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/operator.h"

#include "paddle/fluid/pybind/pybind.h"

#include "paddle/fluid/platform/init.h"
#include "paddle/fluid/framework/new_exec.h"

#include <chrono>
#include <gperftools/profiler.h>


int main()
{   
    paddle::framework::InitDevices();
    paddle::framework::VariableScope global_scope;

    
    {
        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<std::unique_ptr<paddle::framework::OperatorBase>> op_list;
        paddle::framework::build_op_func_list( test_prog, op_list, vec_func_list, global_scope);

        paddle::framework::exec_op_func_list( vec_func_list, op_list, global_scope ); 
    }

    cerr << "run main" << 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<std::unique_ptr<paddle::framework::OperatorBase>> op_main_list;
    paddle::framework::build_op_func_list( main_prog, op_main_list, vec_main_func_list, global_scope);

    auto start = std::chrono::steady_clock::now();
    //ProfilerStart("new_executor.prof");
    for ( size_t i = 0; i < 2320; ++i )
    {
        if( i % 200 == 0)
        {   
            cerr << i << endl;
        }
        paddle::framework::exec_op_func_list( vec_main_func_list, op_main_list, global_scope ); 
    }
    //ProfilerStop();
    auto end = std::chrono::steady_clock::now();
    std::chrono::duration<double> diff = end-start;

    cerr << "time cost " << diff.count() << endl;


    return 1;

}