tvmjs
    Preparing search index...

    Class WebGPUContext

    WebGPU context Manages all the webgpu resources here.

    Index
    device: GPUDevice
    memory: Memory
    • Bind a canvas element to the runtime.

      Parameters

      • canvas: HTMLCanvasElement

        The HTML canvas/

      Returns void

    • Clear canvas

      Returns void

    • Copy raw bytes into buffer ptr.

      Parameters

      • rawBytes: Uint8Array

        The raw bytes

      • toPtr: number

        The target gpu buffer ptr

      • toOffset: number

        The beginning offset

      • nbytes: number

        Number of bytes

      Returns void

    • Create a PackedFunc that runs the given shader via createComputePipeline

      Parameters

      • finfo: FunctionInfo

        The function information already parsed as a record.

      • code: string

        The shader data(in WGSL)

      Returns Function

      The shader

    • Create a PackedFunc that runs the given shader asynchronously via createComputePipelineAsync

      Parameters

      • finfo: FunctionInfo

        The function information already parsed as a record.

      • code: string

        The shader data(in WGSL)

      Returns Promise<Function>

      The shader

    • Dispose context.

      Returns void

    • Dispose a previously created sampled-token readback ring.

      Parameters

      • ringId: number

      Returns void

    • Draw image from data in storage buffer.

      Parameters

      • ptr: number

        The GPU ptr

      • height: number

        The height of the image.

      • width: number

        The width of the image.

      Returns void

    • Flush all pending GPU commands by finishing and submitting the accumulated command encoder.

      Must be called before:

      • GPU→CPU readback (deviceCopyFromGPU)
      • CPU→GPU writes (deviceCopyToGPU, copyRawBytesToBuffer)
      • Buffer deallocation (deviceFreeDataSpace)
      • Canvas drawing (drawImageFromBuffer)
      • Queue sync (sync)

      Returns void

    • Get the device API according to its name *

      Parameters

      • name: string

        The name of the API.

      Returns Function

      The corresponding device api.

    • Obtain the runtime information in readable format.

      Returns string

    • Submit pending commands without waiting for GPU completion.

      Returns boolean

      Whether a command buffer was submitted.

    • Submit a sampled-token readback batch from a GPU buffer.

      Parameters

      • ringId: number

        Ring handle returned by createSampledTokenReadbackRing.

      • from: number

        Source GPU pointer containing int32 tokens.

      • fromTokenOffset: number

        Source token offset (in token units, not bytes).

      • tokenCount: number

        Number of int32 token ids to copy.

      • Optionalinto: Int32Array

        Host array to copy the batch into instead of a new one; see SampledTokenReadbackRing.submit.

      Returns number

      Monotonic batch sequence id.

    • Submit token ranges, including offsets into their allocations.

      Parameters

      Returns number

    • Wait for all pending GPU tasks to complete

      Returns Promise<void>