From 684c56c8adce8552fe7c0f754e2752ad0b1c5002 Mon Sep 17 00:00:00 2001 From: Lauren Wrubleski Date: Wed, 20 Mar 2024 09:29:47 -0600 Subject: [PATCH] Switch from using hipcc to using Clang compiler (#514) * Change default from hipcc to amdclang * use clang not amdclang * remove compiler from install script * remove redundant toolchain argument * Switch back to amdclang * Update to correct flag behaviour * Update CI script --- .jenkins/common.groovy | 3 +-- install | 13 ++++------- toolchain-linux.cmake | 53 +++++++++++++++--------------------------- 3 files changed, 25 insertions(+), 44 deletions(-) diff --git a/.jenkins/common.groovy b/.jenkins/common.groovy index 723c73c15..0db07124c 100644 --- a/.jenkins/common.groovy +++ b/.jenkins/common.groovy @@ -16,7 +16,7 @@ def runCompileCommand(platform, project, jobName, boolean debug=false) cd ${project.paths.project_build_prefix} mkdir -p build/${buildTypeDir} && cd build/${buildTypeDir} ${auxiliary.gfxTargetParser()} - ${cmake} -DCMAKE_CXX_COMPILER=/opt/rocm/bin/hipcc ${buildTypeArg} ${amdgpuTargets} -DBUILD_TEST=ON -DBUILD_BENCHMARK=ON ../.. + ${cmake} --toolchain=toolchain-linux.cmake ${buildTypeArg} ${amdgpuTargets} -DBUILD_TEST=ON -DBUILD_BENCHMARK=ON ../.. make -j\$(nproc) """ @@ -74,4 +74,3 @@ def runPackageCommand(platform, project) } return this - diff --git a/install b/install index a3019c76d..2b2bb63f4 100755 --- a/install +++ b/install @@ -147,10 +147,8 @@ fi # Configure rocPRIM, setup options for your system. # See README.md under "Build and Install" for options and defaults. -compiler="hipcc" - cmake_executable="cmake" -cmake_common_options="" +cmake_common_options="--toolchain=toolchain-linux.cmake" benchmark="OFF" if [[ "${build_benchmark}" == true ]]; then @@ -188,7 +186,7 @@ if [[ "${build_codecoverage}" == true ]]; then fi if [[ "${build_relocatable}" == true ]]; then - CXX=${rocm_path}/bin/${compiler} ${cmake_executable} ${cmake_common_options} \ + ${cmake_executable} ${cmake_common_options} \ -DCMAKE_INSTALL_PREFIX=${rocm_path} -DBUILD_BENCHMARK=${benchmark} \ -DCMAKE_PREFIX_PATH="${rocm_path} ${rocm_path}/hip" \ -DBUILD_BENCHMARK=${benchmark} -DBUILD_TEST=${clients} \ @@ -196,10 +194,9 @@ if [[ "${build_relocatable}" == true ]]; then "${static_libs}" \ ../../. # or cmake-gui ../. else - CXX=${rocm_path}/bin/${compiler} ${cmake_executable} ${cmake_common_options} -DBUILD_BENCHMARK=${benchmark} \ - -DBUILD_TEST=${clients} -DCMAKE_BUILD_TYPE=${build_type} -DBUILD_CODE_COVERAGE=${codecoverage} \ - "${static_libs}" \ - ../../. # or cmake-gui ../. + ${cmake_executable} ${cmake_common_options} -DBUILD_BENCHMARK=${benchmark} \ + -DBUILD_TEST=${clients} -DCMAKE_BUILD_TYPE=${build_type} -DBUILD_CODE_COVERAGE=${codecoverage} ../../. # or cmake-gui ../. + fi # Build diff --git a/toolchain-linux.cmake b/toolchain-linux.cmake index 76f78a81b..6a8b6d082 100644 --- a/toolchain-linux.cmake +++ b/toolchain-linux.cmake @@ -1,42 +1,27 @@ -#set(CMAKE_MAKE_PROGRAM "nmake.exe") -#set(CMAKE_GENERATOR "Ninja") -# Ninja doesn't support platform -#set(CMAKE_GENERATOR_PLATFORM x64) if (DEFINED ENV{ROCM_PATH}) set(rocm_bin "$ENV{ROCM_PATH}/bin") else() + set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to the ROCm installation.") set(rocm_bin "/opt/rocm/bin") endif() +if (NOT DEFINED ENV{CXX}) + set(CMAKE_CXX_COMPILER "${rocm_bin}/amdclang++" CACHE PATH "Path to the C++ compiler") + set(CMAKE_CXX_FLAGS_INIT "-mllvm -amdgpu-early-inline-all=true -mllvm -amdgpu-function-calls=false") + if (DEFINED ENV{HIPCC_COMPILE_FLAGS_APPEND}) + set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} $ENV{HIPCC_COMPILE_FLAGS_APPEND}") + endif() +else() + set(CMAKE_CXX_COMPILER "$ENV{CXX}" CACHE PATH "Path to the C++ compiler") +endif() -# set(CMAKE_CXX_COMPILER "hipcc") -# set(CMAKE_C_COMPILER "hipcc") -set(CMAKE_CXX_COMPILER "${rocm_bin}/hipcc") -set(CMAKE_C_COMPILER "${rocm_bin}/hipcc") - -#set(CMAKE_CXX_LINKER "hipcc" ) - -# TODO remove, just to speed up slow cmake -# set(CMAKE_C_COMPILER_WORKS 1) -# set(CMAKE_CXX_COMPILER_WORKS 1) -# - -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -IC:/hip/include -IC:/hip/lib/clang/12.0.0 -DWIN32 -D_CRT_SECURE_NO_WARNINGS") - -# flags for clang direct use -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fms-extensions -fms-compatibility") -# -Wno-ignored-attributes to avoid warning: __declspec attribute 'dllexport' is not supported [-Wignored-attributes] which is used by msvc compiler -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fms-extensions -fms-compatibility -Wno-ignored-attributes") - -# flags for clang direct use with hip -# -x hip causes linker error -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x hip -IC:/hip/include/hip -D__HIP_PLATFORM_AMD__ -D__HIP_ROCclr__") -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -IC:/hip/include/hip -D__HIP_PLATFORM_AMD__ -D__HIP_ROCclr__") - - -# set(GTEST_DIR "C:/rocm/Utils/GTestMSVC") -# set(GTEST_INCLUDE_DIR "${GTEST_DIR}/include") -# set(GTEST_LIBRARY "${GTEST_DIR}/lib/Release/gtest.lib") -# set(GTEST_MAIN_LIBRARY "${GTEST_DIR}/lib/Release/gtest_main.lib") -# set(GTEST_LIBRARIES "${GTEST_DIR}/lib/Release/gtest.lib;${GTEST_DIR}/lib/Release/gtest_main.lib") +if (NOT DEFINED ENV{CC}) + set(CMAKE_C_COMPILER "${rocm_bin}/amdclang" CACHE PATH "Path to the C compiler") + set(CMAKE_C_FLAGS_INIT "-mllvm -amdgpu-early-inline-all=true -mllvm -amdgpu-function-calls=false") + if (DEFINED ENV{HIPCC_COMPILE_FLAGS_APPEND}) + set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} $ENV{HIPCC_COMPILE_FLAGS_APPEND}") + endif() +else() + set(CMAKE_C_COMPILER "$ENV{CC}" CACHE PATH "Path to the C compiler") +endif()