transformations.data_offload

Classes

DataOffloadTransformation(**kwargs)

Utility transformation to insert data offload regions for GPU devices based on marked !$loki data regions.

GlobalVarOffloadTransformation([key])

Transformation class that facilitates insertion of offload directives for module variable imports.

class DataOffloadTransformation(**kwargs)

Bases: Transformation

Utility transformation to insert data offload regions for GPU devices based on marked !$loki data regions. In the first instance this will insert OpenACC data offload regions, but can be extended to other offload region semantics (eg. OpenMP-5) in the future.

Parameters:

remove_openmp (bool) – Remove any existing OpenMP pragmas inside the marked region.

transform_subroutine(routine, **kwargs)

Apply the transformation to a Subroutine object.

Parameters:
  • routine (Subroutine) – Subroutine to apply this transformation to.

  • role (string) – Role of the routine in the scheduler call tree. This transformation will only apply at the 'driver' level.

  • targets (list or string) – List of subroutines that are to be considered as part of the transformation call tree.

insert_data_offload_pragmas(routine, targets)

Find !$loki data pragma regions and create according !$acc udpdate regions.

Parameters:
  • routine (Subroutine) – Subroutine to apply this transformation to.

  • targets (list or string) – List of subroutines that are to be considered as part of the transformation call tree.

remove_openmp_pragmas(routine, targets)

Remove any existing OpenMP pragmas in the offload regions that will have been intended for OpenMP threading rather than offload.

Parameters:
  • routine (Subroutine) – Subroutine to apply this transformation to.

  • targets (list or string) – List of subroutines that are to be considered as part of the transformation call tree.

class GlobalVarOffloadTransformation(key=None)

Bases: Transformation

Transformation class that facilitates insertion of offload directives for module variable imports. The following offload paradigms are currently supported:

  • OpenACC

It comprises of three main components. process_kernel which collects a set of imported variables to offload, transform_module which adds device-side declarations for the imported variables to the relevant modules, and process_driver which adds offload instructions at the driver-layer. !$loki update_device and !$loki update_host pragmas are needed in the driver source to insert offload and/or copy-back directives. The functionality is illustrated in the example below.

E.g., the following code:

module moduleB
   real :: var2
   real :: var3
end module moduleB

module moduleC
   real :: var4
   real :: var5
end module moduleC

subroutine driver()
implicit none

!$loki update_device
!$acc serial
call kernel()
!$acc end serial
!$loki update_host

end subroutine driver

subroutine kernel()
use moduleB, only: var2,var3
use moduleC, only: var4,var5
implicit none
!$acc routine seq

var4 = var2
var5 = var3

end subroutine kernel

is transformed to:

module moduleB
   real :: var2
   real :: var3
  !$acc declare create(var2)
  !$acc declare create(var3)
end module moduleB

module moduleC
   real :: var4
   real :: var5
  !$acc declare create(var4)
  !$acc declare create(var5)
end module moduleC

subroutine driver()
implicit none

!$acc update device( var2,var3 )
!$acc serial
call kernel()
!$acc end serial
!$acc update self( var4,var5 )

end subroutine driver

Nested Fortran derived-types and arrays of derived-types are not currently supported. If such an import is encountered, only the device-side declaration will be added to the relevant module file, and the offload instructions will have to manually be added afterwards.

NB: This transformation should only be used as part of a Scheduler traversal, and must be run in reverse, e.g.: scheduler.process(transformation=GlobalVarOffloadTransformation(), reverse=True)

Parameters:

key (str, optional) – Overwrite the key that is used to store analysis results in trafo_data.

transform_module(module, **kwargs)

Add device-side declarations for imported variables.

transform_subroutine(routine, **kwargs)

Defines the transformation to apply to Subroutine items.

For transformations that modify Subroutine objects, this method should be implemented. It gets called via the dispatch method apply().

Parameters:
  • routine (Subroutine) – The subroutine to be transformed.

  • **kwargs (optional) – Keyword arguments for the transformation.

process_driver(routine, successors)

Add offload and/or copy-back directives for the imported variables.

process_kernel(routine, successors, item)

Collect the set of module variables to be offloaded.