README.md 2.6 KB
Newer Older
1 2 3 4 5 6 7 8
# Inference Analysis

The `inference/analysis` module is used to analyze and optimize the inference program,
it references some philosophy from `LLVM/analysis`, 
and make the various optimization features be pluggable and co-exist in a pipeline.

We borrowed some concepts from LLVM, such as

W
Wilber 已提交
9 10 11
- [Pass](../../framework/ir/pass.h)es to implement optimization that traverse the inference program,
- [Graph](../../framework/ir/graph.h) to represent the data flow graph built from a program,
- [PassManager](./ir_pass_manager.h) to manage a sequence of `Pass`es over a graph.
12 13 14

There are some other basic concepts here

W
Wilber 已提交
15
- [Node](../../framework/ir/node.h), the node in a `Graph`,
16 17 18 19 20 21 22 23
  - `Function`, the Operator in Fluid,
  - `Value`, the Variable in Fluid;
- [Argument](./argument.h), the argument that treat as the input and output of all `Pass`es in the pipeline,

## How it works

The `inference/analysis` module make all the passes in a pipeline, and works in such way:

W
Wilber 已提交
24 25 26
1. Build a `Graph` from a Fluid inference ProgramDesc,
2. Call the middle passes one by one, the same `Graph` is passed across all the passes,
3. Transform a new ProgramDesc from the modified `Graph`.
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

The new optimization features can be added as an independent `Pass` and controlled by gflags,
each pass will generate unified debug information or visualization for better debugging.

## Supported Passes

### `FluidToDataFlowGraphPass`
Transform the fluid `ProgramDesc` to a `DataFlowGraph` to give an abstract representation for all the middle passes, 
this should be the first pass of the pipeline.

### `DataFlowGraphToFluidPass`
Generate a final `ProgramDesc` from a data flow graph, this should be the last pass of the pipeline.

### `TensorRTSubgraphNodeMarkPass`
Mark the `Node` that are supported by TensorRT, 
this pass will generate a visualization file which can be used for debugging.

### `TensorRTSubGraphPass`
Split the sub-graph that are can be accelerated by TensorRT.

### `DFG_GraphvizDrawPass`
This pass is just for debug, it will visualize the `DataFlowGraph` using the [graphviz](http://www.graphviz.org) tool.

It can be used as a helper class that draws the modified graph after each pass.

## Utilities

X
Xin Pan 已提交
54
There is some helper legacy/function/class for analysis.
55 56

- [dot.h](./dot.h) give a easy to use interface for generating `DOT` codes,
W
Wilber 已提交
57 58
- [graph_traits.h](../../framework/ir/graph_traits.h) contains the interfaces of the graph traversal algorithms, it uses `iterator`to make the algorithms easy to share across different passes,
there are some implementations in  [graph_helper.cc](../../framework/ir/graph_helper.cc) , such as BFS and DFS..