14#include "arcane/accelerator/sycl/SyclAccelerator.h"
15#include "arcane/accelerator/sycl/internal/SyclAcceleratorInternal.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/Array.h"
19#include "arcane/utils/TraceInfo.h"
20#include "arcane/utils/NotSupportedException.h"
21#include "arcane/utils/FatalErrorException.h"
22#include "arcane/utils/IMemoryAllocator.h"
26namespace Arcane::Accelerator::Sycl
29using namespace Arccore;
34std::unique_ptr<sycl::queue> global_default_queue;
37 sycl::queue& _defaultQueue()
39 return *global_default_queue;
48class SyclMemoryAllocatorBase
49:
public Arccore::AlignedMemoryAllocator3
53 SyclMemoryAllocatorBase()
54 : AlignedMemoryAllocator3(128)
60 sycl::queue& q = _defaultQueue();
62 _allocate(&out, new_size, args, q);
64 ARCANE_FATAL(
"Can not allocate memory size={0}", new_size);
65 Int64 a =
reinterpret_cast<Int64
>(out);
67 ARCANE_FATAL(
"Bad alignment for SYCL allocator: offset={0}", (a % 128));
68 return { out, new_size };
72 sycl::queue& q = _defaultQueue();
74 q.submit([&](sycl::handler& cgh) {
75 cgh.memcpy(a.baseAddress(), current_ptr.
baseAddress(), current_ptr.
size());
79 deallocate(args, current_ptr);
84 sycl::queue& q = _defaultQueue();
98:
public SyclMemoryAllocatorBase
104 *ptr = sycl::malloc_shared(new_size, q);
117:
public SyclMemoryAllocatorBase
124 *ptr = sycl::malloc_host(new_size, q);
137:
public SyclMemoryAllocatorBase
143 *ptr = sycl::malloc_device(new_size, q);
157 UnifiedMemorySyclMemoryAllocator unified_memory_sycl_memory_allocator;
158 HostPinnedSyclMemoryAllocator host_pinned_sycl_memory_allocator;
159 DeviceSyclMemoryAllocator device_sycl_memory_allocator;
174getSyclMemoryAllocator()
176 return &unified_memory_sycl_memory_allocator;
179Arccore::IMemoryAllocator* Sycl::
180getSyclDeviceMemoryAllocator()
182 return &device_sycl_memory_allocator;
185Arccore::IMemoryAllocator* Sycl::
186getSyclUnifiedMemoryAllocator()
188 return &unified_memory_sycl_memory_allocator;
191Arccore::IMemoryAllocator* Sycl::
192getSyclHostPinnedMemoryAllocator()
194 return &host_pinned_sycl_memory_allocator;
201setSyclMemoryQueue(
const sycl::queue& memory_queue)
203 global_default_queue = std::make_unique<sycl::queue>(memory_queue);
#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.
Interface d'un allocateur pour la mémoire.
Classe contenant des informations pour spécialiser les allocations.
Espace de nom pour l'utilisation des accélérateurs.
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.