From df1dc87d0fa879a3fbd97908082ea3469b1f0435 Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Tue, 1 Sep 2020 23:42:12 +0000 Subject: [PATCH 1/5] Fix dependency on rocm-dkms pkg SWDEV-249463- hipcc can't find the rocm_agent_enumerator Change-Id: I768a0d09753047508734d8360eb3d154edc0b0ef --- bin/hipcc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/hipcc b/bin/hipcc index 0e3027e03a..9b5756d160 100755 --- a/bin/hipcc +++ b/bin/hipcc @@ -73,11 +73,11 @@ $HIPCC_LINK_FLAGS_APPEND=$ENV{'HIPCC_LINK_FLAGS_APPEND'}; # derive HIP_PATH, as dirname $0 could be /opt/rocm/bin or /opt/rocm/hip/bin # depending on how it gets invoked. # ROCM_PATH which points to is determined based on whether -# we find .info/version in the parent of HIP_PATH or not. If it is found, +# we find bin/rocminfo in the parent of HIP_PATH or not. If it is found, # ROCM_PATH is defined relative to HIP_PATH else it is hardcoded to /opt/rocm. # $HIP_PATH=$ENV{'HIP_PATH'} // dirname(Cwd::abs_path("$0/../")); # use parent directory of hipcc -if (-e "$HIP_PATH/../.info/version") { +if (-e "$HIP_PATH/../bin/rocminfo") { $ROCM_PATH=$ENV{'ROCM_PATH'} // dirname("$HIP_PATH"); # use parent directory of HIP_PATH } else { $ROCM_PATH=$ENV{'ROCM_PATH'} // "/opt/rocm"; From 1f8543560f7c7ac7745232498329fef2fd11a663 Mon Sep 17 00:00:00 2001 From: kjayapra-amd Date: Thu, 13 Aug 2020 16:09:51 -0400 Subject: [PATCH 2/5] SWDEV-240800 - P2P device attributes support Change-Id: Ia32b87ffea17e0d98b69a07f2633ba14e7637b8a --- rocclr/hip_device_runtime.cpp | 26 ----------- rocclr/hip_peer.cpp | 86 +++++++++++++++++++++++++++++------ 2 files changed, 73 insertions(+), 39 deletions(-) diff --git a/rocclr/hip_device_runtime.cpp b/rocclr/hip_device_runtime.cpp index 470b088f02..350363b1b6 100755 --- a/rocclr/hip_device_runtime.cpp +++ b/rocclr/hip_device_runtime.cpp @@ -551,29 +551,3 @@ hipError_t hipSetValidDevices ( int* device_arr, int len ) { HIP_RETURN(hipErrorNotSupported); } - -hipError_t hipExtGetLinkTypeAndHopCount(int device1, int device2, uint32_t* linktype, uint32_t* hopcount) { - HIP_INIT_API(hipExtGetLinkTypeAndHopCount, device1, device2, linktype, hopcount); - - amd::Device* amd_dev_obj1 = nullptr; - amd::Device* amd_dev_obj2 = nullptr; - const int numDevices = static_cast(g_devices.size()); - - if ((device1 < 0) || (device1 >= numDevices) || (device2 < 0) || (device2 >= numDevices)) { - HIP_RETURN(hipErrorInvalidDevice); - } - - if ((linktype == nullptr) || (hopcount == nullptr)) { - HIP_RETURN(hipErrorInvalidValue); - } - - amd_dev_obj1 = g_devices[device1]->devices()[0]; - amd_dev_obj2 = g_devices[device2]->devices()[0]; - - if (!amd_dev_obj1->findLinkTypeAndHopCount(amd_dev_obj2, linktype, hopcount)) { - HIP_RETURN(hipErrorInvalidHandle); - } - - HIP_RETURN(hipSuccess); -} - diff --git a/rocclr/hip_peer.cpp b/rocclr/hip_peer.cpp index 24207b52c6..ded6843957 100755 --- a/rocclr/hip_peer.cpp +++ b/rocclr/hip_peer.cpp @@ -72,12 +72,48 @@ hipError_t canAccessPeer(int* canAccessPeer, int deviceId, int peerDeviceId){ return hipSuccess; } +hipError_t findLinkInfo(int device1, int device2, + std::vector* link_attrs) { + + amd::Device* amd_dev_obj1 = nullptr; + amd::Device* amd_dev_obj2 = nullptr; + const int numDevices = static_cast(g_devices.size()); + + if ((device1 < 0) || (device1 >= numDevices) || (device2 < 0) || (device2 >= numDevices)) { + return hipErrorInvalidDevice; + } + + amd_dev_obj1 = g_devices[device1]->devices()[0]; + amd_dev_obj2 = g_devices[device2]->devices()[0]; + + if (!amd_dev_obj1->findLinkInfo(*amd_dev_obj2, link_attrs)) { + return hipErrorInvalidHandle; + } + + return hipSuccess; +} + +hipError_t hipExtGetLinkTypeAndHopCount(int device1, int device2, + uint32_t* linktype, uint32_t* hopcount) { + HIP_INIT_API(hipExtGetLinkTypeAndHopCount, device1, device2, linktype, hopcount); + + // Fill out the list of LinkAttributes + std::vector link_attrs; + link_attrs.push_back(std::make_pair(amd::Device::LinkAttribute::kLinkLinkType, 0)); + link_attrs.push_back(std::make_pair(amd::Device::LinkAttribute::kLinkHopCount, 0)); + + HIP_RETURN_ONFAIL(findLinkInfo(device1, device2, &link_attrs)); + + *linktype = static_cast(link_attrs[0].second); + *hopcount = static_cast(link_attrs[1].second); + + HIP_RETURN(hipSuccess); +} + hipError_t hipDeviceGetP2PAttribute(int* value, hipDeviceP2PAttr attr, int srcDevice, int dstDevice) { HIP_INIT_API(hipDeviceGetP2PAttribute, value, attr, srcDevice, dstDevice); - hipError_t hip_error = hipSuccess; - if (value == nullptr) { HIP_RETURN(hipErrorInvalidValue); } @@ -87,26 +123,50 @@ hipError_t hipDeviceGetP2PAttribute(int* value, hipDeviceP2PAttr attr, HIP_RETURN(hipErrorInvalidDevice); } + std::vector link_attrs; + switch (attr) { - case hipDevP2PAttrPerformanceRank : - assert(0 && "Unimplemented"); + case hipDevP2PAttrPerformanceRank : { + link_attrs.push_back(std::make_pair(amd::Device::LinkAttribute::kLinkLinkType, 0)); break; - case hipDevP2PAttrAccessSupported : - hip_error = canAccessPeer(value, srcDevice, dstDevice); + } + case hipDevP2PAttrAccessSupported : { + HIP_RETURN_ONFAIL(canAccessPeer(value, srcDevice, dstDevice)); break; - case hipDevP2PAttrNativeAtomicSupported : - assert(0 && "Unimplemented"); + } + case hipDevP2PAttrNativeAtomicSupported : { + link_attrs.push_back(std::make_pair(amd::Device::LinkAttribute::kLinkLinkType, 0)); break; - case hipDevP2PAttrHipArrayAccessSupported : - assert(0 && "Unimplemented"); + } + case hipDevP2PAttrHipArrayAccessSupported : { + hipDeviceProp_t srcDeviceProp; + hipDeviceProp_t dstDeviceProp; + HIP_RETURN_ONFAIL(hipGetDeviceProperties(&srcDeviceProp, srcDevice)); + HIP_RETURN_ONFAIL(hipGetDeviceProperties(&dstDeviceProp, dstDevice)); + + // Linear layout access is supported if P2P is enabled + // Opaque Images are supported only on homogeneous systems + // Might have more conditions to check, in future. + if (srcDeviceProp.gcnArch == dstDeviceProp.gcnArch) { + HIP_RETURN_ONFAIL(canAccessPeer(value, srcDevice, dstDevice)); + } else { + value = 0; + } break; - default : + } + default : { DevLogPrintfError("Invalid attribute attr: %d ", attr); - hip_error = hipErrorInvalidValue; + HIP_RETURN(hipErrorInvalidValue); break; + } } - HIP_RETURN(hip_error); + if ((attr != hipDevP2PAttrAccessSupported) && (attr != hipDevP2PAttrHipArrayAccessSupported)) { + HIP_RETURN_ONFAIL(findLinkInfo(srcDevice, dstDevice, &link_attrs)); + *value = static_cast(link_attrs[0].second); + } + + HIP_RETURN(hipSuccess); } hipError_t hipDeviceCanAccessPeer(int* canAccess, int deviceId, int peerDeviceId) { From bf0d8f37e47aafcecf2be3fbe3bbeae05746f8bd Mon Sep 17 00:00:00 2001 From: Siu Chi Chan Date: Wed, 5 Aug 2020 19:43:47 -0400 Subject: [PATCH 3/5] fix no matching push_macro warmnings Change-Id: I352fe1170cfc9e8de5307536a21c86f0b483c68e --- include/hip/hcc_detail/math_functions.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/hip/hcc_detail/math_functions.h b/include/hip/hcc_detail/math_functions.h index 60dc644ecd..61b445ad5d 100644 --- a/include/hip/hcc_detail/math_functions.h +++ b/include/hip/hcc_detail/math_functions.h @@ -1533,13 +1533,14 @@ inline _Float16 pow(_Float16 base, int iexp) { return __ocml_pown_f16(base, iexp); } -#endif // !__CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__ - #pragma pop_macro("__DEF_FLOAT_FUN") #pragma pop_macro("__DEF_FLOAT_FUN2") #pragma pop_macro("__DEF_FLOAT_FUN2I") #pragma pop_macro("__HIP_OVERLOAD") #pragma pop_macro("__HIP_OVERLOAD2") + +#endif // !__CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__ + #pragma pop_macro("__DEVICE__") #pragma pop_macro("__RETURN_TYPE") From 9e2fa6e2158dd1e485d0938b5fdba6ed1924ba5c Mon Sep 17 00:00:00 2001 From: agodavar Date: Thu, 3 Sep 2020 04:59:10 -0400 Subject: [PATCH 4/5] SWDEV-249870 - Short-Term solution for Pre-Compiled Headers for Online Compilation Change-Id: Ibcb365ce2ff27c4c2379609964078da42e1226b1 --- CMakeLists.txt | 4 ++ bin/hip_embed_pch.sh | 58 ++++++++++++++++++++++++ bin/hip_gen_pch.sh | 36 +++++++++++++++ include/hip/hcc_detail/hip_runtime_api.h | 6 +++ rocclr/CMakeLists.txt | 20 ++++++-- rocclr/hip_global.cpp | 7 +++ rocclr/hip_hcc.map.in | 1 + 7 files changed, 127 insertions(+), 5 deletions(-) create mode 100755 bin/hip_embed_pch.sh create mode 100755 bin/hip_gen_pch.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 055543a245..c5a49feaa3 100755 --- a/CMakeLists.txt +++ b/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/bin/hip_embed_pch.sh b/bin/hip_embed_pch.sh new file mode 100755 index 0000000000..8fe3c20f98 --- /dev/null +++ b/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/bin/hip_gen_pch.sh b/bin/hip_gen_pch.sh new file mode 100755 index 0000000000..b212177119 --- /dev/null +++ b/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/rocclr/hip_global.cpp b/rocclr/hip_global.cpp index 1211d99556..1bd12a442f 100755 --- a/rocclr/hip_global.cpp +++ b/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/rocclr/hip_hcc.map.in b/rocclr/hip_hcc.map.in index 989cbca40b..370eda4fb6 100755 --- a/rocclr/hip_hcc.map.in +++ b/rocclr/hip_hcc.map.in @@ -274,6 +274,7 @@ global: hipMemcpyAtoH; hipMemcpyHtoA; hipMemcpyParam2DAsync; + __hipGetPCH; }; local: *; From 5c7b7d1dd2bdcb5d5624e21d6f7f4ed7b42ac6a5 Mon Sep 17 00:00:00 2001 From: Sarbojit Sarkar Date: Tue, 1 Sep 2020 05:49:23 -0400 Subject: [PATCH 5/5] Fix for hipPointerGetAttributes [github#2137] Change-Id: I5295575638ecc4d3b7129552a9c26c6f6a7195fc --- rocclr/hip_memory.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rocclr/hip_memory.cpp b/rocclr/hip_memory.cpp index da8bd5be78..b0e1d6abdd 100755 --- a/rocclr/hip_memory.cpp +++ b/rocclr/hip_memory.cpp @@ -2029,14 +2029,20 @@ hipError_t hipHostGetDevicePointer(void** devicePointer, void* hostPointer, unsi hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void* ptr) { HIP_INIT_API(hipPointerGetAttributes, attributes, ptr); + if (attributes == nullptr || ptr == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } size_t offset = 0; amd::Memory* memObj = getMemoryObject(ptr, offset); int device = 0; + memset(attributes, 0, sizeof(hipPointerAttribute_t)); if (memObj != nullptr) { attributes->memoryType = (CL_MEM_SVM_FINE_GRAIN_BUFFER & memObj->getMemFlags())? hipMemoryTypeHost : hipMemoryTypeDevice; - attributes->hostPointer = memObj->getSvmPtr(); - attributes->devicePointer = memObj->getSvmPtr(); + if (attributes->memoryType == hipMemoryTypeHost) { + attributes->hostPointer = static_cast(memObj->getSvmPtr()) + offset; + } + attributes->devicePointer = static_cast(memObj->getSvmPtr()) + offset; attributes->isManaged = 0; attributes->allocationFlags = memObj->getMemFlags() >> 16;