Skip to content

Commit b6ec7a3

Browse files
authored
Merge pull request #1154 from oneapi-src/main
merge main to v0.12.x-dev
2 parents dcd7c9c + 9fb88d5 commit b6ec7a3

File tree

16 files changed

+181
-125
lines changed

16 files changed

+181
-125
lines changed

.github/workflows/reusable_basic.yml

+1-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
name: Ubuntu
1818
strategy:
1919
matrix:
20-
os: ['ubuntu-20.04', 'ubuntu-22.04']
20+
os: ['ubuntu-22.04', 'ubuntu-24.04']
2121
build_type: [Debug, Release]
2222
compiler: [{c: gcc, cxx: g++}]
2323
shared_library: ['OFF']
@@ -27,15 +27,6 @@ jobs:
2727
disable_hwloc: ['OFF']
2828
link_hwloc_statically: ['OFF']
2929
include:
30-
- os: 'ubuntu-20.04'
31-
build_type: Release
32-
compiler: {c: gcc-7, cxx: g++-7}
33-
shared_library: 'OFF'
34-
level_zero_provider: 'ON'
35-
cuda_provider: 'ON'
36-
install_tbb: 'ON'
37-
disable_hwloc: 'OFF'
38-
link_hwloc_statically: 'OFF'
3930
- os: 'ubuntu-22.04'
4031
build_type: Release
4132
compiler: {c: clang, cxx: clang++}

.github/workflows/reusable_compatibility.yml

-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ jobs:
9797
-DUMF_FORMAT_CODE_STYLE=OFF
9898
-DUMF_DEVELOPER_MODE=ON
9999
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
100-
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
101100
-DUMF_TESTS_FAIL_ON_SKIP=ON
102101
103102
- name: Build latest UMF
@@ -197,7 +196,6 @@ jobs:
197196
-DUMF_FORMAT_CODE_STYLE=OFF
198197
-DUMF_DEVELOPER_MODE=ON
199198
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
200-
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
201199
-DUMF_TESTS_FAIL_ON_SKIP=ON
202200
203201
- name: Build latest UMF

.github/workflows/reusable_fast.yml

+4-11
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ jobs:
4343
build_tests: 'ON'
4444
extra_build_options: '-DCMAKE_BUILD_TYPE=Release'
4545
simple_cmake: 'ON'
46-
# simplest CMake ubuntu-20.04
47-
- os: ubuntu-20.04
46+
# simplest CMake ubuntu-22.04
47+
- os: ubuntu-22.04
4848
build_tests: 'ON'
4949
extra_build_options: '-DCMAKE_BUILD_TYPE=Release'
5050
simple_cmake: 'ON'
@@ -69,19 +69,12 @@ jobs:
6969
run: vcpkg install
7070
shell: pwsh # Specifies PowerShell as the shell for running the script.
7171

72-
- name: Install dependencies (ubuntu-latest)
73-
if: matrix.os == 'ubuntu-latest'
72+
- name: Install dependencies
73+
if: matrix.os != 'windows-latest'
7474
run: |
7575
sudo apt-get update
7676
sudo apt-get install -y cmake libhwloc-dev libnuma-dev libtbb-dev
7777
78-
- name: Install dependencies (ubuntu-20.04)
79-
if: matrix.os == 'ubuntu-20.04'
80-
run: |
81-
sudo apt-get update
82-
sudo apt-get install -y cmake libnuma-dev libtbb-dev
83-
.github/scripts/install_hwloc.sh # install hwloc-2.3.0 instead of hwloc-2.1.0 present in the OS package
84-
8578
- name: Configure CMake
8679
if: matrix.simple_cmake == 'OFF'
8780
run: >

CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ else()
283283

284284
message(STATUS "hwloc CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
285285

286-
if(CMAKE_GENERATOR STREQUAL "Ninja")
286+
if(CMAKE_GENERATOR STREQUAL "Ninja" OR CMAKE_GENERATOR STREQUAL
287+
"Unix Makefiles")
287288
add_custom_command(
288289
COMMAND ${CMAKE_COMMAND}
289290
-DCMAKE_INSTALL_PREFIX=${hwloc_targ_BINARY_DIR} -B build
@@ -408,7 +409,7 @@ if(UMF_BUILD_LEVEL_ZERO_PROVIDER AND (NOT UMF_LEVEL_ZERO_INCLUDE_DIR))
408409
include(FetchContent)
409410

410411
set(LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
411-
set(LEVEL_ZERO_LOADER_TAG v1.19.2)
412+
set(LEVEL_ZERO_LOADER_TAG v1.20.2)
412413

413414
message(
414415
STATUS

benchmark/benchmark.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ static void multithreaded(benchmark::internal::Benchmark *benchmark) {
3535
benchmark->Threads(1);
3636
}
3737

38+
static void singlethreaded(benchmark::internal::Benchmark *benchmark) {
39+
benchmark->Threads(1);
40+
}
41+
3842
static void
3943
default_multiple_alloc_fix_size(benchmark::internal::Benchmark *benchmark) {
4044
benchmark->Args({10000, 1, 4096});
@@ -68,15 +72,17 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, proxy_pool,
6872
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, proxy_pool)
6973
->Apply(&default_multiple_alloc_fix_size)
7074
// reduce iterations, as this benchmark is slower than others
71-
->Iterations(50000);
75+
->Iterations(50000)
76+
->Apply(&singlethreaded);
7277

7378
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, os_provider,
7479
fixed_alloc_size,
7580
provider_allocator<os_provider>);
7681
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, os_provider)
7782
->Apply(&default_multiple_alloc_fix_size)
7883
// reduce iterations, as this benchmark is slower than others
79-
->Iterations(50000);
84+
->Iterations(50000)
85+
->Apply(&singlethreaded);
8086

8187
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, disjoint_pool_fix,
8288
fixed_alloc_size,
@@ -89,8 +95,9 @@ UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
8995
disjoint_pool_uniform, uniform_alloc_size,
9096
pool_allocator<disjoint_pool<os_provider>>);
9197
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, disjoint_pool_uniform)
92-
->Apply(&default_multiple_alloc_uniform_size);
93-
// TODO: enable
98+
->Apply(&default_multiple_alloc_uniform_size)
99+
->Apply(&singlethreaded);
100+
// TODO: change to multithreaded
94101
//->Apply(&multithreaded);
95102

96103
#ifdef UMF_POOL_JEMALLOC_ENABLED

examples/ipc_level_zero/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ endif()
2424
include(FetchContent)
2525

2626
set(LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
27-
set(LEVEL_ZERO_LOADER_TAG v1.19.2)
27+
set(LEVEL_ZERO_LOADER_TAG v1.20.2)
2828

2929
message(
3030
STATUS

examples/level_zero_shared_memory/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ endif()
2424
include(FetchContent)
2525

2626
set(LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
27-
set(LEVEL_ZERO_LOADER_TAG v1.19.2)
27+
set(LEVEL_ZERO_LOADER_TAG v1.20.2)
2828

2929
message(
3030
STATUS

src/coarse/coarse.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -1170,10 +1170,13 @@ umf_result_t coarse_free(coarse_t *coarse, void *ptr, size_t bytes) {
11701170
}
11711171

11721172
block_t *block = get_node_block(node);
1173-
assert(block->used);
1173+
if (!block->used) {
1174+
LOG_ERR("double free");
1175+
utils_mutex_unlock(&coarse->lock);
1176+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1177+
}
11741178

11751179
if (bytes > 0 && bytes != block->size) {
1176-
// wrong size of allocation
11771180
LOG_ERR("wrong size of allocation");
11781181
utils_mutex_unlock(&coarse->lock);
11791182
return UMF_RESULT_ERROR_INVALID_ARGUMENT;

src/pool/pool_disjoint.c

+31-6
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,10 @@ void *disjoint_pool_aligned_malloc(void *pool, size_t size, size_t alignment) {
752752
}
753753

754754
void *aligned_ptr = (void *)ALIGN_UP_SAFE((size_t)ptr, alignment);
755-
VALGRIND_DO_MEMPOOL_ALLOC(disjoint_pool, aligned_ptr, size);
756-
utils_annotate_memory_undefined(aligned_ptr, size);
755+
size_t diff = (ptrdiff_t)aligned_ptr - (ptrdiff_t)ptr;
756+
size_t real_size = bucket->size - diff;
757+
VALGRIND_DO_MEMPOOL_ALLOC(disjoint_pool, aligned_ptr, real_size);
758+
utils_annotate_memory_undefined(aligned_ptr, real_size);
757759

758760
utils_mutex_unlock(&bucket->bucket_lock);
759761

@@ -767,11 +769,34 @@ void *disjoint_pool_aligned_malloc(void *pool, size_t size, size_t alignment) {
767769
}
768770

769771
size_t disjoint_pool_malloc_usable_size(void *pool, void *ptr) {
770-
(void)pool;
771-
(void)ptr;
772+
disjoint_pool_t *disjoint_pool = (disjoint_pool_t *)pool;
773+
if (ptr == NULL) {
774+
return 0;
775+
}
772776

773-
// Not supported
774-
return 0;
777+
// check if given pointer is allocated inside any Disjoint Pool slab
778+
slab_t *slab =
779+
(slab_t *)critnib_find_le(disjoint_pool->known_slabs, (uintptr_t)ptr);
780+
if (slab == NULL || ptr >= slab_get_end(slab)) {
781+
// memory comes directly from the provider
782+
umf_alloc_info_t allocInfo = {NULL, 0, NULL};
783+
umf_result_t ret = umfMemoryTrackerGetAllocInfo(ptr, &allocInfo);
784+
if (ret != UMF_RESULT_SUCCESS) {
785+
return 0;
786+
}
787+
788+
return allocInfo.baseSize;
789+
}
790+
// Get the unaligned pointer
791+
// NOTE: the base pointer slab->mem_ptr needn't to be aligned to bucket size
792+
size_t chunk_idx =
793+
(((uintptr_t)ptr - (uintptr_t)slab->mem_ptr) / slab->bucket->size);
794+
void *unaligned_ptr =
795+
(void *)((uintptr_t)slab->mem_ptr + chunk_idx * slab->bucket->size);
796+
797+
ptrdiff_t diff = (ptrdiff_t)ptr - (ptrdiff_t)unaligned_ptr;
798+
799+
return slab->bucket->size - diff;
775800
}
776801

777802
umf_result_t disjoint_pool_free(void *pool, void *ptr) {

src/provider/provider_tracking.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -291,26 +291,26 @@ static umf_result_t trackingAllocationMerge(void *hProvider, void *lowPtr,
291291
tracker_alloc_info_t *lowValue = (tracker_alloc_info_t *)critnib_get(
292292
provider->hTracker->alloc_segments_map, (uintptr_t)lowPtr);
293293
if (!lowValue) {
294-
LOG_ERR("no left value");
294+
LOG_FATAL("no left value");
295295
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
296-
goto err;
296+
goto err_assert;
297297
}
298298
tracker_alloc_info_t *highValue = (tracker_alloc_info_t *)critnib_get(
299299
provider->hTracker->alloc_segments_map, (uintptr_t)highPtr);
300300
if (!highValue) {
301-
LOG_ERR("no right value");
301+
LOG_FATAL("no right value");
302302
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
303-
goto err;
303+
goto err_assert;
304304
}
305305
if (lowValue->pool != highValue->pool) {
306-
LOG_ERR("pool mismatch");
306+
LOG_FATAL("pool mismatch");
307307
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
308-
goto err;
308+
goto err_assert;
309309
}
310310
if (lowValue->size + highValue->size != totalSize) {
311-
LOG_ERR("lowValue->size + highValue->size != totalSize");
311+
LOG_FATAL("lowValue->size + highValue->size != totalSize");
312312
ret = UMF_RESULT_ERROR_INVALID_ARGUMENT;
313-
goto err;
313+
goto err_assert;
314314
}
315315

316316
ret = umfMemoryProviderAllocationMerge(provider->hUpstream, lowPtr, highPtr,
@@ -342,7 +342,7 @@ static umf_result_t trackingAllocationMerge(void *hProvider, void *lowPtr,
342342

343343
return UMF_RESULT_SUCCESS;
344344

345-
err:
345+
err_assert:
346346
assert(0);
347347

348348
not_merged:

test/coarse_lib.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ TEST_P(CoarseWithMemoryStrategyTest, coarseTest_basic_provider) {
160160
ASSERT_EQ(coarse_get_stats(ch).alloc_size, alloc_size);
161161
ASSERT_EQ(coarse_get_stats(ch).num_all_blocks, 1);
162162

163+
// test double free
164+
umf_result = coarse_free(ch, ptr, 2 * MB);
165+
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
166+
ASSERT_EQ(coarse_get_stats(ch).used_size, 0);
167+
ASSERT_EQ(coarse_get_stats(ch).alloc_size, alloc_size);
168+
ASSERT_EQ(coarse_get_stats(ch).num_all_blocks, 1);
169+
163170
coarse_delete(ch);
164171
umfMemoryProviderDestroy(malloc_memory_provider);
165172
}
@@ -202,6 +209,13 @@ TEST_P(CoarseWithMemoryStrategyTest, coarseTest_basic_fixed_memory) {
202209
ASSERT_EQ(coarse_get_stats(ch).alloc_size, buff_size);
203210
ASSERT_EQ(coarse_get_stats(ch).num_all_blocks, 1);
204211

212+
// test double free
213+
umf_result = coarse_free(ch, ptr, 2 * MB);
214+
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
215+
ASSERT_EQ(coarse_get_stats(ch).used_size, 0);
216+
ASSERT_EQ(coarse_get_stats(ch).alloc_size, buff_size);
217+
ASSERT_EQ(coarse_get_stats(ch).num_all_blocks, 1);
218+
205219
coarse_delete(ch);
206220
}
207221

test/common/pool.hpp

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2024 Intel Corporation
3+
* Copyright (C) 2023-2025 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
@@ -19,6 +19,7 @@
1919

2020
#include <umf/base.h>
2121
#include <umf/memory_provider.h>
22+
#include <umf/pools/pool_disjoint.h>
2223

2324
#include "base.hpp"
2425
#include "cpp_helpers.hpp"
@@ -150,6 +151,49 @@ struct malloc_pool : public pool_base_t {
150151
umf_memory_pool_ops_t MALLOC_POOL_OPS =
151152
umf::poolMakeCOps<umf_test::malloc_pool, void>();
152153

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+
153197
} // namespace umf_test
154198

155199
#endif /* UMF_TEST_POOL_HPP */

test/memoryPoolAPI.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "test_helpers.h"
1313

1414
#include <umf/memory_provider.h>
15+
#include <umf/pools/pool_disjoint.h>
1516
#include <umf/pools/pool_proxy.h>
1617

1718
#ifdef UMF_PROXY_LIB_ENABLED
@@ -295,12 +296,14 @@ TEST_F(tagTest, SetAndGetInvalidPool) {
295296

296297
INSTANTIATE_TEST_SUITE_P(
297298
mallocPoolTest, umfPoolTest,
298-
::testing::Values(poolCreateExtParams{&MALLOC_POOL_OPS, nullptr, nullptr,
299-
&UMF_NULL_PROVIDER_OPS, nullptr,
300-
nullptr},
301-
poolCreateExtParams{umfProxyPoolOps(), nullptr, nullptr,
302-
&BA_GLOBAL_PROVIDER_OPS, nullptr,
303-
nullptr}));
299+
::testing::Values(
300+
poolCreateExtParams{&MALLOC_POOL_OPS, nullptr, nullptr,
301+
&UMF_NULL_PROVIDER_OPS, nullptr, nullptr},
302+
poolCreateExtParams{umfProxyPoolOps(), nullptr, nullptr,
303+
&BA_GLOBAL_PROVIDER_OPS, nullptr, nullptr},
304+
poolCreateExtParams{umfDisjointPoolOps(), defaultDisjointPoolConfig,
305+
defaultDisjointPoolConfigDestroy,
306+
&BA_GLOBAL_PROVIDER_OPS, nullptr, nullptr}));
304307

305308
INSTANTIATE_TEST_SUITE_P(mallocMultiPoolTest, umfMultiPoolTest,
306309
::testing::Values(poolCreateExtParams{

0 commit comments

Comments
 (0)