Skip to main content

Device

Struct Device 

Source
pub struct Device { /* private fields */ }
Expand description

An initialized native device. Clones share the process-owned device.

§Thread affinity

The native device table is thread-affine: enumerate once per thread and keep the device, its allocator and every network that uses them on that thread. Devices coordinate process-owned runtime state, so a device is not Send or Sync.

Implementations§

Source§

impl Device

Source

pub fn enumerate() -> Result<Vec<DeviceInfo>>

Enumerates available devices without silently substituting the CPU backend.

The order is the native one and matches the index Device::new accepts. An empty vector means no driver or ICD is visible, which is a missing capability rather than an empty device list to fall back from.

Source

pub fn new(index: usize) -> Result<Self>

Selects one device by index after validating it.

An index the driver does not expose returns Error::Unsupported. The native device outlives this handle: every network that selects it keeps a reference.

Source

pub fn default_device() -> Result<Self>

Selects the device the native runtime ranks first.

ncnn scores the visible devices and picks one, so this is the portable choice for an application that does not pin a GPU. Combine enumerate with new when a specific device matters.

Source

pub fn info(&self) -> DeviceInfo

Returns the copied device metadata.

The values are read once per call, so later driver-side changes are not observed.

Source§

impl Device

Source

pub fn allocator(&self) -> Result<Allocator>

Creates a thread-affine allocator on this device.

Source

pub fn heap_budget_mib(&self) -> usize

Reports the native device-wide heap budget in MiB, not application usage.

Source

pub fn raw_device_handle(&self) -> u64

Returns the borrowed native VkDevice handle. This does not transfer ownership.

Source

pub fn save_pipeline_cache(&self, path: impl AsRef<Path>) -> Result<()>

Serializes native compatibility metadata, shaders, and Vulkan pipeline data.

Source

pub fn pipeline_cache(&self) -> Result<Vec<u8>>

Returns the serialized pipeline cache for storage outside the file system.

The bytes are what save_pipeline_cache writes, so a caller can keep them in memory, in an archive or in another process’s transport.

Source

pub fn load_pipeline_cache(&self, path: impl AsRef<Path>) -> Result<()>

Rejects incompatible or corrupted native cache headers and payload hashes.

Source

pub fn set_pipeline_cache(&self, data: &[u8]) -> Result<()>

Loads a serialized pipeline cache produced by pipeline_cache.

Trait Implementations§

Source§

impl Clone for Device

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Device

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.