diff --git a/projects/clr/hipamd/CMakeLists.txt b/projects/clr/hipamd/CMakeLists.txt index 055543a245..c5a49feaa3 100755 --- a/projects/clr/hipamd/CMakeLists.txt +++ b/projects/clr/hipamd/CMakeLists.txt @@ -8,6 +8,10 @@ set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared library (.so) or static lib ( set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +if(NOT ${BUILD_SHARED_LIBS} AND NOT DEFINED ENABLE_HIP_PCH) + set(ENABLE_HIP_PCH ON CACHE BOOL "enable/disable pre-compiled hip headers") +endif() + ############################# # Options ############################# diff --git a/projects/clr/hipamd/bin/hip_embed_pch.sh b/projects/clr/hipamd/bin/hip_embed_pch.sh new file mode 100755 index 0000000000..8fe3c20f98 --- /dev/null +++ b/projects/clr/hipamd/bin/hip_embed_pch.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +#set -x + +ROCM_PATH=${ROCM_PATH:-/opt/rocm} +tmp=/tmp/hip_pch.$$ +mkdir -p $tmp + +cat >$tmp/hip_macros.h <$tmp/hip_pch.h <$tmp/hip_pch.mcin <$tmp/pch.cui + +cat $tmp/hip_macros.h >> $tmp/pch.cui + +$ROCM_PATH/llvm/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 + +$ROCM_PATH/llvm/bin/llvm-mc -o hip_pch.o $tmp/hip_pch.mcin --filetype=obj + +rm -rf $tmp diff --git a/projects/clr/hipamd/bin/hip_gen_pch.sh b/projects/clr/hipamd/bin/hip_gen_pch.sh new file mode 100755 index 0000000000..b212177119 --- /dev/null +++ b/projects/clr/hipamd/bin/hip_gen_pch.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +#set -x + +cat >/tmp/hip_macros.h </tmp/hip_pch.h </tmp/pch.cui + +cat /tmp/hip_macros.h >> /tmp/pch.cui + +/opt/rocm/llvm/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 - ) endif() - # Enable profiling API +# Short-Term solution for pre-compiled headers for online compilation +# Enable pre compiled header +if(${ENABLE_HIP_PCH}) + execute_process(COMMAND sh -c "${CMAKE_CURRENT_SOURCE_DIR}/../bin/hip_gen_pch.sh") + execute_process(COMMAND sh -c "${CMAKE_CURRENT_SOURCE_DIR}/../bin/hip_embed_pch.sh") + add_definitions(-DENABLE_HIP_PCH) +endif() + +# Enable profiling API if(USE_PROF_API EQUAL 1) find_path(PROF_API_HEADER_DIR prof_protocol.h HINTS @@ -205,17 +213,21 @@ target_link_libraries(host INTERFACE hip::amdhip64) add_library(device INTERFACE) target_link_libraries(device INTERFACE host) + +# Short-Term solution for pre-compiled headers for online compilation +if(${ENABLE_HIP_PCH}) + target_link_libraries(amdhip64 PRIVATE ${CMAKE_BINARY_DIR}/hip_pch.o) +endif() + # TODO: we may create host_static and device_static to let app # link amdhip64_static # FIXME: Linux convention is to create static library with same base # filename. - if(${BUILD_SHARED_LIBS}) target_link_libraries(amdhip64 PRIVATE amdrocclr_static Threads::Threads dl hsa-runtime64::hsa-runtime64) INSTALL(PROGRAMS $ DESTINATION lib COMPONENT MAIN) else() - target_link_libraries(amdhip64 PRIVATE Threads::Threads dl hsa-runtime64::hsa-runtime64 amd_comgr) # combine objects of vid and hip into amdhip64_static add_custom_target( @@ -228,9 +240,7 @@ else() DEPENDS amdhip64 amdrocclr_static # To make sure this is the last step COMMENT "Combining static libs into amdhip64_static" ) - INSTALL(PROGRAMS $ DESTINATION lib COMPONENT MAIN) - endif() INSTALL(TARGETS amdhip64 host device EXPORT hip-targets DESTINATION ${LIB_INSTALL_DIR}) diff --git a/projects/clr/hipamd/rocclr/hip_global.cpp b/projects/clr/hipamd/rocclr/hip_global.cpp index 1211d99556..1bd12a442f 100755 --- a/projects/clr/hipamd/rocclr/hip_global.cpp +++ b/projects/clr/hipamd/rocclr/hip_global.cpp @@ -5,6 +5,13 @@ #include "hip_code_object.hpp" #include "platform/program.hpp" +#ifdef ENABLE_HIP_PCH +void __hipGetPCH(const char** pch, unsigned int *size) { + *pch = __hip_pch; + *size = __hip_pch_size; +} +#endif + namespace hip { //Device Vars diff --git a/projects/clr/hipamd/rocclr/hip_hcc.map.in b/projects/clr/hipamd/rocclr/hip_hcc.map.in index 989cbca40b..370eda4fb6 100755 --- a/projects/clr/hipamd/rocclr/hip_hcc.map.in +++ b/projects/clr/hipamd/rocclr/hip_hcc.map.in @@ -274,6 +274,7 @@ global: hipMemcpyAtoH; hipMemcpyHtoA; hipMemcpyParam2DAsync; + __hipGetPCH; }; local: *;