Skip to content

Commit f979485

Browse files
committed
a
1 parent 1faa557 commit f979485

17 files changed

+578
-333
lines changed

benchmark/ubench.c

Lines changed: 168 additions & 225 deletions
Large diffs are not rendered by default.

docs/config/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ memory as well as functions that create, destroy and operate on the pool.
2828
.. doxygenfile:: memory_pool.h
2929
:sections: define enum typedef func var
3030

31+
TODO
32+
------------------------------------------
33+
34+
TODO
35+
36+
.. doxygenfile:: memory_props.h
37+
:sections: define enum typedef func var
38+
3139
Disjoint Pool
3240
------------------------------------------
3341

include/umf/memory_props.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
#include <umf/memory_pool.h>
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
/// @brief TODO
21+
// write about experimental api
22+
typedef enum umf_memory_property_id_t {
23+
UMF_MEMORY_PROPERTY_INVALID = -1, ///< TODO
24+
25+
// UMF specyfic
26+
UMF_MEMORY_PROVIDER_HANDLE,
27+
UMF_MEMORY_PROVIDER_OPS, // == type?
28+
UMF_MEMORY_POOL_HANDLE,
29+
UMF_MEMORY_POOL_OPS, // == type?
30+
31+
// generic pointer properties
32+
UMF_MEMORY_PROPERTY_POINTER_TYPE, // unreg host, reg host ??, dev, managed or umf_usm_memory_type_t?
33+
UMF_MEMORY_PROPERTY_BASE_ADDRESS, // base address
34+
UMF_MEMORY_PROPERTY_BASE_SIZE, // base size
35+
36+
// GPU specyfic
37+
UMF_MEMORY_PROPERTY_DEVICE, // handle (ze) or id (cuda)
38+
UMF_MEMORY_PROPERTY_BUFFER_ID, // unique id NOTE: this id is unique across all UMF allocs and != L0 or CUDA ID
39+
UMF_MEMORY_PROPERTY_DEVICE_ATTRIBUTES, // ze_memory_allocation_properties_t ?
40+
41+
// all cuda + l0
42+
// next other providers?
43+
// todo return type?
44+
45+
/// @cond
46+
UMF_MEMORY_PROPERTY_MAX_RESERVED = 0x1000, ///< Maximum reserved value
47+
/// @endcond
48+
49+
} umf_memory_property_id_t;
50+
51+
typedef struct umf_memory_properties_t *umf_memory_properties_handle_t;
52+
53+
/// @brief TODO
54+
umf_result_t
55+
umfGetMemoryPropertiesHandle(void *ptr,
56+
umf_memory_properties_handle_t *props_handle);
57+
58+
/// @brief TODO
59+
umf_result_t umfGetMemoryProperty(umf_memory_properties_handle_t props_handle,
60+
umf_memory_property_id_t memory_property_id,
61+
void *value);
62+
63+
#ifdef __cplusplus
64+
}
65+
#endif
66+
67+
#endif /* UMF_MEMORY_PROPS_H */

include/umf/providers/provider_level_zero.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef UMF_PROVIDER_LEVEL_ZERO_H
99
#define UMF_PROVIDER_LEVEL_ZERO_H
1010

11+
#include <umf/memory_props.h>
1112
#include <umf/memory_provider_gpu.h>
1213

1314
#ifdef __cplusplus
@@ -91,6 +92,11 @@ umf_result_t umfLevelZeroMemoryProviderParamsSetDeviceOrdinal(
9192
umf_level_zero_memory_provider_params_handle_t hParams,
9293
uint32_t deviceOrdinal);
9394

95+
/// TODO
96+
umf_result_t umfLevelZeroMemoryProviderGetMemoryProperty(
97+
umf_memory_properties_handle_t props_handle,
98+
umf_memory_property_id_t memory_property_id, void *value);
99+
94100
const umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void);
95101

96102
#ifdef __cplusplus

src/CMakeLists.txt

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ set(UMF_SOURCES
6666
ipc.c
6767
ipc_cache.c
6868
memory_pool.c
69+
memory_props.c
6970
memory_provider.c
7071
memory_provider_get_last_failed.c
7172
memtarget.c
@@ -115,20 +116,22 @@ set(UMF_SOURCES_LINUX libumf_linux.c)
115116
set(UMF_SOURCES_MACOSX libumf_linux.c)
116117
set(UMF_SOURCES_WINDOWS libumf_windows.c)
117118

118-
# Add compile definitions to handle unsupported functions
119-
if(NOT UMF_BUILD_CUDA_PROVIDER)
120-
set(UMF_COMMON_COMPILE_DEFINITIONS ${UMF_COMMON_COMPILE_DEFINITIONS}
121-
"UMF_NO_CUDA_PROVIDER=1")
122-
endif()
123-
if(NOT UMF_BUILD_LEVEL_ZERO_PROVIDER)
119+
if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
120+
if(LINUX)
121+
# WA for error ze_api.h:14234:20: no newline at end of file
122+
# [-Werror,-Wnewline-eof]
123+
set_source_files_properties(
124+
provider/provider_level_zero.c
125+
PROPERTIES APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-newline-eof")
126+
endif()
127+
124128
set(UMF_COMMON_COMPILE_DEFINITIONS ${UMF_COMMON_COMPILE_DEFINITIONS}
125-
"UMF_NO_LEVEL_ZERO_PROVIDER=1")
129+
"UMF_BUILD_LEVEL_ZERO_PROVIDER=1")
126130
endif()
127-
if(UMF_DISABLE_HWLOC OR WINDOWS)
128-
set(UMF_COMMON_COMPILE_DEFINITIONS ${UMF_COMMON_COMPILE_DEFINITIONS}
129-
"UMF_NO_DEVDAX_PROVIDER=1")
131+
132+
if(UMF_BUILD_CUDA_PROVIDER)
130133
set(UMF_COMMON_COMPILE_DEFINITIONS ${UMF_COMMON_COMPILE_DEFINITIONS}
131-
"UMF_NO_FILE_PROVIDER=1")
134+
"UMF_BUILD_CUDA_PROVIDER=1")
132135
endif()
133136

134137
if(LINUX)
@@ -198,24 +201,6 @@ if(NOT WINDOWS AND UMF_POOL_JEMALLOC_ENABLED)
198201
add_dependencies(umf jemalloc)
199202
endif()
200203

201-
if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
202-
if(LINUX)
203-
# WA for error ze_api.h:14234:20: no newline at end of file
204-
# [-Werror,-Wnewline-eof]
205-
set_source_files_properties(
206-
provider/provider_level_zero.c
207-
PROPERTIES APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-newline-eof")
208-
endif()
209-
210-
set(UMF_COMPILE_DEFINITIONS ${UMF_COMPILE_DEFINITIONS}
211-
"UMF_BUILD_LEVEL_ZERO_PROVIDER=1")
212-
endif()
213-
214-
if(UMF_BUILD_CUDA_PROVIDER)
215-
set(UMF_COMPILE_DEFINITIONS ${UMF_COMPILE_DEFINITIONS}
216-
"UMF_BUILD_CUDA_PROVIDER=1")
217-
endif()
218-
219204
add_library(${PROJECT_NAME}::umf ALIAS umf)
220205

221206
if(LIBHWLOC_INCLUDE_DIRS)

src/ipc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
6565
return ret;
6666
}
6767

68-
ret = umfPoolGetIPCHandleSize(allocInfo.pool, &ipcHandleSize);
68+
ret = umfPoolGetIPCHandleSize(allocInfo.props->pool, &ipcHandleSize);
6969
if (ret != UMF_RESULT_SUCCESS) {
7070
LOG_ERR("cannot get IPC handle size.");
7171
return ret;
@@ -79,7 +79,7 @@ umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
7979

8080
// We cannot use umfPoolGetMemoryProvider function because it returns
8181
// upstream provider but we need tracking one
82-
umf_memory_provider_handle_t provider = allocInfo.pool->provider;
82+
umf_memory_provider_handle_t provider = allocInfo.props->pool->provider;
8383
assert(provider);
8484

8585
ret = umfMemoryProviderGetIPCHandle(provider, allocInfo.base,

src/libumf.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ EXPORTS
139139
umfCtlExec
140140
umfCtlGet
141141
umfCtlSet
142+
umfGetMemoryPropertiesHandle
143+
umfGetMemoryProperty
142144
umfJemallocPoolParamsCreate
143145
umfJemallocPoolParamsDestroy
144146
umfJemallocPoolParamsSetNumArenas

src/libumf.map

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ UMF_0.12 {
139139
umfCtlExec;
140140
umfCtlGet;
141141
umfCtlSet;
142+
umfGetMemoryPropertiesHandle;
143+
umfGetMemoryProperty;
142144
umfJemallocPoolParamsCreate;
143145
umfJemallocPoolParamsDestroy;
144146
umfJemallocPoolParamsSetNumArenas;

src/memory_props.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
#include <umf/memory_props.h>
11+
#include <umf/providers/provider_cuda.h>
12+
#include <umf/providers/provider_level_zero.h>
13+
14+
#include "memory_props_internal.h"
15+
#include "memory_provider_internal.h"
16+
#include "provider/provider_tracking.h"
17+
18+
umf_result_t
19+
umfGetMemoryPropertiesHandle(void *ptr,
20+
umf_memory_properties_handle_t *props_handle) {
21+
umf_alloc_info_t allocInfo = {NULL, 0, NULL};
22+
umf_result_t ret = umfMemoryTrackerGetAllocInfo(ptr, &allocInfo);
23+
if (ret != UMF_RESULT_SUCCESS) {
24+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
25+
}
26+
27+
*props_handle = allocInfo.props;
28+
return UMF_RESULT_SUCCESS;
29+
}
30+
31+
umf_result_t umfGetMemoryProperty(umf_memory_properties_handle_t props_handle,
32+
umf_memory_property_id_t memory_property_id,
33+
void *value) {
34+
if ((value == NULL) ||
35+
(memory_property_id == UMF_MEMORY_PROPERTY_INVALID) ||
36+
(memory_property_id >= UMF_MEMORY_PROPERTY_MAX_RESERVED) ||
37+
props_handle == NULL) {
38+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
39+
}
40+
41+
switch (memory_property_id) {
42+
case UMF_MEMORY_POOL_HANDLE:
43+
*(umf_memory_pool_handle_t *)value = props_handle->pool;
44+
return UMF_RESULT_SUCCESS;
45+
46+
case UMF_MEMORY_PROPERTY_BUFFER_ID:
47+
*(uint64_t *)value = props_handle->id;
48+
return UMF_RESULT_SUCCESS;
49+
50+
default:
51+
break;
52+
}
53+
54+
// properties that are related to the memory provider
55+
umf_memory_provider_t *provider = NULL;
56+
umfPoolGetMemoryProvider(props_handle->pool, &provider);
57+
assert(provider != NULL);
58+
59+
switch (memory_property_id) {
60+
// GPU Memory Provider specyfic properties
61+
case UMF_MEMORY_PROPERTY_POINTER_TYPE:
62+
case UMF_MEMORY_PROPERTY_DEVICE:
63+
case UMF_MEMORY_PROPERTY_DEVICE_ATTRIBUTES:
64+
if (provider->ops.get_name(provider) ==
65+
umfLevelZeroMemoryProviderOps()->get_name(provider)) {
66+
return umfLevelZeroMemoryProviderGetMemoryProperty(
67+
props_handle, memory_property_id, value);
68+
} else if (provider->ops.get_name(provider) ==
69+
umfCUDAMemoryProviderOps()->get_name(provider)) {
70+
// TODO
71+
assert(0);
72+
return UMF_RESULT_SUCCESS;
73+
}
74+
// no provider found
75+
return UMF_RESULT_ERROR_UNKNOWN;
76+
77+
default:
78+
break;
79+
}
80+
81+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
82+
}

src/memory_props_internal.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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_INTERNAL_H
11+
#define UMF_MEMORY_PROPS_INTERNAL_H 1
12+
13+
#include <stdbool.h>
14+
15+
#include <umf/base.h>
16+
#include <umf/memory_props.h>
17+
18+
#if UMF_BUILD_LEVEL_ZERO_PROVIDER
19+
#include "ze_api.h"
20+
#endif
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
typedef struct umf_memory_properties_t {
27+
void *ptr;
28+
umf_memory_pool_handle_t pool;
29+
uint64_t id;
30+
31+
// TODO
32+
bool gpu_properties_initialized;
33+
union {
34+
#if UMF_BUILD_LEVEL_ZERO_PROVIDER
35+
ze_memory_allocation_properties_t ze_properties;
36+
#endif
37+
int unused; // in case of no GPU support
38+
} gpu;
39+
} umf_memory_properties_t;
40+
41+
#ifdef __cplusplus
42+
}
43+
#endif
44+
45+
#endif // UMF_MEMORY_PROPS_INTERNAL_H

src/memory_provider.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
#include <stdio.h>
1313
#include <stdlib.h>
1414

15+
#include <umf/base.h>
1516
#include <umf/memory_provider.h>
1617

1718
#include "base_alloc.h"
1819
#include "base_alloc_global.h"
1920
#include "libumf.h"
2021
#include "memory_provider_internal.h"
21-
#include "umf/base.h"
2222
#include "utils_assert.h"
2323

2424
static int CTL_SUBTREE_HANDLER(by_handle_provider)(

0 commit comments

Comments
 (0)