-
Notifications
You must be signed in to change notification settings - Fork 35
Add memspace "lowest latency" #509
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* | ||
* 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 | ||
* | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <ctype.h> | ||
#include <hwloc.h> | ||
#include <stdlib.h> | ||
|
||
#include "base_alloc_global.h" | ||
#include "memory_target_numa.h" | ||
#include "memspace_internal.h" | ||
#include "memspace_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, | ||
size_t numNodes, | ||
umf_memory_target_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); | ||
if (ret) { | ||
return ret; | ||
} | ||
|
||
if (latency < bestLatency) { | ||
ldorau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bestNodeIdx = nodeIdx; | ||
bestLatency = latency; | ||
} | ||
} | ||
|
||
*target = nodes[bestNodeIdx]; | ||
|
||
return UMF_RESULT_SUCCESS; | ||
} | ||
|
||
static umf_result_t | ||
umfMemspaceLowestLatencyCreate(umf_memspace_handle_t *hMemspace) { | ||
if (!hMemspace) { | ||
return UMF_RESULT_ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
umf_memspace_handle_t hostAllMemspace = umfMemspaceHostAllGet(); | ||
if (!hostAllMemspace) { | ||
return UMF_RESULT_ERROR_UNKNOWN; | ||
} | ||
|
||
umf_memspace_handle_t lowLatencyMemspace = NULL; | ||
umf_result_t ret = umfMemspaceFilter(hostAllMemspace, getBestLatencyTarget, | ||
&lowLatencyMemspace); | ||
if (ret != UMF_RESULT_SUCCESS) { | ||
// HWLOC could possibly return an 'EINVAL' error, which in this context | ||
// means that the HMAT is unavailable and we can't obtain the | ||
// 'latency' value of any NUMA node. | ||
return ret; | ||
} | ||
|
||
*hMemspace = lowLatencyMemspace; | ||
return UMF_RESULT_SUCCESS; | ||
} | ||
|
||
static umf_memspace_handle_t UMF_MEMSPACE_LOWEST_LATENCY = NULL; | ||
static UTIL_ONCE_FLAG UMF_MEMSPACE_LOWEST_LATENCY_INITIALIZED = | ||
UTIL_ONCE_FLAG_INIT; | ||
|
||
void umfMemspaceLowestLatencyDestroy(void) { | ||
if (UMF_MEMSPACE_LOWEST_LATENCY) { | ||
umfMemspaceDestroy(UMF_MEMSPACE_LOWEST_LATENCY); | ||
UMF_MEMSPACE_LOWEST_LATENCY = NULL; | ||
} | ||
} | ||
|
||
static void umfMemspaceLowestLatencyInit(void) { | ||
umf_result_t ret = | ||
umfMemspaceLowestLatencyCreate(&UMF_MEMSPACE_LOWEST_LATENCY); | ||
if (ret != UMF_RESULT_SUCCESS) { | ||
LOG_ERR("Creating the lowest latency memspace failed with a %u error\n", | ||
ret); | ||
assert(ret == UMF_RESULT_ERROR_NOT_SUPPORTED); | ||
} | ||
|
||
#if defined(_WIN32) && !defined(UMF_SHARED_LIBRARY) | ||
atexit(umfMemspaceLowestLatencyDestroy); | ||
#endif | ||
} | ||
|
||
umf_memspace_handle_t umfMemspaceLowestLatencyGet(void) { | ||
util_init_once(&UMF_MEMSPACE_LOWEST_LATENCY_INITIALIZED, | ||
umfMemspaceLowestLatencyInit); | ||
return UMF_MEMSPACE_LOWEST_LATENCY; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.