forked from kokkos/kokkos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kokkos_CudaSpace.hpp
720 lines (582 loc) · 25.4 KB
/
Kokkos_CudaSpace.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
#include <Kokkos_Macros.hpp>
static_assert(false,
"Including non-public Kokkos header files is not allowed.");
#endif
#ifndef KOKKOS_CUDASPACE_HPP
#define KOKKOS_CUDASPACE_HPP
#include <Kokkos_Macros.hpp>
#if defined(KOKKOS_ENABLE_CUDA)
#include <Kokkos_Core_fwd.hpp>
#include <iosfwd>
#include <typeinfo>
#include <string>
#include <memory>
#include <Kokkos_HostSpace.hpp>
#include <impl/Kokkos_SharedAlloc.hpp>
#include <impl/Kokkos_Profiling_Interface.hpp>
#include <Cuda/Kokkos_Cuda_abort.hpp>
#ifdef KOKKOS_IMPL_DEBUG_CUDA_PIN_UVM_TO_HOST
extern "C" bool kokkos_impl_cuda_pin_uvm_to_host();
extern "C" void kokkos_impl_cuda_set_pin_uvm_to_host(bool);
#endif
/*--------------------------------------------------------------------------*/
namespace Kokkos {
namespace Impl {
template <typename T>
struct is_cuda_type_space : public std::false_type {};
} // namespace Impl
/** \brief Cuda on-device memory management */
class CudaSpace {
public:
//! Tag this class as a kokkos memory space
using memory_space = CudaSpace;
using execution_space = Kokkos::Cuda;
using device_type = Kokkos::Device<execution_space, memory_space>;
using size_type = unsigned int;
/*--------------------------------*/
CudaSpace();
private:
CudaSpace(int device_id, cudaStream_t stream);
public:
CudaSpace(CudaSpace&& rhs) = default;
CudaSpace(const CudaSpace& rhs) = default;
CudaSpace& operator=(CudaSpace&& rhs) = default;
CudaSpace& operator=(const CudaSpace& rhs) = default;
~CudaSpace() = default;
/**\brief Allocate untracked memory in the cuda space */
void* allocate(const Cuda& exec_space, const size_t arg_alloc_size) const;
void* allocate(const Cuda& exec_space, const char* arg_label,
const size_t arg_alloc_size,
const size_t arg_logical_size = 0) const;
void* allocate(const size_t arg_alloc_size) const;
void* allocate(const char* arg_label, const size_t arg_alloc_size,
const size_t arg_logical_size = 0) const;
/**\brief Deallocate untracked memory in the cuda space */
void deallocate(void* const arg_alloc_ptr, const size_t arg_alloc_size) const;
void deallocate(const char* arg_label, void* const arg_alloc_ptr,
const size_t arg_alloc_size,
const size_t arg_logical_size = 0) const;
static CudaSpace impl_create(int device_id, cudaStream_t stream) {
return CudaSpace(device_id, stream);
}
private:
void* impl_allocate(const Cuda& exec_space, const char* arg_label,
const size_t arg_alloc_size,
const size_t arg_logical_size = 0,
const Kokkos::Tools::SpaceHandle =
Kokkos::Tools::make_space_handle(name())) const;
void* impl_allocate(const char* arg_label, const size_t arg_alloc_size,
const size_t arg_logical_size = 0,
const Kokkos::Tools::SpaceHandle =
Kokkos::Tools::make_space_handle(name())) const;
void impl_deallocate(const char* arg_label, void* const arg_alloc_ptr,
const size_t arg_alloc_size,
const size_t arg_logical_size = 0,
const Kokkos::Tools::SpaceHandle =
Kokkos::Tools::make_space_handle(name())) const;
public:
/**\brief Return Name of the MemorySpace */
static constexpr const char* name() { return m_name; }
private:
int m_device;
cudaStream_t m_stream;
static constexpr const char* m_name = "Cuda";
friend class Kokkos::Impl::SharedAllocationRecord<Kokkos::CudaSpace, void>;
};
template <>
struct Impl::is_cuda_type_space<CudaSpace> : public std::true_type {};
} // namespace Kokkos
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace Kokkos {
/** \brief Cuda memory that is accessible to Host execution space
* through Cuda's unified virtual memory (UVM) runtime.
*/
class CudaUVMSpace {
public:
//! Tag this class as a kokkos memory space
using memory_space = CudaUVMSpace;
using execution_space = Cuda;
using device_type = Kokkos::Device<execution_space, memory_space>;
using size_type = unsigned int;
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
/** \brief If UVM capability is available */
KOKKOS_DEPRECATED static bool available();
#endif
/*--------------------------------*/
/*--------------------------------*/
CudaUVMSpace();
private:
CudaUVMSpace(int device_id, cudaStream_t stream);
public:
CudaUVMSpace(CudaUVMSpace&& rhs) = default;
CudaUVMSpace(const CudaUVMSpace& rhs) = default;
CudaUVMSpace& operator=(CudaUVMSpace&& rhs) = default;
CudaUVMSpace& operator=(const CudaUVMSpace& rhs) = default;
~CudaUVMSpace() = default;
/**\brief Allocate untracked memory in the cuda space */
void* allocate(const size_t arg_alloc_size) const;
void* allocate(const char* arg_label, const size_t arg_alloc_size,
const size_t arg_logical_size = 0) const;
/**\brief Deallocate untracked memory in the cuda space */
void deallocate(void* const arg_alloc_ptr, const size_t arg_alloc_size) const;
void deallocate(const char* arg_label, void* const arg_alloc_ptr,
const size_t arg_alloc_size,
const size_t arg_logical_size = 0) const;
private:
void* impl_allocate(const char* arg_label, const size_t arg_alloc_size,
const size_t arg_logical_size = 0,
const Kokkos::Tools::SpaceHandle =
Kokkos::Tools::make_space_handle(name())) const;
void impl_deallocate(const char* arg_label, void* const arg_alloc_ptr,
const size_t arg_alloc_size,
const size_t arg_logical_size = 0,
const Kokkos::Tools::SpaceHandle =
Kokkos::Tools::make_space_handle(name())) const;
public:
/**\brief Return Name of the MemorySpace */
static constexpr const char* name() { return m_name; }
#ifdef KOKKOS_IMPL_DEBUG_CUDA_PIN_UVM_TO_HOST
static bool cuda_pin_uvm_to_host();
static void cuda_set_pin_uvm_to_host(bool val);
#endif
/*--------------------------------*/
static CudaUVMSpace impl_create(int device_id, cudaStream_t stream) {
return CudaUVMSpace(device_id, stream);
}
private:
int m_device;
cudaStream_t m_stream;
#ifdef KOKKOS_IMPL_DEBUG_CUDA_PIN_UVM_TO_HOST
static bool kokkos_impl_cuda_pin_uvm_to_host_v;
#endif
static constexpr const char* m_name = "CudaUVM";
};
template <>
struct Impl::is_cuda_type_space<CudaUVMSpace> : public std::true_type {};
} // namespace Kokkos
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace Kokkos {
/** \brief Host memory that is accessible to Cuda execution space
* through Cuda's host-pinned memory allocation.
*/
class CudaHostPinnedSpace {
public:
//! Tag this class as a kokkos memory space
/** \brief Memory is in HostSpace so use the HostSpace::execution_space */
using execution_space = HostSpace::execution_space;
using memory_space = CudaHostPinnedSpace;
using device_type = Kokkos::Device<execution_space, memory_space>;
using size_type = unsigned int;
/*--------------------------------*/
CudaHostPinnedSpace();
private:
CudaHostPinnedSpace(int device_id, cudaStream_t stream);
public:
CudaHostPinnedSpace(CudaHostPinnedSpace&& rhs) = default;
CudaHostPinnedSpace(const CudaHostPinnedSpace& rhs) = default;
CudaHostPinnedSpace& operator=(CudaHostPinnedSpace&& rhs) = default;
CudaHostPinnedSpace& operator=(const CudaHostPinnedSpace& rhs) = default;
~CudaHostPinnedSpace() = default;
/**\brief Allocate untracked memory in the space */
void* allocate(const size_t arg_alloc_size) const;
void* allocate(const char* arg_label, const size_t arg_alloc_size,
const size_t arg_logical_size = 0) const;
/**\brief Deallocate untracked memory in the space */
void deallocate(void* const arg_alloc_ptr, const size_t arg_alloc_size) const;
void deallocate(const char* arg_label, void* const arg_alloc_ptr,
const size_t arg_alloc_size,
const size_t arg_logical_size = 0) const;
static CudaHostPinnedSpace impl_create(int device_id, cudaStream_t stream) {
return CudaHostPinnedSpace(device_id, stream);
}
private:
void* impl_allocate(const char* arg_label, const size_t arg_alloc_size,
const size_t arg_logical_size = 0,
const Kokkos::Tools::SpaceHandle =
Kokkos::Tools::make_space_handle(name())) const;
void impl_deallocate(const char* arg_label, void* const arg_alloc_ptr,
const size_t arg_alloc_size,
const size_t arg_logical_size = 0,
const Kokkos::Tools::SpaceHandle =
Kokkos::Tools::make_space_handle(name())) const;
public:
/**\brief Return Name of the MemorySpace */
static constexpr const char* name() { return m_name; }
private:
int m_device;
cudaStream_t m_stream;
static constexpr const char* m_name = "CudaHostPinned";
/*--------------------------------*/
};
template <>
struct Impl::is_cuda_type_space<CudaHostPinnedSpace> : public std::true_type {};
} // namespace Kokkos
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace Kokkos {
namespace Impl {
cudaStream_t cuda_get_deep_copy_stream();
const std::unique_ptr<Kokkos::Cuda>& cuda_get_deep_copy_space(
bool initialize = true);
static_assert(Kokkos::Impl::MemorySpaceAccess<Kokkos::CudaSpace,
Kokkos::CudaSpace>::assignable);
static_assert(Kokkos::Impl::MemorySpaceAccess<
Kokkos::CudaUVMSpace, Kokkos::CudaUVMSpace>::assignable);
static_assert(
Kokkos::Impl::MemorySpaceAccess<Kokkos::CudaHostPinnedSpace,
Kokkos::CudaHostPinnedSpace>::assignable);
//----------------------------------------
template <>
struct MemorySpaceAccess<Kokkos::HostSpace, Kokkos::CudaSpace> {
enum : bool { assignable = false };
enum : bool { accessible = false };
enum : bool { deepcopy = true };
};
template <>
struct MemorySpaceAccess<Kokkos::HostSpace, Kokkos::CudaUVMSpace> {
// HostSpace::execution_space != CudaUVMSpace::execution_space
enum : bool { assignable = false };
enum : bool { accessible = true };
enum : bool { deepcopy = true };
};
template <>
struct MemorySpaceAccess<Kokkos::HostSpace, Kokkos::CudaHostPinnedSpace> {
// HostSpace::execution_space == CudaHostPinnedSpace::execution_space
enum : bool { assignable = true };
enum : bool { accessible = true };
enum : bool { deepcopy = true };
};
//----------------------------------------
template <>
struct MemorySpaceAccess<Kokkos::CudaSpace, Kokkos::HostSpace> {
enum : bool { assignable = false };
enum : bool { accessible = false };
enum : bool { deepcopy = true };
};
template <>
struct MemorySpaceAccess<Kokkos::CudaSpace, Kokkos::CudaUVMSpace> {
// CudaSpace::execution_space == CudaUVMSpace::execution_space
enum : bool { assignable = true };
enum : bool { accessible = true };
enum : bool { deepcopy = true };
};
template <>
struct MemorySpaceAccess<Kokkos::CudaSpace, Kokkos::CudaHostPinnedSpace> {
// CudaSpace::execution_space != CudaHostPinnedSpace::execution_space
enum : bool { assignable = false };
enum : bool { accessible = true }; // CudaSpace::execution_space
enum : bool { deepcopy = true };
};
//----------------------------------------
// CudaUVMSpace::execution_space == Cuda
// CudaUVMSpace accessible to both Cuda and Host
template <>
struct MemorySpaceAccess<Kokkos::CudaUVMSpace, Kokkos::HostSpace> {
enum : bool { assignable = false };
enum : bool { accessible = false }; // Cuda cannot access HostSpace
enum : bool { deepcopy = true };
};
template <>
struct MemorySpaceAccess<Kokkos::CudaUVMSpace, Kokkos::CudaSpace> {
// CudaUVMSpace::execution_space == CudaSpace::execution_space
// Can access CudaUVMSpace from Host but cannot access CudaSpace from Host
enum : bool { assignable = false };
// CudaUVMSpace::execution_space can access CudaSpace
enum : bool { accessible = true };
enum : bool { deepcopy = true };
};
template <>
struct MemorySpaceAccess<Kokkos::CudaUVMSpace, Kokkos::CudaHostPinnedSpace> {
// CudaUVMSpace::execution_space != CudaHostPinnedSpace::execution_space
enum : bool { assignable = false };
enum : bool { accessible = true }; // CudaUVMSpace::execution_space
enum : bool { deepcopy = true };
};
//----------------------------------------
// CudaHostPinnedSpace::execution_space == HostSpace::execution_space
// CudaHostPinnedSpace accessible to both Cuda and Host
template <>
struct MemorySpaceAccess<Kokkos::CudaHostPinnedSpace, Kokkos::HostSpace> {
enum : bool { assignable = false }; // Cannot access from Cuda
enum : bool { accessible = true }; // CudaHostPinnedSpace::execution_space
enum : bool { deepcopy = true };
};
template <>
struct MemorySpaceAccess<Kokkos::CudaHostPinnedSpace, Kokkos::CudaSpace> {
enum : bool { assignable = false }; // Cannot access from Host
enum : bool { accessible = false };
enum : bool { deepcopy = true };
};
template <>
struct MemorySpaceAccess<Kokkos::CudaHostPinnedSpace, Kokkos::CudaUVMSpace> {
enum : bool { assignable = false }; // different execution_space
enum : bool { accessible = true }; // same accessibility
enum : bool { deepcopy = true };
};
//----------------------------------------
} // namespace Impl
} // namespace Kokkos
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace Kokkos {
namespace Impl {
void DeepCopyCuda(void* dst, const void* src, size_t n);
void DeepCopyAsyncCuda(const Cuda& instance, void* dst, const void* src,
size_t n);
void DeepCopyAsyncCuda(void* dst, const void* src, size_t n);
template <class MemSpace>
struct DeepCopy<MemSpace, HostSpace, Cuda,
std::enable_if_t<is_cuda_type_space<MemSpace>::value>> {
DeepCopy(void* dst, const void* src, size_t n) { DeepCopyCuda(dst, src, n); }
DeepCopy(const Cuda& instance, void* dst, const void* src, size_t n) {
DeepCopyAsyncCuda(instance, dst, src, n);
}
};
template <class MemSpace>
struct DeepCopy<HostSpace, MemSpace, Cuda,
std::enable_if_t<is_cuda_type_space<MemSpace>::value>> {
DeepCopy(void* dst, const void* src, size_t n) { DeepCopyCuda(dst, src, n); }
DeepCopy(const Cuda& instance, void* dst, const void* src, size_t n) {
DeepCopyAsyncCuda(instance, dst, src, n);
}
};
template <class MemSpace1, class MemSpace2>
struct DeepCopy<MemSpace1, MemSpace2, Cuda,
std::enable_if_t<is_cuda_type_space<MemSpace1>::value &&
is_cuda_type_space<MemSpace2>::value>> {
DeepCopy(void* dst, const void* src, size_t n) { DeepCopyCuda(dst, src, n); }
DeepCopy(const Cuda& instance, void* dst, const void* src, size_t n) {
DeepCopyAsyncCuda(instance, dst, src, n);
}
};
template <class MemSpace1, class MemSpace2, class ExecutionSpace>
struct DeepCopy<MemSpace1, MemSpace2, ExecutionSpace,
std::enable_if_t<is_cuda_type_space<MemSpace1>::value &&
is_cuda_type_space<MemSpace2>::value &&
!std::is_same<ExecutionSpace, Cuda>::value>> {
inline DeepCopy(void* dst, const void* src, size_t n) {
DeepCopyCuda(dst, src, n);
}
inline DeepCopy(const ExecutionSpace& exec, void* dst, const void* src,
size_t n) {
exec.fence(fence_string());
DeepCopyAsyncCuda(dst, src, n);
}
private:
static const std::string& fence_string() {
static const std::string string =
std::string("Kokkos::Impl::DeepCopy<") + MemSpace1::name() + "Space, " +
MemSpace2::name() +
"Space, ExecutionSpace>::DeepCopy: fence before copy";
return string;
}
};
template <class MemSpace, class ExecutionSpace>
struct DeepCopy<MemSpace, HostSpace, ExecutionSpace,
std::enable_if_t<is_cuda_type_space<MemSpace>::value &&
!std::is_same<ExecutionSpace, Cuda>::value>> {
inline DeepCopy(void* dst, const void* src, size_t n) {
DeepCopyCuda(dst, src, n);
}
inline DeepCopy(const ExecutionSpace& exec, void* dst, const void* src,
size_t n) {
exec.fence(fence_string());
DeepCopyAsyncCuda(dst, src, n);
}
private:
static const std::string& fence_string() {
static const std::string string =
std::string("Kokkos::Impl::DeepCopy<") + MemSpace::name() +
"Space, HostSpace, ExecutionSpace>::DeepCopy: fence before copy";
return string;
}
};
template <class MemSpace, class ExecutionSpace>
struct DeepCopy<HostSpace, MemSpace, ExecutionSpace,
std::enable_if_t<is_cuda_type_space<MemSpace>::value &&
!std::is_same<ExecutionSpace, Cuda>::value>> {
inline DeepCopy(void* dst, const void* src, size_t n) {
DeepCopyCuda(dst, src, n);
}
inline DeepCopy(const ExecutionSpace& exec, void* dst, const void* src,
size_t n) {
exec.fence(fence_string());
DeepCopyAsyncCuda(dst, src, n);
}
private:
static const std::string& fence_string() {
static const std::string string =
std::string("Kokkos::Impl::DeepCopy<HostSpace, ") + MemSpace::name() +
"Space, ExecutionSpace>::DeepCopy: fence before copy";
return string;
}
};
} // namespace Impl
} // namespace Kokkos
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
namespace Kokkos {
namespace Impl {
template <>
class SharedAllocationRecord<Kokkos::CudaSpace, void>
: public HostInaccessibleSharedAllocationRecordCommon<Kokkos::CudaSpace> {
private:
friend class SharedAllocationRecord<Kokkos::CudaUVMSpace, void>;
friend class SharedAllocationRecordCommon<Kokkos::CudaSpace>;
friend class HostInaccessibleSharedAllocationRecordCommon<Kokkos::CudaSpace>;
using RecordBase = SharedAllocationRecord<void, void>;
using base_t =
HostInaccessibleSharedAllocationRecordCommon<Kokkos::CudaSpace>;
SharedAllocationRecord(const SharedAllocationRecord&) = delete;
SharedAllocationRecord& operator=(const SharedAllocationRecord&) = delete;
#ifdef KOKKOS_ENABLE_DEBUG
static RecordBase s_root_record;
#endif
const Kokkos::CudaSpace m_space;
protected:
~SharedAllocationRecord();
SharedAllocationRecord() = default;
// This constructor does not forward to the one without exec_space arg
// in order to work around https://github.com/kokkos/kokkos/issues/5258
// This constructor is templated so I can't just put it into the cpp file
// like the other constructor.
template <typename ExecutionSpace>
SharedAllocationRecord(
const ExecutionSpace& /*exec_space*/, const Kokkos::CudaSpace& arg_space,
const std::string& arg_label, const size_t arg_alloc_size,
const RecordBase::function_type arg_dealloc = &base_t::deallocate)
: base_t(
#ifdef KOKKOS_ENABLE_DEBUG
&SharedAllocationRecord<Kokkos::CudaSpace, void>::s_root_record,
#endif
Impl::checked_allocation_with_header(arg_space, arg_label,
arg_alloc_size),
sizeof(SharedAllocationHeader) + arg_alloc_size, arg_dealloc,
arg_label),
m_space(arg_space) {
SharedAllocationHeader header;
this->base_t::_fill_host_accessible_header_info(header, arg_label);
// Copy to device memory
// workaround for issue with NVCC and MSVC
// https://github.com/kokkos/kokkos/issues/5258
deep_copy_header_no_exec(RecordBase::m_alloc_ptr, &header);
}
SharedAllocationRecord(
const Kokkos::Cuda& exec_space, const Kokkos::CudaSpace& arg_space,
const std::string& arg_label, const size_t arg_alloc_size,
const RecordBase::function_type arg_dealloc = &base_t::deallocate);
SharedAllocationRecord(
const Kokkos::CudaSpace& arg_space, const std::string& arg_label,
const size_t arg_alloc_size,
const RecordBase::function_type arg_dealloc = &base_t::deallocate);
// helper function to work around MSVC+NVCC issue
// https://github.com/kokkos/kokkos/issues/5258
static void deep_copy_header_no_exec(void*, const void*);
};
template <>
class SharedAllocationRecord<Kokkos::CudaUVMSpace, void>
: public SharedAllocationRecordCommon<Kokkos::CudaUVMSpace> {
private:
friend class SharedAllocationRecordCommon<Kokkos::CudaUVMSpace>;
using base_t = SharedAllocationRecordCommon<Kokkos::CudaUVMSpace>;
using RecordBase = SharedAllocationRecord<void, void>;
SharedAllocationRecord(const SharedAllocationRecord&) = delete;
SharedAllocationRecord& operator=(const SharedAllocationRecord&) = delete;
static RecordBase s_root_record;
const Kokkos::CudaUVMSpace m_space;
protected:
~SharedAllocationRecord();
SharedAllocationRecord() = default;
// This constructor does not forward to the one without exec_space arg
// in order to work around https://github.com/kokkos/kokkos/issues/5258
// This constructor is templated so I can't just put it into the cpp file
// like the other constructor.
template <typename ExecutionSpace>
SharedAllocationRecord(
const ExecutionSpace& /*exec_space*/,
const Kokkos::CudaUVMSpace& arg_space, const std::string& arg_label,
const size_t arg_alloc_size,
const RecordBase::function_type arg_dealloc = &base_t::deallocate)
: base_t(
#ifdef KOKKOS_ENABLE_DEBUG
&SharedAllocationRecord<Kokkos::CudaUVMSpace, void>::s_root_record,
#endif
Impl::checked_allocation_with_header(arg_space, arg_label,
arg_alloc_size),
sizeof(SharedAllocationHeader) + arg_alloc_size, arg_dealloc,
arg_label),
m_space(arg_space) {
this->base_t::_fill_host_accessible_header_info(*base_t::m_alloc_ptr,
arg_label);
}
SharedAllocationRecord(
const Kokkos::CudaUVMSpace& arg_space, const std::string& arg_label,
const size_t arg_alloc_size,
const RecordBase::function_type arg_dealloc = &base_t::deallocate);
};
template <>
class SharedAllocationRecord<Kokkos::CudaHostPinnedSpace, void>
: public SharedAllocationRecordCommon<Kokkos::CudaHostPinnedSpace> {
private:
friend class SharedAllocationRecordCommon<Kokkos::CudaHostPinnedSpace>;
using RecordBase = SharedAllocationRecord<void, void>;
using base_t = SharedAllocationRecordCommon<Kokkos::CudaHostPinnedSpace>;
SharedAllocationRecord(const SharedAllocationRecord&) = delete;
SharedAllocationRecord& operator=(const SharedAllocationRecord&) = delete;
static RecordBase s_root_record;
const Kokkos::CudaHostPinnedSpace m_space;
protected:
~SharedAllocationRecord();
SharedAllocationRecord() = default;
// This constructor does not forward to the one without exec_space arg
// in order to work around https://github.com/kokkos/kokkos/issues/5258
// This constructor is templated so I can't just put it into the cpp file
// like the other constructor.
template <typename ExecutionSpace>
SharedAllocationRecord(
const ExecutionSpace& /*exec_space*/,
const Kokkos::CudaHostPinnedSpace& arg_space,
const std::string& arg_label, const size_t arg_alloc_size,
const RecordBase::function_type arg_dealloc = &base_t::deallocate)
: base_t(
#ifdef KOKKOS_ENABLE_DEBUG
&SharedAllocationRecord<Kokkos::CudaHostPinnedSpace,
void>::s_root_record,
#endif
Impl::checked_allocation_with_header(arg_space, arg_label,
arg_alloc_size),
sizeof(SharedAllocationHeader) + arg_alloc_size, arg_dealloc,
arg_label),
m_space(arg_space) {
this->base_t::_fill_host_accessible_header_info(*base_t::m_alloc_ptr,
arg_label);
}
SharedAllocationRecord(
const Kokkos::CudaHostPinnedSpace& arg_space,
const std::string& arg_label, const size_t arg_alloc_size,
const RecordBase::function_type arg_dealloc = &base_t::deallocate);
};
} // namespace Impl
} // namespace Kokkos
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
#endif /* #if defined( KOKKOS_ENABLE_CUDA ) */
#endif /* #define KOKKOS_CUDASPACE_HPP */