# loki.transformations.data_offload.field_offload

Functions

`add_async_blocking_vars`(routine, block_loop, ...) | Add the variables required for asynchronous blocked offloading over multiple queues to the routine.
`add_async_queue_to_pragmas`(section, queue) | Add async pragma content to Loki data and driver-loop pragmas in the section.
`add_blocked_field_offload_calls`(driver, ...) | Add blocked Field API data transfer calls to a region inside a block loop.
`add_device_field_allocations`(driver, ...) | Add Field API device data allocation calls for variables in offload_map.
`add_field_offload_calls`(driver, region, ...) |
`add_wait_calls`(driver, block_loop, queue, ...) | Add wait calls to synchronize all queues after a block loop.
`block_driver_loop`(driver, region, block_size) | Block a driver loop inside a code region.
`declare_device_ptrs`(driver, deviceptrs) | Add a set of data pointer declarations to a given `Subroutine`
`find_offload_variables`(driver, region, ...) | Find the sets of array variable symbols for which we can generate Field API offload code.
`replace_offload_args`(driver, region, ...) | Replace instances of offload variables with their device pointers inside the region.

Classes

`FieldOffloadBlockedTransformation`(block_size) | Transformation to perform blocked offload of arrays owned by Field API fields to the device.
`FieldOffloadTransformation`([devptr_prefix, ...]) | Transformation to offload arrays owned by Field API fields to the device.

class FieldOffloadTransformation(devptr_prefix=None, field_group_types=None, offload_index=None)

  Bases: `Transformation`

  Transformation to offload arrays owned by Field API fields to the device.

  This transformation is IFS specific.

  The transformation assumes that fields are wrapped in derived types specified in `field_group_types` and will only offload arrays that are members of such derived types. In the process this transformation removes calls to Field API `update_view` and adds declarations for the device pointers to the driver subroutine.

  The transformation acts on `!$loki data` regions and offloads all `Array` symbols that satisfy the following conditions:

  1. The array is a member of an object that is of type specified in `field_group_types`.

  2. The array is passed as a parameter to at least one of the kernel targets passed to `transform_subroutine`.

  Parameters:

    - deviceptr_prefix (str, optional) – The prefix of device pointers added by this transformation (defaults to `'loki_devptr_'`).

    - field_group_types (list or tuple of str, optional) – Names of the field group types with members that may be offloaded (defaults to `['']`).

    - offload_index (str, optional) – Names of index variable to inject in the outmost dimension of offloaded arrays in the kernel calls (defaults to `'IBL'`).

  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(driver)

class FieldOffloadBlockedTransformation(block_size, devptr_prefix=None, field_group_types=None, offload_index=None, asynchronous=False, num_queues=1)

  Bases: `Transformation`

  Transformation to perform blocked offload of arrays owned by Field API fields to the device.

  This transformation is IFS specific.

  The transformation assumes that fields are wrapped in derived types specified in `field_group_types` and will only offload arrays that are members of such derived types. In the process this transformation removes calls to Field API `update_view` and adds declarations for the device pointers to the driver subroutine.

  The transformation acts on `!$loki data` regions and offloads all `Array` symbols that satisfy the following conditions:

  1. The array is a member of an object that is of type specified in `field_group_types`.

  2. The array is passed as a parameter to at least one of the kernel targets passed to `transform_subroutine`.

  Parameters:

    - block_size (int) – Number of blocks per chunk (specified in the final dimension of the field).

    - deviceptr_prefix (str, optional) – The prefix of device pointers added by this transformation (defaults to `'loki_devptr_'`).

    - field_group_types (list or tuple of str, optional) – Names of the field group types with members that may be offloaded (defaults to `['']`).

    - offload_index (str, optional) – Names of index variable to inject in the outmost dimension of offloaded arrays in the kernel calls (defaults to `'IBL'`).

    - asynchronous (bool, optional) – Perform asynchronous blocked offload (defaults to `False`)

    - num_queues (int, optional) – Number of queues for asynchronous offload should be set to 2 or higher for asynchronous offload (defaults to 1).

  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(driver)

find_offload_variables(driver, region, field_group_types)

  Find the sets of array variable symbols for which we can generate Field API offload code.

  Note

  This method requires Loki’s dataflow analysis to be run on the `region` via `dataflow_analysis_attached()`.

  Parameters:

    - region (`PragmaRegion`) – Code region object for which to determine offload variables

    - field_group_types (list or tuple of str, optional) – Names of the field group types with members that may be offloaded (defaults to `['']`).

  Returns:

    (inargs, inoutargs, outargs) – The sets of array symbols split into three tuples according to access type.

  Return type:

    (tuple, tuple, tuple)

add_field_offload_calls(driver, region, offload_map)

replace_offload_args(driver, region, offload_map, offload_index)

  Replace instances of offload variables with their device pointers inside the region.

  Parameters:

    - driver (`Subroutine`) – Subroutine containing the data region.

    - region (`PragmaRegion`) – Data region in which offload variables in the offload map will be replaced.

    - offload_map (`FieldPointerMap`) – FieldPointerMap with variables to be offloaded.

    - offload_index (str) – Name of index variable to inject in the outmost dimension of offloaded pointers.