Module tornado.api

Class TornadoNativeArray

java.lang.Object
uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
Direct Known Subclasses:
ByteArray, CharArray, DoubleArray, FloatArray, HalfFloatArray, Int8Array, IntArray, LongArray, ShortArray, Tensor

public abstract sealed class TornadoNativeArray extends Object permits ByteArray, CharArray, DoubleArray, FloatArray, HalfFloatArray, IntArray, LongArray, ShortArray, Int8Array, Tensor
TornadoNativeArray relies on preview features of the Java platform:
  • TornadoNativeArray refers to one or more preview APIs: MemorySegment.
Programs can only use TornadoNativeArray when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
This abstract sealed class represents the common functionality of the TornadoVM custom native arrays, (e.g., ByteArray, IntArray, etc.)

The class provides methods for retrieving the number of elements stored in the native arrays, for obtaining the underlying memory segment, for clearing the data, for calculating the total number of bytes occupied by the memory segment, and for getting the number of bytes, excluding the array header size.

The constant ARRAY_HEADER represents the size of the header in bytes.

  • Field Details

    • ARRAY_HEADER

      public static final long ARRAY_HEADER
      The size of the header in bytes. It sets the default value either to 16 or 24, depending on whether the uncompressed flags are passed by the user. It can also be configurable through the "tornado.panama.objectHeader" system property.
  • Constructor Details

    • TornadoNativeArray

      public TornadoNativeArray()
  • Method Details

    • getSize

      public abstract int getSize()
      Returns the number of elements stored in the native array.
      Returns:
      The number of elements of the native data array.
    • getSegment

      public abstract MemorySegmentPREVIEW getSegment()
      Returns the underlying MemorySegmentPREVIEW of the native array, without the Tornado Array header.
      Returns:
      The MemorySegmentPREVIEW associated with the native array instance.
    • getSegmentWithHeader

      public abstract MemorySegmentPREVIEW getSegmentWithHeader()
      Returns the underlying MemorySegmentPREVIEW of the native array, including the header.
      Returns:
      The MemorySegmentPREVIEW associated with the native array instance.
    • getNumBytesOfSegmentWithHeader

      public abstract long getNumBytesOfSegmentWithHeader()
      Returns the total number of bytes that the MemorySegmentPREVIEW occupies, including the header bytes.
      Returns:
      The total number of bytes of the MemorySegmentPREVIEW.
    • getNumBytesOfSegment

      public abstract long getNumBytesOfSegment()
      Returns the number of bytes of the MemorySegmentPREVIEW, excluding the header bytes.
      Returns:
      The number of bytes of the raw data in the MemorySegmentPREVIEW.
    • clear

      protected abstract void clear()
      Clears the contents of the native array.
    • getElementSize

      public abstract int getElementSize()