Arcane  v4.1.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
AlignedMemoryAllocator.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* AlignedMemoryAllocator.h (C) 2000-2025 */
9/* */
10/* Allocateur mémoire par défaut. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_ALIGNEDMEMORYALLOCATOR_H
13#define ARCCORE_COMMON_ALIGNEDMEMORYALLOCATOR_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/common/IMemoryAllocator.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Impl
29{
30 extern "C++" ARCCORE_COMMON_EXPORT size_t
31 adjustMemoryCapacity(size_t wanted_capacity, size_t element_size);
32}
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
44class ARCCORE_COMMON_EXPORT AlignedMemoryAllocator
45: public IMemoryAllocator
46{
47 private:
48
49 static AlignedMemoryAllocator SimdAllocator;
50 static AlignedMemoryAllocator CacheLineAllocator;
51
52 public:
53
54 // TODO: essayer de trouver les bonnes valeurs en fonction de la cible.
55 // 64 est OK pour toutes les architectures x64 à la fois pour le SIMD
56 // et la ligne de cache.
57
58 // IMPORTANT : Si on change la valeur ici, il faut changer la taille de
59 // l'alignement de ArrayImplBase.
60
61 // TODO Pour l'instant seul un alignement sur 64 est autorisé. Pour
62 // autoriser d'autres valeurs, il faut modifier l'implémentation dans
63 // ArrayImplBase.
64
65 // TODO marquer les méthodes comme 'final'.
66
68 static constexpr Integer simdAlignment() { return 64; }
70 static constexpr Integer cacheLineAlignment() { return 64; }
71
79 static AlignedMemoryAllocator* Simd()
80 {
81 return &SimdAllocator;
82 }
83
87 static AlignedMemoryAllocator* CacheLine()
88 {
89 return &CacheLineAllocator;
90 }
91
92 protected:
93
94 explicit AlignedMemoryAllocator(Int32 alignment)
95 : m_alignment(static_cast<size_t>(alignment))
96 {}
97
98 public:
99
100 bool hasRealloc(MemoryAllocationArgs) const override { return false; }
101 AllocatedMemoryInfo allocate(MemoryAllocationArgs args, Int64 new_size) override;
102 AllocatedMemoryInfo reallocate(MemoryAllocationArgs args, AllocatedMemoryInfo current_ptr, Int64 new_size) override;
103 void deallocate(MemoryAllocationArgs args, AllocatedMemoryInfo ptr) override;
104 Int64 adjustedCapacity(MemoryAllocationArgs args, Int64 wanted_capacity, Int64 element_size) const override;
105 size_t guaranteedAlignment(MemoryAllocationArgs) const override { return m_alignment; }
107
108 private:
109
110 size_t m_alignment;
111};
112
113/*---------------------------------------------------------------------------*/
114/*---------------------------------------------------------------------------*/
115
116} // End namespace Arccore
117
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
120
121#endif
122
Allocateur mémoire avec alignement mémoire spécifique.
size_t guaranteedAlignment(MemoryAllocationArgs) const override
Valeur de l'alignement garanti par l'allocateur.
static AlignedMemoryAllocator * CacheLine()
Allocateur garantissant l'alignement sur une ligne de cache.
eMemoryResource memoryResource() const override
Ressource mémoire fournie par l'allocateur.
static constexpr Integer simdAlignment()
Alignement pour les structures utilisant la vectorisation.
static AlignedMemoryAllocator * Simd()
Allocateur garantissant l'alignement pour utiliser la vectorisation sur la plateforme cible.
bool hasRealloc(MemoryAllocationArgs) const override
Indique si l'allocateur supporte la sémantique de realloc.
static constexpr Integer cacheLineAlignment()
Alignement pour une ligne de cache.
Informations sur une zone mémoire allouée.
Interface d'un allocateur pour la mémoire.
Classe contenant des informations pour spécialiser les allocations.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
eMemoryResource
Liste des ressources mémoire disponibles.
@ Host
Alloue sur l'hôte.
std::int32_t Int32
Type entier signé sur 32 bits.