Skip to content

Commit

Permalink
Merge pull request #661 from igchor/umf_rename
Browse files Browse the repository at this point in the history
[uma] rename uma to umf
  • Loading branch information
pbalcer authored Jun 30, 2023
2 parents 7e5059c + dde7199 commit a632ba3
Show file tree
Hide file tree
Showing 47 changed files with 1,267 additions and 1,267 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "python|uma|loader|validation|tracing|unit|urtrace"
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "python|umf|loader|validation|tracing|unit|urtrace"

windows-build:
name: Build - Windows
Expand Down Expand Up @@ -124,4 +124,4 @@ jobs:

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "python|uma|loader|validation|tracing|unit|urtrace"
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "python|umf|loader|validation|tracing|unit|urtrace"
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ option(UR_FORMAT_CPP_STYLE "format code style of C++ sources" OFF)
option(UR_USE_ASAN "enable AddressSanitizer" OFF)
option(UR_USE_UBSAN "enable UndefinedBehaviorSanitizer" OFF)
option(UR_USE_MSAN "enable MemorySanitizer" OFF)
option(UMA_BUILD_SHARED_LIBRARY "Build UMA as shared library" OFF)
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
option(UR_ENABLE_TRACING "enable api tracing through xpti" OFF)
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
option(UR_BUILD_TOOLS "build ur tools" ON)
Expand Down
10 changes: 5 additions & 5 deletions source/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ target_include_directories(ur_common INTERFACE
${CMAKE_SOURCE_DIR}/include
)

add_subdirectory(unified_memory_allocation)
add_subdirectory(uma_pools)
target_link_libraries(ur_common INTERFACE unified_memory_allocation disjoint_pool ${CMAKE_DL_LIBS} ${PROJECT_NAME}::headers)
add_subdirectory(unified_malloc_framework)
add_subdirectory(umf_pools)
target_link_libraries(ur_common INTERFACE unified_malloc_framework disjoint_pool ${CMAKE_DL_LIBS} ${PROJECT_NAME}::headers)

if(WIN32)
target_sources(ur_common
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/windows/ur_lib_loader.cpp
uma_helpers.hpp ur_pool_manager.hpp
umf_helpers.hpp ur_pool_manager.hpp
)
else()
target_sources(ur_common
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/linux/ur_lib_loader.cpp
uma_helpers.hpp ur_pool_manager.hpp
umf_helpers.hpp ur_pool_manager.hpp
)
endif()
116 changes: 58 additions & 58 deletions source/common/uma_helpers.hpp → source/common/umf_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@
*
*/

#ifndef UMA_HELPERS_H
#define UMA_HELPERS_H 1
#ifndef UMF_HELPERS_H
#define UMF_HELPERS_H 1

#include <uma/memory_pool.h>
#include <uma/memory_pool_ops.h>
#include <uma/memory_provider.h>
#include <uma/memory_provider_ops.h>
#include <umf/memory_pool.h>
#include <umf/memory_pool_ops.h>
#include <umf/memory_provider.h>
#include <umf/memory_provider_ops.h>

#include <functional>
#include <memory>
#include <stdexcept>
#include <tuple>
#include <utility>

namespace uma {
namespace umf {

using pool_unique_handle_t =
std::unique_ptr<uma_memory_pool_t,
std::function<void(uma_memory_pool_handle_t)>>;
std::unique_ptr<umf_memory_pool_t,
std::function<void(umf_memory_pool_handle_t)>>;
using provider_unique_handle_t =
std::unique_ptr<uma_memory_provider_t,
std::function<void(uma_memory_provider_handle_t)>>;
std::unique_ptr<umf_memory_provider_t,
std::function<void(umf_memory_provider_handle_t)>>;

#define UMA_ASSIGN_OP(ops, type, func, default_return) \
#define UMF_ASSIGN_OP(ops, type, func, default_return) \
ops.func = [](void *obj, auto... args) { \
try { \
return reinterpret_cast<type *>(obj)->func(args...); \
Expand All @@ -40,32 +40,32 @@ using provider_unique_handle_t =
} \
}

#define UMA_ASSIGN_OP_NORETURN(ops, type, func) \
#define UMF_ASSIGN_OP_NORETURN(ops, type, func) \
ops.func = [](void *obj, auto... args) { \
try { \
return reinterpret_cast<type *>(obj)->func(args...); \
} catch (...) { \
} \
}

/// @brief creates UMA memory provider based on given T type.
/// @brief creates UMF memory provider based on given T type.
/// T should implement all functions defined by
/// uma_memory_provider_ops_t, except for finalize (it is
/// umf_memory_provider_ops_t, except for finalize (it is
/// replaced by dtor). All arguments passed to this function are
/// forwarded to T::initialize().
template <typename T, typename... Args>
auto memoryProviderMakeUnique(Args &&...args) {
uma_memory_provider_ops_t ops;
umf_memory_provider_ops_t ops;
auto argsTuple = std::make_tuple(std::forward<Args>(args)...);

ops.version = UMA_VERSION_CURRENT;
ops.version = UMF_VERSION_CURRENT;
ops.initialize = [](void *params, void **obj) {
auto *tuple = reinterpret_cast<decltype(argsTuple) *>(params);
T *provider;
try {
provider = new T;
} catch (...) {
return UMA_RESULT_ERROR_OUT_OF_HOST_MEMORY;
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}

*obj = provider;
Expand All @@ -74,53 +74,53 @@ auto memoryProviderMakeUnique(Args &&...args) {
auto ret =
std::apply(&T::initialize,
std::tuple_cat(std::make_tuple(provider), *tuple));
if (ret != UMA_RESULT_SUCCESS) {
if (ret != UMF_RESULT_SUCCESS) {
delete provider;
}
return ret;
} catch (...) {
delete provider;
return UMA_RESULT_ERROR_UNKNOWN;
return UMF_RESULT_ERROR_UNKNOWN;
}
};
ops.finalize = [](void *obj) { delete reinterpret_cast<T *>(obj); };

UMA_ASSIGN_OP(ops, T, alloc, UMA_RESULT_ERROR_UNKNOWN);
UMA_ASSIGN_OP(ops, T, free, UMA_RESULT_ERROR_UNKNOWN);
UMA_ASSIGN_OP_NORETURN(ops, T, get_last_native_error);
UMA_ASSIGN_OP(ops, T, get_recommended_page_size, UMA_RESULT_ERROR_UNKNOWN);
UMA_ASSIGN_OP(ops, T, get_min_page_size, UMA_RESULT_ERROR_UNKNOWN);
UMA_ASSIGN_OP(ops, T, purge_lazy, UMA_RESULT_ERROR_UNKNOWN);
UMA_ASSIGN_OP(ops, T, purge_force, UMA_RESULT_ERROR_UNKNOWN);
UMA_ASSIGN_OP(ops, T, get_name, "");

uma_memory_provider_handle_t hProvider = nullptr;
auto ret = umaMemoryProviderCreate(&ops, &argsTuple, &hProvider);
return std::pair<uma_result_t, provider_unique_handle_t>{
ret, provider_unique_handle_t(hProvider, &umaMemoryProviderDestroy)};
UMF_ASSIGN_OP(ops, T, alloc, UMF_RESULT_ERROR_UNKNOWN);
UMF_ASSIGN_OP(ops, T, free, UMF_RESULT_ERROR_UNKNOWN);
UMF_ASSIGN_OP_NORETURN(ops, T, get_last_native_error);
UMF_ASSIGN_OP(ops, T, get_recommended_page_size, UMF_RESULT_ERROR_UNKNOWN);
UMF_ASSIGN_OP(ops, T, get_min_page_size, UMF_RESULT_ERROR_UNKNOWN);
UMF_ASSIGN_OP(ops, T, purge_lazy, UMF_RESULT_ERROR_UNKNOWN);
UMF_ASSIGN_OP(ops, T, purge_force, UMF_RESULT_ERROR_UNKNOWN);
UMF_ASSIGN_OP(ops, T, get_name, "");

umf_memory_provider_handle_t hProvider = nullptr;
auto ret = umfMemoryProviderCreate(&ops, &argsTuple, &hProvider);
return std::pair<umf_result_t, provider_unique_handle_t>{
ret, provider_unique_handle_t(hProvider, &umfMemoryProviderDestroy)};
}

/// @brief creates UMA memory pool based on given T type.
/// @brief creates UMF memory pool based on given T type.
/// T should implement all functions defined by
/// uma_memory_provider_ops_t, except for finalize (it is
/// umf_memory_provider_ops_t, except for finalize (it is
/// replaced by dtor). All arguments passed to this function are
/// forwarded to T::initialize().
template <typename T, typename... Args>
auto poolMakeUnique(uma_memory_provider_handle_t *providers,
auto poolMakeUnique(umf_memory_provider_handle_t *providers,
size_t numProviders, Args &&...args) {
uma_memory_pool_ops_t ops;
umf_memory_pool_ops_t ops;
auto argsTuple = std::make_tuple(std::forward<Args>(args)...);

ops.version = UMA_VERSION_CURRENT;
ops.initialize = [](uma_memory_provider_handle_t *providers,
ops.version = UMF_VERSION_CURRENT;
ops.initialize = [](umf_memory_provider_handle_t *providers,
size_t numProviders, void *params, void **obj) {
auto *tuple = reinterpret_cast<decltype(argsTuple) *>(params);
T *pool;

try {
pool = new T;
} catch (...) {
return UMA_RESULT_ERROR_OUT_OF_HOST_MEMORY;
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}

*obj = pool;
Expand All @@ -130,36 +130,36 @@ auto poolMakeUnique(uma_memory_provider_handle_t *providers,
&T::initialize,
std::tuple_cat(std::make_tuple(pool, providers, numProviders),
*tuple));
if (ret != UMA_RESULT_SUCCESS) {
if (ret != UMF_RESULT_SUCCESS) {
delete pool;
}
return ret;
} catch (...) {
delete pool;
return UMA_RESULT_ERROR_UNKNOWN;
return UMF_RESULT_ERROR_UNKNOWN;
}
};
ops.finalize = [](void *obj) { delete reinterpret_cast<T *>(obj); };

UMA_ASSIGN_OP(ops, T, malloc, ((void *)nullptr));
UMA_ASSIGN_OP(ops, T, calloc, ((void *)nullptr));
UMA_ASSIGN_OP(ops, T, aligned_malloc, ((void *)nullptr));
UMA_ASSIGN_OP(ops, T, realloc, ((void *)nullptr));
UMA_ASSIGN_OP(ops, T, malloc_usable_size, ((size_t)0));
UMA_ASSIGN_OP_NORETURN(ops, T, free);
UMA_ASSIGN_OP(ops, T, get_last_allocation_error, UMA_RESULT_ERROR_UNKNOWN);

uma_memory_pool_handle_t hPool = nullptr;
auto ret = umaPoolCreate(&ops, providers, numProviders, &argsTuple, &hPool);
return std::pair<uma_result_t, pool_unique_handle_t>{
ret, pool_unique_handle_t(hPool, &umaPoolDestroy)};
UMF_ASSIGN_OP(ops, T, malloc, ((void *)nullptr));
UMF_ASSIGN_OP(ops, T, calloc, ((void *)nullptr));
UMF_ASSIGN_OP(ops, T, aligned_malloc, ((void *)nullptr));
UMF_ASSIGN_OP(ops, T, realloc, ((void *)nullptr));
UMF_ASSIGN_OP(ops, T, malloc_usable_size, ((size_t)0));
UMF_ASSIGN_OP_NORETURN(ops, T, free);
UMF_ASSIGN_OP(ops, T, get_last_allocation_error, UMF_RESULT_ERROR_UNKNOWN);

umf_memory_pool_handle_t hPool = nullptr;
auto ret = umfPoolCreate(&ops, providers, numProviders, &argsTuple, &hPool);
return std::pair<umf_result_t, pool_unique_handle_t>{
ret, pool_unique_handle_t(hPool, &umfPoolDestroy)};
}

template <typename Type> uma_result_t &getPoolLastStatusRef() {
static thread_local uma_result_t last_status = UMA_RESULT_SUCCESS;
template <typename Type> umf_result_t &getPoolLastStatusRef() {
static thread_local umf_result_t last_status = UMF_RESULT_SUCCESS;
return last_status;
}

} // namespace uma
} // namespace umf

#endif /* UMA_HELPERS_H */
#endif /* UMF_HELPERS_H */
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_library(disjoint_pool STATIC
add_library(${PROJECT_NAME}::disjoint_pool ALIAS disjoint_pool)

target_link_libraries(disjoint_pool PRIVATE
unified_memory_allocation
unified_malloc_framework
${PROJECT_NAME}::headers)

if (UNIX)
Expand Down
Loading

0 comments on commit a632ba3

Please sign in to comment.