From 4df820c0c3362a0e3133f92a2504c61a0a6d816b Mon Sep 17 00:00:00 2001 From: scchan Date: Wed, 27 Apr 2016 17:45:50 -0500 Subject: [PATCH 1/8] [deb] don't create symlinks for clang,clang++ --- packaging/debian/postinst.in | 4 +--- packaging/debian/prerm.in | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packaging/debian/postinst.in b/packaging/debian/postinst.in index 0ac5e0ad6ea..254d1393710 100755 --- a/packaging/debian/postinst.in +++ b/packaging/debian/postinst.in @@ -7,12 +7,10 @@ INSTALL_PATH=@INSTALL_PATH@ ROCM_PATH="/opt/rocm" -# NOTE: if you modify this table, also update the same table in postrm +# NOTE: if you modify this table, also update the same table in prerm SOFTLINKS=( # "bin" "clamp-config" - "bin" "clang" - "bin" "clang++" "bin" "extractkernel" "bin" "hcc" "bin" "hcc-config" diff --git a/packaging/debian/prerm.in b/packaging/debian/prerm.in index 9bf9c07dc59..eaa61616398 100755 --- a/packaging/debian/prerm.in +++ b/packaging/debian/prerm.in @@ -11,8 +11,6 @@ ROCM_PATH="/opt/rocm" SOFTLINKS=( # "bin" "clamp-config" - "bin" "clang" - "bin" "clang++" "bin" "extractkernel" "bin" "hcc" "bin" "hcc-config" From 7e499f8ed25db37e1fdbb83f1687a021e3915a56 Mon Sep 17 00:00:00 2001 From: scchan Date: Wed, 27 Apr 2016 17:46:40 -0500 Subject: [PATCH 2/8] [deb] update dependency, add section to control file Conflicts: CMakeLists.txt --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5cbaa73faa..8dce605d1b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -563,6 +563,8 @@ set(CPACK_PACKAGE_VERSION_PATCH ${KALMAR_VERSION_PATCH}) set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}) set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "HCC: a Heterogeneous C++ to OpenCL/HSA compiler") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Siu Chi Chan ") +set(CPACK_DEBIAN_PACKAGE_SECTION "devel") + set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${PROJECT_BINARY_DIR}/packaging/debian/postinst;${PROJECT_BINARY_DIR}/packaging/debian/prerm") From 60058c6a28b38f12ea7d4a9212aa55b7b3aea12b Mon Sep 17 00:00:00 2001 From: Yan-Ming Li Date: Fri, 29 Apr 2016 15:01:48 -0500 Subject: [PATCH 3/8] use FNV-1a for kernel indexing instead of md5 this will improve hcc runtime performance when multiple kernels are used in a program --- lib/hsa/mcwamp_hsa.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/hsa/mcwamp_hsa.cpp b/lib/hsa/mcwamp_hsa.cpp index 59641af265c..25daccf8dcd 100644 --- a/lib/hsa/mcwamp_hsa.cpp +++ b/lib/hsa/mcwamp_hsa.cpp @@ -72,6 +72,9 @@ #define ASYNCOPS_VECTOR_GC_SIZE (1024) +// whether to use MD5 as kernel indexing hash function +// default set as 0 (use faster FNV-1a hash instead) +#define USE_MD5_HASH (0) static const char* getHSAErrorString(hsa_status_t s) { @@ -1323,6 +1326,7 @@ class HSADevice final : public KalmarDevice // calculate MD5 checksum std::string MD5Sum(size_t size, void* source) { +#if USE_MD5_HASH unsigned char md5_hash[16]; memset(md5_hash, 0, sizeof(unsigned char) * 16); MD5_CTX md5ctx; @@ -1337,6 +1341,22 @@ class HSADevice final : public KalmarDevice } return checksum.str(); +#else + // FNV-1a hashing, 64-bit version + const uint64_t FNV_prime = 0x100000001b3; + const uint64_t FNV_basis = 0xcbf29ce484222325; + uint64_t hash = FNV_prime; + + const char *str = static_cast(source); + + const int N = 104; + size = size > N ? N : size; + for (auto i = 0; i < size; ++i) { + hash ^= *str++; + hash *= FNV_prime; + } + return std::to_string(hash); +#endif } void BuildProgram(void* size, void* source, bool needsCompilation = true) override { From ceaf9edb0891cccb03a1ddd48a6f8fe7afeca938 Mon Sep 17 00:00:00 2001 From: Yan-Ming Li Date: Fri, 29 Apr 2016 15:14:25 -0500 Subject: [PATCH 4/8] fix typo --- lib/hsa/mcwamp_hsa.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/hsa/mcwamp_hsa.cpp b/lib/hsa/mcwamp_hsa.cpp index 25daccf8dcd..cda9585b4fe 100644 --- a/lib/hsa/mcwamp_hsa.cpp +++ b/lib/hsa/mcwamp_hsa.cpp @@ -1345,10 +1345,11 @@ class HSADevice final : public KalmarDevice // FNV-1a hashing, 64-bit version const uint64_t FNV_prime = 0x100000001b3; const uint64_t FNV_basis = 0xcbf29ce484222325; - uint64_t hash = FNV_prime; + uint64_t hash = FNV_basis; const char *str = static_cast(source); + // 104 is the proper size from Jack's research const int N = 104; size = size > N ? N : size; for (auto i = 0; i < size; ++i) { From cb0f88312fe46609364f93051802074132e4ab56 Mon Sep 17 00:00:00 2001 From: Yan-Ming Li Date: Fri, 29 Apr 2016 15:32:19 -0500 Subject: [PATCH 5/8] change the magic number from 104 to 140 --- lib/hsa/mcwamp_hsa.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/hsa/mcwamp_hsa.cpp b/lib/hsa/mcwamp_hsa.cpp index cda9585b4fe..d79708f336e 100644 --- a/lib/hsa/mcwamp_hsa.cpp +++ b/lib/hsa/mcwamp_hsa.cpp @@ -1349,8 +1349,8 @@ class HSADevice final : public KalmarDevice const char *str = static_cast(source); - // 104 is the proper size from Jack's research - const int N = 104; + // 140 is the proper size from Jack's research + const int N = 140; size = size > N ? N : size; for (auto i = 0; i < size; ++i) { hash ^= *str++; From 82d307798ce136a0ad1a7502d19996002f051883 Mon Sep 17 00:00:00 2001 From: Yan-Ming Li Date: Fri, 29 Apr 2016 15:35:31 -0500 Subject: [PATCH 6/8] rename the kernel checksum function name for clarity --- lib/hsa/mcwamp_hsa.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/hsa/mcwamp_hsa.cpp b/lib/hsa/mcwamp_hsa.cpp index d79708f336e..9a3adb6a29d 100644 --- a/lib/hsa/mcwamp_hsa.cpp +++ b/lib/hsa/mcwamp_hsa.cpp @@ -1325,7 +1325,7 @@ class HSADevice final : public KalmarDevice } // calculate MD5 checksum - std::string MD5Sum(size_t size, void* source) { + std::string kernel_checksum(size_t size, void* source) { #if USE_MD5_HASH unsigned char md5_hash[16]; memset(md5_hash, 0, sizeof(unsigned char) * 16); @@ -1361,7 +1361,7 @@ class HSADevice final : public KalmarDevice } void BuildProgram(void* size, void* source, bool needsCompilation = true) override { - if (executables.find(MD5Sum((size_t)size, source)) == executables.end()) { + if (executables.find(kernel_checksum((size_t)size, source)) == executables.end()) { bool use_amdgpu = false; #ifdef HSA_USE_AMDGPU_BACKEND const char *km_use_amdgpu = getenv("KM_USE_AMDGPU"); @@ -1768,7 +1768,7 @@ class HSADevice final : public KalmarDevice void BuildOfflineFinalizedProgramImpl(void* kernelBuffer, int kernelSize) { hsa_status_t status; - std::string index = MD5Sum((size_t)kernelSize, kernelBuffer); + std::string index = kernel_checksum((size_t)kernelSize, kernelBuffer); // load HSA program if we haven't done so if (executables.find(index) == executables.end()) { @@ -1800,7 +1800,7 @@ class HSADevice final : public KalmarDevice HSAKernel* CreateOfflineFinalizedKernelImpl(void *kernelBuffer, int kernelSize, const char *entryName) { hsa_status_t status; - std::string index = MD5Sum((size_t)kernelSize, kernelBuffer); + std::string index = kernel_checksum((size_t)kernelSize, kernelBuffer); // load HSA program if we haven't done so if (executables.find(index) == executables.end()) { @@ -1826,7 +1826,7 @@ class HSADevice final : public KalmarDevice void BuildProgramImpl(const char* hsailBuffer, int hsailSize) { hsa_status_t status; - std::string index = MD5Sum((size_t)hsailSize, (void*)hsailBuffer); + std::string index = kernel_checksum((size_t)hsailSize, (void*)hsailBuffer); // finalize HSA program if we haven't done so if (executables.find(index) == executables.end()) { @@ -1893,7 +1893,7 @@ class HSADevice final : public KalmarDevice HSAKernel* CreateKernelImpl(const char *hsailBuffer, int hsailSize, const char *entryName) { hsa_status_t status; - std::string index = MD5Sum((size_t)hsailSize, (void*)hsailBuffer); + std::string index = kernel_checksum((size_t)hsailSize, (void*)hsailBuffer); // finalize HSA program if we haven't done so if (executables.find(index) == executables.end()) { From dcf39683d023b8b54644deb1201077d2d118a4a0 Mon Sep 17 00:00:00 2001 From: Yan-Ming Li Date: Fri, 29 Apr 2016 15:45:52 -0500 Subject: [PATCH 7/8] Revert "change the magic number from 104 to 140" This reverts commit cb0f88312fe46609364f93051802074132e4ab56. --- lib/hsa/mcwamp_hsa.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/hsa/mcwamp_hsa.cpp b/lib/hsa/mcwamp_hsa.cpp index 9a3adb6a29d..f8393e05cff 100644 --- a/lib/hsa/mcwamp_hsa.cpp +++ b/lib/hsa/mcwamp_hsa.cpp @@ -1349,8 +1349,8 @@ class HSADevice final : public KalmarDevice const char *str = static_cast(source); - // 140 is the proper size from Jack's research - const int N = 140; + // 104 is the proper size from Jack's research + const int N = 104; size = size > N ? N : size; for (auto i = 0; i < size; ++i) { hash ^= *str++; From 94071f316c67677e9b2a82b8e98903af63a01595 Mon Sep 17 00:00:00 2001 From: Yan-Ming Li Date: Fri, 29 Apr 2016 15:53:12 -0500 Subject: [PATCH 8/8] use a macro to hold the magic number 104 --- lib/hsa/mcwamp_hsa.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/hsa/mcwamp_hsa.cpp b/lib/hsa/mcwamp_hsa.cpp index f8393e05cff..69ca60d2db4 100644 --- a/lib/hsa/mcwamp_hsa.cpp +++ b/lib/hsa/mcwamp_hsa.cpp @@ -76,6 +76,11 @@ // default set as 0 (use faster FNV-1a hash instead) #define USE_MD5_HASH (0) +// cutoff size used in FNV-1a hash function +// default set as 104, which is the larger value between HSA BrigModuleHeader +// and AMD GCN ISA header (Elf64_Ehdr) from Jack's research +#define FNV1A_CUTOFF_SIZE (104) + static const char* getHSAErrorString(hsa_status_t s) { #define CASE_ERROR_STRING(X) case X: error_string = #X ;break; @@ -1349,9 +1354,7 @@ class HSADevice final : public KalmarDevice const char *str = static_cast(source); - // 104 is the proper size from Jack's research - const int N = 104; - size = size > N ? N : size; + size = size > FNV1A_CUTOFF_SIZE ? FNV1A_CUTOFF_SIZE : size; for (auto i = 0; i < size; ++i) { hash ^= *str++; hash *= FNV_prime;