nupp.gpu.layout

Where an element of a tensor actually is.

A layout is a shape, a stride per dimension, and an offset. nupp.gpu uses these to say what a view of a buffer covers without copying it, and the algebra here -- slicing, transposing, reshaping -- returns a new layout over the same storage.

const layout = require("nupp.gpu.layout")

const rows = layout.new({4, 4}, {4, 1})
const column = layout.subview(rows, {0, 2}, {4, 1})

print(column:offset(), column:isDense())

Every operation is checked, so a layout that would read outside its extent is refused rather than produced. A layout knows whether it is dense and whether its stride structure proves that writes use distinct element offsets. A false injectivity result can also mean the bounded stride proof was inconclusive.

Module contents

Types

TypeKindDescription
Layoutrecord

Functions

FunctionKindDescription
asStridedfunction
broadcastfunction
newfunctionChecks a shape and its strides, with the element offset of the first element, 0 unless given.
subviewfunction
transposefunction

Types#

Layoutrecord#

record layout.Layout ...

Members

NameKindDescription
countfield
offsetmethodThe element offset of the layout's first element.
extentmethodOne more than the largest element offset the layout reaches, measured from its first element.
dimensionsmethodThe logical shape.
stridesmethodThe element stride of each dimension.
isDensemethodReports whether the elements occupy a dense row-major range.
isInjectivemethodReports whether the layout's strides prove that element offsets are distinct.

countfield#

count: integer
@readonly

offsetmethod#

offset: function offset(borrows self): integer

The element offset of the layout's first element.

Arguments
NameTypeDescription
borrows selfany
Returns
TypeDescription
integer

extentmethod#

extent: function extent(borrows self): integer

One more than the largest element offset the layout reaches, measured from its first element.

Arguments
NameTypeDescription
borrows selfany
Returns
TypeDescription
integer

dimensionsmethod#

dimensions: function dimensions(borrows self): {integer}

The logical shape. The returned table is a copy.

Arguments
NameTypeDescription
borrows selfany
Returns
TypeDescription
{integer}

stridesmethod#

strides: function strides(borrows self): {integer}

The element stride of each dimension. The returned table is a copy.

Arguments
NameTypeDescription
borrows selfany
Returns
TypeDescription
{integer}

isDensemethod#

isDense: function isDense(borrows self): boolean

Reports whether the elements occupy a dense row-major range.

Arguments
NameTypeDescription
borrows selfany
Returns
TypeDescription
boolean

isInjectivemethod#

isInjective: function isInjective(borrows self): boolean

Reports whether the layout's strides prove that element offsets are distinct.

A false result also covers layouts for which the bounded stride proof is inconclusive.

Arguments
NameTypeDescription
borrows selfany
Returns
TypeDescription
boolean

Functions#

layout.asStridedfunction#

function layout.asStrided(borrows value: layout.Layout, shape: {integer}, strides: {integer}, relativeOffset: integer): layout.Layout

Arguments

NameTypeDescription
borrows valuelayout.Layout
shape{integer}
strides{integer}
relativeOffsetinteger

Returns

TypeDescription
layout.Layout

layout.broadcastfunction#

function layout.broadcast(borrows value: layout.Layout, shape: {integer}): layout.Layout

Arguments

NameTypeDescription
borrows valuelayout.Layout
shape{integer}

Returns

TypeDescription
layout.Layout

layout.newfunction#

function layout.new(shape: {integer}, strides: {integer}, offset: integer?): layout.Layout

Checks a shape and its strides, with the element offset of the first element, 0 unless given.

Arguments

NameTypeDescription
shape{integer}
strides{integer}
offsetinteger?

Returns

TypeDescription
layout.Layout

Raises

TypeCondition
string

when the shape, strides or offset do not fit uint32

layout.subviewfunction#

function layout.subview(borrows value: layout.Layout, origin: {integer}, shape: {integer}): layout.Layout

Arguments

NameTypeDescription
borrows valuelayout.Layout
origin{integer}
shape{integer}

Returns

TypeDescription
layout.Layout

layout.transposefunction#

function layout.transpose(borrows value: layout.Layout, order: {integer}): layout.Layout

Arguments

NameTypeDescription
borrows valuelayout.Layout
order{integer}

Returns

TypeDescription
layout.Layout