Open leozp opened 5 years ago
Pipeline step to wrap primitives in non-call positions into graphs.
在trainsforms.py中定义。 从处理过程上看类似于剪枝,将Graph中与结果计算无关的constant node进行封装,使其无法调用
step_wrap_primitives = WrapPrimitives.partial()
Inputs:
graph: A graph
Outputs:
graph: The transformed graph
将图集转换为指令列表
step_compile = CompileGraphs.partial(linear_impl='nnvm', target='cpu', dev_id=0)
Inputs:
graph: A graph
Outputs:
mapping: map each graph to its starting position in the code list.
uinstrs: list of unlinked instructions for all the graphs in
the cluster, starting with the passed-in graph.
graph_transform转换具体参数和操作配置如下,原形实现中调用TVM进行图编译。
graph_transform = PipelineDefinition(
resources=dict(
lin_convert=nnvm_convert,
target='cpu',
dev_id=0,
),
steps=dict(
split=SplitGraph.partial(),
compile=CompileGraph.partial(),
optimize=OptimizeInstrs.partial(),
)
)
编译操作过程:
class SplitGraph(PipelineStep):
"""Pipeline step to cut the graph into linear portions and control flow.
Inputs:
graph: A graph
Outputs:
splits: list of graph portions
"""
处理流程:
class CompileGraph(PipelineStep):
"""Step to convert splits into linear instruction flow.
Inputs:
graph: A graph
splits: list of graph portions
Outputs:
uinstrs: list of instructions for the graph (unlinked)
"""
完成指令序列的链接
step_link = LinkInstrs.partial()
class LinkInstrs(PipelineStep):
"""Link unlinked instructions.
Inputs:
mapping: graph map
uinstrs: unlinked instructions
Outputs:
instrs: linked instructions
"""
def step(self, mapping, uinstrs):
"""Link instructions."""
for i in range(len(uinstrs)):
instr = uinstrs[i]
if instr[0] == 'push_graph':
uinstrs[i] = ('push', mapping[instr[1]])
return {'instrs': uinstrs}
处理流程:
生成可调用的指令集,并运行
step_export = VMExporter.partial()
parser.py
block
attributes
method
cond
parser
attributes
method