diff options
| author | Khem Raj <raj.khem@gmail.com> | 2021-06-23 11:01:46 -0700 |
|---|---|---|
| committer | Khem Raj <raj.khem@gmail.com> | 2021-06-24 10:31:32 -0700 |
| commit | b9c9325d65fdcc6a1bfdb15b538c7454894ce15f (patch) | |
| tree | 10f331e5a6976c44d7ed9d09d52b804e7105a43c /recipes-devtools/clang | |
| parent | 9c84711bbf8ff21e4276fb59d0e858fc3983155e (diff) | |
| download | meta-clang-b9c9325d65fdcc6a1bfdb15b538c7454894ce15f.tar.gz | |
openmp: Fix build on non-x86 targets
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Diffstat (limited to 'recipes-devtools/clang')
| -rw-r--r-- | recipes-devtools/clang/clang/0035-openmp-Fix-build-on-non-x86-targets.patch | 121 | ||||
| -rw-r--r-- | recipes-devtools/clang/common.inc | 1 |
2 files changed, 122 insertions, 0 deletions
diff --git a/recipes-devtools/clang/clang/0035-openmp-Fix-build-on-non-x86-targets.patch b/recipes-devtools/clang/clang/0035-openmp-Fix-build-on-non-x86-targets.patch new file mode 100644 index 0000000..3ce1096 --- /dev/null +++ b/recipes-devtools/clang/clang/0035-openmp-Fix-build-on-non-x86-targets.patch | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | [OpenMP] Fix builds for non-x86 after distributed barrier patch | ||
| 2 | |||
| 3 | Upstream-Status: Submitted [https://reviews.llvm.org/D104788] | ||
| 4 | |||
| 5 | diff --git a/openmp/runtime/cmake/config-ix.cmake b/openmp/runtime/cmake/config-ix.cmake | ||
| 6 | --- a/openmp/runtime/cmake/config-ix.cmake | ||
| 7 | +++ b/openmp/runtime/cmake/config-ix.cmake | ||
| 8 | @@ -109,6 +109,23 @@ | ||
| 9 | set(CMAKE_REQUIRED_LIBRARIES) | ||
| 10 | endif() | ||
| 11 | |||
| 12 | +# Check for aligned memory allocator function | ||
| 13 | +check_include_file(xmmintrin.h LIBOMP_HAVE_XMMINTRIN_H) | ||
| 14 | +set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) | ||
| 15 | +if (LIBOMP_HAVE_XMMINTRIN_H) | ||
| 16 | + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -DLIBOMP_HAVE_XMMINTRIN_H") | ||
| 17 | +endif() | ||
| 18 | +set(source_code "// check for _mm_malloc | ||
| 19 | + #ifdef LIBOMP_HAVE_XMMINTRIN_H | ||
| 20 | + #include <xmmintrin.h> | ||
| 21 | + #endif | ||
| 22 | + int main() { void *ptr = _mm_malloc(sizeof(int) * 1000, 64); _mm_free(ptr); return 0; }") | ||
| 23 | +check_cxx_source_compiles("${source_code}" LIBOMP_HAVE__MM_MALLOC) | ||
| 24 | +set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) | ||
| 25 | +check_symbol_exists(aligned_alloc "stdlib.h" LIBOMP_HAVE_ALIGNED_ALLOC) | ||
| 26 | +check_symbol_exists(posix_memalign "stdlib.h" LIBOMP_HAVE_POSIX_MEMALIGN) | ||
| 27 | +check_symbol_exists(_aligned_malloc "malloc.h" LIBOMP_HAVE__ALIGNED_MALLOC) | ||
| 28 | + | ||
| 29 | # Check linker flags | ||
| 30 | if(WIN32) | ||
| 31 | libomp_check_linker_flag(/SAFESEH LIBOMP_HAVE_SAFESEH_FLAG) | ||
| 32 | diff --git a/openmp/runtime/src/kmp_barrier.h b/openmp/runtime/src/kmp_barrier.h | ||
| 33 | --- a/openmp/runtime/src/kmp_barrier.h | ||
| 34 | +++ b/openmp/runtime/src/kmp_barrier.h | ||
| 35 | @@ -15,6 +15,34 @@ | ||
| 36 | |||
| 37 | #include "kmp.h" | ||
| 38 | |||
| 39 | +#if KMP_HAVE_XMMINTRIN_H && KMP_HAVE__MM_MALLOC | ||
| 40 | +#include <xmmintrin.h> | ||
| 41 | +#define KMP_ALIGNED_ALLOCATE(size, alignment) _mm_malloc(size, alignment) | ||
| 42 | +#define KMP_ALIGNED_FREE(ptr) _mm_free(ptr) | ||
| 43 | +#elif KMP_HAVE_ALIGNED_ALLOC | ||
| 44 | +#define KMP_ALIGNED_ALLOCATE(size, alignment) aligned_alloc(alignment, size) | ||
| 45 | +#define KMP_ALIGNED_FREE(ptr) free(ptr) | ||
| 46 | +#elif KMP_HAVE_POSIX_MEMALIGN | ||
| 47 | +#include "kmp_i18n.h" | ||
| 48 | +static inline void *KMP_ALIGNED_ALLOCATE(size_t size, size_t alignment) { | ||
| 49 | + void *ptr; | ||
| 50 | + int n = posix_memalign(&ptr, alignment, size); | ||
| 51 | + if (n != 0) { | ||
| 52 | + __kmp_fatal(KMP_MSG(FunctionError, "posix_memalign()"), KMP_ERR(errno), | ||
| 53 | + __kmp_msg_null); | ||
| 54 | + } | ||
| 55 | + return ptr; | ||
| 56 | +} | ||
| 57 | +#define KMP_ALIGNED_FREE(ptr) free(ptr) | ||
| 58 | +#elif KMP_HAVE__ALIGNED_MALLOC | ||
| 59 | +#include <malloc.h> | ||
| 60 | +#define KMP_ALIGNED_ALLOCATE(size, alignment) _aligned_malloc(size, alignment) | ||
| 61 | +#define KMP_ALIGNED_FREE(ptr) _aligned_free(ptr) | ||
| 62 | +#else | ||
| 63 | +#define KMP_ALIGNED_ALLOCATE(size, alignment) KMP_INTERNAL_MALLOC(size) | ||
| 64 | +#define KMP_ALIGNED_FREE(ptr) KMP_INTERNAL_FREE(ptr) | ||
| 65 | +#endif | ||
| 66 | + | ||
| 67 | // Use four cache lines: MLC tends to prefetch the next or previous cache line | ||
| 68 | // creating a possible fake conflict between cores, so this is the only way to | ||
| 69 | // guarantee that no such prefetch can happen. | ||
| 70 | @@ -79,7 +107,7 @@ | ||
| 71 | |||
| 72 | // Used instead of constructor to create aligned data | ||
| 73 | static distributedBarrier *allocate(int nThreads) { | ||
| 74 | - distributedBarrier *d = (distributedBarrier *)_mm_malloc( | ||
| 75 | + distributedBarrier *d = (distributedBarrier *)KMP_ALIGNED_ALLOCATE( | ||
| 76 | sizeof(distributedBarrier), 4 * CACHE_LINE); | ||
| 77 | d->num_threads = 0; | ||
| 78 | d->max_threads = 0; | ||
| 79 | @@ -96,7 +124,7 @@ | ||
| 80 | return d; | ||
| 81 | } | ||
| 82 | |||
| 83 | - static void deallocate(distributedBarrier *db) { _mm_free(db); } | ||
| 84 | + static void deallocate(distributedBarrier *db) { KMP_ALIGNED_FREE(db); } | ||
| 85 | |||
| 86 | void update_num_threads(size_t nthr) { init(nthr); } | ||
| 87 | |||
| 88 | diff --git a/openmp/runtime/src/kmp_config.h.cmake b/openmp/runtime/src/kmp_config.h.cmake | ||
| 89 | --- a/openmp/runtime/src/kmp_config.h.cmake | ||
| 90 | +++ b/openmp/runtime/src/kmp_config.h.cmake | ||
| 91 | @@ -88,6 +88,16 @@ | ||
| 92 | #define KMP_HAVE_ATTRIBUTE_RTM LIBOMP_HAVE_ATTRIBUTE_RTM | ||
| 93 | #cmakedefine01 LIBOMP_ARCH_AARCH64_A64FX | ||
| 94 | #define KMP_ARCH_AARCH64_A64FX LIBOMP_ARCH_AARCH64_A64FX | ||
| 95 | +#cmakedefine01 LIBOMP_HAVE_XMMINTRIN_H | ||
| 96 | +#define KMP_HAVE_XMMINTRIN_H LIBOMP_HAVE_XMMINTRIN_H | ||
| 97 | +#cmakedefine01 LIBOMP_HAVE__MM_MALLOC | ||
| 98 | +#define KMP_HAVE__MM_MALLOC LIBOMP_HAVE__MM_MALLOC | ||
| 99 | +#cmakedefine01 LIBOMP_HAVE_ALIGNED_ALLOC | ||
| 100 | +#define KMP_HAVE_ALIGNED_ALLOC LIBOMP_HAVE_ALIGNED_ALLOC | ||
| 101 | +#cmakedefine01 LIBOMP_HAVE_POSIX_MEMALIGN | ||
| 102 | +#define KMP_HAVE_POSIX_MEMALIGN LIBOMP_HAVE_POSIX_MEMALIGN | ||
| 103 | +#cmakedefine01 LIBOMP_HAVE__ALIGNED_MALLOC | ||
| 104 | +#define KMP_HAVE__ALIGNED_MALLOC LIBOMP_HAVE__ALIGNED_MALLOC | ||
| 105 | |||
| 106 | // Configured cache line based on architecture | ||
| 107 | #if KMP_ARCH_PPC64 | ||
| 108 | diff --git a/openmp/runtime/src/kmp_os.h b/openmp/runtime/src/kmp_os.h | ||
| 109 | --- a/openmp/runtime/src/kmp_os.h | ||
| 110 | +++ b/openmp/runtime/src/kmp_os.h | ||
| 111 | @@ -1038,6 +1038,9 @@ | ||
| 112 | KMP_MFENCE_(); \ | ||
| 113 | } | ||
| 114 | #define KMP_SFENCE() KMP_SFENCE_() | ||
| 115 | +#else | ||
| 116 | +#define KMP_MFENCE() KMP_MB() | ||
| 117 | +#define KMP_SFENCE() KMP_MB() | ||
| 118 | #endif | ||
| 119 | |||
| 120 | #ifndef KMP_IMB | ||
| 121 | |||
diff --git a/recipes-devtools/clang/common.inc b/recipes-devtools/clang/common.inc index b625221..2a23ba3 100644 --- a/recipes-devtools/clang/common.inc +++ b/recipes-devtools/clang/common.inc | |||
| @@ -44,6 +44,7 @@ SRC_URI = "\ | |||
| 44 | file://0032-libunwind-Added-unw_backtrace-method.patch \ | 44 | file://0032-libunwind-Added-unw_backtrace-method.patch \ |
| 45 | file://0033-compiler-rt-Use-uintptr_t-instead-of-_Unwind_Word.patch \ | 45 | file://0033-compiler-rt-Use-uintptr_t-instead-of-_Unwind_Word.patch \ |
| 46 | file://0034-compiler-rt-Do-not-force-thumb-mode-directive.patch \ | 46 | file://0034-compiler-rt-Do-not-force-thumb-mode-directive.patch \ |
| 47 | file://0035-openmp-Fix-build-on-non-x86-targets.patch \ | ||
| 47 | " | 48 | " |
| 48 | # Fallback to no-PIE if not set | 49 | # Fallback to no-PIE if not set |
| 49 | GCCPIE ??= "" | 50 | GCCPIE ??= "" |
