Fork me on GitHub

src/arraymancer/tensor/data_structure

  Source Edit

Types

AnyTensor[T] = Tensor[T] or CudaTensor[T] or ClTensor[T]
  Source Edit
ClStorage[T] = object
  Flen*: int
  Fdata*: ptr UncheckedArray[T]
  Fref_tracking*: ref [ptr UncheckedArray[T]]
Opaque seq-like structure for storage on the OpenCL backend.   Source Edit
ClTensor[T] = object
  shape*: Metadata
  strides*: Metadata
  offset*: int
  storage*: ClStorage[T]
Tensor data structure stored on OpenCL (CPU, GPU, FPGAs or other accelerators)
  • shape: Dimensions of the CudaTensor
  • strides: Numbers of items to skip to get the next item along a dimension.
  • offset: Offset to get the first item of the CudaTensor. Note: offset can be negative, in particular for slices.
  • storage: An opaque data storage for the CudaTensor

Warning âš : Assignment var a = b does not copy the data. Data modification on one CudaTensor will be reflected on the other. However modification on metadata (shape, strides or offset) will not affect the other tensor. Explicit copies can be made with clone: var a = b.clone

  Source Edit
CudaStorage[T] = object
  Flen*: int
  Fdata*: ptr UncheckedArray[T]
  Fref_tracking*: ref [ptr UncheckedArray[T]]

Opaque seq-like structure for storage on the Cuda backend.

Nim garbage collector will automatically ask cuda to clear GPU memory if data becomes unused.

  Source Edit
CudaTensor[T] = object
  shape*: Metadata
  strides*: Metadata
  offset*: int
  storage*: CudaStorage[T]
Tensor data structure stored on Nvidia GPU (Cuda)
  • shape: Dimensions of the CudaTensor
  • strides: Numbers of items to skip to get the next item along a dimension.
  • offset: Offset to get the first item of the CudaTensor. Note: offset can be negative, in particular for slices.
  • storage: An opaque data storage for the CudaTensor

Warning âš : Assignment var a = b does not copy the data. Data modification on one CudaTensor will be reflected on the other. However modification on metadata (shape, strides or offset) will not affect the other tensor. Explicit copies can be made with clone: var a = b.clone

  Source Edit

Procs

proc data=[T](t: var Tensor[T]; s: seq[T]) {.
    ...deprecated: "Use copyFromRaw instead".}
Deprecated: Use copyFromRaw instead
  Source Edit
proc dataArray[T: KnownSupportsCopyMem](t: Tensor[T]): ptr UncheckedArray[T] {.
    noSideEffect, inline, ...deprecated: "Use toUnsafeView instead".}
Deprecated: Use toUnsafeView instead
Input:
- A tensor

Returns:

- A pointer to the offset start of the data.
  Return value supports array indexing.
  Source Edit
proc dataArray[T: not KnownSupportsCopyMem](t: Tensor[T]): ptr UncheckedArray[T] {.error: "`dataArray`  is deprecated for mem copyable types and not supported for GC\'ed types!".}
  Source Edit
proc get_data_ptr[T: KnownSupportsCopyMem](t: Tensor[T]): ptr T {.noSideEffect,
    inline.}
Input:
- A tensor

Returns:

- A pointer to the real start of its data (no offset)
  Source Edit
proc get_data_ptr[T: not KnownSupportsCopyMem](t: AnyTensor[T]): ptr T {.
    error: "`get_data_ptr` cannot be safely used for GC\'ed types!".}
  Source Edit
proc get_data_ptr[T](t: CudaTensor[T] or ClTensor[T]): ptr T {.noSideEffect,
    inline.}
Input:
- A tensor

Returns:

- A pointer to the real start of its data (no offset)
  Source Edit
proc get_offset_ptr[T: KnownSupportsCopyMem](t: Tensor[T]): ptr T {.
    noSideEffect, inline.}
Input:
- A tensor

Returns:

- A pointer to the offset start of its data
  Source Edit
proc get_offset_ptr[T: not KnownSupportsCopyMem](t: AnyTensor[T]): ptr T {.
    error: "`get_offset_ptr` cannot be safely used for GC\'ed types!".}
  Source Edit
proc get_offset_ptr[T](t: CudaTensor[T] or ClTensor[T]): ptr T {.noSideEffect,
    inline.}
Input:
- A tensor

Returns:

- A pointer to the offset start of its data
  Source Edit
func is_C_contiguous(t: CudaTensor or ClTensor): bool
Check if the tensor follows C convention / is row major   Source Edit
proc is_F_contiguous(t: AnyTensor): bool {.noSideEffect, inline.}
Check if the tensor follows Fortran convention / is column major   Source Edit
proc isContiguous(t: AnyTensor): bool {.noSideEffect, inline.}
Check if the tensor is contiguous   Source Edit
func rank[T](t: CudaTensor[T] or ClTensor[T]): range[0 .. LASER_MAXRANK] {.
    inline.}
  Source Edit
proc shape_to_strides(shape: Metadata; layout: OrderType = rowMajor;
                      result: var Metadata) {.noSideEffect, ...raises: [],
    tags: [], forbids: [].}
Input:
- A shape (Metadata), for example [3,5] for a 3x5 matrix
- Optionally rowMajor (C layout - default) or colMajor (Fortran)

Returns:

- The strides in C or Fortran order corresponding to this shape and layout

 Arraymancer defaults to rowMajor. Temporarily, CudaTensors are colMajor by default.

  Source Edit
func size[T](t: CudaTensor[T] or ClTensor[T]): Natural {.inline.}
  Source Edit
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood