pub struct PaddedArray<T> { /* private fields */ }Expand description
A device array in which each element occupies a full cache line.
Use this for per-hart outputs so distinct harts never share a cache line
(see the module docs). T must be no larger than one cache line.
Implementations§
Source§impl<T: DevicePod> PaddedArray<T>
impl<T: DevicePod> PaddedArray<T>
Sourcepub fn addr(&self) -> u64
pub fn addr(&self) -> u64
Device address of element 0 (element i lives at addr + i * CACHE_LINE).
Examples found in repository?
examples/reset_test.rs (line 110)
91fn launch_reduce(
92 device: &Device<et_soc1::transport::IoctlTransport>,
93 kernel: &et_soc1::LoadedKernel,
94 shire_mask: u64,
95 n_harts: u32,
96) -> et_soc1::Result<()> {
97 const N: u32 = 4096;
98 // The reduce-rs kernel reads the input as &[u32], so upload u32 values.
99 // The expected total is sum(0..N) regardless of whether i64 or u32 is used,
100 // but the partial values written by the kernel (out[h] = sum of the h-th
101 // slice of u32 elements) must be consistent with what the kernel computes.
102 let input: Vec<u32> = (0..N).collect();
103 let expected: i64 = (0..N as i64).sum();
104
105 let buf = device.upload(&input)?;
106 let partials = device.alloc_padded::<i64>(n_harts as usize)?;
107
108 let args = ReduceArgs {
109 input: buf.addr(),
110 out: partials.addr(),
111 n: N,
112 n_harts,
113 };
114 let opts = LaunchOptions::new(shire_mask).with_args(args.as_bytes().to_vec());
115 device.launch(kernel, &opts)?;
116
117 let result: Vec<i64> = device.download_padded(&partials)?;
118 let total: i64 = result.iter().copied().take(n_harts as usize).sum();
119 if total != expected {
120 return Err(et_soc1::Error::Protocol(format!(
121 "reduction mismatch: got {total}, expected {expected}"
122 )));
123 }
124 println!(" reduction over {N} elements: total = {total} (correct)");
125 Ok(())
126}More examples
examples/reduce.rs (line 92)
39fn run() -> et_soc1::Result<()> {
40 let kernel_path = std::env::args().nth(1).unwrap_or_else(|| {
41 eprintln!("usage: reduce <reduce-rs.elf>");
42 std::process::exit(2);
43 });
44 let elf = std::fs::read(&kernel_path).map_err(|e| et_soc1::Error::io("read kernel ELF", e))?;
45
46 let device = open_device()?;
47 let di = device.dram_info();
48 println!(
49 "Device ready: DRAM base {:#x}, size {} bytes",
50 di.base, di.size
51 );
52
53 // Size the launch to the device: one shire, all its harts. No hard-coded 64.
54 let topo = device.topology()?;
55 let shire_mask = topo.first_shire();
56 let n_harts = topo.harts_per_shire;
57 // `Grid` numbers harts by their global id, so harts 0..n_harts exist only
58 // in shire 0; on any other shire every hart would be inactive.
59 if shire_mask != 1 {
60 return Err(et_soc1::Error::Limit(format!(
61 "reduce requires shire 0 (present mask {:#x})",
62 topo.shire_mask
63 )));
64 }
65 println!(
66 "Topology: {} shire(s) present (mask {:#x}), {} harts/shire; launching on shire mask {:#x}",
67 topo.num_shires(),
68 topo.shire_mask,
69 topo.harts_per_shire,
70 shire_mask
71 );
72
73 let kernel = device.load_kernel(&elf)?;
74
75 // Host input: element i = i + 1, so the exact sum is known.
76 let host_in: Vec<u32> = (0..N).map(|i| i + 1).collect();
77
78 // Typed device buffers: upload the input, allocate one cache-line-padded
79 // partial per hart (the padding prevents false sharing). No byte casts, no
80 // raw addresses at the call site.
81 let input = device.upload(&host_in)?;
82 let partials = device.alloc_padded::<u64>(n_harts as usize)?;
83 // Every hart's partial is non-zero (each slice holds positive elements), so
84 // a zero-filled buffer exposes any hart that did not write its cell.
85 device.fill(partials.region(), 0)?;
86 let trace_buf = device.alloc(TRACE_BUFFER_SIZE)?;
87
88 // Kernel args: the same struct the kernel reads (et-abi), so host and device
89 // cannot drift on layout.
90 let args = ReduceArgs {
91 input: input.addr(),
92 out: partials.addr(),
93 n: N,
94 n_harts,
95 };
96
97 // One typed call bundles the shire mask, the argument staging, and tracing.
98 let launch = device.launch_spmd_traced(
99 &kernel,
100 shire_mask,
101 &args,
102 TraceConfig::full(trace_buf, shire_mask),
103 );
104
105 // Print any trace lines regardless of launch outcome (on an exception the
106 // firmware still fills the trace buffer -- useful for diagnostics).
107 if let Ok(tb) = TraceBuffer::parse(&out_trace(&device, trace_buf)?) {
108 for (hart, s) in tb.string_entries() {
109 println!("[hart {hart}] {}", s.trim_end());
110 }
111 }
112
113 match &launch {
114 Ok(r) => println!(
115 "Kernel completed in {} cycles (waited {}).",
116 r.timing.execute_dur, r.timing.wait_dur
117 ),
118 Err(e) => println!("Launch error: {e}"),
119 }
120 launch?;
121
122 // Combine the per-hart partials (download extracts one u64 per cache line).
123 let parts = device.download_padded(&partials)?;
124 let total: u64 = parts.iter().copied().fold(0u64, u64::wrapping_add);
125 let nonzero = parts.iter().filter(|&&p| p != 0).count();
126
127 let expected = (N as u64) * (N as u64 + 1) / 2;
128 println!(
129 "\nReduction over {N} elements on {n_harts} harts ({nonzero} contributed):\n \
130 device total = {total}\n expected = {expected}"
131 );
132 if nonzero != n_harts as usize {
133 return Err(et_soc1::Error::Protocol(format!(
134 "only {nonzero} of {n_harts} harts wrote a partial"
135 )));
136 }
137 if total == expected {
138 println!("RESULT PASS");
139 Ok(())
140 } else {
141 Err(et_soc1::Error::Protocol(format!(
142 "reduction mismatch: got {total}, expected {expected}"
143 )))
144 }
145}examples/double_buffer.rs (line 112)
67fn run() -> et_soc1::Result<()> {
68 let kernel_path = std::env::args().nth(1).unwrap_or_else(|| {
69 eprintln!("usage: double_buffer <cache-test-rs.elf>");
70 std::process::exit(2);
71 });
72
73 let elf = std::fs::read(&kernel_path).map_err(|e| et_soc1::Error::io("read kernel ELF", e))?;
74
75 let device = Device::open(0)?;
76 let topo = device.topology()?;
77 let n_shires = topo.num_shires() as usize;
78 let n_minions = n_shires * MINIONS_PER_SHIRE as usize;
79 // Cells are indexed by physical shire, so the arrays span every shire up to
80 // the highest present one and the kernel receives that extent; cells of
81 // absent shires must keep the sentinel.
82 let shire_extent = (u64::BITS - topo.shire_mask.leading_zeros()) as usize;
83 let n_cells = shire_extent * MINIONS_PER_SHIRE as usize;
84 let present = |cell: usize| topo.shire_mask & (1 << (cell / MINIONS_PER_SHIRE as usize)) != 0;
85
86 println!(
87 "Device: {} shires (mask {:#x}), {} Minions",
88 n_shires, topo.shire_mask, n_minions,
89 );
90
91 let kernel = device.load_kernel(&elf)?;
92
93 // Two separate output arrays: each Minion writes its global index to its
94 // own 64-byte-padded cell.
95 // Both are prefilled with the sentinel so an unwritten cell fails.
96 let out_a = device.alloc_padded::<u32>(n_cells)?;
97 let out_b = device.alloc_padded::<u32>(n_cells)?;
98 device.fill(out_a.region(), SENTINEL)?;
99 device.fill(out_b.region(), SENTINEL)?;
100
101 // Device region used as the staging target for the Phase B DMA.
102 // Content does not matter; we just need a valid writable region.
103 let staging = device.alloc(STAGING_BYTES as u64)?;
104 let staging_data = vec![0u8; STAGING_BYTES];
105
106 // -----------------------------------------------------------------------
107 // Phase A: basic launch_async + wait_launch
108 // -----------------------------------------------------------------------
109 println!("\nPhase A: launch_async + wait_launch");
110
111 let args_a = CacheTestArgs {
112 output: out_a.addr(),
113 n_shires: shire_extent as u64,
114 dest: 3, // Mem: writeback to DDR for host visibility
115 };
116 let opts_a = LaunchOptions::new(topo.shire_mask)
117 .without_barrier() // first launch: no prior command to wait for
118 .with_args(args_a.as_bytes().to_vec());
119
120 let pending_a = device.launch_async(&kernel, &opts_a)?;
121 println!(" kernel A fired (async, SQ 0)");
122
123 let _r = device.wait_launch(pending_a)?;
124 println!(" kernel A complete");
125
126 let results_a = device.download_padded(&out_a)?;
127 check("A", &results_a, &present)?;
128
129 // -----------------------------------------------------------------------
130 // Phase B: response stash + concurrent DMA on SQ 1
131 // -----------------------------------------------------------------------
132 println!("\nPhase B: kernel (SQ 0) overlapped with DMA (SQ 1)");
133
134 let args_b = CacheTestArgs {
135 output: out_b.addr(),
136 n_shires: shire_extent as u64,
137 dest: 3, // Mem: writeback to DDR for host visibility
138 };
139 let opts_b = LaunchOptions::new(topo.shire_mask)
140 // barrier=true (default): wait for prior SQ 0 commands (kernel A is
141 // already done, so this barrier is immediate).
142 .with_args(args_b.as_bytes().to_vec());
143
144 // Fire kernel B asynchronously.
145 let pending_b = device.launch_async(&kernel, &opts_b)?;
146 println!(" kernel B fired (async, SQ 0)");
147
148 // While kernel B may be running on SQ 0, DMA 64 KB on SQ 1.
149 // The firmware can schedule both streams concurrently. If kernel B's CQ
150 // response arrives during this DMA wait, `collect_response` stashes it;
151 // `wait_launch` below retrieves it from the stash without re-polling.
152 device.memcpy_h2d_opts(&staging_data, staging.addr, &DmaOptions::new().on_sq(1))?;
153 println!(" {} KB staging DMA complete (SQ 1)", STAGING_BYTES / 1024);
154
155 // Collect kernel B's result, possibly from the stash.
156 let _r = device.wait_launch(pending_b)?;
157 println!(" kernel B complete");
158
159 let results_b = device.download_padded(&out_b)?;
160 check("B", &results_b, &present)?;
161
162 println!("\ndouble_buffer PASSED");
163 Ok(())
164}examples/cache_test.rs (line 138)
81fn run() -> et_soc1::Result<()> {
82 let argv: Vec<String> = std::env::args().collect();
83 let kernel_path = argv.get(1).cloned().unwrap_or_else(|| {
84 eprintln!("usage: cache_test <cache-test-rs.elf> [shires] [dest:1=L2,2=L3,3=Mem]");
85 std::process::exit(2);
86 });
87 let elf = std::fs::read(&kernel_path).map_err(|e| et_soc1::Error::io("read kernel ELF", e))?;
88
89 let device = Device::open(0)?;
90 let topo = device.topology()?;
91 let max_shires = topo.num_shires() as usize;
92
93 // Narrowing controls. `shires` (default all) isolates concurrency-dependent
94 // faults; `dest` (default 3 = Mem) isolates the DDR writeback path.
95 let n_shires = argv
96 .get(2)
97 .and_then(|s| s.parse::<usize>().ok())
98 .map(|k| k.clamp(1, max_shires))
99 .unwrap_or(max_shires);
100 let dest: u64 = argv.get(3).and_then(|s| s.parse().ok()).unwrap_or(3);
101 // The lowest `n_shires` present shires. Cells are indexed by physical
102 // shire, so the output spans every shire up to the highest launched one and
103 // `n_shires` in the arguments is that extent, not the count.
104 let mut shire_mask = 0u64;
105 for shire in (0..u64::BITS)
106 .filter(|&s| topo.shire_mask & (1 << s) != 0)
107 .take(n_shires)
108 {
109 shire_mask |= 1 << shire;
110 }
111 let shire_extent = (u64::BITS - shire_mask.leading_zeros()) as usize;
112 let n_cells = shire_extent * MINIONS_PER_SHIRE as usize;
113 let n_minions = n_shires * MINIONS_PER_SHIRE as usize;
114 let launched = |cell: usize| shire_mask & (1 << (cell / MINIONS_PER_SHIRE as usize)) != 0;
115
116 println!(
117 "Device: {} shires present (mask {:#x}); running {} shire(s) (mask {:#x}), {} Minions, dest = {}",
118 max_shires,
119 topo.shire_mask,
120 n_shires,
121 shire_mask,
122 n_minions,
123 dest_name(dest),
124 );
125
126 // Kernel must be loaded first so it lands at DRAM base (its link address).
127 // Allocating output before load_kernel would place the output buffer at
128 // DRAM base and kernel code would then DMA-overwrite it.
129 let kernel = device.load_kernel(&elf)?;
130
131 // Output: one u32 per Minion, each on its own 64-byte cache line, prefilled
132 // with the sentinel. Every Minion index is below it, so an unwritten cell
133 // cannot pass verification.
134 let output = device.alloc_padded::<u32>(n_cells)?;
135 device.fill(output.region(), SENTINEL)?;
136
137 let args = CacheTestArgs {
138 output: output.addr(),
139 n_shires: shire_extent as u64,
140 dest,
141 };
142
143 // Opt-in exception-context capture. Setting a non-zero exception_buffer is a
144 // firmware-supported feature only on some builds: on the current card build
145 // it is itself rejected with EXCEPTION (status 2) regardless of kernel
146 // correctness, and firmware leaves the buffer untouched. It is therefore off
147 // by default (the launch then mirrors the passing double_buffer path) and
148 // enabled only via ET_EXC_BUFFER=1 for probing a future firmware.
149 let exc = if std::env::var_os("ET_EXC_BUFFER").is_some() {
150 // Pre-zeroed so a non-fault run leaves recognisable zeros.
151 let region = device.alloc(EXC_BUF_LEN as u64)?;
152 device.memcpy_h2d(&[0u8; EXC_BUF_LEN], region.addr)?;
153 println!(
154 "ET_EXC_BUFFER set: capturing U-mode context @ {:#x}",
155 region.addr
156 );
157 Some(region)
158 } else {
159 None
160 };
161
162 println!("Launching cache_writeback test ...");
163 let mut opts = LaunchOptions::new(shire_mask).with_args(args.as_bytes().to_vec());
164 // ET_NO_BARRIER clears the launch BARRIER flag (diagnostic). Tested and
165 // refuted: a stress loop measured the same 50-90 percent EXCEPTION rate with
166 // the barrier on or off, so the firmware barrier/drain path is not the fault
167 // trigger. Retained so the comparison can be reproduced without recompiling.
168 if std::env::var_os("ET_NO_BARRIER").is_some() {
169 opts = opts.without_barrier();
170 }
171 if let Some(ref region) = exc {
172 opts.exception_buffer = region.addr;
173 }
174 if let Err(e) = device.launch(&kernel, &opts) {
175 // Decode the U-mode context the firmware saved before returning the error.
176 if let Some(ref region) = exc {
177 let mut raw = vec![0u8; EXC_BUF_LEN];
178 device.memcpy_d2h(region.addr, &mut raw)?;
179 print_exception(&raw);
180 }
181 return Err(e);
182 }
183 println!("Kernel returned.");
184
185 // Download the per-Minion outputs (strips 64-byte padding).
186 let results = device.download_padded(&output)?;
187
188 let mut failures = 0_usize;
189 for (i, &val) in results.iter().enumerate() {
190 let expected = if launched(i) { i as u32 } else { SENTINEL_WORD };
191 if val != expected {
192 eprintln!(" FAIL output[{i}] = {val:#010x} (expected {expected:#010x})");
193 failures += 1;
194 }
195 }
196
197 if failures == 0 {
198 println!("cache_writeback PASSED: all {} cells correct", n_cells);
199 Ok(())
200 } else {
201 Err(et_soc1::Error::Protocol(format!(
202 "cache_writeback FAILED: {failures}/{n_cells} cells incorrect"
203 )))
204 }
205}Sourcepub fn stride(&self) -> usize
pub fn stride(&self) -> usize
The stride between consecutive elements, in bytes (one cache line).
Sourcepub fn region(&self) -> DeviceRegion
pub fn region(&self) -> DeviceRegion
The underlying untyped region.
Examples found in repository?
examples/reduce.rs (line 85)
39fn run() -> et_soc1::Result<()> {
40 let kernel_path = std::env::args().nth(1).unwrap_or_else(|| {
41 eprintln!("usage: reduce <reduce-rs.elf>");
42 std::process::exit(2);
43 });
44 let elf = std::fs::read(&kernel_path).map_err(|e| et_soc1::Error::io("read kernel ELF", e))?;
45
46 let device = open_device()?;
47 let di = device.dram_info();
48 println!(
49 "Device ready: DRAM base {:#x}, size {} bytes",
50 di.base, di.size
51 );
52
53 // Size the launch to the device: one shire, all its harts. No hard-coded 64.
54 let topo = device.topology()?;
55 let shire_mask = topo.first_shire();
56 let n_harts = topo.harts_per_shire;
57 // `Grid` numbers harts by their global id, so harts 0..n_harts exist only
58 // in shire 0; on any other shire every hart would be inactive.
59 if shire_mask != 1 {
60 return Err(et_soc1::Error::Limit(format!(
61 "reduce requires shire 0 (present mask {:#x})",
62 topo.shire_mask
63 )));
64 }
65 println!(
66 "Topology: {} shire(s) present (mask {:#x}), {} harts/shire; launching on shire mask {:#x}",
67 topo.num_shires(),
68 topo.shire_mask,
69 topo.harts_per_shire,
70 shire_mask
71 );
72
73 let kernel = device.load_kernel(&elf)?;
74
75 // Host input: element i = i + 1, so the exact sum is known.
76 let host_in: Vec<u32> = (0..N).map(|i| i + 1).collect();
77
78 // Typed device buffers: upload the input, allocate one cache-line-padded
79 // partial per hart (the padding prevents false sharing). No byte casts, no
80 // raw addresses at the call site.
81 let input = device.upload(&host_in)?;
82 let partials = device.alloc_padded::<u64>(n_harts as usize)?;
83 // Every hart's partial is non-zero (each slice holds positive elements), so
84 // a zero-filled buffer exposes any hart that did not write its cell.
85 device.fill(partials.region(), 0)?;
86 let trace_buf = device.alloc(TRACE_BUFFER_SIZE)?;
87
88 // Kernel args: the same struct the kernel reads (et-abi), so host and device
89 // cannot drift on layout.
90 let args = ReduceArgs {
91 input: input.addr(),
92 out: partials.addr(),
93 n: N,
94 n_harts,
95 };
96
97 // One typed call bundles the shire mask, the argument staging, and tracing.
98 let launch = device.launch_spmd_traced(
99 &kernel,
100 shire_mask,
101 &args,
102 TraceConfig::full(trace_buf, shire_mask),
103 );
104
105 // Print any trace lines regardless of launch outcome (on an exception the
106 // firmware still fills the trace buffer -- useful for diagnostics).
107 if let Ok(tb) = TraceBuffer::parse(&out_trace(&device, trace_buf)?) {
108 for (hart, s) in tb.string_entries() {
109 println!("[hart {hart}] {}", s.trim_end());
110 }
111 }
112
113 match &launch {
114 Ok(r) => println!(
115 "Kernel completed in {} cycles (waited {}).",
116 r.timing.execute_dur, r.timing.wait_dur
117 ),
118 Err(e) => println!("Launch error: {e}"),
119 }
120 launch?;
121
122 // Combine the per-hart partials (download extracts one u64 per cache line).
123 let parts = device.download_padded(&partials)?;
124 let total: u64 = parts.iter().copied().fold(0u64, u64::wrapping_add);
125 let nonzero = parts.iter().filter(|&&p| p != 0).count();
126
127 let expected = (N as u64) * (N as u64 + 1) / 2;
128 println!(
129 "\nReduction over {N} elements on {n_harts} harts ({nonzero} contributed):\n \
130 device total = {total}\n expected = {expected}"
131 );
132 if nonzero != n_harts as usize {
133 return Err(et_soc1::Error::Protocol(format!(
134 "only {nonzero} of {n_harts} harts wrote a partial"
135 )));
136 }
137 if total == expected {
138 println!("RESULT PASS");
139 Ok(())
140 } else {
141 Err(et_soc1::Error::Protocol(format!(
142 "reduction mismatch: got {total}, expected {expected}"
143 )))
144 }
145}More examples
examples/double_buffer.rs (line 98)
67fn run() -> et_soc1::Result<()> {
68 let kernel_path = std::env::args().nth(1).unwrap_or_else(|| {
69 eprintln!("usage: double_buffer <cache-test-rs.elf>");
70 std::process::exit(2);
71 });
72
73 let elf = std::fs::read(&kernel_path).map_err(|e| et_soc1::Error::io("read kernel ELF", e))?;
74
75 let device = Device::open(0)?;
76 let topo = device.topology()?;
77 let n_shires = topo.num_shires() as usize;
78 let n_minions = n_shires * MINIONS_PER_SHIRE as usize;
79 // Cells are indexed by physical shire, so the arrays span every shire up to
80 // the highest present one and the kernel receives that extent; cells of
81 // absent shires must keep the sentinel.
82 let shire_extent = (u64::BITS - topo.shire_mask.leading_zeros()) as usize;
83 let n_cells = shire_extent * MINIONS_PER_SHIRE as usize;
84 let present = |cell: usize| topo.shire_mask & (1 << (cell / MINIONS_PER_SHIRE as usize)) != 0;
85
86 println!(
87 "Device: {} shires (mask {:#x}), {} Minions",
88 n_shires, topo.shire_mask, n_minions,
89 );
90
91 let kernel = device.load_kernel(&elf)?;
92
93 // Two separate output arrays: each Minion writes its global index to its
94 // own 64-byte-padded cell.
95 // Both are prefilled with the sentinel so an unwritten cell fails.
96 let out_a = device.alloc_padded::<u32>(n_cells)?;
97 let out_b = device.alloc_padded::<u32>(n_cells)?;
98 device.fill(out_a.region(), SENTINEL)?;
99 device.fill(out_b.region(), SENTINEL)?;
100
101 // Device region used as the staging target for the Phase B DMA.
102 // Content does not matter; we just need a valid writable region.
103 let staging = device.alloc(STAGING_BYTES as u64)?;
104 let staging_data = vec![0u8; STAGING_BYTES];
105
106 // -----------------------------------------------------------------------
107 // Phase A: basic launch_async + wait_launch
108 // -----------------------------------------------------------------------
109 println!("\nPhase A: launch_async + wait_launch");
110
111 let args_a = CacheTestArgs {
112 output: out_a.addr(),
113 n_shires: shire_extent as u64,
114 dest: 3, // Mem: writeback to DDR for host visibility
115 };
116 let opts_a = LaunchOptions::new(topo.shire_mask)
117 .without_barrier() // first launch: no prior command to wait for
118 .with_args(args_a.as_bytes().to_vec());
119
120 let pending_a = device.launch_async(&kernel, &opts_a)?;
121 println!(" kernel A fired (async, SQ 0)");
122
123 let _r = device.wait_launch(pending_a)?;
124 println!(" kernel A complete");
125
126 let results_a = device.download_padded(&out_a)?;
127 check("A", &results_a, &present)?;
128
129 // -----------------------------------------------------------------------
130 // Phase B: response stash + concurrent DMA on SQ 1
131 // -----------------------------------------------------------------------
132 println!("\nPhase B: kernel (SQ 0) overlapped with DMA (SQ 1)");
133
134 let args_b = CacheTestArgs {
135 output: out_b.addr(),
136 n_shires: shire_extent as u64,
137 dest: 3, // Mem: writeback to DDR for host visibility
138 };
139 let opts_b = LaunchOptions::new(topo.shire_mask)
140 // barrier=true (default): wait for prior SQ 0 commands (kernel A is
141 // already done, so this barrier is immediate).
142 .with_args(args_b.as_bytes().to_vec());
143
144 // Fire kernel B asynchronously.
145 let pending_b = device.launch_async(&kernel, &opts_b)?;
146 println!(" kernel B fired (async, SQ 0)");
147
148 // While kernel B may be running on SQ 0, DMA 64 KB on SQ 1.
149 // The firmware can schedule both streams concurrently. If kernel B's CQ
150 // response arrives during this DMA wait, `collect_response` stashes it;
151 // `wait_launch` below retrieves it from the stash without re-polling.
152 device.memcpy_h2d_opts(&staging_data, staging.addr, &DmaOptions::new().on_sq(1))?;
153 println!(" {} KB staging DMA complete (SQ 1)", STAGING_BYTES / 1024);
154
155 // Collect kernel B's result, possibly from the stash.
156 let _r = device.wait_launch(pending_b)?;
157 println!(" kernel B complete");
158
159 let results_b = device.download_padded(&out_b)?;
160 check("B", &results_b, &present)?;
161
162 println!("\ndouble_buffer PASSED");
163 Ok(())
164}examples/cache_test.rs (line 135)
81fn run() -> et_soc1::Result<()> {
82 let argv: Vec<String> = std::env::args().collect();
83 let kernel_path = argv.get(1).cloned().unwrap_or_else(|| {
84 eprintln!("usage: cache_test <cache-test-rs.elf> [shires] [dest:1=L2,2=L3,3=Mem]");
85 std::process::exit(2);
86 });
87 let elf = std::fs::read(&kernel_path).map_err(|e| et_soc1::Error::io("read kernel ELF", e))?;
88
89 let device = Device::open(0)?;
90 let topo = device.topology()?;
91 let max_shires = topo.num_shires() as usize;
92
93 // Narrowing controls. `shires` (default all) isolates concurrency-dependent
94 // faults; `dest` (default 3 = Mem) isolates the DDR writeback path.
95 let n_shires = argv
96 .get(2)
97 .and_then(|s| s.parse::<usize>().ok())
98 .map(|k| k.clamp(1, max_shires))
99 .unwrap_or(max_shires);
100 let dest: u64 = argv.get(3).and_then(|s| s.parse().ok()).unwrap_or(3);
101 // The lowest `n_shires` present shires. Cells are indexed by physical
102 // shire, so the output spans every shire up to the highest launched one and
103 // `n_shires` in the arguments is that extent, not the count.
104 let mut shire_mask = 0u64;
105 for shire in (0..u64::BITS)
106 .filter(|&s| topo.shire_mask & (1 << s) != 0)
107 .take(n_shires)
108 {
109 shire_mask |= 1 << shire;
110 }
111 let shire_extent = (u64::BITS - shire_mask.leading_zeros()) as usize;
112 let n_cells = shire_extent * MINIONS_PER_SHIRE as usize;
113 let n_minions = n_shires * MINIONS_PER_SHIRE as usize;
114 let launched = |cell: usize| shire_mask & (1 << (cell / MINIONS_PER_SHIRE as usize)) != 0;
115
116 println!(
117 "Device: {} shires present (mask {:#x}); running {} shire(s) (mask {:#x}), {} Minions, dest = {}",
118 max_shires,
119 topo.shire_mask,
120 n_shires,
121 shire_mask,
122 n_minions,
123 dest_name(dest),
124 );
125
126 // Kernel must be loaded first so it lands at DRAM base (its link address).
127 // Allocating output before load_kernel would place the output buffer at
128 // DRAM base and kernel code would then DMA-overwrite it.
129 let kernel = device.load_kernel(&elf)?;
130
131 // Output: one u32 per Minion, each on its own 64-byte cache line, prefilled
132 // with the sentinel. Every Minion index is below it, so an unwritten cell
133 // cannot pass verification.
134 let output = device.alloc_padded::<u32>(n_cells)?;
135 device.fill(output.region(), SENTINEL)?;
136
137 let args = CacheTestArgs {
138 output: output.addr(),
139 n_shires: shire_extent as u64,
140 dest,
141 };
142
143 // Opt-in exception-context capture. Setting a non-zero exception_buffer is a
144 // firmware-supported feature only on some builds: on the current card build
145 // it is itself rejected with EXCEPTION (status 2) regardless of kernel
146 // correctness, and firmware leaves the buffer untouched. It is therefore off
147 // by default (the launch then mirrors the passing double_buffer path) and
148 // enabled only via ET_EXC_BUFFER=1 for probing a future firmware.
149 let exc = if std::env::var_os("ET_EXC_BUFFER").is_some() {
150 // Pre-zeroed so a non-fault run leaves recognisable zeros.
151 let region = device.alloc(EXC_BUF_LEN as u64)?;
152 device.memcpy_h2d(&[0u8; EXC_BUF_LEN], region.addr)?;
153 println!(
154 "ET_EXC_BUFFER set: capturing U-mode context @ {:#x}",
155 region.addr
156 );
157 Some(region)
158 } else {
159 None
160 };
161
162 println!("Launching cache_writeback test ...");
163 let mut opts = LaunchOptions::new(shire_mask).with_args(args.as_bytes().to_vec());
164 // ET_NO_BARRIER clears the launch BARRIER flag (diagnostic). Tested and
165 // refuted: a stress loop measured the same 50-90 percent EXCEPTION rate with
166 // the barrier on or off, so the firmware barrier/drain path is not the fault
167 // trigger. Retained so the comparison can be reproduced without recompiling.
168 if std::env::var_os("ET_NO_BARRIER").is_some() {
169 opts = opts.without_barrier();
170 }
171 if let Some(ref region) = exc {
172 opts.exception_buffer = region.addr;
173 }
174 if let Err(e) = device.launch(&kernel, &opts) {
175 // Decode the U-mode context the firmware saved before returning the error.
176 if let Some(ref region) = exc {
177 let mut raw = vec![0u8; EXC_BUF_LEN];
178 device.memcpy_d2h(region.addr, &mut raw)?;
179 print_exception(&raw);
180 }
181 return Err(e);
182 }
183 println!("Kernel returned.");
184
185 // Download the per-Minion outputs (strips 64-byte padding).
186 let results = device.download_padded(&output)?;
187
188 let mut failures = 0_usize;
189 for (i, &val) in results.iter().enumerate() {
190 let expected = if launched(i) { i as u32 } else { SENTINEL_WORD };
191 if val != expected {
192 eprintln!(" FAIL output[{i}] = {val:#010x} (expected {expected:#010x})");
193 failures += 1;
194 }
195 }
196
197 if failures == 0 {
198 println!("cache_writeback PASSED: all {} cells correct", n_cells);
199 Ok(())
200 } else {
201 Err(et_soc1::Error::Protocol(format!(
202 "cache_writeback FAILED: {failures}/{n_cells} cells incorrect"
203 )))
204 }
205}Trait Implementations§
Source§impl<T: Clone> Clone for PaddedArray<T>
impl<T: Clone> Clone for PaddedArray<T>
impl<T: Copy> Copy for PaddedArray<T>
Auto Trait Implementations§
impl<T> Freeze for PaddedArray<T>where
PhantomData<T>: Freeze,
impl<T> RefUnwindSafe for PaddedArray<T>where
PhantomData<T>: RefUnwindSafe,
impl<T> Send for PaddedArray<T>where
PhantomData<T>: Send,
impl<T> Sync for PaddedArray<T>where
PhantomData<T>: Sync,
impl<T> Unpin for PaddedArray<T>where
PhantomData<T>: Unpin,
impl<T> UnsafeUnpin for PaddedArray<T>where
PhantomData<T>: UnsafeUnpin,
impl<T> UnwindSafe for PaddedArray<T>where
PhantomData<T>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more