Skip to main content

TensorBackendCapability

Trait TensorBackendCapability 

Source
pub trait TensorBackendCapability {
    // Required methods
    fn backend_id(&self) -> BackendId;
    fn capabilities(&self) -> &'static [OperationCapability];

    // Provided method
    fn capability(&self, query: CapabilityQuery) -> Option<OperationCapability> { ... }
}
Expand description

Backend capability query surface.

§Examples

use tenferro_core_ops::PrimitiveOpKind;
use tenferro_tensor::{
    BackendId, CapabilityQuery, DType, OperationCapability, SupportLevel,
    TensorBackendCapability,
};

struct Backend;

const ENTRIES: &[OperationCapability] = &[OperationCapability {
    backend: BackendId::Cpu,
    op: PrimitiveOpKind::Add,
    dtype: DType::F32,
    output_dtype: DType::F32,
    result: SupportLevel::Native,
    read_inputs: SupportLevel::Native,
    write_output: SupportLevel::Native,
    strided_output: SupportLevel::Native,
    accumulation: SupportLevel::Unsupported,
}];

impl TensorBackendCapability for Backend {
    fn backend_id(&self) -> BackendId { BackendId::Cpu }
    fn capabilities(&self) -> &'static [OperationCapability] { ENTRIES }
}

assert!(Backend
    .capability(CapabilityQuery::new(PrimitiveOpKind::Add, DType::F32))
    .is_some());

Required Methods§

Provided Methods§

Source

fn capability(&self, query: CapabilityQuery) -> Option<OperationCapability>

Look up one operation/dtype capability for this backend.

§Examples
use tenferro_core_ops::PrimitiveOpKind;
use tenferro_tensor::{
    BackendId, CapabilityQuery, DType, OperationCapability, SupportLevel,
    TensorBackendCapability,
};

struct Backend;
const ENTRIES: &[OperationCapability] = &[OperationCapability {
    backend: BackendId::Cpu,
    op: PrimitiveOpKind::Mul,
    dtype: DType::I64,
    output_dtype: DType::I64,
    result: SupportLevel::Native,
    read_inputs: SupportLevel::Native,
    write_output: SupportLevel::Unsupported,
    strided_output: SupportLevel::Unsupported,
    accumulation: SupportLevel::Unsupported,
}];
impl TensorBackendCapability for Backend {
    fn backend_id(&self) -> BackendId { BackendId::Cpu }
    fn capabilities(&self) -> &'static [OperationCapability] { ENTRIES }
}

let entry = Backend
    .capability(CapabilityQuery::new(PrimitiveOpKind::Mul, DType::I64))
    .unwrap();
assert_eq!(entry.result, SupportLevel::Native);

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§