# loki.transformations.field_api module

A set of utility classes for dealing with FIELD API boilerplate in parallel kernels and offload regions.

class FieldAPITransferType(*values)

  Bases: `Enum`

  READ_ONLY = 'RDONLY'
  READ_WRITE = 'RDWR'
  WRITE_ONLY = 'WRONLY'
  FORCE = 'FORCE'
  property suffix

class FieldPointerMap(inargs, inoutargs, outargs, scope, ptr_prefix='loki_ptr_')

  Bases: `object`

  Helper class to map FIELD API pointers to intents and access descriptors.

  This utility is used to store arrays passed to target kernel calls and easily access corresponding device pointers added by the transformation.

  dataptr_from_array(a: Array)

    Returns a contiguous pointer `Variable` with types matching the array `a`.

  static field_ptr_from_view(field_view)

    Returns a symbol for the pointer to the corresponding Field object.

  property args

    A tuple of all argument symbols, concatanating in/inout/out arguments

  property dataptrs

    Create a list of contiguous data pointer symbols

  property host_to_device_calls

    Returns a tuple of `CallStatement` for host-to-device transfers on fields.

  property sync_host_calls

    Returns a tuple of `CallStatement` for host-synchronization transfers on fields.

  host_to_device_force_calls(queue=None, blk_bounds=None, offset=None)

    Returns a tuple of `CallStatement` for host-to-device force transfers on fields.

  sync_host_force_calls(queue=None, blk_bounds=None, offset=None)

    Returns a tuple of `CallStatement` for host-synchronization transfers on fields.

get_field_type(a: Array) → DerivedType

  Returns the corresponding FIELD API type for an array.

  This function is IFS specific and assumes that the type is an array declared with one of the IFS type specifiers, e.g. KIND=JPRB

field_get_device_data(field_ptr, dev_ptr, transfer_type: FieldAPITransferType, scope: Scope, queue=None, blk_bounds=None, offset=None, accessor_type: FieldAPIAccessorType = FieldAPIAccessorType.TYPE_BOUND)

  Utility function to generate a `CallStatement` corresponding to a Field API `GET_DEVICE_DATA` call.

  Parameters:

    - field_ptr (pointer to field object) – Pointer to the field to call `GET_DEVICE_DATA` from.

    - dev_ptr (`Array`) – Device pointer array

    - transfer_type (`FieldAPITransferType`) – Field API transfer type to determine which `GET_DEVICE_DATA` method to call.

    - scope (`Scope`) – Scope of the created `CallStatement`

    - queue (integer) – `QUEUE` optional argument

    - blk_bounds (integer dimension(2) array) – `BLK_BOUNDS` optional argument

    - offset (integer) – `OFFSET` optional argument

    - accessor_type (`FieldAPIAccessorType`) – Type of accessor to be used, e.g., ‘get_’ type bound method or ‘sget’

field_get_host_data(field_ptr, dev_ptr, transfer_type: FieldAPITransferType, scope: Scope, queue=None, blk_bounds=None, offset=None, accessor_type: FieldAPIAccessorType = FieldAPIAccessorType.TYPE_BOUND)

  Utility function to generate a `CallStatement` corresponding to a Field API `GET_HOST_DATA` call.

  Parameters:

    - field_ptr (pointer to field object) – Pointer to the field to call `GET_DEVICE_DATA` from.

    - dev_ptr (`Array`) – Device pointer array

    - transfer_type (`FieldAPITransferType`) – Field API transfer type to determine which `GET_HOST_DATA` method to call.

    - scope (`Scope`) – Scope of the created `CallStatement`

    - queue (integer) – `QUEUE` optional argument

    - blk_bounds (integer dimension(2) array) – `BLK_BOUNDS` optional argument

    - offset (integer) – `OFFSET` optional argument

    - accessor_type (`FieldAPIAccessorType`) – Type of accessor to be used, e.g., ‘get_’ type bound method or ‘sget’

field_sync_device(field_ptr, transfer_type: FieldAPITransferType, scope: Scope, queue=None, blk_bounds=None, offset=None)

  Utility function to generate a `CallStatement` corresponding to a Field API `SYNC_DEVICE` call.

  Parameters:

    - field_ptr (pointer to field object) – Pointer to the field to call `SYNC_HOST` from.

    - transfer_type (`FieldAPITransferType`) – Field API transfer type to determine which `SYNC_DEVICE` method to call.

    - scope (`Scope`) – Scope of the created `CallStatement`

    - queue (integer) – `QUEUE` optional argument

    - blk_bounds (integer dimension(2) array) – `BLK_BOUNDS` optional argument

    - offset (integer) – `OFFSET` optional argument

field_sync_host(field_ptr, transfer_type: FieldAPITransferType, scope: Scope, queue=None, blk_bounds=None, offset=None)

  Utility function to generate a `CallStatement` corresponding to a Field API `SYNC_HOST` call.

  Parameters:

    - field_ptr (pointer to field object) – Pointer to the field to call `SYNC_HOST` from.

    - transfer_type (`FieldAPITransferType`) – Field API transfer type to determine which `SYNC_HOST` method to call.

    - scope (`Scope`) – Scope of the created `CallStatement`

    - queue (integer) – `QUEUE` optional argument

    - blk_bounds (integer dimension(2) array) – `BLK_BOUNDS` optional argument

    - offset (integer) – `OFFSET` optional argument

field_create_device_data(field_ptr, scope: Scope, blk_bounds=None)

  Utility unction to generate a `CallStatement` corresponding to a Field API CREATE_DEVICE_DATA call.

  Parameters:

    - field_ptr (pointer to field object) – Pointer to the field to call `DELETE_DEVICE_DATA` from.

    - scope (`Scope`) – Scope of the created `CallStatement`

    - blk_bounds (integer dimension(2) array) – `BLK_BOUNDS` optional argument

field_delete_device_data(field_ptr, scope)

  Utility unction to generate a `CallStatement` corresponding to a Field API DELETE_DEVICE_DATA call.

  Parameters:

    - field_ptr (pointer to field object) – Pointer to the field to call `DELETE_DEVICE_DATA` from.

    - scope (`Scope`) – Scope of the created `CallStatement`

field_wait_for_async_queue(queue, scope: Scope)

class FieldAPIAccessorType(*values)

  Bases: `Enum`

  TYPE_BOUND = 'GET'

    Create FIELD_API data access calls using the native type-bound methods e.g.

        CALL FIELD%GET_HOST/DEVICE_DATA_...()

  GENERIC = 'SGET'

    Create FIELD_API data access calls using a generic interface that takes a FIELD as an argument e.g.

        CALL SGET_HOST/DEVICE_DATA_...(..., FIELD)

    This mode offers additional safety for uninitialised and zero-sized fields.