Skip to content
Open
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
6 changes: 6 additions & 0 deletions nix-builder/lib/extension/torch/arch.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
kernel-builder,
cmake,
cmakeNvccThreadsHook,
cmakeXpuParallelHook,
cuda_nvcc,
get-kernel-check,
kernel-abi-check,
Expand Down Expand Up @@ -54,6 +55,9 @@

nvccThreads,

# TODO: Maximum parallel XPU compilation jobs. (for FA2)
xpuParallelJobs ? 12,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of Nix build cores is already limited to 12:

https://github.com/huggingface/kernels-community/blob/dc0e5d104b149f45a727db43023dcf22f51c428d/.github/workflows/build-release.yaml#L41

I'll try to build huggingface/kernels-community#666 with the latest changes and see what happens.


# A stringly-typed list of Python dependencies. Ideally we'd take a
# list of derivations, but we also need to write the dependencies to
# the output.
Expand Down Expand Up @@ -109,6 +113,7 @@ stdenv.mkDerivation (prevAttrs: {
doKernelBuildCheck
moduleName
nvccThreads
xpuParallelJobs
;

framework = "torch";
Expand Down Expand Up @@ -167,6 +172,7 @@ stdenv.mkDerivation (prevAttrs: {
clr
]
++ lib.optionals xpuSupport ([
cmakeXpuParallelHook
xpuPackages.ocloc
oneapi-torch-dev
])
Expand Down
2 changes: 2 additions & 0 deletions nix-builder/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ in

cmakeNvccThreadsHook = final.callPackage ./pkgs/cmake-nvcc-threads-hook { };

cmakeXpuParallelHook = final.callPackage ./pkgs/cmake-xpu-parallel-hook { };

get-kernel-check = final.callPackage ./pkgs/get-kernel-check { };

kernel-abi-check = final.callPackage ./pkgs/kernel-abi-check { };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

_setXpuParallelHook() {
if [ -z "${xpuParallelJobs}" ] || [ "${xpuParallelJobs}" -ne "${xpuParallelJobs}" ] 2>/dev/null; then
>&2 echo "Number of XPU parallel jobs is not (correctly) set, setting to 12"
xpuParallelJobs=12
fi

# Cap parallel jobs to available cores.
xpuParallelJobs=$((NIX_BUILD_CORES < xpuParallelJobs ? NIX_BUILD_CORES : xpuParallelJobs))

# Reduce NIX_BUILD_CORES to limit ninja parallelism for XPU builds,
export NIX_BUILD_CORES="${xpuParallelJobs}"

>&2 echo "XPU parallel hook: limiting ninja to -j${NIX_BUILD_CORES}"
}

preConfigureHooks+=(_setXpuParallelHook)
5 changes: 5 additions & 0 deletions nix-builder/pkgs/cmake-xpu-parallel-hook/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ makeSetupHook }:

makeSetupHook {
name = "cmake-xpu-parallel-hook";
} ./cmake-xpu-parallel-hook.sh