Skip to content

Commit 1b30173

Browse files
committed
use separate provider/pool versions in ops structure
1 parent f6cbe83 commit 1b30173

23 files changed

+82
-56
lines changed

examples/custom_file_provider/custom_file_provider.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2024 Intel Corporation
3+
* Copyright (C) 2024-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -234,7 +234,7 @@ static umf_result_t file_get_min_page_size(void *provider, void *ptr,
234234

235235
// File provider operations
236236
static umf_memory_provider_ops_t file_ops = {
237-
.version = UMF_VERSION_CURRENT,
237+
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
238238
.initialize = file_init,
239239
.finalize = file_deinit,
240240
.alloc = file_alloc,

include/umf/memory_pool.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define UMF_MEMORY_POOL_H 1
1212

1313
#include <umf/base.h>
14+
#include <umf/memory_pool_ops.h>
1415
#include <umf/memory_provider.h>
1516

1617
#ifdef __cplusplus
@@ -22,12 +23,6 @@ extern "C" {
2223
/// functions
2324
typedef struct umf_memory_pool_t *umf_memory_pool_handle_t;
2425

25-
/// @brief This structure comprises function pointers used by corresponding umfPool*
26-
/// calls. Each memory pool implementation should initialize all function
27-
/// pointers.
28-
///
29-
typedef struct umf_memory_pool_ops_t umf_memory_pool_ops_t;
30-
3126
/// @brief Supported pool creation flags
3227
typedef enum umf_pool_create_flag_t {
3328
UMF_POOL_CREATE_FLAG_NONE =

include/umf/memory_pool_ops.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@
1717
extern "C" {
1818
#endif
1919

20+
/// @brief Version of the Memory Pool ops structure.
21+
/// NOTE: This is equal to the latest UMF version, in which the ops structure
22+
/// has been modified.
23+
#define UMF_POOL_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11)
24+
2025
///
2126
/// @brief This structure comprises function pointers used by corresponding umfPool*
2227
/// calls. Each memory pool implementation should initialize all function
2328
/// pointers.
2429
///
25-
typedef struct umf_memory_pool_ops_t {
30+
typedef struct umf_memory_pool_ops_0_11_t {
2631
/// Version of the ops structure.
27-
/// Should be initialized using UMF_VERSION_CURRENT.
32+
/// Should be initialized using UMF_POOL_OPS_VERSION_CURRENT.
2833
uint32_t version;
2934

3035
///
@@ -120,7 +125,8 @@ typedef struct umf_memory_pool_ops_t {
120125
/// The value is undefined if the previous allocation was successful.
121126
///
122127
umf_result_t (*get_last_allocation_error)(void *pool);
123-
} umf_memory_pool_ops_t;
128+
} umf_memory_pool_ops_0_11_t;
129+
typedef umf_memory_pool_ops_0_11_t umf_memory_pool_ops_t;
124130

125131
#ifdef __cplusplus
126132
}

include/umf/memory_provider_ops.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -16,12 +16,17 @@
1616
extern "C" {
1717
#endif
1818

19+
/// @brief Version of the Memory Provider ops structure.
20+
/// NOTE: This is equal to the latest UMF version, in which the ops structure
21+
/// has been modified.
22+
#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11)
23+
1924
///
2025
/// @brief This structure comprises optional function pointers used
2126
/// by corresponding umfMemoryProvider* calls. A memory provider implementation
2227
/// can keep them NULL.
2328
///
24-
typedef struct umf_memory_provider_ext_ops_t {
29+
typedef struct umf_memory_provider_ext_ops_0_11_t {
2530
///
2631
/// @brief Discard physical pages within the virtual memory mapping associated at the given addr
2732
/// and \p size. This call is asynchronous and may delay purging the pages indefinitely.
@@ -78,13 +83,14 @@ typedef struct umf_memory_provider_ext_ops_t {
7883
umf_result_t (*allocation_split)(void *hProvider, void *ptr,
7984
size_t totalSize, size_t firstSize);
8085

81-
} umf_memory_provider_ext_ops_t;
86+
} umf_memory_provider_ext_ops_0_11_t;
87+
typedef umf_memory_provider_ext_ops_0_11_t umf_memory_provider_ext_ops_t;
8288

8389
///
8490
/// @brief This structure comprises optional IPC API. The API allows sharing of
8591
/// memory objects across different processes. A memory provider implementation can keep them NULL.
8692
///
87-
typedef struct umf_memory_provider_ipc_ops_t {
93+
typedef struct umf_memory_provider_ipc_ops_0_11_t {
8894
///
8995
/// @brief Retrieve the size of opaque data structure required to store IPC data.
9096
/// @param provider pointer to the memory provider.
@@ -134,16 +140,17 @@ typedef struct umf_memory_provider_ipc_ops_t {
134140
/// UMF_RESULT_ERROR_INVALID_ARGUMENT if invalid \p ptr is passed.
135141
/// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
136142
umf_result_t (*close_ipc_handle)(void *provider, void *ptr, size_t size);
137-
} umf_memory_provider_ipc_ops_t;
143+
} umf_memory_provider_ipc_ops_0_11_t;
144+
typedef umf_memory_provider_ipc_ops_0_11_t umf_memory_provider_ipc_ops_t;
138145

139146
///
140147
/// @brief This structure comprises function pointers used by corresponding
141148
/// umfMemoryProvider* calls. Each memory provider implementation should
142149
/// initialize all function pointers.
143150
///
144-
typedef struct umf_memory_provider_ops_t {
151+
typedef struct umf_memory_provider_ops_0_11_t {
145152
/// Version of the ops structure.
146-
/// Should be initialized using UMF_VERSION_CURRENT.
153+
/// Should be initialized using UMF_PROVIDER_OPS_VERSION_CURRENT.
147154
uint32_t version;
148155

149156
///
@@ -245,7 +252,8 @@ typedef struct umf_memory_provider_ops_t {
245252
/// @brief Optional IPC ops. The API allows sharing of memory objects across different processes.
246253
///
247254
umf_memory_provider_ipc_ops_t ipc;
248-
} umf_memory_provider_ops_t;
255+
} umf_memory_provider_ops_0_11_t;
256+
typedef umf_memory_provider_ops_0_11_t umf_memory_provider_ops_t;
249257

250258
#ifdef __cplusplus
251259
}

src/cpp_helpers.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -67,7 +67,7 @@ umf_result_t initialize(T *obj, ArgsTuple &&args) {
6767

6868
template <typename T> umf_memory_pool_ops_t poolOpsBase() {
6969
umf_memory_pool_ops_t ops{};
70-
ops.version = UMF_VERSION_CURRENT;
70+
ops.version = UMF_POOL_OPS_VERSION_CURRENT;
7171
ops.finalize = [](void *obj) { delete reinterpret_cast<T *>(obj); };
7272
UMF_ASSIGN_OP(ops, T, malloc, ((void *)nullptr));
7373
UMF_ASSIGN_OP(ops, T, calloc, ((void *)nullptr));
@@ -81,7 +81,7 @@ template <typename T> umf_memory_pool_ops_t poolOpsBase() {
8181

8282
template <typename T> constexpr umf_memory_provider_ops_t providerOpsBase() {
8383
umf_memory_provider_ops_t ops{};
84-
ops.version = UMF_VERSION_CURRENT;
84+
ops.version = UMF_PROVIDER_OPS_VERSION_CURRENT;
8585
ops.finalize = [](void *obj) { delete reinterpret_cast<T *>(obj); };
8686
UMF_ASSIGN_OP(ops, T, alloc, UMF_RESULT_ERROR_UNKNOWN);
8787
UMF_ASSIGN_OP(ops, T, free, UMF_RESULT_ERROR_UNKNOWN);

src/memory_pool.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -38,7 +38,11 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops,
3838
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
3939
}
4040

41-
assert(ops->version == UMF_VERSION_CURRENT);
41+
if (ops->version != UMF_POOL_OPS_VERSION_CURRENT) {
42+
LOG_WARN("memory pool ops version \"%d\" is different than the current "
43+
"version \"%d\"",
44+
ops->version, UMF_POOL_OPS_VERSION_CURRENT);
45+
}
4246

4347
if (!(flags & UMF_POOL_CREATE_FLAG_DISABLE_TRACKING)) {
4448
// Wrap provider with memory tracking provider.

src/memory_provider.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,18 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
167167
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
168168
}
169169

170+
if (ops->version != UMF_PROVIDER_OPS_VERSION_CURRENT) {
171+
LOG_WARN("Memory Provider ops version \"%d\" is different than the "
172+
"current version \"%d\"",
173+
ops->version, UMF_PROVIDER_OPS_VERSION_CURRENT);
174+
}
175+
170176
umf_memory_provider_handle_t provider =
171177
umf_ba_global_alloc(sizeof(umf_memory_provider_t));
172178
if (!provider) {
173179
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
174180
}
175181

176-
assert(ops->version == UMF_VERSION_CURRENT);
177-
178182
provider->ops = *ops;
179183

180184
assignOpsExtDefaults(&(provider->ops));

src/memtarget.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -15,6 +15,7 @@
1515
#include "memtarget_internal.h"
1616
#include "memtarget_ops.h"
1717
#include "utils_concurrency.h"
18+
#include "utils_log.h"
1819

1920
umf_result_t umfMemtargetCreate(const umf_memtarget_ops_t *ops, void *params,
2021
umf_memtarget_handle_t *memoryTarget) {
@@ -29,7 +30,11 @@ umf_result_t umfMemtargetCreate(const umf_memtarget_ops_t *ops, void *params,
2930
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
3031
}
3132

32-
assert(ops->version == UMF_VERSION_CURRENT);
33+
if (ops->version != UMF_MEMTARGET_OPS_VERSION_CURRENT) {
34+
LOG_WARN("memtarget ops version \"%d\" is different than the current "
35+
"version \"%d\"",
36+
ops->version, UMF_MEMTARGET_OPS_VERSION_CURRENT);
37+
}
3338

3439
target->ops = ops;
3540

src/memtarget_internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -16,7 +16,6 @@
1616
extern "C" {
1717
#endif
1818

19-
struct umf_memtarget_ops_t;
2019
typedef struct umf_memtarget_ops_t umf_memtarget_ops_t;
2120

2221
typedef struct umf_memtarget_t {

src/memtarget_ops.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -18,6 +18,11 @@
1818
extern "C" {
1919
#endif
2020

21+
// Version of the Memtarget ops structure.
22+
// NOTE: This is equal to the latest UMF version, in which the ops structure
23+
// has been modified.
24+
#define UMF_MEMTARGET_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11)
25+
2126
typedef struct umf_memtarget_ops_t {
2227
/// Version of the ops structure.
2328
/// Should be initialized using UMF_VERSION_CURRENT

src/memtargets/memtarget_numa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -390,7 +390,7 @@ static umf_result_t numa_compare(void *memTarget, void *otherMemTarget,
390390
}
391391

392392
struct umf_memtarget_ops_t UMF_MEMTARGET_NUMA_OPS = {
393-
.version = UMF_VERSION_CURRENT,
393+
.version = UMF_MEMTARGET_OPS_VERSION_CURRENT,
394394
.initialize = numa_initialize,
395395
.finalize = numa_finalize,
396396
.pool_create_from_memspace = numa_pool_create_from_memspace,

src/pool/pool_jemalloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022-2024 Intel Corporation
2+
* Copyright (C) 2022-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -454,7 +454,7 @@ static umf_result_t op_get_last_allocation_error(void *pool) {
454454
}
455455

456456
static umf_memory_pool_ops_t UMF_JEMALLOC_POOL_OPS = {
457-
.version = UMF_VERSION_CURRENT,
457+
.version = UMF_POOL_OPS_VERSION_CURRENT,
458458
.initialize = op_initialize,
459459
.finalize = op_finalize,
460460
.malloc = op_malloc,

src/pool/pool_proxy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2024 Intel Corporation
3+
* Copyright (C) 2024-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -123,7 +123,7 @@ static umf_result_t proxy_get_last_allocation_error(void *pool) {
123123
}
124124

125125
static umf_memory_pool_ops_t UMF_PROXY_POOL_OPS = {
126-
.version = UMF_VERSION_CURRENT,
126+
.version = UMF_POOL_OPS_VERSION_CURRENT,
127127
.initialize = proxy_pool_initialize,
128128
.finalize = proxy_pool_finalize,
129129
.malloc = proxy_malloc,

src/pool/pool_scalable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -382,7 +382,7 @@ static umf_result_t tbb_get_last_allocation_error(void *pool) {
382382
}
383383

384384
static umf_memory_pool_ops_t UMF_SCALABLE_POOL_OPS = {
385-
.version = UMF_VERSION_CURRENT,
385+
.version = UMF_POOL_OPS_VERSION_CURRENT,
386386
.initialize = tbb_pool_initialize,
387387
.finalize = tbb_pool_finalize,
388388
.malloc = tbb_malloc,

src/provider/provider_cuda.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,8 @@ cu_memory_provider_close_ipc_handle(void *provider, void *ptr, size_t size) {
617617
return UMF_RESULT_SUCCESS;
618618
}
619619

620-
static struct umf_memory_provider_ops_t UMF_CUDA_MEMORY_PROVIDER_OPS = {
621-
.version = UMF_VERSION_CURRENT,
620+
static umf_memory_provider_ops_t UMF_CUDA_MEMORY_PROVIDER_OPS = {
621+
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
622622
.initialize = cu_memory_provider_initialize,
623623
.finalize = cu_memory_provider_finalize,
624624
.alloc = cu_memory_provider_alloc,

src/provider/provider_fixed_memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -254,7 +254,7 @@ static umf_result_t fixed_free(void *provider, void *ptr, size_t size) {
254254
}
255255

256256
static umf_memory_provider_ops_t UMF_FIXED_MEMORY_PROVIDER_OPS = {
257-
.version = UMF_VERSION_CURRENT,
257+
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
258258
.initialize = fixed_initialize,
259259
.finalize = fixed_finalize,
260260
.alloc = fixed_alloc,

src/provider/provider_level_zero.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,8 @@ ze_memory_provider_close_ipc_handle(void *provider, void *ptr, size_t size) {
821821
return UMF_RESULT_SUCCESS;
822822
}
823823

824-
static struct umf_memory_provider_ops_t UMF_LEVEL_ZERO_MEMORY_PROVIDER_OPS = {
825-
.version = UMF_VERSION_CURRENT,
824+
static umf_memory_provider_ops_t UMF_LEVEL_ZERO_MEMORY_PROVIDER_OPS = {
825+
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
826826
.initialize = ze_memory_provider_initialize,
827827
.finalize = ze_memory_provider_finalize,
828828
.alloc = ze_memory_provider_alloc,

src/provider/provider_os_memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022-2024 Intel Corporation
2+
* Copyright (C) 2022-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -1402,7 +1402,7 @@ static umf_result_t os_close_ipc_handle(void *provider, void *ptr,
14021402
}
14031403

14041404
static umf_memory_provider_ops_t UMF_OS_MEMORY_PROVIDER_OPS = {
1405-
.version = UMF_VERSION_CURRENT,
1405+
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
14061406
.initialize = os_initialize,
14071407
.finalize = os_finalize,
14081408
.alloc = os_alloc,

0 commit comments

Comments
 (0)