Skip to main content

Module buffer

Module buffer 

Source
Expand description

Typed device buffers: sizes come from the element type, never from a literal byte count.

Functions§

bytes
Bytes of len elements of E, at least one element (runtimes reject empty allocations).
copy
Copies the first len values of F of src into dst, on the device.
download
Host copy of a device buffer of E (waits for the queued work that writes it).
download_prefix
Host copy of the first len elements of E of a device buffer: only those bytes are read, so a buffer sized for the largest batch costs only the current batch’s transfer.
download_range
Host copy of elements start .. start + len of E of a device buffer: only those bytes are read.
empty
Uninitialized device buffer of len elements of E.
fill
Sets the first len values of handle (which holds at least len values of F) to value, on the device.
filled
Device buffer of len copies of value, filled on the device: nothing is uploaded.
truncate
handle without its last unused elements of E (a view of a buffer larger than the data).
upload
Device copy of data.
write
Writes data to the start of the existing device buffer handle (which holds at least data.len() elements of E): no allocation, enqueued after the work already queued on the client’s stream, so a buffer reused every window is not overwritten before the previous window’s kernels have read it.
write_bytes
Writes data to the start of handle, narrowed to data’s length: a reused buffer is often larger than the chunk written into it, and the CPU runtime copies the whole bound range (a write shorter than its handle panics there; wgpu and CUDA accept it).
write_owned
write taking ownership of data: the bytes move into the transfer without a copy (useful when the buffer was filled on another thread, e.g. a read-ahead loader).
zeros
Device buffer of len zeros, filled on the device (cubecl-std’s zero kernel): nothing is uploaded.