arena

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package arena provides pooled, zero-allocation scratch storage for low-latency CUDA Driver API and cuBLAS calls (such as cuLaunchKernel kernelParams arrays and scalar argument buffers).

Index

Constants

View Source
const (
	// MaxKernelArgs is the maximum number of arguments supported in a single KernelArgs container.
	MaxKernelArgs = 24
)

Variables

This section is empty.

Functions

func PushValue

func PushValue[T any](k *KernelArgs, v T)

PushValue appends any plain-old-data value T (such as a fixed-size struct) by value.

func PutKernelArgs

func PutKernelArgs(ka *KernelArgs)

PutKernelArgs returns a KernelArgs container to the per-P pool.

func PutScratch

func PutScratch(s *Scratch)

PutScratch returns a Scratch arena to the pool.

Types

type KernelArgs

type KernelArgs struct {
	// contains filtered or unexported fields
}

KernelArgs packs cuLaunchKernel's void** kernelParams array and backing parameter bytes into a single pooled Go struct with zero heap allocations on the hot path.

Because ptrs holds Go-typed unsafe.Pointers into slab (within the same struct) and cuLaunchKernel synchronously copies parameter bytes before returning, passing ParamsPtr() followed by runtime.KeepAlive(args) is safe under Go's GC and -race/checkptr.

func GetKernelArgs

func GetKernelArgs() *KernelArgs

GetKernelArgs acquires a reset KernelArgs container from the per-P pool.

func (*KernelArgs) Count

func (k *KernelArgs) Count() int

Count returns the number of pushed arguments.

func (*KernelArgs) Next

func (k *KernelArgs) Next() *KernelArgs

func (*KernelArgs) ParamsPtr

func (k *KernelArgs) ParamsPtr() unsafe.Pointer

ParamsPtr returns the void** pointer suitable for cuLaunchKernel's kernelParams argument. Returns nil if no arguments have been pushed.

func (*KernelArgs) PushBytes

func (k *KernelArgs) PushBytes(b []byte)

PushBytes appends an arbitrary by-value byte struct/array argument.

func (*KernelArgs) PushFloat32

func (k *KernelArgs) PushFloat32(v float32)

PushFloat32 appends a float32 argument.

func (*KernelArgs) PushFloat64

func (k *KernelArgs) PushFloat64(v float64)

PushFloat64 appends a float64 argument.

func (*KernelArgs) PushInt32

func (k *KernelArgs) PushInt32(v int32)

PushInt32 appends an int32 argument.

func (*KernelArgs) PushInt64

func (k *KernelArgs) PushInt64(v int64)

PushInt64 appends an int64 argument.

func (*KernelArgs) PushUint32

func (k *KernelArgs) PushUint32(v uint32)

PushUint32 appends a uint32 argument.

func (*KernelArgs) PushUint64

func (k *KernelArgs) PushUint64(v uint64)

PushUint64 appends a uint64 (or 64-bit CUdeviceptr) argument.

func (*KernelArgs) Reset

func (k *KernelArgs) Reset()

Reset clears the argument list without freeing memory.

func (*KernelArgs) SetNext

func (k *KernelArgs) SetNext(n *KernelArgs)

type Scratch

type Scratch struct {
	// contains filtered or unexported fields
}

Scratch is a pooled power-of-2 byte bump-allocator for transient host metadata buffers (modeled after go-xla/pjrt/arena.go).

func GetScratch

func GetScratch(minBytes int) *Scratch

GetScratch acquires a Scratch arena of at least minBytes bytes.

func (*Scratch) Alloc

func (s *Scratch) Alloc(n int) []byte

Alloc returns an 8-byte aligned sub-slice of n zeroed bytes from the scratch arena.

func (*Scratch) Next

func (s *Scratch) Next() *Scratch

func (*Scratch) Reset

func (s *Scratch) Reset()

Reset rewinds the bump pointer to 0 for reuse.

func (*Scratch) SetNext

func (s *Scratch) SetNext(n *Scratch)

type ScratchPools

type ScratchPools struct {
	// contains filtered or unexported fields
}

ScratchPools manages power-of-2 pools of Scratch arenas.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL