ut_helper.h 1.9 KB
Newer Older
1 2
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

Y
Yan Chunwei 已提交
3 4 5
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
6

Y
Yan Chunwei 已提交
7
http://www.apache.org/licenses/LICENSE-2.0
8

Y
Yan Chunwei 已提交
9 10 11 12 13
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. */
14 15 16 17

#pragma once
#include <gflags/gflags.h>
#include <gtest/gtest.h>
Y
Yan Chunwei 已提交
18
#include <fstream>
19
#include <string>
20 21 22
#include "paddle/fluid/framework/executor.h"
#include "paddle/fluid/inference/analysis/data_flow_graph.h"
#include "paddle/fluid/inference/analysis/fluid_to_data_flow_graph_pass.h"
Y
Yan Chunwei 已提交
23
#include "paddle/fluid/inference/analysis/helper.h"
24 25 26

namespace paddle {
namespace inference {
Y
Yan Chunwei 已提交
27 28 29 30

// Read ProgramDesc from a __model__ file, defined in io.cc
extern void ReadBinaryFile(const std::string& filename, std::string* contents);

31 32 33 34 35 36 37 38
namespace analysis {

DEFINE_string(inference_model_dir, "", "inference test model dir");

static DataFlowGraph ProgramDescToDFG(
    const framework::proto::ProgramDesc& desc) {
  DataFlowGraph graph;
  FluidToDataFlowGraphPass pass;
Y
Yan Chunwei 已提交
39
  Argument argument;
Y
Yan Chunwei 已提交
40
  argument.fluid_model_dir.reset(new std::string(FLAGS_inference_model_dir));
Y
Yan Chunwei 已提交
41 42
  argument.origin_program_desc.reset(new framework::proto::ProgramDesc(desc));
  pass.Initialize(&argument);
43 44 45 46 47 48 49
  pass.Run(&graph);
  pass.Finalize();
  return graph;
}

class DFG_Tester : public ::testing::Test {
 protected:
Y
Yan Chunwei 已提交
50
  void SetUp() override {
Y
Yan Chunwei 已提交
51
    auto desc = LoadProgramDesc(FLAGS_inference_model_dir + "/__model__");
Y
Yan Chunwei 已提交
52 53
    argument.origin_program_desc.reset(new framework::proto::ProgramDesc(desc));
  }
54

Y
Yan Chunwei 已提交
55
  Argument argument;
56 57 58 59 60
};

}  // namespace analysis
}  // namespace inference
}  // namespace paddle