Skip to content

Commit d05a57b

Browse files
committed
add GetCacheLineSize() op to memory provider
1 parent 5d093ed commit d05a57b

27 files changed

Lines changed: 531 additions & 29 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

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);

src/provider/provider_cuda.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024-2025 Intel Corporation
2+
* Copyright (C) 2024-2026 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
@@ -825,6 +825,14 @@ static umf_result_t cu_memory_provider_get_allocation_properties_size(
825825
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
826826
}
827827

828+
static umf_result_t cu_memory_provider_get_cache_line_size(void *provider,
829+
size_t *size) {
830+
(void)provider;
831+
832+
*size = 128;
833+
return UMF_RESULT_SUCCESS;
834+
}
835+
828836
static umf_memory_provider_ops_t UMF_CUDA_MEMORY_PROVIDER_OPS = {
829837
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
830838
.initialize = cu_memory_provider_initialize,
@@ -834,6 +842,7 @@ static umf_memory_provider_ops_t UMF_CUDA_MEMORY_PROVIDER_OPS = {
834842
.get_last_native_error = cu_memory_provider_get_last_native_error,
835843
.get_recommended_page_size = cu_memory_provider_get_recommended_page_size,
836844
.get_min_page_size = cu_memory_provider_get_min_page_size,
845+
.get_cache_line_size = cu_memory_provider_get_cache_line_size,
837846
.get_name = cu_memory_provider_get_name,
838847
// TODO
839848
/*

src/provider/provider_devdax_memory.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024-2025 Intel Corporation
2+
* Copyright (C) 2024-2026 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
@@ -589,6 +589,13 @@ static umf_result_t devdax_free(void *provider, void *ptr, size_t size) {
589589
return ret;
590590
}
591591

592+
static umf_result_t devdax_get_cache_line_size(void *provider, size_t *size) {
593+
(void)provider;
594+
595+
*size = 64;
596+
return UMF_RESULT_SUCCESS;
597+
}
598+
592599
static umf_memory_provider_ops_t UMF_DEVDAX_MEMORY_PROVIDER_OPS = {
593600
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
594601
.initialize = devdax_initialize,
@@ -598,6 +605,7 @@ static umf_memory_provider_ops_t UMF_DEVDAX_MEMORY_PROVIDER_OPS = {
598605
.get_last_native_error = devdax_get_last_native_error,
599606
.get_recommended_page_size = devdax_get_recommended_page_size,
600607
.get_min_page_size = devdax_get_min_page_size,
608+
.get_cache_line_size = devdax_get_cache_line_size,
601609
.get_name = devdax_get_name,
602610
.ext_purge_lazy = devdax_purge_lazy,
603611
.ext_purge_force = devdax_purge_force,

0 commit comments

Comments
 (0)