Skip to content

Commit e93a980

Browse files
committed
add fixed provider
1 parent 9bf1316 commit e93a980

File tree

8 files changed

+744
-5
lines changed

8 files changed

+744
-5
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2024 Intel Corporation
3+
*
4+
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*/
7+
8+
#ifndef UMF_FIXED_MEMORY_PROVIDER_H
9+
#define UMF_FIXED_MEMORY_PROVIDER_H
10+
11+
#include <umf/providers/provider_os_memory.h>
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
/// @cond
18+
#define UMF_FIXED_RESULTS_START_FROM 4000
19+
/// @endcond
20+
21+
struct umf_fixed_memory_provider_params_t;
22+
23+
typedef struct umf_fixed_memory_provider_params_t
24+
*umf_fixed_memory_provider_params_handle_t;
25+
26+
/// @brief Create a struct to store parameters of the Fixed Memory Provider.
27+
/// @param hParams [out] handle to the newly created parameters struct.
28+
/// @param ptr [in] pointer to the memory region.
29+
/// @param size [in] size of the memory region in bytes.
30+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
31+
umf_result_t umfFixedMemoryProviderParamsCreate(
32+
umf_fixed_memory_provider_params_handle_t *hParams, void *ptr, size_t size);
33+
34+
/// @brief Destroy parameters struct.
35+
/// @param hParams [in] handle to the parameters of the Fixed Memory Provider.
36+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
37+
umf_result_t umfFixedMemoryProviderParamsDestroy(
38+
umf_fixed_memory_provider_params_handle_t hParams);
39+
40+
/// @brief Retrieve the operations structure for the Fixed Memory Provider.
41+
/// @return Pointer to the umf_memory_provider_ops_t structure.
42+
umf_memory_provider_ops_t *umfFixedMemoryProviderOps(void);
43+
44+
/// @brief Fixed Memory Provider operation results
45+
typedef enum umf_fixed_memory_provider_native_error {
46+
UMF_FIXED_RESULT_SUCCESS = UMF_FIXED_RESULTS_START_FROM, ///< Success
47+
UMF_FIXED_RESULT_ERROR_PURGE_FORCE_FAILED, ///< Force purging failed
48+
} umf_fixed_memory_provider_native_error_t;
49+
50+
#ifdef __cplusplus
51+
}
52+
#endif
53+
54+
#endif /* UMF_FIXED_MEMORY_PROVIDER_H */

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ set(UMF_SOURCES
6262
provider/provider_cuda.c
6363
provider/provider_devdax_memory.c
6464
provider/provider_file_memory.c
65+
provider/provider_fixed_memory.c
6566
provider/provider_level_zero.c
6667
provider/provider_os_memory.c
6768
provider/provider_tracking.c

src/coarse/coarse.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,11 @@ umf_result_t coarse_alloc(coarse_t *coarse, size_t size, size_t alignment,
10301030
alignment = ALIGN_UP(alignment, coarse->page_size);
10311031
}
10321032

1033+
if (size + alignment < size) {
1034+
LOG_ERR("size + alignment overflow");
1035+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1036+
}
1037+
10331038
if (utils_mutex_lock(&coarse->lock) != 0) {
10341039
LOG_ERR("locking the lock failed");
10351040
return UMF_RESULT_ERROR_UNKNOWN;

src/libumf.def

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,23 @@ EXPORTS
2020
umfCUDAMemoryProviderParamsSetContext
2121
umfCUDAMemoryProviderParamsSetDevice
2222
umfCUDAMemoryProviderParamsSetMemoryType
23+
umfCoarseMemoryProviderGetStats
24+
umfCoarseMemoryProviderOps
2325
umfDevDaxMemoryProviderOps
2426
umfDevDaxMemoryProviderParamsCreate
2527
umfDevDaxMemoryProviderParamsDestroy
2628
umfDevDaxMemoryProviderParamsSetDeviceDax
2729
umfDevDaxMemoryProviderParamsSetProtection
28-
umfFree
2930
umfFileMemoryProviderOps
3031
umfFileMemoryProviderParamsCreate
3132
umfFileMemoryProviderParamsDestroy
3233
umfFileMemoryProviderParamsSetPath
3334
umfFileMemoryProviderParamsSetProtection
3435
umfFileMemoryProviderParamsSetVisibility
36+
umfFixedMemoryProviderOps
37+
umfFixedMemoryProviderParamsCreate
38+
umfFixedMemoryProviderParamsDestroy
39+
umfFree
3540
umfGetIPCHandle
3641
umfGetLastFailedMemoryProvider
3742
umfJemallocPoolOps

src/libumf.map

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@ UMF_1.0 {
1414
umfCUDAMemoryProviderParamsSetContext;
1515
umfCUDAMemoryProviderParamsSetDevice;
1616
umfCUDAMemoryProviderParamsSetMemoryType;
17+
umfCoarseMemoryProviderGetStats;
18+
umfCoarseMemoryProviderOps;
1719
umfDevDaxMemoryProviderOps;
1820
umfDevDaxMemoryProviderParamsCreate;
1921
umfDevDaxMemoryProviderParamsDestroy;
2022
umfDevDaxMemoryProviderParamsSetDeviceDax;
2123
umfDevDaxMemoryProviderParamsSetProtection;
22-
umfFree;
2324
umfFileMemoryProviderOps;
2425
umfFileMemoryProviderParamsCreate;
2526
umfFileMemoryProviderParamsDestroy;
2627
umfFileMemoryProviderParamsSetPath;
2728
umfFileMemoryProviderParamsSetProtection;
2829
umfFileMemoryProviderParamsSetVisibility;
30+
umfFixedMemoryProviderOps;
31+
umfFixedMemoryProviderParamsCreate;
32+
umfFixedMemoryProviderParamsDestroy;
33+
umfFree;
2934
umfGetIPCHandle;
3035
umfGetLastFailedMemoryProvider;
3136
umfJemallocPoolOps;
@@ -81,13 +86,13 @@ UMF_1.0 {
8186
umfOsMemoryProviderOps;
8287
umfOsMemoryProviderParamsCreate;
8388
umfOsMemoryProviderParamsDestroy;
84-
umfOsMemoryProviderParamsSetProtection;
85-
umfOsMemoryProviderParamsSetVisibility;
86-
umfOsMemoryProviderParamsSetShmName;
8789
umfOsMemoryProviderParamsSetNumaList;
8890
umfOsMemoryProviderParamsSetNumaMode;
8991
umfOsMemoryProviderParamsSetPartSize;
9092
umfOsMemoryProviderParamsSetPartitions;
93+
umfOsMemoryProviderParamsSetProtection;
94+
umfOsMemoryProviderParamsSetShmName;
95+
umfOsMemoryProviderParamsSetVisibility;
9196
umfPoolAlignedMalloc;
9297
umfPoolByPtr;
9398
umfPoolCalloc;

0 commit comments

Comments
 (0)