nupp.gpu.spi

Shared interfaces for resident GPU implementations.

The nupp.gpu module selects a device implementation during initialization. open is a receiver-free function; it returns a closeable KernelContext.

Implementations define private records satisfying the shared context, buffer, kernel, and binding interfaces. Reuse the exported types here rather than creating nominal substitutes. Context-bound buffers and kernels preserve their borrows, and every close keeps its non-suspending guarantee.

Generated artifacts and layout facts constrain binding formats, counts, scalar uniforms, and target features. A provider may choose a compatible device, but it cannot change the representation compiled into a kernel. Device and artifact failures must be reported before incompatible operations are published or run. The facade exports the retained open function directly.

Module contents

Types

TypeKindDescription
ArtifactSetrecordGenerated shader formats and entrypoint accepted by provider compilation.
BindinginterfaceCanonical kernel invocation with buffer slots and uniform dispatch.
BufferinterfaceCanonical typed resident buffer/view borrowing its context.
ContextinterfaceComplete shared context protocol, including generated-kernel operations.
KernelinterfaceCanonical opaque kernel handle borrowing its context.
Providerinterface

Types#

ArtifactSetrecord#

record ArtifactSet ...

Generated shader formats and entrypoint accepted by provider compilation.

Members

NameKindDescription
spirvfieldOptional SPIR-V artifact bytes.
wgslfieldOptional WGSL shader source.
entrypointfieldName of the entry point within the supplied artifacts.
sourceFilefieldAuthored kernel identity carried into optional execution cost records.
sourceLinefield
artifactIdfield
readonlyNamesfield
writableNamesfield

spirvfield#

spirv: string?
@readonly

Optional SPIR-V artifact bytes.

wgslfield#

wgsl: string?
@readonly

Optional WGSL shader source.

entrypointfield#

entrypoint: string
@readonly

Name of the entry point within the supplied artifacts.

sourceFilefield#

sourceFile: string?
@readonly

Authored kernel identity carried into optional execution cost records.

sourceLinefield#

sourceLine: integer?
@readonly

artifactIdfield#

artifactId: string?
@readonly

readonlyNamesfield#

readonlyNames: {string}?
@readonly

writableNamesfield#

writableNames: {string}?
@readonly

Bindinginterface#

interface Binding ...

Canonical kernel invocation with buffer slots and uniform dispatch.

Members

NameKindDescription
closemethodReleases the binding's attachments without suspending.
countfieldNumber of logical elements dispatched.
setReadmethodAttaches a same-context buffer to a zero-based read slot.
setWritemethodAttaches a same-context, injective buffer to a zero-based writable slot.
dispatchWordsmethodDispatches using the generated scalar uniform words.
dispatchPackedmethodDispatches from the exact packed uniform layout and byte count.

closemethod#

close: @nosuspend function(borrows self: Binding): nil
@readonly

Releases the binding's attachments without suspending. The kernel and buffers it named remain their owners'.

Arguments
NameTypeDescription
borrows selfBinding
Returns
TypeDescription
nil

countfield#

count: integer
@readonly

Number of logical elements dispatched.

setReadmethod#

setRead: function<T>(
    borrows self: Binding,
    slot: integer,
    borrows buffer: gpu.Buffer<T>,
    matchCount: boolean
): nil
@readonly

Attaches a same-context buffer to a zero-based read slot. matchCount requires a dense buffer element per dispatched element.

Arguments
NameTypeDescription
borrows selfBinding
slotinteger
borrows buffergpu.Buffer<T>
matchCountboolean
Returns
TypeDescription
nil

setWritemethod#

setWrite: function<T>(
    borrows self: Binding,
    slot: integer,
    borrows buffer: gpu.Buffer<T>,
    matchCount: boolean
): nil
@readonly

Attaches a same-context, injective buffer to a zero-based writable slot. matchCount also requires a dense element per dispatched element.

Arguments
NameTypeDescription
borrows selfBinding
slotinteger
borrows buffergpu.Buffer<T>
matchCountboolean
Returns
TypeDescription
nil

dispatchWordsmethod#

dispatchWords: function(borrows self: Binding, scalars: {uint32}): nil
@readonly

Dispatches using the generated scalar uniform words.

Arguments
NameTypeDescription
borrows selfBinding
scalars{uint32}
Returns
TypeDescription
nil

dispatchPackedmethod#

dispatchPacked: function(borrows self: Binding, uniforms: any, uniformBytes: integer): nil
@readonly

Dispatches from the exact packed uniform layout and byte count. The provider must validate the byte count against the compiled kernel.

Arguments
NameTypeDescription
borrows selfBinding
uniformsany
uniformBytesinteger
Returns
TypeDescription
nil

Bufferinterface#

interface Buffer<T> is nupp.Closeable ...

Canonical typed resident buffer/view borrowing its context.

Type parameters

NameDescription
T

Members

NameKindDescription
closemethodReleases a root buffer's allocation, or ends a view, without suspending.
countfieldNumber of logical elements in this buffer or view.
dimensionsmethodReturns the logical shape in elements.
stridesmethodReturns the element strides for the logical view.
subviewmethodCreates a context-borrowed view at a zero-based origin with the requested shape.
layoutmethodReturns the canonical tensor layout for this view.
isDensemethodReports whether this buffer or view occupies one dense element range.
isInjectivemethodReports whether every logical element maps to a distinct storage element.
viewmethodCreates a view using the supplied checked layout without copying storage.

closemethod#

close: @nosuspend function(takes self: Buffer<T>): nil

Releases a root buffer's allocation, or ends a view, without suspending.

Arguments
NameTypeDescription
takes selfBuffer<T>
Returns
TypeDescription
nil

countfield#

count: integer
@readonly

Number of logical elements in this buffer or view.

dimensionsmethod#

dimensions: function(borrows self: Buffer<T>): {integer}
@readonly

Returns the logical shape in elements.

Arguments
NameTypeDescription
borrows selfBuffer<T>
Returns
TypeDescription
{integer}

stridesmethod#

strides: function(borrows self: Buffer<T>): {integer}
@readonly

Returns the element strides for the logical view.

Arguments
NameTypeDescription
borrows selfBuffer<T>
Returns
TypeDescription
{integer}

subviewmethod#

subview: function(
    borrows self: Buffer<T>,
    origin: {integer},
    shape: {integer}
): affine(Buffer<T>) borrows (self)
@readonly

Creates a context-borrowed view at a zero-based origin with the requested shape.

Arguments
NameTypeDescription
borrows selfBuffer<T>
origin{integer}
shape{integer}
Returns
TypeDescription
affine(Buffer<T>) borrows (self)

layoutmethod#

layout: function(borrows self: Buffer<T>): TensorLayout
@readonly

Returns the canonical tensor layout for this view.

Arguments
NameTypeDescription
borrows selfBuffer<T>
Returns
TypeDescription
TensorLayout

isDensemethod#

isDense: function(borrows self: Buffer<T>): boolean
@readonly

Reports whether this buffer or view occupies one dense element range.

Arguments
NameTypeDescription
borrows selfBuffer<T>
Returns
TypeDescription
boolean

isInjectivemethod#

isInjective: function(borrows self: Buffer<T>): boolean
@readonly

Reports whether every logical element maps to a distinct storage element. A false result also covers a stride proof that was inconclusive.

Arguments
NameTypeDescription
borrows selfBuffer<T>
Returns
TypeDescription
boolean

viewmethod#

view: function(borrows self: Buffer<T>, layout: TensorLayout): affine(Buffer<T>) borrows (self)
@readonly

Creates a view using the supplied checked layout without copying storage. The layout must fit within the root allocation.

Arguments
NameTypeDescription
borrows selfBuffer<T>
layoutTensorLayout
Returns
TypeDescription
affine(Buffer<T>) borrows (self)

Contextinterface#

interface Context is gpu.Context ...

Complete shared context protocol, including generated-kernel operations.

Members

NameKindDescription
compileGeneratedmethodCompiles compatible artifacts with exact read/write slot counts and uniform size.
bindKernelmethodCreates a binding for count elements using this context's live kernel.

compileGeneratedmethod#

compileGenerated: function(
    borrows self: Context,
    artifacts: gpu.ArtifactSet,
    readonlyBuffers: integer,
    writableBuffers: integer,
    uniformBytes: integer,
    threads: integer?
): gpu.Kernel borrows (self)
@readonly

Compiles compatible artifacts with exact read/write slot counts and uniform size. threads carries the generated workgroup requirement when specified. Reject unsupported layouts or device limits before returning a kernel.

Arguments
NameTypeDescription
borrows selfContext
artifactsgpu.ArtifactSet
readonlyBuffersinteger
writableBuffersinteger
uniformBytesinteger
threadsinteger?
Returns
TypeDescription
gpu.Kernel borrows (self)

bindKernelmethod#

bindKernel: function(
    borrows self: Context,
    borrows kernel: gpu.Kernel,
    count: integer
): gpu.Binding borrows (self)
@readonly

Creates a binding for count elements using this context's live kernel.

Arguments
NameTypeDescription
borrows selfContext
borrows kernelgpu.Kernel
countinteger
Returns
TypeDescription
gpu.Binding borrows (self)

Kernelinterface#

interface Kernel ...

Canonical opaque kernel handle borrowing its context.

Members

NameKindDescription
closemethodReleases the compiled kernel without suspending.

closemethod#

close: @nosuspend function(borrows self: Kernel): nil
@readonly

Releases the compiled kernel without suspending.

Arguments
NameTypeDescription
borrows selfKernel
Returns
TypeDescription
nil

Providerinterface#

interface Provider ...

Members

NameKindDescription
priorityfield
availablemethodReports whether open can answer a device now, without raising.
openmethodOpens an owned, closeable device context.

priorityfield#

priority: integer?
@readonly

availablemethod#

available: function(): boolean
@readonly

Reports whether open can answer a device now, without raising.

Returns
TypeDescription
boolean

openmethod#

open: function(): types.KernelContext
@readonly

Opens an owned, closeable device context. Raises if the host cannot provide a compatible device.

Returns
TypeDescription
types.KernelContext