simd-ml-kernels 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simd_ml_kernels-0.3.0/.github/workflows/bench.yml +44 -0
- simd_ml_kernels-0.3.0/.github/workflows/build-and-test.yml +160 -0
- simd_ml_kernels-0.3.0/.github/workflows/ci.yml +263 -0
- simd_ml_kernels-0.3.0/.github/workflows/guardrail.yml +108 -0
- simd_ml_kernels-0.3.0/.github/workflows/publish.yml +59 -0
- simd_ml_kernels-0.3.0/.github/workflows/wheels.yml +61 -0
- simd_ml_kernels-0.3.0/.gitignore +92 -0
- simd_ml_kernels-0.3.0/AGENTS.md +158 -0
- simd_ml_kernels-0.3.0/CHANGELOG.md +242 -0
- simd_ml_kernels-0.3.0/CITATION.cff +35 -0
- simd_ml_kernels-0.3.0/CLAUDE.md +1 -0
- simd_ml_kernels-0.3.0/CMakeLists.txt +384 -0
- simd_ml_kernels-0.3.0/CONTRIBUTING.md +161 -0
- simd_ml_kernels-0.3.0/Dockerfile +100 -0
- simd_ml_kernels-0.3.0/LICENSE +224 -0
- simd_ml_kernels-0.3.0/PKG-INFO +685 -0
- simd_ml_kernels-0.3.0/README.md +437 -0
- simd_ml_kernels-0.3.0/benchmarks/make_tables.py +330 -0
- simd_ml_kernels-0.3.0/benchmarks/results/README.md +30 -0
- simd_ml_kernels-0.3.0/benchmarks/results/cloud-xeon-emr-2vcpu_2026-10-18_255f27755c31.json +2040 -0
- simd_ml_kernels-0.3.0/benchmarks/results/cloud-xeon-emr-2vcpu_2026-10-18_9029f1566ddb.json +2038 -0
- simd_ml_kernels-0.3.0/benchmarks/results/lnl-226v-wsl_2026-10-17_7a698867be89.json +590 -0
- simd_ml_kernels-0.3.0/benchmarks/results/lnl-226v-wsl_2026-10-18_045918e51839.json +1461 -0
- simd_ml_kernels-0.3.0/benchmarks/results/lnl-226v-wsl_2026-10-18_19aeaf83cd36.json +2038 -0
- simd_ml_kernels-0.3.0/benchmarks/results/lnl-226v-wsl_2026-10-18_44194476d395.json +596 -0
- simd_ml_kernels-0.3.0/benchmarks/results/lnl-226v-wsl_2026-10-18_b193633ecec1.json +596 -0
- simd_ml_kernels-0.3.0/benchmarks/results/lnl-226v-wsl_2026-10-18_ecc219baa1f2.json +2743 -0
- simd_ml_kernels-0.3.0/cmake/simd_ml_kernels-config.cmake.in +26 -0
- simd_ml_kernels-0.3.0/docs/BENCHMARKS.md +435 -0
- simd_ml_kernels-0.3.0/docs/DESIGN.md +650 -0
- simd_ml_kernels-0.3.0/docs/README.md +12 -0
- simd_ml_kernels-0.3.0/docs/ROADMAP.md +242 -0
- simd_ml_kernels-0.3.0/docs/api/python_api.md +353 -0
- simd_ml_kernels-0.3.0/docs/security.md +132 -0
- simd_ml_kernels-0.3.0/docs/setup.md +154 -0
- simd_ml_kernels-0.3.0/examples/bench_to_json.py +50 -0
- simd_ml_kernels-0.3.0/examples/linear_trans_b.py +50 -0
- simd_ml_kernels-0.3.0/examples/mlp_block.py +58 -0
- simd_ml_kernels-0.3.0/pyproject.toml +88 -0
- simd_ml_kernels-0.3.0/python/simd_kernels/__init__.py +20 -0
- simd_ml_kernels-0.3.0/python/simd_ml_kernels/__init__.py +64 -0
- simd_ml_kernels-0.3.0/python/simd_ml_kernels/__main__.py +5 -0
- simd_ml_kernels-0.3.0/python/simd_ml_kernels/_cli.py +763 -0
- simd_ml_kernels-0.3.0/python/simd_ml_kernels/_core.pyi +374 -0
- simd_ml_kernels-0.3.0/python/simd_ml_kernels/py.typed +0 -0
- simd_ml_kernels-0.3.0/src/bench_stat.cpp +390 -0
- simd_ml_kernels-0.3.0/src/bindings/pybind_entry.cpp +1355 -0
- simd_ml_kernels-0.3.0/src/dispatch/cpuid.hpp +87 -0
- simd_ml_kernels-0.3.0/src/dispatch/dispatch.cpp +381 -0
- simd_ml_kernels-0.3.0/src/dispatch/kernels.hpp +106 -0
- simd_ml_kernels-0.3.0/src/kernels/activations/activations.hpp +39 -0
- simd_ml_kernels-0.3.0/src/kernels/activations/layer_norm_avx2.cpp +160 -0
- simd_ml_kernels-0.3.0/src/kernels/activations/relu_avx2.cpp +38 -0
- simd_ml_kernels-0.3.0/src/kernels/activations/silu_avx2.cpp +52 -0
- simd_ml_kernels-0.3.0/src/kernels/activations/softmax_avx2.cpp +195 -0
- simd_ml_kernels-0.3.0/src/kernels/cache_alloc.hpp +160 -0
- simd_ml_kernels-0.3.0/src/kernels/gemm/avx2_gemm_packed.cpp +821 -0
- simd_ml_kernels-0.3.0/src/kernels/gemm/avx2_gemm_packed.hpp +131 -0
- simd_ml_kernels-0.3.0/src/kernels/gemm/avx512_gemm_packed.cpp +508 -0
- simd_ml_kernels-0.3.0/src/kernels/gemm/avx512bf16_gemm.cpp +229 -0
- simd_ml_kernels-0.3.0/src/kernels/gemm/avx512vnni_gemm.cpp +189 -0
- simd_ml_kernels-0.3.0/src/kernels/gemm/avxvnni_gemm.cpp +260 -0
- simd_ml_kernels-0.3.0/src/kernels/gemm/bf16_gemm.hpp +63 -0
- simd_ml_kernels-0.3.0/src/kernels/gemm/f16_gemm.hpp +47 -0
- simd_ml_kernels-0.3.0/src/kernels/gemm/int8_gemm.hpp +69 -0
- simd_ml_kernels-0.3.0/src/kernels/gemm/int8_pack.hpp +84 -0
- simd_ml_kernels-0.3.0/src/kernels/gemm/naive_gemm.hpp +50 -0
- simd_ml_kernels-0.3.0/src/kernels/intrinsic_gelu.cpp +163 -0
- simd_ml_kernels-0.3.0/src/kernels/intrinsic_gelu.hpp +27 -0
- simd_ml_kernels-0.3.0/src/kernels/kernels_avx2.cpp +32 -0
- simd_ml_kernels-0.3.0/src/kernels/kernels_avx512.cpp +38 -0
- simd_ml_kernels-0.3.0/src/kernels/scalar_kernels.cpp +267 -0
- simd_ml_kernels-0.3.0/src/kernels/simd_math.hpp +183 -0
- simd_ml_kernels-0.3.0/src/main_bench.cpp +538 -0
- simd_ml_kernels-0.3.0/tests/CMakeLists.txt +62 -0
- simd_ml_kernels-0.3.0/tests/check_isa_units.py +112 -0
- simd_ml_kernels-0.3.0/tests/conftest.py +59 -0
- simd_ml_kernels-0.3.0/tests/kernel_tables.hpp +34 -0
- simd_ml_kernels-0.3.0/tests/stubtest_allowlist.txt +5 -0
- simd_ml_kernels-0.3.0/tests/test_activations.cpp +294 -0
- simd_ml_kernels-0.3.0/tests/test_alignment.cpp +66 -0
- simd_ml_kernels-0.3.0/tests/test_bindings_edge_cases.py +647 -0
- simd_ml_kernels-0.3.0/tests/test_cli.py +47 -0
- simd_ml_kernels-0.3.0/tests/test_dispatch.cpp +66 -0
- simd_ml_kernels-0.3.0/tests/test_fp_env.py +50 -0
- simd_ml_kernels-0.3.0/tests/test_gelu.cpp +275 -0
- simd_ml_kernels-0.3.0/tests/test_gemm_int8.cpp +186 -0
- simd_ml_kernels-0.3.0/tests/test_gemm_lowp.cpp +387 -0
- simd_ml_kernels-0.3.0/tests/test_gemm_packed.cpp +262 -0
- simd_ml_kernels-0.3.0/tests/test_precision.py +738 -0
- simd_ml_kernels-0.3.0/tests/test_runner.cpp +32 -0
- simd_ml_kernels-0.3.0/tests/test_stubs.py +77 -0
- simd_ml_kernels-0.3.0/tests/test_threads.cpp +200 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: Weekly Benchmark
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
schedule:
|
|
5
|
+
- cron: '0 4 * * 0' # Every Sunday at 4 AM UTC
|
|
6
|
+
workflow_dispatch: # Also runnable manually
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
bench:
|
|
10
|
+
name: Statistical Benchmark
|
|
11
|
+
runs-on: ubuntu-22.04
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Install dependencies
|
|
16
|
+
run: |
|
|
17
|
+
sudo apt-get update -qq
|
|
18
|
+
# Pin g++-12 to match the rest of CI; avoid defaulting to GCC-11
|
|
19
|
+
sudo apt-get install -y cmake ninja-build g++-12 \
|
|
20
|
+
libopenblas-dev python3-dev python3-pip
|
|
21
|
+
# Use pip pybind11[global] (>=2.11) rather than libpybind11-dev
|
|
22
|
+
# (which pins an older system version and can conflict)
|
|
23
|
+
pip3 install "pybind11[global]>=2.11" numpy scikit-build-core
|
|
24
|
+
|
|
25
|
+
- name: Install the package
|
|
26
|
+
run: pip3 install . --no-build-isolation
|
|
27
|
+
|
|
28
|
+
- name: "Run benchmark (shared runner: for trend inspection only, never for claims)"
|
|
29
|
+
env:
|
|
30
|
+
OPENBLAS_NUM_THREADS: "1"
|
|
31
|
+
OMP_NUM_THREADS: "1"
|
|
32
|
+
MKL_NUM_THREADS: "1"
|
|
33
|
+
run: |
|
|
34
|
+
python3 -m simd_ml_kernels selftest
|
|
35
|
+
taskset -c 0 python3 -m simd_ml_kernels bench \
|
|
36
|
+
--json ci-bench.json --label github-actions --core "CI runner vCPU 0" \
|
|
37
|
+
--note "shared GitHub Actions runner, no frequency control"
|
|
38
|
+
|
|
39
|
+
- name: Upload results artifact
|
|
40
|
+
uses: actions/upload-artifact@v4
|
|
41
|
+
with:
|
|
42
|
+
name: bench-results-${{ github.sha }}
|
|
43
|
+
path: ci-bench.json
|
|
44
|
+
retention-days: 90
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
name: Build and Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main, master]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
# ─── Primary: Linux GCC, AVX2, with OpenBLAS baseline ──────────────────────
|
|
11
|
+
build-linux-gcc:
|
|
12
|
+
name: Linux / GCC-12 / AVX2 + OpenBLAS
|
|
13
|
+
runs-on: ubuntu-22.04
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Install system dependencies
|
|
18
|
+
run: |
|
|
19
|
+
sudo apt-get update -qq
|
|
20
|
+
sudo apt-get install -y cmake ninja-build g++-12 \
|
|
21
|
+
python3-dev python3-pip libopenblas-dev
|
|
22
|
+
pip3 install scikit-build-core pybind11[global] numpy pytest scipy ml_dtypes
|
|
23
|
+
|
|
24
|
+
- name: Clean stale build directory
|
|
25
|
+
run: rm -rf build
|
|
26
|
+
|
|
27
|
+
- name: Configure (Release, OpenBLAS enabled)
|
|
28
|
+
env:
|
|
29
|
+
CC: gcc-12
|
|
30
|
+
CXX: g++-12
|
|
31
|
+
run: |
|
|
32
|
+
cmake -S . -B build -G Ninja \
|
|
33
|
+
-DCMAKE_BUILD_TYPE=Release \
|
|
34
|
+
-DCMAKE_C_COMPILER=gcc-12 \
|
|
35
|
+
-DCMAKE_CXX_COMPILER=g++-12 \
|
|
36
|
+
-DBENCH_OPENBLAS=ON
|
|
37
|
+
|
|
38
|
+
- name: Build all targets
|
|
39
|
+
run: cmake --build build --parallel
|
|
40
|
+
|
|
41
|
+
- name: Run C++ tests
|
|
42
|
+
run: ctest --test-dir build --output-on-failure --parallel 4
|
|
43
|
+
|
|
44
|
+
- name: Verify Python extension loads
|
|
45
|
+
run: |
|
|
46
|
+
pip3 install -e . --no-build-isolation -q
|
|
47
|
+
python3 -c "
|
|
48
|
+
import simd_ml_kernels, numpy as np
|
|
49
|
+
A = np.random.randn(32, 32).astype(np.float32)
|
|
50
|
+
C = simd_ml_kernels.sgemm(A, np.ascontiguousarray(A.T))
|
|
51
|
+
x = np.random.randn(1024).astype(np.float32)
|
|
52
|
+
y = simd_ml_kernels.gelu(x)
|
|
53
|
+
y = simd_ml_kernels.layer_norm(x)
|
|
54
|
+
print('Python extension smoke test: PASS')
|
|
55
|
+
print(simd_ml_kernels.build_info())
|
|
56
|
+
"
|
|
57
|
+
|
|
58
|
+
- name: Self-test (every kernel vs float64; exits 1 on failure)
|
|
59
|
+
run: python3 -m simd_ml_kernels selftest
|
|
60
|
+
|
|
61
|
+
- name: Run Python tests
|
|
62
|
+
run: pytest tests -v --tb=short
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# ─── OpenMP multi-threaded GEMM ─────────────────────────────────────────────
|
|
66
|
+
build-openmp:
|
|
67
|
+
name: Linux / GCC-12 / OpenMP GEMM
|
|
68
|
+
runs-on: ubuntu-22.04
|
|
69
|
+
steps:
|
|
70
|
+
- uses: actions/checkout@v4
|
|
71
|
+
|
|
72
|
+
- name: Install dependencies
|
|
73
|
+
run: |
|
|
74
|
+
sudo apt-get update -qq
|
|
75
|
+
sudo apt-get install -y cmake ninja-build g++-12 \
|
|
76
|
+
python3-dev python3-pip
|
|
77
|
+
pip3 install "pybind11[global]>=2.11" numpy pytest scipy
|
|
78
|
+
|
|
79
|
+
- name: Clean stale build directory
|
|
80
|
+
run: rm -rf build_omp
|
|
81
|
+
|
|
82
|
+
- name: Configure (OpenMP enabled)
|
|
83
|
+
run: |
|
|
84
|
+
cmake -S . -B build_omp -G Ninja \
|
|
85
|
+
-DCMAKE_BUILD_TYPE=Release \
|
|
86
|
+
-DCMAKE_C_COMPILER=gcc-12 \
|
|
87
|
+
-DCMAKE_CXX_COMPILER=g++-12 \
|
|
88
|
+
-DSIMD_ML_OPENMP=ON
|
|
89
|
+
|
|
90
|
+
- name: Build
|
|
91
|
+
run: cmake --build build_omp --parallel
|
|
92
|
+
|
|
93
|
+
- name: C++ tests (with OpenMP)
|
|
94
|
+
run: ctest --test-dir build_omp --output-on-failure
|
|
95
|
+
|
|
96
|
+
# ctest ran the C++ GEMM suite at 1, 2 and 4 threads and the bitwise
|
|
97
|
+
# 1-vs-2/3/4/8-thread checks. The Python tests then run on an OpenMP
|
|
98
|
+
# install: TestGEMMThreads (1, 2, 4 threads) and the OMP_NUM_THREADS default.
|
|
99
|
+
# SKBUILD_CMAKE_DEFINE, not pip's -C: Ubuntu 22.04's pip 22.0 has no -C.
|
|
100
|
+
- name: Install the package with OpenMP
|
|
101
|
+
env:
|
|
102
|
+
SKBUILD_CMAKE_DEFINE: SIMD_ML_OPENMP=ON
|
|
103
|
+
run: |
|
|
104
|
+
pip3 install scikit-build-core
|
|
105
|
+
pip3 install . --no-build-isolation -q
|
|
106
|
+
python3 -c "import simd_ml_kernels as s; i = s.build_info(); assert i['openmp'], i; print('threads', s.get_num_threads())"
|
|
107
|
+
|
|
108
|
+
- name: Self-test and Python tests (OpenMP build)
|
|
109
|
+
run: |
|
|
110
|
+
python3 -m simd_ml_kernels selftest
|
|
111
|
+
pytest tests -v --tb=short
|
|
112
|
+
|
|
113
|
+
# ─── Secondary: Clang-15 with ASan/UBSan ───────────────────────────────────
|
|
114
|
+
build-linux-asan:
|
|
115
|
+
name: Linux / Clang-15 / ASan + UBSan
|
|
116
|
+
runs-on: ubuntu-22.04
|
|
117
|
+
steps:
|
|
118
|
+
- uses: actions/checkout@v4
|
|
119
|
+
|
|
120
|
+
- name: Install dependencies
|
|
121
|
+
run: |
|
|
122
|
+
sudo apt-get update -qq
|
|
123
|
+
sudo apt-get install -y cmake ninja-build clang-15 python3-dev python3-pip
|
|
124
|
+
pip3 install pybind11[global] numpy
|
|
125
|
+
|
|
126
|
+
- name: Clean stale build directory
|
|
127
|
+
run: rm -rf build_asan
|
|
128
|
+
|
|
129
|
+
- name: Configure (RelWithDebInfo, sanitizers enabled)
|
|
130
|
+
run: |
|
|
131
|
+
cmake -S . -B build_asan -G Ninja \
|
|
132
|
+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
|
133
|
+
-DCMAKE_CXX_COMPILER=clang++-15 \
|
|
134
|
+
-DSIMD_ML_SANITIZE=ON
|
|
135
|
+
|
|
136
|
+
- name: Build
|
|
137
|
+
run: cmake --build build_asan --parallel
|
|
138
|
+
|
|
139
|
+
- name: Run ASan/UBSan tests
|
|
140
|
+
run: |
|
|
141
|
+
ASAN_OPTIONS=detect_leaks=1:abort_on_error=1 \
|
|
142
|
+
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 \
|
|
143
|
+
ctest --test-dir build_asan --output-on-failure --parallel 1
|
|
144
|
+
|
|
145
|
+
# ─── macOS: Apple Clang, scalar fallback path ───────────────────────────────
|
|
146
|
+
build-macos:
|
|
147
|
+
name: macOS / Apple Clang / Scalar fallback
|
|
148
|
+
runs-on: macos-14 # Apple Silicon (ARM) — no AVX2; tests scalar fallback
|
|
149
|
+
steps:
|
|
150
|
+
- uses: actions/checkout@v4
|
|
151
|
+
- name: Install CMake and pybind11
|
|
152
|
+
run: brew install cmake ninja pybind11
|
|
153
|
+
- name: Clean stale build directory
|
|
154
|
+
run: rm -rf build
|
|
155
|
+
- name: Configure (scalar build — no AVX2 flags)
|
|
156
|
+
run: cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DSIMD_ML_ENABLE_X86=OFF
|
|
157
|
+
- name: Build
|
|
158
|
+
run: cmake --build build --parallel
|
|
159
|
+
- name: Test (scalar fallback path)
|
|
160
|
+
run: ctest --test-dir build --output-on-failure
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main, master]
|
|
8
|
+
|
|
9
|
+
# Cancel in-progress runs on the same branch/PR to save CI minutes
|
|
10
|
+
concurrency:
|
|
11
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
12
|
+
cancel-in-progress: true
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
# ─── C++ Build and Test Matrix ───────────────────────────────────────────────
|
|
16
|
+
cpp:
|
|
17
|
+
name: C++ / ${{ matrix.os }} / ${{ matrix.compiler }}
|
|
18
|
+
runs-on: ${{ matrix.os }}
|
|
19
|
+
|
|
20
|
+
strategy:
|
|
21
|
+
fail-fast: false
|
|
22
|
+
matrix:
|
|
23
|
+
include:
|
|
24
|
+
# Ubuntu 22.04 + GCC-12 (primary)
|
|
25
|
+
- os: ubuntu-22.04
|
|
26
|
+
compiler: gcc-12
|
|
27
|
+
cc: gcc-12
|
|
28
|
+
cxx: g++-12
|
|
29
|
+
pkgs: gcc-12 g++-12
|
|
30
|
+
|
|
31
|
+
# Ubuntu 22.04 + Clang-15
|
|
32
|
+
- os: ubuntu-22.04
|
|
33
|
+
compiler: clang-15
|
|
34
|
+
cc: clang-15
|
|
35
|
+
cxx: clang++-15
|
|
36
|
+
pkgs: clang-15
|
|
37
|
+
|
|
38
|
+
# Ubuntu 24.04 + GCC-13 (newer toolchain)
|
|
39
|
+
- os: ubuntu-24.04
|
|
40
|
+
compiler: gcc-13
|
|
41
|
+
cc: gcc-13
|
|
42
|
+
cxx: g++-13
|
|
43
|
+
pkgs: gcc-13 g++-13
|
|
44
|
+
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/checkout@v4
|
|
47
|
+
|
|
48
|
+
# Guarantees a working `python`/`pip` on every runner image, including
|
|
49
|
+
# ubuntu-24.04 where python3-pip is not always preinstalled and the
|
|
50
|
+
# system Python is externally-managed (PEP 668).
|
|
51
|
+
- name: Set up Python
|
|
52
|
+
uses: actions/setup-python@v5
|
|
53
|
+
with:
|
|
54
|
+
python-version: "3.12"
|
|
55
|
+
|
|
56
|
+
- name: Install build dependencies
|
|
57
|
+
run: |
|
|
58
|
+
sudo apt-get update -qq
|
|
59
|
+
sudo apt-get install -y --no-install-recommends \
|
|
60
|
+
${{ matrix.pkgs }} \
|
|
61
|
+
cmake ninja-build
|
|
62
|
+
|
|
63
|
+
- name: Install pybind11 (for Python extension build in tests)
|
|
64
|
+
run: python -m pip install "pybind11[global]>=2.11" numpy
|
|
65
|
+
|
|
66
|
+
# Defends against a stale build/ directory leaking in via actions/cache
|
|
67
|
+
# or a previous job on the same runner with a different checkout path
|
|
68
|
+
# (CMakeCache.txt embeds an absolute path and refuses to be reused
|
|
69
|
+
# from a different one — see CI failure history in this repo).
|
|
70
|
+
- name: Clean stale build directory
|
|
71
|
+
run: rm -rf build
|
|
72
|
+
|
|
73
|
+
- name: Configure
|
|
74
|
+
env:
|
|
75
|
+
CC: ${{ matrix.cc }}
|
|
76
|
+
CXX: ${{ matrix.cxx }}
|
|
77
|
+
run: |
|
|
78
|
+
cmake -S . -B build -G Ninja \
|
|
79
|
+
-DCMAKE_BUILD_TYPE=Release \
|
|
80
|
+
-DCMAKE_C_COMPILER=${{ matrix.cc }} \
|
|
81
|
+
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }}
|
|
82
|
+
|
|
83
|
+
- name: Build
|
|
84
|
+
run: cmake --build build --parallel
|
|
85
|
+
|
|
86
|
+
- name: C++ tests
|
|
87
|
+
run: ctest --test-dir build --output-on-failure --parallel 4
|
|
88
|
+
|
|
89
|
+
- name: Benchmark smoke test (first 60 lines)
|
|
90
|
+
run: ./build/bench --warmup 1 --reps 3 2>&1 | head -60
|
|
91
|
+
|
|
92
|
+
# ─── Python Extension + Precision Tests ─────────────────────────────────────
|
|
93
|
+
python:
|
|
94
|
+
name: Python ${{ matrix.python-version }} / ${{ matrix.os }}
|
|
95
|
+
runs-on: ${{ matrix.os }}
|
|
96
|
+
|
|
97
|
+
strategy:
|
|
98
|
+
fail-fast: false
|
|
99
|
+
matrix:
|
|
100
|
+
include:
|
|
101
|
+
- os: ubuntu-22.04
|
|
102
|
+
python-version: "3.10"
|
|
103
|
+
- os: ubuntu-22.04
|
|
104
|
+
python-version: "3.11"
|
|
105
|
+
- os: ubuntu-22.04
|
|
106
|
+
python-version: "3.12"
|
|
107
|
+
- os: ubuntu-24.04
|
|
108
|
+
python-version: "3.12"
|
|
109
|
+
|
|
110
|
+
steps:
|
|
111
|
+
- uses: actions/checkout@v4
|
|
112
|
+
|
|
113
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
114
|
+
uses: actions/setup-python@v5
|
|
115
|
+
with:
|
|
116
|
+
python-version: ${{ matrix.python-version }}
|
|
117
|
+
|
|
118
|
+
- name: Install system dependencies
|
|
119
|
+
run: |
|
|
120
|
+
sudo apt-get update -qq
|
|
121
|
+
sudo apt-get install -y --no-install-recommends \
|
|
122
|
+
cmake ninja-build g++-12
|
|
123
|
+
|
|
124
|
+
- name: Install Python build and test dependencies
|
|
125
|
+
run: |
|
|
126
|
+
python -m pip install \
|
|
127
|
+
"scikit-build-core>=0.6" \
|
|
128
|
+
"pybind11[global]>=2.11" \
|
|
129
|
+
"numpy>=1.24" \
|
|
130
|
+
"scipy>=1.11" \
|
|
131
|
+
"pytest>=7.4" \
|
|
132
|
+
ml_dtypes \
|
|
133
|
+
mypy
|
|
134
|
+
# Install CPU-only PyTorch to enable the 4 cross-validation tests
|
|
135
|
+
# (test_gelu_vs_pytorch_tanh_approx, test_silu_vs_pytorch,
|
|
136
|
+
# test_softmax_vs_pytorch_2d, test_layer_norm_vs_pytorch)
|
|
137
|
+
# that are currently always skipped without torch.
|
|
138
|
+
# CPU-only index avoids the 2 GB CUDA variant.
|
|
139
|
+
python -m pip install \
|
|
140
|
+
torch --index-url https://download.pytorch.org/whl/cpu \
|
|
141
|
+
--quiet || echo "PyTorch install failed (non-fatal: tests will skip)"
|
|
142
|
+
|
|
143
|
+
- name: Build and install Python extension
|
|
144
|
+
run: python3 -m pip install -e . --no-build-isolation -v
|
|
145
|
+
|
|
146
|
+
- name: Verify installed package location
|
|
147
|
+
run: |
|
|
148
|
+
echo "which python3: $(which python3)"
|
|
149
|
+
echo "python3 --version: $(python3 --version)"
|
|
150
|
+
python3 -m pip show simd-ml-kernels
|
|
151
|
+
python3 -c "import simd_ml_kernels; print('simd_ml_kernels location:', simd_ml_kernels.__file__)"
|
|
152
|
+
|
|
153
|
+
- name: Self-test (every kernel vs float64; exits 1 on failure)
|
|
154
|
+
run: python3 -m simd_ml_kernels selftest
|
|
155
|
+
|
|
156
|
+
- name: Build info
|
|
157
|
+
run: python3 -m simd_ml_kernels info
|
|
158
|
+
|
|
159
|
+
# Fails if this runner's CPU has AVX-512F/DQ/BW/VL (or AVX2) and the
|
|
160
|
+
# dispatcher did not pick that table. GitHub runners vary (AMD EPYC Zen 3
|
|
161
|
+
# without AVX-512, Zen 5 and Intel Xeon with it), so over time this runs
|
|
162
|
+
# on real AVX-512 hardware too.
|
|
163
|
+
- name: Default kernel table matches this runner's CPU flags
|
|
164
|
+
run: |
|
|
165
|
+
grep -m1 '^flags' /proc/cpuinfo | grep -o -w -E 'avx2|fma|f16c|avx512(f|dq|bw|vl)' | sort -u | xargs echo "CPU flags:"
|
|
166
|
+
python3 -m pytest tests/test_bindings_edge_cases.py -k default_table_matches_cpuinfo -v
|
|
167
|
+
|
|
168
|
+
- name: Run Python tests
|
|
169
|
+
run: python3 -m pytest tests -v --tb=short
|
|
170
|
+
|
|
171
|
+
# Names in _core.pyi vs the compiled module (missing or extra functions).
|
|
172
|
+
# Parameters and defaults are compared by tests/test_stubs.py: stubtest
|
|
173
|
+
# cannot read pybind11 signatures (no __text_signature__).
|
|
174
|
+
- name: Type stubs match the module (mypy.stubtest)
|
|
175
|
+
run: python3 -m mypy.stubtest simd_ml_kernels --allowlist tests/stubtest_allowlist.txt
|
|
176
|
+
|
|
177
|
+
- name: Benchmark CLI smoke test (tiny sizes; numbers not used)
|
|
178
|
+
env:
|
|
179
|
+
OPENBLAS_NUM_THREADS: "1"
|
|
180
|
+
OMP_NUM_THREADS: "1"
|
|
181
|
+
MKL_NUM_THREADS: "1"
|
|
182
|
+
run: python3 -m simd_ml_kernels bench --sizes 128 --elems 65536 --warmup 1 --reps 3 --json /tmp/bench.json
|
|
183
|
+
|
|
184
|
+
- name: Examples run (examples/)
|
|
185
|
+
run: |
|
|
186
|
+
python3 examples/mlp_block.py
|
|
187
|
+
python3 examples/linear_trans_b.py
|
|
188
|
+
python3 examples/bench_to_json.py /tmp/example.json --sizes 128 --reps 3
|
|
189
|
+
|
|
190
|
+
- name: Benchmark tables match committed JSON
|
|
191
|
+
run: python3 benchmarks/make_tables.py --check
|
|
192
|
+
|
|
193
|
+
# ─── ASan / UBSan (Clang-15, Ubuntu 22.04) ───────────────────────────────────
|
|
194
|
+
sanitizers:
|
|
195
|
+
name: ASan + UBSan / clang-15
|
|
196
|
+
runs-on: ubuntu-22.04
|
|
197
|
+
|
|
198
|
+
steps:
|
|
199
|
+
- uses: actions/checkout@v4
|
|
200
|
+
|
|
201
|
+
- name: Set up Python
|
|
202
|
+
uses: actions/setup-python@v5
|
|
203
|
+
with:
|
|
204
|
+
python-version: "3.12"
|
|
205
|
+
|
|
206
|
+
- name: Install dependencies
|
|
207
|
+
run: |
|
|
208
|
+
sudo apt-get update -qq
|
|
209
|
+
sudo apt-get install -y --no-install-recommends \
|
|
210
|
+
clang-15 cmake ninja-build
|
|
211
|
+
python -m pip install "pybind11[global]>=2.11" numpy
|
|
212
|
+
|
|
213
|
+
- name: Clean stale build directory
|
|
214
|
+
run: rm -rf build_asan
|
|
215
|
+
|
|
216
|
+
- name: Configure (RelWithDebInfo + sanitizers)
|
|
217
|
+
run: |
|
|
218
|
+
cmake -S . -B build_asan -G Ninja \
|
|
219
|
+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
|
220
|
+
-DCMAKE_CXX_COMPILER=clang++-15 \
|
|
221
|
+
-DSIMD_ML_SANITIZE=ON
|
|
222
|
+
|
|
223
|
+
- name: Build
|
|
224
|
+
run: cmake --build build_asan --parallel
|
|
225
|
+
|
|
226
|
+
- name: Run sanitized tests
|
|
227
|
+
run: |
|
|
228
|
+
ASAN_OPTIONS=detect_leaks=1:abort_on_error=1 \
|
|
229
|
+
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 \
|
|
230
|
+
ctest --test-dir build_asan --output-on-failure --parallel 1
|
|
231
|
+
|
|
232
|
+
# ─── Final summary gate ───────────────────────────────────────────────────────
|
|
233
|
+
all-pass:
|
|
234
|
+
name: All checks passed
|
|
235
|
+
needs: [cpp, python, sanitizers]
|
|
236
|
+
runs-on: ubuntu-latest
|
|
237
|
+
# Run even if earlier jobs fail so we always get a status update.
|
|
238
|
+
# 'skipped' is treated as success (e.g. matrix jobs skipped due to
|
|
239
|
+
# path filters or manual workflow_dispatch without certain inputs).
|
|
240
|
+
if: always()
|
|
241
|
+
steps:
|
|
242
|
+
- name: Verify all required jobs succeeded
|
|
243
|
+
run: |
|
|
244
|
+
cpp_result="${{ needs.cpp.result }}"
|
|
245
|
+
python_result="${{ needs.python.result }}"
|
|
246
|
+
san_result="${{ needs.sanitizers.result }}"
|
|
247
|
+
echo "cpp: $cpp_result"
|
|
248
|
+
echo "python: $python_result"
|
|
249
|
+
echo "sanitizers: $san_result"
|
|
250
|
+
|
|
251
|
+
failed=0
|
|
252
|
+
for r in "$cpp_result" "$python_result" "$san_result"; do
|
|
253
|
+
# Accept 'success' or 'skipped'; reject 'failure' or 'cancelled'.
|
|
254
|
+
if [[ "$r" != "success" && "$r" != "skipped" ]]; then
|
|
255
|
+
failed=1
|
|
256
|
+
fi
|
|
257
|
+
done
|
|
258
|
+
|
|
259
|
+
if [[ $failed -eq 1 ]]; then
|
|
260
|
+
echo "❌ One or more required CI jobs did not succeed."
|
|
261
|
+
exit 1
|
|
262
|
+
fi
|
|
263
|
+
echo "✅ All required CI jobs passed."
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
name: Security and Code Quality
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main, master]
|
|
8
|
+
schedule:
|
|
9
|
+
- cron: '0 3 * * 1' # Weekly Monday 3 AM UTC
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
# ─── Static analysis: clang-tidy ────────────────────────────────────────────
|
|
13
|
+
clang-tidy:
|
|
14
|
+
name: clang-tidy static analysis
|
|
15
|
+
runs-on: ubuntu-22.04
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Install dependencies
|
|
20
|
+
run: |
|
|
21
|
+
sudo apt-get update -qq
|
|
22
|
+
sudo apt-get install -y cmake ninja-build clang-15 clang-tidy-15 \
|
|
23
|
+
python3-dev python3-pip
|
|
24
|
+
pip3 install pybind11[global] numpy
|
|
25
|
+
|
|
26
|
+
- name: Generate compile_commands.json
|
|
27
|
+
run: |
|
|
28
|
+
cmake -S . -B build_tidy -G Ninja \
|
|
29
|
+
-DCMAKE_BUILD_TYPE=Release \
|
|
30
|
+
-DCMAKE_CXX_COMPILER=clang++-15 \
|
|
31
|
+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
|
32
|
+
|
|
33
|
+
- name: Run clang-tidy on kernel sources
|
|
34
|
+
run: |
|
|
35
|
+
# Focus on kernel sources; exclude vendored/generated headers
|
|
36
|
+
FILES=$(find src/kernels src/dispatch -name "*.cpp" | tr '\n' ' ')
|
|
37
|
+
clang-tidy-15 \
|
|
38
|
+
-p build_tidy \
|
|
39
|
+
--checks='bugprone-*,cppcoreguidelines-*,modernize-*,performance-*,portability-*,readability-*,-modernize-use-trailing-return-type,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers' \
|
|
40
|
+
--warnings-as-errors='' \
|
|
41
|
+
$FILES \
|
|
42
|
+
2>&1 | tee clang_tidy_report.txt || true
|
|
43
|
+
# Fail if real errors (not warnings) found
|
|
44
|
+
if grep -E "^.*: error:" clang_tidy_report.txt; then
|
|
45
|
+
echo "clang-tidy found errors"
|
|
46
|
+
exit 1
|
|
47
|
+
fi
|
|
48
|
+
echo "clang-tidy: no errors found"
|
|
49
|
+
|
|
50
|
+
# ─── Dependency vulnerability scan: pip-audit ───────────────────────────────
|
|
51
|
+
dependency-audit:
|
|
52
|
+
name: Python dependency vulnerability scan
|
|
53
|
+
runs-on: ubuntu-22.04
|
|
54
|
+
steps:
|
|
55
|
+
- uses: actions/checkout@v4
|
|
56
|
+
|
|
57
|
+
- name: Install pip-audit
|
|
58
|
+
run: pip install pip-audit
|
|
59
|
+
|
|
60
|
+
- name: Audit Python dependencies
|
|
61
|
+
run: |
|
|
62
|
+
pip-audit --requirement <(echo "numpy>=1.24
|
|
63
|
+
pytest
|
|
64
|
+
scipy") || true # Advisory only — don't block on unfixable transitive vulns
|
|
65
|
+
|
|
66
|
+
# ─── Spell check documentation ───────────────────────────────────────────────
|
|
67
|
+
spell-check:
|
|
68
|
+
name: Documentation spell check
|
|
69
|
+
runs-on: ubuntu-22.04
|
|
70
|
+
steps:
|
|
71
|
+
- uses: actions/checkout@v4
|
|
72
|
+
|
|
73
|
+
- name: Install codespell
|
|
74
|
+
run: pip install codespell
|
|
75
|
+
|
|
76
|
+
- name: Run codespell on docs and source
|
|
77
|
+
run: |
|
|
78
|
+
codespell \
|
|
79
|
+
--skip="*.json,*.lock,*.pyc,build,*.egg-info,.git" \
|
|
80
|
+
--ignore-words-list="TE,ths,nin,fo,ans" \
|
|
81
|
+
docs/ src/ tests/ README.md \
|
|
82
|
+
2>&1 | tee codespell_report.txt || true
|
|
83
|
+
if [ -s codespell_report.txt ]; then
|
|
84
|
+
echo "codespell found potential misspellings (advisory):"
|
|
85
|
+
cat codespell_report.txt
|
|
86
|
+
else
|
|
87
|
+
echo "codespell: no issues found"
|
|
88
|
+
fi
|
|
89
|
+
|
|
90
|
+
# ─── License header check ────────────────────────────────────────────────────
|
|
91
|
+
license-check:
|
|
92
|
+
name: License header compliance
|
|
93
|
+
runs-on: ubuntu-22.04
|
|
94
|
+
steps:
|
|
95
|
+
- uses: actions/checkout@v4
|
|
96
|
+
|
|
97
|
+
- name: Check for Apache 2.0 license file
|
|
98
|
+
run: |
|
|
99
|
+
if [ ! -f LICENSE ]; then
|
|
100
|
+
echo "ERROR: LICENSE file missing"
|
|
101
|
+
exit 1
|
|
102
|
+
fi
|
|
103
|
+
if ! grep -q "Apache License" LICENSE; then
|
|
104
|
+
echo "ERROR: LICENSE file does not contain Apache License header"
|
|
105
|
+
exit 1
|
|
106
|
+
fi
|
|
107
|
+
echo "LICENSE file: OK"
|
|
108
|
+
echo "Source file count: $(find src/ -name '*.cpp' -o -name '*.hpp' | wc -l)"
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
# Manual release: builds the wheels and the sdist with wheels.yml (each one
|
|
4
|
+
# installed in a clean environment and selftested), then uploads them to
|
|
5
|
+
# TestPyPI or PyPI with Trusted Publishing: PyPI trusts this workflow's OIDC
|
|
6
|
+
# token for the environment named by `target`, so there is no API token and no
|
|
7
|
+
# repository secret. One-time setup (owner): a trusted publisher on
|
|
8
|
+
# test.pypi.org / pypi.org for workflow publish.yml with environment testpypi /
|
|
9
|
+
# pypi, and GitHub environments of the same names (pypi with a required
|
|
10
|
+
# reviewer).
|
|
11
|
+
on:
|
|
12
|
+
workflow_dispatch:
|
|
13
|
+
inputs:
|
|
14
|
+
target:
|
|
15
|
+
description: "Package index to upload to"
|
|
16
|
+
required: true
|
|
17
|
+
type: choice
|
|
18
|
+
options: [testpypi, pypi]
|
|
19
|
+
|
|
20
|
+
permissions:
|
|
21
|
+
contents: read
|
|
22
|
+
|
|
23
|
+
concurrency:
|
|
24
|
+
group: publish-${{ inputs.target }}
|
|
25
|
+
cancel-in-progress: false
|
|
26
|
+
|
|
27
|
+
jobs:
|
|
28
|
+
build:
|
|
29
|
+
uses: ./.github/workflows/wheels.yml
|
|
30
|
+
|
|
31
|
+
publish:
|
|
32
|
+
name: Upload to ${{ inputs.target }}
|
|
33
|
+
needs: build
|
|
34
|
+
# Releases come from main only.
|
|
35
|
+
if: github.ref == 'refs/heads/main'
|
|
36
|
+
runs-on: ubuntu-24.04
|
|
37
|
+
environment:
|
|
38
|
+
name: ${{ inputs.target }}
|
|
39
|
+
url: ${{ inputs.target == 'pypi' && 'https://pypi.org/p/simd-ml-kernels' || 'https://test.pypi.org/p/simd-ml-kernels' }}
|
|
40
|
+
permissions:
|
|
41
|
+
id-token: write # OIDC token for Trusted Publishing; nothing else
|
|
42
|
+
steps:
|
|
43
|
+
- uses: actions/download-artifact@v4
|
|
44
|
+
with:
|
|
45
|
+
path: dist
|
|
46
|
+
merge-multiple: true
|
|
47
|
+
- name: List files
|
|
48
|
+
run: ls -l dist
|
|
49
|
+
- name: Upload to TestPyPI
|
|
50
|
+
if: inputs.target == 'testpypi'
|
|
51
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
52
|
+
with:
|
|
53
|
+
repository-url: https://test.pypi.org/legacy/
|
|
54
|
+
packages-dir: dist
|
|
55
|
+
- name: Upload to PyPI
|
|
56
|
+
if: inputs.target == 'pypi'
|
|
57
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
58
|
+
with:
|
|
59
|
+
packages-dir: dist
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
name: Wheels
|
|
2
|
+
|
|
3
|
+
# Builds wheels with cibuildwheel and an sdist, installs each in a clean
|
|
4
|
+
# environment and runs selftest (pyproject.toml [tool.cibuildwheel]). On pull
|
|
5
|
+
# requests the files are kept as workflow artifacts only; publish.yml calls this
|
|
6
|
+
# workflow and uploads the same files. (Running a wheel under Intel SDE is a
|
|
7
|
+
# local check: Intel's server refuses CI downloads.)
|
|
8
|
+
on:
|
|
9
|
+
pull_request:
|
|
10
|
+
branches: [main]
|
|
11
|
+
paths: ["CMakeLists.txt", "pyproject.toml", "src/**", "python/**", ".github/workflows/wheels.yml"]
|
|
12
|
+
workflow_dispatch:
|
|
13
|
+
workflow_call:
|
|
14
|
+
|
|
15
|
+
concurrency:
|
|
16
|
+
group: ${{ github.workflow }}-wheels-${{ github.ref }}
|
|
17
|
+
cancel-in-progress: true
|
|
18
|
+
|
|
19
|
+
permissions:
|
|
20
|
+
contents: read
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
build:
|
|
24
|
+
name: Wheels / ${{ matrix.os }}
|
|
25
|
+
runs-on: ${{ matrix.os }}
|
|
26
|
+
strategy:
|
|
27
|
+
fail-fast: false
|
|
28
|
+
matrix:
|
|
29
|
+
os: [ubuntu-24.04, macos-14]
|
|
30
|
+
steps:
|
|
31
|
+
- uses: actions/checkout@v4
|
|
32
|
+
- name: Build and test wheels
|
|
33
|
+
uses: pypa/cibuildwheel@v2.23.3
|
|
34
|
+
- uses: actions/upload-artifact@v4
|
|
35
|
+
with:
|
|
36
|
+
name: wheels-${{ matrix.os }}
|
|
37
|
+
path: wheelhouse/*.whl
|
|
38
|
+
|
|
39
|
+
sdist:
|
|
40
|
+
name: sdist
|
|
41
|
+
runs-on: ubuntu-24.04
|
|
42
|
+
steps:
|
|
43
|
+
- uses: actions/checkout@v4
|
|
44
|
+
- uses: actions/setup-python@v5
|
|
45
|
+
with:
|
|
46
|
+
python-version: "3.12"
|
|
47
|
+
- name: Build the sdist
|
|
48
|
+
run: pipx run build --sdist
|
|
49
|
+
# The sdist must build on its own: a fresh venv, the build requirements
|
|
50
|
+
# from PyPI, the runner's C++ compiler, no checkout on the path.
|
|
51
|
+
- name: Install the sdist in a clean venv and run selftest
|
|
52
|
+
run: |
|
|
53
|
+
python -m venv /tmp/sdist-venv
|
|
54
|
+
/tmp/sdist-venv/bin/pip install dist/*.tar.gz
|
|
55
|
+
cd /tmp
|
|
56
|
+
/tmp/sdist-venv/bin/python -m simd_ml_kernels selftest
|
|
57
|
+
/tmp/sdist-venv/bin/python -m simd_ml_kernels info
|
|
58
|
+
- uses: actions/upload-artifact@v4
|
|
59
|
+
with:
|
|
60
|
+
name: sdist
|
|
61
|
+
path: dist/*.tar.gz
|