summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'dev-util/hip/files')
-rw-r--r--dev-util/hip/files/0001-SWDEV-316128-HIP-surface-API-support.patch35
-rw-r--r--dev-util/hip/files/0001-SWDEV-344620-hipcc-fails-to-parse-version-of-clang-i.patch70
-rw-r--r--dev-util/hip/files/0001-SWDEV-352878-LLVM-pkg-search-directly-using-find_dep.patch163
-rw-r--r--dev-util/hip/files/0002-SWDEV-355608-Remove-clang-include-path-2996.patch51
-rw-r--r--dev-util/hip/files/0003-SWDEV-352878-Removed-relative-path-based-CLANG-inclu.patch173
-rw-r--r--dev-util/hip/files/hip-4.2.0-cancel-hcc-header-removal.patch18
-rw-r--r--dev-util/hip/files/hip-4.2.0-config-cmake-in.patch15
-rw-r--r--dev-util/hip/files/hip-5.0.1-DisableTest.patch32
-rw-r--r--dev-util/hip/files/hip-5.0.1-hip_vector_types.patch11
-rw-r--r--dev-util/hip/files/hip-5.0.2-correct-ldflag.patch18
-rw-r--r--dev-util/hip/files/hip-5.0.2-set-build-id.patch20
-rw-r--r--dev-util/hip/files/hip-5.1.3-clang-include-path.patch12
-rw-r--r--dev-util/hip/files/hip-5.1.3-correct-sample-install-location.patch13
-rw-r--r--dev-util/hip/files/hip-5.1.3-fix-hip_prof_gen.patch38
-rw-r--r--dev-util/hip/files/hip-5.1.3-fno-stack-protector.patch16
-rw-r--r--dev-util/hip/files/hip-5.1.3-llvm-15-noinline-keyword.patch21
-rw-r--r--dev-util/hip/files/hip-5.1.3-remove-cmake-doxygen-commands.patch21
-rw-r--r--dev-util/hip/files/hip-5.1.3-rocm-path.patch13
-rw-r--r--dev-util/hip/files/hip-5.3.3-correct-ldflag.patch20
-rw-r--r--dev-util/hip/files/hip-5.3.3-disable-Werror.patch16
-rw-r--r--dev-util/hip/files/hip-5.3.3-remove-cmake-doxygen-commands.patch21
-rw-r--r--dev-util/hip/files/hip-5.4.3-clang-include.patch30
-rw-r--r--dev-util/hip/files/hip-5.4.3-clang-version.patch70
-rw-r--r--dev-util/hip/files/hip-5.4.3-correct-ldflag.patch20
-rw-r--r--dev-util/hip/files/hip-5.4.3-fix-HIP_CLANG_PATH-detection.patch26
-rw-r--r--dev-util/hip/files/hip-5.5.1-disable-Werror.patch18
-rw-r--r--dev-util/hip/files/hip-5.7.0-install.patch13
-rw-r--r--dev-util/hip/files/hip-5.7.1-disable-stack-protector.patch13
-rw-r--r--dev-util/hip/files/hip-5.7.1-exec-stack.patch31
-rw-r--r--dev-util/hip/files/hip-5.7.1-extend-isa-compatibility-check.patch236
-rw-r--r--dev-util/hip/files/hip-5.7.1-fix-mmap-oom-check.patch41
-rw-r--r--dev-util/hip/files/hip-5.7.1-fix-unaligned-access.patch67
-rw-r--r--dev-util/hip/files/hip-5.7.1-no_asan_doc.patch17
-rw-r--r--dev-util/hip/files/hip-test-5.7.0-rocm_agent_enumerator-location.patch15
-rw-r--r--dev-util/hip/files/hipvars-5.1.3.pm21
-rw-r--r--dev-util/hip/files/hipvars-5.3.3.pm20
-rw-r--r--dev-util/hip/files/hipvars.pm20
-rw-r--r--dev-util/hip/files/rocclr-5.3.3-fix-include.patch218
-rw-r--r--dev-util/hip/files/rocclr-5.3.3-gcc13.patch27
39 files changed, 1700 insertions, 0 deletions
diff --git a/dev-util/hip/files/0001-SWDEV-316128-HIP-surface-API-support.patch b/dev-util/hip/files/0001-SWDEV-316128-HIP-surface-API-support.patch
new file mode 100644
index 000000000000..14af91f9055b
--- /dev/null
+++ b/dev-util/hip/files/0001-SWDEV-316128-HIP-surface-API-support.patch
@@ -0,0 +1,35 @@
+From 4168c6ded4e54602f6fad8b0a483b20ab7f83cd5 Mon Sep 17 00:00:00 2001
+From: haoyuan2 <Hao.Yuan@amd.com>
+Date: Mon, 21 Feb 2022 10:10:04 -0800
+Subject: [PATCH] SWDEV-316128 - HIP surface API support
+
+remove redundant code in host API
+
+Change-Id: I8fbf894e858642da4198cc7afd2d2e2f1971e738
+Signed-off-by: YiyangWu <xgreenlandforwyy@gmail.com>
+---
+ src/hip_surface.cpp | 4 +---
+ 1 file changed, 1 insertion(+), 3 deletions(-)
+
+diff --git a/src/hip_surface.cpp b/src/hip_surface.cpp
+index 831df321..a8e7f71d 100644
+--- a/src/hip_surface.cpp
++++ b/src/hip_surface.cpp
+@@ -1,4 +1,4 @@
+-/* Copyright (c) 2015 - 2021 Advanced Micro Devices, Inc.
++/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+@@ -81,8 +81,6 @@ hipError_t hipCreateSurfaceObject(hipSurfaceObject_t* pSurfObject,
+ }
+
+ hipError_t ihipDestroySurfaceObject(hipSurfaceObject_t surfaceObject) {
+- HIP_INIT_API(hipDestroySurfaceObject, surfaceObject);
+-
+ if (surfaceObject == nullptr) {
+ return hipSuccess;
+ }
+--
+2.34.1
+
diff --git a/dev-util/hip/files/0001-SWDEV-344620-hipcc-fails-to-parse-version-of-clang-i.patch b/dev-util/hip/files/0001-SWDEV-344620-hipcc-fails-to-parse-version-of-clang-i.patch
new file mode 100644
index 000000000000..b9a1329e5931
--- /dev/null
+++ b/dev-util/hip/files/0001-SWDEV-344620-hipcc-fails-to-parse-version-of-clang-i.patch
@@ -0,0 +1,70 @@
+From 73430b62a5437d1ba6c36a1d812a1434d1ad9df7 Mon Sep 17 00:00:00 2001
+From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com>
+Date: Tue, 20 Dec 2022 06:51:12 +0530
+Subject: [PATCH 1/3] SWDEV-344620 - hipcc fails to parse version of clang in
+ some cases (#3119)
+
+Change-Id: I46f716c82a7500b9a2bcaf5f9ff4ad8a8f982770
+Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
+---
+ bin/hipcc.pl | 22 +++++++---------------
+ 1 file changed, 7 insertions(+), 15 deletions(-)
+
+diff --git a/bin/hipcc.pl b/bin/hipcc.pl
+index 645ae62d..2a01dcc3 100755
+--- a/bin/hipcc.pl
++++ b/bin/hipcc.pl
+@@ -144,7 +144,7 @@ if ($HIP_PLATFORM eq "amd") {
+ $execExtension = "";
+ if($isWindows) {
+ $execExtension = ".exe";
+- }
++ }
+ $HIPCC="$HIP_CLANG_PATH/clang++" . $execExtension;
+
+ # If $HIPCC clang++ is not compiled, use clang instead
+@@ -157,13 +157,10 @@ if ($HIP_PLATFORM eq "amd") {
+ $HIPLDFLAGS .= " -fuse-ld=lld";
+ $HIPLDFLAGS .= " --ld-path=$HIP_CLANG_PATH/lld-link.exe";
+ }
+- $HIP_CLANG_VERSION = `$HIPCC --version`;
+- $HIP_CLANG_VERSION=~/.*clang version (\S+).*/;
+- $HIP_CLANG_VERSION=$1;
+
+- # Figure out the target with which llvm is configured
+- $HIP_CLANG_TARGET = `$HIPCC -print-target-triple`;
+- $HIP_CLANG_TARGET = chomp($HIP_CLANG_TARGET);
++ # get Clang RT Builtin path
++ $HIP_CLANG_RT_LIB = `$HIPCC --print-runtime-dir`;
++ chomp($HIP_CLANG_RT_LIB);
+
+ if (! defined $HIP_CLANG_INCLUDE_PATH) {
+ $HIP_CLANG_INCLUDE_PATH = abs_path("$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/include");
+@@ -184,7 +181,7 @@ if ($HIP_PLATFORM eq "amd") {
+ print ("HIP_INCLUDE_PATH=$HIP_INCLUDE_PATH\n");
+ print ("HIP_LIB_PATH=$HIP_LIB_PATH\n");
+ print ("DEVICE_LIB_PATH=$DEVICE_LIB_PATH\n");
+- print ("HIP_CLANG_TARGET=$HIP_CLANG_TARGET\n");
++ print ("HIP_CLANG_RT_LIB=$HIP_CLANG_RT_LIB\n");
+ }
+
+ if ($isWindows) {
+@@ -715,13 +712,8 @@ if ($HIP_PLATFORM eq "amd") {
+ } else {
+ $toolArgs = ${toolArgs} . " -Wl,--enable-new-dtags -Wl,-rpath=$HIP_LIB_PATH:$ROCM_PATH/lib -lamdhip64 ";
+ }
+- # To support __fp16 and _Float16, explicitly link with compiler-rt
+- $HIP_CLANG_BUILTIN_LIB="$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/$HIP_CLANG_TARGET/libclang_rt.builtins.a";
+- if (-e $HIP_CLANG_BUILTIN_LIB) {
+- $toolArgs .= " -L$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/$HIP_CLANG_TARGET -lclang_rt.builtins "
+- } else {
+- $toolArgs .= " -L$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/linux -lclang_rt.builtins-x86_64 "
+- }
++
++ $toolArgs .= " -L$HIP_CLANG_RT_LIB -lclang_rt.builtins-x86_64 "
+ }
+ }
+
+--
+2.38.1
+
diff --git a/dev-util/hip/files/0001-SWDEV-352878-LLVM-pkg-search-directly-using-find_dep.patch b/dev-util/hip/files/0001-SWDEV-352878-LLVM-pkg-search-directly-using-find_dep.patch
new file mode 100644
index 000000000000..9dbfe8a55395
--- /dev/null
+++ b/dev-util/hip/files/0001-SWDEV-352878-LLVM-pkg-search-directly-using-find_dep.patch
@@ -0,0 +1,163 @@
+From 6c12b045bc3c434dd13e74bf124ed54afec668c6 Mon Sep 17 00:00:00 2001
+From: AravindanC <aravindan.cheruvally@amd.com>
+Date: Fri, 26 Aug 2022 15:02:09 -0700
+Subject: [PATCH] SWDEV-352878 - LLVM pkg search directly using find_dep() for
+ CLANG Include path
+
+Change-Id: I355e39890757be07de8b9332deca159f35039dfd
+Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
+---
+ hip-config.cmake.in | 108 ++++++++++++++++++++++++++------------------
+ 1 file changed, 64 insertions(+), 44 deletions(-)
+
+diff --git a/hip-config.cmake.in b/hip-config.cmake.in
+index 89d1224e..67d898d8 100755
+--- a/hip-config.cmake.in
++++ b/hip-config.cmake.in
+@@ -147,41 +147,62 @@ if(HIP_COMPILER STREQUAL "clang")
+ if(NOT HIP_CXX_COMPILER)
+ set(HIP_CXX_COMPILER ${CMAKE_CXX_COMPILER})
+ endif()
+- if(HIP_CXX_COMPILER MATCHES ".*hipcc" OR HIP_CXX_COMPILER MATCHES ".*clang\\+\\+")
+- execute_process(COMMAND ${HIP_CXX_COMPILER} --version
++
++ # Use HIP_CXX_COMPILER option -print-resource-dir
++ # To fetch the clang include path
++ execute_process(
++ COMMAND ${HIP_CXX_COMPILER} -print-resource-dir
++ OUTPUT_VARIABLE HIP_CLANG_INCLUDE_PATH
++ OUTPUT_STRIP_TRAILING_WHITESPACE
++ RESULT_VARIABLE CLANG_INCLUDE_PATH_FETCH_EXIT_CODE)
++
++ if( NOT "${CLANG_INCLUDE_PATH_FETCH_EXIT_CODE}" STREQUAL "0" )
++ if(HIP_CXX_COMPILER MATCHES ".*hipcc" OR HIP_CXX_COMPILER MATCHES ".*clang\\+\\+")
++ # IF not successful in fetching HIP_CLANG_INCLUDE_PATH using
++ # HIP_CXX_COMPILER binary command options -print-resource-dir
++ # fallback to old method of getting include by finding HIP_CLANG_ROOT
++ # and from predefined relative path of HIP_CLANG_ROOT
++ execute_process(COMMAND ${HIP_CXX_COMPILER} --version
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE HIP_CXX_COMPILER_VERSION_OUTPUT)
+- # Capture the repo, branch and patch level details of the HIP CXX Compiler.
+- # Ex. clang version 13.0.0 (https://github.com/ROCm-Developer-Tools/HIP main 12345 COMMIT_HASH)
+- # HIP_CLANG_REPO: https://github.com/ROCm-Developer-Tools/HIP
+- # HIP_CLANG_BRANCH: main
+- # HIP_CLANG_PATCH_LEVEL: 12345
+- if(${HIP_CXX_COMPILER_VERSION_OUTPUT} MATCHES "clang version [0-9]+\\.[0-9]+\\.[0-9]+ \\(([^ \n]*) ([^ \n]*) ([^ \n]*)")
+- set(HIP_CLANG_REPO ${CMAKE_MATCH_1})
+- set(HIP_CLANG_BRANCH ${CMAKE_MATCH_2})
+- set(HIP_CLANG_PATCH_LEVEL ${CMAKE_MATCH_3})
+- endif()
+- endif()
+- if(HIP_CXX_COMPILER MATCHES ".*hipcc")
+- if(HIP_CXX_COMPILER_VERSION_OUTPUT MATCHES "InstalledDir:[ \t]*([^\n]*)")
+- get_filename_component(HIP_CLANG_ROOT "${CMAKE_MATCH_1}" DIRECTORY)
+- endif()
+- elseif (HIP_CXX_COMPILER MATCHES ".*clang\\+\\+")
+- get_filename_component(_HIP_CLANG_REAL_PATH "${HIP_CXX_COMPILER}" REALPATH)
+- get_filename_component(_HIP_CLANG_BIN_PATH "${_HIP_CLANG_REAL_PATH}" DIRECTORY)
+- get_filename_component(HIP_CLANG_ROOT "${_HIP_CLANG_BIN_PATH}" DIRECTORY)
+- endif()
+- file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS ${HIP_CLANG_ROOT}/lib/clang/*/include)
+- find_path(HIP_CLANG_INCLUDE_PATH stddef.h
+- HINTS
++ # Capture the repo, branch and patch level details of the HIP CXX Compiler.
++ # Ex. clang version 13.0.0 (https://github.com/ROCm-Developer-Tools/HIP main 12345 COMMIT_HASH)
++ # HIP_CLANG_REPO: https://github.com/ROCm-Developer-Tools/HIP
++ # HIP_CLANG_BRANCH: main
++ # HIP_CLANG_PATCH_LEVEL: 12345
++ if(${HIP_CXX_COMPILER_VERSION_OUTPUT} MATCHES "clang version [0-9]+\\.[0-9]+\\.[0-9]+ \\(([^ \n]*) ([^ \n]*) ([^ \n]*)")
++ set(HIP_CLANG_REPO ${CMAKE_MATCH_1})
++ set(HIP_CLANG_BRANCH ${CMAKE_MATCH_2})
++ set(HIP_CLANG_PATCH_LEVEL ${CMAKE_MATCH_3})
++ endif()
++ if(HIP_CXX_COMPILER MATCHES ".*hipcc")
++ if(HIP_CXX_COMPILER_VERSION_OUTPUT MATCHES "InstalledDir:[ \t]*([^\n]*)")
++ get_filename_component(HIP_CLANG_ROOT "${CMAKE_MATCH_1}" DIRECTORY)
++ endif()
++ elseif (HIP_CXX_COMPILER MATCHES ".*clang\\+\\+")
++ get_filename_component(_HIP_CLANG_REAL_PATH "${HIP_CXX_COMPILER}" REALPATH)
++ get_filename_component(_HIP_CLANG_BIN_PATH "${_HIP_CLANG_REAL_PATH}" DIRECTORY)
++ get_filename_component(HIP_CLANG_ROOT "${_HIP_CLANG_BIN_PATH}" DIRECTORY)
++ endif()
++
++
++ file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS ${HIP_CLANG_ROOT}/lib/clang/*/include)
++ find_path(HIP_CLANG_INCLUDE_PATH stddef.h
++ HINTS
+ ${HIP_CLANG_INCLUDE_SEARCH_PATHS}
+- NO_DEFAULT_PATH)
++ NO_DEFAULT_PATH)
++ # Since INTERFACE_INCLUDE_DIRECTORIES need to set the parent directory
++ # of HIP_CLANG_INCLUDE_PATH incase using find_path() of stddefs.h
++ set(HIP_CLANG_INCLUDE_PATH "${HIP_CLANG_INCLUDE_PATH}/..")
++ endif() # HIP_CXX_COMPILER Check
++ endif() # CLANG_INCLUDE_PATH_FETCH_EXIT_CODE Check
++
+ if(NOT WIN32)
+ find_dependency(AMDDeviceLibs)
+ endif()
+ set(AMDGPU_TARGETS "gfx900;gfx906;gfx908;gfx90a;gfx1030" CACHE STRING "AMD GPU targets to compile for")
+ set(GPU_TARGETS "${AMDGPU_TARGETS}" CACHE STRING "GPU targets to compile for")
+-endif()
++endif() # HIP_COMPILER check
+
+ if(NOT WIN32)
+ find_dependency(amd_comgr)
+@@ -263,11 +284,11 @@ if(HIP_COMPILER STREQUAL "clang")
+ hip_add_interface_link_flags(hip::device --hip-link)
+
+ set_property(TARGET hip::device APPEND PROPERTY
+- INTERFACE_INCLUDE_DIRECTORIES "${HIP_CLANG_INCLUDE_PATH}/.."
++ INTERFACE_INCLUDE_DIRECTORIES "${HIP_CLANG_INCLUDE_PATH}"
+ )
+
+ set_property(TARGET hip::device APPEND PROPERTY
+- INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${HIP_CLANG_INCLUDE_PATH}/.."
++ INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${HIP_CLANG_INCLUDE_PATH}"
+ )
+
+ foreach(GPU_TARGET ${GPU_TARGETS})
+@@ -291,25 +312,24 @@ if(HIP_COMPILER STREQUAL "clang")
+ endif()
+ endif()
+
+- file(GLOB HIP_CLANGRT_LIB_SEARCH_PATHS "${HIP_CLANG_ROOT}/lib/clang/*/lib/*")
+- find_library(CLANGRT_BUILTINS
+- NAMES
+- clang_rt.builtins
+- clang_rt.builtins-x86_64
+- PATHS
+- ${HIP_CLANGRT_LIB_SEARCH_PATHS}
+- ${HIP_CLANG_INCLUDE_PATH}/../lib/linux
+- ${HIP_CLANG_INCLUDE_PATH}/../lib/windows
+- NO_DEFAULT_PATH)
++
++ # Use HIP_CXX option -print-libgcc-file-name --rtlib=compiler-rt
++ # To fetch the compiler rt library file name.
++ execute_process(
++ COMMAND ${HIP_CXX_COMPILER} -print-libgcc-file-name --rtlib=compiler-rt
++ OUTPUT_VARIABLE CLANGRT_BUILTINS
++ OUTPUT_STRIP_TRAILING_WHITESPACE
++ RESULT_VARIABLE CLANGRT_BUILTINS_FETCH_EXIT_CODE)
+
+ # Add support for __fp16 and _Float16, explicitly link with compiler-rt
+- if(NOT CLANGRT_BUILTINS)
+- message(FATAL_ERROR "clangrt builtins lib not found")
+- else()
++ if( "${CLANGRT_BUILTINS_FETCH_EXIT_CODE}" STREQUAL "0" )
++ # CLANG_RT Builtins found Successfully Set interface link libraries property
+ set_property(TARGET hip::host APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${CLANGRT_BUILTINS}")
+ set_property(TARGET hip::device APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${CLANGRT_BUILTINS}")
+- endif()
+-endif()
++ else()
++ message(STATUS "clangrt builtins lib not found: ${CLANGRT_BUILTINS_FETCH_EXIT_CODE}")
++ endif() # CLANGRT_BUILTINS_FETCH_EXIT_CODE Check
++endif() # HIP_COMPILER Check
+
+ set( hip_LIBRARIES hip::host hip::device)
+ set( hip_LIBRARY ${hip_LIBRARIES})
+--
+2.38.1
+
diff --git a/dev-util/hip/files/0002-SWDEV-355608-Remove-clang-include-path-2996.patch b/dev-util/hip/files/0002-SWDEV-355608-Remove-clang-include-path-2996.patch
new file mode 100644
index 000000000000..6d64ad8c9fd8
--- /dev/null
+++ b/dev-util/hip/files/0002-SWDEV-355608-Remove-clang-include-path-2996.patch
@@ -0,0 +1,51 @@
+From 7613e00fe0299d6584d3ee67e5d4010e7fc0866a Mon Sep 17 00:00:00 2001
+From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com>
+Date: Fri, 14 Oct 2022 16:02:40 +0530
+Subject: [PATCH 2/3] SWDEV-355608 - Remove clang include path (#2996)
+
+Clang doesn't need to be told where to find the clang headers
+
+Change-Id: I175781731c43647676d91eedc8a915124f2479ab
+Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
+---
+ bin/hipcc.pl | 11 -----------
+ 1 file changed, 11 deletions(-)
+
+diff --git a/bin/hipcc.pl b/bin/hipcc.pl
+index 2a01dcc3..7e82cad8 100755
+--- a/bin/hipcc.pl
++++ b/bin/hipcc.pl
+@@ -162,9 +162,6 @@ if ($HIP_PLATFORM eq "amd") {
+ $HIP_CLANG_RT_LIB = `$HIPCC --print-runtime-dir`;
+ chomp($HIP_CLANG_RT_LIB);
+
+- if (! defined $HIP_CLANG_INCLUDE_PATH) {
+- $HIP_CLANG_INCLUDE_PATH = abs_path("$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/include");
+- }
+ if (! defined $HIP_INCLUDE_PATH) {
+ $HIP_INCLUDE_PATH = "$HIP_PATH/include";
+ }
+@@ -177,20 +174,12 @@ if ($HIP_PLATFORM eq "amd") {
+ print ("HIP_ROCCLR_HOME=$HIP_ROCCLR_HOME\n");
+ }
+ print ("HIP_CLANG_PATH=$HIP_CLANG_PATH\n");
+- print ("HIP_CLANG_INCLUDE_PATH=$HIP_CLANG_INCLUDE_PATH\n");
+ print ("HIP_INCLUDE_PATH=$HIP_INCLUDE_PATH\n");
+ print ("HIP_LIB_PATH=$HIP_LIB_PATH\n");
+ print ("DEVICE_LIB_PATH=$DEVICE_LIB_PATH\n");
+ print ("HIP_CLANG_RT_LIB=$HIP_CLANG_RT_LIB\n");
+ }
+
+- if ($isWindows) {
+- $HIPCXXFLAGS .= " -std=c++14 -fms-extensions -fms-compatibility";
+- } else {
+- $HIPCXXFLAGS .= " -std=c++11";
+- }
+- $HIPCXXFLAGS .= " -isystem \"$HIP_CLANG_INCLUDE_PATH/..\"";
+- $HIPCFLAGS .= " -isystem \"$HIP_CLANG_INCLUDE_PATH/..\"";
+ $HIPLDFLAGS .= " -L\"$HIP_LIB_PATH\"";
+ if ($isWindows) {
+ $HIPLDFLAGS .= " -lamdhip64";
+--
+2.38.1
+
diff --git a/dev-util/hip/files/0003-SWDEV-352878-Removed-relative-path-based-CLANG-inclu.patch b/dev-util/hip/files/0003-SWDEV-352878-Removed-relative-path-based-CLANG-inclu.patch
new file mode 100644
index 000000000000..f92cce4cf8d8
--- /dev/null
+++ b/dev-util/hip/files/0003-SWDEV-352878-Removed-relative-path-based-CLANG-inclu.patch
@@ -0,0 +1,173 @@
+From fddbcef9a5a45ab63d4805c53d1f8fcf5c30d095 Mon Sep 17 00:00:00 2001
+From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com>
+Date: Fri, 6 Jan 2023 02:37:15 +0530
+Subject: [PATCH 3/3] SWDEV-352878 - Removed relative path based CLANG include,
+ CLANGRT dependencies (#3124)
+
+Change-Id: Ifdcd117679bff548a6351ba915a8272689e647de
+Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
+---
+ cmake/FindHIP.cmake | 37 ++++++++++++++++++++++++++++-
+ hip-lang-config.cmake.in | 51 +++++++++++++++++++++-------------------
+ 2 files changed, 63 insertions(+), 25 deletions(-)
+
+diff --git a/cmake/FindHIP.cmake b/cmake/FindHIP.cmake
+index 8b196dea..109c9f65 100644
+--- a/cmake/FindHIP.cmake
++++ b/cmake/FindHIP.cmake
+@@ -48,6 +48,29 @@ mark_as_advanced(HIP_HOST_COMPILATION_CPP)
+ # FIND: HIP and associated helper binaries
+ ###############################################################################
+
++if(NOT HIP_CXX_COMPILER)
++ set(HIP_CXX_COMPILER ${CMAKE_CXX_COMPILER})
++endif()
++
++# Approach: To find HIP_CLANG_PATH using HIP_CXX_COMPILER options
++# Using --version option of HIP_CXX_COMPILER get the Install Directory
++# This install directory is set as the HIP_CLANG_PATH.
++# IF not successful in getting the Install Directory using HIP_CXX_COMPILER
++# fallback to Old Method to find HIP_CLANG_PATH from ENV Vars, ROCMPATH, HIPPATH etc.
++execute_process(COMMAND ${HIP_CXX_COMPILER} --version
++ OUTPUT_STRIP_TRAILING_WHITESPACE
++ OUTPUT_VARIABLE HIP_CXX_COMPILER_VERSION_OUTPUT)
++if(HIP_CXX_COMPILER MATCHES ".*hipcc")
++ if(HIP_CXX_COMPILER_VERSION_OUTPUT MATCHES "InstalledDir:[ \t]*([^\n]*)")
++ get_filename_component(HIP_CLANG_INSTALL_DIR "${CMAKE_MATCH_1}" DIRECTORY)
++ endif()
++elseif (HIP_CXX_COMPILER MATCHES ".*clang\\+\\+")
++ get_filename_component(_HIP_CLANG_REAL_PATH "${HIP_CXX_COMPILER}" REALPATH)
++ get_filename_component(_HIP_CLANG_BIN_PATH "${_HIP_CLANG_REAL_PATH}" DIRECTORY)
++ get_filename_component(HIP_CLANG_INSTALL_DIR "${_HIP_CLANG_BIN_PATH}" DIRECTORY)
++endif()
++
++
+ get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../" REALPATH)
+
+ # HIP is currently not supported for apple
+@@ -230,6 +253,10 @@ if("${HIP_COMPILER}" STREQUAL "nvcc")
+ elseif("${HIP_COMPILER}" STREQUAL "clang")
+ #Set HIP_CLANG_PATH
+ if("x${HIP_CLANG_PATH}" STREQUAL "x")
++ # IF HIP_CLANG_INSTALL_DIR is Found
++ if( HIP_CLANG_INSTALL_DIR )
++ set(HIP_CLANG_PATH ${HIP_CLANG_INSTALL_DIR})
++ else() # IF HIP_CLANG_INSTALL_DIR is not found
+ if(DEFINED ENV{HIP_CLANG_PATH})
+ set(HIP_CLANG_PATH $ENV{HIP_CLANG_PATH})
+ elseif(DEFINED ENV{ROCM_PATH})
+@@ -252,7 +279,9 @@ elseif("${HIP_COMPILER}" STREQUAL "clang")
+ else()
+ message(FATAL_ERROR "Unable to find the clang compiler path. Set ROCM_PATH or HIP_PATH in env ")
+ endif()
+- endif()
++ endif() # HIP_CLANG_INSTALL_DIR Check
++ endif() # Set HIP_CLANG_PATH
++
+ #Number of parallel jobs by default is 1
+ if(NOT DEFINED HIP_CLANG_NUM_PARALLEL_JOBS)
+ set(HIP_CLANG_NUM_PARALLEL_JOBS 1)
+@@ -660,6 +689,10 @@ macro(HIP_ADD_EXECUTABLE hip_target)
+ endif()
+ if("${HIP_COMPILER}" STREQUAL "clang")
+ if("x${HIP_CLANG_PATH}" STREQUAL "x")
++ # IF HIP_CLANG_INSTALL_DIR is Found
++ if( HIP_CLANG_INSTALL_DIR )
++ set(HIP_CLANG_PATH ${HIP_CLANG_INSTALL_DIR})
++ else() # IF HIP_CLANG_INSTALL_DIR is not found
+ if(DEFINED ENV{HIP_CLANG_PATH})
+ set(HIP_CLANG_PATH $ENV{HIP_CLANG_PATH})
+ elseif(DEFINED ENV{ROCM_PATH})
+@@ -682,7 +715,9 @@ macro(HIP_ADD_EXECUTABLE hip_target)
+ else()
+ message(FATAL_ERROR "Unable to find the clang compiler path. Set ROCM_PATH or HIP_PATH in env")
+ endif()
++ endif() # HIP_CLANG_INSTALL_DIR Check
+ endif()
++
+ set(CMAKE_HIP_LINK_EXECUTABLE "${HIP_HIPCC_CMAKE_LINKER_HELPER} ${HIP_CLANG_PATH} ${HIP_CLANG_PARALLEL_BUILD_LINK_OPTIONS} <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+ else()
+ set(CMAKE_HIP_LINK_EXECUTABLE "${HIP_HIPCC_CMAKE_LINKER_HELPER} <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+diff --git a/hip-lang-config.cmake.in b/hip-lang-config.cmake.in
+index 9250a68a..1cf4e40f 100644
+--- a/hip-lang-config.cmake.in
++++ b/hip-lang-config.cmake.in
+@@ -70,15 +70,6 @@ get_filename_component(_DIR "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
+ get_filename_component(_IMPORT_PREFIX "${_DIR}/../../../" REALPATH)
+
+
+-#need _IMPORT_PREFIX to be set #FILE_REORG_BACKWARD_COMPATIBILITY
+-file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS "${_IMPORT_PREFIX}/../llvm/lib/clang/*/include")
+-file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS_REORG "${_IMPORT_PREFIX}/llvm/lib/clang/*/include")
+-find_path(HIP_CLANG_INCLUDE_PATH __clang_cuda_math.h
+- HINTS ${HIP_CLANG_INCLUDE_SEARCH_PATHS}
+- ${HIP_CLANG_INCLUDE_SEARCH_PATHS_REORG}
+- NO_DEFAULT_PATH)
+-get_filename_component(HIP_CLANG_INCLUDE_PATH "${HIP_CLANG_INCLUDE_PATH}" DIRECTORY)
+-
+ #If HIP isnot installed under ROCm, need this to find HSA assuming HSA is under ROCm
+ if( DEFINED ENV{ROCM_PATH} )
+ set(ROCM_PATH "$ENV{ROCM_PATH}")
+@@ -96,18 +87,10 @@ if (NOT HSA_HEADER)
+ message (FATAL_ERROR "HSA header not found! ROCM_PATH environment not set")
+ endif()
+
+-get_filename_component(HIP_COMPILER_INSTALL_PATH ${CMAKE_HIP_COMPILER} DIRECTORY)
+-file(GLOB HIP_CLANGRT_LIB_SEARCH_PATHS "${HIP_COMPILER_INSTALL_PATH}/../lib/clang/*/lib/*")
+-find_library(CLANGRT_BUILTINS
+- NAMES
+- clang_rt.builtins
+- clang_rt.builtins-x86_64
+- PATHS
+- ${HIP_CLANGRT_LIB_SEARCH_PATHS}
+- ${HIP_CLANG_INCLUDE_PATH}/../lib/linux)
++
+ set_target_properties(hip-lang::device PROPERTIES
+- INTERFACE_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:HIP>:${_IMPORT_PREFIX}/include;${HIP_CLANG_INCLUDE_PATH}>"
+- INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:HIP>:${_IMPORT_PREFIX}/include;${HIP_CLANG_INCLUDE_PATH}>"
++ INTERFACE_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:HIP>:${_IMPORT_PREFIX}/include>"
++ INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:HIP>:${_IMPORT_PREFIX}/include>"
+ )
+
+ set_target_properties(hip-lang::amdhip64 PROPERTIES
+@@ -133,13 +116,33 @@ set_property(TARGET hip-lang::device APPEND PROPERTY
+ INTERFACE_LINK_OPTIONS "$<$<LINK_LANGUAGE:HIP>:--hip-link>"
+ )
+
++# Approach: Check CLANGRT LIB support for CMAKE_HIP_COMPILER
++# Use CMAKE_HIP_COMPILER option -print-libgcc-file-name --rtlib=compiler-rt
++# Note: For Linux add additional option -unwindlib=libgcc also
++# To fetch the compiler rt library file name and confirm.
++# If unsuccessful in getting clangrt using this option then
++# FATAL_ERROR message send since compiler-rt linkage dependency is mandatory.
++# If successful then --rtlib=compiler-rt (and -unwindlib=libgcc for non windows)
++# added to Target's INTERFACE_LINK_LIBRARIES property
++if (NOT WIN32)
++ set(CLANGRT_LINUX_OPTION "-unwindlib=libgcc")
++endif()
++
++execute_process(
++ COMMAND ${CMAKE_HIP_COMPILER} -print-libgcc-file-name --rtlib=compiler-rt ${CLANGRT_LINUX_OPTION}
++ OUTPUT_VARIABLE CLANGRT_BUILTINS
++ OUTPUT_STRIP_TRAILING_WHITESPACE
++ RESULT_VARIABLE CLANGRT_BUILTINS_FETCH_EXIT_CODE)
++
+ # Add support for __fp16 and _Float16, explicitly link with compiler-rt
+-if(NOT CLANGRT_BUILTINS)
+- message(FATAL_ERROR "clangrt builtins lib not found")
+-else()
++if( "${CLANGRT_BUILTINS_FETCH_EXIT_CODE}" STREQUAL "0" )
+ set_property(TARGET hip-lang::device APPEND PROPERTY
+- INTERFACE_LINK_LIBRARIES "$<$<LINK_LANGUAGE:HIP>:${CLANGRT_BUILTINS}>"
++ INTERFACE_LINK_OPTIONS $<$<LINK_LANGUAGE:HIP>:--rtlib=compiler-rt ${CLANGRT_LINUX_OPTION}>
+ )
++else()
++ # FATAL_ERROR send if not successfull on compiler-rt linkage dependency
++ message(FATAL_ERROR
++ "${CMAKE_FIND_PACKAGE_NAME} Error:${CLANGRT_BUILTINS_FETCH_EXIT_CODE} - clangrt builtins lib could not be found.")
+ endif()
+
+ # Approved by CMake to use this name. This is used so that HIP can
+--
+2.38.1
+
diff --git a/dev-util/hip/files/hip-4.2.0-cancel-hcc-header-removal.patch b/dev-util/hip/files/hip-4.2.0-cancel-hcc-header-removal.patch
new file mode 100644
index 000000000000..08e0f3a3d4e3
--- /dev/null
+++ b/dev-util/hip/files/hip-4.2.0-cancel-hcc-header-removal.patch
@@ -0,0 +1,18 @@
+hcc now deprecated by ROCm upstream. They use cmake to delete hcc headers for upgrating hip on other distros,
+but Gentoo don't need this and the following code causes sandbox violation (#799257).
+
+github.com/ROCm-Developer-Tools/HIP/commit/c2adc70d4df3d30ef0db84d47be14b99b01aa340 introduce these lines.
+
+--- orig/CMakeLists.txt
++++ HIP-rocm-4.2.0/CMakeLists.txt
+@@ -333,10 +333,6 @@ if(NOT ${INSTALL_SOURCE} EQUAL 0)
+ endif()
+ install(DIRECTORY bin DESTINATION . USE_SOURCE_PERMISSIONS)
+
+- # The following two lines will be removed after upstream updation
+- install(CODE "MESSAGE(\"Removing ${CMAKE_INSTALL_PREFIX}/include\")")
+- install(CODE "file(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/include)")
+-
+ install(DIRECTORY include DESTINATION .)
+ install(DIRECTORY cmake DESTINATION .)
+ endif()
diff --git a/dev-util/hip/files/hip-4.2.0-config-cmake-in.patch b/dev-util/hip/files/hip-4.2.0-config-cmake-in.patch
new file mode 100644
index 000000000000..12644828af78
--- /dev/null
+++ b/dev-util/hip/files/hip-4.2.0-config-cmake-in.patch
@@ -0,0 +1,15 @@
+since _IMPORT_PREFIX=/opt/gentoo/usr/lib/hip, INTERFACE_INCLUDE_DIRECTORIES should change
+
+--- orig/hip-config.cmake.in
++++ HIP-rocm-4.2.0/hip-config.cmake.in
+@@ -185,8 +185,8 @@ if(HIP_RUNTIME MATCHES "rocclr")
+
+ if(NOT WIN32)
+ set_target_properties(hip::device PROPERTIES
+- INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/../include"
+- INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/../include"
++ INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
++ INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
+ )
+ endif()
+ endif()
diff --git a/dev-util/hip/files/hip-5.0.1-DisableTest.patch b/dev-util/hip/files/hip-5.0.1-DisableTest.patch
new file mode 100644
index 000000000000..d41b06efc8c9
--- /dev/null
+++ b/dev-util/hip/files/hip-5.0.1-DisableTest.patch
@@ -0,0 +1,32 @@
+Index: hipamd-rocm-5.0.1/CMakeLists.txt
+===================================================================
+--- hipamd-rocm-5.0.1.orig/CMakeLists.txt
++++ hipamd-rocm-5.0.1/CMakeLists.txt
+@@ -503,27 +503,6 @@ endif()
+ if(NOT WIN32)
+ set(HIP_ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR})
+ set(HIP_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR})
+-if(HIP_PLATFORM STREQUAL "nvidia")
+- execute_process(COMMAND "${CMAKE_COMMAND}" -E copy_directory "${HIP_SRC_PATH}/include" "${HIP_ROOT_DIR}/include" RESULT_VARIABLE RUN_HIT ERROR_QUIET)
+-endif()
+-execute_process(COMMAND "${CMAKE_COMMAND}" -E copy_directory "${HIP_COMMON_INCLUDE_DIR}/hip/" "${HIP_ROOT_DIR}/include/hip/" RESULT_VARIABLE RUN_HIT ERROR_QUIET)
+-execute_process(COMMAND "${CMAKE_COMMAND}" -E copy_directory "${HIP_COMMON_DIR}/cmake" "${HIP_ROOT_DIR}/cmake" RESULT_VARIABLE RUN_HIT ERROR_QUIET)
+-if(${RUN_HIT} EQUAL 0)
+- execute_process(COMMAND "${CMAKE_COMMAND}" -E copy_directory "${HIP_COMMON_BIN_DIR}" "${HIP_ROOT_DIR}/bin" RESULT_VARIABLE RUN_HIT ERROR_QUIET)
+-endif()
+-if(HIP_CATCH_TEST EQUAL "1")
+- enable_testing()
+- set(HIP_PATH ${HIP_ROOT_DIR})
+- add_subdirectory(${HIP_COMMON_DIR}/tests/catch ${PROJECT_BINARY_DIR}/catch)
+-else()
+- if(${RUN_HIT} EQUAL 0)
+- set(CMAKE_MODULE_PATH "${HIP_ROOT_DIR}/cmake" ${CMAKE_MODULE_PATH})
+- include(${HIP_COMMON_DIR}/tests/hit/HIT.cmake)
+- include(${HIP_COMMON_DIR}/tests/Tests.cmake)
+- else()
+- message(STATUS "Testing targets will not be available. To enable them please ensure that the HIP installation directory is writeable. Use -DCMAKE_INSTALL_PREFIX to specify a suitable location")
+- endif()
+-endif()
+ endif()
+
+ #############################
diff --git a/dev-util/hip/files/hip-5.0.1-hip_vector_types.patch b/dev-util/hip/files/hip-5.0.1-hip_vector_types.patch
new file mode 100644
index 000000000000..7a1a79b2a936
--- /dev/null
+++ b/dev-util/hip/files/hip-5.0.1-hip_vector_types.patch
@@ -0,0 +1,11 @@
+mitigate compilation error
+--- a/include/hip/amd_detail/amd_hip_vector_types.h
++++ b/include/hip/amd_detail/amd_hip_vector_types.h
+@@ -45,6 +45,7 @@ THE SOFTWARE.
+
+ #if defined(__cplusplus)
+ #if !defined(__HIPCC_RTC__)
++ #include <new>
+ #include <array>
+ #include <iosfwd>
+ #include <type_traits>
diff --git a/dev-util/hip/files/hip-5.0.2-correct-ldflag.patch b/dev-util/hip/files/hip-5.0.2-correct-ldflag.patch
new file mode 100644
index 000000000000..81d1bc3b8552
--- /dev/null
+++ b/dev-util/hip/files/hip-5.0.2-correct-ldflag.patch
@@ -0,0 +1,18 @@
+This removes ldflag -L"/usr/lib" and -Wl,-rpath=/usr/lib:/usr/lib which
+causes `ld: skipping incompatible /usr/lib/libm.so when searching for -lm`
+Reference: https://github.com/justxi/rocm/issues/8#issuecomment-1166193820
+===================================================================
+--- HIP-rocm-5.1.3.orig/bin/hipcc.pl
++++ HIP-rocm-5.1.3/bin/hipcc.pl
+@@ -703,9 +703,9 @@ if ($HIP_PLATFORM eq "amd") {
+
+ if (not $isWindows and not $compileOnly) {
+ if ($linkType eq 0) {
+- $toolArgs = " -L$HIP_LIB_PATH -lamdhip64 -L$ROCM_PATH/lib -lhsa-runtime64 -ldl -lnuma " . ${toolArgs};
++ $toolArgs = " -lamdhip64 -lhsa-runtime64 -ldl -lnuma " . ${toolArgs};
+ } else {
+- $toolArgs = " -Wl,--enable-new-dtags -Wl,-rpath=$HIP_LIB_PATH:$ROCM_PATH/lib -lamdhip64 " . ${toolArgs};
++ $toolArgs = " -Wl,--enable-new-dtags -lamdhip64 " . ${toolArgs};
+ }
+ # To support __fp16 and _Float16, explicitly link with compiler-rt
+ $HIP_CLANG_BUILTIN_LIB="/opt/gentoo/opt/gentoo/usr/lib/llvm/14/bin/../../../../lib/clang/14.0.6/lib/$HIP_CLANG_TARGET/libclang_rt.builtins.a";
diff --git a/dev-util/hip/files/hip-5.0.2-set-build-id.patch b/dev-util/hip/files/hip-5.0.2-set-build-id.patch
new file mode 100644
index 000000000000..21dfadf18b61
--- /dev/null
+++ b/dev-util/hip/files/hip-5.0.2-set-build-id.patch
@@ -0,0 +1,20 @@
+If git is not found, HIP_VERSION_BUILD_ID will not be set, causing bug 853718
+===================================================================
+--- hipamd-rocm-5.0.2.orig/CMakeLists.txt
++++ hipamd-rocm-5.0.2/CMakeLists.txt
+@@ -89,6 +89,7 @@ list(GET VERSION_LIST 2 HIP_VERSION_PATC
+ string(REPLACE "-" ";" VERSION_LIST ${HIP_VERSION_PATCH_GITHASH})
+ list(GET VERSION_LIST 0 HIP_VERSION_PATCH)
+ set(HIP_VERSION_GITDATE 0)
++set(HIP_VERSION_BUILD_ID 0)
+
+ find_package(Git)
+
+@@ -126,7 +127,6 @@ if(GIT_FOUND)
+ set(HIP_VERSION_GITHASH ${git_output})
+ endif()
+
+- set(HIP_VERSION_BUILD_ID 0)
+ set(HIP_VERSION_BUILD_NAME "")
+ if(NOT DEFINED ENV{HIP_OFFICIAL_BUILD} AND NOT HIP_OFFICIAL_BUILD)
+ # FIXME: Disabling it for ROCm 5.0
diff --git a/dev-util/hip/files/hip-5.1.3-clang-include-path.patch b/dev-util/hip/files/hip-5.1.3-clang-include-path.patch
new file mode 100644
index 000000000000..bf1f2dd32ce5
--- /dev/null
+++ b/dev-util/hip/files/hip-5.1.3-clang-include-path.patch
@@ -0,0 +1,12 @@
+pass HIP_CLANG_INCLUDE_PATH which is determined by clang -print-resource-dir
+===================================================================
+--- HIP-rocm-5.1.3.orig/bin/hipcc.pl
++++ HIP-rocm-5.1.3/bin/hipcc.pl
+@@ -105,6 +105,7 @@ $ROCM_PATH = $hipvars::ROCM_PATH;
+ $HIP_VERSION = $hipvars::HIP_VERSION;
+ $HSA_PATH = $hipvars::HSA_PATH;
+ $HIP_ROCCLR_HOME = $hipvars::HIP_ROCCLR_HOME;
++$HIP_CLANG_INCLUDE_PATH = $hipvars::HIP_CLANG_INCLUDE_PATH;
+
+ if ($HIP_PLATFORM eq "amd") {
+ # If using ROCclr runtime, need to find HIP_ROCCLR_HOME
diff --git a/dev-util/hip/files/hip-5.1.3-correct-sample-install-location.patch b/dev-util/hip/files/hip-5.1.3-correct-sample-install-location.patch
new file mode 100644
index 000000000000..57ac5cc3e992
--- /dev/null
+++ b/dev-util/hip/files/hip-5.1.3-correct-sample-install-location.patch
@@ -0,0 +1,13 @@
+Index: hipamd-rocm-5.1.3/packaging/CMakeLists.txt
+===================================================================
+--- hipamd-rocm-5.1.3.orig/packaging/CMakeLists.txt
++++ hipamd-rocm-5.1.3/packaging/CMakeLists.txt
+@@ -106,7 +106,7 @@ endif()
+ #End doc files install
+
+ #Begin samples files install
+-install(DIRECTORY ${HIP_COMMON_DIR}/samples DESTINATION . COMPONENT samples)
++install(DIRECTORY ${HIP_COMMON_DIR}/samples DESTINATION ${CMAKE_INSTALL_DOCDIR}/ COMPONENT samples)
+ #End samples files install
+
+ #Begin test files install
diff --git a/dev-util/hip/files/hip-5.1.3-fix-hip_prof_gen.patch b/dev-util/hip/files/hip-5.1.3-fix-hip_prof_gen.patch
new file mode 100644
index 000000000000..05b25e7178fa
--- /dev/null
+++ b/dev-util/hip/files/hip-5.1.3-fix-hip_prof_gen.patch
@@ -0,0 +1,38 @@
+Backported fb5a64025bb0e10173a1ee4f3475db322b74b594
+fix an issue in hip_prof_gen.py with GLenum.
+diff --git a/src/hip_prof_gen.py b/src/hip_prof_gen.py
+index bd32d5bf..a3071a75 100755
+--- a/src/hip_prof_gen.py
++++ b/src/hip_prof_gen.py
+@@ -81,7 +81,7 @@ def filtr_api_args(args_str):
+ args_str = re.sub(r'\s*,\s*', r',', args_str);
+ args_str = re.sub(r'\s+', r' ', args_str);
+ args_str = re.sub(r'\s*(\*+)\s*', r'\1 ', args_str);
+- args_str = re.sub(r'(enum|struct) ', '', args_str);
++ args_str = re.sub(r'(\benum|struct) ', '', args_str);
+ return args_str
+
+ # Normalizing types
+@@ -129,7 +129,9 @@ def pointer_ck(arg_type):
+ m = re.match(r'(.*)\*$', arg_type)
+ if m:
+ ptr_type = m.group(1)
+- ptr_type = re.sub(r'const ', '', ptr_type)
++ n = re.match(r'(.*)\*\*$', arg_type)
++ if not n:
++ ptr_type = re.sub(r'const ', '', ptr_type)
+ if ptr_type == 'void': ptr_type = ''
+ return ptr_type
+ #############################################################
+@@ -613,7 +615,7 @@ if (len(sys.argv) < 4):
+ " -p - HIP_INIT_API macro patching mode\n" +
+ "\n" +
+ " Example:\n" +
+- " $ " + sys.argv[0] + " -v -p -t --priv ./include/hip/amd_detail/hip_runtime_api.h" +
++ " $ " + sys.argv[0] + " -v -p -t --priv ../hip/include/hip/hip_runtime_api.h" +
+ " ./src ./include/hip/amd_detail/hip_prof_str.h ./include/hip/amd_detail/hip_prof_str.h.new");
+
+ # API header file given as an argument
+--
+2.34.1
+
diff --git a/dev-util/hip/files/hip-5.1.3-fno-stack-protector.patch b/dev-util/hip/files/hip-5.1.3-fno-stack-protector.patch
new file mode 100644
index 000000000000..c5957edba734
--- /dev/null
+++ b/dev-util/hip/files/hip-5.1.3-fno-stack-protector.patch
@@ -0,0 +1,16 @@
+Since 1e9b3a08b9243daae1bebd6bac3da939d924df1f /etc/clang/gentoo-hardened.cfg
+has -fstack-protector-strong which may cause build issues for HIP programs (bug
+#890377) Disable this by adding -fno-stack-protector into c/cxx flags in hipcc.
+===================================================================
+--- HIP-rocm-5.3.3.orig/bin/hipcc.pl
++++ HIP-rocm-5.3.3/bin/hipcc.pl
+@@ -687,6 +687,9 @@ if ($rdc and !$compileOnly and $HIP_PLAT
+ # pass-through CPP mode.
+
+ if ($HIP_PLATFORM eq "amd") {
++ # Append -fno-stack-protector due to stack protection for HIP is not supported
++ $HIPCXXFLAGS .= " -fno-stack-protector";
++ $HIPCFLAGS .= " -fno-stack-protector";
+ # Set default optimization level to -O3 for hip-clang.
+ if ($optArg eq "") {
+ $HIPCXXFLAGS .= " -O3";
diff --git a/dev-util/hip/files/hip-5.1.3-llvm-15-noinline-keyword.patch b/dev-util/hip/files/hip-5.1.3-llvm-15-noinline-keyword.patch
new file mode 100644
index 000000000000..de61356a5cc6
--- /dev/null
+++ b/dev-util/hip/files/hip-5.1.3-llvm-15-noinline-keyword.patch
@@ -0,0 +1,21 @@
+LLVM 15 adds __noinline__ as a keyword to match behaviour of GCC 12.
+
+When this macro is left in, it can cause the expression __attribute__((__noinline__)) to be expanded incorrectly.
+
+When the __noinline__ keyword is available disable the macro.
+
+Ref: https://reviews.llvm.org/D124866
+ https://bugs.gentoo.org/85712
+===================================================================
+--- a/include/hip/amd_detail/host_defines.h
++++ b/include/hip/amd_detail/host_defines.h
+@@ -47,7 +47,9 @@ THE SOFTWARE.
+ #define __constant__ __attribute__((constant))
+ #endif // !__CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__
+
++#if !defined(__has_feature) || !__has_feature(cuda_noinline_keyword)
+ #define __noinline__ __attribute__((noinline))
++#endif
+ #define __forceinline__ inline __attribute__((always_inline))
+
+ #if __HIP_NO_IMAGE_SUPPORT
diff --git a/dev-util/hip/files/hip-5.1.3-remove-cmake-doxygen-commands.patch b/dev-util/hip/files/hip-5.1.3-remove-cmake-doxygen-commands.patch
new file mode 100644
index 000000000000..921452b2ba92
--- /dev/null
+++ b/dev-util/hip/files/hip-5.1.3-remove-cmake-doxygen-commands.patch
@@ -0,0 +1,21 @@
+Index: hipamd-rocm-5.1.3/packaging/CMakeLists.txt
+===================================================================
+--- hipamd-rocm-5.1.3.orig/packaging/CMakeLists.txt
++++ hipamd-rocm-5.1.3/packaging/CMakeLists.txt
+@@ -88,16 +88,6 @@ install(FILES ${CMAKE_BINARY_DIR}/includ
+ DESTINATION include/hip COMPONENT dev)
+ #End dev files install
+
+-#Begin doc files install
+-find_program(DOXYGEN_EXE doxygen)
+-if(DOXYGEN_EXE)
+- add_custom_target(build_doxygen ALL
+- COMMAND HIP_PATH=${HIP_COMMON_DIR} doxygen ${HIP_COMMON_DIR}/docs/doxygen-input/doxy.cfg)
+- install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/RuntimeAPI/html
+- DESTINATION docs/RuntimeAPI COMPONENT doc)
+-endif()
+-#End doc files install
+-
+ #Begin samples files install
+ install(DIRECTORY ${HIP_COMMON_DIR}/samples DESTINATION ${CMAKE_INSTALL_DOCDIR}/ COMPONENT samples)
+ #End samples files install
diff --git a/dev-util/hip/files/hip-5.1.3-rocm-path.patch b/dev-util/hip/files/hip-5.1.3-rocm-path.patch
new file mode 100644
index 000000000000..2ce68b733577
--- /dev/null
+++ b/dev-util/hip/files/hip-5.1.3-rocm-path.patch
@@ -0,0 +1,13 @@
+explicitly specify `--rocm-path=/usr` because clang does not list
+it among the default paths
+===================================================================
+--- HIP-rocm-5.1.3.orig/bin/hipcc.pl
++++ HIP-rocm-5.1.3/bin/hipcc.pl
+@@ -696,6 +696,7 @@ if ($HIP_PLATFORM eq "amd") {
+
+ if ($hasHIP) {
+ if ($DEVICE_LIB_PATH ne "$ROCM_PATH/amdgcn/bitcode") {
++ $HIPCXXFLAGS .= " --rocm-path=\"$ROCM_PATH\"";
+ $HIPCXXFLAGS .= " --hip-device-lib-path=\"$DEVICE_LIB_PATH\"";
+ }
+ $HIPCXXFLAGS .= " -fhip-new-launch-api";
diff --git a/dev-util/hip/files/hip-5.3.3-correct-ldflag.patch b/dev-util/hip/files/hip-5.3.3-correct-ldflag.patch
new file mode 100644
index 000000000000..20d117841c2b
--- /dev/null
+++ b/dev-util/hip/files/hip-5.3.3-correct-ldflag.patch
@@ -0,0 +1,20 @@
+This removes ldflag -L"/usr/lib" and -Wl,-rpath=/usr/lib:/usr/lib which
+causes `ld: skipping incompatible /usr/lib/libm.so when searching for -lm`
+Reference: https://github.com/justxi/rocm/issues/8#issuecomment-1166193820
+===================================================================
+Index: HIP-rocm-5.3.3/bin/hipcc.pl
+===================================================================
+--- HIP-rocm-5.3.3.orig/bin/hipcc.pl
++++ HIP-rocm-5.3.3/bin/hipcc.pl
+@@ -711,9 +711,9 @@ if ($HIP_PLATFORM eq "amd") {
+
+ if (not $isWindows and not $compileOnly) {
+ if ($linkType eq 0) {
+- $toolArgs = " -L$HIP_LIB_PATH -lamdhip64 -L$ROCM_PATH/lib -lhsa-runtime64 -ldl -lnuma " . ${toolArgs};
++ $toolArgs = " -lamdhip64 -lhsa-runtime64 -ldl -lnuma " . ${toolArgs};
+ } else {
+- $toolArgs = ${toolArgs} . " -Wl,--enable-new-dtags -Wl,-rpath=$HIP_LIB_PATH:$ROCM_PATH/lib -lamdhip64 ";
++ $toolArgs = ${toolArgs} . " -Wl,--enable-new-dtags -lamdhip64 ";
+ }
+ # To support __fp16 and _Float16, explicitly link with compiler-rt
+ $HIP_CLANG_BUILTIN_LIB="$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/$HIP_CLANG_TARGET/libclang_rt.builtins.a";
diff --git a/dev-util/hip/files/hip-5.3.3-disable-Werror.patch b/dev-util/hip/files/hip-5.3.3-disable-Werror.patch
new file mode 100644
index 000000000000..bed46bd144f4
--- /dev/null
+++ b/dev-util/hip/files/hip-5.3.3-disable-Werror.patch
@@ -0,0 +1,16 @@
+Index: hipamd-rocm-5.3.3/src/CMakeLists.txt
+===================================================================
+--- hipamd-rocm-5.3.3.orig/src/CMakeLists.txt
++++ hipamd-rocm-5.3.3/src/CMakeLists.txt
+@@ -44,11 +44,6 @@ if(ADDRESS_SANITIZER)
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ASAN_LINKER_FLAGS} -Wl,--build-id=sha1")
+ endif()
+
+-if(CMAKE_COMPILER_IS_GNUCC)
+- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
+- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
+-endif()
+-
+ option(DISABLE_DIRECT_DISPATCH "Disable Direct Dispatch" OFF)
+
+ option(BUILD_SHARED_LIBS "Build the shared library" ON)
diff --git a/dev-util/hip/files/hip-5.3.3-remove-cmake-doxygen-commands.patch b/dev-util/hip/files/hip-5.3.3-remove-cmake-doxygen-commands.patch
new file mode 100644
index 000000000000..c4cd955bed90
--- /dev/null
+++ b/dev-util/hip/files/hip-5.3.3-remove-cmake-doxygen-commands.patch
@@ -0,0 +1,21 @@
+Index: hipamd-rocm-5.3.3/packaging/CMakeLists.txt
+===================================================================
+--- hipamd-rocm-5.3.3.orig/packaging/CMakeLists.txt
++++ hipamd-rocm-5.3.3/packaging/CMakeLists.txt
+@@ -94,16 +94,6 @@ install(FILES ${CMAKE_BINARY_DIR}/.hipVe
+ install(DIRECTORY ${HIP_COMMON_DIR}/cmake/ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hip COMPONENT dev)
+ #End dev files install
+
+-#Begin doc files install
+-find_program(DOXYGEN_EXE doxygen)
+-if(DOXYGEN_EXE)
+- add_custom_target(build_doxygen ALL
+- COMMAND HIP_PATH=${HIP_COMMON_DIR} doxygen ${HIP_COMMON_DIR}/docs/doxygen-input/doxy.cfg)
+- install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/RuntimeAPI/html
+- DESTINATION ${CMAKE_INSTALL_DOCDIR}/RuntimeAPI COMPONENT doc)
+-endif()
+-#End doc files install
+-
+ #Begin samples files install
+ install(DIRECTORY ${HIP_COMMON_DIR}/samples DESTINATION ${CMAKE_INSTALL_DATADIR}/hip COMPONENT samples)
+ #End samples files install
diff --git a/dev-util/hip/files/hip-5.4.3-clang-include.patch b/dev-util/hip/files/hip-5.4.3-clang-include.patch
new file mode 100644
index 000000000000..21b2c5bac8e8
--- /dev/null
+++ b/dev-util/hip/files/hip-5.4.3-clang-include.patch
@@ -0,0 +1,30 @@
+diff --git a/bin/hipcc.pl b/bin/hipcc.pl
+index a143983..331881e 100755
+--- a/bin/hipcc.pl
++++ b/bin/hipcc.pl
+@@ -180,9 +180,6 @@ if ($HIP_PLATFORM eq "amd") {
+ $HIP_CLANG_RT_LIB = `$HIPCC --print-runtime-dir`;
+ chomp($HIP_CLANG_RT_LIB);
+
+- if (! defined $HIP_CLANG_INCLUDE_PATH) {
+- $HIP_CLANG_INCLUDE_PATH = abs_path("$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/include");
+- }
+ if (! defined $HIP_INCLUDE_PATH) {
+ $HIP_INCLUDE_PATH = "$HIP_PATH/include";
+ }
+@@ -195,15 +192,12 @@ if ($HIP_PLATFORM eq "amd") {
+ print ("HIP_ROCCLR_HOME=$HIP_ROCCLR_HOME\n");
+ }
+ print ("HIP_CLANG_PATH=$HIP_CLANG_PATH\n");
+- print ("HIP_CLANG_INCLUDE_PATH=$HIP_CLANG_INCLUDE_PATH\n");
+ print ("HIP_INCLUDE_PATH=$HIP_INCLUDE_PATH\n");
+ print ("HIP_LIB_PATH=$HIP_LIB_PATH\n");
+ print ("DEVICE_LIB_PATH=$DEVICE_LIB_PATH\n");
+ print ("HIP_CLANG_RT_LIB=$HIP_CLANG_RT_LIB\n");
+ }
+
+- $HIPCXXFLAGS .= " -isystem \"$HIP_CLANG_INCLUDE_PATH/..\"";
+- $HIPCFLAGS .= " -isystem \"$HIP_CLANG_INCLUDE_PATH/..\"";
+ $HIPLDFLAGS .= " -L\"$HIP_LIB_PATH\"";
+ if ($isWindows) {
+ $HIPLDFLAGS .= " -lamdhip64";
diff --git a/dev-util/hip/files/hip-5.4.3-clang-version.patch b/dev-util/hip/files/hip-5.4.3-clang-version.patch
new file mode 100644
index 000000000000..88290db66af0
--- /dev/null
+++ b/dev-util/hip/files/hip-5.4.3-clang-version.patch
@@ -0,0 +1,70 @@
+From 73430b62a5437d1ba6c36a1d812a1434d1ad9df7 Mon Sep 17 00:00:00 2001
+From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com>
+Date: Tue, 20 Dec 2022 06:51:12 +0530
+Subject: [PATCH 1/3] SWDEV-344620 - hipcc fails to parse version of clang in
+ some cases (#3119)
+
+Change-Id: I46f716c82a7500b9a2bcaf5f9ff4ad8a8f982770
+Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
+---
+ bin/hipcc.pl | 22 +++++++---------------
+ 1 file changed, 7 insertions(+), 15 deletions(-)
+
+diff --git a/bin/hipcc.pl b/bin/hipcc.pl
+index 645ae62d..2a01dcc3 100755
+--- a/bin/hipcc.pl
++++ b/bin/hipcc.pl
+@@ -144,7 +144,7 @@ if ($HIP_PLATFORM eq "amd") {
+ $execExtension = "";
+ if($isWindows) {
+ $execExtension = ".exe";
+- }
++ }
+ $HIPCC="$HIP_CLANG_PATH/clang++" . $execExtension;
+
+ # If $HIPCC clang++ is not compiled, use clang instead
+@@ -176,13 +176,9 @@ if ($HIP_PLATFORM eq "amd") {
+ $HIPLDFLAGS .= " -fuse-ld=lld";
+ $HIPLDFLAGS .= " --ld-path=$HIP_CLANG_PATH/lld-link.exe";
+ }
+- $HIP_CLANG_VERSION = `$HIPCC --version`;
+- $HIP_CLANG_VERSION=~/.*clang version (\S+).*/;
+- $HIP_CLANG_VERSION=$1;
+-
+- # Figure out the target with which llvm is configured
+- $HIP_CLANG_TARGET = `$HIPCC -print-target-triple`;
+- chomp($HIP_CLANG_TARGET);
++ # get Clang RT Builtin path
++ $HIP_CLANG_RT_LIB = `$HIPCC --print-runtime-dir`;
++ chomp($HIP_CLANG_RT_LIB);
+
+ if (! defined $HIP_CLANG_INCLUDE_PATH) {
+ $HIP_CLANG_INCLUDE_PATH = abs_path("$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/include");
+@@ -184,7 +181,7 @@ if ($HIP_PLATFORM eq "amd") {
+ print ("HIP_INCLUDE_PATH=$HIP_INCLUDE_PATH\n");
+ print ("HIP_LIB_PATH=$HIP_LIB_PATH\n");
+ print ("DEVICE_LIB_PATH=$DEVICE_LIB_PATH\n");
+- print ("HIP_CLANG_TARGET=$HIP_CLANG_TARGET\n");
++ print ("HIP_CLANG_RT_LIB=$HIP_CLANG_RT_LIB\n");
+ }
+
+ if ($isWindows) {
+@@ -715,13 +712,8 @@ if ($HIP_PLATFORM eq "amd") {
+ } else {
+ $toolArgs = ${toolArgs} . " -Wl,--enable-new-dtags -Wl,-rpath=$HIP_LIB_PATH:$ROCM_PATH/lib -lamdhip64 ";
+ }
+- # To support __fp16 and _Float16, explicitly link with compiler-rt
+- $HIP_CLANG_BUILTIN_LIB="$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/$HIP_CLANG_TARGET/libclang_rt.builtins.a";
+- if (-e $HIP_CLANG_BUILTIN_LIB) {
+- $toolArgs .= " -L$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/$HIP_CLANG_TARGET -lclang_rt.builtins "
+- } else {
+- $toolArgs .= " -L$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/linux -lclang_rt.builtins-x86_64 "
+- }
++
++ $toolArgs .= " -L$HIP_CLANG_RT_LIB -lclang_rt.builtins-x86_64 "
+ }
+ }
+
+--
+2.38.1
+
diff --git a/dev-util/hip/files/hip-5.4.3-correct-ldflag.patch b/dev-util/hip/files/hip-5.4.3-correct-ldflag.patch
new file mode 100644
index 000000000000..3dbbb6721f3b
--- /dev/null
+++ b/dev-util/hip/files/hip-5.4.3-correct-ldflag.patch
@@ -0,0 +1,20 @@
+This removes ldflag -L"/usr/lib" and -Wl,-rpath=/usr/lib:/usr/lib which
+causes `ld: skipping incompatible /usr/lib/libm.so when searching for -lm`
+Reference: https://github.com/justxi/rocm/issues/8#issuecomment-1166193820
+===================================================================
+Index: HIP-rocm-5.3.3/bin/hipcc.pl
+===================================================================
+--- HIP-rocm-5.3.3.orig/bin/hipcc.pl
++++ HIP-rocm-5.3.3/bin/hipcc.pl
+@@ -711,9 +711,9 @@ if ($HIP_PLATFORM eq "amd") {
+
+ if (not $isWindows and not $compileOnly) {
+ if ($linkType eq 0) {
+- $toolArgs = " -L$HIP_LIB_PATH -lamdhip64 -L$ROCM_PATH/lib -lhsa-runtime64 -ldl -lnuma " . ${toolArgs};
++ $toolArgs = " -lamdhip64 -lhsa-runtime64 -ldl -lnuma " . ${toolArgs};
+ } else {
+- $toolArgs = ${toolArgs} . " -Wl,-rpath=$HIP_LIB_PATH:$ROCM_PATH/lib -lamdhip64 ";
++ $toolArgs = ${toolArgs} . " -Wl,--enable-new-dtags -lamdhip64 ";
+ }
+ # To support __fp16 and _Float16, explicitly link with compiler-rt
+ $HIP_CLANG_BUILTIN_LIB="$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/$HIP_CLANG_TARGET/libclang_rt.builtins.a";
diff --git a/dev-util/hip/files/hip-5.4.3-fix-HIP_CLANG_PATH-detection.patch b/dev-util/hip/files/hip-5.4.3-fix-HIP_CLANG_PATH-detection.patch
new file mode 100644
index 000000000000..28277d9d880c
--- /dev/null
+++ b/dev-util/hip/files/hip-5.4.3-fix-HIP_CLANG_PATH-detection.patch
@@ -0,0 +1,26 @@
+From 03a7fd2937c146142fa95d22a0ee10df40442788 Mon Sep 17 00:00:00 2001
+From: Yiyang Wu <xgreenlandforwyy@gmail.com>
+Date: Sun, 19 Mar 2023 22:32:01 +0800
+Subject: [PATCH] FindHIP.cmake: fix HIP_CLANG_PATH detection via
+ HIP_CLANG_INSTALL_DIR
+
+---
+ cmake/FindHIP.cmake | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/cmake/FindHIP.cmake b/cmake/FindHIP.cmake
+index 109c9f65..5dc4c632 100644
+--- a/cmake/FindHIP.cmake
++++ b/cmake/FindHIP.cmake
+@@ -255,7 +255,7 @@ elseif("${HIP_COMPILER}" STREQUAL "clang")
+ if("x${HIP_CLANG_PATH}" STREQUAL "x")
+ # IF HIP_CLANG_INSTALL_DIR is Found
+ if( HIP_CLANG_INSTALL_DIR )
+- set(HIP_CLANG_PATH ${HIP_CLANG_INSTALL_DIR})
++ set(HIP_CLANG_PATH "${HIP_CLANG_INSTALL_DIR}/bin")
+ else() # IF HIP_CLANG_INSTALL_DIR is not found
+ if(DEFINED ENV{HIP_CLANG_PATH})
+ set(HIP_CLANG_PATH $ENV{HIP_CLANG_PATH})
+--
+2.40.0
+
diff --git a/dev-util/hip/files/hip-5.5.1-disable-Werror.patch b/dev-util/hip/files/hip-5.5.1-disable-Werror.patch
new file mode 100644
index 000000000000..ee104644fbda
--- /dev/null
+++ b/dev-util/hip/files/hip-5.5.1-disable-Werror.patch
@@ -0,0 +1,18 @@
+diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
+index 619d6a0..c520db0 100644
+--- hipamd-rocm-5.5.1.orig/src/CMakeLists.txt
++++ hipamd-rocm-5.5.1/src/CMakeLists.txt
+@@ -44,13 +44,6 @@ if(ADDRESS_SANITIZER)
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ASAN_LINKER_FLAGS} -Wl,--build-id=sha1")
+ endif()
+
+-if(CMAKE_COMPILER_IS_GNUCC)
+- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
+- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=deprecated-declarations")
+- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
+- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations")
+-endif()
+-
+ option(DISABLE_DIRECT_DISPATCH "Disable Direct Dispatch" OFF)
+
+ option(BUILD_SHARED_LIBS "Build the shared library" ON)
diff --git a/dev-util/hip/files/hip-5.7.0-install.patch b/dev-util/hip/files/hip-5.7.0-install.patch
new file mode 100644
index 000000000000..668e24af7c52
--- /dev/null
+++ b/dev-util/hip/files/hip-5.7.0-install.patch
@@ -0,0 +1,13 @@
+diff --git a/hipamd/CMakeLists.txt b/hipamd/CMakeLists.txt
+index a472c5b7a..ac6fdc2ab 100755
+--- a/hipamd/CMakeLists.txt
++++ b/hipamd/CMakeLists.txt
+@@ -396,8 +396,6 @@ if (NOT ${HIPCC_BIN_DIR} STREQUAL "")
+ install(PROGRAMS ${HIPCC_BIN_DIR}/hipcc.pl DESTINATION bin)
+ install(PROGRAMS ${HIPCC_BIN_DIR}/hipconfig.pl DESTINATION bin)
+ install(PROGRAMS ${HIPCC_BIN_DIR}/hipvars.pm DESTINATION bin)
+- install(PROGRAMS ${HIPCC_BIN_DIR}/hipcc.bat DESTINATION bin)
+- install(PROGRAMS ${HIPCC_BIN_DIR}/hipconfig.bat DESTINATION bin)
+ endif()
+
+ #############################
diff --git a/dev-util/hip/files/hip-5.7.1-disable-stack-protector.patch b/dev-util/hip/files/hip-5.7.1-disable-stack-protector.patch
new file mode 100644
index 000000000000..49d944ef4bc9
--- /dev/null
+++ b/dev-util/hip/files/hip-5.7.1-disable-stack-protector.patch
@@ -0,0 +1,13 @@
+Disable stack-protector (which is enabled by default gentoo-hardened) in device code.
+This is not required after https://github.com/llvm/llvm-project/pull/70799, but helps with older clang.
+Upstream bug: https://github.com/ROCm-Developer-Tools/clr/issues/21
+--- a/hipamd/src/hiprtc/hiprtcInternal.cpp
++++ b/hipamd/src/hiprtc/hiprtcInternal.cpp
+@@ -144,6 +144,7 @@ RTCCompileProgram::RTCCompileProgram(std::string name_) : RTCProgram(name_), fgp
+ compile_options_.push_back("-nogpuinc");
+ compile_options_.push_back("-Wno-gnu-line-marker");
+ compile_options_.push_back("-Wno-missing-prototypes");
++ compile_options_.push_back("-fno-stack-protector");
+ #ifdef _WIN32
+ compile_options_.push_back("-target");
+ compile_options_.push_back("x86_64-pc-windows-msvc");
diff --git a/dev-util/hip/files/hip-5.7.1-exec-stack.patch b/dev-util/hip/files/hip-5.7.1-exec-stack.patch
new file mode 100644
index 000000000000..744ca7b953c3
--- /dev/null
+++ b/dev-util/hip/files/hip-5.7.1-exec-stack.patch
@@ -0,0 +1,31 @@
+Upstream bug: https://github.com/ROCm-Developer-Tools/clr/issues/22
+--- a/hipamd/src/hip_embed_pch.sh
++++ b/hipamd/src/hip_embed_pch.sh
+@@ -178,6 +178,7 @@ EOF
+
+ echo "// Automatically generated script for HIP RTC." > $mcinFile
+ if [[ $isWindows -eq 0 ]]; then
++ echo " .section .note.GNU-stack,"",%progbits" >> $mcinFile
+ echo " .type __hipRTC_header,@object" >> $mcinFile
+ echo " .type __hipRTC_header_size,@object" >> $mcinFile
+ fi
+--- a/hipamd/src/hiprtc/cmake/HIPRTC.cmake
++++ b/hipamd/src/hiprtc/cmake/HIPRTC.cmake
+@@ -98,6 +98,7 @@ macro(generate_hiprtc_mcin HiprtcMcin HiprtcPreprocessedInput)
+ set(HIPRTC_TYPE_LINUX_ONLY "")
+ else()
+ set(HIPRTC_TYPE_LINUX_ONLY
++ " .section .note.GNU-stack,\"\",%progbits\n"
+ " .type __hipRTC_header,@object\n"
+ " .type __hipRTC_header_size,@object")
+ endif()
+--- a/hipamd/src/hip_embed_pch.sh
++++ b/hipamd/src/hip_embed_pch.sh
+@@ -111,6 +111,7 @@ cat >$tmp/hip_pch.h <<EOF
+ EOF
+
+ cat >$tmp/hip_pch.mcin <<EOF
++ .section .note.GNU-stack,"",%progbits
+ .type __hip_pch_wave32,@object
+ .section .hip_pch_wave32,"aMS",@progbits,1
+ .data
diff --git a/dev-util/hip/files/hip-5.7.1-extend-isa-compatibility-check.patch b/dev-util/hip/files/hip-5.7.1-extend-isa-compatibility-check.patch
new file mode 100644
index 000000000000..7853de693cde
--- /dev/null
+++ b/dev-util/hip/files/hip-5.7.1-extend-isa-compatibility-check.patch
@@ -0,0 +1,236 @@
+Combined with matching changes within rocr-runtime ebuild, this patch allows
+to load compatible kernels whenever possible.
+For example if AMDGPU_TARGETS is set to gfx1030 and some application
+was started on gfx1036, it loads gfx1030 kernel.
+
+Author: Cordell Bloor <cgmb@slerp.xyz>
+https://salsa.debian.org/rocm-team/rocm-hipamd/-/blob/master/debian/patches/0025-improve-rocclr-isa-compatibility-check.patch
+https://salsa.debian.org/rocm-team/rocm-hipamd/-/blob/master/debian/patches/0026-extend-hip-isa-compatibility-check.patch
+--- a/hipamd/src/hip_code_object.cpp
++++ b/hipamd/src/hip_code_object.cpp
+@@ -390,47 +390,123 @@ static bool getTripleTargetID(std::string bundled_co_entry_id, const void* code_
+ return true;
+ }
+
+-static bool isCodeObjectCompatibleWithDevice(std::string co_triple_target_id,
+- std::string agent_triple_target_id) {
++struct GfxPattern {
++ std::string root;
++ std::string suffixes;
++};
++
++static bool matches(const GfxPattern& p, const std::string& s) {
++ if (p.root.size() + 1 != s.size()) {
++ return false;
++ }
++ if (0 != std::memcmp(p.root.data(), s.data(), p.root.size())) {
++ return false;
++ }
++ return p.suffixes.find(s[p.root.size()]) != std::string::npos;
++}
++
++static bool isGfx900EquivalentProcessor(const std::string& processor) {
++ return matches(GfxPattern{"gfx90", "029c"}, processor);
++}
++
++static bool isGfx900SupersetProcessor(const std::string& processor) {
++ return matches(GfxPattern{"gfx90", "0269c"}, processor);
++}
++
++static bool isGfx1030EquivalentProcessor(const std::string& processor) {
++ return matches(GfxPattern{"gfx103", "0123456"}, processor);
++}
++
++static bool isGfx1010EquivalentProcessor(const std::string& processor) {
++ return matches(GfxPattern{"gfx101", "02"}, processor);
++}
++
++static bool isGfx1010SupersetProcessor(const std::string& processor) {
++ return matches(GfxPattern{"gfx101", "0123"}, processor);
++}
++
++enum CompatibilityScore {
++ CS_EXACT_MATCH = 1 << 4,
++ CS_PROCESSOR_MATCH = 1 << 3,
++ CS_PROCESSOR_COMPATIBLE = 1 << 2,
++ CS_XNACK_SPECIALIZED = 1 << 1,
++ CS_SRAM_ECC_SPECIALIZED = 1 << 0,
++ CS_INCOMPATIBLE = 0,
++};
++
++static int getProcessorCompatibilityScore(const std::string& co_processor,
++ const std::string& agent_processor) {
++ if (co_processor == agent_processor)
++ return CS_PROCESSOR_MATCH;
++
++ if (isGfx900SupersetProcessor(agent_processor))
++ return isGfx900EquivalentProcessor(co_processor) ? CS_PROCESSOR_COMPATIBLE : CS_INCOMPATIBLE;
++
++ if (isGfx1010SupersetProcessor(agent_processor))
++ return isGfx1010EquivalentProcessor(co_processor) ? CS_PROCESSOR_COMPATIBLE : CS_INCOMPATIBLE;
++
++ if (isGfx1030EquivalentProcessor(agent_processor))
++ return isGfx1030EquivalentProcessor(co_processor) ? CS_PROCESSOR_COMPATIBLE : CS_INCOMPATIBLE;
++
++ return CS_INCOMPATIBLE;
++}
++
++static int getCompatiblityScore(std::string co_triple_target_id,
++ std::string agent_triple_target_id) {
+ // Primitive Check
+- if (co_triple_target_id == agent_triple_target_id) return true;
++ if (co_triple_target_id == agent_triple_target_id) return CS_EXACT_MATCH;
+
+ // Parse code object triple target id
+ if (!consume(co_triple_target_id, std::string(AMDGCN_TARGET_TRIPLE) + '-')) {
+- return false;
++ return CS_INCOMPATIBLE;
+ }
+
+ std::string co_processor;
+ char co_sram_ecc, co_xnack;
+ if (!getTargetIDValue(co_triple_target_id, co_processor, co_sram_ecc, co_xnack)) {
+- return false;
++ return CS_INCOMPATIBLE;
+ }
+
+- if (!co_triple_target_id.empty()) return false;
++ if (!co_triple_target_id.empty()) return CS_INCOMPATIBLE;
+
+ // Parse agent isa triple target id
+ if (!consume(agent_triple_target_id, std::string(AMDGCN_TARGET_TRIPLE) + '-')) {
+- return false;
++ return CS_INCOMPATIBLE;
+ }
+
+ std::string agent_isa_processor;
+ char isa_sram_ecc, isa_xnack;
+ if (!getTargetIDValue(agent_triple_target_id, agent_isa_processor, isa_sram_ecc, isa_xnack)) {
+- return false;
++ return CS_INCOMPATIBLE;
+ }
+
+- if (!agent_triple_target_id.empty()) return false;
++ if (!agent_triple_target_id.empty()) return CS_INCOMPATIBLE;
+
+ // Check for compatibility
+- if (agent_isa_processor != co_processor) return false;
+- if (co_sram_ecc != ' ') {
+- if (co_sram_ecc != isa_sram_ecc) return false;
++ int processor_score = getProcessorCompatibilityScore(co_processor, agent_isa_processor);
++ if (processor_score == CS_INCOMPATIBLE) {
++ return CS_INCOMPATIBLE;
+ }
+- if (co_xnack != ' ') {
+- if (co_xnack != isa_xnack) return false;
++
++ int xnack_bonus;
++ if (co_xnack == ' ') {
++ xnack_bonus = 0;
++ } else if (co_xnack == isa_xnack) {
++ xnack_bonus = CS_XNACK_SPECIALIZED;
++ } else {
++ return CS_INCOMPATIBLE;
+ }
+
+- return true;
++ int sram_ecc_bonus;
++ if (co_sram_ecc == ' ') {
++ sram_ecc_bonus = 0;
++ } else if (co_sram_ecc == isa_sram_ecc) {
++ sram_ecc_bonus = CS_SRAM_ECC_SPECIALIZED;
++ } else {
++ return CS_INCOMPATIBLE;
++ }
++
++ return processor_score + xnack_bonus + sram_ecc_bonus;
+ }
+
+ // This will be moved to COMGR eventually
+@@ -483,6 +559,7 @@ hipError_t CodeObject::extractCodeObjectFromFatBinary(
+ for (size_t i = 0; i < agent_triple_target_ids.size(); i++) {
+ code_objs.push_back(std::make_pair(nullptr, 0));
+ }
++ std::vector<int> compatibility_score(agent_triple_target_ids.size());
+
+ const auto obheader = reinterpret_cast<const __ClangOffloadBundleHeader*>(data);
+ const auto* desc = &obheader->desc[0];
+@@ -495,17 +572,19 @@ hipError_t CodeObject::extractCodeObjectFromFatBinary(
+ reinterpret_cast<const void*>(reinterpret_cast<uintptr_t>(obheader) + desc->offset);
+ const size_t image_size = desc->size;
+
+- if (num_code_objs == 0) break;
+ std::string bundleEntryId{desc->bundleEntryId, desc->bundleEntryIdSize};
+
+ std::string co_triple_target_id;
+ if (!getTripleTargetID(bundleEntryId, image, co_triple_target_id)) continue;
+
+ for (size_t dev = 0; dev < agent_triple_target_ids.size(); ++dev) {
+- if (code_objs[dev].first) continue;
+- if (isCodeObjectCompatibleWithDevice(co_triple_target_id, agent_triple_target_ids[dev])) {
++ if (compatibility_score[dev] >= CS_PROCESSOR_MATCH) continue;
++ int score = getCompatiblityScore(co_triple_target_id, agent_triple_target_ids[dev]);
++ if (score > compatibility_score[dev]) {
++ compatibility_score[dev] = score;
++ if (!code_objs[dev].first)
++ --num_code_objs;
+ code_objs[dev] = std::make_pair(image, image_size);
+- --num_code_objs;
+ }
+ }
+ }
+--- a/rocclr/device/device.cpp
++++ b/rocclr/device/device.cpp
+@@ -232,10 +232,49 @@ std::string Isa::isaName() const {
+ return std::string(hsaIsaNamePrefix) + targetId();
+ }
+
++template <class T, std::size_t N>
++static bool Contains(const std::array<T, N>& arr, const T& value) {
++ return std::find(std::begin(arr), std::end(arr), value) != std::end(arr);
++}
++
++static bool IsVersionCompatible(const Isa &codeObjectIsa,
++ const Isa &agentIsa) {
++ if (codeObjectIsa.versionMajor() == agentIsa.versionMajor() &&
++ codeObjectIsa.versionMinor() == agentIsa.versionMinor()) {
++
++ if (codeObjectIsa.versionStepping() == agentIsa.versionStepping()) {
++ return true; // exact match
++ }
++
++ // The code object and the agent may sometimes be compatible if
++ // they differ only by stepping version.
++ if (codeObjectIsa.versionMajor() == 9 &&
++ codeObjectIsa.versionMinor() == 0) {
++ const std::array<uint32_t, 4> gfx900_equivalent = { 0, 2, 9, 12 };
++ const std::array<uint32_t, 5> gfx900_superset = { 0, 2, 6, 9, 12 };
++ if (Contains(gfx900_equivalent, codeObjectIsa.versionStepping()) &&
++ Contains(gfx900_superset, agentIsa.versionStepping())) {
++ return true; // gfx900 compatible object and agent
++ }
++ } else if (codeObjectIsa.versionMajor() == 10) {
++ if (codeObjectIsa.versionMinor() == 1) {
++ const std::array<uint32_t, 2> gfx1010_equivalent = { 0, 2 };
++ const std::array<uint32_t, 4> gfx1010_superset = { 0, 1, 2, 3 };
++ if (Contains(gfx1010_equivalent, codeObjectIsa.versionStepping()) &&
++ Contains(gfx1010_superset, agentIsa.versionStepping())) {
++ return true; // gfx1010 compatible object and agent
++ }
++ } else if (codeObjectIsa.versionMinor() == 3) {
++ return true; // gfx1030 compatible object and agent
++ }
++ }
++ }
++
++ return false;
++}
++
+ bool Isa::isCompatible(const Isa &codeObjectIsa, const Isa &agentIsa) {
+- if (codeObjectIsa.versionMajor() != agentIsa.versionMajor() ||
+- codeObjectIsa.versionMinor() != agentIsa.versionMinor() ||
+- codeObjectIsa.versionStepping() != agentIsa.versionStepping())
++ if (!IsVersionCompatible(codeObjectIsa, agentIsa))
+ return false;
+
+ assert(codeObjectIsa.isSrameccSupported() == agentIsa.isSrameccSupported() &&
diff --git a/dev-util/hip/files/hip-5.7.1-fix-mmap-oom-check.patch b/dev-util/hip/files/hip-5.7.1-fix-mmap-oom-check.patch
new file mode 100644
index 000000000000..dbafe4e11a74
--- /dev/null
+++ b/dev-util/hip/files/hip-5.7.1-fix-mmap-oom-check.patch
@@ -0,0 +1,41 @@
+Backport of SWDEV-417691 - Error handling for MemoryMap OS calls.
+The issue was fixed in rocclr 6.0.0.
+https://github.com/ROCm/clr/commit/7a10423a44b8b353f67539dc1ae14c0b99c209b8
+--- a/rocclr/os/os_posix.cpp
++++ b/rocclr/os/os_posix.cpp
+@@ -214,7 +214,7 @@ address Os::reserveMemory(address start, size_t size, size_t alignment, MemProt
+ MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS, 0, 0);
+
+ // check for out of memory
+- if (mem == NULL) return NULL;
++ if (mem == MAP_FAILED) return NULL;
+
+ address aligned = alignUp(mem, alignment);
+
+@@ -842,7 +842,7 @@ bool Os::MemoryMapFileDesc(FileDesc fdesc, size_t fsize, size_t foffset, const v
+ }
+
+ *mmap_ptr = mmap(NULL, fsize, PROT_READ, MAP_SHARED, fdesc, foffset);
+- return true;
++ return (*mmap_ptr == MAP_FAILED) ? false : true;
+ }
+
+ bool Os::MemoryUnmapFile(const void* mmap_ptr, size_t mmap_size) {
+@@ -874,7 +874,7 @@ bool Os::MemoryMapFile(const char* fname, const void** mmap_ptr, size_t* mmap_si
+
+ close(fd);
+
+- if (*mmap_ptr == nullptr) {
++ if (*mmap_ptr == MAP_FAILED) {
+ return false;
+ }
+
+@@ -899,7 +899,7 @@ bool Os::MemoryMapFileTruncated(const char* fname, const void** mmap_ptr, size_t
+
+ close(fd);
+
+- if (*mmap_ptr == nullptr) {
++ if (*mmap_ptr == MAP_FAILED) {
+ return false;
+ }
+ \ No newline at end of file
diff --git a/dev-util/hip/files/hip-5.7.1-fix-unaligned-access.patch b/dev-util/hip/files/hip-5.7.1-fix-unaligned-access.patch
new file mode 100644
index 000000000000..ae2092f6e1ac
--- /dev/null
+++ b/dev-util/hip/files/hip-5.7.1-fix-unaligned-access.patch
@@ -0,0 +1,67 @@
+Fix SIGSEGV when compiled with avx-512 instructions.
+
+Due to unaligned allocations, library crashes in
+nontemporalMemcpy in _mm512_stream_si512 (which requires
+64-aligned allocations, but used to copy default-aligned objects).
+
+Without this patch hipamd causes random crashes in hipMemcpy* callers
+(tensile, rocBLAS, miopen, rocThrust, etc.).
+
+Bug: https://bugs.gentoo.org/915969
+Bug report in upstream: https://github.com/ROCm-Developer-Tools/clr/issues/18
+--- a/rocclr/device/rocm/rocvirtual.cpp
++++ b/rocclr/device/rocm/rocvirtual.cpp
+@@ -2790,44 +2790,6 @@ bool VirtualGPU::createVirtualQueue(uint deviceQueueSize)
+ return true;
+ }
+
+-// ================================================================================================
+-__attribute__((optimize("unroll-all-loops"), always_inline))
+-static inline void nontemporalMemcpy(void* __restrict dst, const void* __restrict src,
+- uint16_t size) {
+- #if defined(__AVX512F__)
+- for (auto i = 0u; i != size / sizeof(__m512i); ++i) {
+- _mm512_stream_si512(reinterpret_cast<__m512i* __restrict&>(dst)++,
+- *reinterpret_cast<const __m512i* __restrict&>(src)++);
+- }
+- size = size % sizeof(__m512i);
+- #endif
+-
+- #if defined(__AVX__)
+- for (auto i = 0u; i != size / sizeof(__m256i); ++i) {
+- _mm256_stream_si256(reinterpret_cast<__m256i* __restrict&>(dst)++,
+- *reinterpret_cast<const __m256i* __restrict&>(src)++);
+- }
+- size = size % sizeof(__m256i);
+- #endif
+-
+- for (auto i = 0u; i != size / sizeof(__m128i); ++i) {
+- _mm_stream_si128(reinterpret_cast<__m128i* __restrict&>(dst)++,
+- *(reinterpret_cast<const __m128i* __restrict&>(src)++));
+- }
+- size = size % sizeof(__m128i);
+-
+- for (auto i = 0u; i != size / sizeof(long long); ++i) {
+- _mm_stream_si64(reinterpret_cast<long long* __restrict&>(dst)++,
+- *reinterpret_cast<const long long* __restrict&>(src)++);
+- }
+- size = size % sizeof(long long);
+-
+- for (auto i = 0u; i != size / sizeof(int); ++i) {
+- _mm_stream_si32(reinterpret_cast<int* __restrict&>(dst)++,
+- *reinterpret_cast<const int* __restrict&>(src)++);
+- }
+-}
+-
+ // ================================================================================================
+ bool VirtualGPU::submitKernelInternal(const amd::NDRangeContainer& sizes,
+ const amd::Kernel& kernel, const_address parameters, void* eventHandle,
+@@ -3096,7 +3058,7 @@ bool VirtualGPU::submitKernelInternal(const amd::NDRangeContainer& sizes,
+ argBuffer = reinterpret_cast<address>(allocKernArg(gpuKernel.KernargSegmentByteSize(),
+ gpuKernel.KernargSegmentAlignment()));
+ // Load all kernel arguments
+- nontemporalMemcpy(argBuffer, parameters,
++ memcpy(argBuffer, parameters,
+ std::min(gpuKernel.KernargSegmentByteSize(),
+ signature.paramsSize()));
+ }
diff --git a/dev-util/hip/files/hip-5.7.1-no_asan_doc.patch b/dev-util/hip/files/hip-5.7.1-no_asan_doc.patch
new file mode 100644
index 000000000000..40de416334be
--- /dev/null
+++ b/dev-util/hip/files/hip-5.7.1-no_asan_doc.patch
@@ -0,0 +1,17 @@
+Donot install -asan documents.
+
+Reference:
+https://github.com/RadeonOpenCompute/llvm-project/commit/e782e09f7b113a0f896c6cec7240d411aca1d73f
+https://github.com/RadeonOpenCompute/ROCm-CompilerSupport/issues/61
+
+--- a/hipamd/packaging/CMakeLists.txt 2023-11-18 23:25:45.000000000 +0800
++++ b/hipamd/packaging/CMakeLists.txt 2023-11-18 23:27:27.230354665 +0800
+@@ -36,8 +36,6 @@
+ ###Set License####
+ set(CPACK_RESOURCE_FILE_LICENSE ${hip_SOURCE_DIR}/LICENSE.txt)
+ install(FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT binary)
+-# install license file in share/doc/hip-asan folder
+-install(FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION ${CMAKE_INSTALL_DOCDIR}-asan COMPONENT asan)
+ set(CPACK_RPM_PACKAGE_LICENSE "MIT")
+ #Begin binary files install
+ if(HIP_PLATFORM STREQUAL "amd" )
diff --git a/dev-util/hip/files/hip-test-5.7.0-rocm_agent_enumerator-location.patch b/dev-util/hip/files/hip-test-5.7.0-rocm_agent_enumerator-location.patch
new file mode 100644
index 000000000000..1d967212ac9a
--- /dev/null
+++ b/dev-util/hip/files/hip-test-5.7.0-rocm_agent_enumerator-location.patch
@@ -0,0 +1,15 @@
+In Gentoo rocm_agent_enumerator is installed by rocminfo and is in PATH.
+
+--- catch/CMakeLists.txt~ 2023-11-18 13:56:08.000000000 +0800
++++ catch/CMakeLists.txt 2023-11-18 13:59:28.136170638 +0800
+@@ -182,9 +182,8 @@
+ # rocm_agent_enumerator
+ if(NOT DEFINED OFFLOAD_ARCH_STR
+ AND NOT DEFINED ENV{HCC_AMDGPU_TARGET}
+- AND EXISTS "${ROCM_PATH}/bin/rocm_agent_enumerator"
+ AND HIP_PLATFORM STREQUAL "amd" AND UNIX)
+- execute_process(COMMAND ${ROCM_PATH}/bin/rocm_agent_enumerator
++ execute_process(COMMAND rocm_agent_enumerator
+ OUTPUT_VARIABLE HIP_GPU_ARCH
+ RESULT_VARIABLE ROCM_AGENT_ENUM_RESULT)
+ # Trim out gfx000
diff --git a/dev-util/hip/files/hipvars-5.1.3.pm b/dev-util/hip/files/hipvars-5.1.3.pm
new file mode 100644
index 000000000000..7de38b7f3c78
--- /dev/null
+++ b/dev-util/hip/files/hipvars-5.1.3.pm
@@ -0,0 +1,21 @@
+#!/usr/bin/perl -w
+package hipvars;
+
+$HIP_BASE_VERSION_MAJOR = "@HIP_BASE_VERSION_MAJOR@";
+$HIP_BASE_VERSION_MINOR = "@HIP_BASE_VERSION_MINOR@";
+
+$isWindows = 0;
+$HIP_PATH='/usr';
+$ROCM_PATH='/usr';
+$CUDA_PATH='/opt/cuda';
+$HSA_PATH='/usr';
+$HIP_CLANG_PATH='@CLANG_PATH@';
+$HIP_CLANG_INCLUDE_PATH='@CLANG_INCLUDE_PATH@';
+$HIP_ROCCLR_HOME=$HIP_PATH;
+$HIP_PLATFORM='amd';
+$HIP_COMPILER = "clang";
+$HIP_RUNTIME = "rocclr";
+$HIP_VERSION_MAJOR = $HIP_BASE_VERSION_MAJOR;
+$HIP_VERSION_MINOR = $HIP_BASE_VERSION_MINOR;
+$HIP_VERSION_PATCH = "@HIP_VERSION_PATCH@";
+$HIP_VERSION="$HIP_VERSION_MAJOR.$HIP_VERSION_MINOR.$HIP_VERSION_PATCH";
diff --git a/dev-util/hip/files/hipvars-5.3.3.pm b/dev-util/hip/files/hipvars-5.3.3.pm
new file mode 100644
index 000000000000..fd1403661efb
--- /dev/null
+++ b/dev-util/hip/files/hipvars-5.3.3.pm
@@ -0,0 +1,20 @@
+#!/usr/bin/perl -w
+package hipvars;
+
+$HIP_BASE_VERSION_MAJOR = "@HIP_BASE_VERSION_MAJOR@";
+$HIP_BASE_VERSION_MINOR = "@HIP_BASE_VERSION_MINOR@";
+
+$isWindows = 0;
+$HIP_PATH='/usr';
+$ROCM_PATH='/usr';
+$CUDA_PATH='/opt/cuda';
+$HSA_PATH='/usr';
+$HIP_CLANG_PATH='@CLANG_PATH@';
+$HIP_ROCCLR_HOME=$HIP_PATH;
+$HIP_PLATFORM='amd';
+$HIP_COMPILER = "clang";
+$HIP_RUNTIME = "rocclr";
+$HIP_VERSION_MAJOR = $HIP_BASE_VERSION_MAJOR;
+$HIP_VERSION_MINOR = $HIP_BASE_VERSION_MINOR;
+$HIP_VERSION_PATCH = "@HIP_VERSION_PATCH@";
+$HIP_VERSION="$HIP_VERSION_MAJOR.$HIP_VERSION_MINOR.$HIP_VERSION_PATCH";
diff --git a/dev-util/hip/files/hipvars.pm b/dev-util/hip/files/hipvars.pm
new file mode 100644
index 000000000000..4c614080a119
--- /dev/null
+++ b/dev-util/hip/files/hipvars.pm
@@ -0,0 +1,20 @@
+#!/usr/bin/perl -w
+package hipvars;
+
+$HIP_BASE_VERSION_MAJOR = "@HIP_BASE_VERSION_MAJOR@";
+$HIP_BASE_VERSION_MINOR = "@HIP_BASE_VERSION_MINOR@";
+
+$isWindows = 0;
+$HIP_PATH='/usr/lib/hip';
+$ROCM_PATH='/usr';
+$CUDA_PATH='/opt/cuda';
+$HSA_PATH='/usr';
+$HIP_CLANG_PATH='/usr/lib/llvm/roc/bin';
+$HIP_ROCCLR_HOME=$HIP_PATH;
+$HIP_PLATFORM='amd';
+$HIP_COMPILER = "clang";
+$HIP_RUNTIME = "rocclr";
+$HIP_VERSION_MAJOR = $HIP_BASE_VERSION_MAJOR;
+$HIP_VERSION_MINOR = $HIP_BASE_VERSION_MINOR;
+$HIP_VERSION_PATCH = "@HIP_VERSION_PATCH@";
+$HIP_VERSION="$HIP_VERSION_MAJOR.$HIP_VERSION_MINOR.$HIP_VERSION_PATCH";
diff --git a/dev-util/hip/files/rocclr-5.3.3-fix-include.patch b/dev-util/hip/files/rocclr-5.3.3-fix-include.patch
new file mode 100644
index 000000000000..e014fe374bec
--- /dev/null
+++ b/dev-util/hip/files/rocclr-5.3.3-fix-include.patch
@@ -0,0 +1,218 @@
+For https://bugs.gentoo.org/893602
+==================================
+From 197ea6f76f34e0b3c8ab46d96c2fa5014e467e37 Mon Sep 17 00:00:00 2001
+From: Maneesh Gupta <maneesh.gupta@amd.com>
+Date: Fri, 5 Aug 2022 05:42:39 +0000
+Subject: [PATCH] SWDEV-350289 - Fix build warnings due to file re-org
+
+Change-Id: I0066fa163b9f25fdde4c5b3baed1ef0654390c06
+---
+ device/comgrctx.hpp | 2 +-
+ device/devkernel.hpp | 2 +-
+ device/devprogram.hpp | 2 +-
+ device/rocm/pro/prodevice.cpp | 2 +-
+ device/rocm/pro/prodriver.hpp | 2 +-
+ device/rocm/roccounters.hpp | 2 +-
+ device/rocm/rocdevice.hpp | 8 ++++----
+ device/rocm/rocglinterop.hpp | 2 +-
+ device/rocm/rockernel.cpp | 2 +-
+ device/rocm/rocprogram.cpp | 2 +-
+ device/rocm/rocsignal.hpp | 4 ++--
+ device/rocm/rocvirtual.cpp | 4 ++--
+ device/rocm/rocvirtual.hpp | 8 ++++----
+ 13 files changed, 21 insertions(+), 21 deletions(-)
+
+diff --git a/device/comgrctx.hpp b/device/comgrctx.hpp
+index d69506e2..31ee24e1 100644
+--- a/device/comgrctx.hpp
++++ b/device/comgrctx.hpp
+@@ -23,7 +23,7 @@
+ #include <mutex>
+ #if defined(USE_COMGR_LIBRARY)
+ #include "top.hpp"
+-#include "amd_comgr.h"
++#include "amd_comgr/amd_comgr.h"
+
+ namespace amd {
+ typedef void (*t_amd_comgr_get_version)(size_t *major, size_t *minor);
+diff --git a/device/devkernel.hpp b/device/devkernel.hpp
+index 19b3212d..b256abf3 100644
+--- a/device/devkernel.hpp
++++ b/device/devkernel.hpp
+@@ -105,7 +105,7 @@ struct RuntimeHandle {
+ uint32_t group_segment_size; //!< From GROUP_SEGMENT_FIXED_SIZE
+ };
+
+-#include "amd_comgr.h"
++#include "amd_comgr/amd_comgr.h"
+
+ // for Code Object V3
+ enum class ArgField : uint8_t {
+diff --git a/device/devprogram.hpp b/device/devprogram.hpp
+index 099d6a37..741d81b0 100644
+--- a/device/devprogram.hpp
++++ b/device/devprogram.hpp
+@@ -29,7 +29,7 @@
+ #include "devwavelimiter.hpp"
+
+ #if defined(USE_COMGR_LIBRARY)
+-#include "amd_comgr.h"
++#include "amd_comgr/amd_comgr.h"
+ #endif // defined(USE_COMGR_LIBRARY)
+
+ namespace amd {
+diff --git a/device/rocm/pro/prodevice.cpp b/device/rocm/pro/prodevice.cpp
+index a0e49461..1e366cd2 100644
+--- a/device/rocm/pro/prodevice.cpp
++++ b/device/rocm/pro/prodevice.cpp
+@@ -20,7 +20,7 @@
+
+ #ifndef WITHOUT_HSA_BACKEND
+
+-#include "hsa_ext_amd.h"
++#include "hsa/hsa_ext_amd.h"
+ #include "lnxheaders.h"
+ #include "prodevice.hpp"
+ #include "amdgpu_drm.h"
+diff --git a/device/rocm/pro/prodriver.hpp b/device/rocm/pro/prodriver.hpp
+index bc420697..819ade27 100644
+--- a/device/rocm/pro/prodriver.hpp
++++ b/device/rocm/pro/prodriver.hpp
+@@ -23,7 +23,7 @@
+ #ifndef WITHOUT_HSA_BACKEND
+
+ #include "top.hpp"
+-#include "hsa.h"
++#include "hsa/hsa.h"
+
+ /*! \addtogroup HSA
+ * @{
+diff --git a/device/rocm/roccounters.hpp b/device/rocm/roccounters.hpp
+index ffc9fad0..45ebbe66 100644
+--- a/device/rocm/roccounters.hpp
++++ b/device/rocm/roccounters.hpp
+@@ -24,7 +24,7 @@
+ #include "top.hpp"
+ #include "device/device.hpp"
+ #include "device/rocm/rocdevice.hpp"
+-#include "hsa_ven_amd_aqlprofile.h"
++#include "hsa/hsa_ven_amd_aqlprofile.h"
+
+ namespace roc {
+
+diff --git a/device/rocm/rocdevice.hpp b/device/rocm/rocdevice.hpp
+index d8cb4c6c..44339bb9 100644
+--- a/device/rocm/rocdevice.hpp
++++ b/device/rocm/rocdevice.hpp
+@@ -40,10 +40,10 @@
+ #include "device/rocm/rocprintf.hpp"
+ #include "device/rocm/rocglinterop.hpp"
+
+-#include "hsa.h"
+-#include "hsa_ext_image.h"
+-#include "hsa_ext_amd.h"
+-#include "hsa_ven_amd_loader.h"
++#include "hsa/hsa.h"
++#include "hsa/hsa_ext_image.h"
++#include "hsa/hsa_ext_amd.h"
++#include "hsa/hsa_ven_amd_loader.h"
+
+ #include <atomic>
+ #include <iostream>
+diff --git a/device/rocm/rocglinterop.hpp b/device/rocm/rocglinterop.hpp
+index a539cc6f..588d8a6f 100644
+--- a/device/rocm/rocglinterop.hpp
++++ b/device/rocm/rocglinterop.hpp
+@@ -34,7 +34,7 @@ typedef __GLXcontextRec* GLXContext;
+
+ #include "device/rocm/mesa_glinterop.h"
+ #include "device/rocm/rocregisters.hpp"
+-#include "hsa_ext_amd.h"
++#include "hsa/hsa_ext_amd.h"
+
+ namespace roc {
+
+diff --git a/device/rocm/rockernel.cpp b/device/rocm/rockernel.cpp
+index 76ab76ad..5624c877 100644
+--- a/device/rocm/rockernel.cpp
++++ b/device/rocm/rockernel.cpp
+@@ -19,7 +19,7 @@
+ THE SOFTWARE. */
+
+ #include "rockernel.hpp"
+-#include "amd_hsa_kernel_code.h"
++#include "hsa/amd_hsa_kernel_code.h"
+
+ #include <algorithm>
+
+diff --git a/device/rocm/rocprogram.cpp b/device/rocm/rocprogram.cpp
+index e4559645..4f77026d 100644
+--- a/device/rocm/rocprogram.cpp
++++ b/device/rocm/rocprogram.cpp
+@@ -25,7 +25,7 @@
+ #include "utils/options.hpp"
+ #include "rockernel.hpp"
+
+-#include "amd_hsa_kernel_code.h"
++#include "hsa/amd_hsa_kernel_code.h"
+
+ #include <string>
+ #include <vector>
+diff --git a/device/rocm/rocsignal.hpp b/device/rocm/rocsignal.hpp
+index 3e8c1e6e..fff310d5 100644
+--- a/device/rocm/rocsignal.hpp
++++ b/device/rocm/rocsignal.hpp
+@@ -22,7 +22,7 @@
+
+ #include "device/devsignal.hpp"
+
+-#include <hsa.h>
++#include "hsa/hsa.h"
+
+ namespace roc {
+
+@@ -44,4 +44,4 @@ public:
+ }
+ };
+
+-};
+\ No newline at end of file
++};
+diff --git a/device/rocm/rocvirtual.cpp b/device/rocm/rocvirtual.cpp
+index 63b96378..1b6287e9 100644
+--- a/device/rocm/rocvirtual.cpp
++++ b/device/rocm/rocvirtual.cpp
+@@ -33,8 +33,8 @@
+ #include "platform/sampler.hpp"
+ #include "utils/debug.hpp"
+ #include "os/os.hpp"
+-#include "amd_hsa_kernel_code.h"
+-#include "amd_hsa_queue.h"
++#include "hsa/amd_hsa_kernel_code.h"
++#include "hsa/amd_hsa_queue.h"
+
+ #include <fstream>
+ #include <limits>
+diff --git a/device/rocm/rocvirtual.hpp b/device/rocm/rocvirtual.hpp
+index 6c738776..1bb0868c 100644
+--- a/device/rocm/rocvirtual.hpp
++++ b/device/rocm/rocvirtual.hpp
+@@ -24,11 +24,11 @@
+ #include "rocdefs.hpp"
+ #include "rocdevice.hpp"
+ #include "utils/util.hpp"
+-#include "hsa.h"
+-#include "hsa_ext_image.h"
+-#include "hsa_ext_amd.h"
++#include "hsa/hsa.h"
++#include "hsa/hsa_ext_image.h"
++#include "hsa/hsa_ext_amd.h"
+ #include "rocprintf.hpp"
+-#include "hsa_ven_amd_aqlprofile.h"
++#include "hsa/hsa_ven_amd_aqlprofile.h"
+ #include "rocsched.hpp"
+
+ namespace roc {
+--
+2.39.1
+
diff --git a/dev-util/hip/files/rocclr-5.3.3-gcc13.patch b/dev-util/hip/files/rocclr-5.3.3-gcc13.patch
new file mode 100644
index 000000000000..09e8a95d585b
--- /dev/null
+++ b/dev-util/hip/files/rocclr-5.3.3-gcc13.patch
@@ -0,0 +1,27 @@
+For https://bugs.gentoo.org/895396
+==================================
+From ca70cd7c3d63b1036e604116f3b269ca123e7904 Mon Sep 17 00:00:00 2001
+From: Jeremy Newton <Jeremy.Newton@amd.com>
+Date: Wed, 8 Feb 2023 14:03:58 -0500
+Subject: [PATCH] SWDEV-1 - device: Add missing include
+
+Newer GCC's seem to require this.
+
+Change-Id: I85926d4fa552b772f2eb9f8ede7863a546c47f54
+Signed-off-by: Jeremy Newton <Jeremy.Newton@amd.com>
+---
+ device/devhcprintf.cpp | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/device/devhcprintf.cpp b/device/devhcprintf.cpp
+index b36f7758..a5aba4a4 100644
+--- a/device/devhcprintf.cpp
++++ b/device/devhcprintf.cpp
+@@ -23,6 +23,7 @@
+
+ #include <assert.h>
+ #include <cstdarg>
++#include <cstdint>
+ #include <cstdio>
+ #include <cstring>
+ #include <string>