vyre_runtime/megakernel/advanced/
zero_copy_io.rs1use vyre_foundation::ir::{Expr, Node};
9
10use crate::resident_work_queue::io::{
11 IO_DESTINATION_CAPABILITY_TABLE, IO_QUEUE_DMA_TAG, IO_SOURCE_CAPABILITY_TABLE,
12};
13
14#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct DirectIoBindings {
17 pub source: &'static str,
19 pub destination: &'static str,
21 pub file_start: &'static str,
23 pub file_end: &'static str,
25 pub tag: &'static str,
27}
28
29impl Default for DirectIoBindings {
30 fn default() -> Self {
31 Self {
32 source: IO_SOURCE_CAPABILITY_TABLE,
33 destination: IO_DESTINATION_CAPABILITY_TABLE,
34 file_start: "file_start",
35 file_end: "file_end",
36 tag: IO_QUEUE_DMA_TAG,
37 }
38 }
39}
40
41#[must_use]
46pub fn pull_file_async_direct() -> Node {
47 pull_file_async_direct_with(&DirectIoBindings::default())
48}
49
50#[must_use]
52pub fn pull_file_async_direct_with(bindings: &DirectIoBindings) -> Node {
53 Node::async_load_gpu_driven(
54 bindings.source,
55 bindings.destination,
56 Expr::var(bindings.file_start),
57 Expr::sub(Expr::var(bindings.file_end), Expr::var(bindings.file_start)),
58 bindings.tag,
59 )
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn direct_io_uses_extended_async_load_fields() {
68 let node = pull_file_async_direct();
69 let Node::AsyncLoad {
70 source,
71 destination,
72 offset,
73 size,
74 tag,
75 } = node
76 else {
77 panic!("direct IO must emit AsyncLoad");
78 };
79 assert_eq!(source.as_str(), IO_SOURCE_CAPABILITY_TABLE);
80 assert_eq!(destination.as_str(), IO_DESTINATION_CAPABILITY_TABLE);
81 assert_eq!(tag.as_str(), IO_QUEUE_DMA_TAG);
82 assert!(matches!(*offset, Expr::Var(_)));
83 assert!(matches!(*size, Expr::BinOp { .. }));
84 }
85}