Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MemoryUtils.h
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/* MemoryUtils.h (C) 2000-2024 */
9/* */
10/* Fonctions utilitaires de gestion mémoire. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_MEMORYUTILS_H
13#define ARCANE_UTILS_MEMORYUTILS_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/MemoryRessource.h"
19#include "arcane/utils/MemoryView.h"
20
21#include "arccore/collections/MemoryAllocationArgs.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane::MemoryUtils
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
42extern "C++" ARCANE_UTILS_EXPORT IMemoryAllocator*
43getDefaultDataAllocator();
44
53extern "C++" ARCANE_UTILS_EXPORT IMemoryAllocator*
54getDeviceOrHostAllocator();
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
65extern "C++" ARCANE_UTILS_EXPORT MemoryAllocationOptions
66getDefaultDataAllocator(eMemoryLocationHint hint);
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
76extern "C++" ARCANE_UTILS_EXPORT MemoryAllocationOptions
77getAllocatorForMostlyReadOnlyData();
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
92extern "C++" ARCANE_UTILS_EXPORT MemoryAllocationOptions
93getAllocationOptions(eMemoryRessource mem_ressource);
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
98namespace impl
99{
101 extern "C++" ARCANE_UTILS_EXPORT Int64
102 computeCapacity(Int64 size);
103} // namespace impl
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
120template <typename DataType> inline Int32
121checkResizeArrayWithCapacity(Array<DataType>& array, Int64 new_size, bool force_resize)
122{
123 Int32 ret_value = 0;
124 Int64 s = array.largeSize();
125 if (new_size > s || force_resize) {
126 ret_value = 1;
127 if (new_size > array.capacity()) {
128 array.reserve(impl::computeCapacity(new_size));
129 ret_value = 2;
130 }
131 array.resize(new_size);
132 }
133 return ret_value;
134}
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
145extern "C++" ARCANE_UTILS_EXPORT void
146copy(MutableMemoryView destination, eMemoryRessource destination_mem,
147 ConstMemoryView source, eMemoryRessource source_mem,
148 const RunQueue* queue = nullptr);
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
152
154inline void
155copy(MutableMemoryView destination, ConstMemoryView source, const RunQueue* queue = nullptr)
156{
158 copy(destination, mem_type, source, mem_type, queue);
159}
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
163
165template <typename DataType> inline void
166copy(Span<DataType> destination, Span<const DataType> source, const RunQueue* queue = nullptr)
167{
168 ConstMemoryView input(asBytes(source));
169 MutableMemoryView output(asWritableBytes(destination));
170 copy(output, input, queue);
171}
172
174template <typename DataType> inline void
175copy(SmallSpan<DataType> destination, SmallSpan<const DataType> source, const RunQueue* queue = nullptr)
176{
177 copy(Span<DataType>(destination), Span<const DataType>(source), queue);
178}
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182
183} // namespace Arcane::MemoryUtils
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188#endif
Déclarations des types utilisés dans Arcane.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
char * copy(char *to, const char *from)
Copie from dans to.
eMemoryRessource
Liste des ressources mémoire disponibles.
@ Unknown
Valeur inconnue ou non initialisée.
detail::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets non modifiables.
Definition Span.h:881
detail::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets modifiables.
Definition Span.h:916