Skip to main content

vyre_runtime/megakernel/execution/
readback_dispatch.rs

1use super::{Megakernel, MegakernelDispatchStats};
2use crate::megakernel::readback::MegakernelReadback;
3use crate::PipelineError;
4use vyre_driver::backend::OutputBuffers;
5
6impl Megakernel {
7    /// Dispatch with a caller-supplied IO queue and decode the strict
8    /// megakernel readback ABI.
9    ///
10    /// # Errors
11    ///
12    /// Returns [`PipelineError`] when dispatch fails or returned buffers do not
13    /// match the compiled megakernel ABI.
14    pub fn dispatch_with_io_queue_readback(
15        &self,
16        control_bytes: Vec<u8>,
17        ring_bytes: Vec<u8>,
18        debug_log_bytes: Vec<u8>,
19        io_queue_bytes: Vec<u8>,
20    ) -> Result<MegakernelReadback, PipelineError> {
21        let outputs = self.dispatch_with_io_queue_borrowed(
22            &control_bytes,
23            &ring_bytes,
24            &debug_log_bytes,
25            &io_queue_bytes,
26        )?;
27        MegakernelReadback::from_outputs(outputs, self.slot_count)
28    }
29
30    /// Dispatch owned buffers with a caller-supplied IO queue and decode the
31    /// strict megakernel readback ABI into caller-owned storage.
32    ///
33    /// # Errors
34    ///
35    /// Returns [`PipelineError`] when dispatch or readback validation fails.
36    pub fn dispatch_with_io_queue_readback_into(
37        &self,
38        control_bytes: Vec<u8>,
39        ring_bytes: Vec<u8>,
40        debug_log_bytes: Vec<u8>,
41        io_queue_bytes: Vec<u8>,
42        readback: &mut MegakernelReadback,
43        outputs: &mut OutputBuffers,
44    ) -> Result<MegakernelDispatchStats, PipelineError> {
45        self.dispatch_with_io_queue_readback_borrowed_into(
46            &control_bytes,
47            &ring_bytes,
48            &debug_log_bytes,
49            &io_queue_bytes,
50            readback,
51            outputs,
52        )
53    }
54
55    /// Dispatch borrowed buffers with a caller-supplied IO queue and decode
56    /// the strict megakernel readback ABI.
57    ///
58    /// # Errors
59    ///
60    /// See [`Megakernel::dispatch_with_io_queue_readback`].
61    pub fn dispatch_with_io_queue_readback_borrowed(
62        &self,
63        control_bytes: &[u8],
64        ring_bytes: &[u8],
65        debug_log_bytes: &[u8],
66        io_queue_bytes: &[u8],
67    ) -> Result<MegakernelReadback, PipelineError> {
68        let outputs = self.dispatch_with_io_queue_borrowed(
69            control_bytes,
70            ring_bytes,
71            debug_log_bytes,
72            io_queue_bytes,
73        )?;
74        MegakernelReadback::from_outputs(outputs, self.slot_count)
75    }
76
77    /// Dispatch borrowed buffers with a caller-supplied IO queue, decode the
78    /// strict megakernel readback ABI, and return dispatch instrumentation.
79    ///
80    /// # Errors
81    ///
82    /// See [`Megakernel::dispatch_with_io_queue_readback_borrowed`].
83    pub fn dispatch_with_io_queue_readback_borrowed_observed(
84        &self,
85        control_bytes: &[u8],
86        ring_bytes: &[u8],
87        debug_log_bytes: &[u8],
88        io_queue_bytes: &[u8],
89    ) -> Result<(MegakernelReadback, MegakernelDispatchStats), PipelineError> {
90        let output = self.dispatch_with_io_queue_borrowed_observed(
91            control_bytes,
92            ring_bytes,
93            debug_log_bytes,
94            io_queue_bytes,
95        )?;
96        let stats = output.stats;
97        let readback = MegakernelReadback::from_outputs(output.buffers, self.slot_count)?;
98        Ok((readback, stats))
99    }
100
101    /// Dispatch borrowed buffers with a caller-supplied IO queue, decode the
102    /// strict megakernel readback ABI into caller-owned storage, and return
103    /// dispatch instrumentation.
104    ///
105    /// # Errors
106    ///
107    /// Returns [`PipelineError`] when dispatch or readback validation fails.
108    pub fn dispatch_with_io_queue_readback_borrowed_into(
109        &self,
110        control_bytes: &[u8],
111        ring_bytes: &[u8],
112        debug_log_bytes: &[u8],
113        io_queue_bytes: &[u8],
114        readback: &mut MegakernelReadback,
115        outputs: &mut OutputBuffers,
116    ) -> Result<MegakernelDispatchStats, PipelineError> {
117        let stats = self.dispatch_with_io_queue_borrowed_into(
118            control_bytes,
119            ring_bytes,
120            debug_log_bytes,
121            io_queue_bytes,
122            outputs,
123        )?;
124        MegakernelReadback::drain_outputs_into(outputs, self.slot_count, readback)?;
125        Ok(stats)
126    }
127}