Files
alex 16166f115b feat(rocm): Vendor SDK recipe and update to 10.1
Maintain the gfx1151 SDK locally using the official AMD archive. Use the TheRock patchelf pin and adapt LLVM auxiliary tools for pure Nix builds.

Verify SDK installation, HIP and rocBLAS GPU operations, and rebuild its consumers. Document the internal rc3 stamp and upstream migration findings.
2026-11-12 23:40:48 +03:00

129 lines
4.0 KiB
Nix

{
pkgs,
hipfireSource,
therockRocm,
modelDir ? "/var/lib/hipfire/models",
}:
let
lib = pkgs.lib;
gcc = pkgs.stdenv.cc;
hipccFixed = pkgs.writeShellScriptBin "hipcc" ''
export ROCM_PATH=${therockRocm}
exec ${therockRocm}/bin/hipcc \
--gcc-toolchain=${gcc.cc} \
-idirafter ${gcc.libc.dev}/include \
-B${gcc.libc}/lib \
-L${gcc.libc}/lib \
-L${gcc.cc.lib}/lib \
-L${gcc.cc}/lib \
"$@"
'';
glibcLoader = "${pkgs.glibc}/lib/ld-linux-x86-64.so.2";
llvmRunPath = lib.makeSearchPathOutput "lib" "lib" [
gcc.cc.lib
gcc.cc
];
therockLlvmTool =
name:
pkgs.writeShellScriptBin name ''
exec ${glibcLoader} --library-path ${therockRocm}/lib:${llvmRunPath} \
${therockRocm}/lib/llvm/bin/${name} "$@"
'';
llvmReadobj = therockLlvmTool "llvm-readobj";
llvmObjdump = therockLlvmTool "llvm-objdump";
therockDeviceLibs = pkgs.runCommand "therock-device-libs" { } ''
mkdir -p $out/amdgcn
ln -sfn ${therockRocm}/amdgcn/bitcode $out/amdgcn/bitcode
'';
hipfireKernelsPkg =
(pkgs.callPackage (hipfireSource + "/nix/kernels.nix") {
src = hipfireSource;
cargoLockFile = hipfireSource + "/Cargo.lock";
gpuTargets = [ "gfx1151" ];
rocmPackages = pkgs.rocmPackages // {
clr = therockRocm;
rocm-device-libs = therockDeviceLibs;
};
}).overrideAttrs
(old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ hipccFixed ];
env.HIPFIRE_HIPCC = "${hipccFixed}/bin/hipcc";
preBuild = (old.preBuild or "") + ''
export CARGO_BUILD_JOBS="$NIX_BUILD_CORES"
export HIPFIRE_PACK_JOBS="$NIX_BUILD_CORES"
'';
});
hipfireWithQuantize = pkgs.hipfire.overrideAttrs (_: {
buildPhase = ''
runHook preBuild
export CARGO_BUILD_JOBS="$NIX_BUILD_CORES"
cargo build --release -p hipfire-daemon
cargo build --release -p hipfire-cli
cargo build --release -p hipfire-quantize \
--bin hipfire-quantize --bin dflash_convert --bin draft_to_mq4
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp target/release/daemon $out/bin/hipfire-daemon-unwrapped
makeWrapper $out/bin/hipfire-daemon-unwrapped $out/bin/hipfire-daemon \
--set HIPFIRE_ROCM_PATH ${therockRocm} \
--set HIPFIRE_HIPCC ${hipccFixed}/bin/hipcc \
--set ROCM_PATH ${therockRocm} \
--set RADIOWAVE_READOBJ ${llvmReadobj}/bin/llvm-readobj \
--set RADIOWAVE_OBJDUMP ${llvmObjdump}/bin/llvm-objdump \
--prefix PATH : ${
pkgs.lib.makeBinPath [
hipccFixed
pkgs.pciutils
]
} \
--prefix LD_LIBRARY_PATH : ${therockRocm}/lib
cp target/release/hipfire $out/bin/hipfire-unwrapped
makeWrapper $out/bin/hipfire-unwrapped $out/bin/hipfire \
--set HIPFIRE_DAEMON_BIN $out/bin/hipfire-daemon \
--set HIPFIRE_NORMALIZE_PROMPT "1" \
--set HIPFIRE_MODELS_DIR "${modelDir}" \
--set HIP_PATH "${therockRocm}" \
--set HIPFIRE_HIPCC ${hipccFixed}/bin/hipcc \
--set ROCM_PATH ${therockRocm} \
--set RADIOWAVE_READOBJ ${llvmReadobj}/bin/llvm-readobj \
--set RADIOWAVE_OBJDUMP ${llvmObjdump}/bin/llvm-objdump \
--prefix PATH : ${
pkgs.lib.makeBinPath [
hipccFixed
pkgs.pciutils
]
} \
--prefix LD_LIBRARY_PATH : ${therockRocm}/lib
mkdir -p $out/share/hipfire/target/release
cp target/release/hipfire-quantize $out/share/hipfire/target/release/
cp target/release/dflash_convert $out/share/hipfire/target/release/
cp target/release/draft_to_mq4 $out/share/hipfire/target/release/
runHook postInstall
'';
});
in
hipfireWithQuantize.overrideAttrs (old: {
passthru = (old.passthru or { }) // {
kernels = hipfireKernelsPkg;
hipcc = hipccFixed;
inherit llvmReadobj llvmObjdump;
rocm = therockRocm;
category = "AI Inference";
};
})