Skip to content

Memtarget refactor #623

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 3 commits into from
Jul 23, 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
24 changes: 24 additions & 0 deletions include/umf/memtarget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
*
* Copyright (C) 2024 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*/

#ifndef UMF_MEMTARGET_H
#define UMF_MEMTARGET_H 1

#ifdef __cplusplus
extern "C" {
#endif

typedef struct umf_memtarget_t *umf_memtarget_handle_t;
typedef const struct umf_memtarget_t *umf_const_memtarget_handle_t;

#ifdef __cplusplus
}
#endif

#endif /* UMF_MEMTARGET_H */
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ set(UMF_SOURCES
memory_pool.c
memory_provider.c
memory_provider_get_last_failed.c
memory_target.c
memtarget.c
mempolicy.c
memspace.c
provider/provider_tracking.c
Expand All @@ -81,7 +81,7 @@ set(UMF_PRIVATE_COMPILE_DEFINITIONS "-DUMF_SRC_VERSION=${UMF_SRC_VERSION}")
set(UMF_SOURCES_COMMON_LINUX_MACOSX
provider/provider_os_memory.c
provider/provider_os_memory_posix.c
memory_targets/memory_target_numa.c
memtargets/memtarget_numa.c
memspaces/memspace_numa.c
memspaces/memspace_host_all.c
memspaces/memspace_highest_capacity.c
Expand Down Expand Up @@ -178,7 +178,7 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/critnib>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/provider>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/memspaces>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/memory_targets>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/memtargets>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

install(TARGETS umf EXPORT ${PROJECT_NAME}-targets)
Expand Down
51 changes: 0 additions & 51 deletions src/memory_target.h

This file was deleted.

44 changes: 22 additions & 22 deletions src/memspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include <umf/memspace.h>

#include "base_alloc_global.h"
#include "memory_target.h"
#include "memory_target_ops.h"
#include "memspace_internal.h"
#include "memtarget_internal.h"
#include "memtarget_ops.h"

#ifndef NDEBUG
static umf_result_t
Expand All @@ -25,7 +25,7 @@ verifyMemTargetsTypes(umf_const_memspace_handle_t memspace) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

const struct umf_memory_target_ops_t *ops = memspace->nodes[0]->ops;
const struct umf_memtarget_ops_t *ops = memspace->nodes[0]->ops;
for (size_t i = 1; i < memspace->size; i++) {
if (memspace->nodes[i]->ops != ops) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
Expand Down Expand Up @@ -66,7 +66,7 @@ umf_result_t umfPoolCreateFromMemspace(umf_const_memspace_handle_t memspace,
return ret;
}

// TODO: for now, we only support memspaces that consist of memory_targets
// TODO: for now, we only support memspaces that consist of memtargets
// of the same type. Fix this.
assert(verifyMemTargetsTypes(memspace) == UMF_RESULT_SUCCESS);
ret = memspace->nodes[0]->ops->pool_create_from_memspace(
Expand All @@ -91,7 +91,7 @@ umfMemoryProviderCreateFromMemspace(umf_const_memspace_handle_t memspace,
return ret;
}

// TODO: for now, we only support memspaces that consist of memory_targets
// TODO: for now, we only support memspaces that consist of memtargets
// of the same type. Fix this.
assert(verifyMemTargetsTypes(memspace) == UMF_RESULT_SUCCESS);
ret = memspace->nodes[0]->ops->memory_provider_create_from_memspace(
Expand All @@ -105,7 +105,7 @@ umfMemoryProviderCreateFromMemspace(umf_const_memspace_handle_t memspace,
void umfMemspaceDestroy(umf_memspace_handle_t memspace) {
assert(memspace);
for (size_t i = 0; i < memspace->size; i++) {
umfMemoryTargetDestroy(memspace->nodes[i]);
umfMemtargetDestroy(memspace->nodes[i]);
}

umf_ba_global_free(memspace->nodes);
Expand All @@ -126,7 +126,7 @@ umf_result_t umfMemspaceClone(umf_const_memspace_handle_t hMemspace,

clone->size = hMemspace->size;
clone->nodes =
umf_ba_global_alloc(sizeof(umf_memory_target_handle_t) * clone->size);
umf_ba_global_alloc(sizeof(umf_memtarget_handle_t) * clone->size);
if (!clone->nodes) {
umf_ba_global_free(clone);
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
Expand All @@ -136,7 +136,7 @@ umf_result_t umfMemspaceClone(umf_const_memspace_handle_t hMemspace,
umf_result_t ret;

for (i = 0; i < clone->size; i++) {
ret = umfMemoryTargetClone(hMemspace->nodes[i], &clone->nodes[i]);
ret = umfMemtargetClone(hMemspace->nodes[i], &clone->nodes[i]);
if (ret != UMF_RESULT_SUCCESS) {
goto err;
}
Expand All @@ -148,21 +148,21 @@ umf_result_t umfMemspaceClone(umf_const_memspace_handle_t hMemspace,
err:
while (i != 0) {
i--;
umfMemoryTargetDestroy(clone->nodes[i]);
umfMemtargetDestroy(clone->nodes[i]);
}
umf_ba_global_free(clone->nodes);
umf_ba_global_free(clone);
return ret;
}

struct memory_target_sort_entry {
struct memtarget_sort_entry {
uint64_t property;
umf_memory_target_handle_t node;
umf_memtarget_handle_t node;
};

static int propertyCmp(const void *a, const void *b) {
const struct memory_target_sort_entry *entryA = a;
const struct memory_target_sort_entry *entryB = b;
const struct memtarget_sort_entry *entryA = a;
const struct memtarget_sort_entry *entryB = b;

if (entryA->property < entryB->property) {
return 1;
Expand All @@ -175,14 +175,14 @@ static int propertyCmp(const void *a, const void *b) {

umf_result_t
umfMemspaceSortDesc(umf_memspace_handle_t hMemspace,
umf_result_t (*getProperty)(umf_memory_target_handle_t node,
umf_result_t (*getProperty)(umf_memtarget_handle_t node,
uint64_t *property)) {
if (!hMemspace || !getProperty) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

struct memory_target_sort_entry *entries = umf_ba_global_alloc(
sizeof(struct memory_target_sort_entry) * hMemspace->size);
struct memtarget_sort_entry *entries = umf_ba_global_alloc(
sizeof(struct memtarget_sort_entry) * hMemspace->size);
if (!entries) {
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
Expand All @@ -198,7 +198,7 @@ umfMemspaceSortDesc(umf_memspace_handle_t hMemspace,
}
}

qsort(entries, hMemspace->size, sizeof(struct memory_target_sort_entry),
qsort(entries, hMemspace->size, sizeof(struct memtarget_sort_entry),
propertyCmp);

// apply the order to the original array
Expand All @@ -218,7 +218,7 @@ umf_result_t umfMemspaceFilter(umf_const_memspace_handle_t hMemspace,
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

umf_memory_target_handle_t *uniqueBestNodes =
umf_memtarget_handle_t *uniqueBestNodes =
umf_ba_global_alloc(hMemspace->size * sizeof(*uniqueBestNodes));
if (!uniqueBestNodes) {
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
Expand All @@ -228,7 +228,7 @@ umf_result_t umfMemspaceFilter(umf_const_memspace_handle_t hMemspace,

size_t numUniqueBestNodes = 0;
for (size_t nodeIdx = 0; nodeIdx < hMemspace->size; nodeIdx++) {
umf_memory_target_handle_t target = NULL;
umf_memtarget_handle_t target = NULL;
ret = getTarget(hMemspace->nodes[nodeIdx], hMemspace->nodes,
hMemspace->size, &target);
if (ret != UMF_RESULT_SUCCESS) {
Expand Down Expand Up @@ -268,8 +268,8 @@ umf_result_t umfMemspaceFilter(umf_const_memspace_handle_t hMemspace,

size_t cloneIdx = 0;
for (cloneIdx = 0; cloneIdx < newMemspace->size; cloneIdx++) {
ret = umfMemoryTargetClone(uniqueBestNodes[cloneIdx],
&newMemspace->nodes[cloneIdx]);
ret = umfMemtargetClone(uniqueBestNodes[cloneIdx],
&newMemspace->nodes[cloneIdx]);
if (ret != UMF_RESULT_SUCCESS) {
goto err_free_cloned_nodes;
}
Expand All @@ -283,7 +283,7 @@ umf_result_t umfMemspaceFilter(umf_const_memspace_handle_t hMemspace,
err_free_cloned_nodes:
while (cloneIdx != 0) {
cloneIdx--;
umfMemoryTargetDestroy(newMemspace->nodes[cloneIdx]);
umfMemtargetDestroy(newMemspace->nodes[cloneIdx]);
}
umf_ba_global_free(newMemspace->nodes);
err_free_new_memspace:
Expand Down
13 changes: 6 additions & 7 deletions src/memspace_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
#include <umf/memspace.h>

#include "base_alloc.h"
#include "memory_target.h"
#include "memtarget_internal.h"

#ifdef __cplusplus
extern "C" {
#endif

struct umf_memspace_t {
size_t size;
umf_memory_target_handle_t *nodes;
umf_memtarget_handle_t *nodes;
};

///
Expand All @@ -30,19 +30,18 @@ struct umf_memspace_t {
umf_result_t umfMemspaceClone(umf_const_memspace_handle_t hMemspace,
umf_memspace_handle_t *outHandle);

typedef umf_result_t (*umfGetPropertyFn)(umf_memory_target_handle_t,
uint64_t *);
typedef umf_result_t (*umfGetPropertyFn)(umf_memtarget_handle_t, uint64_t *);

///
/// \brief Sorts memspace by getProperty() in descending order
///
umf_result_t umfMemspaceSortDesc(umf_memspace_handle_t hMemspace,
umfGetPropertyFn getProperty);

typedef umf_result_t (*umfGetTargetFn)(umf_memory_target_handle_t initiator,
umf_memory_target_handle_t *nodes,
typedef umf_result_t (*umfGetTargetFn)(umf_memtarget_handle_t initiator,
umf_memtarget_handle_t *nodes,
size_t numNodes,
umf_memory_target_handle_t *target);
umf_memtarget_handle_t *target);

///
/// \brief Filters the targets using getTarget() to create a new memspace
Expand Down
10 changes: 5 additions & 5 deletions src/memspaces/memspace_highest_bandwidth.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
#include <stdlib.h>

#include "base_alloc_global.h"
#include "memory_target_numa.h"
#include "memspace_internal.h"
#include "memtarget_numa.h"
#include "topology.h"
#include "utils_common.h"
#include "utils_concurrency.h"
#include "utils_log.h"

static umf_result_t getBestBandwidthTarget(umf_memory_target_handle_t initiator,
umf_memory_target_handle_t *nodes,
static umf_result_t getBestBandwidthTarget(umf_memtarget_handle_t initiator,
umf_memtarget_handle_t *nodes,
size_t numNodes,
umf_memory_target_handle_t *target) {
umf_memtarget_handle_t *target) {
size_t bestNodeIdx = 0;
size_t bestBandwidth = 0;
for (size_t nodeIdx = 0; nodeIdx < numNodes; nodeIdx++) {
size_t bandwidth = 0;
umf_result_t ret =
umfMemoryTargetGetBandwidth(initiator, nodes[nodeIdx], &bandwidth);
umfMemtargetGetBandwidth(initiator, nodes[nodeIdx], &bandwidth);
if (ret) {
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/memspaces/memspace_highest_capacity.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <stdlib.h>

#include "base_alloc_global.h"
#include "memory_target_numa.h"
#include "memspace_internal.h"
#include "memtarget_numa.h"
#include "topology.h"
#include "utils_concurrency.h"

Expand All @@ -34,7 +34,7 @@ umfMemspaceHighestCapacityCreate(umf_memspace_handle_t *hMemspace) {
}

ret = umfMemspaceSortDesc(highCapacityMemspace,
(umfGetPropertyFn)&umfMemoryTargetGetCapacity);
(umfGetPropertyFn)&umfMemtargetGetCapacity);
if (ret != UMF_RESULT_SUCCESS) {
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/memspaces/memspace_host_all.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <stdlib.h>

#include "base_alloc_global.h"
#include "memory_target_numa.h"
#include "memspace_internal.h"
#include "memtarget_numa.h"
#include "topology.h"
#include "utils_concurrency.h"

Expand Down
10 changes: 5 additions & 5 deletions src/memspaces/memspace_lowest_latency.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
#include <stdlib.h>

#include "base_alloc_global.h"
#include "memory_target_numa.h"
#include "memspace_internal.h"
#include "memtarget_numa.h"
#include "topology.h"
#include "utils_common.h"
#include "utils_concurrency.h"
#include "utils_log.h"

static umf_result_t getBestLatencyTarget(umf_memory_target_handle_t initiator,
umf_memory_target_handle_t *nodes,
static umf_result_t getBestLatencyTarget(umf_memtarget_handle_t initiator,
umf_memtarget_handle_t *nodes,
size_t numNodes,
umf_memory_target_handle_t *target) {
umf_memtarget_handle_t *target) {
size_t bestNodeIdx = 0;
size_t bestLatency = SIZE_MAX;
for (size_t nodeIdx = 0; nodeIdx < numNodes; nodeIdx++) {
size_t latency = SIZE_MAX;
umf_result_t ret =
umfMemoryTargetGetLatency(initiator, nodes[nodeIdx], &latency);
umfMemtargetGetLatency(initiator, nodes[nodeIdx], &latency);
if (ret) {
return ret;
}
Expand Down
Loading
Loading