Skip to main content

GpuDevice

Trait GpuDevice 

Source
pub trait GpuDevice {
    type Buffer;

    const PRELUDE: &'static str;

    // Required methods
    fn name(&self) -> String;
    fn max_threads_per_group(&self) -> u32;
    fn alloc(&self, bytes: usize) -> Result<Self::Buffer>;
    fn upload(
        &self,
        buffer: &Self::Buffer,
        offset: usize,
        data: &[u8],
    ) -> Result<()>;
    fn download(
        &self,
        buffer: &Self::Buffer,
        offset: usize,
        out: &mut [u8],
    ) -> Result<()>;
    fn compile(&mut self, source: &str, kernels: &[&str]) -> Result<()>;
    fn launch(
        &self,
        kernel: usize,
        grid: [u32; 3],
        block: [u32; 3],
        args: &[Arg<'_, Self::Buffer>],
    ) -> Result<()>;
    fn sync(&self) -> Result<()>;

    // Provided method
    fn flush(&self) -> Result<()> { ... }
}

Required Associated Constants§

Source

const PRELUDE: &'static str

The macro vocabulary (kernels/prelude_*.h) that compiles kernels/common.h and kernels/kernels.kern for this API.

Required Associated Types§

Required Methods§

Source

fn name(&self) -> String

The device’s name, as the driver reports it.

Source

fn max_threads_per_group(&self) -> u32

The largest threadgroup (block) the compiled kernels may be launched with.

Source

fn alloc(&self, bytes: usize) -> Result<Self::Buffer>

A zero-filled buffer of bytes bytes (at least 4).

Source

fn upload( &self, buffer: &Self::Buffer, offset: usize, data: &[u8], ) -> Result<()>

Copies data into buffer at byte offset.

Source

fn download( &self, buffer: &Self::Buffer, offset: usize, out: &mut [u8], ) -> Result<()>

Copies out.len() bytes from buffer at byte offset, after every earlier launch completed.

Source

fn compile(&mut self, source: &str, kernels: &[&str]) -> Result<()>

Compiles source and loads kernels; later launches name a kernel by its index in kernels.

Source

fn launch( &self, kernel: usize, grid: [u32; 3], block: [u32; 3], args: &[Arg<'_, Self::Buffer>], ) -> Result<()>

Launches kernel kernel over grid threadgroups of block threads.

Source

fn sync(&self) -> Result<()>

Waits for every earlier launch.

Provided Methods§

Source

fn flush(&self) -> Result<()>

Starts every earlier launch without waiting for it, so the device works while the host does. A device whose launches start on their own (CUDA streams) needs nothing here.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§