Skip to content

Commit bce264a

Browse files
Merge pull request #1198 from arcaneframework/ht-pagesize
Use the real page size instead of hardcoded 4096 bytes that can be false
2 parents 6798ca4 + 0390e4b commit bce264a

File tree

5 files changed

+65
-9
lines changed

5 files changed

+65
-9
lines changed

arcane/src/arcane/accelerator/cuda/CudaAccelerator.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* CudaAccelerator.cc (C) 2000-2023 */
8+
/* CudaAccelerator.cc (C) 2000-2024 */
99
/* */
1010
/* Backend 'CUDA' pour les accélérateurs. */
1111
/*---------------------------------------------------------------------------*/
@@ -100,7 +100,7 @@ class UnifiedMemoryCudaMemoryAllocator
100100
{
101101
public:
102102

103-
static constexpr Int64 page_size = 4096;
103+
Int64 page_size = platform::getPageSize();
104104

105105
void initialize()
106106
{
@@ -121,7 +121,7 @@ class UnifiedMemoryCudaMemoryAllocator
121121
_applyHint(ptr.baseAddress(), ptr.size(), new_args);
122122
}
123123

124-
Int64 adjustedCapacity(MemoryAllocationArgs args, Int64 wanted_capacity, Int64 element_size) const
124+
Int64 adjustedCapacity(MemoryAllocationArgs args, Int64 wanted_capacity, Int64 element_size) const override
125125
{
126126
wanted_capacity = AlignedMemoryAllocator3::adjustedCapacity(args, wanted_capacity, element_size);
127127
const bool do_page = m_page_allocate_level > 0;
@@ -173,7 +173,7 @@ class UnifiedMemoryCudaMemoryAllocator
173173
return ::cudaFree(ptr);
174174
}
175175

176-
cudaError_t _allocate(void** ptr, size_t new_size, MemoryAllocationArgs args)
176+
cudaError_t _allocate(void** ptr, size_t new_size, MemoryAllocationArgs args) override
177177
{
178178
auto r = ::cudaMallocManaged(ptr, new_size, cudaMemAttachGlobal);
179179
void* p = *ptr;

arcane/src/arcane/utils/PlatformUtils.cc

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* PlatformUtils.cc (C) 2000-2023 */
8+
/* PlatformUtils.cc (C) 2000-2024 */
99
/* */
1010
/* Fonctions utilitaires dépendant de la plateforme. */
1111
/*---------------------------------------------------------------------------*/
@@ -525,6 +525,25 @@ getRealTimeNS()
525525
/*---------------------------------------------------------------------------*/
526526
/*---------------------------------------------------------------------------*/
527527

528+
extern "C++" ARCANE_UTILS_EXPORT Int64 platform::
529+
getPageSize()
530+
{
531+
#if defined(ARCCORE_OS_WIN32)
532+
SYSTEM_INFO si;
533+
GetSystemInfo(&si);
534+
return si.dwPageSize;
535+
#elif defined(ARCANE_OS_LINUX)
536+
return ::sysconf(_SC_PAGESIZE);
537+
#else
538+
#warning "getPageSize() not implemented for your platform. Default is 4096"
539+
Int64 page_size = 4096;
540+
return page_size;
541+
#endif
542+
}
543+
544+
/*---------------------------------------------------------------------------*/
545+
/*---------------------------------------------------------------------------*/
546+
528547
namespace
529548
{
530549
void (*global_garbage_collector_delegate)() = nullptr;

arcane/src/arcane/utils/PlatformUtils.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* PlatformUtils.h (C) 2000-2019 */
8+
/* PlatformUtils.h (C) 2000-2024 */
99
/* */
1010
/* Fonctions utilitaires dépendant de la plateforme. */
1111
/*---------------------------------------------------------------------------*/
@@ -384,6 +384,14 @@ getLoadedSharedLibraryFullPath(const String& dll_name);
384384
extern "C++" ARCANE_UTILS_EXPORT void
385385
fillCommandLineArguments(StringList& arg_list);
386386

387+
/*---------------------------------------------------------------------------*/
388+
/*---------------------------------------------------------------------------*/
389+
/*!
390+
* \brief Taille des pages du système hôte en octets
391+
*/
392+
extern "C++" ARCANE_UTILS_EXPORT Int64
393+
getPageSize();
394+
387395
/*---------------------------------------------------------------------------*/
388396
/*---------------------------------------------------------------------------*/
389397

arcane/src/arcane/utils/tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
TestHash.cc
88
TestHashTable.cc
99
TestMemory.cc
10+
TestPlatform.cc
1011
TestVector2.cc
1112
TestVector3.cc
1213
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2+
//-----------------------------------------------------------------------------
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4+
// See the top-level COPYRIGHT file for details.
5+
// SPDX-License-Identifier: Apache-2.0
6+
//-----------------------------------------------------------------------------
7+
8+
#include <gtest/gtest.h>
9+
10+
#include "arcane/utils/HashTableMap.h"
11+
#include "arcane/utils/PlatformUtils.h"
12+
13+
#include <iostream>
14+
15+
/*---------------------------------------------------------------------------*/
16+
/*---------------------------------------------------------------------------*/
17+
18+
using namespace Arcane;
19+
20+
TEST(TestPlatform, Misc)
21+
{
22+
Int64 page_size = platform::getPageSize();
23+
std::cout << "PageSize=" << page_size << "\n";
24+
ASSERT_TRUE(page_size>0);
25+
}
26+
27+
/*---------------------------------------------------------------------------*/
28+
/*---------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)