Skip to content

Implement umfPoolCreateFromMemspace() with proxy pool #471

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

Closed
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
15 changes: 15 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ if(UMF_ENABLE_POOL_TRACKING)
"UMF_ENABLE_POOL_TRACKING")
endif()

if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
set(UMF_PRIVATE_COMPILE_DEFINITIONS ${UMF_PRIVATE_COMPILE_DEFINITIONS}
"UMF_BUILD_LIBUMF_POOL_DISJOINT=1")
endif()

if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
set(UMF_PRIVATE_COMPILE_DEFINITIONS ${UMF_PRIVATE_COMPILE_DEFINITIONS}
"UMF_BUILD_LIBUMF_POOL_JEMALLOC=1")
endif()

if(UMF_BUILD_LIBUMF_POOL_SCALABLE)
set(UMF_PRIVATE_COMPILE_DEFINITIONS ${UMF_PRIVATE_COMPILE_DEFINITIONS}
"UMF_BUILD_LIBUMF_POOL_SCALABLE=1")
endif()

target_link_directories(umf PRIVATE ${UMF_PRIVATE_LIBRARY_DIRS})

target_compile_definitions(umf PRIVATE ${UMF_PRIVATE_COMPILE_DEFINITIONS})
Expand Down
38 changes: 30 additions & 8 deletions src/memory_targets/memory_target_numa.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
*
* Copyright (C) 2023-2024 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
Expand All @@ -11,7 +10,11 @@
#include <hwloc.h>
#include <stdlib.h>

#include <umf/pools/pool_disjoint.h>
#ifdef UMF_BUILD_LIBUMF_POOL_SCALABLE
#include <umf/pools/pool_scalable.h>
#endif

#include <umf/pools/pool_proxy.h>
#include <umf/providers/provider_os_memory.h>

#include "../memory_pool_internal.h"
Expand Down Expand Up @@ -101,12 +104,31 @@ static umf_result_t numa_memory_provider_create_from_memspace(
static umf_result_t numa_pool_create_from_memspace(
umf_memspace_handle_t memspace, void **memTargets, size_t numTargets,
umf_memspace_policy_handle_t policy, umf_memory_pool_handle_t *pool) {
(void)memspace;
(void)memTargets;
(void)numTargets;
(void)policy;
(void)pool;
return UMF_RESULT_ERROR_NOT_SUPPORTED;

umf_memory_provider_handle_t numa_provider;
umf_result_t umf_result = numa_memory_provider_create_from_memspace(
memspace, memTargets, numTargets, policy, &numa_provider);
if (umf_result != UMF_RESULT_SUCCESS) {
return umf_result;
}

umf_memory_pool_handle_t numa_pool;

#ifdef UMF_BUILD_LIBUMF_POOL_SCALABLE
umf_result = umfPoolCreate(umfScalablePoolOps(), numa_provider, NULL,
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &numa_pool);
#else
umf_result = UMF_RESULT_ERROR_NOT_SUPPORTED;
#endif

if (umf_result != UMF_RESULT_SUCCESS) {
umfMemoryProviderDestroy(numa_provider);
return umf_result;
}

*pool = numa_pool;

return umf_result;
}

static umf_result_t numa_clone(void *memTarget, void **outMemTarget) {
Expand Down
6 changes: 5 additions & 1 deletion src/provider/provider_os_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,14 @@ static umf_result_t os_alloc(void *provider, size_t size, size_t alignment,
}

static umf_result_t os_free(void *provider, void *ptr, size_t size) {
if (provider == NULL || ptr == NULL) {
if (provider == NULL) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

if (ptr == NULL) {
return UMF_RESULT_SUCCESS;
}

os_memory_provider_t *os_provider = (os_memory_provider_t *)provider;

if (os_provider->fd > 0) {
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ if(LINUX) # OS-specific functions are implemented only for Linux now
LIBS ${UMF_UTILS_FOR_TEST} ${LIBNUMA_LIBRARIES})
add_umf_test(
NAME memspace_numa
SRCS memspaces/memspace_numa.cpp
SRCS memspaces/memspace_numa.cpp malloc_compliance_tests.cpp
LIBS ${LIBNUMA_LIBRARIES})
add_umf_test(
NAME provider_os_memory_config
Expand Down
44 changes: 43 additions & 1 deletion test/memspaces/memspace_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ struct memspaceNumaProviderTest : ::memspaceNumaTest {
umf_memory_provider_handle_t hProvider = nullptr;
};

struct memspaceNumaPoolTest : ::memspaceNumaTest {
void SetUp() override {
::memspaceNumaTest::SetUp();

umf_result_t ret = umfPoolCreateFromMemspace(hMemspace, nullptr, &pool);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
ASSERT_NE(pool, nullptr);
}

void TearDown() override {
::memspaceNumaTest::TearDown();

if (pool != nullptr) {
umfPoolDestroy(pool);
}
}

umf_memory_pool_handle_t pool = nullptr;
};

struct memspaceHostAllTest : ::numaNodesTest {
void SetUp() override {
::numaNodesTest::SetUp();
Expand All @@ -105,10 +125,32 @@ struct memspaceHostAllProviderTest : ::memspaceHostAllTest {
void TearDown() override {
::memspaceHostAllTest::TearDown();

umfMemoryProviderDestroy(hProvider);
if (hProvider != nullptr) {
umfMemoryProviderDestroy(hProvider);
}
}

umf_memory_provider_handle_t hProvider = nullptr;
};

struct memspaceHostAllPoolTest : ::memspaceHostAllTest {
void SetUp() override {
::memspaceHostAllTest::SetUp();

umf_result_t ret = umfPoolCreateFromMemspace(hMemspace, nullptr, &pool);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
ASSERT_NE(pool, nullptr);
}

void TearDown() override {
::memspaceHostAllTest::TearDown();

if (pool != nullptr) {
umfPoolDestroy(pool);
}
}

umf_memory_pool_handle_t pool = nullptr;
};

#endif /* UMF_MEMSPACE_HELPERS_HPP */
50 changes: 50 additions & 0 deletions test/memspaces/memspace_numa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#include "memspaces/memspace_numa.h"
#include "base.hpp"
#include "malloc_compliance_tests.hpp"
#include "memspace_helpers.hpp"
#include "memspace_internal.h"
#include "pool.hpp"

#include <umf/providers/provider_os_memory.h>

Expand Down Expand Up @@ -65,3 +67,51 @@ TEST_F(memspaceNumaProviderTest, allocFree) {
ret = umfMemoryProviderFree(hProvider, ptr, size);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
}

/* malloc compliance tests of memspaceNumaPoolTest */

TEST_F(memspaceNumaPoolTest, malloc_compliance) {
malloc_compliance_test(pool);
}

TEST_F(memspaceNumaPoolTest, calloc_compliance) {
if (!umf_test::isCallocSupported(pool)) {
GTEST_SKIP();
}

calloc_compliance_test(pool);
}

TEST_F(memspaceNumaPoolTest, realloc_compliance) {
if (!umf_test::isReallocSupported(pool)) {
GTEST_SKIP();
}

realloc_compliance_test(pool);
}

TEST_F(memspaceNumaPoolTest, free_compliance) { free_compliance_test(pool); }

/* malloc compliance tests of memspaceHostAllPoolTest */

TEST_F(memspaceHostAllPoolTest, malloc_compliance) {
malloc_compliance_test(pool);
}

TEST_F(memspaceHostAllPoolTest, calloc_compliance) {
if (!umf_test::isCallocSupported(pool)) {
GTEST_SKIP();
}

calloc_compliance_test(pool);
}

TEST_F(memspaceHostAllPoolTest, realloc_compliance) {
if (!umf_test::isReallocSupported(pool)) {
GTEST_SKIP();
}

realloc_compliance_test(pool);
}

TEST_F(memspaceHostAllPoolTest, free_compliance) { free_compliance_test(pool); }
6 changes: 3 additions & 3 deletions test/provider_os_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ TEST_P(umfProviderTest, free_size_0_ptr_not_null) {
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
}

// other negative tests

TEST_P(umfProviderTest, free_NULL) {
umf_result_t umf_result = umfMemoryProviderFree(provider.get(), nullptr, 0);
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
}

// other negative tests

TEST_P(umfProviderTest, free_INVALID_POINTER_SIZE_GT_0) {
umf_result_t umf_result =
umfMemoryProviderFree(provider.get(), INVALID_PTR, page_plus_64);
Expand Down
Loading