Skip to content

Commit

Permalink
Merge pull request #299589 from mschwaig/compress-composable-kernel
Browse files Browse the repository at this point in the history
rocmPackages.composable_kernel: compress output
  • Loading branch information
wegank authored Apr 14, 2024
2 parents 70dcf56 + 772dbad commit e8d27c9
Show file tree
Hide file tree
Showing 9 changed files with 1,232 additions and 57 deletions.

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions pkgs/development/rocm-modules/6/llvm/base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ in stdenv.mkDerivation (finalAttrs: {
"info" # Avoid `attribute 'info' missing` when using with wrapCC
];

patches = extraPatches;
patches = [
./add-compression-to-clang-offload-bundler.patch
] ++ extraPatches;

src = fetchFromGitHub {
owner = "ROCm";
Expand Down Expand Up @@ -133,15 +135,22 @@ in stdenv.mkDerivation (finalAttrs: {
"-DLLVM_EXTERNAL_LIT=${lit}/bin/.lit-wrapped"
] ++ extraCMakeFlags;

postPatch = lib.optionalString finalAttrs.passthru.isLLVM ''
prePatch = ''
cd ../
chmod -R u+w .
'';

postPatch = ''
cd ${targetDir}
'' + lib.optionalString finalAttrs.passthru.isLLVM ''
patchShebangs lib/OffloadArch/make_generated_offload_arch_h.sh
'' + lib.optionalString (buildTests && finalAttrs.passthru.isLLVM) ''
# FileSystem permissions tests fail with various special bits
rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
rm unittests/Support/Path.cpp
substituteInPlace unittests/Support/CMakeLists.txt \
--replace "Path.cpp" ""
--replace-fail "Path.cpp" ""
'' + extraPostPatch;

doCheck = buildTests;
Expand Down
11 changes: 9 additions & 2 deletions pkgs/development/rocm-modules/6/llvm/stage-1/clang-unwrapped.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
, callPackage
, rocmUpdateScript
, llvm
, makeWrapper
}:

callPackage ../base.nix rec {
inherit stdenv rocmUpdateScript;
targetName = "clang-unwrapped";
targetDir = "clang";
extraBuildInputs = [ llvm ];
extraBuildInputs = [ llvm makeWrapper ];

extraCMakeFlags = [
"-DCLANG_INCLUDE_DOCS=ON"
Expand All @@ -20,7 +21,7 @@ callPackage ../base.nix rec {
ln -s ../cmake/Modules/FindLibEdit.cmake cmake/modules
substituteInPlace CMakeLists.txt \
--replace "include(CheckIncludeFile)" "include(CheckIncludeFile)''\nfind_package(LibEdit)"
--replace-fail "include(CheckIncludeFile)" "include(CheckIncludeFile)''\nfind_package(LibEdit)"
# `No such file or directory: '/build/source/clang/tools/scan-build/bin/scan-build'`
rm test/Analysis/scan-build/*.test
Expand All @@ -41,6 +42,12 @@ callPackage ../base.nix rec {

extraPostInstall = ''
mv bin/clang-tblgen $out/bin
# add wrapper to compress embedded accelerator-specific code
# this makes the output of composable_kernel significantly smaller right now
# TODO: remove this once ROCm does it out of the box
mv $out/bin/clang-offload-bundler $out/bin/clang-offload-bundler-unwrapped
makeWrapper $out/bin/clang-offload-bundler-unwrapped $out/bin/clang-offload-bundler \
--add-flags '-compress'
'';

requiredSystemFeatures = [ "big-parallel" ];
Expand Down
10 changes: 5 additions & 5 deletions pkgs/development/rocm-modules/6/llvm/stage-2/libc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ callPackage ../base.nix rec {
# `Failed to match ... against ...` `Match value not within tolerance value of MPFR result:`
# We need a better way, but I don't know enough sed magic and patching `CMakeLists.txt` isn't working...
substituteInPlace ../libc/test/src/math/log10_test.cpp \
--replace "i < N" "i < 0" \
--replace "test(mpfr::RoundingMode::Nearest);" "" \
--replace "test(mpfr::RoundingMode::Downward);" "" \
--replace "test(mpfr::RoundingMode::Upward);" "" \
--replace "test(mpfr::RoundingMode::TowardZero);" ""
--replace-fail "i < N" "i < 0" \
--replace-fail "test(mpfr::RoundingMode::Nearest);" "" \
--replace-fail "test(mpfr::RoundingMode::Downward);" "" \
--replace-fail "test(mpfr::RoundingMode::Upward);" "" \
--replace-fail "test(mpfr::RoundingMode::TowardZero);" ""
'';

checkTargets = [ "check-${targetName}" ];
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion pkgs/development/rocm-modules/6/llvm/stage-3/clang.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ wrapCCWith rec {
# GPU compilation uses builtin `lld`
substituteInPlace $out/bin/{clang,clang++} \
--replace "-MM) dontLink=1 ;;" "-MM | --cuda-device-only) dontLink=1 ;;''\n--cuda-host-only | --cuda-compile-host-device) dontLink=0 ;;"
--replace-fail "-MM) dontLink=1 ;;" "-MM | --cuda-device-only) dontLink=1 ;;''\n--cuda-host-only | --cuda-compile-host-device) dontLink=0 ;;"
'';
}
10 changes: 5 additions & 5 deletions pkgs/development/rocm-modules/6/llvm/stage-3/libclc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ in callPackage ../base.nix rec {
# `clspv` tests fail, unresolved calls
extraPostPatch = ''
substituteInPlace CMakeLists.txt \
--replace "find_program( LLVM_CLANG clang PATHS \''${LLVM_BINDIR} NO_DEFAULT_PATH )" \
--replace-fail "find_program( LLVM_CLANG clang PATHS \''${LLVM_BINDIR} NO_DEFAULT_PATH )" \
"find_program( LLVM_CLANG clang PATHS \"${clang}/bin\" NO_DEFAULT_PATH )" \
--replace "find_program( LLVM_SPIRV llvm-spirv PATHS \''${LLVM_BINDIR} NO_DEFAULT_PATH )" \
--replace-fail "find_program( LLVM_SPIRV llvm-spirv PATHS \''${LLVM_BINDIR} NO_DEFAULT_PATH )" \
"find_program( LLVM_SPIRV llvm-spirv PATHS \"${spirv}/bin\" NO_DEFAULT_PATH )" \
--replace " spirv-mesa3d-" "" \
--replace " spirv64-mesa3d-" "" \
--replace "NOT \''${t} MATCHES" \
--replace-fail " spirv-mesa3d-" "" \
--replace-fail " spirv64-mesa3d-" "" \
--replace-fail "NOT \''${t} MATCHES" \
"NOT \''${ARCH} STREQUAL \"clspv\" AND NOT \''${ARCH} STREQUAL \"clspv64\" AND NOT \''${t} MATCHES"
'';

Expand Down
12 changes: 8 additions & 4 deletions pkgs/development/rocm-modules/6/llvm/stage-3/mlir.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
, glslang
, shaderc
, lit
, fetchpatch
}:

callPackage ../base.nix rec {
Expand All @@ -17,9 +18,12 @@ callPackage ../base.nix rec {
targetDir = targetName;

# Fix `DebugTranslation.cpp:139:10: error: no matching function for call to 'get'`
# We patch at a different source root, so we modify the patch and include it locally
# https://github.com/ROCm/llvm-project/commit/f1d1e10ec7e1061bf0b90abbc1e298d9438a5e74.patch
extraPatches = [ ./0000-mlir-fix-debugtranslation.patch ];
extraPatches = [
(fetchpatch {
url = "https://github.com/ROCm/llvm-project/commit/f1d1e10ec7e1061bf0b90abbc1e298d9438a5e74.patch";
hash = "sha256-3c91A9InMKxm+JcnWxoUeOU68y5I6w1AAXx6T9UByqI=";
})
];
extraNativeBuildInputs = [ clr ];

extraBuildInputs = [
Expand All @@ -41,7 +45,7 @@ callPackage ../base.nix rec {
extraPostPatch = ''
# `add_library cannot create target "llvm_gtest" because an imported target with the same name already exists`
substituteInPlace CMakeLists.txt \
--replace "EXISTS \''${UNITTEST_DIR}/googletest/include/gtest/gtest.h" "FALSE"
--replace-fail "EXISTS \''${UNITTEST_DIR}/googletest/include/gtest/gtest.h" "FALSE"
# Mainly `No such file or directory`
cat ${./1001-mlir-failing-tests.list} | xargs -d \\n rm
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/rocm-modules/6/llvm/stage-3/polly.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ callPackage ../base.nix rec {
extraPostPatch = ''
# `add_library cannot create target "llvm_gtest" because an imported target with the same name already exists`
substituteInPlace CMakeLists.txt \
--replace "NOT TARGET gtest" "FALSE"
--replace-fail "NOT TARGET gtest" "FALSE"
'';

checkTargets = [ "check-${targetName}" ];
Expand Down

0 comments on commit e8d27c9

Please sign in to comment.