Skip to content

Commit cc0565d

Browse files
authored
Merge pull request #1301 from bratpiorka/rrudnick_props_api
add memory properties API
2 parents d291734 + a7ca9f6 commit cc0565d

33 files changed

+1554
-105
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:

docs/config/api.rst

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

173+
Memory Properties
174+
==========================================
175+
176+
Memory properties in UMF describe the characteristics and capabilities of
177+
different memory regions or allocations. These properties can include
178+
information such as memory type, allocation size, context and device used for
179+
allocation, and other attributes that are relevant for memory management.
180+
181+
The Memory Properties API allows users to retrieve and interpret these
182+
attributes for memory managed by UMF, enabling advanced memory management
183+
strategies and improved interoperability with heterogeneous systems.
184+
185+
.. note::
186+
The memory properties APIs are experimental and may change in future releases.
187+
188+
Memory Properties
189+
------------------------------------------
190+
.. doxygenfile:: experimental/memory_properties.h
191+
:sections: define enum typedef func var
192+
173193
Inter-Process Communication
174194
==========================================
175195

docs/config/spelling_exceptions.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@ allocatable
33
allocator
44
allocators
55
calloc
6-
CXL
76
copyable
7+
CUcontext
8+
CUdevice
89
customizable
10+
CXL
911
daxX
10-
deallocation
1112
deallocating
13+
deallocation
1214
deallocations
13-
Devdax
1415
dev
16+
Devdax
1517
Globals
18+
highPtr
1619
hMemtarget
1720
hPool
1821
hProvider
19-
highPtr
20-
io
2122
interprocess
23+
io
2224
ipc
2325
jemalloc
2426
lowPtr
@@ -48,8 +50,9 @@ partList
4850
pid
4951
poolable
5052
preallocated
51-
providerIpcData
53+
propertyId
5254
providential
55+
providerIpcData
5356
ptr
5457
realloc
5558
Scalable
@@ -58,11 +61,16 @@ stdout
5861
Tiering
5962
tiering
6063
topologies
64+
uint
65+
uintptr
6166
umf
6267
umfGetIPCHandle
68+
umfGetMemoryPropertySize
6369
umfMemoryProviderAlloc
6470
umfMemoryProviderGetLastNativeError
6571
umfMemoryProviderOpenIPCHandle
72+
umfMemspaceMemtargetAdd
73+
umfMemspaceUserFilter
6674
umfOsMemoryProviderParamsDestroy
6775
umfPool
6876
umfPoolCalloc
@@ -73,4 +81,6 @@ umfPoolRealloc
7381
umfMemspaceUserFilter
7482
umfMemspaceMemtargetAdd
7583
unfreed
84+
usm
7685
zA
86+
ze

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_BASE_ADDRESS = 10, ///< Base address of the allocation
67+
UMF_MEMORY_PROPERTY_BASE_SIZE = 11, ///< Base size of the allocation
68+
UMF_MEMORY_PROPERTY_BUFFER_ID = 12, ///< Unique identifier for the buffer
69+
70+
// GPU specific
71+
UMF_MEMORY_PROPERTY_POINTER_TYPE = 20, ///< Type of the pointer
72+
UMF_MEMORY_PROPERTY_CONTEXT = 21, ///< GPU context of the allocation
73+
UMF_MEMORY_PROPERTY_DEVICE =
74+
22, ///< 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,
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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_PROPERTIES_H
11+
#define UMF_MEMORY_PROPERTIES_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 the size of a specific memory property
31+
/// \details
32+
/// The size of the property should be used to allocate a buffer to hold the
33+
/// value of the property.
34+
/// @param props_handle handle to the memory properties
35+
/// @param memory_property_id ID of the memory property to get the size of
36+
/// @param size [out] pointer to the size of the property
37+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
38+
umf_result_t
39+
umfGetMemoryPropertySize(umf_memory_properties_handle_t props_handle,
40+
umf_memory_property_id_t memory_property_id,
41+
size_t *size);
42+
43+
/// @brief Get a specific memory property from the properties handle
44+
/// \details
45+
/// The type of the property value depends on the property ID. The size of
46+
/// the property value buffer must be large enough to hold the
47+
/// value of the property. The size of the property can be obtained by
48+
/// calling umfGetMemoryPropertySize() with the same property ID.
49+
/// @param props_handle handle to the memory properties
50+
/// @param memory_property_id ID of the memory property to get
51+
/// @param property_value [out] pointer to the value of the memory property
52+
/// which will be filled
53+
/// @param max_property_size size of the property value buffer
54+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
55+
umf_result_t umfGetMemoryProperty(umf_memory_properties_handle_t props_handle,
56+
umf_memory_property_id_t memory_property_id,
57+
void *property_value,
58+
size_t max_property_size);
59+
60+
#ifdef __cplusplus
61+
}
62+
#endif
63+
64+
#endif /* UMF_MEMORY_PROPERTIES_H */

include/umf/memory_provider_ops.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern "C" {
2121
/// @brief Version of the Memory Provider ops structure.
2222
/// NOTE: This is equal to the latest UMF version, in which the ops structure
2323
/// has been modified.
24-
#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(1, 0)
24+
#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(1, 1)
2525

2626
///
2727
/// @brief This structure comprises function pointers used by corresponding
@@ -288,6 +288,40 @@ typedef struct umf_memory_provider_ops_t {
288288
const char *name, void *arg, size_t size,
289289
umf_ctl_query_type_t queryType, va_list args);
290290

291+
// The following operations were added in ops version 1.1
292+
293+
///
294+
/// @brief Retrieve provider-specific properties of the memory allocation.
295+
/// \details
296+
/// If provider supports allocation properties,
297+
/// ext_get_allocation_properties and ext_get_allocation_properties_size,
298+
/// must either be all set or all NULL.
299+
/// @param provider pointer to the memory provider
300+
/// @param ptr pointer to the allocated memory
301+
/// @param memory_property_id ID of the memory property
302+
/// @param property_value [out] pointer to the value of the memory property
303+
/// which will be filled
304+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
305+
///
306+
umf_result_t (*ext_get_allocation_properties)(
307+
void *provider, const void *ptr,
308+
umf_memory_property_id_t memory_property_id, void *property_value);
309+
310+
/// @brief Retrieve size of the provider-specific properties of the memory
311+
/// allocation.
312+
/// \details
313+
/// If provider supports allocation properties,
314+
/// ext_get_allocation_properties and ext_get_allocation_properties_size,
315+
/// must either be all set or all NULL.
316+
/// @param provider pointer to the memory provider
317+
/// @param memory_property_id ID of the memory property to get the size of
318+
/// @param size [out] pointer to the size of the property
319+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
320+
///
321+
umf_result_t (*ext_get_allocation_properties_size)(
322+
void *provider, umf_memory_property_id_t memory_property_id,
323+
size_t *size);
324+
291325
} umf_memory_provider_ops_t;
292326

293327
#ifdef __cplusplus

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ set(UMF_SOURCES
4242
ipc.c
4343
ipc_cache.c
4444
memory_pool.c
45+
memory_properties.c
4546
memory_provider.c
4647
memory_provider_get_last_failed.c
4748
memtarget.c

src/ipc.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,19 @@ umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
5858
}
5959

6060
size_t ipcHandleSize = 0;
61-
umf_alloc_info_t allocInfo;
62-
umf_result_t ret = umfMemoryTrackerGetAllocInfo(ptr, &allocInfo);
61+
umf_memory_properties_handle_t props = NULL;
62+
umf_result_t ret = umfGetMemoryPropertiesHandle(ptr, &props);
6363
if (ret != UMF_RESULT_SUCCESS) {
64-
LOG_ERR("cannot get alloc info for ptr = %p.", ptr);
64+
LOG_ERR("cannot get alloc props for ptr = %p.", ptr);
6565
return ret;
6666
}
6767

68-
ret = umfPoolGetIPCHandleSize(allocInfo.pool, &ipcHandleSize);
68+
if (props == NULL || props->pool == NULL) {
69+
LOG_ERR("cannot get pool from alloc info for ptr = %p.", ptr);
70+
return UMF_RESULT_ERROR_UNKNOWN;
71+
}
72+
73+
ret = umfPoolGetIPCHandleSize(props->pool, &ipcHandleSize);
6974
if (ret != UMF_RESULT_SUCCESS) {
7075
LOG_ERR("cannot get IPC handle size.");
7176
return ret;
@@ -79,11 +84,14 @@ umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
7984

8085
// We cannot use umfPoolGetMemoryProvider function because it returns
8186
// upstream provider but we need tracking one
82-
umf_memory_provider_handle_t provider = allocInfo.pool->provider;
83-
assert(provider);
87+
if (props->pool->provider == NULL) {
88+
LOG_ERR("cannot get memory provider from pool");
89+
umf_ba_global_free(ipcData);
90+
return UMF_RESULT_ERROR_UNKNOWN;
91+
}
92+
umf_memory_provider_handle_t provider = props->pool->provider;
8493

85-
ret = umfMemoryProviderGetIPCHandle(provider, allocInfo.base,
86-
allocInfo.baseSize,
94+
ret = umfMemoryProviderGetIPCHandle(provider, props->base, props->base_size,
8795
(void *)ipcData->providerIpcData);
8896
if (ret != UMF_RESULT_SUCCESS) {
8997
LOG_ERR("failed to get IPC handle.");
@@ -92,10 +100,10 @@ umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
92100
}
93101

94102
// ipcData->handle_id is filled by tracking provider
95-
ipcData->base = allocInfo.base;
103+
ipcData->base = props->base;
96104
ipcData->pid = utils_getpid();
97-
ipcData->baseSize = allocInfo.baseSize;
98-
ipcData->offset = (uintptr_t)ptr - (uintptr_t)allocInfo.base;
105+
ipcData->baseSize = props->base_size;
106+
ipcData->offset = (uintptr_t)ptr - (uintptr_t)props->base;
99107

100108
*umfIPCHandle = ipcData;
101109
*size = ipcHandleSize;

src/libumf.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
LIBRARY UMF
88

9-
VERSION 1.0
9+
VERSION 1.1
1010

1111
EXPORTS
1212
DllMain
@@ -149,6 +149,9 @@ EXPORTS
149149
umfDevDaxMemoryProviderParamsSetName
150150
umfFileMemoryProviderParamsSetName
151151
umfFixedMemoryProviderParamsSetName
152+
umfGetMemoryPropertiesHandle
153+
umfGetMemoryProperty
154+
umfGetMemoryPropertySize
152155
umfJemallocPoolParamsSetName
153156
umfLevelZeroMemoryProviderParamsSetName
154157
umfOsMemoryProviderParamsSetName

src/libumf.map

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ UMF_1.1 {
147147
umfDevDaxMemoryProviderParamsSetName;
148148
umfFileMemoryProviderParamsSetName;
149149
umfFixedMemoryProviderParamsSetName;
150+
umfGetMemoryPropertiesHandle;
151+
umfGetMemoryProperty;
152+
umfGetMemoryPropertySize;
150153
umfJemallocPoolParamsSetName;
151154
umfLevelZeroMemoryProviderParamsSetName;
152155
umfOsMemoryProviderParamsSetName;

0 commit comments

Comments
 (0)