push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,333 @@
{
lib,
stdenv,
callPackage,
fetchFromGitHub,
fetchpatch,
rocmUpdateScript,
runCommand,
pkg-config,
cmake,
rocm-cmake,
rocblas,
rocmlir,
rocrand,
rocm-runtime,
rocm-merged-llvm,
hipblas-common,
hipblas,
hipblaslt,
clr,
composable_kernel,
frugally-deep,
rocm-docs-core,
half,
boost,
sqlite,
bzip2,
lbzip2,
nlohmann_json,
texliveSmall,
doxygen,
sphinx,
zlib,
gtest,
rocm-comgr,
roctracer,
python3Packages,
gpuTargets ? clr.localGpuTargets or clr.gpuTargets,
buildDocs ? false, # Needs internet because of rocm-docs-core
buildTests ? false,
withComposableKernel ? composable_kernel.anyMfmaTarget,
}:
let
# FIXME: cmake files need patched to include this properly
cFlags = "-Wno-documentation-pedantic --offload-compress -I${hipblas-common}/include -I${hipblas}/include -I${roctracer}/include -I${nlohmann_json}/include -I${sqlite.dev}/include -I${rocrand}/include";
version = "6.4.3";
# Targets outside this list will get
# error: use of undeclared identifier 'CK_BUFFER_RESOURCE_3RD_DWORD'
supportedTargets = lib.intersectLists [
"gfx900"
"gfx906"
"gfx908"
"gfx90a"
"gfx942"
"gfx950"
"gfx1030"
"gfx1031"
"gfx1100"
"gfx1101"
"gfx1102"
"gfx1150"
"gfx1151"
"gfx1200"
"gfx1201"
] gpuTargets;
src = fetchFromGitHub {
owner = "ROCm";
repo = "MIOpen";
rev = "rocm-${version}";
hash = "sha256-DEcVj2vOwIYYyNKEKFqZ0fb9o+/QRpwiSksxwnmgEMc=";
fetchLFS = true;
fetchSubmodules = true;
# WORKAROUND: .lfsconfig is incorrectly set to exclude everything upstream
leaveDotGit = true;
# FIXME: if someone can reduce the level of awful here that would be really nice
postFetch = ''
export HOME=$(mktemp -d)
cd $out
git remote add origin $url
git fetch origin +refs/tags/rocm-${version}:refs/tags/rocm-${version}
git clean -fdx
git switch -c rocm-${version} refs/tags/rocm-${version}
git config lfs.fetchexclude "none"
rm .lfsconfig
git lfs install
git lfs track "*.kdb.bz2"
git lfs fetch --include="src/kernels/**"
git lfs pull --include="src/kernels/**"
git lfs checkout
rm -rf .git
'';
};
latex = lib.optionalAttrs buildDocs (
texliveSmall.withPackages (
ps: with ps; [
latexmk
tex-gyre
fncychap
wrapfig
capt-of
framed
needspace
tabulary
varwidth
titlesec
]
)
);
gfx900 = runCommand "miopen-gfx900.kdb" { preferLocalBuild = true; } ''
${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx900.kdb.bz2 > $out
'';
gfx906 = runCommand "miopen-gfx906.kdb" { preferLocalBuild = true; } ''
${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx906.kdb.bz2 > $out
'';
gfx908 = runCommand "miopen-gfx908.kdb" { preferLocalBuild = true; } ''
${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx908.kdb.bz2 > $out
'';
gfx90a = runCommand "miopen-gfx90a.kdb" { preferLocalBuild = true; } ''
${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx90a.kdb.bz2 > $out
'';
gfx1030 = runCommand "miopen-gfx1030.kdb" { preferLocalBuild = true; } ''
${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx1030.kdb.bz2 > $out
'';
in
stdenv.mkDerivation (finalAttrs: {
inherit version src;
pname = "miopen";
env.CFLAGS = cFlags;
env.CXXFLAGS = cFlags;
# Find zstd and add to target. Mainly for torch.
patches = [
./skip-preexisting-dbs.patch
(fetchpatch {
url = "https://github.com/ROCm/MIOpen/commit/e608b4325646afeabb5e52846997b926d2019d19.patch";
hash = "sha256-oxa3qlIC2bzbwGxrQOZXoY/S7CpLsMrnWRB7Og0tk0M=";
})
(fetchpatch {
url = "https://github.com/ROCm/MIOpen/commit/3413d2daaeb44b7d6eadcc03033a5954a118491e.patch";
hash = "sha256-ST4snUcTmmSI1Ogx815KEX9GdMnmubsavDzXCGJkiKs=";
})
# FIXME: We need to rebase or drop this arch compat patch
# https://github.com/ROCm/MIOpen/issues/3540 suggests that
# arch compat patching doesn't work correctly for gfx1031
# (fetchpatch {
# name = "Extend-MIOpen-ISA-compatibility.patch";
# url = "https://github.com/GZGavinZhao/MIOpen/commit/416088b534618bd669a765afce59cfc7197064c1.patch";
# hash = "sha256-OwONCA68y8s2GqtQj+OtotXwUXQ5jM8tpeM92iaD4MU=";
# })
];
outputs = [
"out"
]
++ lib.optionals buildDocs [
"doc"
]
++ lib.optionals buildTests [
"test"
];
enableParallelBuilding = true;
env.ROCM_PATH = clr;
env.LD_LIBRARY_PATH = lib.makeLibraryPath [ rocm-runtime ];
env.HIP_CLANG_PATH = "${rocm-merged-llvm}/bin";
nativeBuildInputs = [
pkg-config
cmake
rocm-cmake
clr
];
buildInputs = [
hipblas
hipblas-common
rocblas
rocmlir
half
boost
sqlite
bzip2
nlohmann_json
frugally-deep
roctracer
rocrand
hipblaslt
]
++ lib.optionals withComposableKernel [
composable_kernel
]
++ lib.optionals buildDocs [
latex
doxygen
sphinx
rocm-docs-core
python3Packages.sphinx-rtd-theme
python3Packages.breathe
python3Packages.myst-parser
]
++ lib.optionals buildTests [
gtest
zlib
];
cmakeFlags = [
"-DAMDGPU_TARGETS=${lib.concatStringsSep ";" supportedTargets}"
"-DGPU_TARGETS=${lib.concatStringsSep ";" supportedTargets}"
"-DGPU_ARCHS=${lib.concatStringsSep ";" supportedTargets}"
"-DMIOPEN_USE_SQLITE_PERFDB=ON"
"-DCMAKE_VERBOSE_MAKEFILE=ON"
"-DCMAKE_MODULE_PATH=${clr}/hip/cmake"
"-DCMAKE_BUILD_TYPE=Release"
# needs to stream to stdout so bzcat rather than bunzip2
"-DUNZIPPER=${bzip2}/bin/bzcat"
"-DCMAKE_C_COMPILER=amdclang"
"-DCMAKE_CXX_COMPILER=amdclang++"
"-DROCM_PATH=${clr}"
"-DHIP_ROOT_DIR=${clr}"
(lib.cmakeBool "MIOPEN_USE_ROCBLAS" true)
(lib.cmakeBool "MIOPEN_USE_HIPBLASLT" true)
(lib.cmakeBool "MIOPEN_USE_COMPOSABLEKERNEL" withComposableKernel)
(lib.cmakeBool "MIOPEN_USE_HIPRTC" true)
(lib.cmakeBool "MIOPEN_USE_COMGR" true)
"-DCMAKE_HIP_COMPILER_ROCM_ROOT=${clr}"
# Manually define CMAKE_INSTALL_<DIR>
# See: https://github.com/NixOS/nixpkgs/pull/197838
"-DCMAKE_INSTALL_BINDIR=bin"
"-DCMAKE_INSTALL_LIBDIR=lib"
"-DCMAKE_INSTALL_INCLUDEDIR=include"
"-DMIOPEN_BACKEND=HIP"
]
++ lib.optionals buildTests [
"-DBUILD_TESTS=ON"
"-DMIOPEN_TEST_ALL=ON"
];
postPatch = ''
substituteInPlace cmake/ClangTidy.cmake \
--replace-fail 'macro(enable_clang_tidy)' 'macro(enable_clang_tidy)
endmacro()
macro(enable_clang_tidy_unused)' \
--replace-fail 'function(clang_tidy_check TARGET)' 'function(clang_tidy_check TARGET)
return()'
patchShebangs test src/composable_kernel fin utils install_deps.cmake
ln -sf ${gfx900} src/kernels/gfx900.kdb
ln -sf ${gfx906} src/kernels/gfx906.kdb
ln -sf ${gfx908} src/kernels/gfx908.kdb
ln -sf ${gfx90a} src/kernels/gfx90a.kdb
ln -sf ${gfx1030} src/kernels/gfx1030.kdb
mkdir -p build/share/miopen/db/
ln -sf ${gfx900} build/share/miopen/db/gfx900.kdb
ln -sf ${gfx906} build/share/miopen/db/gfx906.kdb
ln -sf ${gfx908} build/share/miopen/db/gfx908.kdb
ln -sf ${gfx90a} build/share/miopen/db/gfx90a.kdb
ln -sf ${gfx1030} build/share/miopen/db/gfx1030.kdb
'';
# Unfortunately, it seems like we have to call make on these manually
postBuild =
lib.optionalString buildDocs ''
python -m sphinx -T -E -b html -d _build/doctrees -D language=en ../docs _build/html
''
+ lib.optionalString buildTests ''
make -j$NIX_BUILD_CORES check
'';
postInstall = ''
rm $out/libexec/miopen/install_precompiled_kernels.sh
ln -sf ${gfx900} $out/share/miopen/db/gfx900.kdb
ln -sf ${gfx906} $out/share/miopen/db/gfx906.kdb
ln -sf ${gfx908} $out/share/miopen/db/gfx908.kdb
ln -sf ${gfx90a} $out/share/miopen/db/gfx90a.kdb
ln -sf ${gfx1030} $out/share/miopen/db/gfx1030.kdb
''
+ lib.optionalString buildDocs ''
mv ../doc/html $out/share/doc/miopen-hip
''
+ lib.optionalString buildTests ''
mkdir -p $test/bin
mv bin/test_* $test/bin
patchelf --set-rpath $out/lib:${
lib.makeLibraryPath (
finalAttrs.buildInputs
++ [
clr
rocm-comgr
]
)
} $test/bin/*
'';
requiredSystemFeatures = [ "big-parallel" ];
passthru.tests = {
# Ensure all .tn.model files can be loaded by whatever version of frugally-deep we have
# This is otherwise hard to verify as MIOpen will only use these models on specific,
# expensive Instinct GPUs
# If MIOpen stops embedding .tn.model files the test will also fail, and can be deleted,
# likely along with the frugally-deep dependency
can-load-models = callPackage ./test-frugally-deep-model-loading.nix {
inherit (finalAttrs) src version;
inherit frugally-deep nlohmann_json;
};
};
passthru.updateScript = rocmUpdateScript {
name = finalAttrs.pname;
inherit (finalAttrs.src) owner;
inherit (finalAttrs.src) repo;
};
meta = with lib; {
description = "Machine intelligence library for ROCm";
homepage = "https://github.com/ROCm/MIOpen";
license = with licenses; [ mit ];
teams = [ teams.rocm ];
platforms = platforms.linux;
};
})

View File

@@ -0,0 +1,22 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0ffaf983..0b9ed0952 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -554,7 +554,7 @@ endif()
function(unpack_db db_bzip2_file)
get_filename_component(__fname ${db_bzip2_file} NAME_WLE)
add_custom_command(OUTPUT ${KERNELS_BINARY_DIR}/${__fname}
- COMMAND ${UNZIPPER} -dc -k ${db_bzip2_file} > ${KERNELS_BINARY_DIR}/${__fname})
+ COMMAND test -e ${KERNELS_BINARY_DIR}/${__fname} || ${UNZIPPER} -dc -k ${db_bzip2_file} > ${KERNELS_BINARY_DIR}/${__fname})
string(REPLACE "." "_" __tname ${__fname})
add_custom_target(generate_${__tname} ALL DEPENDS ${KERNELS_BINARY_DIR}/${__fname})
@@ -563,7 +563,7 @@ function(unpack_db db_bzip2_file)
if(NOT MIOPEN_USE_SQLITE_PERFDB AND __extension STREQUAL ".db")
add_custom_command(OUTPUT ${KERNELS_BINARY_DIR}/${__fname}.txt
DEPENDS sqlite2txt generate_${__tname}
- COMMAND $<TARGET_FILE:sqlite2txt> ${KERNELS_BINARY_DIR}/${__fname} ${KERNELS_BINARY_DIR}/${__fname}.txt
+ COMMAND test -e ${KERNELS_BINARY_DIR}/${__fname}.txt || $<TARGET_FILE:sqlite2txt> ${KERNELS_BINARY_DIR}/${__fname} ${KERNELS_BINARY_DIR}/${__fname}.txt
)
add_custom_target(generate_${__tname}_txt ALL DEPENDS ${KERNELS_BINARY_DIR}/${__fname}.txt)
add_dependencies(generate_kernels generate_${__tname}_txt)

View File

@@ -0,0 +1,55 @@
#include <fdeep/fdeep.hpp>
#include <iostream>
#include <filesystem>
#include <vector>
#include <string>
int main() {
std::vector<std::string> model_files;
std::string src_dir = std::getenv("SRC_DIR") ? std::getenv("SRC_DIR") : ".";
// collect *tn.model files except _metadata
try {
for (const auto& entry : std::filesystem::recursive_directory_iterator(src_dir)) {
if (entry.is_regular_file()) {
std::string path = entry.path().string();
if (path.find("tn.model") != std::string::npos && path.find("_metadata.") == std::string::npos) {
model_files.push_back(path);
}
}
}
} catch (const std::exception& e) {
std::cerr << "Error scanning directory: " << e.what() << std::endl;
return 1;
}
if (model_files.empty()) {
std::cout << "No *.tn.model files found in " << src_dir << std::endl;
return 1;
}
std::cout << "Found " << model_files.size() << " model files to test" << std::endl;
int failed_count = 0;
for (const auto& model_file : model_files) {
std::cout << "Loading: " << model_file << " ... ";
std::cout.flush();
try {
const auto model = fdeep::load_model(model_file);
std::cout << "OK" << std::endl;
} catch (const std::exception& e) {
std::cout << "FAILED: " << e.what() << std::endl;
failed_count++;
}
}
if (failed_count > 0) {
std::cerr << "\n" << failed_count << " out of " << model_files.size()
<< " models failed to load" << std::endl;
return 1;
}
std::cout << "\nAll " << model_files.size() << " models loaded successfully!" << std::endl;
return 0;
}

View File

@@ -0,0 +1,49 @@
{
lib,
stdenv,
eigen,
frugally-deep,
functionalplus,
nlohmann_json,
src,
version,
}:
stdenv.mkDerivation {
pname = "miopen-frugally-deep-model-test";
inherit version src;
dontConfigure = true;
dontInstall = true;
doCheck = true;
buildPhase = ''
runHook preBuild
$CXX -std=c++20 \
-I${lib.getDev eigen}/include/eigen3 \
-I${lib.getDev functionalplus}/include \
-I${lib.getDev frugally-deep}/include \
-I${lib.getDev nlohmann_json}/include \
${./test-frugally-deep-model-loading.cpp} \
-o test_models
runHook postBuild
'';
checkPhase = ''
runHook preCheck
echo "Running model loading tests..."
SRC_DIR="${src}" ./test_models
mkdir -p $out
runHook postCheck
'';
meta = {
description = "Test that frugally-deep can load MIOpen model files";
maintainers = with lib.teams; [ rocm ];
platforms = lib.platforms.linux;
};
}