|
1 | 1 | /*
|
2 | 2 | *
|
3 |
| - * Copyright (C) 2023-2024 Intel Corporation |
| 3 | + * Copyright (C) 2023-2025 Intel Corporation |
4 | 4 | *
|
5 | 5 | * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
|
6 | 6 | * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
19 | 19 |
|
20 | 20 | #include <umf/base.h>
|
21 | 21 | #include <umf/memory_provider.h>
|
| 22 | +#include <umf/pools/pool_disjoint.h> |
22 | 23 |
|
23 | 24 | #include "base.hpp"
|
24 | 25 | #include "cpp_helpers.hpp"
|
@@ -150,6 +151,49 @@ struct malloc_pool : public pool_base_t {
|
150 | 151 | umf_memory_pool_ops_t MALLOC_POOL_OPS =
|
151 | 152 | umf::poolMakeCOps<umf_test::malloc_pool, void>();
|
152 | 153 |
|
| 154 | +static constexpr size_t DEFAULT_DISJOINT_SLAB_MIN_SIZE = 4096; |
| 155 | +static constexpr size_t DEFAULT_DISJOINT_MAX_POOLABLE_SIZE = 4096; |
| 156 | +static constexpr size_t DEFAULT_DISJOINT_CAPACITY = 4; |
| 157 | +static constexpr size_t DEFAULT_DISJOINT_MIN_BUCKET_SIZE = 64; |
| 158 | + |
| 159 | +inline void *defaultDisjointPoolConfig() { |
| 160 | + umf_disjoint_pool_params_handle_t config = nullptr; |
| 161 | + umf_result_t res = umfDisjointPoolParamsCreate(&config); |
| 162 | + if (res != UMF_RESULT_SUCCESS) { |
| 163 | + throw std::runtime_error("Failed to create pool params"); |
| 164 | + } |
| 165 | + res = umfDisjointPoolParamsSetSlabMinSize(config, |
| 166 | + DEFAULT_DISJOINT_SLAB_MIN_SIZE); |
| 167 | + if (res != UMF_RESULT_SUCCESS) { |
| 168 | + umfDisjointPoolParamsDestroy(config); |
| 169 | + throw std::runtime_error("Failed to set slab min size"); |
| 170 | + } |
| 171 | + res = umfDisjointPoolParamsSetMaxPoolableSize( |
| 172 | + config, DEFAULT_DISJOINT_MAX_POOLABLE_SIZE); |
| 173 | + if (res != UMF_RESULT_SUCCESS) { |
| 174 | + umfDisjointPoolParamsDestroy(config); |
| 175 | + throw std::runtime_error("Failed to set max poolable size"); |
| 176 | + } |
| 177 | + res = umfDisjointPoolParamsSetCapacity(config, DEFAULT_DISJOINT_CAPACITY); |
| 178 | + if (res != UMF_RESULT_SUCCESS) { |
| 179 | + umfDisjointPoolParamsDestroy(config); |
| 180 | + throw std::runtime_error("Failed to set capacity"); |
| 181 | + } |
| 182 | + res = umfDisjointPoolParamsSetMinBucketSize( |
| 183 | + config, DEFAULT_DISJOINT_MIN_BUCKET_SIZE); |
| 184 | + if (res != UMF_RESULT_SUCCESS) { |
| 185 | + umfDisjointPoolParamsDestroy(config); |
| 186 | + throw std::runtime_error("Failed to set min bucket size"); |
| 187 | + } |
| 188 | + |
| 189 | + return config; |
| 190 | +} |
| 191 | + |
| 192 | +inline umf_result_t defaultDisjointPoolConfigDestroy(void *config) { |
| 193 | + return umfDisjointPoolParamsDestroy( |
| 194 | + static_cast<umf_disjoint_pool_params_handle_t>(config)); |
| 195 | +} |
| 196 | + |
153 | 197 | } // namespace umf_test
|
154 | 198 |
|
155 | 199 | #endif /* UMF_TEST_POOL_HPP */
|
0 commit comments