From 82054c12bd2320c04198d6d99844616d8a1ad5d9 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Fri, 15 Mar 2024 19:15:28 +0000 Subject: [PATCH 1/2] Add benchmark for vector-matrix product MatMul operations with with shapes like this come up frequently in transformer decoders. This runs at about 1/4 the speed of Accelerate on my Intel i5-1038NG7. [1] https://gist.github.com/robertknight/3e7bf748b5435657ca671930c30e4ec7 --- src/gemm.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gemm.rs b/src/gemm.rs index 3a6d1a85..43de552c 100644 --- a/src/gemm.rs +++ b/src/gemm.rs @@ -1460,6 +1460,12 @@ mod tests { n: 128, k: 512, }, + // Vector-matrix. This is common in transformer decoders for example. + Case { + m: 1, + n: 4096, + k: 512, + }, ]; println!("Testing kernel {}", GemmExecutor::new().kernel_name()); @@ -1473,6 +1479,10 @@ mod tests { let target_ops: u64 = 512 * 512 * 512 * 1000; let iters = target_ops / (m * n * k) as u64; + // Cap the number of iterations, for cases where the equal-efficiency + // assumption is untrue. + let iters = iters.min(1000); + let mut rng = XorShiftRng::new(1234); let mut result = Tensor::zeros(&[m, n]); let a = Tensor::rand(&[m, k], &mut rng); From fb5db6adf25bcafceb8b5d77d73e7ec074ff14b7 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Mon, 18 Mar 2024 19:42:45 +0000 Subject: [PATCH 2/2] Cache everything in ~/.cargo This may fix an issue where `cargo install wasm-bindgen-cli` fails due to a conflicting binary existing in ~/.cargo/bin but other cargo files which track the crate <-> binary association not being present (because they were not cached). --- .github/workflows/ci.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c52785df..d643f2c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,17 +14,14 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Setup rust + - name: Install Rust wasm toolchain run: rustup target add wasm32-unknown-unknown if: ${{ matrix.os == 'ubuntu-latest' }} - name: Cache uses: actions/cache@v3 with: path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ + ~/.cargo/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Install wasm-bindgen