Skip to content

Commit 4c1612c

Browse files
committed
resolve conflicts.
2 parents 1a0e3f5 + b079fd8 commit 4c1612c

24 files changed

Lines changed: 6707 additions & 8 deletions

build2cmake/src/templates/utils.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ function(extract_unique_cuda_archs_ascending OUT_ARCHES CUDA_ARCH_FLAGS)
217217
endfunction()
218218

219219
#
220-
# For a specific file set the `-gencode` flag in compile options conditionally
221-
# for the CUDA language.
220+
# For a specific file set the `-gencode` flag in compile options conditionally
221+
# for the CUDA language.
222222
#
223223
# Example:
224224
# set_gencode_flag_for_srcs(
225225
# SRCS "foo.cu"
226226
# ARCH "compute_75"
227227
# CODE "sm_75")
228-
# adds: "-gencode arch=compute_75,code=sm_75" to the compile options for
228+
# adds: "-gencode arch=compute_75,code=sm_75" to the compile options for
229229
# `foo.cu` (only for the CUDA language).
230230
#
231231
macro(set_gencode_flag_for_srcs)
@@ -344,13 +344,13 @@ function(cuda_archs_loose_intersection OUT_CUDA_ARCHS SRC_CUDA_ARCHS TGT_CUDA_AR
344344
list(REMOVE_DUPLICATES _PTX_ARCHS)
345345
list(REMOVE_DUPLICATES _SRC_CUDA_ARCHS)
346346

347-
# if x.0a is in SRC_CUDA_ARCHS and x.0 is in CUDA_ARCHS then we should
348-
# remove x.0a from SRC_CUDA_ARCHS and add x.0a to _CUDA_ARCHS
347+
# If x.0a or x.0f is in SRC_CUDA_ARCHS and x.0 is in CUDA_ARCHS then we should
348+
# remove x.0a or x.0f from SRC_CUDA_ARCHS and add x.0a or x.0f to _CUDA_ARCHS
349349
set(_CUDA_ARCHS)
350350
foreach(_arch ${_SRC_CUDA_ARCHS})
351-
if(_arch MATCHES "\\a$")
351+
if(_arch MATCHES "[af]$")
352352
list(REMOVE_ITEM _SRC_CUDA_ARCHS "${_arch}")
353-
string(REPLACE "a" "" _base "${_arch}")
353+
string(REGEX REPLACE "[af]$" "" _base "${_arch}")
354354
if ("${_base}" IN_LIST TGT_CUDA_ARCHS)
355355
list(REMOVE_ITEM _TGT_CUDA_ARCHS "${_base}")
356356
list(APPEND _CUDA_ARCHS "${_arch}")

docs/source/cli.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,25 @@ your kernel builds to the Hub. To know the supported arguments run: `kernels upl
3737
Use `kernels create-and-upload-card <kernel_source_dir> --card-path README.md` to generate a basic homepage
3838
for the kernel. Find an example [here](https://hf.co/kernels-community/kernel-card-template). You can
3939
optionally push it to the Hub by specifying a `--repo-id`.
40+
41+
### kernels skills add
42+
43+
Use `kernels skills add` to install the skills for AI coding assistants like Claude, Codex, and OpenCode. For now, only the `cuda-kernels` skill is supported. Skill files are downloaded from the `huggingface/kernels` directory in this [repository](https://github.com/huggingface/kernels/tree/main/skills).
44+
45+
Skills instruct agents how to deal with hardware-specific optimizations, integrate with libraries like diffusers and transformers, and benchmark kernel performance in consistent ways.
46+
47+
Examples:
48+
49+
```bash
50+
# install for Claude in the current project
51+
kernels skills add --claude
52+
53+
# install globally for Codex
54+
kernels skills add --codex --global
55+
56+
# install for multiple assistants
57+
kernels skills add --claude --codex --opencode
58+
59+
# install to a custom destination and overwrite if already present
60+
kernels skills add --dest ~/my-skills --force
61+
```

flake.nix

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
22
description = "Kernels";
33

4+
nixConfig = {
5+
extra-substituters = [ "https://huggingface.cachix.org" ];
6+
extra-trusted-public-keys = [
7+
"huggingface.cachix.org-1:ynTPbLS0W8ofXd9fDjk1KvoFky9K2jhxe6r4nXAkc/o="
8+
];
9+
};
10+
411
inputs = {
512
flake-utils.url = "github:numtide/flake-utils";
613
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
@@ -121,7 +128,8 @@
121128

122129
buildSets = defaultBuildSetsPerSystem.${system};
123130
buildSetsByBackend = (partitionBuildSetsBySystemBackend defaultBuildSets).${system};
124-
buildSet = builtins.head buildSetsByBackend.cuda;
131+
defaultBackend = if system == "aarch64-darwin" then "metal" else "cuda";
132+
buildSet = builtins.head buildSetsByBackend.${defaultBackend};
125133

126134
# Dev shells per framework.
127135
devShellByBackend = lib.mapAttrs (

kernels/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dev = [
3636
[project.optional-dependencies]
3737
abi-check = ["kernel-abi-check>=0.6.2,<0.7.0"]
3838
benchmark = [
39+
"matplotlib>=3.7.0",
3940
"numpy>=2.0.2",
4041
"tabulate>=0.9.0",
4142
"torch",

kernels/src/kernels/cli/__init__.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
KNOWN_BACKENDS,
1414
)
1515
from kernels.cli.init import run_init, parse_kernel_name
16+
from kernels.cli.skills import add_skill
1617
from kernels.cli.versions import print_kernel_versions
1718
from kernels.cli.doc import generate_readme_for_kernel
1819
from kernels.kernel_card_utils import (
@@ -98,6 +99,53 @@ def main():
9899
)
99100
upload_parser.set_defaults(func=upload_kernels)
100101

102+
skills_parser = subparsers.add_parser(
103+
"skills",
104+
help="Install kernels specific skills for agents like Claude, Codex, and OpenCode",
105+
)
106+
skills_subparsers = skills_parser.add_subparsers(required=True)
107+
skills_add_parser = skills_subparsers.add_parser(
108+
"add",
109+
help="Install the cuda-kernels skill for an AI assistant",
110+
)
111+
skills_add_parser.add_argument(
112+
"--claude",
113+
action="store_true",
114+
help="Install for Claude.",
115+
)
116+
skills_add_parser.add_argument(
117+
"--codex",
118+
action="store_true",
119+
help="Install for Codex.",
120+
)
121+
skills_add_parser.add_argument(
122+
"--opencode",
123+
action="store_true",
124+
help="Install for OpenCode.",
125+
)
126+
skills_add_parser.add_argument(
127+
"--global",
128+
"-g",
129+
dest="global_",
130+
action="store_true",
131+
help=(
132+
"Install globally (user-level) instead of in the current project "
133+
"directory."
134+
),
135+
)
136+
skills_add_parser.add_argument(
137+
"--dest",
138+
type=Path,
139+
default=None,
140+
help="Install into a custom destination (path to skills directory).",
141+
)
142+
skills_add_parser.add_argument(
143+
"--force",
144+
action="store_true",
145+
help="Overwrite existing skills in the destination.",
146+
)
147+
skills_add_parser.set_defaults(func=add_skill)
148+
101149
lock_parser = subparsers.add_parser("lock", help="Lock kernel revisions")
102150
lock_parser.add_argument(
103151
"project_dir",
@@ -156,6 +204,17 @@ def main():
156204
)
157205
benchmark_parser.add_argument("--iterations", type=int, default=100)
158206
benchmark_parser.add_argument("--warmup", type=int, default=10)
207+
benchmark_parser.add_argument(
208+
"--visual",
209+
type=str,
210+
default=None,
211+
help="Save visual outputs using this base path (e.g., --visual bench creates bench_light.svg and bench_dark.svg variants)",
212+
)
213+
benchmark_parser.add_argument(
214+
"--rasterized",
215+
action="store_true",
216+
help="Output PNG and GIF formats instead of SVG",
217+
)
159218
benchmark_parser.set_defaults(func=run_benchmark)
160219

161220
init_parser = subparsers.add_parser(
@@ -356,4 +415,6 @@ def run_benchmark(args):
356415
warmup=args.warmup,
357416
output=args.output,
358417
print_json=args.json,
418+
visual=args.visual,
419+
rasterized=args.rasterized,
359420
)

kernels/src/kernels/cli/benchmark.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ def run_benchmark(
682682
upload: bool = False,
683683
output: str | None = None,
684684
print_json: bool = False,
685+
visual: str | None = None,
686+
rasterized: bool = False,
685687
) -> BenchmarkResult:
686688
if MISSING_DEPS:
687689
print(
@@ -794,6 +796,56 @@ def run_benchmark(
794796
if print_json:
795797
print(json.dumps(result.to_payload(), indent=2))
796798

799+
if visual:
800+
from kernels.cli.benchmark_graphics import (
801+
save_speedup_animation,
802+
save_speedup_image,
803+
)
804+
805+
media_dir = Path("media")
806+
media_dir.mkdir(exist_ok=True)
807+
808+
for theme in ("light", "dark"):
809+
dark = theme == "dark"
810+
base_path = media_dir / f"{visual}_{theme}"
811+
812+
# Always produce SVGs
813+
save_speedup_image(
814+
timing_results,
815+
f"{base_path}.svg",
816+
machine_info.backend,
817+
repo_id,
818+
machine_info.pytorch_version,
819+
dark=dark,
820+
)
821+
save_speedup_animation(
822+
timing_results,
823+
f"{base_path}_animation.svg",
824+
machine_info.backend,
825+
repo_id,
826+
machine_info.pytorch_version,
827+
dark=dark,
828+
)
829+
830+
# Additionally produce PNGs and GIFs when --rasterized is used
831+
if rasterized:
832+
save_speedup_image(
833+
timing_results,
834+
f"{base_path}.png",
835+
machine_info.backend,
836+
repo_id,
837+
machine_info.pytorch_version,
838+
dark=dark,
839+
)
840+
save_speedup_animation(
841+
timing_results,
842+
f"{base_path}_animation.gif",
843+
machine_info.backend,
844+
repo_id,
845+
machine_info.pytorch_version,
846+
dark=dark,
847+
)
848+
797849
if upload:
798850
submit_benchmark(repo_id=repo_id, result=result)
799851
print("Benchmark submitted successfully!", file=sys.stderr)

0 commit comments

Comments
 (0)