14#include "arcane/accelerator/hip/HipAccelerator.h"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/Array.h"
18#include "arcane/utils/TraceInfo.h"
19#include "arcane/utils/NotSupportedException.h"
20#include "arcane/utils/FatalErrorException.h"
21#include "arcane/utils/IMemoryAllocator.h"
25namespace Arcane::Accelerator::Hip
28using namespace Arccore;
34arcaneCheckHipErrors(
const TraceInfo& ti,hipError_t e)
37 ARCANE_FATAL(
"HIP Error trace={0} e={1} str={2}",ti,e,hipGetErrorString(e));
42arcaneCheckHipErrorsNoThrow(
const TraceInfo& ti,hipError_t e)
46 String str = String::format(
"HIP Error trace={0} e={1} str={2}",ti,e,hipGetErrorString(e));
48 ex.explain(std::cerr);
56class HipMemoryAllocatorBase
57:
public Arccore::AlignedMemoryAllocator3
61 HipMemoryAllocatorBase()
62 : AlignedMemoryAllocator3(128)
69 ARCANE_CHECK_HIP(_allocate(&out, new_size, args));
70 Int64 a =
reinterpret_cast<Int64
>(out);
72 ARCANE_FATAL(
"Bad alignment for HIP allocator: offset={0}", (a % 128));
73 return { out, new_size };
78 ARCANE_CHECK_HIP(hipMemcpy(a.baseAddress(), current_ptr.
baseAddress(), current_ptr.
size(), hipMemcpyDefault));
79 deallocate(args, current_ptr);
84 ARCANE_CHECK_HIP_NOTHROW(_deallocate(ptr.
baseAddress(), args));
97:
public HipMemoryAllocatorBase
103 return ::hipMallocManaged(ptr, new_size, hipMemAttachGlobal);
107 return ::hipFree(ptr);
116:
public HipMemoryAllocatorBase
122 return ::hipHostMalloc(ptr, new_size);
126 return ::hipHostFree(ptr);
135:
public HipMemoryAllocatorBase
141 return ::hipMalloc(ptr, new_size);
145 return ::hipFree(ptr);
155 UnifiedMemoryHipMemoryAllocator unified_memory_hip_memory_allocator;
156 HostPinnedHipMemoryAllocator host_pinned_hip_memory_allocator;
157 DeviceHipMemoryAllocator device_hip_memory_allocator;
164getHipMemoryAllocator()
166 return &unified_memory_hip_memory_allocator;
170getHipDeviceMemoryAllocator()
172 return &device_hip_memory_allocator;
176getHipUnifiedMemoryAllocator()
178 return &unified_memory_hip_memory_allocator;
182getHipHostPinnedMemoryAllocator()
184 return &host_pinned_hip_memory_allocator;
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
eMemoryResource memoryResource() const override
Ressource mémoire fournie par l'allocateur.
eMemoryResource memoryResource() const override
Ressource mémoire fournie par l'allocateur.
eMemoryResource memoryResource() const override
Ressource mémoire fournie par l'allocateur.
Informations sur une zone mémoire allouée.
void * baseAddress() const
Adresse du début de la zone allouée.
Int64 size() const
Taille en octets de la zone mémoire utilisée. (-1) si inconnue.
Exception lorsqu'une erreur fatale est survenue.
Interface d'un allocateur pour la mémoire.
Classe contenant des informations pour spécialiser les allocations.
Chaîne de caractères unicode.
eMemoryResource
Liste des ressources mémoire disponibles.
@ HostPinned
Alloue sur l'hôte.
@ UnifiedMemory
Alloue en utilisant la mémoire unifiée.
@ Device
Alloue sur le device.