v0.3.13 PyPI • v0.3.8 APT FP32 • SGEMM • 4D BMM • INT8 W^X Safe (Zero-JIT ~100 KB) MCP: nanogemm-mcp

NanoGEMM — Bare-Metal Small-Tensor GEMM Microkernel (~100 KB)

Eliminates OpenBLAS thread-pool barriers and dispatch overhead on edge AI and LLM tensor sizes (16x16 to 64x64) via direct 6x16 AVX2+FMA and 4x8 ARM NEON register tiling, batched Transformer BMM, and quantized INT8 GEMM.

📦 1. Installation & Compatibility Matrix

pip install nanogemm
Runtime / OSVersionsStatus & Mode
CPython3.8 – 3.16C99 6x16 AVX2+FMA / 4x8 NEON + FASM x64 DLL
Free-Threaded No-GIL3.13t – 3.16t (PEP 703)Py_MOD_GIL_NOT_USED & Py_BEGIN_ALLOW_THREADS
PyPy JIT3.8 – 3.12Pure ctypes FASM x64/x86 fallback on PyPy
Operating SystemsWindows / Linux / macOSWindows / Linux / macOS (Apple Silicon M-series & x86_64)

🧮 2. Matrix Multiplication, Transformer BMM & INT8

nanogemm_demo.py
import numpy as np
import nanogemm as ng

print("Active ISA:", ng.get_simd_isa(), "Backend:", ng.get_backend())

A = np.random.randn(32, 64).astype(np.float32)
B = np.random.randn(64, 128).astype(np.float32)

# Direct FP32 GEMM (with optional zero-copy out buffer)
out = np.empty((32, 128), dtype=np.float32)
C = ng.matmul(A, B, out=out)

# Standard BLAS SGEMM: C = alpha * (A @ B) + beta * C
res = ng.sgemm(A, B, alpha=2.0, beta=0.5, c=out)

# 4D Batched Multi-Head Attention (Batch x Heads x Seq x Dim)
Q = np.random.randn(8, 16, 32, 64).astype(np.float32)
K_t = np.random.randn(8, 16, 64, 32).astype(np.float32)
attn = ng.bmm(Q, K_t)

# Quantized INT8 SIMD GEMM & Linear scale pass
A_q = np.random.randint(-128, 127, size=(32, 64), dtype=np.int8)
B_q = np.random.randint(-128, 127, size=(64, 128), dtype=np.int8)
C_i32 = ng.matmul_int8(A_q, B_q)
Y_f32 = ng.quantized_matmul(A_q, B_q, scale_a=0.05, scale_b=0.02)

🔌 3. CLI Subcommands & MCP Tools (nanogemm-mcp)

CLI / MCP ToolParameters / Behavior
nanogemm benchmark / gemm_benchmarkMicrobenchmark NanoGEMM vs NumPy (`m, k, n, iterations`) returning latency & speedup
gemm_multiplyExecute direct FP32/INT8 GEMM (`matrix_a, matrix_b, alpha, beta`) over JSON-RPC
nanogemm info / gemm_hardware_infoReport CPU AVX2/FMA/NEON/SSE2 ISA and loaded kernel backend
nanogemm mcp / nanogemm-mcpLaunch JSON-RPC 2.0 stdio MCP server for Antigravity, Claude, Cursor
Copied!