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
36 changes: 18 additions & 18 deletions .github/workflows/build_kernel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,49 @@ jobs:
run: nix-shell -p nix-info --run "nix-info -m"

- name: Build relu kernel
run: ( cd builder/examples/relu && nix build .\#redistributable.torch29-cxx11-cu126-${{ matrix.arch }} )
run: ( cd examples/kernels/relu && nix build .\#redistributable.torch29-cxx11-cu126-${{ matrix.arch }} )
- name: Copy relu kernel
run: cp -rL builder/examples/relu/result relu-kernel
run: cp -rL examples/kernels/relu/result relu-kernel

- name: Build relu-tvm-ffi kernel
run: ( cd builder/examples/relu-tvm-ffi && nix build .\#redistributable.tvm-ffi01-cu126-${{ matrix.arch }} )
run: ( cd examples/kernels/relu-tvm-ffi && nix build .\#redistributable.tvm-ffi01-cu126-${{ matrix.arch }} )
- name: Copy relu-tvm-ffi kernel
run: cp -rL builder/examples/relu-tvm-ffi/result relu-tvm-ffi-kernel
run: cp -rL examples/kernels/relu-tvm-ffi/result relu-tvm-ffi-kernel

- name: Build extra-data kernel
run: ( cd builder/examples/extra-data && nix build .\#redistributable.torch29-cxx11-cu126-${{ matrix.arch }} )
run: ( cd examples/kernels/extra-data && nix build .\#redistributable.torch29-cxx11-cu126-${{ matrix.arch }} )
- name: Copy extra-data kernel
run: cp -rL builder/examples/extra-data/result extra-data
run: cp -rL examples/kernels/extra-data/result extra-data

- name: Build relu kernel (CPU)
run: ( cd builder/examples/relu && nix build .\#redistributable.torch29-cxx11-cpu-${{ matrix.arch }} )
run: ( cd examples/kernels/relu && nix build .\#redistributable.torch29-cxx11-cpu-${{ matrix.arch }} )
- name: Copy relu kernel (CPU)
run: cp -rL builder/examples/relu/result relu-kernel-cpu
run: cp -rL examples/kernels/relu/result relu-kernel-cpu

- name: Build cutlass GEMM kernel
run: ( cd builder/examples/cutlass-gemm && nix build .\#redistributable.torch29-cxx11-cu126-${{ matrix.arch }} )
run: ( cd examples/kernels/cutlass-gemm && nix build .\#redistributable.torch29-cxx11-cu126-${{ matrix.arch }} )
- name: Copy cutlass GEMM kernel
run: cp -rL builder/examples/cutlass-gemm/result cutlass-gemm-kernel
run: cp -rL examples/kernels/cutlass-gemm/result cutlass-gemm-kernel

- name: Build relu-backprop-compile kernel
run: ( cd builder/examples/relu-backprop-compile && nix build .\#redistributable.torch29-cxx11-cu126-${{ matrix.arch }} )
run: ( cd examples/kernels/relu-backprop-compile && nix build .\#redistributable.torch29-cxx11-cu126-${{ matrix.arch }} )
- name: Copy relu-backprop-compile kernel
run: cp -rL builder/examples/relu-backprop-compile/result relu-backprop-compile-kernel
run: cp -rL examples/kernels/relu-backprop-compile/result relu-backprop-compile-kernel

# Just test that we build with the extra torchVersions argument.
- name: Build relu kernel (specific Torch version)
run: ( cd builder/examples/relu-specific-torch && nix build . )
run: ( cd examples/kernels/relu-specific-torch && nix build . )

- name: Build relu kernel (compiler flags)
run: ( cd builder/examples/relu-compiler-flags && nix build .\#redistributable.torch29-cxx11-cu126-${{ matrix.arch }} )
run: ( cd examples/kernels/relu-compiler-flags && nix build .\#redistributable.torch29-cxx11-cu126-${{ matrix.arch }} )

- name: Test that we can build a test shell (e.g. that gcc corresponds to CUDA-required)
run: ( cd builder/examples/relu && nix build .#devShells.${{ matrix.arch }}.test )
run: ( cd examples/kernels/relu && nix build .#devShells.${{ matrix.arch }}.test )

- name: Build silu-and-mul kernel
run: ( cd builder/examples/silu-and-mul && nix build .\#redistributable.torch-cuda )
run: ( cd examples/kernels/silu-and-mul && nix build .\#redistributable.torch-cuda )
- name: Copy silu-and-mul kernel
run: cp -rL builder/examples/silu-and-mul/result silu-and-mul-kernel
run: cp -rL examples/kernels/silu-and-mul/result silu-and-mul-kernel

- name: Upload kernel artifacts
uses: actions/upload-artifact@v6
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: builder/tests/Dockerfile.test-kernel
file: nix-builder/tests/Dockerfile.test-kernel
platforms: linux/amd64
load: true
push: false
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build_kernel_macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
# For now we only test that there are no regressions in building macOS
# kernels. Also run tests once we have a macOS runner.
- name: Build relu kernel
run: ( cd builder/examples/relu && nix build .\#redistributable.torch29-metal-aarch64-darwin -L )
run: ( cd examples/kernels/relu && nix build .\#redistributable.torch29-metal-aarch64-darwin -L )

- name: Build relu metal cpp kernel
run: ( cd builder/examples/relu-metal-cpp && nix build .\#redistributable.torch29-metal-aarch64-darwin -L )
run: ( cd examples/kernels/relu-metal-cpp && nix build .\#redistributable.torch29-metal-aarch64-darwin -L )
4 changes: 2 additions & 2 deletions .github/workflows/build_kernel_rocm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# For now we only test that there are no regressions in building ROCm
# kernels. Also run tests once we have a ROCm runner.
- name: Build relu kernel
run: ( cd builder/examples/relu && nix build .\#redistributable.torch29-cxx11-rocm63-x86_64-linux -L )
run: ( cd examples/kernels/relu && nix build .\#redistributable.torch29-cxx11-rocm63-x86_64-linux -L )

- name: Build relu kernel (compiler flags)
run: ( cd builder/examples/relu-compiler-flags && nix build .\#redistributable.torch29-cxx11-rocm63-x86_64-linux )
run: ( cd examples/kernels/relu-compiler-flags && nix build .\#redistributable.torch29-cxx11-rocm63-x86_64-linux )
12 changes: 6 additions & 6 deletions .github/workflows/build_kernel_windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:
profile: minimal
override: true

- name: Build build2cmake
run: ( cd build2cmake && cargo build --release )
- name: Build kernel-builder
run: ( cd kernel-builder && cargo build --release )

# Python environment setup
- uses: actions/setup-python@v6
Expand All @@ -64,13 +64,13 @@ jobs:
run: pip install torch --index-url https://download.pytorch.org/whl/cu${{ matrix.torch.wheel }}

- name: Build cutlass GEMM kernel
run: ( builder\scripts\windows\builder.ps1 -SourceFolder builder/examples/cutlass-gemm -BuildConfig Release -Backend cuda -Build -Force )
run: ( builder\scripts\windows\builder.ps1 -SourceFolder examples/kernels/cutlass-gemm -BuildConfig Release -Backend cuda -Build -Force )

- name: Build relu kernel
run: ( builder\scripts\windows\builder.ps1 -SourceFolder builder/examples/relu -BuildConfig Release -Backend cuda -Build -Force )
run: ( builder\scripts\windows\builder.ps1 -SourceFolder examples/kernels/relu -BuildConfig Release -Backend cuda -Build -Force )

- name: Build relu-backprop-compile kernel
run: ( builder\scripts\windows\builder.ps1 -SourceFolder builder/examples/relu-backprop-compile -BuildConfig Release -Backend cuda -Build -Force )
run: ( builder\scripts\windows\builder.ps1 -SourceFolder examples/kernels/relu-backprop-compile -BuildConfig Release -Backend cuda -Build -Force )

- name: Build silu-and-mul kernel
run: ( builder\scripts\windows\builder.ps1 -SourceFolder builder/examples/silu-and-mul -BuildConfig Release -Backend cuda -Build -Force)
run: ( builder\scripts\windows\builder.ps1 -SourceFolder examples/kernels/silu-and-mul -BuildConfig Release -Backend cuda -Build -Force)
6 changes: 3 additions & 3 deletions .github/workflows/build_kernel_xpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
# For now we only test that there are no regressions in building XPU
# kernels. Also run tests once we have a XPU runner.
- name: Build relu kernel
run: ( cd builder/examples/relu && nix build .\#redistributable.torch29-cxx11-xpu20252-x86_64-linux -L )
run: ( cd examples/kernels/relu && nix build .\#redistributable.torch29-cxx11-xpu20252-x86_64-linux -L )

- name: Build relu kernel (compiler flags)
run: ( cd builder/examples/relu-compiler-flags && nix build .\#redistributable.torch29-cxx11-xpu20252-x86_64-linux )
run: ( cd examples/kernels/relu-compiler-flags && nix build .\#redistributable.torch29-cxx11-xpu20252-x86_64-linux )

- name: Build cutlass-gemm kernel
run: ( cd builder/examples/cutlass-gemm && nix build .\#redistributable.torch29-cxx11-xpu20252-x86_64-linux -L )
run: ( cd examples/kernels/cutlass-gemm && nix build .\#redistributable.torch29-cxx11-xpu20252-x86_64-linux -L )
10 changes: 5 additions & 5 deletions .github/workflows/check_variants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ jobs:
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Generate variants JSON
run: nix eval --raw .#lib.allBuildVariantsJSON | nix run nixpkgs#jq 'walk(if type == "array" then sort else . end)' > builder/build-variants.json
run: nix eval --raw .#lib.allBuildVariantsJSON | nix run nixpkgs#jq 'walk(if type == "array" then sort else . end)' > nix-builder/build-variants.json
- name: Check if variants JSON is up-to-date
run: |
if git diff --exit-code builder/build-variants.json; then
if git diff --exit-code nix-builder/build-variants.json; then
echo "✅ variants.json is up-to-date"
else
echo "🛑 regenerate variants.json: nix eval --raw .#lib.allBuildVariantsJSON | nix run nixpkgs#jq 'walk(if type == "array" then sort else . end)' > builder/build-variants.json"
echo "🛑 regenerate variants.json: nix eval --raw .#lib.allBuildVariantsJSON | nix run nixpkgs#jq 'walk(if type == "array" then sort else . end)' > nix-builder/build-variants.json"
exit 1
fi
- name: Generate variants Markdown
run: nix run nixpkgs#python3 builder/scripts/gen_variants_markdown.py
run: nix run nixpkgs#python3 nix-builder/scripts/gen_variants_markdown.py
- name: Check if variants Markdown is up-to-date
run: |
if git diff --exit-code docs/source/builder/build-variants.md; then
echo "✅ docs/source/buidler/build-variants.md is up-to-date"
else
echo "🛑 regenerate docs/build-variants: nix run nixpkgs#python3 builder/scripts/gen_variants_markdown.py"
echo "🛑 regenerate docs/build-variants: nix run nixpkgs#python3 nix-builder/scripts/gen_variants_markdown.py"
exit 1
fi
8 changes: 4 additions & 4 deletions .github/workflows/docker-build-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
- main
paths:
# Only run on changes to the Dockerfile or workflow file
- "buidler/Dockerfile"
- "builder/dockerfiles/**"
- "nix-buidler/Dockerfile"
- "nix-builder/dockerfiles/**"
- ".github/workflows/docker-build-push.yaml"
workflow_dispatch: # Allow manual triggering

Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: ./builder/dockerfiles/Dockerfile.user
file: ./nix-builder/dockerfiles/Dockerfile.user
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: ./builder/dockerfiles/Dockerfile
file: ./nix-builder/dockerfiles/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta-root.outputs.tags }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
run: |
( cd kernel-abi-check/kernel-abi-check && cargo fmt --all -- --check )
( cd kernel-abi-check/bindings/python && cargo fmt --all -- --check )
- name: Cargo fmt (build2cmake)
run: ( cd build2cmake && cargo fmt --all -- --check )
- name: Cargo fmt (kernel-builder)
run: ( cd kernel-builder && cargo fmt --all -- --check )

clippy:
name: Clippy
Expand All @@ -39,5 +39,5 @@ jobs:
run: |
( cd kernel-abi-check/kernel-abi-check && cargo clippy -- -D warnings )
( cd kernel-abi-check/bindings/python && cargo clippy -- -D warnings )
- name: Clippy (build2cmake)
run: ( cd build2cmake && cargo clippy -- -D warnings )
- name: Clippy (kernel-builder)
run: ( cd kernel-builder && cargo clippy -- -D warnings )
2 changes: 1 addition & 1 deletion .github/workflows/test_extra_commands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
env:
USER: runner
- name: Test nix run .#kernels
run: ( cd builder/examples/relu ; nix run .#kernels -- lock ../../tests/run-kernels )
run: ( cd examples/kernels/relu ; nix run .#kernels -- lock ../../../nix-builder/tests/run-kernels )
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ mamba/
poetry.lock

# Nix
builder/examples/**/flake.lock
examples/kernels/**/flake.lock
2 changes: 1 addition & 1 deletion docs/source/builder/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The kernel builder includes a command-line interface for easier interaction. The
# Build the example relu kernel from the root of the repository
docker run --rm \
-v $(pwd):/kernel-builder \
-w /kernel-builder/examples/relu \
-w /kernel-builder/examples/kernels/relu \
ghcr.io/huggingface/kernel-builder:main \
build

Expand Down
18 changes: 9 additions & 9 deletions docs/source/builder/local-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ with older C library versions and avoiding accidental dependencies.
However, this is not ideal during kernel development, since language
servers and IDEs do not interpret the `build.toml` file. As a result,
code completion will typically not work. `kernel-builder` provides the
`build2cmake` utility to generate CMake files to build native code and
`kernel-builder` utility to generate CMake files to build native code and
setuptools files for building the kernel as a regular Python package.
Since CMake and setuptools are widely supported by IDEs, this provides
a much-improved development experience.

## Installing `build2cmake`
## Installing `kernel-builder`

`build2cmake` is available as a Rust crate. After [installing Rust](https://rustup.rs),
`kernel-builder` is available as a Rust crate. After [installing Rust](https://rustup.rs),
it can be built and installed as follows:

```bash
$ cargo install build2cmake
$ cargo install hf-kernel-builder
```

## Generating a Python project with `build2cmake`
## Generating a Python project with `kernel-builder`

`build2cmake` generates a CMake/Python project from a [`build.toml`](./writing-kernels.md)
`kernel-builder` generates a CMake/Python project from a [`build.toml`](./writing-kernels.md)
file. The invocation is as follows:

```bash
$ build2cmake generate build.toml -f
$ kernel-builder generate build.toml -f
```

The `-f` flag is optional and instructs `build2cmake` to overwrite
The `-f` flag is optional and instructs `kernel-builder` to overwrite
existing files.

It is recommended to do an editable install of the generated project into
Expand All @@ -47,7 +47,7 @@ $ pip install --no-build-isolation -e .

- Kernels built in this way should **not** be published on the Kernel
Hub. They do not fulfill the [kernel requirements](../kernel-requirements.md).
- Do not add the generated files to Git. `build2cmake` has regular updates
- Do not add the generated files to Git. `kernel-builder` has regular updates
and you generally want to use files generated by the latest version.

## Testing kernel builds before publishing
Expand Down
8 changes: 4 additions & 4 deletions docs/source/builder/nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ We recommend installing Nix in the following way:

The easiest way get all the Nix functionality is by putting a
`flake.nix` in your kernel repository. To do so, copy
[`examples/relu/flake.nix`](https://github.com/huggingface/kernels/blob/main/builder/examples/relu/flake.nix) into the
[`examples/relu/flake.nix`](https://github.com/huggingface/kernels/blob/main/examples/kernels/relu/flake.nix) into the
same directory as your `build.toml` file. Then run `nix flake update`.
This generates a `flake.lock` file that pins the kernel builder
and _all_ its transitive dependencies. Commit both `flake.nix`
Expand Down Expand Up @@ -57,12 +57,12 @@ The compiled kernel will then be in the local `build/` directory.
## Shell for local development

`kernel-builder` provides shells for developing kernels. In such a shell,
all required dependencies are available, as well as `build2cmake` for generating
all required dependencies are available, as well as `kernel-builder` for generating
project files. For example:

```bash
$ nix develop
$ build2cmake generate build.toml
$ kernel-builder generate build.toml
$ cmake -B build-ext
$ cmake --build build-ext
```
Expand All @@ -74,7 +74,7 @@ Python package in this virtual environment:

```bash
$ nix develop
$ build2cmake generate build.toml
$ kernel-builder generate build.toml
$ pip install --no-build-isolation -e .
```

Expand Down
4 changes: 2 additions & 2 deletions docs/source/builder/writing-kernels.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ of CMake or setuptools.

This page describes the directory layout of a kernel-builder project, the
format of the `build.toml` file, and some additional Python glue that
`kernel-builder` provides. We will use a [simple ReLU kernel](https://github.com/huggingface/kernels/tree/main/builder/examples/relu)
`kernel-builder` provides. We will use a [simple ReLU kernel](https://github.com/huggingface/kernels/tree/main/examples/kernels/relu)
as the running example. After reading this page, you may also want to have
a look at the more realistic [ReLU kernel with backprop and `torch.compile`](https://github.com/huggingface/kernels/tree/main/builder/examples/relu-backprop-compile)
a look at the more realistic [ReLU kernel with backprop and `torch.compile`](https://github.com/huggingface/kernels/tree/main/examples/kernels/relu-backprop-compile)
support.

## Setting up environment
Expand Down
File renamed without changes.
File renamed without changes.
Loading
Loading