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

CHAI_LOG only active with CHAI_DEBUG regardless of RM being enabled #167

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ option(ENABLE_UM "Use CUDA unified (managed) memory" Off)
option(ENABLE_PINNED "Use pinned host memory" Off)
option(ENABLE_RAJA_PLUGIN "Build plugin to set RAJA execution spaces" Off)
option(CHAI_ENABLE_GPU_ERROR_CHECKING "Enable GPU error checking" On)
option(CHAI_DEBUG "Enable Debug Logging.")
option(CHAI_DEBUG "Enable Debug Logging." Off)
option(CHAI_ENABLE_WARNING_LOGGING "Enable Warning Logging." On)
option(CHAI_DISABLE_ALL_LOGGING "Disable all logging." Off)
set(ENABLE_RAJA_NESTED_TEST ON CACHE BOOL "Enable raja-chai-nested-tests, which fails to build on Debug CUDA builds.")

set(ENABLE_TESTS On CACHE BOOL "")
Expand Down
21 changes: 11 additions & 10 deletions src/chai/ArrayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void ArrayManager::registerPointer(
// if it's actually the same pointer record, then we're OK. If it's a different
// one, delete the old one.
if (foundRecord != record) {
CHAI_LOG(Warning, "ArrayManager::registerPointer found a record for " <<
CHAI_LOG_WARNING( "ArrayManager::registerPointer found a record for " <<
pointer << " already there. Deleting abandoned pointer record.");

callback(foundRecord, ACTION_FOUND_ABANDONED, space);
Expand All @@ -98,7 +98,7 @@ void ArrayManager::registerPointer(
}
}

CHAI_LOG(Debug, "Registering " << pointer << " in space " << space);
CHAI_LOG_DEBUG( "Registering " << pointer << " in space " << space);

m_pointer_map.insert(pointer, record);

Expand Down Expand Up @@ -135,7 +135,7 @@ void ArrayManager::deregisterPointer(PointerRecord* record, bool deregisterFromU
if (deregisterFromUmpire) {
m_resource_manager.deregisterAllocation(pointer);
}
CHAI_LOG(Debug, "De-registering " << pointer);
CHAI_LOG_DEBUG( "De-registering " << pointer);
m_pointer_map.erase(pointer);
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ void ArrayManager::setExecutionSpace(ExecutionSpace space)
}
#endif

CHAI_LOG(Debug, "Setting execution space to " << space);
CHAI_LOG_DEBUG("Setting execution space to " << space);

if (chai::GPU == space) {
m_synced_since_last_kernel = false;
Expand Down Expand Up @@ -207,7 +207,7 @@ void ArrayManager::registerTouch(PointerRecord* pointer_record,
if (pointer_record && pointer_record != &s_null_record) {

if (space != NONE) {
CHAI_LOG(Debug, pointer_record->m_pointers[space] << " touched in space " << space);
CHAI_LOG_DEBUG( pointer_record->m_pointers[space] << " touched in space " << space);
pointer_record->m_touched[space] = true;
pointer_record->m_last_space = space;
}
Expand Down Expand Up @@ -265,6 +265,7 @@ void ArrayManager::move(PointerRecord* record, ExecutionSpace space)
} else if (dst_pointer != src_pointer) {
// Exclude the copy if src and dst are the same (can happen for PINNED memory)
{
CHAI_LOG_DEBUG( "Moving " << src_pointer << "to " << dst_pointer);
m_resource_manager.copy(dst_pointer, src_pointer);
}

Expand All @@ -286,7 +287,7 @@ void ArrayManager::allocate(

registerPointer(pointer_record, space);

CHAI_LOG(Debug, "Allocated array at: " << pointer_record->m_pointers[space]);
CHAI_LOG_DEBUG( "Allocated array at: " << pointer_record->m_pointers[space]);
}

void ArrayManager::free(PointerRecord* pointer_record, ExecutionSpace spaceToFree)
Expand Down Expand Up @@ -346,7 +347,7 @@ void ArrayManager::free(PointerRecord* pointer_record, ExecutionSpace spaceToFre
m_resource_manager.deregisterAllocation(space_ptr);
}
{
CHAI_LOG(Debug, "DeRegistering " << space_ptr);
CHAI_LOG_DEBUG( "DeRegistering " << space_ptr);
std::lock_guard<std::mutex> lock(m_mutex);
m_pointer_map.erase(space_ptr);
}
Expand Down Expand Up @@ -423,7 +424,7 @@ PointerRecord* ArrayManager::makeManaged(void* pointer,
}
}
else {
CHAI_LOG(Warning, "ArrayManager::makeManaged found abandoned pointer record!!!");
CHAI_LOG_WARNING( "ArrayManager::makeManaged found abandoned pointer record!!!");
callback(pointer_record, ACTION_FOUND_ABANDONED, space);
}

Expand Down Expand Up @@ -533,13 +534,13 @@ void ArrayManager::evict(ExecutionSpace space, ExecutionSpace destinationSpace)
if (destinationSpace == NONE) {
// If the destination space is NONE, evicting invalidates all data and
// leaves us in a bad state (if the last touch was in the eviction space).
CHAI_LOG(Warning, "evict does nothing with destinationSpace == NONE!");
CHAI_LOG_WARNING( "evict does nothing with destinationSpace == NONE!");
return;
}

if (space == destinationSpace) {
// It doesn't make sense to evict to the same space, so do nothing
CHAI_LOG(Warning, "evict does nothing with space == destinationSpace!");
CHAI_LOG_WARNING( "evict does nothing with space == destinationSpace!");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/chai/ArrayManager.inl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void* ArrayManager::reallocate(void* pointer, size_t elems, PointerRecord* point

for (int space = CPU; space < NUM_EXECUTION_SPACES; ++space) {
if (!pointer_record->m_owned[space]) {
CHAI_LOG(Debug, "Cannot reallocate unowned pointer");
CHAI_LOG_DEBUG( "Cannot reallocate unowned pointer");
return pointer_record->m_pointers[my_space];
}
}
Expand Down
26 changes: 18 additions & 8 deletions src/chai/ChaiMacros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,33 @@

#define CHAI_UNUSED_ARG(X)

#if !defined(CHAI_DISABLE_ALL_LOGGING)
#if !defined(CHAI_DISABLE_RM)

#define CHAI_LOG(level, msg) \
#define _CHAI_LOG(level, msg) \
UMPIRE_LOG(level, msg);

#else

#if defined(CHAI_DEBUG)

#define CHAI_LOG(level, msg) \
#define _CHAI_LOG(level, msg) \
std::cerr << "[" << __FILE__ << "] " << msg << std::endl;

#endif // !CHAI_DISABLE_RM
#else

#define CHAI_LOG(level, msg)
#define _CHAI_LOG(level, msg)

#endif
#endif
#endif // CHAI_DISABLE_ALL_LOGGING

#if defined(CHAI_ENABLE_DEBUG_LOGGING)
#define CHAI_LOG_DEBUG(msg) _CHAI_LOG(Debug, msg)
#else
#define CHAI_LOG_DEBUG(msg)
#endif // CHAI_DISABLE_DEBUG_LOGGING

#if defined(CHAI_ENABLE_WARNING_LOGGING)
#define CHAI_LOG_WARNING(msg) _CHAI_LOG(Warning, msg)
#else
#define CHAI_LOG_WARNING(msg)
#endif // CHAI_DISABLE_WARNING_LOGGING

#endif // CHAI_ChaiMacros_HPP
2 changes: 1 addition & 1 deletion src/chai/ManagedArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ CHAI_INLINE CHAI_HOST_DEVICE ManagedArray<T> ManagedArray<T>::slice( size_t offs
}
if (offset + elems > size()) {
#if !defined(CHAI_DEVICE_COMPILE)
CHAI_LOG(Debug,
CHAI_LOG_DEBUG(
"Invalid slice. No active pointer or index out of bounds");
#endif
} else {
Expand Down
22 changes: 10 additions & 12 deletions src/chai/ManagedArray.inl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ CHAI_HOST void ManagedArray<T>::allocate(
{
if(!m_is_slice) {
if (elems > 0) {
CHAI_LOG(Debug, "Allocating array of size " << elems << " in space " << space);
CHAI_LOG_DEBUG( "Allocating array of size " << elems << " in space " << space);

if (m_pointer_record == &ArrayManager::s_null_record) {
// since we are about to allocate, this will get registered
Expand Down Expand Up @@ -199,7 +199,7 @@ CHAI_HOST void ManagedArray<T>::allocate(
#endif
}
#endif
CHAI_LOG(Debug, "m_active_base_ptr allocated at address: " << m_active_base_pointer);
CHAI_LOG_DEBUG( "m_active_base_ptr allocated at address: " << m_active_base_pointer);
}
}
}
Expand All @@ -216,7 +216,7 @@ CHAI_HOST void ManagedArray<T>::reallocate(size_t elems)
if (m_elems == 0 && m_active_base_pointer == nullptr) {
return allocate(elems, CPU);
}
CHAI_LOG(Debug, "Reallocating array of size " << m_elems << " with new size" << elems);
CHAI_LOG_DEBUG( "Reallocating array of size " << m_elems << " with new size" << elems);
if (m_pointer_record == &ArrayManager::s_null_record) {
m_pointer_record = m_resource_manager->makeManaged((void *)m_active_base_pointer,m_elems*sizeof(T),CPU,true);
}
Expand All @@ -241,7 +241,7 @@ CHAI_HOST void ManagedArray<T>::reallocate(size_t elems)
}
}

CHAI_LOG(Debug, "m_active_ptr reallocated at address: " << m_active_pointer);
CHAI_LOG_DEBUG( "m_active_ptr reallocated at address: " << m_active_pointer);
}
else {
this->free();
Expand Down Expand Up @@ -271,7 +271,7 @@ CHAI_HOST void ManagedArray<T>::free(ExecutionSpace space)
m_pointer_record = &ArrayManager::s_null_record;
}
} else {
CHAI_LOG(Debug, "Cannot free a slice!");
CHAI_LOG_DEBUG( "Cannot free a slice!");
}
}

Expand All @@ -292,7 +292,7 @@ template<typename T>
CHAI_INLINE
CHAI_HOST void ManagedArray<T>::registerTouch(ExecutionSpace space) {
if (m_active_pointer && (m_pointer_record == nullptr || m_pointer_record == &ArrayManager::s_null_record)) {
CHAI_LOG(Warning,"registerTouch called on ManagedArray with nullptr pointer record.");
CHAI_LOG_WARNING("registerTouch called on ManagedArray with nullptr pointer record.");
m_pointer_record = m_resource_manager->makeManaged((void *)m_active_base_pointer,m_elems*sizeof(T),space,true);
}
m_resource_manager->registerTouch(m_pointer_record, space);
Expand Down Expand Up @@ -395,11 +395,9 @@ void ManagedArray<T>::move(ExecutionSpace space, bool registerTouch) const
// and so the meta data associated with them are updated before we move the other array down.
moveInnerImpl();
}
CHAI_LOG(Debug, "Moving " << m_active_pointer);
m_active_base_pointer = static_cast<T*>(m_resource_manager->move((void *)m_active_base_pointer, m_pointer_record, space));
m_active_pointer = m_active_base_pointer + m_offset;

CHAI_LOG(Debug, "Moved to " << m_active_pointer);
#if defined(CHAI_ENABLE_UM)
if (m_pointer_record->m_last_space == UM) {
} else
Expand All @@ -409,7 +407,7 @@ void ManagedArray<T>::move(ExecutionSpace space, bool registerTouch) const
} else
#endif
if (registerTouch) {
CHAI_LOG(Debug, "T is non-const, registering touch of pointer" << m_active_pointer);
CHAI_LOG_DEBUG( "T is non-const, registering touch of pointer" << m_active_pointer);
m_resource_manager->registerTouch(m_pointer_record, space);
}
if (space != GPU && prev_space == GPU) {
Expand Down Expand Up @@ -456,7 +454,7 @@ CHAI_HOST_DEVICE ManagedArray<T>::ManagedArray(T* data, CHAIDISAMBIGUATE, bool )
#if !defined(CHAI_DEVICE_COMPILE)

if (m_active_pointer && (m_pointer_record == &ArrayManager::s_null_record || m_active_pointer != m_pointer_record->m_pointers[CPU])) {
CHAI_LOG(Warning,"REINTEGRATED external pointer unknown by CHAI.");
CHAI_LOG_WARNING("REINTEGRATED external pointer unknown by CHAI.");
}
#endif
}
Expand All @@ -483,7 +481,7 @@ T* ManagedArray<T>::data() const {
#if !defined(CHAI_DEVICE_COMPILE)
if (m_active_pointer) {
if (m_pointer_record == nullptr || m_pointer_record == &ArrayManager::s_null_record) {
CHAI_LOG(Warning, "nullptr pointer_record associated with non-nullptr active_pointer")
CHAI_LOG_WARNING( "nullptr pointer_record associated with non-nullptr active_pointer")
}

move(CPU);
Expand All @@ -506,7 +504,7 @@ const T* ManagedArray<T>::cdata() const {
#if !defined(CHAI_DEVICE_COMPILE)
if (m_active_pointer) {
if (m_pointer_record == nullptr || m_pointer_record == &ArrayManager::s_null_record) {
CHAI_LOG(Warning, "nullptr pointer_record associated with non-nullptr active_pointer")
CHAI_LOG_WARNING( "nullptr pointer_record associated with non-nullptr active_pointer")
}

move(CPU, false);
Expand Down
14 changes: 7 additions & 7 deletions src/chai/ManagedArray_thin.inl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ CHAI_HOST void ManagedArray<T>::allocate(size_t elems,
UserCallback const &) {
if (!m_is_slice) {
(void) space; // Quiet compiler warning when CHAI_LOG does nothing
CHAI_LOG(Debug, "Allocating array of size " << elems
CHAI_LOG_DEBUG, "Allocating array of size " << elems
<< " in space "
<< space);

Expand All @@ -155,10 +155,10 @@ CHAI_HOST void ManagedArray<T>::allocate(size_t elems,
m_active_pointer = static_cast<T*>(malloc(sizeof(T) * elems));
#endif

CHAI_LOG(Debug, "m_active_ptr allocated at address: " << m_active_pointer);
CHAI_LOG_DEBUG, "m_active_ptr allocated at address: " << m_active_pointer);
}
else {
CHAI_LOG(Debug, "Attempted to allocate slice!");
CHAI_LOG_DEBUG, "Attempted to allocate slice!");
}
m_active_base_pointer = m_active_pointer;
}
Expand All @@ -168,7 +168,7 @@ CHAI_INLINE
CHAI_HOST void ManagedArray<T>::reallocate(size_t new_elems)
{
if (!m_is_slice) {
CHAI_LOG(Debug, "Reallocating array of size " << m_elems
CHAI_LOG_DEBUG, "Reallocating array of size " << m_elems
<< " with new size"
<< elems);

Expand All @@ -186,10 +186,10 @@ CHAI_HOST void ManagedArray<T>::reallocate(size_t new_elems)
m_active_pointer = new_ptr;
m_active_base_pointer = m_active_pointer;

CHAI_LOG(Debug, "m_active_ptr reallocated at address: " << m_active_pointer);
CHAI_LOG_DEBUG, "m_active_ptr reallocated at address: " << m_active_pointer);
}
else {
CHAI_LOG(Debug, "Attempted to realloc slice!");
CHAI_LOG_DEBUG, "Attempted to realloc slice!");
}
}

Expand All @@ -209,7 +209,7 @@ CHAI_INLINE CHAI_HOST void ManagedArray<T>::free(ExecutionSpace space)
}
}
else {
CHAI_LOG(Debug, "tried to free slice!");
CHAI_LOG_DEBUG, "tried to free slice!");
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/chai/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
#cmakedefine CHAI_ENABLE_IMPLICIT_CONVERSIONS
#cmakedefine CHAI_DISABLE_RM
#cmakedefine CHAI_ENABLE_UM
#cmakedefine CHAI_DEBUG
#cmakedefine01 CHAI_DEBUG
#if CHAI_DEBUG
#define CHAI_ENABLE_DEBUG_LOGGING
#endif
#cmakedefine CHAI_ENABLE_WARNING_LOGGING
#cmakedefine CHAI_ENABLE_GPU_ERROR_CHECKING
#cmakedefine CHAI_ENABLE_RAJA_PLUGIN
#cmakedefine CHAI_ENABLE_GPU_SIMULATION_MODE
Expand Down