def test_no_change2():
    """
    test_no_change2

    before)

    c -+
       +-{Add}- y
    v -+

    after)

    c -+
       +-{Add & Inplace}- y
    v -+
    """

    c = ConstantVariable(np.random.rand(2, 3, 4, 5), OrderNCHW)
    v = Variable(c.shape, c.order)

    y = v + c
    op = y.output_from

    assert not op.has_attribute(Inplace)

    UpdateInplaceAttribute().optimize(Graph([v], [y]))

    assert op.has_attribute(Inplace)

    UpdateInplaceAttribute().optimize(Graph([v], [y]))

    assert op.has_attribute(Inplace)
예제 #2
0
    def __init__(self):
        sub_rules = [
            OptimizeRuleGroup([
                InsertTranspose(),
                ReplaceConvolutionByIm2Col(),
                MergeSgemmAndElementwiseMul(),
                ConstantFolding(),
                ReplaceDeconvolutionByCol2Im(),
                MergeSgemmAndElementwiseMul(),
                ConstantFolding(),
                ReplaceLinearBySgemm(),
                MergeSgemmAndElementwiseMul(),
                ConstantFolding(),
                ConcatLSTMInputAndHidden(),
                RemoveRedundantOperator(),
                RemoveNoEffectOperator(),
                UpdateInplaceAttribute()
            ]),
            ElementwiseKernelFusion()
        ]

        if flags.DEBUG:
            sub_rules.append(DumpGraph("cg{count}.dot"))

        super(WebGPUOptimizeRule, self).__init__(sub_rules)
    def __init__(self):
        sub_rules = [
            InsertTranspose(),

            ReplaceConvolutionByIm2Col(),
            MergeSgemmAndElementwiseMul(),
            ConstantFolding(),

            ReplaceDeconvolutionByCol2Im(),
            MergeSgemmAndElementwiseMul(),
            ConstantFolding(),

            ReplaceLinearBySgemm(),
            MergeSgemmAndElementwiseMul(),
            ConstantFolding(),

            UseEigen(),
            ElementwiseKernelFusion(),
            UpdateInplaceAttribute()
        ]

        if flags.DEBUG:
            sub_rules.append(DumpGraph("cg{count}.dot"))

        super(WebassemblyOptimizeRule, self).__init__(sub_rules)
def test_remove():
    c = ConstantVariable(np.random.rand(2, 3, 4, 5), OrderNCHW)
    v = Variable(c.shape, c.order)

    y = v + c
    op = y.output_from

    assert not op.has_attribute(Inplace)

    UpdateInplaceAttribute().optimize(Graph([v], [y]))

    assert op.has_attribute(Inplace)

    v.change_order(OrderNHWC)
    UpdateInplaceAttribute().optimize(Graph([v], [y]))

    assert not op.has_attribute(Inplace)
예제 #5
0
 def __init__(self):
     super(WebassemblyOptimizeRule, self).__init__([
         InsertTranspose(),
         ReplaceConvolutionByIm2Col(),
         MergeSgemmAndElementwiseMul(),
         ConstantFolding(),
         ReplaceDeconvolutionByCol2Im(),
         MergeSgemmAndElementwiseMul(),
         ConstantFolding(),
         ReplaceLinearBySgemm(),
         MergeSgemmAndElementwiseMul(),
         ConstantFolding(),
         OptimizeSgemmEigen(),
         ElementwiseKernelFusion(),
         UpdateInplaceAttribute()
     ])
예제 #6
0
 def __init__(self):
     super(WebGPUOptimizeRule, self).__init__([
         OptimizeRuleGroup([
             InsertTranspose(),
             ReplaceConvolutionByIm2Col(),
             MergeSgemmAndElementwiseMul(),
             ConstantFolding(),
             ReplaceDeconvolutionByCol2Im(),
             MergeSgemmAndElementwiseMul(),
             ConstantFolding(),
             ReplaceLinearBySgemm(),
             MergeSgemmAndElementwiseMul(),
             ConstantFolding(),
             ConcatLSTMInputAndHidden(),
             RemoveRedundantOperator(),
             RemoveNoEffectOperator(),
             UpdateInplaceAttribute()
         ]),
         ElementwiseKernelFusion()
     ])
def test_input():
    """
    test_input

    v[Input] -+
              +-{Add}- y
           c -+
    """

    c = ConstantVariable(np.random.rand(2, 3, 4, 5), OrderNCHW)
    v = Variable(c.shape, c.order)
    v.attributes.add(Input())

    y = v + c
    op = y.output_from

    assert not op.has_attribute(Inplace)

    UpdateInplaceAttribute().optimize(Graph([v], [y]))

    assert not op.has_attribute(Inplace)
def test_no_change1():
    """
    test_no_change1

    c[OrderNCHW] -+
                  +-{Add}- y
    v[OrderNHWC] -+
    """

    c = ConstantVariable(np.random.rand(2, 3, 4, 5), OrderNCHW)
    v = Variable(c.shape, c.order)

    v.change_order(OrderNHWC)

    y = c + v
    op = y.output_from

    assert not op.has_attribute(Inplace)

    UpdateInplaceAttribute().optimize(Graph([v], [y]))

    assert not op.has_attribute(Inplace)
def test_constant():
    """
    test_constant

    c1 -+
        +-{Add}- h -+
    c2 -+           +- y
                 v -+
    """

    c1 = ConstantVariable(np.random.rand(2, 3, 4, 5), OrderNCHW)
    c2 = ConstantVariable(np.random.rand(2, 3, 4, 5), OrderNCHW)
    v = Variable(c1.shape, c1.order)

    h = c1 + c2
    y = h + v
    op = h.output_from

    assert not op.has_attribute(Inplace)

    UpdateInplaceAttribute().optimize(Graph([v], [y]))

    assert not op.has_attribute(Inplace)