From fb3c40d97b83172e959a258f789aba4e940c53c3 Mon Sep 17 00:00:00 2001 From: Alan Dayton Date: Fri, 25 Mar 2022 07:51:00 -0700 Subject: [PATCH] Add option for initializing all memory to 0 --- cmake/SetupChaiOptions.cmake | 1 + src/chai/ArrayManager.cpp | 5 +++++ src/chai/ArrayManager.inl | 5 +++++ src/chai/config.hpp.in | 1 + 4 files changed, 12 insertions(+) diff --git a/cmake/SetupChaiOptions.cmake b/cmake/SetupChaiOptions.cmake index e4390faf..7c3f2c16 100644 --- a/cmake/SetupChaiOptions.cmake +++ b/cmake/SetupChaiOptions.cmake @@ -19,6 +19,7 @@ option(CHAI_ENABLE_RAJA_PLUGIN "Build plugin to set RAJA execution spaces" Off) option(CHAI_ENABLE_GPU_ERROR_CHECKING "Enable GPU error checking" On) option(CHAI_ENABLE_MANAGED_PTR "Enable managed_ptr" On) option(CHAI_DEBUG "Enable Debug Logging." Off) +option(CHAI_ENABLE_ZERO_INITIALIZED_MEMORY "Initialize allocations to 0" Off) option(CHAI_ENABLE_RAJA_NESTED_TEST "Enable raja-chai-nested-tests, which fails to build on Debug CUDA builds." On) option(CHAI_ENABLE_TESTS "Enable CHAI tests" On) diff --git a/src/chai/ArrayManager.cpp b/src/chai/ArrayManager.cpp index 946ff5ce..13389019 100644 --- a/src/chai/ArrayManager.cpp +++ b/src/chai/ArrayManager.cpp @@ -282,6 +282,11 @@ void ArrayManager::allocate( auto alloc = m_resource_manager.getAllocator(pointer_record->m_allocators[space]); pointer_record->m_pointers[space] = alloc.allocate(size); + +#if CHAI_ENABLE_ZERO_INITIALIZED_MEMORY + m_resource_manager.memset(new_ptr, 0, new_size); +#endif + callback(pointer_record, ACTION_ALLOC, space); registerPointer(pointer_record, space); diff --git a/src/chai/ArrayManager.inl b/src/chai/ArrayManager.inl index 06a5253c..380f0584 100644 --- a/src/chai/ArrayManager.inl +++ b/src/chai/ArrayManager.inl @@ -62,6 +62,11 @@ void* ArrayManager::reallocate(void* pointer, size_t elems, PointerRecord* point if (old_ptr) { void* new_ptr = m_allocators[space]->allocate(new_size); + +#if CHAI_ENABLE_ZERO_INITIALIZED_MEMORY + m_resource_manager.memset(new_ptr, 0, new_size); +#endif + m_resource_manager.copy(new_ptr, old_ptr, num_bytes_to_copy); m_allocators[space]->deallocate(old_ptr); diff --git a/src/chai/config.hpp.in b/src/chai/config.hpp.in index 8325184c..f6de188b 100644 --- a/src/chai/config.hpp.in +++ b/src/chai/config.hpp.in @@ -14,6 +14,7 @@ #cmakedefine CHAI_DISABLE_RM #cmakedefine CHAI_ENABLE_UM #cmakedefine CHAI_DEBUG +#cmakedefine CHAI_ENABLE_ZERO_INITIALIZED_MEMORY #cmakedefine CHAI_ENABLE_GPU_ERROR_CHECKING #cmakedefine CHAI_ENABLE_MANAGED_PTR #cmakedefine CHAI_ENABLE_RAJA_PLUGIN