Skip to content

Commit 01cd312

Browse files
committed
Import kernel-builder
1 parent 1e29e01 commit 01cd312

282 files changed

Lines changed: 52152 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: "Build and test kernel"
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
types: [opened, synchronize, reopened] # trigger on PRs
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
name: Build kernels
13+
runs-on:
14+
group: aws-highmemory-32-plus-nix
15+
steps:
16+
- uses: actions/checkout@v6
17+
- uses: DeterminateSystems/nix-installer-action@main
18+
with:
19+
extra-conf: |
20+
max-jobs = 4
21+
cores = 12
22+
sandbox-fallback = false
23+
- uses: cachix/cachix-action@v16
24+
with:
25+
name: huggingface
26+
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
27+
env:
28+
USER: runner
29+
- name: Nix info
30+
run: nix-shell -p nix-info --run "nix-info -m"
31+
- name: Build relu kernel
32+
run: ( cd examples/relu && nix build .\#redistributable.torch29-cxx11-cu126-x86_64-linux )
33+
- name: Copy relu kernel
34+
run: cp -rL examples/relu/result relu-kernel
35+
36+
- name: Build relu kernel (CPU)
37+
run: ( cd examples/relu && nix build .\#redistributable.torch29-cxx11-cpu-x86_64-linux )
38+
- name: Copy relu kernel (CPU)
39+
run: cp -rL examples/relu/result relu-kernel-cpu
40+
41+
- name: Build cutlass GEMM kernel
42+
run: ( cd examples/cutlass-gemm && nix build .\#redistributable.torch29-cxx11-cu126-x86_64-linux )
43+
- name: Copy cutlass GEMM kernel
44+
run: cp -rL examples/cutlass-gemm/result cutlass-gemm-kernel
45+
46+
- name: Build relu-backprop-compile kernel
47+
run: ( cd examples/relu-backprop-compile && nix build .\#redistributable.torch29-cxx11-cu126-x86_64-linux )
48+
- name: Copy relu-backprop-compile kernel
49+
run: cp -rL examples/relu-backprop-compile/result relu-backprop-compile-kernel
50+
51+
# Just test that we build with the extra torchVersions argument.
52+
- name: Build relu kernel (specific Torch version)
53+
run: ( cd examples/relu-specific-torch && nix build . )
54+
55+
- name: Build relu kernel (compiler flags)
56+
run: ( cd examples/relu-compiler-flags && nix build .\#redistributable.torch29-cxx11-cu126-x86_64-linux )
57+
58+
- name: Test that we can build a test shell (e.g. that gcc corresponds to CUDA-required)
59+
run: ( cd examples/relu && nix build .#devShells.x86_64-linux.test )
60+
61+
- name: Build silu-and-mul kernel
62+
run: ( cd examples/silu-and-mul && nix build .\#redistributable.torch-cuda )
63+
- name: Copy silu-and-mul kernel
64+
run: cp -rL examples/silu-and-mul/result silu-and-mul-kernel
65+
66+
- name: Upload kernel artifacts
67+
uses: actions/upload-artifact@v6
68+
with:
69+
name: built-kernels
70+
path: |
71+
activation-kernel
72+
cutlass-gemm-kernel
73+
relu-kernel
74+
relu-kernel-cpu
75+
relu-backprop-compile-kernel
76+
silu-and-mul-kernel
77+
78+
test:
79+
name: Test kernels
80+
needs: build
81+
runs-on:
82+
group: aws-g6-12xlarge-plus
83+
steps:
84+
- uses: actions/checkout@v6
85+
86+
- name: Download kernel artifacts
87+
uses: actions/download-artifact@v7
88+
with:
89+
name: built-kernels
90+
path: .
91+
92+
- name: Set up Docker Buildx
93+
uses: docker/setup-buildx-action@v3
94+
- name: Build Docker image
95+
uses: docker/build-push-action@v6
96+
with:
97+
context: .
98+
file: tests/Dockerfile.test-kernel
99+
platforms: linux/amd64
100+
load: true
101+
push: false
102+
tags: kernel-builder:latest
103+
104+
- name: Run Tests
105+
run: |
106+
docker run --gpus all kernel-builder:latest
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "Build and test kernel (macOS)"
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
types: [opened, synchronize, reopened] # trigger on PRs
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
name: Build kernel
13+
runs-on: macos-26
14+
steps:
15+
- name: "Select Xcode"
16+
run: sudo xcrun xcode-select -s /Applications/Xcode_26.0.app
17+
- name: "Install Metal Toolchain"
18+
run: xcodebuild -downloadComponent metalToolchain
19+
- uses: actions/checkout@v6
20+
- uses: cachix/install-nix-action@v31
21+
- uses: cachix/cachix-action@v15
22+
with:
23+
name: huggingface
24+
#authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
25+
# For now we only test that there are no regressions in building macOS
26+
# kernels. Also run tests once we have a macOS runner.
27+
- name: Build relu kernel
28+
run: ( cd examples/relu && nix build .\#redistributable.torch29-metal-aarch64-darwin -L )
29+
30+
- name: Build relu metal cpp kernel
31+
run: ( cd examples/relu-metal-cpp && nix build .\#redistributable.torch29-metal-aarch64-darwin -L )
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "Build and test kernel (ROCm)"
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
types: [opened, synchronize, reopened] # trigger on PRs
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
name: Build kernel
13+
runs-on:
14+
group: aws-highmemory-32-plus-nix
15+
steps:
16+
- uses: actions/checkout@v6
17+
- uses: DeterminateSystems/nix-installer-action@main
18+
with:
19+
extra-conf: |
20+
max-jobs = 4
21+
cores = 12
22+
sandbox-fallback = false
23+
- uses: cachix/cachix-action@v14
24+
with:
25+
name: huggingface
26+
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
27+
env:
28+
USER: runner
29+
- name: Nix info
30+
run: nix-shell -p nix-info --run "nix-info -m"
31+
# For now we only test that there are no regressions in building ROCm
32+
# kernels. Also run tests once we have a ROCm runner.
33+
- name: Build relu kernel
34+
run: ( cd examples/relu && nix build .\#redistributable.torch29-cxx11-rocm63-x86_64-linux -L )
35+
36+
- name: Build relu kernel (compiler flags)
37+
run: ( cd examples/relu-compiler-flags && nix build .\#redistributable.torch29-cxx11-rocm63-x86_64-linux )
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: "Build and test kernel - Windows"
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
types: [opened, synchronize, reopened] # trigger on PRs
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
strategy:
13+
matrix:
14+
os: [ windows-2022 ]
15+
python: [ 3.12 ]
16+
torch: [
17+
# { version: '2.9.1', cuda: '12.6.3', wheel: '126' },
18+
{ version: '2.9.1', cuda: '12.8.1', wheel: '128' },
19+
# { version: '2.9.1', cuda: '13.0.1', wheel: '130' }
20+
]
21+
22+
name: Build kernel
23+
runs-on: ${{ matrix.os }}
24+
25+
steps:
26+
- uses: actions/cache@v5
27+
with:
28+
key: cuda-toolkit-v${{ matrix.cuda }}-${{ matrix.os }}
29+
path: |
30+
C:\Program Files\NVIDIA GPU Computing Toolkit
31+
~/.cargo/registry
32+
~/.cargo/git
33+
34+
- uses: actions/checkout@v6
35+
36+
# CUDA environment setup
37+
- uses: Jimver/cuda-toolkit@v0.2.29
38+
id: setup-cuda-toolkit
39+
with:
40+
cuda: ${{ matrix.torch.cuda }} # TODO(mfuntowicz): How can we test multiple CUDA versions than align with torch?
41+
- name: "NVCC checks"
42+
run: nvcc -V
43+
44+
# Rust build environment setup
45+
- uses: actions-rs/toolchain@v1
46+
with:
47+
toolchain: stable
48+
profile: minimal
49+
override: true
50+
51+
- name: Build build2cmake
52+
run: ( cd build2cmake && cargo build --release )
53+
54+
# Python environment setup
55+
- uses: actions/setup-python@v6
56+
with:
57+
python-version: ${{ matrix.python }}
58+
cache: 'pip'
59+
60+
- name: Install PyTorch
61+
run: pip install torch --index-url https://download.pytorch.org/whl/cu${{ matrix.torch.wheel }}
62+
63+
- name: Build cutlass GEMM kernel
64+
run: ( scripts\windows\builder.ps1 -SourceFolder examples/cutlass-gemm -BuildConfig Release -Backend cuda -Build -Force )
65+
# - name: Copy cutlass GEMM kernel
66+
# run: cp -rL examples/cutlass-gemm/result cutlass-gemm-kernel
67+
68+
- name: Build relu kernel
69+
run: ( scripts\windows\builder.ps1 -SourceFolder examples/relu -BuildConfig Release -Backend cuda -Build -Force )
70+
# - name: Copy relu kernel
71+
# run: cp -rL examples/relu/result relu-kernel
72+
73+
- name: Build relu-backprop-compile kernel
74+
run: ( scripts\windows\builder.ps1 -SourceFolder examples/relu-backprop-compile -BuildConfig Release -Backend cuda -Build -Force )
75+
# - name: Copy relu-backprop-compile kernel
76+
# run: cp -rL examples/relu-backprop-compile/result relu-backprop-compile-kernel
77+
78+
# Just test that we build with the extra torchVersions argument.
79+
# - name: Build relu kernel (specific Torch version)
80+
# run: ( cd examples/relu-specific-torch && nix build . )
81+
82+
- name: Build silu-and-mul kernel
83+
run: ( scripts\windows\builder.ps1 -SourceFolder examples/silu-and-mul -BuildConfig Release -Backend cuda -Build -Force)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "Build and test kernel (XPU)"
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
types: [opened, synchronize, reopened] # trigger on PRs
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
name: Build kernel
13+
runs-on:
14+
group: aws-highmemory-32-plus-nix
15+
steps:
16+
- uses: actions/checkout@v6
17+
- uses: DeterminateSystems/nix-installer-action@main
18+
with:
19+
extra-conf: |
20+
max-jobs = 4
21+
cores = 12
22+
sandbox-fallback = false
23+
- uses: cachix/cachix-action@v16
24+
with:
25+
name: huggingface
26+
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
27+
env:
28+
USER: runner
29+
- name: Nix info
30+
run: nix-shell -p nix-info --run "nix-info -m"
31+
# For now we only test that there are no regressions in building XPU
32+
# kernels. Also run tests once we have a XPU runner.
33+
- name: Build relu kernel
34+
run: ( cd examples/relu && nix build .\#redistributable.torch29-cxx11-xpu20252-x86_64-linux -L )
35+
36+
- name: Build relu kernel (compiler flags)
37+
run: ( cd examples/relu-compiler-flags && nix build .\#redistributable.torch29-cxx11-xpu20252-x86_64-linux )
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Check build variants"
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
types: [opened, synchronize, reopened] # trigger on PRs
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
name: Check build variants
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v6
16+
- uses: cachix/install-nix-action@v27
17+
with:
18+
nix_path: nixpkgs=channel:nixos-unstable
19+
- name: Generate variants JSON
20+
run: nix eval --raw .#lib.allBuildVariantsJSON | nix run nixpkgs#jq 'walk(if type == "array" then sort else . end)' > build-variants.json
21+
- name: Check if variants JSON is up-to-date
22+
run: |
23+
if git diff --exit-code build-variants.json; then
24+
echo "✅ variants.json is up-to-date"
25+
else
26+
echo "🛑 regenerate variants.json: nix eval --raw .#lib.allBuildVariantsJSON | nix run nixpkgs#jq 'walk(if type == "array" then sort else . end)' > build-variants.json"
27+
exit 1
28+
fi
29+
- name: Generate variants Markdown
30+
run: nix run nixpkgs#python3 scripts/gen_variants_markdown.py
31+
- name: Check if variants Markdown is up-to-date
32+
run: |
33+
if git diff --exit-code docs/build-variants.md; then
34+
echo "✅ docs/build-variants.md is up-to-date"
35+
else
36+
echo "🛑 regenerate docs/build-variants: nix run nixpkgs#python3 scripts/gen_variants_markdown.py"
37+
exit 1
38+
fi

0 commit comments

Comments
 (0)