Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
steps:
- name: Install OpenCL
run: |
sudo add-apt-repository ppa:intel-opencl/intel-opencl
sudo apt-get update
sudo apt-get install ocl-icd-opencl-dev
- uses: actions/checkout@aabbfeb2ce60b5bd82389903509092c4648a9713
Expand All @@ -22,7 +21,6 @@ jobs:
steps:
- name: Install OpenCL
run: |
sudo add-apt-repository ppa:intel-opencl/intel-opencl
sudo apt-get update
sudo apt-get install ocl-icd-opencl-dev
- uses: actions/checkout@aabbfeb2ce60b5bd82389903509092c4648a9713
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/nano-work-simd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# CI for the nano-work-simd crate: build, test and lint on x86-64 (AVX2 and,
# where the runner has it, AVX-512) and on Apple Silicon (NEON). The macOS job
# is the CI job that compiles and executes the NEON kernel.
name: nano-work-simd

on:
push:
paths:
- "nano-work-simd/**"
- "src/**"
- "tests/**"
- "Cargo.toml"
- "Cargo.lock"
- ".github/workflows/nano-work-simd.yml"
pull_request:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1

jobs:
test:
name: test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-14]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: CPU features
shell: bash
run: |
uname -m
if [ "$(uname -s)" = "Linux" ]; then grep -m1 -o 'avx512f\|avx2' /proc/cpuinfo | sort -u; fi
if [ "$(uname -s)" = "Darwin" ]; then sysctl -n machdep.cpu.brand_string; fi
- name: Report kernels
run: cargo test --release -p nano-work-simd --lib report_kernels -- --nocapture
- name: Test
run: cargo test --release -p nano-work-simd
- name: Clippy
run: cargo clippy -p nano-work-simd --all-targets -- -D warnings
10 changes: 8 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ ocl = "0.19.4"
serde_json = "1.0.87"
hex = "0.4.3"
rand = "0.8.5"
blake2 = "0.10.4"
digest = "0.10.5"
byteorder = "1.4.3"
nano-work-simd = { path = "nano-work-simd" }
parking_lot = "0.12.1"
chrono = "0.4.22"
tokio = { version = "1.21.2", features = ["rt-multi-thread", "macros"] }
rand_xorshift = "0.3.0"

[workspace]
members = ["nano-work-simd"]
default-members = [".", "nano-work-simd"]
20 changes: 20 additions & 0 deletions nano-work-simd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "nano-work-simd"
version = "0.1.0"
edition = "2021"
rust-version = "1.89"
license = "BSD-2-Clause"
description = "Fast CPU proof-of-work generator for the Nano cryptocurrency (unrolled Blake2b-8 with AVX-512 / AVX2 / NEON / scalar kernels)"
repository = "https://github.com/nanocurrency/nano-work-server"
keywords = ["nano", "blake2b", "proof-of-work", "simd"]
categories = ["cryptography", "algorithms"]

[lib]
name = "nano_work_simd"
path = "src/lib.rs"

[dependencies]
# none: the crate is std-only

[dev-dependencies]
blake2 = "0.10"
29 changes: 29 additions & 0 deletions nano-work-simd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# nano-work-simd

The CPU work back end of nano-work-server: Nano proof-of-work
(`u64::from_le_bytes(blake2b_8(work_le || hash)) >= threshold`) with a Blake2b
compression specialised for the fixed 40-byte message, run on 8 (AVX-512),
4 (AVX2), 2 (NEON) or 1 (scalar) nonces per instruction stream. The kernel is
picked at runtime from the CPU's feature flags (`Kernel::best()`), or forced by
the server's `--cpu-kernel` option.

Public API: `generate`, `generate_with`, `validate`, `difficulty`,
`hash_rate_benchmark`, `expected_hashes`, `resolve_hit`, `Kernel`
(`search`, `difficulties`, `best`, `available`, `from_name`), `Precomputed`,
and the `SEND_THRESHOLD` / `RECEIVE_THRESHOLD` / `LEGACY_THRESHOLD` / `BATCH`
constants. The server uses `Kernel::search` over `BATCH`-sized nonce ranges,
`resolve_hit` to pick and re-verify the winning lane, and `validate` for
`work_validate`.

Tests (`cargo test --release -p nano-work-simd` from the server root) cross-check
every available kernel against the `blake2` crate on 10 000 random (hash, nonce)
pairs, check nonce wrap-around at `u64::MAX`, check that `search` finds exactly
the hit set of a brute-force scan, that generated work validates for every
kernel and thread count, and the documented Nano example. `Precomputed`'s words
and the lane-level kernels are crate-private; `unsafe` is confined to the
`#[target_feature]` entry points in `src/x86.rs` / `src/neon.rs`.

This is a vendored copy of the standalone `nano-work-simd` crate, which also
carries a CLI (`info`, `generate`, `validate`, `bench`, `timing`) and a
`hashlib`-based Python cross-check. No dependencies; `blake2` is a
dev-dependency for the tests only. MSRV 1.89. License: BSD-2-Clause.
Loading