Skip to main content

GpuComputeBackend

Trait GpuComputeBackend 

Source
pub trait GpuComputeBackend {
    type Error: Debug + Into<CodecError>;

    // Required methods
    fn prepare_for_device(
        &mut self,
        prepared: &mut PreparedCodec,
    ) -> Result<(), Self::Error>;
    fn compress_batch(
        &mut self,
        input: &[f32],
        rows: usize,
        cols: usize,
        prepared: &PreparedCodec,
    ) -> Result<Vec<CompressedVector>, Self::Error>;
}
Expand description

Trait that every TinyQuant GPU compute backend must satisfy.

Implementations of this trait live in external crates (e.g. tinyquant-gpu-wgpu). The trait is defined here so tinyquant-core can express the compress_batch_gpu_with method without a dependency on any concrete GPU crate (which would create a cyclic crate dependency, since GPU crates already depend on tinyquant-core).

Required Associated Types§

Source

type Error: Debug + Into<CodecError>

The error type returned by this backend’s operations.

Must be convertible to CodecError so [Codec::compress_batch_gpu_with] can map errors uniformly.

Required Methods§

Source

fn prepare_for_device( &mut self, prepared: &mut PreparedCodec, ) -> Result<(), Self::Error>

Upload PreparedCodec buffers to device memory. Idempotent.

§Errors

Returns Self::Error if device upload fails.

Source

fn compress_batch( &mut self, input: &[f32], rows: usize, cols: usize, prepared: &PreparedCodec, ) -> Result<Vec<CompressedVector>, Self::Error>

Compress rows FP32 vectors of dimension cols on the GPU.

§Errors

Returns Self::Error if the GPU kernel dispatch or readback fails.

Implementors§