Reference Guide  2.5.0
psyclone.transformations.ACCRoutineTrans Class Reference
Inheritance diagram for psyclone.transformations.ACCRoutineTrans:
Collaboration diagram for psyclone.transformations.ACCRoutineTrans:

Public Member Functions

def name (self)
 
def apply (self, node, options=None)
 
def validate (self, node, options=None)
 
- Public Member Functions inherited from psyclone.transformations.MarkRoutineForGPUMixin
def validate_it_can_run_on_gpu (self, node, options)
 

Detailed Description

Transform a kernel or routine by adding a "!$acc routine" directive
(causing it to be compiled for the OpenACC accelerator device).
For example:

>>> from psyclone.parse.algorithm import parse
>>> from psyclone.psyGen import PSyFactory
>>> api = "gocean1.0"
>>> ast, invokeInfo = parse(GOCEAN_SOURCE_FILE, api=api)
>>> psy = PSyFactory(api).create(invokeInfo)
>>>
>>> from psyclone.transformations import ACCRoutineTrans
>>> rtrans = ACCRoutineTrans()
>>>
>>> schedule = psy.invokes.get('invoke_0').schedule
>>> # Uncomment the following line to see a text view of the schedule
>>> # print(schedule.view())
>>> kern = schedule.children[0].children[0].children[0]
>>> # Transform the kernel
>>> rtrans.apply(kern)

Definition at line 2507 of file transformations.py.

Member Function Documentation

◆ apply()

def psyclone.transformations.ACCRoutineTrans.apply (   self,
  node,
  options = None 
)
Add the '!$acc routine' OpenACC directive into the code of the
supplied Kernel (in a PSyKAl API such as GOcean or LFRic) or directly
in the supplied Routine.

:param node: the kernel call or routine implementation to transform.
:type node: :py:class:`psyclone.psyGen.Kern` or \
            :py:class:`psyclone.psyir.nodes.Routine`
:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 2538 of file transformations.py.

2538  def apply(self, node, options=None):
2539  '''
2540  Add the '!$acc routine' OpenACC directive into the code of the
2541  supplied Kernel (in a PSyKAl API such as GOcean or LFRic) or directly
2542  in the supplied Routine.
2543 
2544  :param node: the kernel call or routine implementation to transform.
2545  :type node: :py:class:`psyclone.psyGen.Kern` or \
2546  :py:class:`psyclone.psyir.nodes.Routine`
2547  :param options: a dictionary with options for transformations.
2548  :type options: Optional[Dict[str, Any]]
2549 
2550  '''
2551  # Check that we can safely apply this transformation
2552  self.validate(node, options)
2553 
2554  if isinstance(node, Kern):
2555  # Flag that the kernel has been modified
2556  node.modified = True
2557 
2558  # Get the schedule representing the kernel subroutine
2559  routine = node.get_kernel_schedule()
2560  else:
2561  routine = node
2562 
2563  # Insert the directive to the routine if it doesn't already exist
2564  for child in routine.children:
2565  if isinstance(child, ACCRoutineDirective):
2566  return # The routine is already marked with ACCRoutine
2567  routine.children.insert(0, ACCRoutineDirective())
2568 

References psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata.validate(), psyclone.transformations.MoveTrans.validate(), psyclone.transformations.Dynamo0p3AsyncHaloExchangeTrans.validate(), psyclone.domain.common.transformations.alg_invoke_2_psy_call_trans.AlgInvoke2PSyCallTrans.validate(), psyclone.domain.common.transformations.alg_trans.AlgTrans.validate(), psyclone.domain.common.transformations.kernel_module_inline_trans.KernelModuleInlineTrans.validate(), psyclone.domain.common.transformations.raise_psyir_2_alg_trans.RaisePSyIR2AlgTrans.validate(), psyclone.domain.gocean.transformations.gocean_const_loop_bounds_trans.GOConstLoopBoundsTrans.validate(), psyclone.domain.gocean.transformations.gocean_move_iteration_boundaries_inside_kernel_trans.GOMoveIterationBoundariesInsideKernelTrans.validate(), psyclone.domain.gocean.transformations.gocean_opencl_trans.GOOpenCLTrans.validate(), psyclone.domain.gocean.transformations.raise_psyir_2_gocean_kern_trans.RaisePSyIR2GOceanKernTrans.validate(), psyclone.domain.lfric.transformations.lfric_alg_invoke_2_psy_call_trans.LFRicAlgInvoke2PSyCallTrans.validate(), psyclone.domain.lfric.transformations.raise_psyir_2_lfric_kern_trans.RaisePSyIR2LFRicKernTrans.validate(), psyclone.domain.nemo.transformations.create_nemo_invoke_schedule_trans.CreateNemoInvokeScheduleTrans.validate(), psyclone.domain.nemo.transformations.create_nemo_psy_trans.CreateNemoPSyTrans.validate(), psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans.validate(), psyclone.domain.nemo.transformations.nemo_arrayrange2loop_trans.NemoArrayRange2LoopTrans.validate(), psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans.validate(), psyclone.psyad.transformations.assignment_trans.AssignmentTrans.validate(), psyclone.psyGen.Transformation.validate(), psyclone.psyir.transformations.acc_update_trans.ACCUpdateTrans.validate(), psyclone.psyir.transformations.allarrayaccess2loop_trans.AllArrayAccess2LoopTrans.validate(), psyclone.psyir.transformations.arrayaccess2loop_trans.ArrayAccess2LoopTrans.validate(), psyclone.psyir.transformations.arrayrange2loop_trans.ArrayRange2LoopTrans.validate(), psyclone.psyir.transformations.chunk_loop_trans.ChunkLoopTrans.validate(), psyclone.psyir.transformations.fold_conditional_return_expressions_trans.FoldConditionalReturnExpressionsTrans.validate(), psyclone.psyir.transformations.hoist_local_arrays_trans.HoistLocalArraysTrans.validate(), psyclone.psyir.transformations.hoist_loop_bound_expr_trans.HoistLoopBoundExprTrans.validate(), psyclone.psyir.transformations.hoist_trans.HoistTrans.validate(), psyclone.psyir.transformations.inline_trans.InlineTrans.validate(), psyclone.psyir.transformations.intrinsics.array_reduction_base_trans.ArrayReductionBaseTrans.validate(), psyclone.psyir.transformations.intrinsics.dotproduct2code_trans.DotProduct2CodeTrans.validate(), psyclone.psyir.transformations.intrinsics.intrinsic2code_trans.Intrinsic2CodeTrans.validate(), psyclone.psyir.transformations.intrinsics.matmul2code_trans.Matmul2CodeTrans.validate(), psyclone.psyir.transformations.loop_swap_trans.LoopSwapTrans.validate(), psyclone.psyir.transformations.loop_tiling_2d_trans.LoopTiling2DTrans.validate(), psyclone.psyir.transformations.loop_trans.LoopTrans.validate(), psyclone.psyir.transformations.omp_task_trans.OMPTaskTrans.validate(), psyclone.psyir.transformations.omp_taskwait_trans.OMPTaskwaitTrans.validate(), psyclone.psyir.transformations.parallel_loop_trans.ParallelLoopTrans.validate(), psyclone.psyir.transformations.reference2arrayrange_trans.Reference2ArrayRangeTrans.validate(), psyclone.psyir.transformations.replace_induction_variables_trans.ReplaceInductionVariablesTrans.validate(), psyclone.transformations.OMPDeclareTargetTrans.validate(), psyclone.transformations.DynamoOMPParallelLoopTrans.validate(), psyclone.transformations.Dynamo0p3OMPLoopTrans.validate(), psyclone.transformations.GOceanOMPLoopTrans.validate(), psyclone.transformations.Dynamo0p3RedundantComputationTrans.validate(), psyclone.transformations.Dynamo0p3KernelConstTrans.validate(), psyclone.transformations.ACCRoutineTrans.validate(), psyclone.transformations.KernelImportsToArguments.validate(), psyclone.domain.gocean.transformations.gocean_loop_fuse_trans.GOceanLoopFuseTrans.validate(), psyclone.domain.lfric.transformations.lfric_loop_fuse_trans.LFRicLoopFuseTrans.validate(), psyclone.psyir.transformations.loop_fuse_trans.LoopFuseTrans.validate(), psyclone.domain.gocean.transformations.gocean_extract_trans.GOceanExtractTrans.validate(), psyclone.domain.lfric.transformations.lfric_extract_trans.LFRicExtractTrans.validate(), psyclone.psyir.transformations.extract_trans.ExtractTrans.validate(), psyclone.psyir.transformations.nan_test_trans.NanTestTrans.validate(), psyclone.psyir.transformations.read_only_verify_trans.ReadOnlyVerifyTrans.validate(), psyclone.transformations.ParallelRegionTrans.validate(), psyclone.transformations.OMPParallelTrans.validate(), psyclone.transformations.ACCParallelTrans.validate(), psyclone.transformations.ACCKernelsTrans.validate(), psyclone.transformations.ACCDataTrans.validate(), psyclone.psyir.transformations.psy_data_trans.PSyDataTrans.validate(), psyclone.psyir.transformations.region_trans.RegionTrans.validate(), and psyclone.transformations.ACCEnterDataTrans.validate().

Here is the call graph for this function:

◆ name()

def psyclone.transformations.ACCRoutineTrans.name (   self)
:returns: the name of this transformation class.
:rtype: str

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 2531 of file transformations.py.

2531  def name(self):
2532  '''
2533  :returns: the name of this transformation class.
2534  :rtype: str
2535  '''
2536  return "ACCRoutineTrans"
2537 
Here is the caller graph for this function:

◆ validate()

def psyclone.transformations.ACCRoutineTrans.validate (   self,
  node,
  options = None 
)
Perform checks that the supplied kernel or routine can be transformed.

:param node: the kernel or routine which is the target of this
    transformation.
:type node: :py:class:`psyclone.psyGen.Kern` |
            :py:class:`psyclone.psyir.nodes.Routine`
:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]
:param bool options["force"]: whether to allow routines with
    CodeBlocks to run on the GPU.

:raises TransformationError: if the node is not a kernel or a routine.
:raises TransformationError: if the target is a built-in kernel.
:raises TransformationError: if it is a kernel but without an
                             associated PSyIR.
:raises TransformationError: if any of the symbols in the kernel are
                             accessed via a module use statement.
:raises TransformationError: if the kernel contains any calls to other
                             routines.

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 2569 of file transformations.py.

2569  def validate(self, node, options=None):
2570  '''
2571  Perform checks that the supplied kernel or routine can be transformed.
2572 
2573  :param node: the kernel or routine which is the target of this
2574  transformation.
2575  :type node: :py:class:`psyclone.psyGen.Kern` |
2576  :py:class:`psyclone.psyir.nodes.Routine`
2577  :param options: a dictionary with options for transformations.
2578  :type options: Optional[Dict[str, Any]]
2579  :param bool options["force"]: whether to allow routines with
2580  CodeBlocks to run on the GPU.
2581 
2582  :raises TransformationError: if the node is not a kernel or a routine.
2583  :raises TransformationError: if the target is a built-in kernel.
2584  :raises TransformationError: if it is a kernel but without an
2585  associated PSyIR.
2586  :raises TransformationError: if any of the symbols in the kernel are
2587  accessed via a module use statement.
2588  :raises TransformationError: if the kernel contains any calls to other
2589  routines.
2590  '''
2591  super().validate(node, options)
2592 
2593  self.validate_it_can_run_on_gpu(node, options)
2594 
2595 

References psyclone.transformations.MarkRoutineForGPUMixin.validate_it_can_run_on_gpu().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: