Skip to content

Commit 6ae608c

Browse files
authored
Merge pull request #741 from kswiecicki/opt-pool-tracking-2
[umf] Make pool tracking optional
2 parents 2ffcda3 + ff705f5 commit 6ae608c

File tree

13 files changed

+278
-125
lines changed

13 files changed

+278
-125
lines changed

.github/workflows/cmake.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
build_type: [Debug, Release]
1212
compiler: [{c: gcc, cxx: g++}]
1313
libbacktrace: ['-DVAL_USE_LIBBACKTRACE_BACKTRACE=OFF']
14+
pool_tracking: ['-DUMF_ENABLE_POOL_TRACKING=ON', '-DUMF_ENABLE_POOL_TRACKING=OFF']
1415
include:
1516
- os: 'ubuntu-22.04'
1617
build_type: Release
@@ -53,9 +54,9 @@ jobs:
5354
cd libbacktrace
5455
./configure
5556
make
56-
sudo make install
57+
sudo make install
5758
cd ..
58-
59+
5960
- name: Download DPC++
6061
run: |
6162
sudo apt install libncurses5
@@ -75,6 +76,7 @@ jobs:
7576
-DUR_FORMAT_CPP_STYLE=ON
7677
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
7778
${{matrix.libbacktrace}}
79+
${{matrix.pool_tracking}}
7880
7981
- name: Generate source from spec, check for uncommitted diff
8082
if: matrix.os == 'ubuntu-22.04'
@@ -153,5 +155,6 @@ jobs:
153155
-DCMAKE_BUILD_TYPE=Release
154156
-DUR_BUILD_TESTS=ON
155157
-DUR_FORMAT_CPP_STYLE=ON
158+
-DUMF_ENABLE_POOL_TRACKING=ON
156159
- name: Build
157160
run: cmake --build ${{github.workspace}}/build -j $(nproc)

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
run: pip install -r third_party/requirements.txt
2828

2929
- name: Configure CMake
30-
run: cmake -B ${{github.workspace}}/build -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON -DUR_ENABLE_TRACING=ON -DUR_BUILD_TOOLS=ON
30+
run: cmake -B ${{github.workspace}}/build -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON -DUR_ENABLE_TRACING=ON -DUR_BUILD_TOOLS=ON -DUMF_ENABLE_POOL_TRACKING=ON
3131

3232
- name: Build
3333
run: cmake --build ${{github.workspace}}/build -j $(nproc)
@@ -61,7 +61,7 @@ jobs:
6161
run: python3 -m pip install -r third_party/requirements.txt
6262

6363
- name: Configure CMake
64-
run: cmake -B ${{github.workspace}}/build -DCMAKE_POLICY_DEFAULT_CMP0094=NEW -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON -DUR_ENABLE_TRACING=ON -DUR_BUILD_TOOLS=ON
64+
run: cmake -B ${{github.workspace}}/build -DCMAKE_POLICY_DEFAULT_CMP0094=NEW -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON -DUR_ENABLE_TRACING=ON -DUR_BUILD_TOOLS=ON -DUMF_ENABLE_POOL_TRACKING=ON
6565

6666
- name: Build
6767
run: cmake --build ${{github.workspace}}/build -j $(nproc) --config Release

.github/workflows/coverity.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
linux:
2727
name: Coverity
2828
runs-on: ubuntu-latest
29-
29+
3030
steps:
3131
- name: Clone the git repo
3232
uses: actions/checkout@v3
@@ -35,12 +35,12 @@ jobs:
3535
run: |
3636
sudo apt-get update
3737
sudo apt-get install -y doxygen
38-
38+
3939
- name: Install pip packages
4040
run: pip install -r third_party/requirements.txt
4141

4242
- name: Configure CMake
43-
run: cmake -B $WORKDIR/build -DUR_ENABLE_TRACING=ON -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON -DUR_FORMAT_CPP_STYLE=ON
43+
run: cmake -B $WORKDIR/build -DUR_ENABLE_TRACING=ON -DUR_DEVELOPER_MODE=ON -DUR_BUILD_TESTS=ON -DUR_FORMAT_CPP_STYLE=ON -DUMF_ENABLE_POOL_TRACKING=ON
4444

4545
- name: Generate source from spec, check for uncommitted diff
4646
run: |

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
3434
option(UR_ENABLE_TRACING "enable api tracing through xpti" OFF)
3535
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
3636
option(UR_BUILD_TOOLS "build ur tools" ON)
37+
option(UMF_ENABLE_POOL_TRACKING "Build UMF with pool tracking" OFF)
3738

3839
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
3940
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

source/common/unified_malloc_framework/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ else()
2222
${UMF_SOURCES})
2323
endif()
2424

25+
if (UMF_ENABLE_POOL_TRACKING)
26+
target_sources(unified_malloc_framework PRIVATE src/memory_pool_tracking.c)
27+
else()
28+
target_sources(unified_malloc_framework PRIVATE src/memory_pool_default.c)
29+
endif()
30+
2531
add_library(${PROJECT_NAME}::unified_malloc_framework ALIAS unified_malloc_framework)
2632

2733
target_include_directories(unified_malloc_framework PUBLIC include)

source/common/unified_malloc_framework/src/memory_pool.c

Lines changed: 1 addition & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -8,96 +8,14 @@
88
*
99
*/
1010

11-
#include "memory_provider_internal.h"
12-
#include "memory_tracker.h"
11+
#include "memory_pool_internal.h"
1312

1413
#include <umf/memory_pool.h>
1514
#include <umf/memory_pool_ops.h>
1615

1716
#include <assert.h>
1817
#include <stdlib.h>
1918

20-
struct umf_memory_pool_t {
21-
void *pool_priv;
22-
struct umf_memory_pool_ops_t ops;
23-
24-
// Holds array of memory providers. All providers are wrapped
25-
// by memory tracking providers (owned and released by UMF).
26-
umf_memory_provider_handle_t *providers;
27-
28-
size_t numProviders;
29-
};
30-
31-
static void
32-
destroyMemoryProviderWrappers(umf_memory_provider_handle_t *providers,
33-
size_t numProviders) {
34-
for (size_t i = 0; i < numProviders; i++) {
35-
umfMemoryProviderDestroy(providers[i]);
36-
}
37-
38-
free(providers);
39-
}
40-
41-
enum umf_result_t umfPoolCreate(const struct umf_memory_pool_ops_t *ops,
42-
umf_memory_provider_handle_t *providers,
43-
size_t numProviders, void *params,
44-
umf_memory_pool_handle_t *hPool) {
45-
if (!numProviders || !providers) {
46-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
47-
}
48-
49-
enum umf_result_t ret = UMF_RESULT_SUCCESS;
50-
umf_memory_pool_handle_t pool = malloc(sizeof(struct umf_memory_pool_t));
51-
if (!pool) {
52-
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
53-
}
54-
55-
assert(ops->version == UMF_VERSION_CURRENT);
56-
57-
pool->providers =
58-
calloc(numProviders, sizeof(umf_memory_provider_handle_t));
59-
if (!pool->providers) {
60-
ret = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
61-
goto err_providers_alloc;
62-
}
63-
64-
size_t providerInd = 0;
65-
pool->numProviders = numProviders;
66-
67-
// Wrap each provider with memory tracking provider.
68-
for (providerInd = 0; providerInd < numProviders; providerInd++) {
69-
ret = umfTrackingMemoryProviderCreate(providers[providerInd], pool,
70-
&pool->providers[providerInd]);
71-
if (ret != UMF_RESULT_SUCCESS) {
72-
goto err_providers_init;
73-
}
74-
}
75-
76-
pool->ops = *ops;
77-
ret = ops->initialize(pool->providers, pool->numProviders, params,
78-
&pool->pool_priv);
79-
if (ret != UMF_RESULT_SUCCESS) {
80-
goto err_pool_init;
81-
}
82-
83-
*hPool = pool;
84-
return UMF_RESULT_SUCCESS;
85-
86-
err_pool_init:
87-
err_providers_init:
88-
destroyMemoryProviderWrappers(pool->providers, providerInd);
89-
err_providers_alloc:
90-
free(pool);
91-
92-
return ret;
93-
}
94-
95-
void umfPoolDestroy(umf_memory_pool_handle_t hPool) {
96-
hPool->ops.finalize(hPool->pool_priv);
97-
destroyMemoryProviderWrappers(hPool->providers, hPool->numProviders);
98-
free(hPool);
99-
}
100-
10119
void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size) {
10220
return hPool->ops.malloc(hPool->pool_priv, size);
10321
}
@@ -123,41 +41,7 @@ enum umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr) {
12341
return hPool->ops.free(hPool->pool_priv, ptr);
12442
}
12543

126-
enum umf_result_t umfFree(void *ptr) {
127-
umf_memory_pool_handle_t hPool = umfPoolByPtr(ptr);
128-
if (hPool) {
129-
return umfPoolFree(hPool, ptr);
130-
}
131-
return UMF_RESULT_SUCCESS;
132-
}
133-
13444
enum umf_result_t
13545
umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool) {
13646
return hPool->ops.get_last_allocation_error(hPool->pool_priv);
13747
}
138-
139-
umf_memory_pool_handle_t umfPoolByPtr(const void *ptr) {
140-
return umfMemoryTrackerGetPool(umfMemoryTrackerGet(), ptr);
141-
}
142-
143-
enum umf_result_t
144-
umfPoolGetMemoryProviders(umf_memory_pool_handle_t hPool, size_t numProviders,
145-
umf_memory_provider_handle_t *hProviders,
146-
size_t *numProvidersRet) {
147-
if (hProviders && numProviders < hPool->numProviders) {
148-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
149-
}
150-
151-
if (numProvidersRet) {
152-
*numProvidersRet = hPool->numProviders;
153-
}
154-
155-
if (hProviders) {
156-
for (size_t i = 0; i < hPool->numProviders; i++) {
157-
umfTrackingMemoryProviderGetUpstreamProvider(
158-
umfMemoryProviderGetPriv(hPool->providers[i]), hProviders + i);
159-
}
160-
}
161-
162-
return UMF_RESULT_SUCCESS;
163-
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
*
3+
* Copyright (C) 2023 Intel Corporation
4+
*
5+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
6+
* See LICENSE.TXT
7+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
*
9+
*/
10+
11+
#include "memory_pool_internal.h"
12+
13+
#include <umf/memory_pool.h>
14+
15+
#include <assert.h>
16+
#include <stdlib.h>
17+
18+
enum umf_result_t umfPoolCreate(const struct umf_memory_pool_ops_t *ops,
19+
umf_memory_provider_handle_t *providers,
20+
size_t numProviders, void *params,
21+
umf_memory_pool_handle_t *hPool) {
22+
if (!numProviders || !providers) {
23+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
24+
}
25+
26+
enum umf_result_t ret = UMF_RESULT_SUCCESS;
27+
umf_memory_pool_handle_t pool = malloc(sizeof(struct umf_memory_pool_t));
28+
if (!pool) {
29+
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
30+
}
31+
32+
assert(ops->version == UMF_VERSION_CURRENT);
33+
34+
pool->providers =
35+
calloc(numProviders, sizeof(umf_memory_provider_handle_t));
36+
if (!pool->providers) {
37+
ret = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
38+
goto err_providers_alloc;
39+
}
40+
41+
size_t providerInd = 0;
42+
pool->numProviders = numProviders;
43+
44+
for (providerInd = 0; providerInd < numProviders; providerInd++) {
45+
pool->providers[providerInd] = providers[providerInd];
46+
}
47+
48+
pool->ops = *ops;
49+
ret = ops->initialize(pool->providers, pool->numProviders, params,
50+
&pool->pool_priv);
51+
if (ret != UMF_RESULT_SUCCESS) {
52+
goto err_pool_init;
53+
}
54+
55+
*hPool = pool;
56+
return UMF_RESULT_SUCCESS;
57+
58+
err_pool_init:
59+
err_providers_alloc:
60+
free(pool);
61+
62+
return ret;
63+
}
64+
65+
void umfPoolDestroy(umf_memory_pool_handle_t hPool) {
66+
hPool->ops.finalize(hPool->pool_priv);
67+
free(hPool);
68+
}
69+
70+
enum umf_result_t umfFree(void *ptr) { return UMF_RESULT_ERROR_NOT_SUPPORTED; }
71+
72+
umf_memory_pool_handle_t umfPoolByPtr(const void *ptr) { return NULL; }
73+
74+
enum umf_result_t
75+
umfPoolGetMemoryProviders(umf_memory_pool_handle_t hPool, size_t numProviders,
76+
umf_memory_provider_handle_t *hProviders,
77+
size_t *numProvidersRet) {
78+
if (hProviders && numProviders < hPool->numProviders) {
79+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
80+
}
81+
82+
if (numProvidersRet) {
83+
*numProvidersRet = hPool->numProviders;
84+
}
85+
86+
if (hProviders) {
87+
for (size_t i = 0; i < hPool->numProviders; i++) {
88+
hProviders[i] = hPool->providers[i];
89+
}
90+
}
91+
92+
return UMF_RESULT_SUCCESS;
93+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
*
3+
* Copyright (C) 2023 Intel Corporation
4+
*
5+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
6+
* See LICENSE.TXT
7+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
*
9+
*/
10+
11+
#ifndef UMF_MEMORY_POOL_INTERNAL_H
12+
#define UMF_MEMORY_POOL_INTERNAL_H 1
13+
14+
#include <umf/base.h>
15+
#include <umf/memory_pool_ops.h>
16+
#include <umf/memory_provider.h>
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
struct umf_memory_pool_t {
23+
void *pool_priv;
24+
struct umf_memory_pool_ops_t ops;
25+
26+
// Holds array of memory providers. All providers are wrapped
27+
// by memory tracking providers (owned and released by UMF).
28+
umf_memory_provider_handle_t *providers;
29+
30+
size_t numProviders;
31+
};
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
37+
#endif /* UMF_MEMORY_POOL_INTERNAL_H */

0 commit comments

Comments
 (0)