Skip to content

Add umfMemspaceMemtarget[Num|Get] #631

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

Merged
merged 1 commit into from
Jul 25, 2024
Merged
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
16 changes: 16 additions & 0 deletions include/umf/memspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <umf/memory_pool.h>
#include <umf/memory_provider.h>
#include <umf/mempolicy.h>
#include <umf/memtarget.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -84,6 +85,21 @@ umf_const_memspace_handle_t umfMemspaceHighestBandwidthGet(void);
///
umf_const_memspace_handle_t umfMemspaceLowestLatencyGet(void);

/// \brief Returns number of memory targets in memspace.
/// \param hMemspace handle to memspace
/// \return number of memory targets in memspace
///
size_t umfMemspaceMemtargetNum(umf_const_memspace_handle_t hMemspace);

/// \brief Returns memory target by index.
/// \param hMemspace handle to memspace
/// \param targetNum index of the memory target
/// \return memory target handle on success or NULL on invalid input.
///
umf_const_memtarget_handle_t
umfMemspaceMemtargetGet(umf_const_memspace_handle_t hMemspace,
unsigned targetNum);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/libumf.def.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ EXPORTS
umfMempolicySetCustomSplitPartitions
umfMempolicySetInterleavePartSize
umfMemspaceDestroy
umfMemspaceMemtargetNum
umfMemspaceMemtargetGet
umfOpenIPCHandle
umfOsMemoryProviderOps
umfPoolAlignedMalloc
Expand Down
2 changes: 2 additions & 0 deletions src/libumf.map
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ UMF_1.0 {
umfMempolicySetInterleavePartSize;
umfMemspaceCreateFromNumaArray;
umfMemspaceDestroy;
umfMemspaceMemtargetNum;
umfMemspaceMemtargetGet;
umfMemspaceHighestBandwidthGet;
umfMemspaceHighestCapacityGet;
umfMemspaceHostAllGet;
Expand Down
16 changes: 16 additions & 0 deletions src/memspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,19 @@ umf_result_t umfMemspaceFilter(umf_const_memspace_handle_t hMemspace,
umf_ba_global_free(uniqueBestNodes);
return ret;
}

size_t umfMemspaceMemtargetNum(umf_const_memspace_handle_t hMemspace) {
if (!hMemspace) {
return 0;
}
return hMemspace->size;
}

umf_const_memtarget_handle_t
umfMemspaceMemtargetGet(umf_const_memspace_handle_t hMemspace,
unsigned targetNum) {
if (!hMemspace || targetNum >= hMemspace->size) {
return NULL;
}
return hMemspace->nodes[targetNum];
}
23 changes: 22 additions & 1 deletion test/memspaces/memspace_numa.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023 Intel Corporation
// Copyright (C) 2023-2024 Intel Corporation
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

Expand All @@ -7,6 +7,7 @@
#include "memspace_helpers.hpp"
#include "memspace_internal.h"

#include <umf/memspace.h>
#include <umf/providers/provider_os_memory.h>

struct memspaceNumaTest : ::numaNodesTest {
Expand Down Expand Up @@ -56,6 +57,10 @@ TEST_F(numaNodesTest, createDestroy) {
nodeIds.data(), nodeIds.size(), &hMemspace);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
ASSERT_NE(hMemspace, nullptr);
EXPECT_EQ(umfMemspaceMemtargetNum(hMemspace), nodeIds.size());
for (size_t i = 0; i < umfMemspaceMemtargetNum(hMemspace); ++i) {
EXPECT_NE(umfMemspaceMemtargetGet(hMemspace, i), nullptr);
}

umfMemspaceDestroy(hMemspace);
}
Expand Down Expand Up @@ -91,6 +96,22 @@ TEST_F(memspaceNumaTest, providerFromNumaMemspace) {
umfMemoryProviderDestroy(hProvider);
}

TEST_F(numaNodesTest, memtargetsInvalid) {
umf_memspace_handle_t hMemspace = nullptr;
EXPECT_EQ(umfMemspaceMemtargetNum(nullptr), 0);
EXPECT_EQ(umfMemspaceMemtargetGet(nullptr, 0), nullptr);

umf_result_t ret = umfMemspaceCreateFromNumaArray(
nodeIds.data(), nodeIds.size(), &hMemspace);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
ASSERT_NE(hMemspace, nullptr);

ASSERT_EQ(umfMemspaceMemtargetNum(hMemspace), nodeIds.size());
EXPECT_EQ(umfMemspaceMemtargetGet(hMemspace, nodeIds.size()), nullptr);

umfMemspaceDestroy(hMemspace);
}

TEST_F(memspaceNumaProviderTest, allocFree) {
void *ptr = nullptr;
size_t size = SIZE_4K;
Expand Down
Loading