Fork me on GitHub
Nothing Special   »   [go: up one dir, main page]

src/arraymancer/laser/tensor/datatypes

Search:
Group by:
  Source Edit

Types

CpuStorage[T] {.shallow.} = ref CpuStorageObj[T]
  Source Edit
KnownSupportsCopyMem = concept xtypeof(T)
    supportsCopyMem(T)
  Source Edit
MetadataArray {....deprecated: "Use Metadata instead".} = Metadata
Deprecated: Use Metadata instead
  Source Edit
RawImmutableView[T] = distinct ptr UncheckedArray[T]
  Source Edit
RawMutableView[T] = distinct ptr UncheckedArray[T]
  Source Edit
Tensor[T] = object
  shape*: Metadata
  strides*: Metadata
  offset*: int
  storage*: CpuStorage[T]
  Source Edit

Procs

proc allocCpuStorage[T](storage: var CpuStorage[T]; size: int)
Allocate aligned memory to hold size elements of type T. If T does not supports copyMem, it is also zero-initialized. I.e. Tensors of seq, strings, ref types or types with non-trivial destructors are always zero-initialized. This prevents potential GC issues.   Source Edit
proc cpuStorageFromBuffer[T: KnownSupportsCopyMem](storage: var CpuStorage[T];
    rawBuffer: pointer; size: int)

Create a CpuStorage, which stores data from a given raw pointer, which it does not own. The destructor/finalizer will be a no-op, because the memory is marked as not owned by the CpuStorage.

The input buffer must be a raw pointer.

  Source Edit
proc initMetadataArray(len: int): Metadata {.inline, ...raises: [], tags: [],
    forbids: [].}
  Source Edit
func is_C_contiguous(t: Tensor): bool
Check if the tensor follows C convention / is row major   Source Edit
func len[T](t: Tensor[T]): int {.inline.}
  Source Edit
func rank[T](t: Tensor[T]): range[0 .. LASER_MAXRANK] {.inline.}
  Source Edit
func size[T](t: Tensor[T]): Natural {.inline.}
  Source Edit
proc toMetadataArray(s: varargs[int]): Metadata {.inline, ...raises: [], tags: [],
    forbids: [].}
  Source Edit
func unsafe_raw_buf[T: KnownSupportsCopyMem](t: Tensor[T];
    aligned: static bool = true): RawImmutableView[T] {.inline.}

Returns a view to the start of the data buffer

Unsafe: the pointer can outlive the input tensor For optimization purposes, Laser will hint the compiler that while the pointer is valid, all data accesses will be through it (no aliasing) and that the data is aligned by LASER_MEM_ALIGN (default 64).

  Source Edit
func unsafe_raw_buf[T: KnownSupportsCopyMem](t: var Tensor[T];
    aligned: static bool = true): RawMutableView[T] {.inline.}

Returns a view to the start of the data buffer

Unsafe: the pointer can outlive the input tensor For optimization purposes, Laser will hint the compiler that while the pointer is valid, all data accesses will be through it (no aliasing) and that the data is aligned by LASER_MEM_ALIGN (default 64).

  Source Edit
func unsafe_raw_buf[T: not KnownSupportsCopyMem](t: Tensor[T];
    aligned: static bool = true): ptr UncheckedArray[T] {.
    error: "Access via raw pointer forbidden for non mem copyable types!".}
  Source Edit
func unsafe_raw_offset[T: KnownSupportsCopyMem](t: Tensor[T];
    aligned: static bool = true): RawImmutableView[T] {.inline.}

Returns a view to the start of the valid data

Unsafe: the pointer can outlive the input tensor For optimization purposes, Laser will hint the compiler that while the pointer is valid, all data accesses will be through it (no aliasing) and that the data is aligned by LASER_MEM_ALIGN (default 64).

  Source Edit
func unsafe_raw_offset[T: KnownSupportsCopyMem](t: var Tensor[T];
    aligned: static bool = true): RawMutableView[T] {.inline.}

Returns a view to the start of the valid data

Unsafe: the pointer can outlive the input tensor For optimization purposes, Laser will hint the compiler that while the pointer is valid, all data accesses will be through it (no aliasing) and that the data is aligned by LASER_MEM_ALIGN (default 64).

  Source Edit
func unsafe_raw_offset[T: not KnownSupportsCopyMem](t: Tensor[T];
    aligned: static bool = true): ptr UncheckedArray[T] {.
    error: "Access via raw pointer forbidden for non mem copyable types!".}
  Source Edit

Macros

macro raw_data_unaligned(body: untyped): untyped

Within this code block, all raw data accesses will not be assumed aligned by default (LASER_MEM_ALIGN is 64 by default). Use this when interfacing with external buffers of unknown alignment.

⚠️ Warning: At the moment Nim's builtin term-rewriting macros are not scoped. All processing within the file this is called will be considered unaligned. https://github.com/nim-lang/Nim/issues/7214#issuecomment-431567894.

  Source Edit

Templates

template `[]`[T](v: RawImmutableView[T]; idx: int): T
  Source Edit
template `[]`[T](v: RawMutableView[T]; idx: int): var T
  Source Edit
template `[]=`[T](v: RawMutableView[T]; idx: int; val: T)
  Source Edit
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood