From 7133d788f710ec19b3288bd8d67dbe4a4940001d Mon Sep 17 00:00:00 2001 From: Xavier Lacoste Date: Mon, 24 Jul 2023 15:56:02 +0200 Subject: [PATCH 01/11] use specific implementation ti get available host memory on MacOS --- .../common/LifoStorageCommon.hpp | 5 +- .../common/getAvailableMemory.hpp | 56 +++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/coreComponents/common/getAvailableMemory.hpp diff --git a/src/coreComponents/common/LifoStorageCommon.hpp b/src/coreComponents/common/LifoStorageCommon.hpp index 6fec8404332..80ed5989e3c 100644 --- a/src/coreComponents/common/LifoStorageCommon.hpp +++ b/src/coreComponents/common/LifoStorageCommon.hpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -38,7 +37,7 @@ #include "common/TimingMacros.hpp" #include "common/FixedSizeDequeWithMutexes.hpp" #include "common/MultiMutexesLock.hpp" - +#include "common/getAvailableMemory.hpp" namespace geos { @@ -155,7 +154,7 @@ class LifoStorageCommon static int computeNumberOfBufferOnHost( int percent, size_t bufferSize, int maxNumberOfBuffers, int numberOfBuffersToStoreOnDevice ) { GEOS_ERROR_IF( percent > 100, "Error, percentage of memory should be smallerer than -100, check lifoOnHost (should be greater that -100)" ); - size_t free = sysconf( _SC_AVPHYS_PAGES ) * sysconf( _SC_PAGESIZE ); + size_t free = getAvailableMemory(); int numberOfBuffersToStoreOnHost = std::max( 1, std::min( ( int )( 0.01 * percent * free / bufferSize ), maxNumberOfBuffers - numberOfBuffersToStoreOnDevice ) ); double freeGB = ( ( double ) free ) / ( 1024.0 * 1024.0 * 1024.0 ) / MpiWrapper::nodeCommSize(); LIFO_LOG_RANK( " LIFO : available memory on host " << freeGB << " GB" ); diff --git a/src/coreComponents/common/getAvailableMemory.hpp b/src/coreComponents/common/getAvailableMemory.hpp new file mode 100644 index 00000000000..afd8de394e2 --- /dev/null +++ b/src/coreComponents/common/getAvailableMemory.hpp @@ -0,0 +1,56 @@ +#ifndef GET_AVAILABLE_MEMORY_HPP +#define GET_AVAILABLE_MEMORY_HPP + +#include +#if defined __MACH__ +#include +#include + +#include +#include +#include +#include +#endif + +namespace geos +{ + /** + * @brief Retieves current available memory on host + * @return the available memory in bytes. + */ + static inline size_t getAvailableMemory() + { +#if defined(__APPLE__) && defined(__MACH__) + int mib[6]; + mib[0] = CTL_HW; + mib[1] = HW_PAGESIZE; + + int pagesize; + size_t length; + length = sizeof( pagesize ); + if ( sysctl( mib, 2, &pagesize, &length, NULL, 0 ) < 0 ) + { + fprintf( stderr, "getting page size" ); + } + + mach_msg_type_number_t count = HOST_VM_INFO_COUNT; + + vm_statistics_data_t vmstat; + if ( host_statistics( mach_host_self(), HOST_VM_INFO, ( host_info_t ) &vmstat, &count ) != KERN_SUCCESS ) + { + fprintf (stderr, "Failed to get VM statistics."); + } + + return vmstat.free_count * pagesize; +#else + GEOS_ERROR_IF( percent > 100, "Error, percentage of memory should be smallerer than -100, check lifoOnHost (should be greater that -100)" ); + return (size_t)sysconf( _SC_AVPHYS_PAGES ) *(size_t) sysconf( _SC_PAGESIZE ); +#endif + } +} + +// remove these definitions from mach/boolean.h that can conflict with GEOS code (eg. InputFlags::FALSE) +#undef TRUE +#undef FALSE + +#endif From 2c10b6a83c6ca2db39988ddb6d5af1428b7b7c5e Mon Sep 17 00:00:00 2001 From: Xavier Lacoste Date: Mon, 24 Jul 2023 16:44:36 +0200 Subject: [PATCH 02/11] uncrustify --- .../common/getAvailableMemory.hpp | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/coreComponents/common/getAvailableMemory.hpp b/src/coreComponents/common/getAvailableMemory.hpp index afd8de394e2..1c2d9da62ed 100644 --- a/src/coreComponents/common/getAvailableMemory.hpp +++ b/src/coreComponents/common/getAvailableMemory.hpp @@ -14,39 +14,39 @@ namespace geos { - /** - * @brief Retieves current available memory on host - * @return the available memory in bytes. - */ - static inline size_t getAvailableMemory() - { +/** + * @brief Retieves current available memory on host + * @return the available memory in bytes. + */ +static inline size_t getAvailableMemory() +{ #if defined(__APPLE__) && defined(__MACH__) - int mib[6]; - mib[0] = CTL_HW; - mib[1] = HW_PAGESIZE; - - int pagesize; - size_t length; - length = sizeof( pagesize ); - if ( sysctl( mib, 2, &pagesize, &length, NULL, 0 ) < 0 ) - { - fprintf( stderr, "getting page size" ); - } - - mach_msg_type_number_t count = HOST_VM_INFO_COUNT; - - vm_statistics_data_t vmstat; - if ( host_statistics( mach_host_self(), HOST_VM_INFO, ( host_info_t ) &vmstat, &count ) != KERN_SUCCESS ) - { - fprintf (stderr, "Failed to get VM statistics."); - } - - return vmstat.free_count * pagesize; + int mib[6]; + mib[0] = CTL_HW; + mib[1] = HW_PAGESIZE; + + int pagesize; + size_t length; + length = sizeof( pagesize ); + if( sysctl( mib, 2, &pagesize, &length, NULL, 0 ) < 0 ) + { + fprintf( stderr, "getting page size" ); + } + + mach_msg_type_number_t count = HOST_VM_INFO_COUNT; + + vm_statistics_data_t vmstat; + if( host_statistics( mach_host_self(), HOST_VM_INFO, ( host_info_t ) &vmstat, &count ) != KERN_SUCCESS ) + { + fprintf ( stderr, "Failed to get VM statistics." ); + } + + return vmstat.free_count * pagesize; #else - GEOS_ERROR_IF( percent > 100, "Error, percentage of memory should be smallerer than -100, check lifoOnHost (should be greater that -100)" ); - return (size_t)sysconf( _SC_AVPHYS_PAGES ) *(size_t) sysconf( _SC_PAGESIZE ); + GEOS_ERROR_IF( percent > 100, "Error, percentage of memory should be smallerer than -100, check lifoOnHost (should be greater that -100)" ); + return (size_t)sysconf( _SC_AVPHYS_PAGES ) *(size_t) sysconf( _SC_PAGESIZE ); #endif - } +} } // remove these definitions from mach/boolean.h that can conflict with GEOS code (eg. InputFlags::FALSE) From 6f1f3c1c25b7c2a08275dcc13e9bf77411f40435 Mon Sep 17 00:00:00 2001 From: Xavier Lacoste Date: Tue, 25 Jul 2023 10:18:35 +0200 Subject: [PATCH 03/11] remove wrong code --- src/coreComponents/common/getAvailableMemory.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreComponents/common/getAvailableMemory.hpp b/src/coreComponents/common/getAvailableMemory.hpp index 1c2d9da62ed..58c61d8839f 100644 --- a/src/coreComponents/common/getAvailableMemory.hpp +++ b/src/coreComponents/common/getAvailableMemory.hpp @@ -43,7 +43,6 @@ static inline size_t getAvailableMemory() return vmstat.free_count * pagesize; #else - GEOS_ERROR_IF( percent > 100, "Error, percentage of memory should be smallerer than -100, check lifoOnHost (should be greater that -100)" ); return (size_t)sysconf( _SC_AVPHYS_PAGES ) *(size_t) sysconf( _SC_PAGESIZE ); #endif } From b9d17f18e7db77147e0da0f9f33b5d7a088839d3 Mon Sep 17 00:00:00 2001 From: Xavier Lacoste Date: Tue, 25 Jul 2023 17:00:34 +0200 Subject: [PATCH 04/11] use getAvailableMemoryOnHost() and getAvailableMemoryOnDevice() from LvArray --- src/coreComponents/LvArray | 2 +- .../common/LifoStorageCommon.hpp | 4 +- src/coreComponents/common/LifoStorageCuda.hpp | 4 +- .../common/getAvailableMemory.hpp | 55 ------------------- 4 files changed, 5 insertions(+), 60 deletions(-) delete mode 100644 src/coreComponents/common/getAvailableMemory.hpp diff --git a/src/coreComponents/LvArray b/src/coreComponents/LvArray index 145bb1c530a..977bc1f2cff 160000 --- a/src/coreComponents/LvArray +++ b/src/coreComponents/LvArray @@ -1 +1 @@ -Subproject commit 145bb1c530a68afa7d446e21c7a90b9c6a987d1f +Subproject commit 977bc1f2cff9b95ff2c3efc8a7258df97af4740e diff --git a/src/coreComponents/common/LifoStorageCommon.hpp b/src/coreComponents/common/LifoStorageCommon.hpp index 80ed5989e3c..1974d509d8f 100644 --- a/src/coreComponents/common/LifoStorageCommon.hpp +++ b/src/coreComponents/common/LifoStorageCommon.hpp @@ -37,7 +37,7 @@ #include "common/TimingMacros.hpp" #include "common/FixedSizeDequeWithMutexes.hpp" #include "common/MultiMutexesLock.hpp" -#include "common/getAvailableMemory.hpp" +#include "LvArray/system.hpp" namespace geos { @@ -154,7 +154,7 @@ class LifoStorageCommon static int computeNumberOfBufferOnHost( int percent, size_t bufferSize, int maxNumberOfBuffers, int numberOfBuffersToStoreOnDevice ) { GEOS_ERROR_IF( percent > 100, "Error, percentage of memory should be smallerer than -100, check lifoOnHost (should be greater that -100)" ); - size_t free = getAvailableMemory(); + size_t free = LvArray::system::getAvailableMemoryOnHost(); int numberOfBuffersToStoreOnHost = std::max( 1, std::min( ( int )( 0.01 * percent * free / bufferSize ), maxNumberOfBuffers - numberOfBuffersToStoreOnDevice ) ); double freeGB = ( ( double ) free ) / ( 1024.0 * 1024.0 * 1024.0 ) / MpiWrapper::nodeCommSize(); LIFO_LOG_RANK( " LIFO : available memory on host " << freeGB << " GB" ); diff --git a/src/coreComponents/common/LifoStorageCuda.hpp b/src/coreComponents/common/LifoStorageCuda.hpp index 9345db2615d..d2fe6a1b3d4 100644 --- a/src/coreComponents/common/LifoStorageCuda.hpp +++ b/src/coreComponents/common/LifoStorageCuda.hpp @@ -30,6 +30,7 @@ #include "common/FixedSizeDequeWithMutexes.hpp" #include "common/MultiMutexesLock.hpp" #include "common/LifoStorageCommon.hpp" +#include "LvArray/system.hpp" namespace geos { @@ -147,8 +148,7 @@ class LifoStorageCuda : public LifoStorageCommon< T, INDEX_TYPE > static int computeNumberOfBufferOnDevice( int percent, size_t bufferSize, int maxNumberOfBuffers ) { GEOS_ERROR_IF( percent > 100, "Error, percentage of memory should be smaller than 100, check lifoOnDevice (should be greater than -100)" ); - size_t free, total; - GEOS_ERROR_IF( cudaSuccess != cudaMemGetInfo( &free, &total ), "Error getting CUDA device available memory" ); + size_t free = LvArray::system::getAvailableMemoryOnDevice(); double freeGB = ( ( double ) free ) / ( 1024.0 * 1024.0 * 1024.0 ); LIFO_LOG_RANK( " LIFO : available memory on device " << freeGB << " GB" ); return std::min( ( int )( 0.01 * percent * free / bufferSize ), maxNumberOfBuffers ); diff --git a/src/coreComponents/common/getAvailableMemory.hpp b/src/coreComponents/common/getAvailableMemory.hpp deleted file mode 100644 index 58c61d8839f..00000000000 --- a/src/coreComponents/common/getAvailableMemory.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef GET_AVAILABLE_MEMORY_HPP -#define GET_AVAILABLE_MEMORY_HPP - -#include -#if defined __MACH__ -#include -#include - -#include -#include -#include -#include -#endif - -namespace geos -{ -/** - * @brief Retieves current available memory on host - * @return the available memory in bytes. - */ -static inline size_t getAvailableMemory() -{ -#if defined(__APPLE__) && defined(__MACH__) - int mib[6]; - mib[0] = CTL_HW; - mib[1] = HW_PAGESIZE; - - int pagesize; - size_t length; - length = sizeof( pagesize ); - if( sysctl( mib, 2, &pagesize, &length, NULL, 0 ) < 0 ) - { - fprintf( stderr, "getting page size" ); - } - - mach_msg_type_number_t count = HOST_VM_INFO_COUNT; - - vm_statistics_data_t vmstat; - if( host_statistics( mach_host_self(), HOST_VM_INFO, ( host_info_t ) &vmstat, &count ) != KERN_SUCCESS ) - { - fprintf ( stderr, "Failed to get VM statistics." ); - } - - return vmstat.free_count * pagesize; -#else - return (size_t)sysconf( _SC_AVPHYS_PAGES ) *(size_t) sysconf( _SC_PAGESIZE ); -#endif -} -} - -// remove these definitions from mach/boolean.h that can conflict with GEOS code (eg. InputFlags::FALSE) -#undef TRUE -#undef FALSE - -#endif From b75e9b4b193eb167f6c98186ac308aaf9c2bb35e Mon Sep 17 00:00:00 2001 From: Xavier Lacoste Date: Wed, 26 Jul 2023 10:26:55 +0200 Subject: [PATCH 05/11] fix includes --- src/coreComponents/LvArray | 2 +- src/coreComponents/common/LifoStorageCuda.hpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/LvArray b/src/coreComponents/LvArray index 977bc1f2cff..c7282c24686 160000 --- a/src/coreComponents/LvArray +++ b/src/coreComponents/LvArray @@ -1 +1 @@ -Subproject commit 977bc1f2cff9b95ff2c3efc8a7258df97af4740e +Subproject commit c7282c24686257b5bebc3e03506ee5084dc7333c diff --git a/src/coreComponents/common/LifoStorageCuda.hpp b/src/coreComponents/common/LifoStorageCuda.hpp index d2fe6a1b3d4..b3c1fd590bc 100644 --- a/src/coreComponents/common/LifoStorageCuda.hpp +++ b/src/coreComponents/common/LifoStorageCuda.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include "common/FixedSizeDeque.hpp" @@ -30,7 +29,7 @@ #include "common/FixedSizeDequeWithMutexes.hpp" #include "common/MultiMutexesLock.hpp" #include "common/LifoStorageCommon.hpp" -#include "LvArray/system.hpp" +#include "LvArray/src/system.hpp" namespace geos { From fa12329e6434c070f1bff2132bad1c0c0d283ad7 Mon Sep 17 00:00:00 2001 From: Xavier Lacoste Date: Wed, 26 Jul 2023 10:27:22 +0200 Subject: [PATCH 06/11] fix includes --- src/coreComponents/common/LifoStorageCommon.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/common/LifoStorageCommon.hpp b/src/coreComponents/common/LifoStorageCommon.hpp index 1974d509d8f..0189e7cc1ed 100644 --- a/src/coreComponents/common/LifoStorageCommon.hpp +++ b/src/coreComponents/common/LifoStorageCommon.hpp @@ -37,7 +37,7 @@ #include "common/TimingMacros.hpp" #include "common/FixedSizeDequeWithMutexes.hpp" #include "common/MultiMutexesLock.hpp" -#include "LvArray/system.hpp" +#include "LvArray/src/system.hpp" namespace geos { From 8064c872a678eebf450f080ac90d240451c639c3 Mon Sep 17 00:00:00 2001 From: Xavier Lacoste Date: Wed, 26 Jul 2023 10:29:55 +0200 Subject: [PATCH 07/11] uncrustify --- src/coreComponents/LvArray | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/LvArray b/src/coreComponents/LvArray index c7282c24686..936ac08ae07 160000 --- a/src/coreComponents/LvArray +++ b/src/coreComponents/LvArray @@ -1 +1 @@ -Subproject commit c7282c24686257b5bebc3e03506ee5084dc7333c +Subproject commit 936ac08ae0713e0720c6de7d9712ea066b5caa1f From c513af2f2c357dc2ed6a528969dee8f0a810a872 Mon Sep 17 00:00:00 2001 From: Xavier Lacoste Date: Wed, 26 Jul 2023 10:49:18 +0200 Subject: [PATCH 08/11] prgma once not supported by Apple clang version 14.0.3 (clang-1403.0.22.14.1) --- src/coreComponents/LvArray | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/LvArray b/src/coreComponents/LvArray index 936ac08ae07..8fd53ad223f 160000 --- a/src/coreComponents/LvArray +++ b/src/coreComponents/LvArray @@ -1 +1 @@ -Subproject commit 936ac08ae0713e0720c6de7d9712ea066b5caa1f +Subproject commit 8fd53ad223f18925504931ba478d1a001be87647 From 8f0287a781b9063817b9ab5e7ffac396fbc8fce6 Mon Sep 17 00:00:00 2001 From: Xavier Lacoste Date: Wed, 26 Jul 2023 11:08:51 +0200 Subject: [PATCH 09/11] includes --- src/coreComponents/LvArray | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/LvArray b/src/coreComponents/LvArray index 8fd53ad223f..c4f22f7ae79 160000 --- a/src/coreComponents/LvArray +++ b/src/coreComponents/LvArray @@ -1 +1 @@ -Subproject commit 8fd53ad223f18925504931ba478d1a001be87647 +Subproject commit c4f22f7ae79457308db4626165ee0b3cd19d03ec From fef0ea9a2ea6c960a3eca6f5f65d3de9e2742121 Mon Sep 17 00:00:00 2001 From: Xavier Lacoste Date: Wed, 26 Jul 2023 14:49:09 +0200 Subject: [PATCH 10/11] unused variable --- src/coreComponents/LvArray | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/LvArray b/src/coreComponents/LvArray index c4f22f7ae79..67ee02a5478 160000 --- a/src/coreComponents/LvArray +++ b/src/coreComponents/LvArray @@ -1 +1 @@ -Subproject commit c4f22f7ae79457308db4626165ee0b3cd19d03ec +Subproject commit 67ee02a5478110107e247c051757f28cc18b90c7 From 267844a02c363175a4e11bc42cab4266e41cf65f Mon Sep 17 00:00:00 2001 From: Xavier Lacoste Date: Wed, 26 Jul 2023 14:56:07 +0200 Subject: [PATCH 11/11] typo --- src/coreComponents/LvArray | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/LvArray b/src/coreComponents/LvArray index 67ee02a5478..c506d0d307c 160000 --- a/src/coreComponents/LvArray +++ b/src/coreComponents/LvArray @@ -1 +1 @@ -Subproject commit 67ee02a5478110107e247c051757f28cc18b90c7 +Subproject commit c506d0d307cb1a5ddfa71a43c83b89dbd3caf6d8