Skip to content

Commit

Permalink
#2730 Add gen_code support for OpenMP target directives
Browse files Browse the repository at this point in the history
  • Loading branch information
sergisiso committed Oct 2, 2024
1 parent 3f39f9f commit 8992b75
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/lfric/scripts/gpu_offloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def trans(psy):
# Add GPU offloading to loops unless they are over colours or are null.
schedule = invoke.schedule
for loop in schedule.walk(Loop):
if offload or all(kern.name.lower() in failed_to_offload for
kern in loop.kernels()):
if offload and all(kern.name.lower() not in failed_to_offload for
kern in loop.kernels()):
try:
if loop.loop_type == "colours":
pass
Expand Down
2 changes: 1 addition & 1 deletion src/psyclone/f2pygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class OMPDirective(Directive):
'''
def __init__(self, root, line, position, dir_type):
self._types = ["parallel do", "parallel", "do", "master", "single",
"taskloop", "taskwait", "declare"]
"taskloop", "taskwait", "declare", "target"]
self._positions = ["begin", "end"]

super(OMPDirective, self).__init__(root, line, position, dir_type)
Expand Down
13 changes: 13 additions & 0 deletions src/psyclone/psyir/nodes/omp_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -2402,6 +2402,19 @@ def end_string(self):
'''
return "omp end target"

def gen_code(self, parent):
'''Generate the OpenMP Target Directive and any associated code.
:param parent: the parent Node in the Schedule to which to add our
content.
:type parent: sub-class of :py:class:`psyclone.f2pygen.BaseGen`
'''
# Check the constraints are correct
self.validate_global_constraints()

# Generate the code for this Directive
parent.add(DirectiveGen(parent, "omp", "begin", "target"))


class OMPLoopDirective(OMPRegionDirective):
''' Class for the !$OMP LOOP directive that specifies that the iterations
Expand Down
15 changes: 13 additions & 2 deletions src/psyclone/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,21 @@ def apply(self, node, options=None):
'''
self.validate(node, options)
for child in node.children:

if isinstance(node, Kern):
# Flag that the kernel has been modified
node.modified = True

# Get the schedule representing the kernel subroutine
routine = node.get_kernel_schedule()
else:
routine = node

for child in routine.children:
if isinstance(child, OMPDeclareTargetDirective):
return # The routine is already marked with OMPDeclareTarget
node.children.insert(0, OMPDeclareTargetDirective())

routine.children.insert(0, OMPDeclareTargetDirective())

def validate(self, node, options=None):
''' Check that an OMPDeclareTargetDirective can be inserted.
Expand Down

0 comments on commit 8992b75

Please sign in to comment.