Skip to content

Commit

Permalink
BUILD: added support for amdclang-based build
Browse files Browse the repository at this point in the history
Signed-off-by: nileshnegi <Nilesh.Negi@amd.com>
  • Loading branch information
nileshnegi committed Jan 16, 2024
1 parent 2058f67 commit b2cb8f1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
60 changes: 49 additions & 11 deletions config/m4/rocm.m4
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ 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"
)

Expand Down Expand Up @@ -102,11 +102,36 @@ AS_IF([test "x$with_rocm" != "xno"],
LDFLAGS="$SAVE_LDFLAGS"
LIBS="$SAVE_LIBS"
#Check whether we run on ROCm 6.0 or higher
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <${with_rocm}/include/hip/hip_version.h>
]], [[
#if HIP_VERSION_MAJOR >= 6
return 0;
#else
intr make+compilation_fail()
#endif
]])],
[ROCM_VERSION_60_OR_GREATER=1],
[ROCM_VERSION_60_OR_GREATER=0])
#Check whether we run on ROCm 5.0 or higher
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <${with_rocm}/include/hip/hip_version.h>
]], [[
#if HIP_VERSION_MAJOR < 6 && HIP_VERSION_MAJOR >= 5
return 0;
#else
intr make+compilation_fail()
#endif
]])],
[ROCM_VERSION_50_OR_GREATER=1],
[ROCM_VERSION_50_OR_GREATER=0])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <${with_rocm}/include/rocm_version.h>
]], [[
#if ROCM_VERSION_MAJOR >= 5
#if ROCM_VERSION_MAJOR < 6 && ROCM_VERSION_MAJOR >= 5
return 0;
#else
intr make+compilation_fail()
Expand All @@ -117,13 +142,19 @@ intr make+compilation_fail()
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
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"
AC_MSG_CHECKING([if ROCm version is 5.0 or above])
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"
Expand All @@ -142,10 +173,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 if 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 if 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])
Expand Down
10 changes: 8 additions & 2 deletions cuda_lt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ 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}"
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

Expand Down

0 comments on commit b2cb8f1

Please sign in to comment.