nupp.runtime.services.gpu

Resident-compute provider contract for host.gpu API 1.

Import service to register or select a device implementation before requiring nupp.gpu. open is a receiver-free function; it returns an affine KernelContext using the canonical destroyContext cleanup identity exported here.

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 cleanup preserves its non-suspending guarantees.

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.
ContextTokeninterfaceShared non-suspending context cleanup obligation.
KernelinterfaceCanonical opaque kernel handle borrowing its context.
Providerinterface

Functions

FunctionKindDescription
destroyContextfunctionShared affine cleanup identity; provider returns must preserve it.

Values

ValueKindDescription
servicevariableCanonical host.gpu API 1 handle; setup selects before the public facade loads.

Types#

ArtifactSetrecord#

record ArtifactSet
    readonly spirv: string?
    readonly wgsl: string?
    readonly entrypoint: string
end

Generated shader formats and entrypoint accepted by provider compilation.

Fields

spirv#
spirv: string?

Optional SPIR-V artifact bytes.

wgsl#
wgsl: string?

Optional WGSL shader source.

entrypoint#
entrypoint: string

Name of the entry point within the supplied artifacts.

Bindinginterface#

interface Binding
    readonly count: integer
    readonly setRead: function<T>(
        borrows self: Binding,
        slot: integer,
        borrows buffer: gpu.Buffer<T>,
        matchCount: boolean
    ): nil
    readonly setWrite: function<T>(
        borrows self: Binding,
        slot: integer,
        borrows buffer: gpu.Buffer<T>,
        matchCount: boolean
    ): nil
    readonly dispatchWords: function(borrows self: Binding, scalars: {uint32}): nil
    readonly dispatchPacked: function(borrows self: Binding, uniforms: any, uniformBytes: integer): nil
end

Canonical kernel invocation with buffer slots and uniform dispatch.

Methods

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

Attaches a buffer to a zero-based read slot. matchCount requires one buffer element per dispatched element.

Arguments
NameTypeDescription
borrows selfgpu.Binding
slotinteger
borrows buffergpu.Buffer<T>
matchCountboolean
Returns
TypeDescription
nil
setWrite#
setWrite: function<T>(
    borrows self: gpu.Binding,
    slot: integer,
    borrows buffer: gpu.Buffer<T>,
    matchCount: boolean
): nil

Attaches a buffer to a zero-based writable slot with the same count rule.

Arguments
NameTypeDescription
borrows selfgpu.Binding
slotinteger
borrows buffergpu.Buffer<T>
matchCountboolean
Returns
TypeDescription
nil
dispatchWords#
dispatchWords: function(borrows self: gpu.Binding, scalars: {uint32}): nil

Dispatches using the generated scalar uniform words.

Arguments
NameTypeDescription
borrows selfgpu.Binding
scalars{uint32}
Returns
TypeDescription
nil
dispatchPacked#
dispatchPacked: function(borrows self: gpu.Binding, uniforms: any, uniformBytes: integer): nil

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

Arguments
NameTypeDescription
borrows selfgpu.Binding
uniformsany
uniformBytesinteger
Returns
TypeDescription
nil

Fields

count#
count: integer

Number of logical elements dispatched.

Bufferinterface#

interface Buffer<T>
    readonly count: integer
    readonly dimensions: function(borrows self: Buffer<T>): {integer}
    readonly strides: function(borrows self: Buffer<T>): {integer}
    readonly subview: function(
        borrows self: Buffer<T>,
        origin: {integer},
        shape: {integer}
    ): Buffer<T> borrows (self)
    readonly layout: function(borrows self: Buffer<T>): TensorLayout
    readonly view: function(borrows self: Buffer<T>, layout: TensorLayout): Buffer<T> borrows (self)
end

Canonical typed resident buffer/view borrowing its context.

Type parameters

NameDescription
T

Methods

dimensions#
dimensions: function(borrows self: gpu.Buffer<T>): {integer}

Returns the logical shape in elements.

Arguments
NameTypeDescription
borrows selfgpu.Buffer<T>
Returns
TypeDescription
{integer}
strides#
strides: function(borrows self: gpu.Buffer<T>): {integer}

Returns the element strides for the logical view.

Arguments
NameTypeDescription
borrows selfgpu.Buffer<T>
Returns
TypeDescription
{integer}
subview#
subview: function(
    borrows self: gpu.Buffer<T>,
    origin: {integer},
    shape: {integer}
): gpu.Buffer<T> borrows (self)

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

Arguments
NameTypeDescription
borrows selfgpu.Buffer<T>
origin{integer}
shape{integer}
Returns
TypeDescription
gpu.Buffer<T> borrows (self)
layout#
layout: function(borrows self: gpu.Buffer<T>): TensorLayout

Returns the canonical tensor layout for this view.

Arguments
NameTypeDescription
borrows selfgpu.Buffer<T>
Returns
TypeDescription
TensorLayout
view#
view: function(borrows self: gpu.Buffer<T>, layout: TensorLayout): gpu.Buffer<T> borrows (self)

Creates a view using the supplied checked layout without copying storage.

Arguments
NameTypeDescription
borrows selfgpu.Buffer<T>
layoutTensorLayout
Returns
TypeDescription
gpu.Buffer<T> borrows (self)

Fields

count#
count: integer

Number of elements, kept with the allocation.

Contextinterface#

interface Context is gpu.Context
    readonly compileGenerated: function(
        borrows self: Context,
        artifacts: gpu.ArtifactSet,
        readonlyBuffers: integer,
        writableBuffers: integer,
        uniformBytes: integer,
        threads: integer?
    ): gpu.Kernel borrows (self)
    readonly bindKernel: function(
        borrows self: Context,
        borrows kernel: gpu.Kernel,
        count: integer
    ): gpu.Binding borrows (self)
    readonly releaseKernel: function(borrows self: Context, borrows kernel: gpu.Kernel): nil
    readonly releaseBinding: function(borrows self: Context, exclusive binding: gpu.Binding): nil
end

Complete shared context protocol, including generated-kernel operations.

Methods

compileGenerated#
compileGenerated: function(
    borrows self: gpu.KernelContext,
    artifacts: gpu.ArtifactSet,
    readonlyBuffers: integer,
    writableBuffers: integer,
    uniformBytes: integer,
    threads: integer?
): gpu.Kernel borrows (self)

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 selfgpu.KernelContext
artifactsgpu.ArtifactSet
readonlyBuffersinteger
writableBuffersinteger
uniformBytesinteger
threadsinteger?
Returns
TypeDescription
gpu.Kernel borrows (self)
bindKernel#
bindKernel: function(
    borrows self: gpu.KernelContext,
    borrows kernel: gpu.Kernel,
    count: integer
): gpu.Binding borrows (self)

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

Arguments
NameTypeDescription
borrows selfgpu.KernelContext
borrows kernelgpu.Kernel
countinteger
Returns
TypeDescription
gpu.Binding borrows (self)
releaseKernel#
releaseKernel: function(borrows self: gpu.KernelContext, borrows kernel: gpu.Kernel): nil

Releases a compiled kernel; dependent bindings must no longer be used.

Arguments
NameTypeDescription
borrows selfgpu.KernelContext
borrows kernelgpu.Kernel
Returns
TypeDescription
nil
releaseBinding#
releaseBinding: function(borrows self: gpu.KernelContext, exclusive binding: gpu.Binding): nil

Releases a binding while holding exclusive access to it.

Arguments
NameTypeDescription
borrows selfgpu.KernelContext
exclusive bindinggpu.Binding
Returns
TypeDescription
nil

ContextTokeninterface#

interface ContextToken
    readonly drop: nosuspend function(takes self: ContextToken): nil
end

Shared non-suspending context cleanup obligation.

Methods

drop#
drop: nosuspend function(takes self: ContextToken): nil

Consumes and releases the context without suspending.

Arguments
NameTypeDescription
takes selfContextToken
Returns
TypeDescription
nil

Kernelinterface#

interface Kernel
end

Canonical opaque kernel handle borrowing its context.

Providerinterface#

interface Provider
    readonly open: function(): affine(types.KernelContext, types.destroyContext)
end

Methods

open#
open: function(): affine(types.KernelContext, types.destroyContext)

Opens an owned device context using the canonical destroyContext cleanup. Raise if the host cannot provide a compatible device.

Returns
TypeDescription
affine(types.KernelContext, types.destroyContext)

Functions#

destroyContextfunction#

function destroyContext<T is gpu.ContextToken>(takes context: T): nil

Shared affine cleanup identity; provider returns must preserve it.

Type parameters

NameDescription
T

Arguments

NameTypeDescription
takes contextT

Returns

TypeDescription
nil

Values#

servicevariable#

const service: services.Service<Provider>

Canonical host.gpu API 1 handle; setup selects before the public facade loads.