23
23
// Std library headers
24
24
#include < cstddef>
25
25
26
+
26
27
namespace care {
27
28
// /////////////////////////////////////////////////////////////////////////
28
29
// / @struct _kv
@@ -138,13 +139,20 @@ namespace care {
138
139
{
139
140
}
140
141
141
- #if defined (CHAI_DISABLE_RM) || defined(CHAI_THIN_GPU_ALLOCATE)
142
142
// /
143
143
// / @author Peter Robinson
144
144
// /
145
145
// / Construct from a raw pointer, size, and name
146
146
// / This is defined when the CHAI resource manager is disabled
147
147
// /
148
+ #if defined(CARE_DEEP_COPY_RAW_PTR)
149
+ host_device_ptr<T>(T* from, size_t size, const char * name)
150
+ : MA(size)
151
+ {
152
+ std::copy_n (from, size, (T_non_const*)MA::data ());
153
+ }
154
+ #else /* defined(CARE_DEEP_COPY_RAW_PTR) */
155
+ #if defined (CHAI_DISABLE_RM) || defined(CHAI_THIN_GPU_ALLOCATE)
148
156
host_device_ptr<T>(T* from, size_t size, const char * name)
149
157
: MA(from, nullptr , size, nullptr )
150
158
{
@@ -173,6 +181,7 @@ namespace care {
173
181
}
174
182
}
175
183
#endif
184
+ #endif /* defined(CARE_DEEP_COPY_RAW_PTR) */
176
185
177
186
// /
178
187
// / @author Peter Robinson
@@ -412,6 +421,16 @@ namespace care {
412
421
void freeDeviceMemory (T_non_const ** CPU_destination,
413
422
size_t elems,
414
423
bool deregisterPointer=true ) {
424
+ #if defined(CARE_DEEP_COPY_RAW_PTR)
425
+ // if there is a pointer to update ...
426
+ if (CPU_destination != nullptr ) {
427
+ if (*CPU_destination == nullptr ) {
428
+ *CPU_destination = (T_non_const *) std::malloc (elems*sizeof (T));
429
+ }
430
+ std::copy_n (MA::cdata (), elems, *CPU_destination);
431
+ }
432
+ MA::free ();
433
+ #else /* defined(CARE_DEEP_COPY_RAW_PTR) */
415
434
#if !defined(CHAI_DISABLE_RM)
416
435
#if defined(CHAI_GPUCC) || CARE_ENABLE_GPU_SIMULATION_MODE
417
436
if (CPU_destination != nullptr ) {
@@ -441,6 +460,7 @@ namespace care {
441
460
arrayManager->deregisterPointer (MA::m_pointer_record,true );
442
461
CHAICallback::deregisterRecord (MA::m_pointer_record);
443
462
}
463
+
444
464
#else // no resource manager active
445
465
#if defined(CHAI_THIN_GPU_ALLOCATE) // GPU allocated thin wrapped
446
466
// ... then sync to ensure data is up to date
@@ -464,6 +484,7 @@ namespace care {
464
484
}
465
485
}
466
486
#endif
487
+ #endif /* defined(CARE_DEEP_COPY_RAW_PTR) */
467
488
}
468
489
469
490
CARE_HOST_DEVICE void pick (int idx, T_non_const& val) const {
0 commit comments