Beispiel #1
0
def test_goloop_no_children():
    ''' Attempt to generate code for a loop that has no child
    kernel calls '''
    gosched = GOInvokeSchedule('name', [])
    gojloop = GOLoop(parent=gosched, loop_type="outer")
    goiloop = GOLoop(parent=gosched, loop_type="inner")
    gosched.addchild(gojloop)
    gojloop.loop_body.addchild(goiloop)
    # Try and generate the code for this loop even though it
    # has no children
    with pytest.raises(GenerationError):
        goiloop.gen_code(None)
Beispiel #2
0
def test_gosched_parent():
    ''' Check that the GOInvokeSchedule constructor allows the parent node
    to be supplied or omitted. '''
    _, invoke_info = parse(os.path.join(BASE_PATH,
                                        "single_invoke_two_kernels.f90"),
                           api=API)
    kcalls = invoke_info.calls[0].kcalls
    # With no parent specified
    gsched = GOInvokeSchedule("my_sched", kcalls)
    assert gsched.parent is None
    # With a parent
    cont = Container("my_mod")
    gsched = GOInvokeSchedule("my_sched", kcalls, parent=cont)
    assert gsched.parent is cont
Beispiel #3
0
def test_goloop_bounds_invalid_iteration_space():
    ''' Check that the _upper/lower_bound() methods raise the expected error
    if the iteration space is not recognised. '''
    gosched = GOInvokeSchedule('name', [])
    gojloop = GOLoop(parent=gosched, loop_type="outer")
    # Have to turn-off constant loop bounds to get to the error condition
    gosched._const_loop_bounds = False
    # Set the iteration space to something invalid
    gojloop._iteration_space = "broken"
    with pytest.raises(GenerationError) as err:
        gojloop.upper_bound()
    assert "Unrecognised iteration space, 'broken'." in str(err.value)
    with pytest.raises(GenerationError) as err:
        gojloop.lower_bound()
    assert "Unrecognised iteration space, 'broken'." in str(err.value)
Beispiel #4
0
def test_goloop_unsupp_offset():
    ''' Attempt to generate code for a loop with constant bounds with
    an unsupported index offset '''
    gosched = GOInvokeSchedule('name', [])
    # This test expects constant loop bounds
    gosched._const_loop_bounds = True
    gojloop = GOLoop(parent=gosched, loop_type="outer")
    goiloop = GOLoop(parent=gosched, loop_type="inner")
    gosched.addchild(gojloop)
    gojloop.loop_body.addchild(goiloop)
    gokern = GOKern()
    # Set the index-offset of this kernel to a value that is not
    # supported when using constant loop bounds
    gokern._index_offset = "offset_se"
    goiloop.loop_body.addchild(gokern)
    with pytest.raises(GenerationError):
        goiloop.gen_code(None)
Beispiel #5
0
def test_goloop_unmatched_offsets():
    ''' Attempt to generate code for a loop with constant bounds with
    two different index offsets '''
    gosched = GOInvokeSchedule('name', [])
    gojloop = GOLoop(parent=gosched, loop_type="outer")
    goiloop = GOLoop(parent=gosched, loop_type="inner")
    gosched.addchild(gojloop)
    gojloop.loop_body.addchild(goiloop)
    gokern1 = GOKern()
    gokern2 = GOKern()
    # Set the index-offset of this kernel to a value that is not
    # supported when using constant loop bounds
    gokern1._index_offset = "go_offset_ne"
    gokern2._index_offset = "go_offset_sw"
    goiloop.loop_body.addchild(gokern1)
    goiloop.loop_body.addchild(gokern2)
    with pytest.raises(GenerationError) as excinfo:
        goiloop.gen_code(None)
    # Note that the kernels do not have a name, so there is a double space
    assert "All Kernels must expect the same grid offset but kernel  " \
        "has offset go_offset_sw which does not match go_offset_ne" \
        in str(excinfo.value)
Beispiel #6
0
def test_goloop_lower_to_language_level(monkeypatch):
    ''' Tests that the GOLoop lower_to_language_level method provides the start
    and stop expressions for the loops using the upper/lower_bound methods. '''
    schedule = GOInvokeSchedule('name', [])
    goloop = GOLoop(loop_type="inner", parent=schedule)
    assert goloop.start_expr.value == 'NOT_INITIALISED'
    assert goloop.stop_expr.value == 'NOT_INITIALISED'
    monkeypatch.setattr(GOLoop, "lower_bound",
                        lambda x: Literal("1", INTEGER_TYPE))
    monkeypatch.setattr(GOLoop, "upper_bound",
                        lambda x: Literal("1", INTEGER_TYPE))

    goloop.lower_to_language_level()
    assert goloop.start_expr.value == '1'
    assert goloop.stop_expr.value == '1'
Beispiel #7
0
def test_goloop_no_parent():
    ''' Attempt to generate code for a loop that has no GOInvokeSchedule
    as a parent '''
    # Attempt to create a GOLoop within a generic Schedule
    schedule = Schedule()
    with pytest.raises(GenerationError) as err:
        goloop = GOLoop(loop_type="inner", parent=schedule)
    assert ("GOLoops must always be constructed with a parent which is inside "
            "(directly or indirectly) of a GOInvokeSchedule" in str(err.value))

    # Now create it in a GOInvokeSchedule but then detach it
    schedule = GOInvokeSchedule('name', [])
    goloop = GOLoop(loop_type="inner", parent=schedule)
    schedule.children = [goloop]
    # Now remove parent and children
    goloop.detach()

    # Try and generate the code for this loop even though it
    # has no parent schedule and no children
    with pytest.raises(GenerationError):
        goloop.gen_code(None)