Skip to content

Commit 94a3476

Browse files
committed
mem props API
1 parent c19c1b8 commit 94a3476

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1391
-120
lines changed

.github/workflows/.spellcheck-conf.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[default]
22
# Don't correct the following words:
3-
extend-ignore-words-re = ["ASSER", "Tne", "ba", "BA", "PN"]
3+
extend-ignore-words-re = ["ASSER", "Tne", "ba", "BA", "PN", "usm"]
44

55
[files]
66
# completely exclude those files from consideration:

.github/workflows/reusable_basic.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ jobs:
195195
${{ matrix.compiler.cxx == 'icpx' && '. /opt/intel/oneapi/setvars.sh' || true }}
196196
cmake --build ${{env.BUILD_DIR}} -j $(nproc)
197197
198+
# UMF_LOG="level:debug;flush:debug;output:stderr;pid:no"
199+
# -R "test_provider_os_memory"
198200
- name: Run tests
199201
working-directory: ${{env.BUILD_DIR}}
200202
run: |

docs/config/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ Memtarget
170170
.. doxygenfile:: experimental/memtarget.h
171171
:sections: define enum typedef func
172172

173+
Memory Properties
174+
==========================================
175+
176+
.. doxygenfile:: memory_props.h
177+
:sections: define enum typedef func var
178+
173179
Inter-Process Communication
174180
==========================================
175181

docs/config/spelling_exceptions.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ partList
4747
pid
4848
poolable
4949
preallocated
50+
propertyId
5051
providerIpcData
5152
providential
5253
ptr
@@ -71,4 +72,5 @@ umfPoolMallocUsableSize
7172
umfPoolRealloc
7273
umfMemspaceUserFilter
7374
umfMemspaceMemtargetAdd
74-
unfreed
75+
unfreed
76+
usm

include/umf/base.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,33 @@ typedef enum umf_result_t {
5151
UMF_RESULT_ERROR_UNKNOWN = 0x7ffffffe ///< Unknown error
5252
} umf_result_t;
5353

54+
/// @brief Handle to the memory properties structure
55+
typedef struct umf_memory_properties_t *umf_memory_properties_handle_t;
56+
57+
/// @brief ID of the memory property
58+
typedef enum umf_memory_property_id_t {
59+
UMF_MEMORY_PROPERTY_INVALID = -1, ///< Invalid property
60+
61+
// UMF specific
62+
UMF_MEMORY_PROPERTY_PROVIDER_HANDLE = 0, ///< Handle to the memory provider
63+
UMF_MEMORY_PROPERTY_POOL_HANDLE = 1, ///< Handle to the memory pool
64+
65+
// generic pointer properties
66+
UMF_MEMORY_PROPERTY_POINTER_TYPE =
67+
2, ///< Type of the pointer (umf_usm_memory_type_t)
68+
UMF_MEMORY_PROPERTY_BASE_ADDRESS = 3, ///< Base address of the allocation
69+
UMF_MEMORY_PROPERTY_BASE_SIZE = 4, ///< Base size of the allocation
70+
UMF_MEMORY_PROPERTY_BUFFER_ID = 5, ///< Unique identifier for the buffer
71+
72+
// GPU specific
73+
UMF_MEMORY_PROPERTY_CONTEXT = 6, ///< GPU context of the allocation
74+
UMF_MEMORY_PROPERTY_DEVICE = 7, ///< GPU device where the allocation resides
75+
76+
/// @cond
77+
UMF_MEMORY_PROPERTY_MAX_RESERVED = 0x1000, ///< Maximum reserved value
78+
/// @endcond
79+
} umf_memory_property_id_t;
80+
5481
/// @brief Type of the CTL query
5582
typedef enum umf_ctl_query_type {
5683
CTL_QUERY_READ,

include/umf/memory_props.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
*
3+
* Copyright (C) 2025 Intel Corporation
4+
*
5+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
6+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
*
8+
*/
9+
10+
#ifndef UMF_MEMORY_PROPS_H
11+
#define UMF_MEMORY_PROPS_H 1
12+
13+
#include <umf/base.h>
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
/// @brief Get the memory properties handle for a given pointer
20+
/// \details
21+
/// The handle returned by this function is valid until the memory pointed
22+
/// to by the pointer is freed.
23+
/// @param ptr pointer to the allocated memory
24+
/// @param props_handle [out] pointer to the memory properties handle
25+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
26+
umf_result_t
27+
umfGetMemoryPropertiesHandle(const void *ptr,
28+
umf_memory_properties_handle_t *props_handle);
29+
30+
/// @brief Get a specific memory property from the properties handle
31+
/// @param props_handle handle to the memory properties
32+
/// @param memory_property_id ID of the memory property to get
33+
/// @param max_property_size size of the property value buffer
34+
/// @param property_value [out] pointer to the value of the memory property
35+
/// which will be filled
36+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
37+
umf_result_t umfGetMemoryProperty(umf_memory_properties_handle_t props_handle,
38+
umf_memory_property_id_t memory_property_id,
39+
size_t max_property_size,
40+
void *property_value);
41+
42+
#ifdef __cplusplus
43+
}
44+
#endif
45+
46+
#endif /* UMF_MEMORY_PROPS_H */

include/umf/memory_provider.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,21 @@ umf_result_t
265265
umfMemoryProviderAllocationMerge(umf_memory_provider_handle_t hProvider,
266266
void *lowPtr, void *highPtr, size_t totalSize);
267267

268+
///
269+
/// @brief Retrieve properties of the memory allocation.
270+
/// @param hProvider pointer to the memory provider
271+
/// @param ptr pointer to the allocated memory
272+
/// @param propertyId identifier of the memory property to retrieve
273+
/// @param max_property_size size of the property value buffer
274+
/// @param property_value [out] pointer to the value of the memory property
275+
/// which will be filled
276+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
277+
///
278+
umf_result_t umfMemoryProviderGetAllocationProperties(
279+
umf_memory_provider_handle_t hProvider, const void *ptr,
280+
umf_memory_property_id_t propertyId, size_t max_property_size,
281+
void *property_value);
282+
268283
#ifdef __cplusplus
269284
}
270285
#endif

include/umf/memory_provider_ops.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,21 @@ typedef struct umf_memory_provider_ops_t {
275275
void *arg, size_t size,
276276
umf_ctl_query_type_t queryType);
277277

278+
///
279+
/// @brief Retrieve properties of the memory allocation.
280+
/// @param provider pointer to the memory provider
281+
/// @param ptr pointer to the allocated memory
282+
/// @param memory_property_id identifier of the memory property to retrieve
283+
/// @param max_property_size size of the property value buffer
284+
/// @param property_value [out] pointer to the value of the memory property
285+
/// which will be filled
286+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
287+
///
288+
umf_result_t (*ext_get_allocation_properties)(
289+
void *provider, const void *ptr,
290+
umf_memory_property_id_t memory_property_id, size_t max_property_size,
291+
void *value);
292+
278293
} umf_memory_provider_ops_t;
279294

280295
#ifdef __cplusplus

scripts/qemu/run-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ numactl -H
2828

2929
cd build
3030
echo "## Running all tests ..."
31+
#UMF_LOG="level:debug;flush:debug;output:stderr;pid:no"
3132
ctest --verbose
33+
# --output-on-failure -R "memoryPool"
3234

3335
echo "## Running tests bound to a numa node 0 and node 1 ..."
3436
numactl -N 0 ctest --output-on-failure

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ set(UMF_SOURCES
4444
ipc.c
4545
ipc_cache.c
4646
memory_pool.c
47+
memory_props.c
4748
memory_provider.c
4849
memory_provider_get_last_failed.c
4950
memtarget.c

0 commit comments

Comments
 (0)