Skip to content

Commit 4bb0a31

Browse files
committed
Expand DEFAULT memspace tests
Those tests confirm that the DEFAULT memspace is composed of memory targets that correspond to all available NUMA node ids. They also affirm that the memory obtained from DEFAULT memspace follows UMF_NUMA_MODE_BIND policy and is made available to all discovered NUMA nodes.
1 parent b80eb41 commit 4bb0a31

File tree

6 files changed

+272
-201
lines changed

6 files changed

+272
-201
lines changed

test/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,14 @@ if(UMF_BUILD_OS_MEMORY_PROVIDER AND LINUX) # OS-specific functions are implement
117117
SRCS provider_os_memory_multiple_numa_nodes.cpp
118118
LIBS umf_utils numa)
119119
add_umf_test(NAME memspace_numa
120-
SRCS memspace_numa.cpp
120+
SRCS memspaces/memspace_numa.cpp
121121
LIBS numa)
122122
add_umf_test(NAME provider_os_memory_config
123123
SRCS provider_os_memory_config.cpp
124124
LIBS umf_utils numa)
125125
add_umf_test(NAME memspace_default
126-
SRCS memspace_default.cpp)
126+
SRCS memspaces/memspace_default.cpp
127+
LIBS numa)
127128
endif()
128129

129130
if(UMF_BUILD_SHARED_LIBRARY)

test/memspace_default.cpp

Lines changed: 0 additions & 65 deletions
This file was deleted.

test/memspace_numa.cpp

Lines changed: 0 additions & 134 deletions
This file was deleted.

test/memspaces/memspace_default.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
#include "memory_target_numa.h"
6+
#include "memspace_helpers.hpp"
7+
#include "memspace_internal.h"
8+
#include "test_helpers.h"
9+
10+
#include <numa.h>
11+
#include <numaif.h>
12+
#include <umf/memspace.h>
13+
14+
using umf_test::test;
15+
16+
TEST_F(numaNodesTest, memspaceGet) {
17+
umf_memspace_handle_t hMemspace = umfMemspaceDefaultGet();
18+
UT_ASSERTne(hMemspace, nullptr);
19+
20+
// Confirm that the DEFAULT memspace is composed of all available NUMA nodes.
21+
UT_ASSERTeq(hMemspace->size, nodeIds.size());
22+
for (size_t i = 0; i < hMemspace->size; i++) {
23+
// NUMA memory target internally casts the config directly into priv.
24+
struct umf_numa_memory_target_config_t *numaTargetCfg =
25+
(struct umf_numa_memory_target_config_t *)hMemspace->nodes[i]->priv;
26+
UT_ASSERT(std::find(nodeIds.begin(), nodeIds.end(),
27+
numaTargetCfg->id) != nodeIds.end());
28+
}
29+
}
30+
31+
TEST_F(memspaceDefaultTest, providerFromDefaultMemspace) {
32+
umf_memory_provider_handle_t hProvider = nullptr;
33+
enum umf_result_t ret =
34+
umfMemoryProviderCreateFromMemspace(hMemspace, nullptr, &hProvider);
35+
UT_ASSERTeq(ret, UMF_RESULT_SUCCESS);
36+
UT_ASSERTne(hProvider, nullptr);
37+
38+
umfMemoryProviderDestroy(hProvider);
39+
}
40+
41+
TEST_F(memspaceDefaultProviderTest, allocFree) {
42+
void *ptr = nullptr;
43+
size_t size = SIZE_4K;
44+
size_t alignment = 0;
45+
46+
enum umf_result_t ret =
47+
umfMemoryProviderAlloc(hProvider, size, alignment, &ptr);
48+
UT_ASSERTeq(ret, UMF_RESULT_SUCCESS);
49+
UT_ASSERTne(ptr, nullptr);
50+
51+
memset(ptr, 0xFF, size);
52+
53+
ret = umfMemoryProviderFree(hProvider, ptr, size);
54+
UT_ASSERTeq(ret, UMF_RESULT_SUCCESS);
55+
}
56+
57+
TEST_F(memspaceDefaultProviderTest, memoryPolicy) {
58+
void *ptr = nullptr;
59+
size_t size = SIZE_4K;
60+
size_t alignment = 0;
61+
62+
enum umf_result_t umf_ret =
63+
umfMemoryProviderAlloc(hProvider, size, alignment, &ptr);
64+
UT_ASSERTeq(umf_ret, UMF_RESULT_SUCCESS);
65+
UT_ASSERTne(ptr, nullptr);
66+
67+
auto it = std::max_element(nodeIds.begin(), nodeIds.end());
68+
UT_ASSERT(it != nodeIds.end());
69+
70+
unsigned long maxNodeId = *it;
71+
72+
unsigned bitsPerUlong = sizeof(unsigned long) * 8;
73+
unsigned nrUlongs = (maxNodeId + bitsPerUlong) / bitsPerUlong;
74+
std::vector<unsigned long> memNodeMasks(nrUlongs, 0);
75+
76+
int memMode = -1;
77+
int ret = get_mempolicy(&memMode, memNodeMasks.data(),
78+
nrUlongs * bitsPerUlong, ptr, MPOL_F_ADDR);
79+
UT_ASSERTeq(ret, 0);
80+
// Obtained memory should be bound to all available NUMA nodes.
81+
UT_ASSERTeq(memMode, MPOL_BIND);
82+
for (auto &nodeId : nodeIds) {
83+
size_t memNodeMaskIdx = ((nodeId + bitsPerUlong) / bitsPerUlong) - 1;
84+
auto &memNodeMask = memNodeMasks.at(memNodeMaskIdx);
85+
86+
UT_ASSERT(memNodeMask && (1UL << (nodeId % bitsPerUlong)));
87+
}
88+
89+
umf_ret = umfMemoryProviderFree(hProvider, ptr, size);
90+
UT_ASSERTeq(umf_ret, UMF_RESULT_SUCCESS);
91+
}

0 commit comments

Comments
 (0)