Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMD SHA-3 and memory usage optimizations #278

Merged
merged 66 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
f59d36f
sha3 for arm64
karthikbhargavan May 10, 2024
73a6bdb
hooked up simd arm64 to ml-kem
karthikbhargavan May 10, 2024
28ad265
disable nightly instructions
karthikbhargavan May 10, 2024
4c61c4f
eliminated some memmoves
karthikbhargavan May 12, 2024
35d60d1
removed some memmove in squeeze_three_blocks
karthikbhargavan May 12, 2024
96485c2
PRFxN for Arm64
karthikbhargavan May 12, 2024
857802d
sha3 instruc
karthikbhargavan May 13, 2024
bc97a58
rust sha3 made generic
karthikbhargavan May 13, 2024
e93717b
some bugfixes in portable
karthikbhargavan May 13, 2024
2db7fb1
some bugfixes in portable
karthikbhargavan May 13, 2024
3323b7a
Failing implementation of AVX2 rejection sampling.
xvzcf May 14, 2024
08b6022
wip avx2
karthikbhargavan May 14, 2024
bbe2c8e
avx2
karthikbhargavan May 14, 2024
1c7ff60
Merge branch 'dev' into karthik/sha3-arm64
franziskuskiefer May 14, 2024
3f739cb
make it compile; format
franziskuskiefer May 14, 2024
8488d32
fix avx2 sha3
franziskuskiefer May 14, 2024
6dc6471
fix build on avx2 using portable sha3 in mlkem
franziskuskiefer May 14, 2024
b5bdc54
fixed portable
karthikbhargavan May 14, 2024
4e25d05
fixed some feature flags
karthikbhargavan May 14, 2024
d11c3d5
Merge branch 'karthik/sha3-arm64' of github.com:cryspen/libcrux into …
franziskuskiefer May 14, 2024
1b66ac4
fix av2 build
franziskuskiefer May 14, 2024
cd5aa4d
fix avx2 and allow portable
franziskuskiefer May 14, 2024
7103d4a
simd256 hash functions
franziskuskiefer May 14, 2024
0376b12
drop other sha3 code
franziskuskiefer May 14, 2024
302736f
shak256 simd256
franziskuskiefer May 14, 2024
1389350
AVX2 implementation of Kyber rejection sampling.
xvzcf May 14, 2024
84b22fb
prfxn simd
karthikbhargavan May 14, 2024
d2350f3
Merge branch 'goutam/avx2-rej-sample' into karthik/sha3-arm64
karthikbhargavan May 14, 2024
e059f93
merged
karthikbhargavan May 14, 2024
acaa292
bugfix for arm
karthikbhargavan May 14, 2024
f156bf4
Updates to avx2 rejection sampling.
xvzcf May 14, 2024
78da7ec
load -> loadu
xvzcf May 14, 2024
ef3d4d7
mutable inputs to lessen memmoves
karthikbhargavan May 15, 2024
a885b69
more mutability
karthikbhargavan May 15, 2024
393efa2
made polynomial non-copy
karthikbhargavan May 15, 2024
ed7c67b
misc fixes
franziskuskiefer May 15, 2024
2079973
Break out implementations into their own modules.
xvzcf May 15, 2024
7846cd2
Sugar and desugar the SIMD256Vector struct only in lib.rs
xvzcf May 15, 2024
8cb3fd5
Wrapping avx2 intrinsics in safe wrappers.
xvzcf May 15, 2024
689a3ec
Feature detection and cleanup (Ml-KEM/SHA3) (#280)
franziskuskiefer May 16, 2024
f8790fc
Merge pull request #279 from cryspen/goutam/clean-document-kyber-avx2
franziskuskiefer May 16, 2024
d51781e
rustfmt
franziskuskiefer May 16, 2024
82ed694
fixup sha3 features
franziskuskiefer May 16, 2024
f39d840
check for target_arch in ml-kem
franziskuskiefer May 16, 2024
8fd44b7
added pointer annotations for neon
karthikbhargavan May 16, 2024
1065a33
bump libc
franziskuskiefer May 17, 2024
30696f8
check for arm on macos platform
franziskuskiefer May 17, 2024
4b1c8a2
check platform on ci
franziskuskiefer May 17, 2024
9841f6f
work around gh actions
franziskuskiefer May 17, 2024
3a3071d
update platforms
franziskuskiefer May 17, 2024
ad16ac6
asan
franziskuskiefer May 17, 2024
0c3d844
install nightly on ci
franziskuskiefer May 17, 2024
ef9de75
clean before test
franziskuskiefer May 17, 2024
5b39c28
disable linux asan for now
franziskuskiefer May 17, 2024
3d75761
more guards
franziskuskiefer May 17, 2024
b9fa21c
more ci
franziskuskiefer May 17, 2024
df5b91c
clean before test
franziskuskiefer May 17, 2024
0240aac
print cfg
franziskuskiefer May 17, 2024
9ee7d1d
check sysctl
franziskuskiefer May 17, 2024
6f7f943
More safe wrappers around avx2 intrinsics (#283).
xvzcf May 17, 2024
e2592de
disable macos release tests for now
franziskuskiefer May 17, 2024
cf87c09
Merge branch 'karthik/mutable-inputs' into franziskus/ml-kem-sha3-cross
franziskuskiefer May 17, 2024
a4c5d6c
Merge pull request #284 from cryspen/franziskus/ml-kem-sha3-cross
franziskuskiefer May 17, 2024
13de53d
disable hax extraction for now on ci
franziskuskiefer May 17, 2024
c0ebb12
rustfmt
franziskuskiefer May 17, 2024
4514dd4
Merge branch 'dev' into karthik/mutable-inputs
franziskuskiefer May 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/hax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
- name: 🏃 Extract & Verify ML-KEM crate (lax)
run: |
cd libcrux-ml-kem
./hax.py extract
# ./hax.py extract
# env FSTAR_HOME=${{ github.workspace }}/fstar \
# HACL_HOME=${{ github.workspace }}/hacl-star \
# HAX_HOME=${{ github.workspace }}/hax \
Expand Down
134 changes: 73 additions & 61 deletions .github/workflows/mlkem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: ["main", "dev"]
pull_request:
branches: ["main", "dev"]
branches: ["main", "dev", "*"]
workflow_dispatch:
merge_group:

Expand All @@ -22,15 +22,15 @@ jobs:
matrix:
bits: [32, 64]
os:
- macos-latest
- macos-13 # Intel mac
- macos-latest # macos-14 m1
- ubuntu-latest
- windows-latest
exclude:
- bits: 32
os: "macos-latest"
# FIXME: Linking isn't working here yet for hacl #42
- bits: 32
os: "windows-latest"
os: "macos-13"

runs-on: ${{ matrix.os }}
defaults:
Expand All @@ -44,23 +44,21 @@ jobs:
- run: echo "RUST_TARGET_FLAG=" > $GITHUB_ENV
if: ${{ matrix.bits == 64 }}

- name: ⚙️ Setup Ubuntu x86
- name: 🛠️ Setup Rust Nightly
run: rustup toolchain install nightly

- name: 🛠️ Setup Ubuntu x86
if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }}
run: |
rustup target add i686-unknown-linux-gnu
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib

- name: ️ Setup Ubuntu x64
- name: 🛠️ Setup Ubuntu x64
if: ${{ matrix.bits == 64 && matrix.os == 'ubuntu-latest' }}
run: |
rustup target add aarch64-unknown-linux-gnu

- name: ⚙️ Setup macOS
if: ${{ matrix.os == 'macos-latest' }}
run: |
rustup target add aarch64-apple-darwin

# Set up 32 bit systems

- name: 🛠️ Config Windows x86
Expand All @@ -72,60 +70,90 @@ jobs:
echo "RUST_TARGET_FLAG=--target=i686-unknown-linux-gnu" > $GITHUB_ENV
if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }}

# Set up windows

- name: ⚙️ Setup Windows x86
if: ${{ matrix.bits == 32 && matrix.os == 'windows-latest' }}
shell: pwsh
run: |
echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
vcpkg install openssl:x86-windows-static-md

- name: ⚙️ Setup Windows x64
if: ${{ matrix.bits == 64 && matrix.os == 'windows-latest' }}
shell: pwsh
run: |
echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
vcpkg install openssl:x64-windows-static-md

# Build ...

- name: 🔨 Build
run: cargo build --verbose $RUST_TARGET_FLAG
run: |
rustc --print=cfg
cargo build --verbose $RUST_TARGET_FLAG

- name: 🔨 Build Release
run: cargo build --verbose --release $RUST_TARGET_FLAG

# Cross compilation

- name: 🔨 Build aarch64 macOS
- name: 🏃🏻 Asan MacOS
if: ${{ matrix.os == 'macos-latest' }}
run: cargo build --verbose --target aarch64-apple-darwin
run: RUSTDOCFLAGS=-Zsanitizer=address RUSTFLAGS=-Zsanitizer=address cargo +nightly test --release --target aarch64-apple-darwin

# We get false positives here.
# TODO: Figure out what is going on here
# - name: 🏃🏻 Asan Linux
# if: ${{ matrix.bits == 64 && matrix.os == 'ubuntu-latest' }}
# run: RUSTDOCFLAGS=-Zsanitizer=address RUSTFLAGS=-Zsanitizer=address cargo +nightly test --release --target x86_64-unknown-linux-gnu

# Test SHA3
- name: 🏃🏻‍♀️ SHA3 Test
working-directory: libcrux-sha3
run: |
cargo clean
cargo test --verbose $RUST_TARGET_FLAG

- name: 🏃🏻‍♀️ SHA3 Test Release
working-directory: libcrux-sha3
run: |
cargo clean
cargo test --release --verbose $RUST_TARGET_FLAG

- name: 🏃🏻‍♀️ SHA3 Test Portable
working-directory: libcrux-sha3
run: |
cargo clean
LIBCRUX_DISABLE_SIMD128=1 LIBCRUX_DISABLE_SIMD256=1 cargo test --verbose $RUST_TARGET_FLAG

- name: 🏃🏻‍♀️ SHA3 Test Portable Release
working-directory: libcrux-sha3
run: |
cargo clean
LIBCRUX_DISABLE_SIMD128=1 LIBCRUX_DISABLE_SIMD256=1 cargo test --verbose --release $RUST_TARGET_FLAG

# Test ...

- name: 🏃🏻‍♀️ Test
run: cargo test --verbose $RUST_TARGET_FLAG
run: |
cargo clean
cargo test --verbose $RUST_TARGET_FLAG

- name: 🏃🏻‍♀️ Test Release
run: cargo test --verbose --release $RUST_TARGET_FLAG
if: ${{ matrix.os != 'macos-latest' }}
run: |
cargo clean
cargo test --verbose --release $RUST_TARGET_FLAG

- name: 🏃🏻‍♀️ Test Portable
run: |
cargo clean
LIBCRUX_DISABLE_SIMD128=1 LIBCRUX_DISABLE_SIMD256=1 cargo test --verbose $RUST_TARGET_FLAG

- name: 🏃🏻‍♀️ Test Portable Release
run: |
cargo clean
LIBCRUX_DISABLE_SIMD128=1 LIBCRUX_DISABLE_SIMD256=1 cargo test --verbose --release $RUST_TARGET_FLAG

benchmarks:
strategy:
fail-fast: true
matrix:
bits: [32, 64]
os:
- macos-13
- macos-latest
- ubuntu-latest
- windows-latest
exclude:
# There's no such thing as 32-bit macOS
- bits: 32
os: "macos-latest"
# FIXME: Linking isn't working here yet for hacl #42
- bits: 32
os: "windows-latest"
os: "macos-13"

runs-on: ${{ matrix.os }}
defaults:
Expand All @@ -139,19 +167,19 @@ jobs:
- run: echo "RUST_TARGET_FLAG=" > $GITHUB_ENV
if: ${{ matrix.bits == 64 }}

- name: ️ Setup Ubuntu x86
- name: 🛠️ Setup Ubuntu x86
if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }}
run: |
rustup target add i686-unknown-linux-gnu
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib

- name: ️ Setup Ubuntu x64
- name: 🛠️ Setup Ubuntu x64
if: ${{ matrix.bits == 64 && matrix.os == 'ubuntu-latest' }}
run: |
rustup target add aarch64-unknown-linux-gnu

- name: ️ Setup macOS
- name: 🛠️ Setup macOS
if: ${{ matrix.os == 'macos-latest' }}
run: |
rustup target add aarch64-apple-darwin
Expand All @@ -167,28 +195,12 @@ jobs:
echo "RUST_TARGET_FLAG=--target=i686-unknown-linux-gnu" > $GITHUB_ENV
if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }}

# Set up windows

- name: ⚙️ Setup Windows x86
if: ${{ matrix.bits == 32 && matrix.os == 'windows-latest' }}
shell: pwsh
run: |
echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
vcpkg install openssl:x86-windows-static-md

- name: ⚙️ Setup Windows x64
if: ${{ matrix.bits == 64 && matrix.os == 'windows-latest' }}
shell: pwsh
run: |
echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
vcpkg install openssl:x64-windows-static-md

# Benchmarks ...

- name: 🏃🏻‍♀️ Benchmarks Windows
if: ${{ matrix.os == 'windows-latest' }}
- name: 🏃🏻‍♀️ Benchmarks
run: cargo bench --verbose $RUST_TARGET_FLAG

- name: 🏃🏻‍♀️ Benchmarks Clang
if: ${{ matrix.os != 'windows-latest' }}
run: CC=clang cargo bench --verbose $RUST_TARGET_FLAG

- name: 🏃🏻‍♀️ Benchmarks Portable
run: |
cargo clean
LIBCRUX_DISABLE_SIMD128=1 LIBCRUX_DISABLE_SIMD256=1 cargo bench --verbose $RUST_TARGET_FLAG
74 changes: 74 additions & 0 deletions .github/workflows/platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Platform

on:
push:
branches: ["main", "dev"]
pull_request:
branches: ["main", "dev", "*"]
workflow_dispatch:
merge_group:

env:
CARGO_TERM_COLOR: always

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
platform:
strategy:
fail-fast: false
matrix:
bits: [32, 64]
os:
- macos-13 # Intel mac
- macos-latest # macos-14 m1
- ubuntu-latest
- windows-latest
exclude:
- bits: 32
os: "macos-latest"
- bits: 32
os: "macos-13"

runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
working-directory: sys/platform

steps:
- uses: actions/checkout@v4

- name: 🔨 Build
run: cargo build --verbose

- name: 🏃🏻‍♀️ Test
run: cargo test --verbose -- --nocapture

- name: 🏃🏻‍♀️ Test Release
run: cargo test --verbose --release -- --nocapture

- name: 🛠️ Setup Linux x86
if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }}
run: |
rustup target add i686-unknown-linux-gnu
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib

- name: 🏃🏻‍♀️ Test Linux x86
if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }}
run: cargo test --verbose --target i686-unknown-linux-gnu -- --nocapture

- name: 🏃🏻‍♀️ Test Release Linux x86
if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }}
run: cargo test --verbose --release --target i686-unknown-linux-gnu -- --nocapture

- name: 🏃🏻‍♀️ Test Windows x86
if: ${{ matrix.bits == 32 && matrix.os == 'windows-latest' }}
run: cargo test --verbose --target i686-pc-windows-msvc -- --nocapture

- name: 🏃🏻‍♀️ Test Release Windows x86
if: ${{ matrix.bits == 32 && matrix.os == 'windows-latest' }}
run: cargo test --verbose --release --target i686-pc-windows-msvc -- --nocapture
6 changes: 4 additions & 2 deletions libcrux-ml-kem/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ fn main() {
// We enable simd128 on all aarch64 builds.
println!("cargo:rustc-cfg=feature=\"simd128\"");
}
if (target_arch == "x86" || target_arch == "x86_64") && !disable_simd256 {
// We enable simd256 on all x86 and x86_64 builds.
if target_arch == "x86_64" && !disable_simd256 {
// We enable simd256 on all x86_64 builds.
// Note that this doesn't mean the required CPU features are available.
// But the compiler will support them and the runtime checks ensure that
// it's only used when available.
//
// We don't enable this on x86 because it seems to generate invalid code.
println!("cargo:rustc-cfg=feature=\"simd256\"");
}
}
3 changes: 3 additions & 0 deletions libcrux-ml-kem/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ pub(crate) const CPA_PKE_KEY_GENERATION_SEED_SIZE: usize = 32;

// XXX: Eurydice can't handle this.
// digest_size(Algorithm::Sha3_256);
/// SHA3 256 digest size
pub(crate) const H_DIGEST_SIZE: usize = 32;
/// SHA3 512 digest size
pub(crate) const G_DIGEST_SIZE: usize = 64;
Loading
Loading