leozp / Myia-Issues

0 stars 0 forks source link

Myia 流程分析 #1

Open leozp opened 5 years ago

leozp commented 5 years ago

parser.py

block

attributes

leozp commented 5 years ago

wrap_primitives

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
leozp commented 5 years ago

compile

将图集转换为指令列表

    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(),
        )
    )

编译操作过程:

SplitGraph

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

    """

处理流程:

CompileGraph

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)

    """
leozp commented 5 years ago

link

完成指令序列的链接

    step_link = LinkInstrs.partial()

LinkInstrs

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}

处理流程:

leozp commented 5 years ago

export

生成可调用的指令集,并运行

    step_export = VMExporter.partial()
Olivert007 commented 2 years ago

博主,您好,咨询一下,https://github.com/leozp/Myia-Issues/wiki/Code-Review-%E2%80%94%E2%80%94-Myia-Compile,文章中的流程图是怎么生成的