From 5e74685556f0077bf48fe6bb94dcce91755ff86f Mon Sep 17 00:00:00 2001 From: nileshnegi Date: Wed, 17 Jan 2024 20:40:39 +0000 Subject: [PATCH] BUILD: added support for amdclang-based build Signed-off-by: nileshnegi --- config/m4/rocm.m4 | 69 ++++++++++++++++++++++++++++++----------------- cuda_lt.sh | 10 +++++-- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/config/m4/rocm.m4 b/config/m4/rocm.m4 index 356961939f..6575b108d4 100644 --- a/config/m4/rocm.m4 +++ b/config/m4/rocm.m4 @@ -39,11 +39,28 @@ AC_DEFUN([ROCM_BUILD_FLAGS], # Parse value of ARG into appropriate LIBS, LDFLAGS, and # CPPFLAGS variables. AC_DEFUN([HIP_BUILD_FLAGS], - $4="-D__HIP_PLATFORM_AMD__ -I$1/include/hip -I$1/include" - $3="-L$1/lib" + $4="-D__HIP_PLATFORM_AMD__ -I$1/include/hip -I$1/include -I$1/llvm/include" + $3="-L$1/lib -L$1/llvm/lib" $2="-lamdhip64" ) +# CHECK_ROCM_VERSION(HIP_VERSION_MAJOR, ROCM_VERSION_CONDITION) +# ---------------------------------------------------------- +# Checks ROCm version and marks condition as 1 (TRUE) or 0 (FALSE) +AC_DEFUN([CHECK_ROCM_VERSION], [ +AC_COMPILE_IFELSE( +[AC_LANG_PROGRAM([[#include <${with_rocm}/include/hip/hip_version.h> + ]], [[ +#if HIP_VERSION_MAJOR >= $1 +return 0; +#else +intr make+compilation_fail() +#endif + ]])], + [$2=1], + [$2=0]) +]) + # # Check for ROCm support # @@ -102,28 +119,25 @@ AS_IF([test "x$with_rocm" != "xno"], LDFLAGS="$SAVE_LDFLAGS" LIBS="$SAVE_LIBS" - #Check whether we run on ROCm 5.0 or higher - AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[#include <${with_rocm}/include/rocm_version.h> - ]], [[ -#if ROCM_VERSION_MAJOR >= 5 -return 0; -#else -intr make+compilation_fail() -#endif - ]])], - [ROCM_VERSION_50_OR_GREATER=1], - [ROCM_VERSION_50_OR_GREATER=0]) - - HIP_BUILD_FLAGS([$with_rocm], [HIP_LIBS], [HIP_LDFLAGS], [HIP_CPPFLAGS]) - AC_MSG_CHECKING([if ROCm version is 5.0 or above]) - if test "$ROCM_VERSION_50_OR_GREATER" = "1" ; then + + # Check whether we run on ROCm 6.0 or higher + CHECK_ROCM_VERSION(6, ROCM_VERSION_60_OR_GREATER) + AC_MSG_CHECKING([if ROCm version is 6.0 or above]) + if test "$ROCM_VERSION_60_OR_GREATER" = "1" ; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) - HIP_CPPFLAGS="${HIP_CPPFLAGS} -I${with_rocm}/hip/include" - HIP_LDFLAGS="${HIP_LDFLAGS} -L${with_rocm}/hip/lib" + # Check whether we run on ROCm 5.0-5.7 + CHECK_ROCM_VERSION(5, 6, ROCM_VERSION_50_OR_GREATER) + AC_MSG_CHECKING([if ROCm version is 5.0 - 5.7]) + if test "$ROCM_VERSION_50_OR_GREATER" = "1" ; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + HIP_CPPFLAGS="${HIP_CPPFLAGS} -I${with_rocm}/hip/include" + HIP_LDFLAGS="${HIP_LDFLAGS} -L${with_rocm}/hip/lib" + fi fi CPPFLAGS="$HIP_CPPFLAGS $CPPFLAGS" @@ -142,10 +156,17 @@ intr make+compilation_fail() LDFLAGS="$SAVE_LDFLAGS" LIBS="$SAVE_LIBS" - - AS_IF([test "x$hip_happy" = "xyes"], - [AC_PATH_PROG([HIPCC], [hipcc], [notfound], [$PATH:$with_rocm/bin])]) - AS_IF([test "$HIPCC" = "notfound"], [hip_happy="no"]) + if test "$ROCM_VERSION_60_OR_GREATER" = "1" ; then + AC_MSG_NOTICE([using amdclang as ROCm version is 6.0 or above]) + AS_IF([test "x$hip_happy" = "xyes"], + [AC_PATH_PROG([HIPCC], [amdclang], [notfound], [$PATH:$with_rocm/bin])]) + AS_IF([test "$HIPCC" = "notfound"], [hip_happy="no"]) + else + AC_MSG_NOTICE([using hipcc as ROCm version is 3.7.0 to ROCm 5.7.1]) + AS_IF([test "x$hip_happy" = "xyes"], + [AC_PATH_PROG([HIPCC], [hipcc], [notfound], [$PATH:$with_rocm/bin])]) + AS_IF([test "$HIPCC" = "notfound"], [hip_happy="no"]) + fi AS_IF([test "x$hip_happy" = "xyes"], [AC_DEFINE([HAVE_HIP], 1, [Enable HIP support]) diff --git a/cuda_lt.sh b/cuda_lt.sh index 68f9b5ff60..8ee28177c1 100755 --- a/cuda_lt.sh +++ b/cuda_lt.sh @@ -27,7 +27,9 @@ local_npic_filepath="${local_npic_dir}${o_filename}" mkdir -p $pic_dir tmpcmd="${@:3}" -if [[ "$tmpcmd" == *"hipcc"* ]]; then +if [[ "$tmpcmd" == *"amdclang"* ]]; then + cmd="${@:3:2} -x hip -target x86_64-unknown-linux-gnu --offload-arch=gfx908:xnack- --offload-arch=gfx90a:xnack- --offload-arch=gfx90a:xnack+ --offload-arch=gfx940 --offload-arch=gfx941 --offload-arch=gfx942 --offload-arch=gfx1030 --offload-arch=gfx1100 --offload-arch=gfx1101 --offload-arch=gfx1102 ${@:5} -fPIC -o ${pic_filepath}" +elif [[ "$tmpcmd" == *"hipcc"* ]]; then cmd="${@:3} -fPIC -o ${pic_filepath}" else cmd="${@:3} -Xcompiler -fPIC -o ${pic_filepath}" @@ -35,7 +37,11 @@ fi echo $cmd $cmd -cmd="${@:3} -o ${npic_filepath}" +if [[ "$tmpcmd" == *"amdclang"* ]]; then + cmd="${@:3:2} -x hip -target x86_64-unknown-linux-gnu --offload-arch=gfx908:xnack- --offload-arch=gfx90a:xnack- --offload-arch=gfx90a:xnack+ --offload-arch=gfx940 --offload-arch=gfx941 --offload-arch=gfx942 --offload-arch=gfx1030 --offload-arch=gfx1100 --offload-arch=gfx1101 --offload-arch=gfx1102 ${@:5} -o ${npic_filepath}" +else + cmd="${@:3} -o ${npic_filepath}" +fi echo $cmd $cmd