Skip to main content

GpuBackend

Struct GpuBackend 

Source
pub struct GpuBackend<D: GpuDevice> { /* private fields */ }
Expand description

silvic_core::Backend over any GpuDevice.

Implementations§

Source§

impl<D: GpuDevice> GpuBackend<D>

Source

pub fn new(device: D) -> Self

Wraps device; kernels compile on GpuBackend::compile or the first load.

Source

pub fn device(&self) -> &D

Source

pub fn compile(&mut self) -> Result<()>

Compiles the kernels for the device, once.

Source

pub fn gradients(&self) -> Result<(Vec<f32>, Vec<f32>)>

The training gradients and hessians of the last compute_gradients, read back for inspection.

Trait Implementations§

Source§

impl<D: GpuDevice> Backend for GpuBackend<D>

Source§

fn partition_and_histogram( &mut self, leaf: LeafRange, split: &BinSplit, side: Side, quantized: bool, out: &mut [f64], ) -> Result<u32>

Partition and the child’s histogram in one command buffer: the histogram kernel takes the child’s rows from the device-side left count, so the host waits once.

Source§

fn name(&self) -> String

Human-readable device name for logs (cpu (14 threads), Apple M4 Pro (metal)).
Source§

fn load( &mut self, train: &BinnedDataset, valid: &[&BinnedDataset], objective: &ObjectiveSetup, ) -> Result<()>

Takes the training set and validation sets; called once, before anything else.
Source§

fn init_scores(&mut self, dataset: usize, value: f64) -> Result<()>

Sets every score of dataset to value.
Source§

fn compute_gradients(&mut self) -> Result<GradientStats>

Computes f32 gradients and hessians of the training scores; returns their local maxima.
Source§

fn quantize(&mut self, spec: &QuantSpec) -> Result<()>

Quantizes the gradients and hessians with spec (quantize::quantize_row, keyed by global row id).
Source§

fn reset_partition(&mut self, bag: &BagSpec) -> Result<u32>

Refills the partition with the bagged training rows in ascending order; returns their count.
Source§

fn histogram( &mut self, leaf: LeafRange, quantized: bool, out: &mut [f64], ) -> Result<()>

Histogram of the rows of leaf into out (2 * total_bins, overwritten): quantized units when quantized, else float sums of gradients and hessians.
Source§

fn partition(&mut self, leaf: LeafRange, split: &BinSplit) -> Result<u32>

Stable in-place partition of leaf’s rows by split; returns the number of rows going left.
Source§

fn leaf_sums( &mut self, leaves: &[LeafRange], grad_scale: f32, hess_scale: f32, ) -> Result<Vec<[i64; 2]>>

Exact fixed-point sums [sum rint(g * scale), sum rint(h * scale)] of each leaf’s float gradients (quantize::to_fixed), for leaf renewal.
Source§

fn add_tree(&mut self, tree: &DeviceTree) -> Result<()>

Adds tree to the scores of every dataset, traversing binned rows.
Source§

fn scores(&mut self, dataset: usize) -> Result<Vec<f32>>

The current scores of dataset.
Source§

fn set_thread_pool(&mut self, pool: Arc<ThreadPool>)

The pool host-side parallel work runs on when num_threads is set; backends without host-side parallelism ignore it. Called before load.
Source§

fn set_histogram_features(&mut self, used: &[bool])

Histograms from now on only need the bins of the features with used[feature] (LightGBM is_feature_used: the tree’s feature mask and the parent’s splittable features); the other bins may hold anything. Every rank passes the same mask. Backends may ignore it.

Auto Trait Implementations§

§

impl<D> Forget for GpuBackend<D>

§

impl<D> Freeze for GpuBackend<D>
where Option<Loaded<<D as GpuDevice>::Buffer>>: Freeze, D: Freeze,

§

impl<D> Move for GpuBackend<D>

§

impl<D> RefUnwindSafe for GpuBackend<D>
where Option<Loaded<<D as GpuDevice>::Buffer>>: RefUnwindSafe, D: RefUnwindSafe,

§

impl<D> Send for GpuBackend<D>
where Option<Loaded<<D as GpuDevice>::Buffer>>: Send, D: Send,

§

impl<D> Sync for GpuBackend<D>
where Option<Loaded<<D as GpuDevice>::Buffer>>: Sync, D: Sync,

§

impl<D> Unpin for GpuBackend<D>
where Option<Loaded<<D as GpuDevice>::Buffer>>: Unpin, D: Unpin,

§

impl<D> UnsafeUnpin for GpuBackend<D>
where Option<Loaded<<D as GpuDevice>::Buffer>>: UnsafeUnpin, D: UnsafeUnpin,

§

impl<D> UnwindSafe for GpuBackend<D>
where Option<Loaded<<D as GpuDevice>::Buffer>>: UnwindSafe, D: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more