|
| 1 | +/* |
| 2 | + * Copyright (C) 2023-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_COARSE_PROVIDER_H |
| 9 | +#define UMF_COARSE_PROVIDER_H |
| 10 | + |
| 11 | +#include <stdbool.h> |
| 12 | +#include <umf/memory_provider.h> |
| 13 | + |
| 14 | +#if defined(__cplusplus) |
| 15 | +extern "C" { |
| 16 | +#endif |
| 17 | + |
| 18 | +/// @brief Coarse Memory Provider settings struct. |
| 19 | +typedef struct coarse_memory_provider_params_t { |
| 20 | + /// Handle to the upstream memory provider, could be NULL. |
| 21 | + umf_memory_provider_handle_t upstream_memory_provider; |
| 22 | + |
| 23 | + /// When set, the init buffer would be pre-allocated (with |
| 24 | + /// `init_buffer_size` bytes) during creation time. The memory used to |
| 25 | + /// pre-allocate it would be taken either from the `init_buffer` or from |
| 26 | + /// the `upstream_memory_provider`, so either one of them has to be set. |
| 27 | + bool immediate_init; |
| 28 | + |
| 29 | + /// Init buffer used to pre-allocate memory at the creation time, could be |
| 30 | + /// NULL. |
| 31 | + void *init_buffer; |
| 32 | + |
| 33 | + /// Size of the pre-allocated buffer. If the `init_buffer` is set, the |
| 34 | + /// `init_buffer_size` should be the size of this buffer. |
| 35 | + size_t init_buffer_size; |
| 36 | +} coarse_memory_provider_params_t; |
| 37 | + |
| 38 | +/// @brief Coarse Memory Provider stats (TODO move to CTL) |
| 39 | +typedef struct coarse_memory_provider_stats_t { |
| 40 | + /// Total allocation size. |
| 41 | + size_t alloc_size; |
| 42 | + |
| 43 | + /// Size of used memory. |
| 44 | + size_t used_size; |
| 45 | + |
| 46 | + /// Number of memory blocks allocated from the upstream provider. |
| 47 | + size_t upstream_blocks_num; |
| 48 | + |
| 49 | + /// Total number of allocated memory blocks. |
| 50 | + size_t blocks_num; |
| 51 | + |
| 52 | + /// Number of free memory blocks. |
| 53 | + size_t free_blocks_num; |
| 54 | +} coarse_memory_provider_stats_t; |
| 55 | + |
| 56 | +umf_memory_provider_ops_t *umfCoarseMemoryProviderOps(void); |
| 57 | + |
| 58 | +// TODO use CTL |
| 59 | +coarse_memory_provider_stats_t |
| 60 | +umfCoarseMemoryProviderGetStats(umf_memory_provider_handle_t provider); |
| 61 | + |
| 62 | +#ifdef __cplusplus |
| 63 | +} |
| 64 | +#endif |
| 65 | + |
| 66 | +#endif // UMF_coarse_PROVIDER_H |
0 commit comments