Ejemplo n.º 1
0
def test_pad_4x3():
    z = {}  # problemType definition
    conv = Convolution(z,
                       'ConvolutionForward',
                       config={
                           'TensorAFormat': 'NCHW',
                           'Filter': '4x3',
                           'PadStart': 'NxN',
                           'PadEnd': 'NxN',
                       })
    log.debug(conv.printUsage(z))
    e = {
        'n': 1,
        'c': 4,
        'h': 12,
        'w': 8,
        'k': 1,
        'p': 1,
        'p_': 2,
        'q': 3,
        'q_': 4
    }
    ec = ConvProblem(e, conv)
    assert (ec.zeroPadA[0] == [0, 5, 3, 4])
    assert (ec.zeroPadA[1] == [1, 4, 8, 16])
    assert (len(ec.zeroPadA) == 2)
Ejemplo n.º 2
0
    def ConvolutionContraction(cls, conv, problemType, solution, dataType, \
                                problemFunc, generateConvFormat=True, problemLevel=1):
        """
        Generates a YamlBuilder object that will run a convolution, in normal
        contraction mode.
        """

        availableArchs = cls.findAvailableArchs()
        benchmarkParams = solution()

        for item in benchmarkParams["ForkParameters"]:
            if 'MatrixInstruction' in item and 'gfx908' not in availableArchs:
                pytest.skip()
                break

        doc = cls.Header(debug=False)

        if generateConvFormat:
            tensileProblemType = {
                "OperationType":
                conv.convolutionType,
                "ConvolutionConfig": [{
                    key: val
                } for (key, val) in conv.config.items()],
                "DataType":
                dataType
            }
        else:
            tensileProblemType = {
                "OperationType": "TensorContraction",
                "DataType": dataType
            }
            tensileProblemType.update(problemType)

        for (key, value) in conv.solutionParms.items():
            benchmarkParams["ForkParameters"].append({key: [value]})
        problems = problemFunc(conv, problemType, problemLevel)

        #print("problems:", problems)
        if generateConvFormat:
            convs = [{"Conv": e} for e in problems]
            benchmarkParams["BenchmarkFinalParameters"] = [{
                "ProblemSizes":
                convs
            }]
        else:
            exacts = [{
                "Exact": dict(ConvProblem(p, conv).toExactDict())
            } for p in problems]
            benchmarkParams["BenchmarkFinalParameters"] = [{
                "ProblemSizes":
                exacts
            }]

        doc["BenchmarkProblems"] = [[tensileProblemType, benchmarkParams]]

        #print (doc)

        return cls(doc)
Ejemplo n.º 3
0
def test_bad_invalid_list():
    z = {}  # problemType definition
    conv = Convolution(z,
                       'ConvolutionForward',
                       config={
                           'TensorAFormat': 'NCHW',
                           'Stride': '2x3',
                       })
    log.debug(conv.printUsage(z))
    e = [1, 2, 3, 4]
    with pytest.raises(Exception, match="ConvProblem must be a dictionary"):
        ConvProblem(e, conv)
Ejemplo n.º 4
0
def test_stride2x3_defaults():
    z = {}  # problemType definition
    conv = Convolution(z,
                       'ConvolutionForward',
                       config={
                           'TensorAFormat': 'NCHW',
                           'Stride': '2x3',
                       })
    log.debug(conv.printUsage(z))
    e = {'n': 64, 'c': 256, 'h': 20, 'w': 14, 'k': 1024}
    ec = ConvProblem(e, conv)
    assert (ec.sizes == (4, 10, e['k'], e['n'], e['c']))
    assert (ec.stridesA == (3, 28, -1, -1))
Ejemplo n.º 5
0
def test_pad_4x1():
    z = {}  # problemType definition
    conv = Convolution(z,
                       'ConvolutionForward',
                       config={
                           'TensorAFormat': 'NCHW',
                           'Filter': '4x1',
                           'PadStart': 'Nx0',
                           'PadEnd': 'Nx0',
                       })
    log.debug(conv.printUsage(z))
    e = {'n': 1, 'c': 4, 'h': 12, 'w': 8, 'k': 1, 'p': 2, 'p_': 3}
    ec = ConvProblem(e, conv)
    assert (ec.zeroPadA == [[1, 4, 2, 3]])
Ejemplo n.º 6
0
def test_bad_missing_field():
    z = {}  # problemType definition
    conv = Convolution(z,
                       'ConvolutionForward',
                       config={
                           'TensorAFormat': 'NCHW',
                           'Stride': '2x3',
                       })
    log.debug(conv.printUsage(z))
    e = {'c': 256, 'h': 20, 'w': 14, 'k': 1024, 'x': 1, 'y': 1, 'u': 1, 'v': 1}
    with pytest.raises(
            Exception,
            match="required ConvProblem field 'n' not present in ConvProblem"):
        ConvProblem(e, conv)
Ejemplo n.º 7
0
def test_bad_invalid_field():
    z = {}  # problemType definition
    conv = Convolution(z,
                       'ConvolutionForward',
                       config={
                           'TensorAFormat': 'NCHW',
                           'Stride': '2x3',
                       })
    log.debug(conv.printUsage(z))
    e = {
        'A': 123,
        'n': 64,
        'c': 256,
        'h': 20,
        'w': 14,
        'k': 1024,
        'x': 1,
        'y': 1,
        'u': 1,
        'v': 1
    }
    with pytest.raises(Exception, match="unknown ConvProblem field 'A'"):
        ConvProblem(e, conv)
Ejemplo n.º 8
0
def test_bad_stride():
    z = {}  # problemType definition
    conv = Convolution(z,
                       'ConvolutionForward',
                       config={
                           'TensorAFormat': 'NCHW',
                           'Stride': '2x3',
                       })
    log.debug(conv.printUsage(z))
    e = {
        'n': 64,
        'c': 256,
        'h': 20,
        'w': 14,
        'k': 1024,
        'x': 1,
        'y': 1,
        'u': 7,
        'v': 2
    }
    with pytest.raises(RuntimeError, \
            match="Mismatch between ConvolutionConfig value.*stride"):
        ConvProblem(e, conv)
Ejemplo n.º 9
0
def test_bad_filter():
    z = {}  # problemType definition
    conv = Convolution(z,
                       'ConvolutionForward',
                       config={
                           'TensorAFormat': 'NCHW',
                       })
    log.debug(conv.printUsage(z))
    e = {
        'n': 64,
        'c': 256,
        'h': 20,
        'w': 14,
        'k': 1024,
        'x': 2,
        'y': 1,
        'u': 1,
        'v': 1
    }
    with pytest.raises(RuntimeError, \
            #match="Mismatch between ConvolutionConfig value \(1\) and specified value \(2\) for filter[0]."):

            match="Mismatch between ConvolutionConfig value"):
        ConvProblem(e, conv)