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

Commit 5f63d41

Browse files
authored
Fix a regression in test shells (#217)
The XPU support PR changed stdenv selection to choose the default stdenv when one of the kernels is an XPU kernel. However, this does not work for mixed XPU/CUDA projects, since we need to select the CUDA backend stdenv when building for CUDA. Change the logic to always use the stdenv for the backend that we are building for.
1 parent 33d6373 commit 5f63d41

2 files changed

Lines changed: 21 additions & 23 deletions

File tree

.github/workflows/build_kernel.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ jobs:
4747
- name: Build relu kernel (specific Torch version)
4848
run: ( cd examples/relu-specific-torch && nix build . )
4949

50+
- name: Test that we can build a test shell (e.g. that gcc corresponds to CUDA-required)
51+
run: ( cd examples/relu && nix build .#devShells.x86_64-linux.test )
52+
5053
- name: Build silu-and-mul-universal kernel
5154
run: ( cd examples/silu-and-mul-universal && nix build .\#redistributable.torch27-cxx11-cu126-x86_64-linux )
5255
- name: Copy silu-and-mul-universal kernel

lib/build.nix

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ let
2222
isRocm
2323
isXpu
2424
;
25+
mkStdenv =
26+
buildSet: oldLinuxCompat:
27+
let
28+
inherit (buildSet) pkgs torch;
29+
in
30+
if pkgs.stdenv.hostPlatform.isDarwin then
31+
pkgs.stdenv
32+
else if oldLinuxCompat then
33+
# Uses CUDA stdenv when we are building for CUDA.
34+
pkgs.stdenvGlibc_2_27
35+
else if torch.cudaSupport then
36+
torch.cudaPackages.backendStdenv
37+
else
38+
pkgs.stdenv;
39+
2540
in
2641
rec {
2742
resolveDeps = import ./deps.nix { inherit lib; };
@@ -126,15 +141,7 @@ rec {
126141
_: buildConfig: builtins.length (buildConfig.cuda-capabilities or supportedCudaCapabilities)
127142
) buildConfig.kernel
128143
);
129-
stdenv =
130-
if pkgs.stdenv.hostPlatform.isDarwin then
131-
pkgs.stdenv
132-
else if oldLinuxCompat then
133-
pkgs.stdenvGlibc_2_27
134-
else if lib.any (k: k.backend == "xpu") (lib.attrValues buildConfig.kernel) then
135-
pkgs.stdenv
136-
else
137-
pkgs.cudaPackages.backendStdenv;
144+
stdenv = mkStdenv { inherit pkgs torch; } oldLinuxCompat;
138145
in
139146
if buildConfig.general.universal then
140147
# No torch extension sources? Treat it as a noarch package.
@@ -244,13 +251,7 @@ rec {
244251
let
245252
pkgs = buildSet.pkgs;
246253
rocmSupport = pkgs.config.rocmSupport or false;
247-
stdenv =
248-
if rocmSupport then
249-
pkgs.stdenv
250-
else if isXpu buildSet.buildConfig then
251-
pkgs.stdenv
252-
else
253-
pkgs.cudaPackages.backendStdenv;
254+
stdenv = mkStdenv buildSet false;
254255
mkShell = pkgs.mkShell.override { inherit stdenv; };
255256
in
256257
{
@@ -291,13 +292,7 @@ rec {
291292
pkgs = buildSet.pkgs;
292293
rocmSupport = pkgs.config.rocmSupport or false;
293294
xpuSupport = pkgs.config.xpuSupport or false;
294-
stdenv =
295-
if rocmSupport then
296-
pkgs.stdenv
297-
else if xpuSupport then
298-
pkgs.stdenv
299-
else
300-
pkgs.cudaPackages.backendStdenv;
295+
stdenv = mkStdenv buildSet false;
301296
mkShell = pkgs.mkShell.override { inherit stdenv; };
302297
in
303298
{

0 commit comments

Comments
 (0)