Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit fb3a893

Browse files
authored
gen-flake-outputs: add backendBundle output (#312)
This output is similar to bundle, except that building `backendBundle.<backend>` will only build the variants for a specific backend. This can be useful for rebuilding kernels where only one backend was changed.
1 parent 594618e commit fb3a893

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

lib/gen-flake-outputs.nix

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ let
4040

4141
applicableBuildSets = build.applicableBuildSets { inherit path buildSets; };
4242

43+
buildConfigBackend =
44+
buildConfig:
45+
if buildConfig.cpu or false then
46+
"cpu"
47+
else if buildConfig ? cudaVersion then
48+
"cuda"
49+
else if buildConfig ? rocmVersion then
50+
"rocm"
51+
else if buildConfig ? xpuVersion then
52+
"xpu"
53+
else if buildConfig.metal or false then
54+
"metal"
55+
else
56+
throw "Cannot determine framework for build set";
57+
4358
# For picking a default shell, etc. we want to use the following logic:
4459
#
4560
# - Prefer bundle builds over non-bundle builds.
@@ -60,19 +75,7 @@ let
6075

6176
buildConfig // {
6277
bundleBuild = buildConfig.bundleBuild or false;
63-
framework =
64-
if buildConfig.cpu or false then
65-
"cpu"
66-
else if buildConfig ? cudaVersion then
67-
"cuda"
68-
else if buildConfig ? rocmVersion then
69-
"rocm"
70-
else if buildConfig ? xpuVersion then
71-
"xpu"
72-
else if buildConfig.metal or false then
73-
"metal"
74-
else
75-
throw "Cannot determine framework for build set";
78+
framework = buildConfigBackend buildConfig;
7679
frameworkOrder = if buildConfig ? cudaVersion then 0 else 1;
7780
frameworkVersion =
7881
buildConfig.cudaVersion or buildConfig.rocmVersion or buildConfig.xpuVersion or "0.0";
@@ -138,6 +141,24 @@ in
138141
{
139142
inherit bundle;
140143

144+
# Bundles by backend.
145+
backendBundle =
146+
let
147+
backends = lib.unique (map (set: buildConfigBackend set.buildConfig) applicableBuildSets);
148+
in
149+
builtins.listToAttrs (
150+
builtins.map (backend: {
151+
name = backend;
152+
value = build.mkTorchExtensionBundle {
153+
inherit path doGetKernelCheck;
154+
buildSets = builtins.filter (
155+
set: buildConfigBackend set.buildConfig == backend
156+
) applicableBuildSets;
157+
rev = revUnderscored;
158+
};
159+
}) backends
160+
);
161+
141162
default = bundle;
142163

143164
build-and-copy = writeScriptBin "build-and-copy" ''

0 commit comments

Comments
 (0)