Skip to content

Commit 3e3a870

Browse files
authored
Merge pull request #1587 from bratpiorka/rrudnick_get_cacheline_size
add GetCacheLineSize() op to memory provider and use it to initialize DP min bucket size
2 parents fce113a + f7e4994 commit 3e3a870

32 files changed

Lines changed: 621 additions & 93 deletions

examples/ctl/custom_ctl.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2025 Intel Corporation
3+
* Copyright (C) 2025-2026 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
@@ -92,6 +92,12 @@ static umf_result_t ctl_get_min_page_size(void *provider, const void *ptr,
9292
return UMF_RESULT_SUCCESS;
9393
}
9494

95+
static umf_result_t ctl_get_cache_line_size(void *provider, size_t *size) {
96+
(void)provider;
97+
*size = 64;
98+
return UMF_RESULT_SUCCESS;
99+
}
100+
95101
static umf_result_t ctl_get_name(void *provider, const char **name) {
96102
(void)provider;
97103
if (name) {
@@ -243,6 +249,7 @@ static umf_memory_provider_ops_t ctl_ops = {
243249
.get_last_native_error = ctl_get_last_native_error,
244250
.get_recommended_page_size = ctl_get_recommended_page_size,
245251
.get_min_page_size = ctl_get_min_page_size,
252+
.get_cache_line_size = ctl_get_cache_line_size,
246253
.get_name = ctl_get_name,
247254
.ext_ctl = ctl_ctl, // register CTL handler
248255
};

examples/custom_file_provider/custom_file_provider.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2024-2025 Intel Corporation
3+
* Copyright (C) 2024-2026 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
@@ -240,6 +240,12 @@ static umf_result_t file_get_min_page_size(void *provider, const void *ptr,
240240
return UMF_RESULT_SUCCESS;
241241
}
242242

243+
static umf_result_t file_get_cache_line_size(void *provider, size_t *size) {
244+
(void)provider;
245+
*size = 64;
246+
return UMF_RESULT_SUCCESS;
247+
}
248+
243249
// File provider operations
244250
static umf_memory_provider_ops_t file_ops = {
245251
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
@@ -251,6 +257,7 @@ static umf_memory_provider_ops_t file_ops = {
251257
.get_last_native_error = file_get_last_native_error,
252258
.get_recommended_page_size = file_get_recommended_page_size,
253259
.get_min_page_size = file_get_min_page_size,
260+
.get_cache_line_size = file_get_cache_line_size,
254261
};
255262

256263
// Main function

include/umf/memory_provider.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2025 Intel Corporation
3+
* Copyright (C) 2023-2026 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
@@ -129,6 +129,16 @@ umf_result_t
129129
umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider,
130130
const void *ptr, size_t *pageSize);
131131

132+
///
133+
/// @brief Retrieve cache line size for memory allocated by the provider.
134+
/// @param hProvider handle to the memory provider
135+
/// @param size [out] pointer to the cache line size
136+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
137+
///
138+
umf_result_t
139+
umfMemoryProviderGetCacheLineSize(umf_memory_provider_handle_t hProvider,
140+
size_t *size);
141+
132142
///
133143
/// @brief Discard physical pages within the virtual memory mapping associated at the given addr
134144
/// and \p size. This call is asynchronous and may delay purging the pages indefinitely.

include/umf/memory_provider_ops.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2025 Intel Corporation
3+
* Copyright (C) 2023-2026 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
@@ -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, 1)
24+
#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(1, 2)
2525

2626
///
2727
/// @brief This structure comprises function pointers used by corresponding
@@ -326,6 +326,16 @@ typedef struct umf_memory_provider_ops_t {
326326
void *provider, umf_memory_property_id_t memory_property_id,
327327
size_t *size);
328328

329+
// The following operations were added in ops version 1.2
330+
331+
///
332+
/// @brief Retrieve cache line size for memory allocated by the provider.
333+
/// @param provider pointer to the memory provider
334+
/// @param size [out] pointer to the cache line size
335+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
336+
///
337+
umf_result_t (*get_cache_line_size)(void *provider, size_t *size);
338+
329339
} umf_memory_provider_ops_t;
330340

331341
#ifdef __cplusplus

include/umf/pools/pool_disjoint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2025 Intel Corporation
3+
* Copyright (C) 2023-2026 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
@@ -82,7 +82,7 @@ umfDisjointPoolParamsSetCapacity(umf_disjoint_pool_params_handle_t hParams,
8282
size_t maxCapacity);
8383

8484
/// @brief Set minimum bucket allocation size.
85-
/// @details Default value for minimum bucket size is 8.
85+
/// @details If not set, the pool uses the provider cache line size.
8686
/// @param hParams handle to the parameters of the disjoint pool.
8787
/// @param minBucketSize minimum bucket size. Must be power of 2.
8888
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.

src/libumf.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
;;;; Begin Copyright Notice
2-
; Copyright (C) 2023-2025 Intel Corporation
2+
; Copyright (C) 2023-2026 Intel Corporation
33
; Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
44
; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55
;;;; End Copyright Notice
66

77
LIBRARY UMF
88

9-
VERSION 1.1
9+
VERSION 1.2
1010

1111
EXPORTS
1212
DllMain
@@ -158,3 +158,5 @@ EXPORTS
158158
umfOsMemoryProviderParamsSetName
159159
umfPoolTrimMemory
160160
umfScalablePoolParamsSetName
161+
; Added in UMF_1.2
162+
umfMemoryProviderGetCacheLineSize

src/libumf.map

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2023-2025 Intel Corporation
1+
# Copyright (C) 2023-2026 Intel Corporation
22
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

@@ -157,3 +157,7 @@ UMF_1.1 {
157157
umfPoolTrimMemory;
158158
umfScalablePoolParamsSetName;
159159
} UMF_1.0;
160+
161+
UMF_1.2 {
162+
umfMemoryProviderGetCacheLineSize;
163+
} UMF_1.1;

src/libumf.rc.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2024-2025 Intel Corporation
1+
// Copyright (C) 2024-2026 Intel Corporation
22
//
33
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -53,7 +53,7 @@ BEGIN
5353
VALUE "CompanyName", "Intel Corporation\0"
5454
VALUE "FileDescription", "Unified Memory Framework (UMF) library (build options: " _UMF_CMAKE_VARS ")\0"
5555
VALUE "FileVersion", _UMF_VERSION "\0"
56-
VALUE "LegalCopyright", "Copyright 2024-2025, Intel Corporation. All rights reserved.\0"
56+
VALUE "LegalCopyright", "Copyright 2024-2026, Intel Corporation. All rights reserved.\0"
5757
VALUE "LegalTrademarks", "\0"
5858
VALUE "OriginalFilename", "umf.dll\0"
5959
VALUE "ProductName", "Unified Memory Framework (UMF)\0"

src/memory_provider.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ static umf_result_t umfDefaultGetAllocationPropertiesSize(
175175
return UMF_RESULT_ERROR_NOT_SUPPORTED;
176176
}
177177

178+
static umf_result_t umfDefaultGetCacheLineSize(void *provider, size_t *size) {
179+
(void)provider;
180+
181+
*size = 64;
182+
return UMF_RESULT_SUCCESS;
183+
}
184+
178185
void assignOpsExtDefaults(umf_memory_provider_ops_t *ops) {
179186
if (!ops->ext_purge_lazy) {
180187
ops->ext_purge_lazy = umfDefaultPurgeLazy;
@@ -263,6 +270,7 @@ static bool validateOps(const umf_memory_provider_ops_t *ops) {
263270
CHECK_OP(ops, free);
264271
CHECK_OP(ops, get_recommended_page_size);
265272
CHECK_OP(ops, get_min_page_size);
273+
CHECK_OP(ops, get_cache_line_size);
266274
CHECK_OP(ops, initialize);
267275
CHECK_OP(ops, finalize);
268276
CHECK_OP(ops, get_last_native_error);
@@ -321,6 +329,13 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
321329
memcpy(&compatible_ops, ops,
322330
offsetof(umf_memory_provider_ops_t,
323331
ext_get_allocation_properties));
332+
compatible_ops.get_cache_line_size = umfDefaultGetCacheLineSize;
333+
} else if (UMF_MINOR_VERSION(ops->version) == 1) {
334+
LOG_INFO("Detected 1.1 version of Memory Provider ops, "
335+
"upgrading to current version");
336+
memcpy(&compatible_ops, ops,
337+
offsetof(umf_memory_provider_ops_t, get_cache_line_size));
338+
compatible_ops.get_cache_line_size = umfDefaultGetCacheLineSize;
324339
} else {
325340
LOG_ERR("Unsupported Memory Provider ops version: %d",
326341
ops->version);
@@ -479,6 +494,19 @@ umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider,
479494
return res;
480495
}
481496

497+
umf_result_t
498+
umfMemoryProviderGetCacheLineSize(umf_memory_provider_handle_t hProvider,
499+
size_t *size) {
500+
UMF_CHECK((hProvider != NULL), UMF_RESULT_ERROR_INVALID_ARGUMENT);
501+
UMF_CHECK((size != NULL), UMF_RESULT_ERROR_INVALID_ARGUMENT);
502+
503+
umf_result_t res =
504+
hProvider->ops.get_cache_line_size(hProvider->provider_priv, size);
505+
506+
checkErrorAndSetLastProvider(res, hProvider);
507+
return res;
508+
}
509+
482510
umf_result_t umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider,
483511
const char **name) {
484512
UMF_CHECK((hProvider != NULL), UMF_RESULT_ERROR_INVALID_ARGUMENT);

0 commit comments

Comments
 (0)