Skip to content

Commit b9b7871

Browse files
committed
docs,chore(growth): add GitHub social preview, Colab quickstart notebook, issue/PR templates, technical blog posts, and PyPI SEO metadata
1 parent 0a40b77 commit b9b7871

9 files changed

Lines changed: 282 additions & 3 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Bug Report
2+
description: Report a crash, incorrect gradient/output, or build issue in Oxideon
3+
title: "[Bug]: "
4+
labels: ["bug"]
5+
body:
6+
- type: textarea
7+
id: description
8+
attributes:
9+
label: What happened?
10+
description: Clear description of the bug and what you expected to happen.
11+
validations:
12+
required: true
13+
- type: textarea
14+
id: repro
15+
attributes:
16+
label: Minimal reproduction
17+
description: Paste a small Rust or Python snippet reproducing the issue.
18+
render: python
19+
- type: textarea
20+
id: env
21+
attributes:
22+
label: Environment
23+
description: OS, CPU/GPU, Rust version (`rustc --version`), Python version, and Oxideon version (`pip show oxideon` or commit SHA).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Feature Request
2+
description: Propose a new op, backend kernel, exporter, or API improvement
3+
title: "[Feature]: "
4+
labels: ["enhancement"]
5+
body:
6+
- type: textarea
7+
id: summary
8+
attributes:
9+
label: Summary
10+
description: What capability or API would you like added?
11+
validations:
12+
required: true
13+
- type: textarea
14+
id: context
15+
attributes:
16+
label: Use case & context
17+
description: Why is this useful, and how does PyTorch or another Rust crate handle it?

‎.github/PULL_REQUEST_TEMPLATE.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Summary
2+
<!-- Briefly describe what this PR does and link any related issue (e.g., Fixes #4). -->
3+
4+
## Verification
5+
- [ ] `cargo test -p oxideon-core --lib`
6+
- [ ] `cargo clippy --workspace --all-targets -- -D warnings`
7+
- [ ] `pytest tests/ -q` (if Python bindings or Python code changed)
8+
- [ ] `python tools/gen_stubs.py` (if Python signatures/docstrings changed)

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
**A fast, Hackable Deep Learning & Tensor Library in Rust — with a PyTorch-friendly Python API.**
88

99
[![Browser demo](https://img.shields.io/badge/browser%20demo-run%20Oxideon%20in%20your%20browser-brightgreen.svg)](https://voidstackloop.github.io/oxideon/)
10+
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/voidstackloop/oxideon/blob/main/examples/oxideon_quickstart.ipynb)
1011
[![Portfolio](https://img.shields.io/badge/portfolio-voidstackloop-blueviolet.svg)](https://github.com/voidstackloop/portfolio)
1112

1213
[![Version](https://img.shields.io/badge/version-v0.1.0-blue.svg)](https://github.com/voidstackloop/oxideon/releases/tag/v0.1.0)

‎docs/assets/social-preview.png‎

75.2 KB
Loading
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Beating PyTorch CPU on AdamW, LayerNorm, and Softmax with AVX2+FMA in Rust
2+
3+
When we first benchmarked **Oxideon** against PyTorch (`2.15.0+cpu`), GEMM via blocked kernels quickly approached MKL parity, yet elementwise math (`exp`, `sigmoid`, `silu`), reductions (`softmax`, `layer_norm`), and optimizer steps (`AdamW`) initially lagged behind PyTorch's oneDNN / ATen vectorized loops by 1.5×–3×.
4+
5+
Here is how we closed—and reversed—that gap in pure safe/intrinsic Rust (`crates/oxideon-core/src/backend/simd_x86.rs` & `optim.rs`).
6+
7+
## 1. Range-Reduced AVX2+FMA `exp` (Unlocks `exp`, `sigmoid`, `silu`, `tanh`, `softmax`)
8+
9+
Standard `f32::exp()` in Rust calls libm scalar-by-scalar, which kills throughput and blocks auto-vectorization. We implemented an 8-lane AVX2+FMA range-reduced `exp_ps_avx2` using Cody–Waite reduction ($x = n \ln 2 + r$), a degree-5 minimax polynomial in FMA chains, and bit-shifted IEEE-754 exponent scaling (`((n + 127) << 23)`).
10+
11+
From that single vectorized primitive, we derived:
12+
- **`sigmoid(x)`** = $1 / (1 + \exp(-x))$
13+
- **`silu(x)`** = $x \cdot \text{sigmoid}(x)$
14+
- **`tanh(x)`** = $2 \cdot \text{sigmoid}(2x) - 1$ (blending exact $x$ for $|x| < 5\times 10^{-4}$ and handling `NaN`)
15+
- **`softmax_row_f32`**: parallel row chunks with AVX2 max reduction, subtracted `exp_ps_avx2`, and sum normalization.
16+
17+
## 2. Single-Pass Fused AVX2+FMA `AdamW`
18+
19+
PyTorch's default Python `AdamW.step()` allocates or streams across separate parameter/moment passes unless fused/foreach is active. In `adam_step_f32_slice`, Oxideon processes `[p, m, v, g]` in a single parallel `rayon` + AVX2+FMA pass with zero intermediate tensor allocations:
20+
21+
- Computes decoupled weight decay, EMA moment updates (`m`, `v`), bias corrections, and parameter step in registers across 8 floats at a time.
22+
- Result on **10M parameters**: **4.323 ms** vs PyTorch CPU **12.620 ms** (**0.34×**, ~2.9× faster).
23+
24+
## 3. Fused `LayerNorm` Forward & Backward + In-Place `Linear` Bias
25+
26+
- **Forward (`layer_norm_row_f32`)**: 2-pass AVX2 sum + variance reduction + FMA affine normalize per row across `rayon` workers (`0.755 ms` vs PyTorch `0.877 ms`).
27+
- **Linear bias fusion**: adding bias in-place inside `Linear::forward` via `Storage::try_add_bias_inplace_f32` avoids allocating an extra broadcast output buffer on every layer.
28+
29+
## Measured CPU Numbers (`--release`, `Oxideon v0.1.0` vs `PyTorch 2.15.0+cpu`)
30+
31+
| Operation | Oxideon | PyTorch | Ratio (`Ox / Th`) |
32+
|---|---:|---:|---:|
33+
| `AdamW step [10M params]` | **4.323 ms** | 12.620 ms | **0.34×** |
34+
| `sigmoid [64, 128, 768]` | **0.924 ms** | 1.667 ms | **0.55×** |
35+
| `exp [64, 128, 768]` | **0.818 ms** | 1.073 ms | **0.76×** |
36+
| `silu [64, 128, 768]` | **1.005 ms** | 1.293 ms | **0.78×** |
37+
| `softmax [64, 128, 768]` | **1.398 ms** | 1.732 ms | **0.81×** |
38+
| `matmul 512×512` | **0.646 ms** | 0.776 ms | **0.83×** |
39+
| `layer_norm [64, 128, 768]` | **0.755 ms** | 0.877 ms | **0.86×** |
40+
| `conv2d [16, 64, 32, 32]` | 7.762 ms | 2.844 ms | 2.73× |
41+
42+
Reproduce every number locally with:
43+
```bash
44+
python benchmarks/bench_vs_pytorch.py
45+
```
46+
Repo: https://github.com/voidstackloop/oxideon
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Running 1.69 TFLOP/s CUDA Kernels in Pure Rust with Zero `nvcc` Dependencies
2+
3+
Most Rust deep learning frameworks face a painful build-time wall on Windows and Linux: you either shell out to `nvcc` inside `build.rs` (breaking `cargo install` / PyPI source builds whenever the user lacks the 4 GB CUDA Toolkit) or rely solely on WebGPU/Vulkan shaders.
4+
5+
In **Oxideon** (`oxideon-core`), we built a zero-build-dependency CUDA backend (`crates/oxideon-core/src/backend/cuda_driver.rs` & `cuda_kernels.rs`) that still runs native NVIDIA PTX/NVRTC kernels, CUDA Graphs, and zero-copy `kDLCUDA` DLPack directly on the GPU.
6+
7+
## 1. Dynamic Driver Loading (`nvcuda.dll` / `libcuda.so.1`)
8+
9+
Instead of linking against CUDA static stubs at compile time, `cuda_driver.rs` opens the NVIDIA driver library at runtime via OS dynamic loading (`LoadLibraryW` on Windows, `dlopen` on Linux) and resolves CUDA Driver API entry points:
10+
11+
- Device/context lifecycle (`cuInit`, `cuDevicePrimaryCtxRetain`, `cuDeviceGetAttribute`)
12+
- VRAM allocation & transfers (`cuMemAlloc_v2`, `cuMemFree_v2`, `cuMemcpyHtoD_v2`, `cuMemcpyDtoH_v2`, `cuMemcpyDtoDAsync_v2`)
13+
- PTX JIT compilation & kernel launches (`cuModuleLoadDataEx` with JIT error log buffer, `cuModuleGetFunction`, `cuLaunchKernel`)
14+
- Streams & CUDA Graphs (`cuStreamCreate`, `cuStreamBeginCapture`, `cuStreamEndCapture`, `cuGraphInstantiate`, `cuGraphLaunch`)
15+
16+
If no NVIDIA driver is present on the machine, Oxideon still builds identically on every OS and cleanly reports `ox.cuda.is_available() == False`.
17+
18+
## 2. Writing 32×32 Register-Blocked SGEMM Directly in PTX
19+
20+
For out-of-the-box execution even when `libnvrtc` isn't installed alongside the driver, `cuda_kernels.rs` embeds self-contained `.version 7.0 / .target sm_50` PTX kernels that the driver JITs straight to native SASS (`sm_89` on RTX 4060):
21+
22+
- **`matmul_tiled32_2x2_f32`**: A `[16, 16, 1]` block (256 threads) computes a `32×32` tile of `C` with `BK=16` in shared memory (`tileA[32][16]`, `tileB[16][32]`), where each thread accumulates a `2×2` register sub-tile (`4` FMAs per pair of shared loads).
23+
- **`softmax_row_f32` & `layer_norm_row_f32`**: Block-per-row 256-thread shared-memory tree reductions so activations don't bounce through global memory between mean, variance, and normalization passes.
24+
- **PTX Addressing Quirk Learned on Hardware**: Shared memory arrays in PTX cannot be indexed with `[sym + %reg]` directly—you must load the shared symbol base (`mov.u32 %r_base, tileA`), add the byte offset into a register (`add.u32`), and load/store `[%r_addr]`. Surfacing the `cuModuleLoadDataEx` JIT error log makes debugging PTX trivial.
25+
26+
### Measured Throughput (RTX 4060 Laptop GPU, JIT PTX, Zero `nvcc`)
27+
28+
| Matrix Size | Latency | Throughput |
29+
|---|---:|---:|
30+
| `CUDA matmul 1024×1024` | **1.404 ms** | **1529.9 GFLOP/s** |
31+
| `CUDA matmul 2048×2048` | **10.148 ms** | **1692.9 GFLOP/s** |
32+
33+
When NVRTC *is* available at runtime (`backend/nvrtc.rs` + `crates/oxideon-core/cuda/*.cu`), higher-throughput `.cu` kernels (attention, conv2d, reductions, optimizers) are JIT-compiled on first use too.
34+
35+
## Try It Yourself
36+
```bash
37+
pip install oxideon
38+
# or in Rust:
39+
cargo add oxideon-core
40+
```
41+
Repo: https://github.com/voidstackloop/oxideon

‎examples/oxideon_quickstart.ipynb‎

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Oxideon Quickstart\n",
8+
"\n",
9+
"Run **Oxideon** (`pip install oxideon`) directly in Google Colab or Jupyter:\n",
10+
"- Zero-copy strided views & higher-order autograd (`create_graph=True`)\n",
11+
"- Training a neural network with `AdamW` & `LayerNorm`\n",
12+
"- Zero-copy NumPy / DLPack interop & Einops `rearrange`\n",
13+
"- Quick CPU speed check vs PyTorch\n",
14+
"\n",
15+
"Repo: https://github.com/voidstackloop/oxideon"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": null,
21+
"metadata": {},
22+
"outputs": [],
23+
"source": [
24+
"!pip install -q oxideon numpy torch"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"metadata": {},
31+
"outputs": [],
32+
"source": [
33+
"import oxideon as ox\n",
34+
"\n",
35+
"# 1. Zero-copy strided views\n",
36+
"x = ox.Tensor.arange(0.0, 24.0, 1.0).reshape([2, 3, 4])\n",
37+
"v = x.transpose(0, 2)\n",
38+
"assert v.shares_storage(x)\n",
39+
"print(\"v shape:\", v.shape(), \"shares_storage:\", v.shares_storage(x))\n",
40+
"\n",
41+
"# 2. Einops-style rearrange & channels_last\n",
42+
"img = ox.randn([2, 8, 4, 4])\n",
43+
"nhwc = img.rearrange(\"b c h w -> b h w c\")\n",
44+
"cl = img.to_channels_last()\n",
45+
"print(\"rearranged shape:\", nhwc.shape(), \"is_channels_last:\", cl.is_channels_last())"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"metadata": {},
52+
"outputs": [],
53+
"source": [
54+
"# 3. Higher-order autograd (1st, 2nd, and 3rd derivatives)\n",
55+
"x = ox.Tensor.from_slice([3.0], [1], requires_grad=True)\n",
56+
"y = x.powf(4.0)\n",
57+
"dy = ox.grad([y], [x], create_graph=True)[0]\n",
58+
"d2y = ox.grad([dy], [x], create_graph=True)[0]\n",
59+
"d3y = ox.grad([d2y], [x])[0]\n",
60+
"print(\"y=x^4 at x=3 -> dy:\", dy.to_list(), \"d2y:\", d2y.to_list(), \"d3y:\", d3y.to_list())"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"# 4. Train a compact MLP with AdamW\n",
70+
"class MLP(ox.nn.Module):\n",
71+
" def __init__(self, d=64):\n",
72+
" super().__init__()\n",
73+
" self.fc1 = ox.nn.Linear(16, d)\n",
74+
" self.ln = ox.nn.LayerNorm(d)\n",
75+
" self.fc2 = ox.nn.Linear(d, 4)\n",
76+
"\n",
77+
" def forward(self, x):\n",
78+
" return self.fc2(self.ln(self.fc1(x)).gelu())\n",
79+
"\n",
80+
"model = MLP()\n",
81+
"opt = ox.optim.AdamW(model.parameters(), lr=1e-2)\n",
82+
"xs = ox.randn([32, 16])\n",
83+
"ys = ox.randn([32, 4])\n",
84+
"\n",
85+
"for step in range(40):\n",
86+
" opt.zero_grad()\n",
87+
" pred = model(xs)\n",
88+
" loss = ((pred - ys) * (pred - ys)).mean()\n",
89+
" loss.backward()\n",
90+
" opt.step()\n",
91+
" if step in (0, 19, 39):\n",
92+
" print(f\"step {step:2d}: loss = {loss.item():.6f}\")"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": null,
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"# 5. Quick CPU benchmark vs PyTorch (AdamW + Softmax + LayerNorm)\n",
102+
"import time\n",
103+
"import torch\n",
104+
"\n",
105+
"x_np = ox.randn([32, 128, 768]).numpy()\n",
106+
"xo = ox.from_numpy(x_np)\n",
107+
"xt = torch.from_numpy(x_np)\n",
108+
"\n",
109+
"for _ in range(3):\n",
110+
" _ = xo.softmax(-1)\n",
111+
" _ = torch.softmax(xt, -1)\n",
112+
"\n",
113+
"t0 = time.perf_counter()\n",
114+
"for _ in range(20):\n",
115+
" _ = xo.softmax(-1)\n",
116+
"ox_ms = (time.perf_counter() - t0) / 20 * 1000\n",
117+
"\n",
118+
"t0 = time.perf_counter()\n",
119+
"for _ in range(20):\n",
120+
" _ = torch.softmax(xt, -1)\n",
121+
"pt_ms = (time.perf_counter() - t0) / 20 * 1000\n",
122+
"print(f\"softmax [32,128,768]: Oxideon={ox_ms:.2f} ms, PyTorch={pt_ms:.2f} ms\")"
123+
]
124+
}
125+
],
126+
"metadata": {
127+
"kernelspec": {
128+
"display_name": "Python 3",
129+
"language": "python",
130+
"name": "python3"
131+
},
132+
"language_info": {
133+
"name": "python",
134+
"version": "3.11.0"
135+
}
136+
},
137+
"nbformat": 4,
138+
"nbformat_minor": 4
139+
}

‎pyproject.toml‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@ build-backend = "maturin"
55
[project]
66
name = "oxideon"
77
dynamic = ["version"]
8-
description = "High-performance multi-dtype deep learning, autograd, quantum computing, scientific PDEs, and autonomous LLM quantization engine in Rust"
8+
description = "A deep learning and tensor library in Rust with Python bindings, higher-order autograd, AVX2/NEON SIMD, and a zero-nvcc CUDA backend"
99
readme = "README.md"
1010
requires-python = ">=3.9"
1111
license = { text = "MIT OR Apache-2.0" }
1212
keywords = [
1313
"deep-learning",
14+
"pytorch",
1415
"autograd",
1516
"tensor",
1617
"machine-learning",
17-
"quantum-computing",
18-
"llm-quantization",
18+
"cuda",
19+
"simd",
20+
"gguf",
21+
"safetensors",
22+
"onnx",
1923
"rust",
2024
"pyo3",
2125
]

0 commit comments

Comments
 (0)