Arcane  4.2.1.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
AlignedMemoryAllocator.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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 std::size_t
31 adjustMemoryCapacity(std::size_t wanted_capacity, std::size_t element_size);
32}
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
37/*!
38 * \brief Allocateur mémoire avec alignement mémoire spécifique.
39 *
40 * Cette classe s'utilise via les deux méthodes publiques Simd()
41 * et CacheLine() qui retournent respectivement un allocateur avec
42 * un alignement adéquat pour autoriser la vectorisation et un allocateur
43 * aligné sur une ligne de cache.
44 */
45class ARCCORE_COMMON_EXPORT AlignedMemoryAllocator
46: public IMemoryAllocator
47{
48 private:
49
50 static AlignedMemoryAllocator SimdAllocator;
51 static AlignedMemoryAllocator CacheLineAllocator;
52
53 public:
54
55 // TODO: essayer de trouver les bonnes valeurs en fonction de la cible.
56 // 64 est OK pour toutes les architectures x64 à la fois pour le SIMD
57 // et la ligne de cache.
58
59 // IMPORTANT : Si on change la valeur ici, il faut changer la taille de
60 // l'alignement de ArrayImplBase.
61
62 // TODO Pour l'instant seul un alignement sur 64 est autorisé. Pour
63 // autoriser d'autres valeurs, il faut modifier l'implémentation dans
64 // ArrayImplBase.
65
66 // TODO marquer les méthodes comme 'final'.
67
68 //! Alignement pour les structures utilisant la vectorisation
69 static constexpr Integer simdAlignment() { return 64; }
70 //! Alignement pour une ligne de cache.
71 static constexpr Integer cacheLineAlignment() { return 64; }
72
73 /*!
74 * \brief Allocateur garantissant l'alignement pour utiliser
75 * la vectorisation sur la plateforme cible.
76 *
77 * Il s'agit de l'alignement pour le type plus restrictif et donc il
78 * est possible d'utiliser cet allocateur pour toutes les structures vectorielles.
79 */
80 static AlignedMemoryAllocator* Simd()
81 {
82 return &SimdAllocator;
83 }
84
85 /*!
86 * \brief Allocateur garantissant l'alignement sur une ligne de cache.
87 */
88 static AlignedMemoryAllocator* CacheLine()
89 {
90 return &CacheLineAllocator;
91 }
92
93 protected:
94
95 explicit AlignedMemoryAllocator(Int32 alignment)
96 : m_alignment(static_cast<std::size_t>(alignment))
97 {}
98
99 public:
100
101 bool hasRealloc(MemoryAllocationArgs) const override { return false; }
102 AllocatedMemoryInfo allocate(MemoryAllocationArgs args, Int64 new_size) override;
103 AllocatedMemoryInfo reallocate(MemoryAllocationArgs args, AllocatedMemoryInfo current_ptr, Int64 new_size) override;
104 void deallocate(MemoryAllocationArgs args, AllocatedMemoryInfo ptr) override;
105 Int64 adjustedCapacity(MemoryAllocationArgs args, Int64 wanted_capacity, Int64 element_size) const override;
106 std::size_t guaranteedAlignment(MemoryAllocationArgs) const override { return m_alignment; }
108
109 private:
110
111 std::size_t m_alignment;
112};
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
116
117} // namespace Arcane
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
122#endif
Allocateur mémoire avec alignement mémoire spécifique.
static AlignedMemoryAllocator * CacheLine()
Allocateur garantissant l'alignement sur une ligne de cache.
eMemoryResource memoryResource() const override
Ressource mémoire fournie par l'allocateur.
std::size_t guaranteedAlignment(MemoryAllocationArgs) const override
Valeur de l'alignement garanti 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.