Example #1
0
def test_schedule_view(capsys):
    ''' Check the schedule view/str methods work as expected '''
    from psyclone.psyGen import colored
    from psyclone.nemo import NEMO_SCHEDULE_COLOUR_MAP
    _, invoke_info = parse(os.path.join(BASE_PATH, "io_in_loop.f90"),
                           api=API,
                           line_length=False)
    psy = PSyFactory(API, distributed_memory=False).create(invoke_info)
    sched = psy.invokes.invoke_list[0].schedule
    sched_str = str(sched)
    assert "NemoLoop[levels]: jk=1,jpk,1" in sched_str
    assert "NemoLoop[lat]: jj=1,jpj,1" in sched_str
    assert "NemoLoop[lon]: ji=1,jpi,1" in sched_str
    sched.view()
    output, _ = capsys.readouterr()

    # Have to allow for colouring of output text
    loop_str = colored("Loop", NEMO_SCHEDULE_COLOUR_MAP["Loop"])
    kern_str = colored("KernCall", NEMO_SCHEDULE_COLOUR_MAP["KernCall"])
    sched_str = colored("Schedule", NEMO_SCHEDULE_COLOUR_MAP["Schedule"])

    expected_sched = (sched_str + "[]\n"
                      "    " + loop_str + "[type='levels',field_space='None',"
                      "it_space='None']\n"
                      "        " + loop_str + "[type='lat',field_space='None',"
                      "it_space='None']\n"
                      "            " + loop_str +
                      "[type='lon',field_space='None',"
                      "it_space='None']\n"
                      "                " + kern_str + "[Explicit]\n"
                      "    " + loop_str + "[type='levels',field_space='None',"
                      "it_space='None']\n"
                      "        " + loop_str + "[type='lat',field_space='None',"
                      "it_space='None']\n"
                      "            " + loop_str +
                      "[type='lon',field_space='None',"
                      "it_space='None']\n"
                      "                ")
    assert expected_sched in output
    expected_sched2 = (loop_str + "[type='levels',field_space='None',"
                       "it_space='None']\n"
                       "        " + loop_str +
                       "[type='lat',field_space='None',"
                       "it_space='None']\n"
                       "            " + loop_str +
                       "[type='lon',field_space='None',"
                       "it_space='None']\n"
                       "                ")
    assert expected_sched2 in output
Example #2
0
def test_extract_node_representation(capsys):
    ''' Test that representation properties and methods of the ExtractNode
    class: view, dag_name and __str__ produce the correct results. '''
    from psyclone.psyGen import colored, SCHEDULE_COLOUR_MAP

    etrans = DynamoExtractRegionTrans()

    _, invoke_info = parse(os.path.join(DYNAMO_BASE_PATH,
                                        "4.8_multikernel_invokes.f90"),
                           api=DYNAMO_API)
    psy = PSyFactory(DYNAMO_API, distributed_memory=False).create(invoke_info)
    invoke = psy.invokes.invoke_list[0]
    schedule = invoke.schedule
    children = schedule.children[1:3]
    schedule, _ = etrans.apply(children)

    # Test view() method
    schedule.view()
    output, _ = capsys.readouterr()
    expected_output = colored("Extract", SCHEDULE_COLOUR_MAP["Extract"])
    assert expected_output in output

    # Test dag_name method
    assert schedule.children[1].dag_name == "extract_1"

    # Test __str__ method
    assert "End DynLoop\nExtractStart\nDynLoop[id:''" in str(schedule)
    assert "End DynLoop\nExtractEnd\nDynLoop[id:''" in str(schedule)
    # Count the loops inside and outside the extract to check it is in
    # the right place
    [before, after] = str(schedule).split("ExtractStart")
    [inside, after] = after.split("ExtractEnd")
    assert before.count("Loop[") == 1
    assert inside.count("Loop[") == 2
    assert after.count("Loop[") == 2
Example #3
0
    def coloured_text(self):
        '''
        Return text containing the (coloured) name of this node type

        :return: the name of this node type, possibly with control codes
                 for colour
        :rtype: string
        '''
        return colored("Profile", SCHEDULE_COLOUR_MAP["Profile"])
Example #4
0
    def coloured_text(self):
        '''
        Returns a string containing the name of this Node along with \
        control characters for colouring in terminals that supports it.

        :returns: the name of this Node, possibly with control codes for \
                  colouring.
        :rtype: str
        '''
        return colored("Extract", SCHEDULE_COLOUR_MAP["Extract"])
Example #5
0
    def coloured_text(self):
        '''
        Returns a string containing the name of this node along with
        control characters for colouring in terminals that support it.

        :returns: The name of this node, possibly with control codes for
                  colouring
        :rtype: string
        '''
        return colored("NemoImplicitLoop", SCHEDULE_COLOUR_MAP["Loop"])
Example #6
0
def test_goschedule_view(capsys):
    ''' Test that the GOSchedule::view() method works as expected '''
    from psyclone.psyGen import colored, SCHEDULE_COLOUR_MAP
    _, invoke_info = parse(os.path.join(
        os.path.dirname(os.path.abspath(__file__)), "test_files", "gocean1p0",
        "single_invoke_two_kernels.f90"),
                           api=API)
    psy = PSyFactory(API).create(invoke_info)
    invoke = psy.invokes.invoke_list[0]
    invoke.schedule.view()

    # The view method writes to stdout and this is captured by py.test
    # by default. We have to query this captured output.
    out, _ = capsys.readouterr()

    # Ensure we check for the correct (colour) control codes in the output
    sched = colored("GOSchedule", SCHEDULE_COLOUR_MAP["Schedule"])
    loop = colored("Loop", SCHEDULE_COLOUR_MAP["Loop"])
    call = colored("KernCall", SCHEDULE_COLOUR_MAP["KernCall"])

    expected_output = (sched +
                       "[invoke='invoke_0',Constant loop bounds=True]\n"
                       "    " + loop + "[type='outer',field_space='cu',"
                       "it_space='internal_pts']\n"
                       "        " + loop + "[type='inner',field_space='cu',"
                       "it_space='internal_pts']\n"
                       "            " + call +
                       " compute_cu_code(cu_fld,p_fld,u_fld) "
                       "[module_inline=False]\n"
                       "    " + loop + "[type='outer',field_space='every',"
                       "it_space='internal_pts']\n"
                       "        " + loop + "[type='inner',field_space='every',"
                       "it_space='internal_pts']\n"
                       "            " + call +
                       " time_smooth_code(u_fld,unew_fld,uold_fld) "
                       "[module_inline=False]")

    assert expected_output in out
Example #7
0
def test_schedule_view(capsys):
    ''' Check the schedule view/str methods work as expected '''
    from psyclone.psyGen import colored, SCHEDULE_COLOUR_MAP
    _, invoke_info = parse(os.path.join(BASE_PATH, "io_in_loop.f90"),
                           api=API,
                           line_length=False)
    psy = PSyFactory(API, distributed_memory=False).create(invoke_info)
    sched = psy.invokes.invoke_list[0].schedule
    sched_str = str(sched)
    assert "NemoLoop[id:'', variable:'ji', loop_type:'lon']" in sched_str
    assert "NemoLoop[id:'', variable:'jj', loop_type:'lat']" in sched_str
    assert "NemoLoop[id:'', variable:'jk', loop_type:'levels']" in sched_str
    sched.view()
    output, _ = capsys.readouterr()

    # Have to allow for colouring of output text
    loop_str = colored("Loop", SCHEDULE_COLOUR_MAP["Loop"])
    kern_str = colored("CodedKern", SCHEDULE_COLOUR_MAP["CodedKern"])
    isched_str = colored("InvokeSchedule", SCHEDULE_COLOUR_MAP["Schedule"])
    sched_str = colored("Schedule", SCHEDULE_COLOUR_MAP["Schedule"])
    lit_str = colored("Literal", SCHEDULE_COLOUR_MAP["Literal"])
    ref_str = colored("Reference", SCHEDULE_COLOUR_MAP["Reference"])

    expected_sched = (isched_str + "[]\n"
                      "    " + loop_str +
                      "[type='levels', field_space='None', "
                      "it_space='None']\n"
                      "        " + lit_str + "[value:'1']\n"
                      "        " + ref_str + "[name:'jpk']\n"
                      "        " + lit_str + "[value:'1']\n"
                      "        " + sched_str + "[]\n"
                      "            " + loop_str +
                      "[type='lat', field_space='None', "
                      "it_space='None']\n"
                      "                " + lit_str + "[value:'1']\n"
                      "                " + ref_str + "[name:'jpj']\n"
                      "                " + lit_str + "[value:'1']\n"
                      "                " + sched_str + "[]\n"
                      "                    " + loop_str +
                      "[type='lon', field_space='None', "
                      "it_space='None']\n"
                      "                        " + lit_str + "[value:'1']\n"
                      "                        " + ref_str + "[name:'jpi']\n"
                      "                        " + lit_str + "[value:'1']\n"
                      "                        " + sched_str + "[]\n"
                      "                            " + kern_str + "[]\n")
    assert expected_sched in output
Example #8
0
def test_profile_basic(capsys):
    '''Check basic functionality: node names, schedule view.
    '''
    from psyclone.psyGen import colored, SCHEDULE_COLOUR_MAP
    Profiler.set_options([Profiler.INVOKES])
    _, invoke = get_invoke("test11_different_iterates_over_one_invoke.f90",
                           "gocean1.0",
                           idx=0)

    assert isinstance(invoke.schedule.children[0], ProfileNode)

    invoke.schedule.view()
    out, _ = capsys.readouterr()

    gsched = colored("GOInvokeSchedule", SCHEDULE_COLOUR_MAP["Schedule"])
    loop = Loop().coloured_text
    profile = invoke.schedule.children[0].coloured_text

    # Do one test based on schedule view, to make sure colouring
    # and indentation is correct
    expected = (gsched + "[invoke='invoke_0', Constant loop bounds=True]\n"
                "    " + profile + "\n"
                "        " + loop + "[type='outer', field_space='go_cv', "
                "it_space='go_internal_pts']\n")

    assert expected in out

    prt = ProfileRegionTrans()

    # Insert a profile call between outer and inner loop.
    # This tests that we find the subroutine node even
    # if it is not the immediate parent.
    new_sched, _ = prt.apply(
        invoke.schedule.children[0].children[0].children[0])

    new_sched_str = str(new_sched)

    correct = ("""GOInvokeSchedule(Constant loop bounds=True):
ProfileStart[var=profile]
GOLoop[id:'', variable:'j', loop_type:'outer']
Literal[value:'2']
Literal[value:'jstop-1']
Literal[value:'1']
Schedule:
GOLoop[id:'', variable:'i', loop_type:'inner']
Literal[value:'2']
Literal[value:'istop']
Literal[value:'1']
Schedule:
kern call: compute_cv_code
End Schedule
End GOLoop
End Schedule
End GOLoop
GOLoop[id:'', variable:'j', loop_type:'outer']
Literal[value:'1']
Literal[value:'jstop+1']
Literal[value:'1']
Schedule:
GOLoop[id:'', variable:'i', loop_type:'inner']
Literal[value:'1']
Literal[value:'istop+1']
Literal[value:'1']
Schedule:
kern call: bc_ssh_code
End Schedule
End GOLoop
End Schedule
End GOLoop
ProfileEnd
End Schedule""")
    assert correct in new_sched_str

    Profiler.set_options(None)
Example #9
0
 def coloured_text(self):
     ''' Return the name of this object with control-codes for
     display in terminals that support colour '''
     from psyclone.psyGen import colored, SCHEDULE_COLOUR_MAP
     return colored("GOSchedule", SCHEDULE_COLOUR_MAP["Schedule"])