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

Public Member Functions

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

Detailed Description

Adds an OpenMP declare target directive to the specified routine.

For example:

>>> from psyclone.psyir.frontend.fortran import FortranReader
>>> from psyclone.psyir.nodes import Loop
>>> from psyclone.transformations import OMPDeclareTargetTrans
>>>
>>> tree = FortranReader().psyir_from_source("""
...     subroutine my_subroutine(A)
...         integer, dimension(10, 10), intent(inout) :: A
...         integer :: i
...         integer :: j
...         do i = 1, 10
...             do j = 1, 10
...                 A(i, j) = 0
...             end do
...         end do
...     end subroutine
...     """
>>> omptargettrans = OMPDeclareTargetTrans()
>>> omptargettrans.apply(tree.walk(Routine)[0])

will generate:

.. code-block:: fortran

    subroutine my_subroutine(A)
        integer, dimension(10, 10), intent(inout) :: A
        integer :: i
        integer :: j
        !$omp declare target
        do i = 1, 10
            do j = 1, 10
                A(i, j) = 0
            end do
        end do
    end subroutine

Definition at line 483 of file transformations.py.

Member Function Documentation

◆ apply()

def psyclone.transformations.OMPDeclareTargetTrans.apply (   self,
  node,
  options = None 
)
 Insert an OMPDeclareTargetDirective inside the provided routine.

:param node: the PSyIR routine to insert the directive into.
:type node: :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 525 of file transformations.py.

525  def apply(self, node, options=None):
526  ''' Insert an OMPDeclareTargetDirective inside the provided routine.
527 
528  :param node: the PSyIR routine to insert the directive into.
529  :type node: :py:class:`psyclone.psyir.nodes.Routine`
530  :param options: a dictionary with options for transformations.
531  :type options: Optional[Dict[str, Any]]
532 
533  '''
534  self.validate(node, options)
535  for child in node.children:
536  if isinstance(child, OMPDeclareTargetDirective):
537  return # The routine is already marked with OMPDeclareTarget
538  node.children.insert(0, OMPDeclareTargetDirective())
539 

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:

◆ validate()

def psyclone.transformations.OMPDeclareTargetTrans.validate (   self,
  node,
  options = None 
)
 Check that an OMPDeclareTargetDirective can be inserted.

: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 540 of file transformations.py.

540  def validate(self, node, options=None):
541  ''' Check that an OMPDeclareTargetDirective can be inserted.
542 
543  :param node: the kernel or routine which is the target of this
544  transformation.
545  :type node: :py:class:`psyclone.psyGen.Kern` |
546  :py:class:`psyclone.psyir.nodes.Routine`
547  :param options: a dictionary with options for transformations.
548  :type options: Optional[Dict[str, Any]]
549  :param bool options["force"]: whether to allow routines with
550  CodeBlocks to run on the GPU.
551 
552  :raises TransformationError: if the node is not a kernel or a routine.
553  :raises TransformationError: if the target is a built-in kernel.
554  :raises TransformationError: if it is a kernel but without an
555  associated PSyIR.
556  :raises TransformationError: if any of the symbols in the kernel are
557  accessed via a module use statement.
558  :raises TransformationError: if the kernel contains any calls to other
559  routines.
560 
561  '''
562  super().validate(node, options=options)
563 
564  self.validate_it_can_run_on_gpu(node, options)
565 
566 

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: