cberner / raptorq

Rust implementation of RaptorQ (RFC6330)
Apache License 2.0
264 stars 47 forks source link

Misaligned pointer errors with dev profile on Apple M2 #162

Closed mlegner closed 6 months ago

mlegner commented 6 months ago

When I generate a SourceBlockEncodingPlan with some specific values of symbol_count and compile with the dev profile on my MacBook Pro with an M2 processor, I get a "misaligned pointer dereference" somewhere in the SIMD code:

thread 'main' panicked at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raptorq-1.8.0/src/octets.rs:692:5:
misaligned pointer dereference: address must be a multiple of 0x8 but is 0x148e0967d
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:110:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:122:9
   3: core::panicking::panic_misaligned_pointer_dereference
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:221:5
   4: raptorq::octets::store_neon
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raptorq-1.8.0/src/octets.rs:692:5
   5: raptorq::octets::fused_addassign_mul_scalar_binary_neon
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raptorq-1.8.0/src/octets.rs:206:9
   6: raptorq::octets::fused_addassign_mul_scalar_binary
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raptorq-1.8.0/src/octets.rs:116:24
   7: raptorq::octet_matrix::DenseOctetMatrix::fma_sub_row
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raptorq-1.8.0/src/octet_matrix.rs:41:9
   8: raptorq::pi_solver::IntermediateSymbolDecoder<T>::fma_rows_with_pi
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raptorq-1.8.0/src/pi_solver.rs:1242:17
   9: raptorq::pi_solver::IntermediateSymbolDecoder<T>::first_phase
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raptorq-1.8.0/src/pi_solver.rs:762:21
  10: raptorq::pi_solver::IntermediateSymbolDecoder<T>::execute
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raptorq-1.8.0/src/pi_solver.rs:1282:42
  11: raptorq::pi_solver::fused_inverse_mul_symbols
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raptorq-1.8.0/src/pi_solver.rs:1334:5
  12: raptorq::encoder::gen_intermediate_symbols
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raptorq-1.8.0/src/encoder.rs:378:16
  13: raptorq::encoder::SourceBlockEncodingPlan::generate
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raptorq-1.8.0/src/encoder.rs:185:24
  14: raptorq_playground::main
             at ./src/main.rs:46:16
  15: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread caused non-unwinding panic. aborting.

My Rust versions are

$ cargo --version
cargo 1.76.0 (c84b36747 2024-01-18)
$ rustc --version
rustc 1.76.0 (07dca489a 2024-02-04)

Minimal working example:

use raptorq::SourceBlockEncodingPlan;

fn main() {
    let _plan = SourceBlockEncodingPlan::generate(20);
}

Some other example values that cause the same error up to 200: 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200

When compiling with --release, the errors don't occur. Is this something that is expected? Any mitigations besides always using a release build?

cberner commented 6 months ago

Can you try the attached PR?

mlegner commented 6 months ago

Thanks a lot for the fix, @cberner. I can confirm that the error is gone with the PR. 💯