Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep copy #303

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/SetupOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ option(CARE_ENABLE_IMPLICIT_CONVERSIONS "Enable implicit conversions to-from raw
# CHAI must also be configured with the same settings for implicit conversions.
set(CHAI_ENABLE_IMPLICIT_CONVERSIONS ${CARE_ENABLE_IMPLICIT_CONVERSIONS} CACHE BOOL "Enable implicit conversions to-from raw pointers")
option(CARE_LEGACY_COMPATIBILITY_MODE "Enable legacy compatibility mode" OFF)
option(CARE_DEEP_COPY_RAW_PTR "Use deep copy for managed array initialization from raw pointer" OFF)
option(CARE_ENABLE_MANAGED_PTR "Enable managed_ptr aliases, tests, and reproducer" ON)
option(CARE_DISABLE_RAJAPLUGIN "Disable use of the RAJA plugin. WILL ALSO DISABLE MEMORY MOTION." OFF)
option(CARE_ENABLE_EXTERN_INSTANTIATE "Enable extern instantiation of template functions" OFF)
Expand Down
1 change: 1 addition & 0 deletions src/care/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef CARE_LEGACY_COMPATIBILITY_MODE
#cmakedefine01 CARE_LEGACY_COMPATIBILITY_MODE
#endif
#cmakedefine CARE_DEEP_COPY_RAW_PTR
#cmakedefine CARE_ENABLE_MANAGED_PTR
#cmakedefine CARE_DISABLE_RAJAPLUGIN
#cmakedefine CARE_ENABLE_EXTERN_INSTANTIATE
Expand Down
23 changes: 22 additions & 1 deletion src/care/host_device_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// Std library headers
#include <cstddef>


namespace care {
///////////////////////////////////////////////////////////////////////////
/// @struct _kv
Expand Down Expand Up @@ -138,13 +139,20 @@ namespace care {
{
}

#if defined (CHAI_DISABLE_RM) || defined(CHAI_THIN_GPU_ALLOCATE)
///
/// @author Peter Robinson
///
/// Construct from a raw pointer, size, and name
/// This is defined when the CHAI resource manager is disabled
///
#if defined(CARE_DEEP_COPY_RAW_PTR)
host_device_ptr<T>(T* from, size_t size, const char * name)
: MA(size)
{
std::copy_n(from, size, (T_non_const*)MA::data());
}
#else /* defined(CARE_DEEP_COPY_RAW_PTR) */
#if defined (CHAI_DISABLE_RM) || defined(CHAI_THIN_GPU_ALLOCATE)
host_device_ptr<T>(T* from, size_t size, const char * name)
: MA(from, nullptr, size, nullptr)
{
Expand Down Expand Up @@ -173,6 +181,7 @@ namespace care {
}
}
#endif
#endif /* defined(CARE_DEEP_COPY_RAW_PTR) */

///
/// @author Peter Robinson
Expand Down Expand Up @@ -412,6 +421,16 @@ namespace care {
void freeDeviceMemory(T_non_const ** CPU_destination,
size_t elems,
bool deregisterPointer=true) {
#if defined(CARE_DEEP_COPY_RAW_PTR)
// if there is a pointer to update ...
if (CPU_destination != nullptr) {
if (*CPU_destination == nullptr) {
*CPU_destination = (T_non_const *) std::malloc(elems*sizeof(T));
}
std::copy_n(MA::cdata(), elems, *CPU_destination);
}
MA::free();
#else /* defined(CARE_DEEP_COPY_RAW_PTR) */
#if !defined(CHAI_DISABLE_RM)
#if defined(CHAI_GPUCC) || CARE_ENABLE_GPU_SIMULATION_MODE
if (CPU_destination != nullptr) {
Expand Down Expand Up @@ -441,6 +460,7 @@ namespace care {
arrayManager->deregisterPointer(MA::m_pointer_record,true);
CHAICallback::deregisterRecord(MA::m_pointer_record);
}

#else // no resource manager active
#if defined(CHAI_THIN_GPU_ALLOCATE) // GPU allocated thin wrapped
// ... then sync to ensure data is up to date
Expand All @@ -464,6 +484,7 @@ namespace care {
}
}
#endif
#endif /* defined(CARE_DEEP_COPY_RAW_PTR) */
}

CARE_HOST_DEVICE void pick(int idx, T_non_const& val) const {
Expand Down
Loading