Skip to main content

XdnaProgram

Struct XdnaProgram 

Source
pub struct XdnaProgram(/* private fields */);
Expand description

Loaded, bound XDNA entry with a private context and establishing command. Clones share one queue and up to 128 accepted invocations. Bindings remain leased until every outstanding invocation has retired.

Implementations§

Source§

impl XdnaProgram

Source

pub unsafe fn wrap_transaction( self, prefix: &[u8], prefix_operations: u32, suffix: &[u8], suffix_operations: u32, retained: &[Buffer], budget: Option<&MemoryBudget>, ) -> Result<Self>

Compose trusted native transaction records around the bound invocation. This consumes an exclusive, never-submitted program. The original command body is preserved; only its transaction size/count header is updated. Additional addressed buffers are retained through checked retirement.

§Safety

Records must own disjoint native resources, preserve the establishing invocation, and drain every added DMA/worker before command completion. Every address they embed must belong to retained or existing bindings.

Source

pub unsafe fn dispatch(&self) -> Result<XdnaCompletion>

Publish the complete establishing command and retain all external backing.

§Safety

The caller orders conflicting accesses by other queues. The compiled program must obey each binding’s declared range and access contract.

Examples found in repository?
examples/mall_probe.rs (line 55)
10fn main() -> Result<()> {
11    let seconds: f64 = std::env::args()
12        .nth(1)
13        .unwrap_or_else(|| "2".into())
14        .parse()
15        .map_err(|e: std::num::ParseFloatError| hrx::Error::Message(e.to_string()))?;
16    if !seconds.is_finite() || !(0.01..=3600.0).contains(&seconds) {
17        return Err(hrx::Error::Message("seconds must be in 0.01..=3600".into()));
18    }
19    let device = Device::open(Engine::Xdna, 0)?;
20    let compiler = Compiler::for_target(None, device.target())?;
21    println!("working_set_MiB GB/s dispatches/s");
22    for mib in [1, 4, 8, 16, 32, 64] {
23        let bytes = mib * 1024 * 1024;
24        let artifact = compiler
25            .module(include_str!("../tests/kernels/copy.xdna.loom"))
26            .compile(
27                &Specialization::new("copy")
28                    .with_config("copy.packets", (bytes / 4096).to_string()),
29            )?;
30        let input = device
31            .fabric()
32            .allocate(bytes, std::slice::from_ref(&device))?;
33        let output = device
34            .fabric()
35            .allocate(bytes, std::slice::from_ref(&device))?;
36        input.write(0, &vec![0x5a; bytes])?;
37        let program = unsafe {
38            device.prepare_xdna(
39                &artifact,
40                1,
41                &[
42                    XdnaBinding {
43                        buffer: &input,
44                        offset: 0,
45                        length: bytes,
46                    },
47                    XdnaBinding {
48                        buffer: &output,
49                        offset: 0,
50                        length: bytes,
51                    },
52                ],
53            )
54        }?;
55        unsafe { program.dispatch() }?.wait()?;
56        let mut check = vec![0; bytes];
57        output.read(0, &mut check)?;
58        assert!(check.iter().all(|&b| b == 0x5a));
59        let start = Instant::now();
60        let mut count = 0;
61        while start.elapsed() < Duration::from_secs_f64(seconds) {
62            unsafe { program.dispatch() }?.wait()?;
63            count += 1;
64        }
65        let elapsed = start.elapsed().as_secs_f64();
66        println!(
67            "{} {:.3} {:.1}",
68            2 * mib,
69            2.0 * bytes as f64 * count as f64 / elapsed / 1e9,
70            count as f64 / elapsed
71        );
72    }
73    Ok(())
74}

Trait Implementations§

Source§

impl Clone for XdnaProgram

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

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> DropFlavorWrapper<T> for T

Source§

type Flavor = MayDrop

The DropFlavor that wraps T into Self
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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