rust-lang / rust-lang/portable-simd
Transpose methods?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 108
- Avg merge
- 22h 53m
- Merged PRs (30d)
- 3
Description
One thing I've been particularly interested in is a (relatively) simple SIMD matrix implementation. There are loads of implementations out there for stuff like matrix multiplication, and I know that this is a gigantic rabbit hole, but I feel like there are some common operations that stand out from the crowd as having one "correct" solution, which are pretty easy to mess up.
For example, looking at the matrix inversion example, there's a rather cryptic implementation of a 4x4 matrix transpose here:
const SHUFFLE01: [Which; 4] = [First(0), First(1), Second(0), Second(1)];
const SHUFFLE02: [Which; 4] = [First(0), First(2), Second(0), Second(2)];
const SHUFFLE13: [Which; 4] = [First(1), First(3), Second(1), Second(3)];
const SHUFFLE23: [Which; 4] = [First(2), First(3), Second(2), Second(3)];
let tmp = simd_swizzle!(m_0, m_1, SHUFFLE01);
let row1 = simd_swizzle!(m_2, m_3, SHUFFLE01);
let row0 = simd_swizzle!(tmp, row1, SHUFFLE02);
let row1 = simd_swizzle!(row1, tmp, SHUFFLE13);
let tmp = simd_swizzle!(m_0, m_1, SHUFFLE23);
let row3 = simd_swizzle!(m_2, m_3, SHUFFLE23);
let row2 = simd_swizzle!(tmp, row3, SHUFFLE02);
let row3 = simd_swizzle!(row3, tmp, SHUFFLE13);
It feels like it would be helpful to offer some easy methods that people can use for "transposing" a set of SIMD vectors which represent a matrix, since doing so is required for all sorts of operations. Essentially, given n SIMD m-vectors, return m SIMD n-vectors, assuming that n and m are both valid lane sizes. Probably the most necessary combinations are 2x2 and 4x4, but assuming that we write the code right, we should be able to make this work with any combination of valid lane sizes.
Maybe it might even be convenient to have a dedicated SIMD type that represents such a matrix (with valid lane sizes on both dimensions), although that may be more than you'd want for the core SIMD module.
I could also be overgeneralising something here that would be better suited for a library, but since we're already in untreaded territory (I don't know of anything similar to std::simd in any other language), it's worth bringing up.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with crates/core_simd/examples/matrix_inversion.rs and inspect the 4x4 transpose implementation using simd_swizzle!. Compare the proposed 2x2, 4x4, and general valid-lane-size combinations, then determine whether the project wants transpose methods, a matrix type, or a separate library; done requires an agreed scope and API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100