From d42d9a619a92cd65b3f8e6676be395f7fc98e98b Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 22 Jan 2021 09:55:46 +0100 Subject: add patch for not linking to clang rt bulitin lib, and apply patches to 3.9.0 too (#20937) --- ...prove-compilation-without-git-repo.3.10.0.patch | 56 ++++++++++++++++++++++ ...mprove-compilation-without-git-repo.3.9.0.patch | 56 ++++++++++++++++++++++ ...0003-Improve-compilation-without-git-repo.patch | 56 ---------------------- ...ng-rt-builtins-linking-on-hip-host.3.10.0.patch | 32 +++++++++++++ ...ang-rt-builtins-linking-on-hip-host.3.9.0.patch | 35 ++++++++++++++ var/spack/repos/builtin/packages/hip/package.py | 31 +++++++----- 6 files changed, 197 insertions(+), 69 deletions(-) create mode 100644 var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.3.10.0.patch create mode 100644 var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.3.9.0.patch delete mode 100644 var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.patch create mode 100644 var/spack/repos/builtin/packages/hip/0004-Drop-clang-rt-builtins-linking-on-hip-host.3.10.0.patch create mode 100644 var/spack/repos/builtin/packages/hip/0004-Drop-clang-rt-builtins-linking-on-hip-host.3.9.0.patch diff --git a/var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.3.10.0.patch b/var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.3.10.0.patch new file mode 100644 index 0000000000..d7f1a8dff3 --- /dev/null +++ b/var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.3.10.0.patch @@ -0,0 +1,56 @@ +From 3a05d9ee5af2d318d27ee4b8e81542e2c81b9d5a Mon Sep 17 00:00:00 2001 +From: Harmen Stoppels +Date: Mon, 11 Jan 2021 16:38:14 +0100 +Subject: [PATCH] Improve compilation without git repo + +--- + CMakeLists.txt | 17 +++++++++-------- + 1 file changed, 9 insertions(+), 8 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 7831bb4d..c0c7a536 100755 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -42,9 +42,17 @@ string(REPLACE "." ";" VERSION_LIST ${HIP_BASE_VERSION}) + list(GET VERSION_LIST 0 HIP_VERSION_MAJOR) + list(GET VERSION_LIST 1 HIP_VERSION_MINOR) + +-find_package(Git) ++# only look for git when we have a git repo ++if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git") ++ find_package(Git) ++endif() + + # FIXME: Two different version strings used. ++ ++set(HIP_PACKAGING_VERSION_PATCH "0") ++set(HIP_VERSION_GITDATE "0") ++set(HIP_VERSION_PATCH "0") ++ + if(GIT_FOUND) + # get date information based on UTC + # use the last two digits of year + week number + day in the week as HIP_VERSION_GITDATE +@@ -88,9 +96,6 @@ if(GIT_FOUND) + else() + set(HIP_PACKAGING_VERSION_PATCH ${HIP_VERSION_GITDATE}.${HIP_VERSION_GITCOUNT}-${HIP_VERSION_GITHASH}) + endif() +-else() +- # FIXME: Some parts depend on this being set. +- set(HIP_PACKAGING_VERSION_PATCH "0") + endif() + + ## Debian package specific variables +@@ -488,10 +493,6 @@ endif() + # Generate .hipVersion + file(WRITE "${PROJECT_BINARY_DIR}/.hipVersion" ${_versionInfo}) + +-if(NOT DEFINED HIP_VERSION_GITDATE) +- set(HIP_VERSION_GITDATE 0) +-endif() +- + # Build doxygen documentation + find_program(DOXYGEN_EXE doxygen) + if(DOXYGEN_EXE) +-- +2.25.1 + diff --git a/var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.3.9.0.patch b/var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.3.9.0.patch new file mode 100644 index 0000000000..2bb5074df2 --- /dev/null +++ b/var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.3.9.0.patch @@ -0,0 +1,56 @@ +From db2a538d9beaef9092dff19c36ed8a2e291bc69a Mon Sep 17 00:00:00 2001 +From: Harmen Stoppels +Date: Mon, 11 Jan 2021 16:38:14 +0100 +Subject: [PATCH 1/2] Improve compilation without git repo + +--- + CMakeLists.txt | 17 +++++++++-------- + 1 file changed, 9 insertions(+), 8 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 7f5bdad9..ca0e7ed4 100755 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -44,9 +44,17 @@ string(REPLACE "." ";" VERSION_LIST ${HIP_BASE_VERSION}) + list(GET VERSION_LIST 0 HIP_VERSION_MAJOR) + list(GET VERSION_LIST 1 HIP_VERSION_MINOR) + +-find_package(Git) ++# only look for git when we have a git repo ++if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git") ++ find_package(Git) ++endif() + + # FIXME: Two different version strings used. ++ ++set(HIP_PACKAGING_VERSION_PATCH "0") ++set(HIP_VERSION_GITDATE "0") ++set(HIP_VERSION_PATCH "0") ++ + if(GIT_FOUND) + # get date information based on UTC + # use the last two digits of year + week number + day in the week as HIP_VERSION_GITDATE +@@ -90,9 +98,6 @@ if(GIT_FOUND) + else() + set(HIP_PACKAGING_VERSION_PATCH ${HIP_VERSION_GITDATE}.${HIP_VERSION_GITCOUNT}-${HIP_VERSION_GITHASH}) + endif() +-else() +- # FIXME: Some parts depend on this being set. +- set(HIP_PACKAGING_VERSION_PATCH "0") + endif() + + add_to_config(_versionInfo HIP_VERSION_MAJOR) +@@ -447,10 +452,6 @@ endif() + # Generate .hipVersion + file(WRITE "${PROJECT_BINARY_DIR}/.hipVersion" ${_versionInfo}) + +-if(NOT DEFINED HIP_VERSION_GITDATE) +- set(HIP_VERSION_GITDATE 0) +-endif() +- + # Generate hip_version.h + set(_versionInfoHeader + "// Auto-generated by cmake\n +-- +2.25.1 + diff --git a/var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.patch b/var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.patch deleted file mode 100644 index d7f1a8dff3..0000000000 --- a/var/spack/repos/builtin/packages/hip/0003-Improve-compilation-without-git-repo.patch +++ /dev/null @@ -1,56 +0,0 @@ -From 3a05d9ee5af2d318d27ee4b8e81542e2c81b9d5a Mon Sep 17 00:00:00 2001 -From: Harmen Stoppels -Date: Mon, 11 Jan 2021 16:38:14 +0100 -Subject: [PATCH] Improve compilation without git repo - ---- - CMakeLists.txt | 17 +++++++++-------- - 1 file changed, 9 insertions(+), 8 deletions(-) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 7831bb4d..c0c7a536 100755 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -42,9 +42,17 @@ string(REPLACE "." ";" VERSION_LIST ${HIP_BASE_VERSION}) - list(GET VERSION_LIST 0 HIP_VERSION_MAJOR) - list(GET VERSION_LIST 1 HIP_VERSION_MINOR) - --find_package(Git) -+# only look for git when we have a git repo -+if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git") -+ find_package(Git) -+endif() - - # FIXME: Two different version strings used. -+ -+set(HIP_PACKAGING_VERSION_PATCH "0") -+set(HIP_VERSION_GITDATE "0") -+set(HIP_VERSION_PATCH "0") -+ - if(GIT_FOUND) - # get date information based on UTC - # use the last two digits of year + week number + day in the week as HIP_VERSION_GITDATE -@@ -88,9 +96,6 @@ if(GIT_FOUND) - else() - set(HIP_PACKAGING_VERSION_PATCH ${HIP_VERSION_GITDATE}.${HIP_VERSION_GITCOUNT}-${HIP_VERSION_GITHASH}) - endif() --else() -- # FIXME: Some parts depend on this being set. -- set(HIP_PACKAGING_VERSION_PATCH "0") - endif() - - ## Debian package specific variables -@@ -488,10 +493,6 @@ endif() - # Generate .hipVersion - file(WRITE "${PROJECT_BINARY_DIR}/.hipVersion" ${_versionInfo}) - --if(NOT DEFINED HIP_VERSION_GITDATE) -- set(HIP_VERSION_GITDATE 0) --endif() -- - # Build doxygen documentation - find_program(DOXYGEN_EXE doxygen) - if(DOXYGEN_EXE) --- -2.25.1 - diff --git a/var/spack/repos/builtin/packages/hip/0004-Drop-clang-rt-builtins-linking-on-hip-host.3.10.0.patch b/var/spack/repos/builtin/packages/hip/0004-Drop-clang-rt-builtins-linking-on-hip-host.3.10.0.patch new file mode 100644 index 0000000000..a930858378 --- /dev/null +++ b/var/spack/repos/builtin/packages/hip/0004-Drop-clang-rt-builtins-linking-on-hip-host.3.10.0.patch @@ -0,0 +1,32 @@ +From 8b266132ee180ff8cc17b394ba64850f207a3dab Mon Sep 17 00:00:00 2001 +From: Harmen Stoppels +Date: Tue, 12 Jan 2021 12:26:44 +0100 +Subject: [PATCH] Drop clang rt builtins linking on hip::host + +Ref this comment +https://github.com/ROCm-Developer-Tools/HIP/pull/2217#discussion_r555402581: + +> Yea, this should only be linked on hip::device as I believe its needed +> for __fp16 support on the GPU. If users need this on the host-side, +> then they should explicitly add it. +--- + hip-config.cmake.in | 3 --- + 1 file changed, 3 deletions(-) + +diff --git a/hip-config.cmake.in b/hip-config.cmake.in +index 6dfbd527..0ac1b659 100644 +--- a/hip-config.cmake.in ++++ b/hip-config.cmake.in +@@ -206,9 +206,6 @@ if(HIP_COMPILER STREQUAL "clang") + endif() + + # Add support for __fp16 and _Float16, explicitly link with compiler-rt +- set_property(TARGET hip::host APPEND PROPERTY +- INTERFACE_LINK_LIBRARIES -L${HIP_CLANG_INCLUDE_PATH}/../lib/linux -lclang_rt.builtins-x86_64 +- ) + set_property(TARGET hip::device APPEND PROPERTY + INTERFACE_LINK_LIBRARIES -L${HIP_CLANG_INCLUDE_PATH}/../lib/linux -lclang_rt.builtins-x86_64 + ) +-- +2.25.1 + diff --git a/var/spack/repos/builtin/packages/hip/0004-Drop-clang-rt-builtins-linking-on-hip-host.3.9.0.patch b/var/spack/repos/builtin/packages/hip/0004-Drop-clang-rt-builtins-linking-on-hip-host.3.9.0.patch new file mode 100644 index 0000000000..936b333277 --- /dev/null +++ b/var/spack/repos/builtin/packages/hip/0004-Drop-clang-rt-builtins-linking-on-hip-host.3.9.0.patch @@ -0,0 +1,35 @@ +From 053bb794c57424fc47d53d8914bca1dc8d776a34 Mon Sep 17 00:00:00 2001 +From: Harmen Stoppels +Date: Tue, 12 Jan 2021 12:26:44 +0100 +Subject: [PATCH 2/2] Drop clang rt builtins linking on hip::host + +Ref this comment +https://github.com/ROCm-Developer-Tools/HIP/pull/2217#discussion_r555402581: + +> Yea, this should only be linked on hip::device as I believe its needed +> for __fp16 support on the GPU. If users need this on the host-side, +> then they should explicitly add it. +--- + hip-config.cmake.in | 6 ------ + 1 file changed, 6 deletions(-) + +diff --git a/hip-config.cmake.in b/hip-config.cmake.in +index ba340134..4daff392 100644 +--- a/hip-config.cmake.in ++++ b/hip-config.cmake.in +@@ -204,12 +204,6 @@ if(HIP_COMPILER STREQUAL "clang") + endif() + + # Add support for __fp16 and _Float16, explicitly link with compiler-rt +- set_property(TARGET hip::host APPEND PROPERTY +- INTERFACE_COMPILE_OPTIONS -L${HIP_CLANG_INCLUDE_PATH}/../lib/linux -lclang_rt.builtins-x86_64 +- ) +- set_property(TARGET hip::host APPEND PROPERTY +- INTERFACE_LINK_LIBRARIES -L${HIP_CLANG_INCLUDE_PATH}/../lib/linux -lclang_rt.builtins-x86_64 +- ) + set_property(TARGET hip::device APPEND PROPERTY + INTERFACE_COMPILE_OPTIONS -L${HIP_CLANG_INCLUDE_PATH}/../lib/linux -lclang_rt.builtins-x86_64 + ) +-- +2.25.1 + diff --git a/var/spack/repos/builtin/packages/hip/package.py b/var/spack/repos/builtin/packages/hip/package.py index fa09ebf7cf..ac992785dc 100644 --- a/var/spack/repos/builtin/packages/hip/package.py +++ b/var/spack/repos/builtin/packages/hip/package.py @@ -52,7 +52,12 @@ class Hip(CMakePackage): patch('0002-Fix-detection-of-HIP_CLANG_ROOT.patch', when='@:3.9.0') # See https://github.com/ROCm-Developer-Tools/HIP/pull/2218 - patch('0003-Improve-compilation-without-git-repo.patch', when='@4.0.0:') + patch('0003-Improve-compilation-without-git-repo.3.9.0.patch', when='@3.9.0') + patch('0003-Improve-compilation-without-git-repo.3.10.0.patch', when='@3.10.0:4.0.0') + + # See https://github.com/ROCm-Developer-Tools/HIP/pull/2219 + patch('0004-Drop-clang-rt-builtins-linking-on-hip-host.3.9.0.patch', when='@3.9.0') + patch('0004-Drop-clang-rt-builtins-linking-on-hip-host.3.10.0.patch', when='@3.10.0:4.0.0') def get_rocm_prefix_info(self): # External packages in Spack do not currently contain dependency @@ -109,6 +114,10 @@ class Hip(CMakePackage): env.set('ROCMINFO_PATH', rocm_prefixes['rocminfo']) env.set('DEVICE_LIB_PATH', rocm_prefixes['device_lib_path']) env.set('HIP_PATH', rocm_prefixes['rocm-path']) + # this guy is used in comgr, see the following file: + # https://github.com/RadeonOpenCompute/ROCm-CompilerSupport/blob/rocm-4.0.0/lib/comgr/src/comgr-env.cpp + # it's necessary on runtime when using hiprtcCreateProgram and such + env.set('LLVM_PATH', rocm_prefixes['llvm-amdgpu']) env.set('HIPCC_COMPILE_FLAGS_APPEND', '--rocm-path={0}'.format(rocm_prefixes['device_lib_path'])) @@ -135,16 +144,6 @@ class Hip(CMakePackage): 'INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"', 'hip-config.cmake.in', string=True) - def flag_handler(self, name, flags): - if name == 'cxxflags' and '@3.7.0:' in self.spec: - incl = self.spec['hip-rocclr'].prefix.include - flags.append('-I {0}/compiler/lib/include'.format(incl)) - flags.append('-I {0}/elf'.format(incl)) - - return (flags, None, None) - - @run_before('install') - def filter_sbang(self): perl = self.spec['perl'].command kwargs = {'ignore_absent': False, 'backup': False, 'string': False} @@ -157,8 +156,6 @@ class Hip(CMakePackage): ] filter_file(match, substitute, *files, **kwargs) - @run_before('install') - def filter_numactl(self): if '@3.7.0:' in self.spec: numactl = self.spec['numactl'].prefix.lib kwargs = {'ignore_absent': False, 'backup': False, 'string': False} @@ -168,6 +165,14 @@ class Hip(CMakePackage): substitute = " -L{numactl} -lnuma".format(numactl=numactl) filter_file(match, substitute, 'hipcc', **kwargs) + def flag_handler(self, name, flags): + if name == 'cxxflags' and '@3.7.0:' in self.spec: + incl = self.spec['hip-rocclr'].prefix.include + flags.append('-I {0}/compiler/lib/include'.format(incl)) + flags.append('-I {0}/elf'.format(incl)) + + return (flags, None, None) + def cmake_args(self): args = [ '-DHIP_COMPILER=clang', -- cgit v1.2.3-70-g09d2