Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MemoryResourceMng.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/* MemoryResourceMng.h (C) 2000-2025 */
9/* */
10/* Memory resource management for CPUs and accelerators. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_INTERNAL_MEMORYRESOURCEMNG_H
13#define ARCCORE_COMMON_INTERNAL_MEMORYRESOURCEMNG_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/base/FixedArray.h"
18
19#include "arccore/common/IMemoryResourceMng.h"
20#include "arccore/common/internal/IMemoryResourceMngInternal.h"
21
22#include <memory>
23#include <array>
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
37class ARCCORE_COMMON_EXPORT MemoryResourceMng
38: public IMemoryResourceMng
40{
41 public:
42
43 MemoryResourceMng();
44
45 public:
46
48 IMemoryAllocator* getAllocator(eMemoryResource r, bool throw_if_not_found) override;
50
51 public:
52
53 void copy(ConstMemoryView from, eMemoryResource from_mem,
54 MutableMemoryView to, eMemoryResource to_mem, const RunQueue* queue) override;
55
56 public:
57
58 void setAllocator(eMemoryResource r, IMemoryAllocator* allocator) override;
59 void setMemoryPool(eMemoryResource r, IMemoryPool* pool) override;
60 void setCopier(IMemoryCopier* copier) override { m_copier = copier; }
61 void setIsAccelerator(bool v) override { m_is_accelerator = v; }
62
63 public:
64
66 IMemoryResourceMngInternal* _internal() override { return this; }
67
68 public:
69
71 static void genericCopy(ConstMemoryView from, MutableMemoryView to);
72
73 private:
74
79 std::unique_ptr<IMemoryCopier> m_default_memory_copier;
80 IMemoryCopier* m_copier = nullptr;
81 bool m_is_accelerator = false;
82
83 private:
84
85 inline int _checkValidResource(eMemoryResource r);
86};
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
91} // End namespace Arcane
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96#endif
Constant view on a contiguous memory region containing fixed-size elements.
Interface for memory copies with accelerator support.
Interface of a memory pool.
Definition IMemoryPool.h:32
Internal part of Arcane's 'IMemoryResourceMng'.
Memory resource management for CPUs and accelerators.
FixedArray< IMemoryPool *, ARCCORE_NB_MEMORY_RESOURCE > m_memory_pools
List of memory pools.
void setAllocator(eMemoryResource r, IMemoryAllocator *allocator) override
Sets the allocator for resource r.
void setIsAccelerator(bool v) override
Indicates if an accelerator is available.
FixedArray< IMemoryAllocator *, ARCCORE_NB_MEMORY_RESOURCE > m_allocators
List of allocators.
IMemoryPool * getMemoryPoolOrNull(eMemoryResource r) override
Memory pool for resource r.
IMemoryAllocator * getAllocator(eMemoryResource r) override
Memory allocator for resource r.
void setCopier(IMemoryCopier *copier) override
Sets the copying instance.
void setMemoryPool(eMemoryResource r, IMemoryPool *pool) override
Sets the memory pool for resource r.
IMemoryResourceMngInternal * _internal() override
Internal interface.
Mutable view on a contiguous memory region containing fixed-size elements.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
eMemoryResource
List of available memory resources.