From 8316b2342d3ecc4e20bb9adc62cade7e95e00fb8 Mon Sep 17 00:00:00 2001 From: anindex Date: Wed, 4 Dec 2019 11:12:42 +0100 Subject: [PATCH 01/11] Fix HOST_NAME_MAX for macOS --- dart-if/include/dash/dart/if/dart_types.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dart-if/include/dash/dart/if/dart_types.h b/dart-if/include/dash/dart/if/dart_types.h index c391e198b..0887edae1 100644 --- a/dart-if/include/dash/dart/if/dart_types.h +++ b/dart-if/include/dash/dart/if/dart_types.h @@ -328,7 +328,13 @@ typedef enum dart_locality_scope_t; /** Maximum size of a host name string in \ref dart_hwinfo_t */ -#define DART_LOCALITY_HOST_MAX_SIZE (HOST_NAME_MAX) +#if defined(HOST_NAME_MAX) + #define DART_LOCALITY_HOST_MAX_SIZE (HOST_NAME_MAX) +#elif defined(_POSIX_HOST_NAME_MAX) + #define DART_LOCALITY_HOST_MAX_SIZE (_POSIX_HOST_NAME_MAX) +#else + #define DART_LOCALITY_HOST_MAX_SIZE ((int)(256)) +#endif /** Maximum size of a domain tag string in \ref dart_hwinfo_t */ #define DART_LOCALITY_DOMAIN_TAG_MAX_SIZE ((int)(32)) /** Maximum number of domain scopes in \ref dart_hwinfo_t */ From d05d01dfc283609badb1c04868be7c64829c301c Mon Sep 17 00:00:00 2001 From: anindex Date: Wed, 4 Dec 2019 11:16:50 +0100 Subject: [PATCH 02/11] malloc porting for macOS --- dart-impl/mpi/src/dart_synchronization.c | 6 +++++- dash/examples/bench.07.local-copy/main.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dart-impl/mpi/src/dart_synchronization.c b/dart-impl/mpi/src/dart_synchronization.c index 5da5a9139..6376b09c3 100644 --- a/dart-impl/mpi/src/dart_synchronization.c +++ b/dart-impl/mpi/src/dart_synchronization.c @@ -23,7 +23,11 @@ #include #include #include -#include +#ifdef __APPLE__ + #include +#else + #include +#endif struct dart_lock_struct diff --git a/dash/examples/bench.07.local-copy/main.cpp b/dash/examples/bench.07.local-copy/main.cpp index d4e083d5b..bed49fbe6 100644 --- a/dash/examples/bench.07.local-copy/main.cpp +++ b/dash/examples/bench.07.local-copy/main.cpp @@ -11,7 +11,11 @@ #include #include -#include +#ifdef __APPLE__ + #include +#else + #include +#endif #ifdef DASH_ENABLE_IPM #include From 7e386cfd7f7622cad594cfa61efbd6109c5eaeab Mon Sep 17 00:00:00 2001 From: anindex Date: Wed, 4 Dec 2019 11:28:06 +0100 Subject: [PATCH 03/11] Fix rt linker macOS --- dart-impl/base/CMakeLists.txt | 4 +++- dart-impl/mpi/CMakeLists.txt | 4 +++- dash/CMakeLists.txt | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dart-impl/base/CMakeLists.txt b/dart-impl/base/CMakeLists.txt index 36ca80de4..68e802034 100644 --- a/dart-impl/base/CMakeLists.txt +++ b/dart-impl/base/CMakeLists.txt @@ -81,7 +81,9 @@ if (NOT ENABLE_SHARED_WINDOWS) "${ADDITIONAL_COMPILE_FLAGS} -DDART_MPI_DISABLE_SHARED_WINDOWS") endif() -set (ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} rt) +if(NOT APPLE) + set (ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} rt) +endif() set(DASH_DART_BASE_INCLUDE_DIRS diff --git a/dart-impl/mpi/CMakeLists.txt b/dart-impl/mpi/CMakeLists.txt index 767807d21..5977b1428 100644 --- a/dart-impl/mpi/CMakeLists.txt +++ b/dart-impl/mpi/CMakeLists.txt @@ -153,7 +153,9 @@ if(MPI_COMPILE_FLAGS) ${ADDITIONAL_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) endif() -set (ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} rt) +if(NOT APPLE) + set (ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} rt) +endif() message (STATUS "DART additional compile flags:") set(ADDITIONAL_COMPILE_FLAGS_STR "") diff --git a/dash/CMakeLists.txt b/dash/CMakeLists.txt index e86df9908..248dd2f42 100644 --- a/dash/CMakeLists.txt +++ b/dash/CMakeLists.txt @@ -102,7 +102,7 @@ if (PAPI_FOUND AND ENABLE_PAPI) ${PAPI_INCLUDE_DIRS}) set (ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} ${PAPI_LIBRARIES}) -else() +elseif(NOT APPLE) set (ADDITIONAL_LIBRARIES ${ADDITIONAL_LIBRARIES} rt) endif() From a5a496fc4e5ddd26f7cc92a52a017f5a7048f3dd Mon Sep 17 00:00:00 2001 From: anindex Date: Wed, 4 Dec 2019 11:30:32 +0100 Subject: [PATCH 04/11] Fix memalign --- dash/examples/bench.07.local-copy/main.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dash/examples/bench.07.local-copy/main.cpp b/dash/examples/bench.07.local-copy/main.cpp index bed49fbe6..9dce3aa5d 100644 --- a/dash/examples/bench.07.local-copy/main.cpp +++ b/dash/examples/bench.07.local-copy/main.cpp @@ -26,6 +26,16 @@ using std::endl; using std::setw; using std::setprecision; +#ifndef __APPLE__ + #define _aligned_malloc(size, alignment) memalign(alignment, size) +#else + void *_aligned_malloc(size_t size, size_t alignment) { + void *buffer; + posix_memalign(&buffer, alignment, size); + return buffer; + } +#endif + typedef double ElementType; typedef int64_t index_t; typedef dash::Array< @@ -323,7 +333,7 @@ measurement copy_block_to_local( ElementType * local_array = nullptr; if (myid == target_unit_id) { local_array = static_cast( - memalign(align_size, block_bytes)); + _aligned_malloc(block_bytes, align_size)); } Array_t global_array; From a3c8c1c944ae15b4d92906ca0d93b7006fa2fb3f Mon Sep 17 00:00:00 2001 From: anindex Date: Fri, 6 Dec 2019 11:56:00 +0100 Subject: [PATCH 05/11] Add POSIX macro definition in Timestamp.h for macOS --- dash/include/dash/internal/Config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/dash/include/dash/internal/Config.h b/dash/include/dash/internal/Config.h index 90e5d0d39..c795fd259 100644 --- a/dash/include/dash/internal/Config.h +++ b/dash/include/dash/internal/Config.h @@ -157,6 +157,7 @@ // OSX #if defined(__MACH__) && defined(__APPLE__) # define DASH__PLATFORM__OSX +# define DASH__PLATFORM__POSIX #endif // UX #if (defined(__hpux) || defined(hpux)) || \ From 34712f48698f7098b93a818f76688f6db75c9573 Mon Sep 17 00:00:00 2001 From: anindex Date: Wed, 11 Dec 2019 14:27:33 +0100 Subject: [PATCH 06/11] Weird ifdef DART__PLATFORM__LINUX, its else block return error while HWLOC or PAPI enabled --- dart-impl/base/src/hwinfo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dart-impl/base/src/hwinfo.c b/dart-impl/base/src/hwinfo.c index f7a6b15aa..e01990e15 100644 --- a/dart-impl/base/src/hwinfo.c +++ b/dart-impl/base/src/hwinfo.c @@ -358,9 +358,9 @@ dart_ret_t dart_hwinfo( hw.cpu_id = sched_getcpu(); } #else - DART_LOG_ERROR("dart_hwinfo: " - "HWLOC or PAPI required if not running on a Linux platform"); - return DART_ERR_OTHER; +// DART_LOG_ERROR("dart_hwinfo: " +// "HWLOC or PAPI required if not running on a Linux platform"); +// return DART_ERR_OTHER; #endif #ifdef DART__ARCH__IS_MIC From f80e85f47b265255737db3d7c4a061672f5a8aca Mon Sep 17 00:00:00 2001 From: anindex Date: Wed, 11 Dec 2019 16:21:43 +0100 Subject: [PATCH 07/11] Support sched_getcpu for macOS --- dart-impl/base/src/hwinfo.c | 40 +++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/dart-impl/base/src/hwinfo.c b/dart-impl/base/src/hwinfo.c index e01990e15..b2a236579 100644 --- a/dart-impl/base/src/hwinfo.c +++ b/dart-impl/base/src/hwinfo.c @@ -4,6 +4,28 @@ # define _GNU_SOURCE # include #endif + +#ifdef DART__PLATFORM__OSX +#include + +#define CPUID(INFO, LEAF, SUBLEAF) __cpuid_count(LEAF, SUBLEAF, INFO[0], INFO[1], INFO[2], INFO[3]) + +static extern int osx_sched_getcpu() { + uint32_t CPUInfo[4]; + int cpuid; + CPUID(CPUInfo, 1, 0); + /* CPUInfo[1] is EBX, bits 24-31 are APIC ID */ + if ( (CPUInfo[3] & (1 << 9)) == 0) { + cpuid = -1; /* no APIC on chip */ + } + else { + cpuid = (unsigned)CPUInfo[1] >> 24; + } + if (cpuid < 0) cpuid = 0; + return cpuid; +} +#endif + #include #include #include @@ -353,15 +375,17 @@ dart_ret_t dart_hwinfo( } #endif /* DART_ENABLE_PAPI */ -#ifdef DART__PLATFORM__LINUX - if (hw.cpu_id < 0) { +if (hw.cpu_id < 0) { + #ifdef DART__PLATFORM__LINUX hw.cpu_id = sched_getcpu(); - } -#else -// DART_LOG_ERROR("dart_hwinfo: " -// "HWLOC or PAPI required if not running on a Linux platform"); -// return DART_ERR_OTHER; -#endif + #elif defined(DART__PLATFORM__OSX) + hw.cpu_id = osx_sched_getcpu(); + #else + DART_LOG_ERROR("dart_hwinfo: " + "HWLOC or PAPI required if not running on a Linux or OSX platform"); + return DART_ERR_OTHER; + #endif +} #ifdef DART__ARCH__IS_MIC /* From ec79c5f6e5cb6d5157ad8e10918ce5598a33020a Mon Sep 17 00:00:00 2001 From: anindex Date: Wed, 11 Dec 2019 16:25:08 +0100 Subject: [PATCH 08/11] minor error --- dart-impl/base/src/hwinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dart-impl/base/src/hwinfo.c b/dart-impl/base/src/hwinfo.c index b2a236579..dda2faf20 100644 --- a/dart-impl/base/src/hwinfo.c +++ b/dart-impl/base/src/hwinfo.c @@ -10,7 +10,7 @@ #define CPUID(INFO, LEAF, SUBLEAF) __cpuid_count(LEAF, SUBLEAF, INFO[0], INFO[1], INFO[2], INFO[3]) -static extern int osx_sched_getcpu() { +static int osx_sched_getcpu() { uint32_t CPUInfo[4]; int cpuid; CPUID(CPUInfo, 1, 0); From 38a745237a2e21a9c282563ac09c33a7fa587ff2 Mon Sep 17 00:00:00 2001 From: anindex Date: Wed, 11 Dec 2019 16:27:50 +0100 Subject: [PATCH 09/11] minor error --- dart-impl/base/src/hwinfo.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dart-impl/base/src/hwinfo.c b/dart-impl/base/src/hwinfo.c index dda2faf20..73f543d1e 100644 --- a/dart-impl/base/src/hwinfo.c +++ b/dart-impl/base/src/hwinfo.c @@ -7,6 +7,7 @@ #ifdef DART__PLATFORM__OSX #include +#include #define CPUID(INFO, LEAF, SUBLEAF) __cpuid_count(LEAF, SUBLEAF, INFO[0], INFO[1], INFO[2], INFO[3]) From 7c160dad154002a61a25d16df1f31079d24a615b Mon Sep 17 00:00:00 2001 From: anindex Date: Wed, 11 Dec 2019 16:34:17 +0100 Subject: [PATCH 10/11] remove malloc.h where not needed --- dart-impl/mpi/src/dart_synchronization.c | 6 ------ dash/examples/bench.07.local-copy/main.cpp | 6 ------ 2 files changed, 12 deletions(-) diff --git a/dart-impl/mpi/src/dart_synchronization.c b/dart-impl/mpi/src/dart_synchronization.c index 6376b09c3..4d5a62d4f 100644 --- a/dart-impl/mpi/src/dart_synchronization.c +++ b/dart-impl/mpi/src/dart_synchronization.c @@ -23,12 +23,6 @@ #include #include #include -#ifdef __APPLE__ - #include -#else - #include -#endif - struct dart_lock_struct { diff --git a/dash/examples/bench.07.local-copy/main.cpp b/dash/examples/bench.07.local-copy/main.cpp index 9dce3aa5d..29faa8b65 100644 --- a/dash/examples/bench.07.local-copy/main.cpp +++ b/dash/examples/bench.07.local-copy/main.cpp @@ -11,12 +11,6 @@ #include #include -#ifdef __APPLE__ - #include -#else - #include -#endif - #ifdef DASH_ENABLE_IPM #include #endif From eb22d3c8c54238263cb7aaeee7de3b1fbc225df5 Mon Sep 17 00:00:00 2001 From: anindex Date: Wed, 11 Dec 2019 16:40:34 +0100 Subject: [PATCH 11/11] using posix_memalign all the way --- dash/examples/bench.07.local-copy/main.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dash/examples/bench.07.local-copy/main.cpp b/dash/examples/bench.07.local-copy/main.cpp index 29faa8b65..069292246 100644 --- a/dash/examples/bench.07.local-copy/main.cpp +++ b/dash/examples/bench.07.local-copy/main.cpp @@ -20,15 +20,11 @@ using std::endl; using std::setw; using std::setprecision; -#ifndef __APPLE__ - #define _aligned_malloc(size, alignment) memalign(alignment, size) -#else - void *_aligned_malloc(size_t size, size_t alignment) { +static void *_aligned_malloc(size_t size, size_t alignment) { void *buffer; posix_memalign(&buffer, alignment, size); return buffer; - } -#endif +} typedef double ElementType; typedef int64_t index_t;