Safe Buffer Operations #
Type-safe buffer read/write utilities with runtime bounds checking.
Backend-agnostic via [GPUBackend β].
Safely read a UInt32 (4 bytes LE) from a ByteArray. Returns 0 if out of bounds.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Safely read a Float32 from a ByteArray at the given byte offset.
Equations
- Hesper.Training.SafeBuffer.readF32 bytes offset = Hesper.Basic.float32BitsToFloat64 (Hesper.Training.SafeBuffer.readU32 bytes offset)
Instances For
@[inline]
def
Hesper.Training.SafeBuffer.safeMapBufferReadF32
{β : Type}
[GPUBackend β]
(ctx : β)
(buf : GPUBackend.Buf β)
(numElements : Nat)
:
Safely read a GPU buffer and return Float32 values.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[inline]
def
Hesper.Training.SafeBuffer.safeReadF32
{β : Type}
[GPUBackend β]
(ctx : β)
(buf : GPUBackend.Buf β)
(elementIdx : Nat := 0)
:
Safely read a single Float32 from a GPU buffer at element index.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Hesper.Training.SafeBuffer.isNaN f = (f != f)
Instances For
@[inline]
def
Hesper.Training.SafeBuffer.hasNaN
{β : Type}
[GPUBackend β]
(ctx : β)
(buf : GPUBackend.Buf β)
(numElements : Nat)
:
Check if any value in a GPU buffer is NaN.
Equations
- Hesper.Training.SafeBuffer.hasNaN ctx buf numElements = do let vals ← Hesper.Training.SafeBuffer.safeMapBufferReadF32 ctx buf numElements pure (vals.any Hesper.Training.SafeBuffer.isNaN)