def test_goloop_no_children(): ''' Attempt to generate code for a loop that has no child kernel calls ''' from psyclone.gocean1p0 import GOLoop, GOSchedule gosched = GOSchedule([]) gojloop = GOLoop(parent=gosched, loop_type="outer") goiloop = GOLoop(parent=gosched, loop_type="inner") gosched.addchild(gojloop) gojloop.addchild(goiloop) # Try and generate the code for this loop even though it # has no children with pytest.raises(GenerationError): goiloop.gen_code(None)
def test_goloop_unsupp_offset(): ''' Attempt to generate code for a loop with constant bounds with an unsupported index offset ''' from psyclone.gocean1p0 import GOLoop, GOSchedule, GOKern gosched = GOSchedule([]) gojloop = GOLoop(parent=gosched, loop_type="outer") goiloop = GOLoop(parent=gosched, loop_type="inner") gosched.addchild(gojloop) gojloop.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.addchild(gokern) with pytest.raises(GenerationError): goiloop.gen_code(None)
def test_profile_basic(capsys): '''Check basic functionality: node names, schedule view. ''' 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() coloured_schedule = GOSchedule([]).coloured_text coloured_loop = Loop().coloured_text coloured_kern = GOKern().coloured_text coloured_profile = invoke.schedule.children[0].coloured_text # Do one test based on schedule view, to make sure colouring # and indentation is correct correct = ( '''{0}[invoke='invoke_0',Constant loop bounds=True] {3} {1}[type='outer',field_space='go_cv',it_space='go_internal_pts'] {1}[type='inner',field_space='go_cv',it_space='go_internal_pts'] {2} compute_cv_code(cv_fld,p_fld,v_fld) ''' '''[module_inline=False] {1}[type='outer',field_space='go_ct',it_space='go_all_pts'] {1}[type='inner',field_space='go_ct',it_space='go_all_pts'] {2} bc_ssh_code(ncycle,p_fld,tmask) ''' '''[module_inline=False]'''.format(coloured_schedule, coloured_loop, coloured_kern, coloured_profile) ) assert correct 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 = ("""GOSchedule(Constant loop bounds=True): ProfileStart[var=profile] Loop[]: j= lower=2,jstop-1,1 ProfileStart[var=profile_1] Loop[]: i= lower=2,istop,1 kern call: compute_cv_code EndLoop ProfileEnd EndLoop Loop[]: j= lower=1,jstop+1,1 Loop[]: i= lower=1,istop+1,1 kern call: bc_ssh_code EndLoop EndLoop ProfileEnd End Schedule""") assert correct in new_sched_str Profiler.set_options(None)