Skip to content

Commit ed0d5f3

Browse files
committed
add separate versioning to ops structures
1 parent c80d2b2 commit ed0d5f3

28 files changed

+86
-67
lines changed

examples/custom_file_provider/custom_file_provider.c

+2-2
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

+1-6
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

+6-1
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
///
2530
typedef struct umf_memory_pool_ops_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
///

include/umf/memory_provider_ops.h

+7-2
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,6 +16,11 @@
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
@@ -143,7 +148,7 @@ typedef struct umf_memory_provider_ipc_ops_t {
143148
///
144149
typedef struct umf_memory_provider_ops_t {
145150
/// Version of the ops structure.
146-
/// Should be initialized using UMF_VERSION_CURRENT.
151+
/// Should be initialized using UMF_PROVIDER_OPS_VERSION_CURRENT.
147152
uint32_t version;
148153

149154
///

src/cpp_helpers.hpp

+3-3
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/ipc.c

+4-3
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 "base_alloc_global.h"
1616
#include "ipc_internal.h"
1717
#include "memory_pool_internal.h"
18+
#include "memory_provider_internal.h"
1819
#include "provider/provider_tracking.h"
1920
#include "utils_common.h"
2021
#include "utils_log.h"
@@ -123,14 +124,14 @@ umf_result_t umfOpenIPCHandle(umf_ipc_handler_handle_t hIPCHandler,
123124
umf_ipc_handle_t umfIPCHandle, void **ptr) {
124125

125126
// IPC handler is an instance of tracking memory provider
126-
if (*(uint32_t *)hIPCHandler != UMF_VERSION_CURRENT) {
127+
umf_memory_provider_handle_t hProvider = hIPCHandler;
128+
if (hProvider->ops.version != UMF_PROVIDER_OPS_VERSION_CURRENT) {
127129
// It is a temporary hack to verify that user passes correct IPC handler,
128130
// not a pool handle, as it was required in previous version.
129131
LOG_ERR("Invalid IPC handler.");
130132
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
131133
}
132134

133-
umf_memory_provider_handle_t hProvider = hIPCHandler;
134135
void *base = NULL;
135136

136137
umf_result_t ret = umfMemoryProviderOpenIPCHandle(

src/memory_pool.c

+6-2
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

+7-8
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
@@ -20,11 +20,6 @@
2020
#include "memory_provider_internal.h"
2121
#include "utils_assert.h"
2222

23-
typedef struct umf_memory_provider_t {
24-
umf_memory_provider_ops_t ops;
25-
void *provider_priv;
26-
} umf_memory_provider_t;
27-
2823
static umf_result_t umfDefaultPurgeLazy(void *provider, void *ptr,
2924
size_t size) {
3025
(void)provider;
@@ -167,14 +162,18 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
167162
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
168163
}
169164

165+
if (ops->version != UMF_PROVIDER_OPS_VERSION_CURRENT) {
166+
LOG_WARN("Memory Provider ops version \"%d\" is different than the "
167+
"current version \"%d\"",
168+
ops->version, UMF_PROVIDER_OPS_VERSION_CURRENT);
169+
}
170+
170171
umf_memory_provider_handle_t provider =
171172
umf_ba_global_alloc(sizeof(umf_memory_provider_t));
172173
if (!provider) {
173174
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
174175
}
175176

176-
assert(ops->version == UMF_VERSION_CURRENT);
177-
178177
provider->ops = *ops;
179178

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

src/memory_provider_internal.h

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
extern "C" {
1919
#endif
2020

21+
typedef struct umf_memory_provider_t {
22+
umf_memory_provider_ops_t ops;
23+
void *provider_priv;
24+
} umf_memory_provider_t;
25+
2126
void *umfMemoryProviderGetPriv(umf_memory_provider_handle_t hProvider);
2227
umf_memory_provider_handle_t *umfGetLastFailedMemoryProviderPtr(void);
2328

src/memtarget.c

+7-2
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

+1-2
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

+7-2
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,9 +18,14 @@
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.
23-
/// Should be initialized using UMF_VERSION_CURRENT
28+
/// Should be initialized using UMF_MEMTARGET_OPS_VERSION_CURRENT
2429
uint32_t version;
2530

2631
umf_result_t (*initialize)(void *params, void **memoryTarget);

src/memtargets/memtarget_numa.c

+2-2
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

+2-2
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

+2-2
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -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

+2-2
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,8 @@ cu_memory_provider_close_ipc_handle(void *provider, void *ptr, size_t size) {
680680
return UMF_RESULT_SUCCESS;
681681
}
682682

683-
static struct umf_memory_provider_ops_t UMF_CUDA_MEMORY_PROVIDER_OPS = {
684-
.version = UMF_VERSION_CURRENT,
683+
static umf_memory_provider_ops_t UMF_CUDA_MEMORY_PROVIDER_OPS = {
684+
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
685685
.initialize = cu_memory_provider_initialize,
686686
.finalize = cu_memory_provider_finalize,
687687
.alloc = cu_memory_provider_alloc,

src/provider/provider_devdax_memory.c

+2-2
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
@@ -530,7 +530,7 @@ static umf_result_t devdax_free(void *provider, void *ptr, size_t size) {
530530
}
531531

532532
static umf_memory_provider_ops_t UMF_DEVDAX_MEMORY_PROVIDER_OPS = {
533-
.version = UMF_VERSION_CURRENT,
533+
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
534534
.initialize = devdax_initialize,
535535
.finalize = devdax_finalize,
536536
.alloc = devdax_alloc,

0 commit comments

Comments
 (0)