17 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18 #include <Kokkos_Macros.hpp>
20 "Including non-public Kokkos header files is not allowed.");
22 #ifndef KOKKOS_SYCLSPACE_HPP
23 #define KOKKOS_SYCLSPACE_HPP
25 #include <Kokkos_Core_fwd.hpp>
27 #ifdef KOKKOS_ENABLE_SYCL
28 #include <Kokkos_Concepts.hpp>
29 #include <Kokkos_HostSpace.hpp>
30 #include <Kokkos_ScratchSpace.hpp>
31 #include <SYCL/Kokkos_SYCL_Instance.hpp>
32 #include <impl/Kokkos_SharedAlloc.hpp>
33 #include <impl/Kokkos_Tools.hpp>
39 struct is_sycl_type_space :
public std::false_type {};
42 namespace Experimental {
44 class SYCLDeviceUSMSpace {
46 using execution_space = SYCL;
47 using memory_space = SYCLDeviceUSMSpace;
48 using device_type = Kokkos::Device<execution_space, memory_space>;
49 using size_type = Impl::SYCLInternal::size_type;
52 explicit SYCLDeviceUSMSpace(sycl::queue queue);
54 void* allocate(
const SYCL& exec_space,
55 const std::size_t arg_alloc_size)
const;
56 void* allocate(
const SYCL& exec_space,
const char* arg_label,
57 const size_t arg_alloc_size,
58 const size_t arg_logical_size = 0)
const;
59 void* allocate(
const std::size_t arg_alloc_size)
const;
60 void* allocate(
const char* arg_label,
const size_t arg_alloc_size,
61 const size_t arg_logical_size = 0)
const;
63 void deallocate(
void*
const arg_alloc_ptr,
64 const std::size_t arg_alloc_size)
const;
65 void deallocate(
const char* arg_label,
void*
const arg_alloc_ptr,
66 const size_t arg_alloc_size,
67 const size_t arg_logical_size = 0)
const;
70 template <
class,
class,
class,
class>
71 friend class LogicalMemorySpace;
74 static constexpr
const char* name() {
return "SYCLDeviceUSM"; };
80 class SYCLSharedUSMSpace {
82 using execution_space = SYCL;
83 using memory_space = SYCLSharedUSMSpace;
84 using device_type = Kokkos::Device<execution_space, memory_space>;
85 using size_type = Impl::SYCLInternal::size_type;
88 explicit SYCLSharedUSMSpace(sycl::queue queue);
90 void* allocate(
const SYCL& exec_space,
91 const std::size_t arg_alloc_size)
const;
92 void* allocate(
const SYCL& exec_space,
const char* arg_label,
93 const size_t arg_alloc_size,
94 const size_t arg_logical_size = 0)
const;
95 void* allocate(
const std::size_t arg_alloc_size)
const;
96 void* allocate(
const char* arg_label,
const size_t arg_alloc_size,
97 const size_t arg_logical_size = 0)
const;
99 void deallocate(
void*
const arg_alloc_ptr,
100 const std::size_t arg_alloc_size)
const;
101 void deallocate(
const char* arg_label,
void*
const arg_alloc_ptr,
102 const size_t arg_alloc_size,
103 const size_t arg_logical_size = 0)
const;
106 template <
class,
class,
class,
class>
107 friend class LogicalMemorySpace;
110 static constexpr
const char* name() {
return "SYCLSharedUSM"; };
116 class SYCLHostUSMSpace {
119 using memory_space = SYCLHostUSMSpace;
120 using device_type = Kokkos::Device<execution_space, memory_space>;
121 using size_type = Impl::SYCLInternal::size_type;
124 explicit SYCLHostUSMSpace(sycl::queue queue);
126 void* allocate(
const SYCL& exec_space,
127 const std::size_t arg_alloc_size)
const;
128 void* allocate(
const SYCL& exec_space,
const char* arg_label,
129 const size_t arg_alloc_size,
130 const size_t arg_logical_size = 0)
const;
131 void* allocate(
const std::size_t arg_alloc_size)
const;
132 void* allocate(
const char* arg_label,
const size_t arg_alloc_size,
133 const size_t arg_logical_size = 0)
const;
135 void deallocate(
void*
const arg_alloc_ptr,
136 const std::size_t arg_alloc_size)
const;
137 void deallocate(
const char* arg_label,
void*
const arg_alloc_ptr,
138 const size_t arg_alloc_size,
139 const size_t arg_logical_size = 0)
const;
142 template <
class,
class,
class,
class>
143 friend class LogicalMemorySpace;
146 static constexpr
const char* name() {
return "SYCLHostUSM"; };
157 struct is_sycl_type_space<Kokkos::Experimental::SYCLDeviceUSMSpace>
158 :
public std::true_type {};
161 struct is_sycl_type_space<Kokkos::Experimental::SYCLSharedUSMSpace>
162 :
public std::true_type {};
165 struct is_sycl_type_space<Kokkos::Experimental::SYCLHostUSMSpace>
166 :
public std::true_type {};
169 Kokkos::Experimental::SYCLDeviceUSMSpace,
170 Kokkos::Experimental::SYCLDeviceUSMSpace>::assignable,
174 Kokkos::Experimental::SYCLSharedUSMSpace,
175 Kokkos::Experimental::SYCLSharedUSMSpace>::assignable,
179 Kokkos::Experimental::SYCLDeviceUSMSpace,
180 Kokkos::Experimental::SYCLDeviceUSMSpace>::assignable,
184 struct MemorySpaceAccess<Kokkos::HostSpace,
185 Kokkos::Experimental::SYCLDeviceUSMSpace> {
186 enum :
bool { assignable =
false };
187 enum :
bool { accessible =
false };
188 enum :
bool { deepcopy =
true };
192 struct MemorySpaceAccess<Kokkos::HostSpace,
193 Kokkos::Experimental::SYCLSharedUSMSpace> {
195 enum :
bool { assignable =
false };
196 enum :
bool { accessible =
true };
197 enum :
bool { deepcopy =
true };
201 struct MemorySpaceAccess<Kokkos::HostSpace,
202 Kokkos::Experimental::SYCLHostUSMSpace> {
205 enum :
bool { assignable =
true };
206 enum :
bool { accessible =
true };
207 enum :
bool { deepcopy =
true };
211 struct MemorySpaceAccess<Kokkos::Experimental::SYCLDeviceUSMSpace,
213 enum :
bool { assignable =
false };
214 enum :
bool { accessible =
false };
215 enum :
bool { deepcopy =
true };
219 struct MemorySpaceAccess<Kokkos::Experimental::SYCLDeviceUSMSpace,
220 Kokkos::Experimental::SYCLSharedUSMSpace> {
222 enum :
bool { assignable =
true };
223 enum :
bool { accessible =
true };
224 enum :
bool { deepcopy =
true };
228 struct MemorySpaceAccess<Kokkos::Experimental::SYCLDeviceUSMSpace,
229 Kokkos::Experimental::SYCLHostUSMSpace> {
232 enum :
bool { assignable =
false };
236 enum :
bool { deepcopy =
true };
244 struct MemorySpaceAccess<Kokkos::Experimental::SYCLSharedUSMSpace,
246 enum :
bool { assignable =
false };
247 enum :
bool { accessible =
false };
248 enum :
bool { deepcopy =
true };
252 struct MemorySpaceAccess<Kokkos::Experimental::SYCLSharedUSMSpace,
253 Kokkos::Experimental::SYCLDeviceUSMSpace> {
257 enum :
bool { assignable =
false };
260 enum :
bool { accessible =
true };
261 enum :
bool { deepcopy =
true };
265 struct MemorySpaceAccess<Kokkos::Experimental::SYCLSharedUSMSpace,
266 Kokkos::Experimental::SYCLHostUSMSpace> {
269 enum :
bool { assignable =
false };
273 enum :
bool { deepcopy =
true };
277 struct MemorySpaceAccess<Kokkos::Experimental::SYCLHostUSMSpace,
279 enum :
bool { assignable =
false };
283 enum :
bool { deepcopy =
true };
287 struct MemorySpaceAccess<Kokkos::Experimental::SYCLHostUSMSpace,
288 Kokkos::Experimental::SYCLDeviceUSMSpace> {
289 enum :
bool { assignable =
false };
290 enum :
bool { accessible =
false };
291 enum :
bool { deepcopy =
true };
295 struct MemorySpaceAccess<Kokkos::Experimental::SYCLHostUSMSpace,
296 Kokkos::Experimental::SYCLSharedUSMSpace> {
297 enum :
bool { assignable =
false };
298 enum :
bool { accessible =
true };
299 enum :
bool { deepcopy =
true };
303 struct MemorySpaceAccess<
304 Kokkos::Experimental::SYCLDeviceUSMSpace,
306 enum :
bool { assignable =
false };
307 enum :
bool { accessible =
true };
308 enum :
bool { deepcopy =
false };
316 class SharedAllocationRecord<Kokkos::Experimental::SYCLDeviceUSMSpace, void>
317 :
public HostInaccessibleSharedAllocationRecordCommon<
318 Kokkos::Experimental::SYCLDeviceUSMSpace> {
320 friend class SharedAllocationRecordCommon<
321 Kokkos::Experimental::SYCLDeviceUSMSpace>;
322 friend class HostInaccessibleSharedAllocationRecordCommon<
323 Kokkos::Experimental::SYCLDeviceUSMSpace>;
324 using base_t = HostInaccessibleSharedAllocationRecordCommon<
325 Kokkos::Experimental::SYCLDeviceUSMSpace>;
326 using RecordBase = SharedAllocationRecord<void, void>;
328 SharedAllocationRecord(const SharedAllocationRecord&) = delete;
329 SharedAllocationRecord(SharedAllocationRecord&&) = delete;
330 SharedAllocationRecord& operator=(const SharedAllocationRecord&) = delete;
331 SharedAllocationRecord& operator=(SharedAllocationRecord&&) = delete;
333 #ifdef KOKKOS_ENABLE_DEBUG
334 static RecordBase s_root_record;
337 const Kokkos::Experimental::SYCLDeviceUSMSpace m_space;
340 ~SharedAllocationRecord();
342 template <typename ExecutionSpace>
343 SharedAllocationRecord(
344 const ExecutionSpace& ,
345 const Kokkos::Experimental::SYCLDeviceUSMSpace& arg_space,
346 const std::string& arg_label, const size_t arg_alloc_size,
347 const RecordBase::function_type arg_dealloc = &base_t::deallocate)
348 : SharedAllocationRecord(arg_space, arg_label, arg_alloc_size,
351 SharedAllocationRecord(
352 const Kokkos::Experimental::SYCL& exec_space,
353 const Kokkos::Experimental::SYCLDeviceUSMSpace& arg_space,
354 const std::string& arg_label,
const size_t arg_alloc_size,
355 const RecordBase::function_type arg_dealloc = &base_t::deallocate);
357 SharedAllocationRecord(
358 const Kokkos::Experimental::SYCLDeviceUSMSpace& arg_space,
359 const std::string& arg_label,
const size_t arg_alloc_size,
360 const RecordBase::function_type arg_dealloc = &base_t::deallocate);
364 class SharedAllocationRecord<Kokkos::Experimental::SYCLSharedUSMSpace, void>
365 :
public SharedAllocationRecordCommon<
366 Kokkos::Experimental::SYCLSharedUSMSpace> {
368 friend class SharedAllocationRecordCommon<
369 Kokkos::Experimental::SYCLSharedUSMSpace>;
371 SharedAllocationRecordCommon<Kokkos::Experimental::SYCLSharedUSMSpace>;
372 using RecordBase = SharedAllocationRecord<void, void>;
374 SharedAllocationRecord(const SharedAllocationRecord&) = delete;
375 SharedAllocationRecord(SharedAllocationRecord&&) = delete;
376 SharedAllocationRecord& operator=(const SharedAllocationRecord&) = delete;
377 SharedAllocationRecord& operator=(SharedAllocationRecord&&) = delete;
379 static RecordBase s_root_record;
381 const Kokkos::Experimental::SYCLSharedUSMSpace m_space;
384 ~SharedAllocationRecord();
386 SharedAllocationRecord() = default;
388 template <typename ExecutionSpace>
389 SharedAllocationRecord(
390 const ExecutionSpace& ,
391 const Kokkos::Experimental::SYCLSharedUSMSpace& arg_space,
392 const std::string& arg_label, const size_t arg_alloc_size,
393 const RecordBase::function_type arg_dealloc = &base_t::deallocate)
394 : SharedAllocationRecord(arg_space, arg_label, arg_alloc_size,
397 SharedAllocationRecord(
398 const Kokkos::Experimental::SYCL& exec_space,
399 const Kokkos::Experimental::SYCLSharedUSMSpace& arg_space,
400 const std::string& arg_label,
const size_t arg_alloc_size,
401 const RecordBase::function_type arg_dealloc = &base_t::deallocate);
403 SharedAllocationRecord(
404 const Kokkos::Experimental::SYCLSharedUSMSpace& arg_space,
405 const std::string& arg_label,
const size_t arg_alloc_size,
406 const RecordBase::function_type arg_dealloc = &base_t::deallocate);
410 class SharedAllocationRecord<Kokkos::Experimental::SYCLHostUSMSpace, void>
411 :
public SharedAllocationRecordCommon<
412 Kokkos::Experimental::SYCLHostUSMSpace> {
414 friend class SharedAllocationRecordCommon<
415 Kokkos::Experimental::SYCLHostUSMSpace>;
417 SharedAllocationRecordCommon<Kokkos::Experimental::SYCLHostUSMSpace>;
418 using RecordBase = SharedAllocationRecord<void, void>;
420 SharedAllocationRecord(const SharedAllocationRecord&) = delete;
421 SharedAllocationRecord(SharedAllocationRecord&&) = delete;
422 SharedAllocationRecord& operator=(const SharedAllocationRecord&) = delete;
423 SharedAllocationRecord& operator=(SharedAllocationRecord&&) = delete;
425 static RecordBase s_root_record;
427 const Kokkos::Experimental::SYCLHostUSMSpace m_space;
430 ~SharedAllocationRecord();
432 SharedAllocationRecord() = default;
434 template <typename ExecutionSpace>
435 SharedAllocationRecord(
436 const ExecutionSpace& ,
437 const Kokkos::Experimental::SYCLHostUSMSpace& arg_space,
438 const std::string& arg_label, const size_t arg_alloc_size,
439 const RecordBase::function_type arg_dealloc = &base_t::deallocate)
440 : SharedAllocationRecord(arg_space, arg_label, arg_alloc_size,
443 SharedAllocationRecord(
444 const Kokkos::Experimental::SYCL& exec_space,
445 const Kokkos::Experimental::SYCLHostUSMSpace& arg_space,
446 const std::string& arg_label,
const size_t arg_alloc_size,
447 const RecordBase::function_type arg_dealloc = &base_t::deallocate);
449 SharedAllocationRecord(
450 const Kokkos::Experimental::SYCLHostUSMSpace& arg_space,
451 const std::string& arg_label,
const size_t arg_alloc_size,
452 const RecordBase::function_type arg_dealloc = &base_t::deallocate);
Scratch memory space associated with an execution space.
Memory management for host memory.
DefaultHostExecutionSpace execution_space
Default execution space for this memory space.
Access relationship between DstMemorySpace and SrcMemorySpace.