Ejemplo n.º 1
0
def test_loop_trans_validate_nemo_specific(monkeypatch):
    ''' Test the NEMO-specifc part of the validation routine.
    TODO #435 remove this test. '''
    trans = OMPParallelLoopTrans()
    _, invoke_info = get_invoke("explicit_do.f90", api="nemo", idx=0)
    schedule = invoke_info.schedule
    loop = schedule.loops()[0]
    monkeypatch.setattr(loop, "_annotations", ["was_where"])
    with pytest.raises(TransformationError) as err:
        trans.validate(loop)
    assert ("In the NEMO API a transformation cannot be applied to a PSyIR "
            "loop representing a WHERE construct." in str(err.value))
Ejemplo n.º 2
0
def test_loop_trans_validate(monkeypatch):
    ''' Test the validation checks on the loop node provided to the
    transformation. '''
    # We have to use sub-class of LoopTrans as it itself is abstract.
    trans = OMPParallelLoopTrans()
    _, invoke = get_invoke("test27_loop_swap.f90", "gocean1.0", idx=1,
                           dist_mem=False)
    with pytest.raises(TransformationError) as err:
        trans.validate(invoke.schedule)
    assert ("Target of OMPParallelLoopTrans transformation must be a sub-"
            "class of Loop but got 'GOInvokeSchedule'" in str(err.value))
    # Check that validate is OK with a valid loop
    loop = invoke.schedule.walk(Loop)[0]
    trans.validate(loop)
    # Pretend that the loop is of 'null' type
    monkeypatch.setattr(loop, "_loop_type", "null")
    with pytest.raises(TransformationError) as err:
        trans.validate(loop)
    assert ("Cannot apply a OMPParallelLoopTrans transformation to a "
            "'null' loop" in str(err.value))
    monkeypatch.undo()
    # Break the contents of the loop
    loop.children = loop.pop_all_children()[0:1]
    with pytest.raises(TransformationError) as err:
        trans.validate(loop)
    assert ("Error in OMPParallelLoopTrans transformation. The target loop "
            "must have four children but found: ['Literal']" in
            str(err.value))
Ejemplo n.º 3
0
def test_parallellooptrans_refuse_codeblock():
    ''' Check that ParallelLoopTrans.validate() rejects a loop nest that
    encloses a CodeBlock. We have to use OMPParallelLoopTrans as
    ParallelLoopTrans is abstract. '''
    otrans = OMPParallelLoopTrans()
    # Construct a valid Loop in the PSyIR with a CodeBlock in its body
    parent = Loop.create(DataSymbol("ji", INTEGER_TYPE),
                         Literal("1",
                                 INTEGER_TYPE), Literal("10", INTEGER_TYPE),
                         Literal("1", INTEGER_TYPE),
                         [CodeBlock([], CodeBlock.Structure.STATEMENT, None)])
    with pytest.raises(TransformationError) as err:
        otrans.validate(parent)
    assert ("Nodes of type 'CodeBlock' cannot be enclosed "
            "by a OMPParallelLoopTrans transformation" in str(err.value))
Ejemplo n.º 4
0
def test_loop_trans_validate_options(monkeypatch):
    ''' Test the options argument to the validate method. '''
    trans = OMPParallelLoopTrans()
    _, invoke = get_invoke("test27_loop_swap.f90", "gocean1.0", idx=1,
                           dist_mem=False)
    loop = invoke.schedule.walk(Loop)[0]
    with pytest.raises(TransformationError) as err:
        trans.validate(loop, options="hello")
    assert ("method 'options' argument must be a dictionary but found 'str'"
            in str(err.value))
    # Monkeypatch the transformation to make it appear that we wish to
    # exclude CodedKern nodes.
    monkeypatch.setattr(trans, "excluded_node_types", (CodedKern, ))
    with pytest.raises(TransformationError) as err:
        trans.validate(loop)
    assert ("Nodes of type 'GOKern' cannot be enclosed by a "
            "OMPParallelLoopTrans transformation" in str(err.value))
    # Now disable this check on excluded node types
    trans.validate(loop, options={"node-type-check": False})
Ejemplo n.º 5
0
def test_loop_trans_validate():
    ''' Test the validation checks on the loop node provided to the
    transformation. '''
    trans = OMPParallelLoopTrans()
    _, invoke = get_invoke("test27_loop_swap.f90",
                           "gocean1.0",
                           idx=1,
                           dist_mem=False)
    with pytest.raises(TransformationError) as err:
        trans.validate(invoke.schedule)
    assert ("Target of OMPParallelLoopTrans transformation must be a sub-"
            "class of Loop but got 'GOInvokeSchedule'" in str(err.value))
    # Check that validate is OK with a valid loop
    loop = invoke.schedule.walk(Loop)[0]
    trans.validate(loop)
    # Break the loop
    loop.children = loop.children[0:1]
    with pytest.raises(TransformationError) as err:
        trans.validate(loop)
    assert ("Error in OMPParallelLoopTrans transformation. The target loop "
            "must have four children but found: ['Literal']" in str(err.value))