Skip to content

Commit

Permalink
Switch to regular fmt library
Browse files Browse the repository at this point in the history
  • Loading branch information
adayton1 committed Jul 18, 2023
1 parent 1e5ef60 commit e02137e
Show file tree
Hide file tree
Showing 58 changed files with 208 additions and 275 deletions.
2 changes: 1 addition & 1 deletion examples/cookbook/recipe_coalesce_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main(int, char**)
quick_pool->coalesce();
// _sphinx_tag_tut_call_coalesce_end
} else {
UMPIRE_ERROR(umpire::runtime_error, umpire::fmt::format("{} is not a QuickPool, cannot coalesce!", pool.getName()));
UMPIRE_ERROR(umpire::runtime_error, fmt::format("{} is not a QuickPool, cannot coalesce!", pool.getName()));
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main(int, char**)
// _sphinx_tag_tut_unwrap_end

if (quick_pool == nullptr) {
UMPIRE_ERROR(umpire::runtime_error, umpire::fmt::format("{} is not a QuickPool", pool.getName()));
UMPIRE_ERROR(umpire::runtime_error, fmt::format("{} is not a QuickPool", pool.getName()));
}

auto ptr = pool.allocate(1024);
Expand Down
8 changes: 4 additions & 4 deletions examples/cookbook/recipe_move_between_numa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ int main(int, char**)
// The pointer shouldn't change even though the memory location changes
if (dst_ptr != src_ptr) {
UMPIRE_ERROR(umpire::runtime_error,
umpire::fmt::format("Pointers should match: dst_ptr: {} != src_ptr: {}", dst_ptr, src_ptr));
fmt::format("Pointers should match: dst_ptr: {} != src_ptr: {}", dst_ptr, src_ptr));
}

// Touch it
rm.memset(dst_ptr, 0);

// Verify NUMA node
if (umpire::numa::get_location(dst_ptr) != host_nodes[1]) {
UMPIRE_ERROR(umpire::runtime_error, umpire::fmt::format("Move was unsuccessful: {}", dst_ptr));
UMPIRE_ERROR(umpire::runtime_error, fmt::format("Move was unsuccessful: {}", dst_ptr));
}
}

Expand All @@ -77,7 +77,7 @@ int main(int, char**)
// The pointer shouldn't change even though the memory location changes
if (dst_ptr != src_ptr) {
UMPIRE_ERROR(umpire::runtime_error,
umpire::fmt::format("Pointers should match: dst_ptr: {} != src_ptr: {}", dst_ptr, src_ptr));
fmt::format("Pointers should match: dst_ptr: {} != src_ptr: {}", dst_ptr, src_ptr));
}

// Touch it -- this currently uses the host memset operation (thus, copying
Expand All @@ -86,7 +86,7 @@ int main(int, char**)

// Verify NUMA node
if (umpire::numa::get_location(dst_ptr) != device_nodes[0]) {
UMPIRE_ERROR(umpire::runtime_error, umpire::fmt::format("Move was unsuccessful: {}", dst_ptr));
UMPIRE_ERROR(umpire::runtime_error, fmt::format("Move was unsuccessful: {}", dst_ptr));
}
}
#endif
Expand Down
75 changes: 4 additions & 71 deletions src/tpl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,82 +133,15 @@ if (NOT TARGET camp)
SCOPE INTERFACE
TARGET_DEFINITIONS CAMP_HAVE_HIP)
endif()

endif ()

set(fmt_headers
umpire/fmt/fmt.hpp
umpire/fmt/args.h
umpire/fmt/chrono.h
umpire/fmt/color.h
umpire/fmt/compile.h
umpire/fmt/core.h
umpire/fmt/format-inl.h
umpire/fmt/format.h
umpire/fmt/locale.h
umpire/fmt/os.h
umpire/fmt/ostream.h
umpire/fmt/printf.h
umpire/fmt/ranges.h
)

blt_add_library(NAME umpire_tpl_fmt
HEADERS ${fmt_headers})


target_include_directories(
umpire_tpl_fmt
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/tpl>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)

# Avoid warnings from fmt (so we can still use -Werror)
blt_convert_to_system_includes(TARGET umpire_tpl_fmt)

target_include_directories(
umpire_tpl_fmt
INTERFACE
$<INSTALL_INTERFACE:include>)

if (C_COMPILER_FAMILY_IS_XL)
set(_fmt_warning_disable_flag
$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-Wno-unknown-attributes>
$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=-Wno-unknown-attributes>)
if (NOT TARGET fmt::fmt-header-only)
find_package(fmt)

target_compile_options(umpire_tpl_fmt INTERFACE ${_fmt_warning_disable_flag})
endif ()

if (C_COMPILER_FAMILY_IS_PGI)
set(_fmt_warning_disable_flag
"--diag_suppress 1625;--diag_suppress 185;--diag_suppress 811;--diag_suppress 186")

if (ENABLE_FORTRAN)
target_compile_options(umpire_tpl_fmt
INTERFACE
$<$<NOT:$<COMPILE_LANGUAGE:Fortran>>:${_fmt_warning_disable_flag}>)
else ()
target_compile_options(umpire_tpl_fmt
INTERFACE
${_fmt_warning_disable_flag})
if (NOT fmt_FOUND)
add_subdirectory(umpire/fmt)
endif ()
endif ()

if (C_COMPILER_FAMILY_IS_GNU)
target_compile_options(umpire_tpl_fmt
INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:-fcompare-debug-second>)
endif ()

install(TARGETS
umpire_tpl_fmt
EXPORT umpire-targets
RUNTIME DESTINATION lib
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

install(FILES
${fmt_headers}
DESTINATION include/umpire/fmt)

set(UMPIRE_ENABLE_TESTS ${OLD_ENABLE_TESTS})
set(UMPIRE_ENABLE_FORTRAN ${OLD_ENABLE_FORTRAN})
54 changes: 27 additions & 27 deletions src/umpire/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Allocator ResourceManager::makeResource(const std::string& name, MemoryResourceT
{
if (m_allocators_by_name.find(name) != m_allocators_by_name.end()) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("Allocator \"{}\" already exists, and cannot be re-created.", name));
fmt::format("Allocator \"{}\" already exists, and cannot be re-created.", name));
}

resource::MemoryResourceRegistry& registry{resource::MemoryResourceRegistry::getInstance()};
Expand Down Expand Up @@ -196,8 +196,8 @@ strategy::AllocationStrategy* ResourceManager::getAllocationStrategy(const std::
if (resource_name != std::end(resource_names)) {
makeResource(name);
} else {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("Allocator \"{}\" not found. Available allocators: {}", name,
getAllocatorInformation()));
UMPIRE_ERROR(runtime_error, fmt::format("Allocator \"{}\" not found. Available allocators: {}", name,
getAllocatorInformation()));
}
}

Expand Down Expand Up @@ -233,7 +233,7 @@ Allocator ResourceManager::getAllocator(int id)

if (id < 0) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("Passed an invalid id: {}. Is this a DeviceAllocator instead?", id));
fmt::format("Passed an invalid id: {}. Is this a DeviceAllocator instead?", id));
}

if (id == umpire::invalid_allocator_id) {
Expand All @@ -242,8 +242,8 @@ Allocator ResourceManager::getAllocator(int id)

auto allocator = m_allocators_by_id.find(id);
if (allocator == m_allocators_by_id.end()) {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("Allocator {} not found. Available allocators: {}", id,
getAllocatorInformation()));
UMPIRE_ERROR(runtime_error, fmt::format("Allocator {} not found. Available allocators: {}", id,
getAllocatorInformation()));
}

return Allocator(m_allocators_by_id[id]);
Expand Down Expand Up @@ -286,8 +286,8 @@ void ResourceManager::setDefaultAllocator(Allocator allocator) noexcept
void ResourceManager::addAlias(const std::string& name, Allocator allocator)
{
if (isAllocator(name)) {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("Allocator \"{}\" is already an alias for \"{}\"", name,
getAllocator(name).getName()));
UMPIRE_ERROR(runtime_error, fmt::format("Allocator \"{}\" is already an alias for \"{}\"", name,
getAllocator(name).getName()));
}

m_allocators_by_name[name] = allocator.getAllocationStrategy();
Expand All @@ -296,17 +296,17 @@ void ResourceManager::addAlias(const std::string& name, Allocator allocator)
void ResourceManager::removeAlias(const std::string& name, Allocator allocator)
{
if (!isAllocator(name)) {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("Allocator \"{}\" is not registered", name));
UMPIRE_ERROR(runtime_error, fmt::format("Allocator \"{}\" is not registered", name));
}

auto a = m_allocators_by_name.find(name);
if (a->second->getName().compare(name) == 0) {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("\"{}\" is not an alias, so cannot be removed", name));
UMPIRE_ERROR(runtime_error, fmt::format("\"{}\" is not an alias, so cannot be removed", name));
}

if (a->second->getId() != allocator.getId()) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("\"{}\" is not is not registered as an alias of {}", name, allocator.getName()));
fmt::format("\"{}\" is not is not registered as an alias of {}", name, allocator.getName()));
}

m_allocators_by_name.erase(a);
Expand Down Expand Up @@ -364,7 +364,7 @@ const util::AllocationRecord* ResourceManager::findAllocationRecord(void* ptr) c
auto alloc_record = m_allocations.find(ptr);

if (!alloc_record->strategy) {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("Cannot find allocator for {}", ptr));
UMPIRE_ERROR(runtime_error, fmt::format("Cannot find allocator for {}", ptr));
}

UMPIRE_LOG(Debug, "(Returning allocation record for ptr = " << ptr << ")");
Expand Down Expand Up @@ -407,7 +407,7 @@ void ResourceManager::copy(void* dst_ptr, void* src_ptr, std::size_t size)

if (size > dst_size) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("Not enough space in destination to copy {} bytes into {} bytes", size, dst_size));
fmt::format("Not enough space in destination to copy {} bytes into {} bytes", size, dst_size));
}

auto op = op_registry.find("COPY", src_alloc_record->strategy, dst_alloc_record->strategy);
Expand Down Expand Up @@ -453,7 +453,7 @@ camp::resources::EventProxy<camp::resources::Resource> ResourceManager::copy(voi

if (size > dst_size) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("Not enough resource in destination for copy: {} -> {}", size, dst_size));
fmt::format("Not enough resource in destination for copy: {} -> {}", size, dst_size));
}

auto op = op_registry.find("COPY", src_alloc_record->strategy, dst_alloc_record->strategy);
Expand Down Expand Up @@ -489,7 +489,7 @@ void ResourceManager::memset(void* ptr, int value, std::size_t length)

if (length > size) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("Cannot memset over the end of allocation: {} -> {}", length, size));
fmt::format("Cannot memset over the end of allocation: {} -> {}", length, size));
}

auto op = op_registry.find("MEMSET", alloc_record->strategy, alloc_record->strategy);
Expand Down Expand Up @@ -528,7 +528,7 @@ camp::resources::EventProxy<camp::resources::Resource> ResourceManager::memset(v

if (length > size) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("Cannot memset over the end of allocation: {} -> {}", length, size));
fmt::format("Cannot memset over the end of allocation: {} -> {}", length, size));
}

auto op = op_registry.find("MEMSET", alloc_record->strategy, alloc_record->strategy);
Expand Down Expand Up @@ -675,8 +675,8 @@ void* ResourceManager::reallocate_impl(void* current_ptr, std::size_t new_size,

if (alloc_record->strategy != allocator.getAllocationStrategy()) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("Cannot reallocate {} from allocator \"{}\" with allocator \"{}\"", current_ptr,
alloc.getName(), allocator.getName()));
fmt::format("Cannot reallocate {} from allocator \"{}\" with allocator \"{}\"", current_ptr,
alloc.getName(), allocator.getName()));
}

//
Expand All @@ -689,8 +689,8 @@ void* ResourceManager::reallocate_impl(void* current_ptr, std::size_t new_size,
auto& op_registry = op::MemoryOperationRegistry::getInstance();

if (current_ptr != alloc_record->ptr) {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("Cannot reallocate an offset ptr (ptr={}, base={})",
current_ptr, alloc_record->ptr));
UMPIRE_ERROR(runtime_error, fmt::format("Cannot reallocate an offset ptr (ptr={}, base={})",
current_ptr, alloc_record->ptr));
}

std::shared_ptr<umpire::op::MemoryOperation> op;
Expand Down Expand Up @@ -727,8 +727,8 @@ void* ResourceManager::reallocate_impl(void* current_ptr, std::size_t new_size,

if (alloc_record->strategy != allocator.getAllocationStrategy()) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("Cannot reallocate {} from allocator \"{}\" with allocator \"{}\"", current_ptr,
alloc.getName(), allocator.getName()));
fmt::format("Cannot reallocate {} from allocator \"{}\" with allocator \"{}\"", current_ptr,
alloc.getName(), allocator.getName()));
}

//
Expand All @@ -741,8 +741,8 @@ void* ResourceManager::reallocate_impl(void* current_ptr, std::size_t new_size,
auto& op_registry = op::MemoryOperationRegistry::getInstance();

if (current_ptr != alloc_record->ptr) {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("Cannot reallocate an offset ptr (ptr={}, base={})",
current_ptr, alloc_record->ptr));
UMPIRE_ERROR(runtime_error, fmt::format("Cannot reallocate an offset ptr (ptr={}, base={})",
current_ptr, alloc_record->ptr));
}

std::shared_ptr<umpire::op::MemoryOperation> op;
Expand Down Expand Up @@ -816,7 +816,7 @@ void* ResourceManager::move(void* ptr, Allocator allocator)

if (ptr != alloc_record->ptr) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("Cannot move an offset ptr (ptr={}, base={})", ptr, alloc_record->ptr));
fmt::format("Cannot move an offset ptr (ptr={}, base={})", ptr, alloc_record->ptr));
}

void* dst_ptr{allocator.allocate(alloc_record->size)};
Expand Down Expand Up @@ -876,7 +876,7 @@ strategy::AllocationStrategy* ResourceManager::findAllocatorForId(int id)
auto allocator_i = m_allocators_by_id.find(id);

if (allocator_i == m_allocators_by_id.end()) {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("Cannot find allocator with id: {}", id));
UMPIRE_ERROR(runtime_error, fmt::format("Cannot find allocator with id: {}", id));
}

UMPIRE_LOG(Debug, "(id=" << id << ") returning " << allocator_i->second);
Expand All @@ -888,7 +888,7 @@ strategy::AllocationStrategy* ResourceManager::findAllocatorForPointer(void* ptr
auto allocation_record = m_allocations.find(ptr);

if (!allocation_record->strategy) {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("Cannot find allocator for pointer: {}", ptr));
UMPIRE_ERROR(runtime_error, fmt::format("Cannot find allocator for pointer: {}", ptr));
}

UMPIRE_LOG(Debug, "(ptr=" << ptr << ") returning " << allocation_record->strategy);
Expand Down
2 changes: 1 addition & 1 deletion src/umpire/ResourceManager.inl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Allocator ResourceManager::makeAllocator(const std::string& name, Tracking track

UMPIRE_LOG(Debug, "(name=\"" << name << "\")");
if (isAllocator(name)) {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("Allocator with name \"{}\" is already registered", name));
UMPIRE_ERROR(runtime_error, fmt::format("Allocator with name \"{}\" is already registered", name));
}

allocator = util::make_unique<Strategy>(name, getNextId(), std::forward<Args>(args)...);
Expand Down
4 changes: 2 additions & 2 deletions src/umpire/Umpire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void* find_pointer_from_name(Allocator allocator, const std::string& name)
{
if (ptr == nullptr) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("Allocator \"{}\" is not a Shared Memory Allocator", allocator.getName()));
fmt::format("Allocator \"{}\" is not a Shared Memory Allocator", allocator.getName()));
}
}
return ptr;
Expand Down Expand Up @@ -311,7 +311,7 @@ void coalesce(Allocator a)
bool coalesced{try_coalesce(a)};

if (!coalesced)
UMPIRE_ERROR(runtime_error, umpire::fmt::format("Allocator \"{}\" could not be coalesced", a.getName()));
UMPIRE_ERROR(runtime_error, fmt::format("Allocator \"{}\" could not be coalesced", a.getName()));
}

} // end namespace umpire
10 changes: 5 additions & 5 deletions src/umpire/alloc/CudaMallocAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ struct CudaMallocAllocator {
UMPIRE_LOG(Debug, "(bytes=" << size << ") returning " << ptr);
if (error != cudaSuccess) {
if (error == cudaErrorMemoryAllocation) {
UMPIRE_ERROR(out_of_memory_error, umpire::fmt::format("cudaMalloc( bytes = {} ) failed with error: {}", size,
cudaGetErrorString(error)));
UMPIRE_ERROR(out_of_memory_error, fmt::format("cudaMalloc( bytes = {} ) failed with error: {}", size,
cudaGetErrorString(error)));
} else {
UMPIRE_ERROR(runtime_error, umpire::fmt::format("cudaMalloc( bytes = {} ) failed with error: {}", size,
cudaGetErrorString(error)));
UMPIRE_ERROR(runtime_error, fmt::format("cudaMalloc( bytes = {} ) failed with error: {}", size,
cudaGetErrorString(error)));
}
}

Expand All @@ -59,7 +59,7 @@ struct CudaMallocAllocator {
cudaError_t error = ::cudaFree(ptr);
if (error != cudaSuccess) {
UMPIRE_ERROR(runtime_error,
umpire::fmt::format("cudaFree( ptr = {} ) failed with error: {}", ptr, cudaGetErrorString(error)));
fmt::format("cudaFree( ptr = {} ) failed with error: {}", ptr, cudaGetErrorString(error)));
}
}
};
Expand Down
Loading

0 comments on commit e02137e

Please sign in to comment.