Skip to content
Merged
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
7 changes: 0 additions & 7 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@ reviews:
mode: "off"

path_filters:
- "!csrc/cutlass/**"
- "!third_party/**"

path_instructions:
- path: "csrc/**"
instructions: |
Review CUDA changes for synchronization and memory-ordering correctness,
shared-memory and barrier lifetimes, out-of-bounds access, divergence,
architecture guards, numerical precision, and concrete performance regressions.

- path: "cula/**"
instructions: |
Review CuTe DSL kernels and Python APIs for architecture dispatch,
Expand Down
122 changes: 22 additions & 100 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build & Release Wheels
name: Build & Release Wheel

on:
push:
Expand All @@ -12,127 +12,50 @@ concurrency:

jobs:
build-wheel:
name: "wheel / ${{ matrix.cuda }} / cp312 / ${{ matrix.arch }}"
runs-on: ${{ matrix.arch == 'aarch64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
cuda:
- cu129
- cu130
arch:
- x86_64
- aarch64
container:
# UBI 8 provides the glibc 2.28 baseline required by manylinux_2_28.
image: "nvidia/cuda:${{ matrix.cuda == 'cu129' && '12.9.0' || '13.0.0' }}-devel-ubi8"

name: wheel / py3-none-any
runs-on: ubuntu-latest
steps:
- name: Free disk space
run: |
rm -rf /opt/hostedtoolcache /usr/local/lib/android /usr/share/dotnet \
/usr/local/share/boost /opt/ghc 2>/dev/null || true
dnf clean all 2>/dev/null || true
df -h / || true

- name: Install system dependencies
run: |
dnf install -y \
git \
gcc-toolset-13-gcc \
gcc-toolset-13-gcc-c++ \
python3.12 \
python3.12-devel \
python3.12-pip
dnf clean all

- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
submodules: recursive

- name: Configure git safe directory
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

- name: Install Python dependencies
run: |
python3.12 -m pip install --no-cache-dir --upgrade pip
python3.12 -m pip install --no-cache-dir torch==2.9.1 --index-url ${{ matrix.cuda == 'cu129' && 'https://download.pytorch.org/whl/cu129' || 'https://download.pytorch.org/whl/cu130' }}
python3.12 -m pip install --no-cache-dir setuptools wheel "setuptools_scm>=6.0" build ninja auditwheel patchelf
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"

- name: Expose PyTorch CUDA libraries
# The nvidia/cuda devel image ships the CUDA toolkit but not cuDNN.
# torch's pip wheels bundle cuDNN inside site-packages/nvidia/*/lib/,
# which is not on the linker search path — add it so torch._C can load.
run: |
LIB_DIRS="$(python3.12 <<'EOF'
import glob, os, site
dirs = []
for sp in site.getsitepackages():
for p in [os.path.join(sp, "torch", "lib")] + glob.glob(os.path.join(sp, "nvidia", "*", "lib")):
if os.path.isdir(p):
dirs.append(p)
print(":".join(dirs))
EOF
)"
echo "LD_LIBRARY_PATH=${LIB_DIRS}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" >> "$GITHUB_ENV"
- name: Install build tools
run: python -m pip install --upgrade build setuptools wheel setuptools_scm

- name: Compute version
id: version
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
BASE="${GITHUB_REF#refs/tags/v}"
else
# Strip any local segment (+gXXX) so we get a clean base
BASE=$(python3.12 -c "from setuptools_scm import get_version; print(get_version().split('+')[0])")
BASE=$(python -c "from setuptools_scm import get_version; print(get_version().split('+')[0])")
fi
echo "version=${BASE}+${{ matrix.cuda }}" >> "$GITHUB_OUTPUT"
echo "version=${BASE}" >> "$GITHUB_OUTPUT"

- name: Build fat-binary wheel
- name: Build wheel
env:
CC: /opt/rh/gcc-toolset-13/root/usr/bin/gcc
CXX: /opt/rh/gcc-toolset-13/root/usr/bin/g++
CUDAHOSTCXX: /opt/rh/gcc-toolset-13/root/usr/bin/g++
CULA_BUILD_ALL_ARCHS: "1"
SETUPTOOLS_SCM_PRETEND_VERSION: "${{ steps.version.outputs.version }}"
NVCC_THREADS: "4"
MAX_JOBS: "4"
run: |
"$CC" --version
"$CXX" --version
python3.12 -m build --wheel --no-isolation --outdir dist-raw

- name: Repair wheel for manylinux_2_28
run: |
# These libraries are supplied by the NVIDIA driver, PyTorch, or
# PyTorch's CUDA runtime dependency and must remain external.
python3.12 -m auditwheel repair \
--plat manylinux_2_28_${{ matrix.arch }} \
--exclude libcuda.so.1 \
--exclude 'libcudart.so.*' \
--exclude 'libc10*.so' \
--exclude 'libtorch*.so' \
--wheel-dir dist \
dist-raw/*.whl
run: python -m build --wheel --outdir dist

- name: Verify wheel
shell: bash
run: |
echo "Built wheel:"
ls -lh dist/*.whl
ls dist/*.whl | grep -q "+${{ matrix.cuda }}" \
|| { echo "ERROR: wheel name missing +${{ matrix.cuda }} suffix"; exit 1; }
ls dist/*.whl | grep -q "manylinux_2_28_${{ matrix.arch }}" \
|| { echo "ERROR: wheel is not tagged manylinux_2_28_${{ matrix.arch }}"; exit 1; }
python3.12 -m auditwheel show dist/*.whl
python -m pip install --no-deps dist/*.whl
python -c "import cula; print(cula.__version__)"
ls dist/*.whl | grep -q -- '-py3-none-any.whl$' \
|| { echo "ERROR: wheel is not platform-independent"; exit 1; }

- name: Upload wheel artifact
uses: actions/upload-artifact@v6
with:
name: wheel-${{ matrix.cuda }}-${{ matrix.arch }}
name: wheel-py3-none-any
path: dist/*.whl

release:
Expand All @@ -143,16 +66,15 @@ jobs:
permissions:
contents: write
steps:
- name: Download all artifacts
- name: Download wheel
uses: actions/download-artifact@v6
with:
path: artifacts/

- name: Create release
uses: softprops/action-gh-release@v3
with:
files: |
artifacts/wheel-*/*.whl
files: artifacts/wheel-py3-none-any/*.whl
generate_release_notes: true
draft: true
prerelease: ${{ contains(github.ref, 'rc') || contains(github.ref, 'beta') || contains(github.ref, 'alpha') }}
11 changes: 0 additions & 11 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ concurrency:
cancel-in-progress: true

jobs:
clang-format:
name: clang-format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: j178/prek-action@v2
with:
install-only: true
- name: Check clang-format
run: prek run clang-format --all-files --show-diff-on-failure --color=always

ruff:
name: Ruff
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "csrc/cutlass"]
path = csrc/cutlass
url = https://github.com/NVIDIA/cutlass.git
[submodule "third_party/flash-linear-attention"]
path = third_party/flash-linear-attention
url = https://github.com/fla-org/flash-linear-attention.git
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v15.0.7
hooks:
- id: clang-format
files: ^csrc/
types_or: [c, c++, cuda]
exclude: ^csrc/(cutlass|kerutils)/

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.0
hooks:
Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ include LICENSE
include pyproject.toml
include setup.py

recursive-include csrc *.h *.hpp *.cuh *.cu *.cpp *.cc
recursive-include csrc/cutlass *
recursive-include cula *.py
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# cuLA — CUDA Linear Attention

**High-performance CUDA kernels for linear attention variants, written in [CuTe DSL](https://github.com/NVIDIA/cutlass/tree/main/python/CuTeDSL) and CUTLASS C++.**
**High-performance CUDA kernels for linear attention variants, written entirely in [CuTe DSL](https://github.com/NVIDIA/cutlass/tree/main/python/CuTeDSL).**

</div>

Expand All @@ -20,17 +20,21 @@ Linear attention mechanisms reformulate standard attention to use linear-time st

cuLA supports both **Hopper (SM90)** and **Blackwell (SM10X)** GPUs.

> **Requirements (Hopper & Blackwell):** Python 3.12+, CUDA Toolkit 12.9+, PyTorch 2.9.1+. Building the optional SM90 native extension also requires NVCC.
> **Requirements (Hopper & Blackwell):** Python 3.12+, CUDA Toolkit 12.9+, PyTorch 2.8.0+, and a matching `nvidia-cutlass-dsl` installation. cuLA does not build a C++/CUDA extension.
Comment thread
icavan marked this conversation as resolved.
Resolved

> **Note:** The PyTorch CUDA version must match your system CUDA Toolkit version. Check with `nvcc --version` and `python -c "import torch; print(torch.version.cuda)"`.

### Pre-built Wheels

Pre-built wheels with the SM90 native extension and CuTeDSL JIT kernels for SM100/SM103 are available on [GitHub Releases](https://github.com/inclusionAI/cuLA/releases). Linux wheels target `manylinux_2_28` and require glibc 2.28 or newer:
Platform-independent wheels containing the CuTeDSL sources are available on [GitHub Releases](https://github.com/inclusionAI/cuLA/releases):

pip install "cuda-linear-attention==<VERSION>+<CUDA_TAG>" -f https://github.com/inclusionAI/cuLA/releases/expanded_assets/<TAG>
pip install "cuda-linear-attention==<VERSION>" -f https://github.com/inclusionAI/cuLA/releases/expanded_assets/<TAG>
Comment thread
icavan marked this conversation as resolved.
Resolved

Replace `<TAG>` with the release tag (e.g., `v0.2.0`), `<VERSION>` with the base version (e.g., `0.2.0`), and `<CUDA_TAG>` with your PyTorch CUDA build tag (e.g., `cu129` or `cu130`). Or download the `.whl` file directly from the [Releases page](https://github.com/inclusionAI/cuLA/releases) and install it with `pip install <filename>.whl`.
Replace `<TAG>` with the release tag (e.g., `v0.2.0`) and `<VERSION>` with the version (e.g., `0.2.0`). Or download the `.whl` file directly from the [Releases page](https://github.com/inclusionAI/cuLA/releases) and install it with `pip install <filename>.whl`.

The cuLA wheel does not install FLA. Install `flash-linear-attention` before importing `chunk_kda`:

pip install flash-linear-attention

### Build from Source

Expand All @@ -41,10 +45,20 @@ git clone https://github.com/inclusionAI/cuLA.git
git submodule update --init --recursive
```

**Install PyTorch:**
**Install PyTorch and CuTeDSL:**

For CUDA 12.9:

```bash
pip install torch==2.8.0 --index-url https://download.pytorch.org/whl/cu129
pip install 'nvidia-cutlass-dsl>=4.6.2,<4.9'
```

For CUDA 13:

```bash
pip install torch==2.9.1 --index-url https://download.pytorch.org/whl/cu129
pip install torch==2.9.1 --index-url https://download.pytorch.org/whl/cu130
pip install 'nvidia-cutlass-dsl[cu13]>=4.6.2,<4.9'
```

**Install cuLA & dependencies:**
Expand All @@ -57,10 +71,10 @@ pip install -e third_party/flash-linear-attention
pip install -e . --no-build-isolation
```

**Build a wheel with the SM90 extension (SM100/SM103 use CuTeDSL JIT):**
**Build the platform-independent wheel:**

```bash
CULA_BUILD_ALL_ARCHS=1 python -m build --wheel --no-isolation
python -m build --wheel
```

## Quick Start
Expand Down
Loading
Loading