|
1 | 1 | # ----------------------------------------------------------------------------- |
2 | 2 | # BSD 3-Clause License |
3 | 3 | # |
4 | | -# Copyright (c) 2017-2026, Science and Technology Facilities Council |
| 4 | +# Copyright (c) 2018-2026, Science and Technology Facilities Council. |
5 | 5 | # All rights reserved. |
6 | 6 | # |
7 | 7 | # Redistribution and use in source and binary forms, with or without |
|
31 | 31 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
32 | 32 | # POSSIBILITY OF SUCH DAMAGE. |
33 | 33 | # ----------------------------------------------------------------------------- |
34 | | -# Authors: R. W. Ford and A. R. Porter, STFC Daresbury Lab |
| 34 | +# Authors: R. W. Ford, A. R. Porter and S. Siso, STFC Daresbury Lab |
35 | 35 |
|
36 | | -'''A simple test script showing basic usage of the PSyclone API. |
37 | | -In order to use it you must first install PSyclone like so: |
| 36 | +''' PSyclone script to fuse invoke_0 loops and insert OpenMP directives ''' |
38 | 37 |
|
39 | | - >>> pip install --user psyclone |
| 38 | +from psyclone.psyir.nodes import FileContainer |
| 39 | +from psyclone.psyGen import InvokeSchedule |
| 40 | +from psyclone.psyGen import TransInfo |
40 | 41 |
|
41 | | -(or see the Getting Going section in the User Guide). Once PSyclone |
42 | | -is installed this script may be run by doing: |
43 | 42 |
|
44 | | - >>> python runme.py |
| 43 | +def trans(psyir: FileContainer): |
| 44 | + ''' |
| 45 | + :param psyir: the PSyIR of the PSy-layer. |
45 | 46 |
|
46 | | -This should generate a lot of output, ending with a view of the |
47 | | -Schedules: |
| 47 | + ''' |
| 48 | + invokes = psyir.walk(InvokeSchedule) |
48 | 49 |
|
49 | | - >>> ... |
50 | | - >>> Schedule[invoke='invoke_0'] |
51 | | - >>> Loop[type='outer',field_space='cu',it_space='internal_pts'] |
52 | | - >>> Loop[type='inner',field_space='cu',it_space='internal_pts'] |
53 | | - >>> CodedKern compute_cu_code(cu_fld,p_fld,u_fld) |
54 | | - >>> Loop[type='outer',field_space='cv',it_space='internal_pts'] |
55 | | - >>> Loop[type='inner',field_space='cv',it_space='internal_pts'] |
56 | | - >>> CodedKern compute_cv_code(cv_fld,p_fld,v_fld) |
57 | | - >>>... |
| 50 | + # Print a list of all of the invokes found |
| 51 | + print([invoke.name for invoke in invokes]) |
58 | 52 |
|
59 | | -''' |
| 53 | + trans_info = TransInfo() |
| 54 | + print(trans_info.list) |
| 55 | + fuse_trans = trans_info.get_trans_name('LoopFuseTrans') |
| 56 | + omp_trans = trans_info.get_trans_name('GOceanOMPParallelLoopTrans') |
60 | 57 |
|
61 | | -from psyclone.parse.algorithm import parse |
62 | | -from psyclone.psyGen import PSyFactory |
63 | | -from psyclone.psyir.backend.fortran import FortranWriter |
64 | | - |
65 | | -API = "gocean" |
66 | | -_, INVOKEINFO = parse("shallow_alg.f90", api=API) |
67 | | -PSY = PSyFactory(API).create(INVOKEINFO) |
68 | | - |
69 | | -# Print the 'vanilla' generated Fortran |
70 | | -writer = FortranWriter() |
71 | | -print(writer(PSY.container)) |
72 | | - |
73 | | -# Print a list of all of the invokes found |
74 | | -print(PSY.invokes.names) |
75 | | - |
76 | | -# Print the Schedule of each of these Invokes |
77 | | -SCHEDULE = PSY.invokes.get('invoke_0').schedule |
78 | | -print(SCHEDULE.view()) |
79 | | - |
80 | | -SCHEDULE = PSY.invokes.get('invoke_1').schedule |
81 | | -print(SCHEDULE.view()) |
82 | | - |
83 | | -SCHEDULE = PSY.invokes.get('invoke_2').schedule |
84 | | -print(SCHEDULE.view()) |
| 58 | + for invoke in invokes: |
| 59 | + if invoke.name == "invoke_0": |
| 60 | + # fuse all outer loops |
| 61 | + fuse_trans.apply(invoke.children[0], invoke.children[1]) |
| 62 | + fuse_trans.apply(invoke.children[0], invoke.children[1]) |
| 63 | + fuse_trans.apply(invoke.children[0], invoke.children[1]) |
| 64 | + # fuse all inner loops |
| 65 | + fuse_trans.apply(invoke.children[0].loop_body[0], |
| 66 | + invoke.children[0].loop_body[1]) |
| 67 | + fuse_trans.apply(invoke.children[0].loop_body[0], |
| 68 | + invoke.children[0].loop_body[1]) |
| 69 | + fuse_trans.apply(invoke.children[0].loop_body[0], |
| 70 | + invoke.children[0].loop_body[1]) |
| 71 | + # Add OpenMP |
| 72 | + omp_trans.apply(invoke.children[0]) |
0 commit comments