Skip to main content

CpuAccess

Enum CpuAccess 

Source
#[repr(u32)]
pub enum CpuAccess { None = 0, Read = 1, Write = 2, ReadWrite = 3, }
Expand description

Declared CPU involvement for a tensor, chosen at allocation.

The declaration covers all CPU access to the buffer: the caller’s maps, pins and sync brackets, and the HAL’s own CPU work (the CPU image backend’s converts and draws, codec decodes, decoder reads and writes). Hardware access (ISP, codec, GPU, NPU, G2D, a compositor) needs no declaration and is always allowed.

The HAL enforces it. A CPU map, pin or sync whose direction the declaration does not cover fails with Error::CpuAccessDenied on every backend, before the memory is touched. The HAL’s own CPU passes go through the same check, so, for example, a CPU draw that would blend over a Write image, or a CPU convert that would read a None source, is refused instead of running.

LevelCPU mayMemory selected
NonenothingLinux DMA-BUF: uncached CMA where available. Android: no CPU usage bits, so tile compression stays possible.
Readreadcached; read-direction syncs only
Writewrite whole passesLinux DMA-BUF: uncached CMA where available, written write-combined
ReadWrite (default)read and writecached

Why uncached. A device that maps a cached buffer has to clean and invalidate the CPU cache over all of it on every access: a compositor blitting a client’s buffer every frame pays that for the whole buffer each time. An uncached buffer needs no cache maintenance. CPU reads of uncached memory are slow, which is why only declarations that exclude CPU reads select it; with the declaration enforced, nothing reads such a buffer on the CPU. On Linux a None or Write DMA-BUF comes from /dev/dma_heap/linux,cma-uncached when the system has it, and from the cached heaps otherwise. A write-only pass must write the whole buffer (see TensorTrait::map_for_write).

On Android the ReadWrite default asks gralloc for CPU_READ_OFTEN | CPU_WRITE_OFTEN, which may give linear, CPU-cached memory. Pass None for a buffer that is never mapped on the CPU, so gralloc can keep a tiled or compressed allocation.

§Examples

A CPU-drawn overlay: written whole every frame, never read back.

use edgefirst_tensor::{
    CpuAccess, Error, PixelFormat, Tensor, TensorMapTrait, TensorMemory, TensorTrait,
};

let overlay = Tensor::<u8>::image(
    640,
    480,
    PixelFormat::Rgba,
    Some(TensorMemory::DmaBuf),
    CpuAccess::Write,
)?;
overlay.map_for_write()?.as_mut_slice().fill(0);
assert!(matches!(overlay.map_read(), Err(Error::CpuAccessDenied { .. })));

CpuAccess::code is the wire code the C header’s ef_cpu_access enumerators are asserted against.

Variants§

§

None = 0

Hardware-only buffer: no CPU access. Required for vendor tile compression on platforms with compressed layouts; uncached CMA for a Linux DMA-BUF where available.

§

Read = 1

CPU reads only (verification, CPU consumers) — cached mapping.

§

Write = 2

CPU writes only, whole-buffer passes (decode targets, CPU-drawn overlays) — write-combined mapping; uncached CMA for a Linux DMA-BUF where available.

§

ReadWrite = 3

CPU reads and writes (the default).

Implementations§

Source§

impl CpuAccess

Source

pub const fn code(self) -> u32

The shared code for this variant. Identical on every surface.

const, deliberately: a downstream binding that cannot write Variant = OtherEnum::Variant.code() in a #[pyclass] discriminant position (PyO3 requires a literal there) can still pin that literal to this value with a const _: () = assert!(...) – a build-time check instead of a hand-synced comment. See PyTensorMemory/PyPixelFormat in crates/python-common/src/tensor.rs for the consumer.

Source

pub fn from_code(code: u32) -> Option<Self>

Reject an unknown code rather than guessing at one.

Source

pub fn as_str(self) -> &'static str

The wire string form – stable, unlike Debug.

Source

pub fn from_str_code(s: &str) -> Option<Self>

Reject an unknown string rather than guessing at one.

Source

pub fn all() -> &'static [Self]

Every variant, for exhaustive cross-surface tests.

Source§

impl CpuAccess

Source

pub fn reads(self) -> bool

Whether this declaration includes CPU reads.

Source

pub fn writes(self) -> bool

Whether this declaration includes CPU writes.

Source

pub fn covers(self, requested: CpuAccess) -> bool

Whether this declaration covers requested (every direction the request needs is declared).

Source

pub fn union(self, other: CpuAccess) -> CpuAccess

The declaration covering every direction of both self and other.

use edgefirst_tensor::CpuAccess;
assert_eq!(CpuAccess::Read.union(CpuAccess::Write), CpuAccess::ReadWrite);
assert_eq!(CpuAccess::None.union(CpuAccess::Write), CpuAccess::Write);
Source

pub fn intersection(self, other: CpuAccess) -> CpuAccess

The declaration covering only the directions both self and other cover.

use edgefirst_tensor::CpuAccess;
assert_eq!(CpuAccess::ReadWrite.intersection(CpuAccess::Write), CpuAccess::Write);
assert_eq!(CpuAccess::Read.intersection(CpuAccess::Write), CpuAccess::None);
Source

pub fn require(self, requested: CpuAccess) -> Result<()>

Ok when this declaration covers requested, otherwise Error::CpuAccessDenied naming both.

use edgefirst_tensor::{CpuAccess, Error};
assert!(CpuAccess::ReadWrite.require(CpuAccess::Write).is_ok());
assert!(matches!(
    CpuAccess::Read.require(CpuAccess::Write),
    Err(Error::CpuAccessDenied { .. })
));

Trait Implementations§

Source§

impl Clone for CpuAccess

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 Copy for CpuAccess

Source§

impl Debug for CpuAccess

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CpuAccess

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for CpuAccess

Source§

impl Hash for CpuAccess

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CpuAccess

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CpuAccess

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
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