std1.0.0-beta-7 SafeC docs

std :: ml::gpu_spirv

Struct std::SpirvBuf

#include <std/ml/gpu_spirv.h> source

struct SpirvBuf {
    unsigned long handle;
    unsigned long bytes;
    int dtype;
}

A Vulkan device buffer. 'handle' is its buffer device address (what the kernels and VulkanTensor.device_buffer() name it by), 0 for an invalid (failed or freed) buffer; every op returns 0 for one. 'bytes' is the size it was made with, 'dtype' its element type (informational: the ops below take fp32). Buffers come from the device's memory cache; free() returns one to it, exactly once, and may wait for queued work that uses it.

Fields

§unsigned long handlesource
§unsigned long bytessource
§int dtypesource

Methods

§int valid() constsource · definition

handle != 0

§void free()source · definition

back to the cache; handle := 0

§int read([]unsigned char dst) constsource · definition

Copies the first 'bytes' (<= this.bytes, whole 32-bit words) into 'dst' once the queued work is done (waits). 1 = done.

§int write([]const unsigned char src)source · definition

Copies src.len bytes (<= this.bytes, whole 32-bit words) from 'src' into the buffer, in order with the queued work (ops queued before it read the old contents). 1 = done.

§static struct SpirvBuf alloc(unsigned long n, int dtype)source · definition

n uninitialized elements

§static struct SpirvBuf upload([]const float host)source · definition