strided_perm/lib.rs
1//! Cache-efficient tensor permutation / transpose.
2//!
3//! This crate provides optimized copy and permutation operations for strided
4//! multidimensional arrays. It is designed as a single-responsibility crate
5//! sitting between `strided-view` (data structures) and `strided-kernel`
6//! (general map/reduce/broadcast operations).
7//!
8//! # Dependency graph
9//!
10//! ```text
11//! strided-view -> strided-perm -> strided-kernel
12//! ```
13//!
14//! # Threading
15//!
16//! Every copy takes a [`strided_exec::Exec`] placement token as its last
17//! parameter and splits the permutation within that budget. A copy of at most
18//! [`MINTHREADLENGTH`] elements runs on the calling thread whatever the budget,
19//! because a fan-out costs more than the copy. The crate never reaches a global
20//! pool; pass `Exec::serial()` for a copy on the calling thread.
21
22#[cfg(test)]
23mod block;
24mod copy;
25mod fuse;
26mod hptt;
27#[cfg(test)]
28#[allow(dead_code)]
29mod kernel;
30#[cfg(test)]
31mod order;
32
33// Re-export primary API
34pub use copy::{copy_into, copy_into_col_major, copy_into_uninit};
35pub use fuse::{plan_bilateral_fusion, BilateralFusionPlan, FusionPlanError};
36
37/// Minimum number of elements for a copy to fan out.
38///
39/// The single threshold of the strided stack: `copy_into*` narrow the token to
40/// one task at or below it, and `strided-basic` re-exports this constant for
41/// its own entries. Matches Julia's `MINTHREADLENGTH = 1 << 15`; see
42/// `docs/design/erased-execution-policy.md` for the decision record.
43pub const MINTHREADLENGTH: usize = 1 << 15;
44
45// Constants
46pub const BLOCK_MEMORY_SIZE: usize = 32 * 1024;
47pub const CACHE_LINE_SIZE: usize = 64;