From 91950fbf62f75673e890b85a303b940e3801c632 Mon Sep 17 00:00:00 2001 From: "Yaxun (Sam) Liu" Date: Tue, 17 Nov 2020 16:38:15 -0500 Subject: [PATCH] Fix embedding PCH Change-Id: Ibaf043c9e331f15965185cd4195da98d9441cba3 [ROCm/hip commit: b7f66b634acd27762fc6935ec41f156888fb6f06] --- projects/hip/bin/hip_embed_pch.sh | 10 ++++++---- projects/hip/rocclr/CMakeLists.txt | 11 +++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/projects/hip/bin/hip_embed_pch.sh b/projects/hip/bin/hip_embed_pch.sh index 1843c8d5c4..79f07416e8 100755 --- a/projects/hip/bin/hip_embed_pch.sh +++ b/projects/hip/bin/hip_embed_pch.sh @@ -49,12 +49,14 @@ __hip_pch_size: .long __hip_pch_size - __hip_pch EOF -$LLVM_DIR/bin/clang -O3 -std=c++17 -nogpulib -isystem $HIP_INC_DIR -isystem $HIP_BUILD_INC_DIR -isystem $HSA_DIR/include --cuda-device-only -x hip $tmp/hip_pch.h -E >$tmp/pch.cui +set -x -cat $tmp/hip_macros.h >> $tmp/pch.cui +$LLVM_DIR/bin/clang -O3 --rocm-path=$HIP_INC_DIR/.. -std=c++17 -nogpulib -isystem $HIP_INC_DIR -isystem $HIP_BUILD_INC_DIR -isystem $HSA_DIR/include --cuda-device-only -x hip $tmp/hip_pch.h -E >$tmp/pch.cui && -$LLVM_DIR/bin/clang -cc1 -O3 -emit-pch -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -std=c++17 -fgnuc-version=4.2.1 -o $tmp/hip.pch -x hip-cpp-output - <$tmp/pch.cui +cat $tmp/hip_macros.h >> $tmp/pch.cui && -$LLVM_DIR/bin/llvm-mc -o hip_pch.o $tmp/hip_pch.mcin --filetype=obj +$LLVM_DIR/bin/clang -cc1 -O3 -emit-pch -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -std=c++17 -fgnuc-version=4.2.1 -o $tmp/hip.pch -x hip-cpp-output - <$tmp/pch.cui && + +$LLVM_DIR/bin/llvm-mc -o hip_pch.o $tmp/hip_pch.mcin --filetype=obj && rm -rf $tmp diff --git a/projects/hip/rocclr/CMakeLists.txt b/projects/hip/rocclr/CMakeLists.txt index 942a1cd6f9..087d644476 100755 --- a/projects/hip/rocclr/CMakeLists.txt +++ b/projects/hip/rocclr/CMakeLists.txt @@ -36,6 +36,10 @@ endif() set(USE_PROF_API "1") +# Need to add /opt/rocm/llvm to package search path since ROCclr will +# find package amd_comgr and amd_comgr will find package llvm/clang. +# Without this, the system llvm/clang at /usr/local may be found. +list(APPEND CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/opt/rocm/llvm") find_package(ROCclr REQUIRED CONFIG) ############################# @@ -69,7 +73,7 @@ endif() #Custom install path can be provided at compile time as cmake parameter(-DCMAKE_PREFIX_PATH="") #/opt/rocm:default:For amd_comgr,hsa-runtime64 #/opt/rocm/llvm/:default:For llvm/clang pulled in as dependency from hsa/comgr -list( APPEND CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/opt/rocm" "/opt/rocm/llvm") +list( APPEND CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/opt/rocm") list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ) set(CMAKE_MODULE_PATH${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") @@ -139,7 +143,10 @@ endif() # Short-Term solution for pre-compiled headers for online compilation # Enable pre compiled header if(__HIP_ENABLE_PCH) - execute_process(COMMAND sh -c "${CMAKE_CURRENT_SOURCE_DIR}/../bin/hip_embed_pch.sh ${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/include ${LLVM_DIR} ${HSA_PATH}") + execute_process(COMMAND sh -c "${CMAKE_CURRENT_SOURCE_DIR}/../bin/hip_embed_pch.sh ${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/include ${LLVM_DIR} ${HSA_PATH}" COMMAND_ECHO STDERR RESULT_VARIABLE EMBED_PCH_RC) + if (EMBED_PCH_RC AND NOT EMBED_PCH_RC EQUAL 0) + message(FATAL_ERROR "Failed to embed PCH") + endif() add_definitions(-D__HIP_ENABLE_PCH) endif()