Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MemoryUtils.cc
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.cc (C) 2000-2024 */
9/* */
10/* Fonctions utilitaires de gestion mémoire. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/MemoryUtils.h"
15
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/MemoryAllocator.h"
18#include "arcane/utils/IMemoryRessourceMng.h"
19#include "arcane/utils/internal/IMemoryRessourceMngInternal.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30IMemoryAllocator* MemoryUtils::
31getDefaultDataAllocator()
32{
34}
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39IMemoryAllocator* MemoryUtils::
40getDeviceOrHostAllocator()
41{
42 IMemoryRessourceMng* mrm = platform::getDataMemoryRessourceMng();
43 IMemoryAllocator* a = mrm->getAllocator(eMemoryRessource::Device,false);
44 if (a)
45 return a;
46 return mrm->getAllocator(eMemoryRessource::Host);
47}
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
52MemoryAllocationOptions MemoryUtils::
53getDefaultDataAllocator(eMemoryLocationHint hint)
54{
55 return MemoryAllocationOptions(getDefaultDataAllocator(), hint);
56}
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60
61MemoryAllocationOptions MemoryUtils::
62getAllocationOptions(eMemoryRessource mem_ressource)
63{
64 IMemoryAllocator* allocator = platform::getDataMemoryRessourceMng()->getAllocator(mem_ressource);
65 return MemoryAllocationOptions(allocator);
66}
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
71MemoryAllocationOptions MemoryUtils::
72getAllocatorForMostlyReadOnlyData()
73{
74 return getDefaultDataAllocator(eMemoryLocationHint::HostAndDeviceMostlyRead);
75}
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
80Int64 MemoryUtils::impl::
81computeCapacity(Int64 size)
82{
83 double d_size = static_cast<double>(size);
84 double d_new_capacity = d_size * 1.8;
85 if (size > 5000000)
86 d_new_capacity = d_size * 1.2;
87 else if (size > 500000)
88 d_new_capacity = d_size * 1.5;
89 return static_cast<Int64>(d_new_capacity);
90}
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95void MemoryUtils::
96copy(MutableMemoryView destination, eMemoryRessource destination_mem,
97 ConstMemoryView source, eMemoryRessource source_mem, const RunQueue* queue)
98{
99 IMemoryRessourceMng* mrm = platform::getDataMemoryRessourceMng();
100 mrm->_internal()->copy(source, destination_mem, destination, source_mem, queue);
101}
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106} // End namespace Arcane
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
virtual IMemoryAllocator * getAllocator(eMemoryRessource r)=0
Allocateur mémoire pour la ressource r.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
IMemoryRessourceMng * getDataMemoryRessourceMng()
Gestionnaire de ressource mémoire pour les données.
IMemoryAllocator * getDefaultDataAllocator()
Allocateur par défaut pour les données.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
eMemoryRessource
Liste des ressources mémoire disponibles.
@ Host
Alloue sur l'hôte.
@ Device
Alloue sur le device.