1818#include " arcane/utils/IMemoryRessourceMng.h"
1919#include " arcane/utils/String.h"
2020#include " arccore/common/internal/IMemoryResourceMngInternal.h"
21- #include " arcane/utils/internal/MemoryUtilsInternal.h"
22- #include " arcane/utils/internal/MemoryResourceMng.h"
2321
2422/* ---------------------------------------------------------------------------*/
2523/* ---------------------------------------------------------------------------*/
@@ -40,161 +38,6 @@ namespace Arcane
4038/* ---------------------------------------------------------------------------*/
4139/* ---------------------------------------------------------------------------*/
4240
43- namespace
44- {
45- IMemoryAllocator* global_accelerator_host_memory_allocator = nullptr ;
46- MemoryResourceMng global_default_data_memory_resource_mng;
47- IMemoryRessourceMng* global_data_memory_resource_mng = nullptr ;
48- eMemoryResource global_data_memory_resource = eMemoryResource::Host;
49- } // namespace
50-
51- /* ---------------------------------------------------------------------------*/
52- /* ---------------------------------------------------------------------------*/
53-
54- eMemoryResource MemoryUtils::
55- getDefaultDataMemoryResource ()
56- {
57- return global_data_memory_resource;
58- }
59-
60- /* ---------------------------------------------------------------------------*/
61- /* ---------------------------------------------------------------------------*/
62-
63- void MemoryUtils::
64- setDefaultDataMemoryResource (eMemoryResource v)
65- {
66- global_data_memory_resource = v;
67- }
68-
69- /* ---------------------------------------------------------------------------*/
70- /* ---------------------------------------------------------------------------*/
71-
72- eMemoryResource MemoryUtils::
73- getMemoryResourceFromName (const String& name)
74- {
75- eMemoryResource v = eMemoryResource::Unknown;
76- if (name.null ())
77- return v;
78- if (name == " Device" )
79- v = eMemoryResource::Device;
80- else if (name == " Host" )
81- v = eMemoryResource::Host;
82- else if (name == " HostPinned" )
83- v = eMemoryResource::HostPinned;
84- else if (name == " UnifiedMemory" )
85- v = eMemoryResource::UnifiedMemory;
86- else
87- ARCANE_FATAL (" Invalid name '{0}' for memory resource. Valid names are "
88- " 'Device', 'Host', 'HostPinned' or 'UnifieMemory'." ,
89- name);
90- return v;
91- }
92-
93- /* ---------------------------------------------------------------------------*/
94- /* ---------------------------------------------------------------------------*/
95-
96- IMemoryRessourceMng* MemoryUtils::
97- setDataMemoryResourceMng (IMemoryRessourceMng* mng)
98- {
99- ARCANE_CHECK_POINTER (mng);
100- IMemoryRessourceMng* old = global_data_memory_resource_mng;
101- global_data_memory_resource_mng = mng;
102- return old;
103- }
104-
105- /* ---------------------------------------------------------------------------*/
106- /* ---------------------------------------------------------------------------*/
107-
108- IMemoryRessourceMng* MemoryUtils::
109- getDataMemoryResourceMng ()
110- {
111- IMemoryRessourceMng* a = global_data_memory_resource_mng;
112- if (!a)
113- return &global_default_data_memory_resource_mng;
114- return a;
115- }
116-
117- /* ---------------------------------------------------------------------------*/
118- /* ---------------------------------------------------------------------------*/
119-
120- IMemoryAllocator* MemoryUtils::
121- getDefaultDataAllocator ()
122- {
123- return getDataMemoryResourceMng ()->getAllocator (getDefaultDataMemoryResource ());
124- }
125-
126- /* ---------------------------------------------------------------------------*/
127- /* ---------------------------------------------------------------------------*/
128-
129- IMemoryAllocator* MemoryUtils::
130- getDeviceOrHostAllocator ()
131- {
132- IMemoryRessourceMng* mrm = getDataMemoryResourceMng ();
133- IMemoryAllocator* a = mrm->getAllocator (eMemoryResource::Device, false );
134- if (a)
135- return a;
136- return mrm->getAllocator (eMemoryResource::Host);
137- }
138-
139- /* ---------------------------------------------------------------------------*/
140- /* ---------------------------------------------------------------------------*/
141-
142- MemoryAllocationOptions MemoryUtils::
143- getDefaultDataAllocator (eMemoryLocationHint hint)
144- {
145- return MemoryAllocationOptions (getDefaultDataAllocator (), hint);
146- }
147-
148- /* ---------------------------------------------------------------------------*/
149- /* ---------------------------------------------------------------------------*/
150-
151- IMemoryAllocator* MemoryUtils::
152- getAllocator (eMemoryRessource mem_resource)
153- {
154- return getDataMemoryResourceMng ()->getAllocator (mem_resource);
155- }
156-
157- /* ---------------------------------------------------------------------------*/
158- /* ---------------------------------------------------------------------------*/
159-
160- MemoryAllocationOptions MemoryUtils::
161- getAllocationOptions (eMemoryRessource mem_resource)
162- {
163- return MemoryAllocationOptions (getAllocator (mem_resource));
164- }
165-
166- /* ---------------------------------------------------------------------------*/
167- /* ---------------------------------------------------------------------------*/
168-
169- MemoryAllocationOptions MemoryUtils::
170- getAllocatorForMostlyReadOnlyData ()
171- {
172- return getDefaultDataAllocator (eMemoryLocationHint::HostAndDeviceMostlyRead);
173- }
174-
175- /* ---------------------------------------------------------------------------*/
176- /* ---------------------------------------------------------------------------*/
177-
178- IMemoryAllocator* MemoryUtils::
179- getAcceleratorHostMemoryAllocator ()
180- {
181- return global_accelerator_host_memory_allocator;
182- }
183-
184- /* ---------------------------------------------------------------------------*/
185- /* ---------------------------------------------------------------------------*/
186-
187- IMemoryAllocator* MemoryUtils::
188- setAcceleratorHostMemoryAllocator (IMemoryAllocator* a)
189- {
190- IMemoryAllocator* old = global_accelerator_host_memory_allocator;
191- global_accelerator_host_memory_allocator = a;
192- return old;
193- }
194-
195- /* ---------------------------------------------------------------------------*/
196- /* ---------------------------------------------------------------------------*/
197-
19841Int64 MemoryUtils::impl::
19942computeCapacity (Int64 size)
20043{
@@ -210,17 +53,6 @@ computeCapacity(Int64 size)
21053/* ---------------------------------------------------------------------------*/
21154/* ---------------------------------------------------------------------------*/
21255
213- void MemoryUtils::
214- copy (MutableMemoryView destination, eMemoryRessource destination_mem,
215- ConstMemoryView source, eMemoryRessource source_mem, const RunQueue* queue)
216- {
217- IMemoryRessourceMng* mrm = getDataMemoryResourceMng ();
218- mrm->_internal ()->copy (source, destination_mem, destination, source_mem, queue);
219- }
220-
221- /* ---------------------------------------------------------------------------*/
222- /* ---------------------------------------------------------------------------*/
223-
22456} // End namespace Arcane
22557
22658/* ---------------------------------------------------------------------------*/
0 commit comments