Skip to content

Commit e7a709b

Browse files
authored
Merge pull request #73 from PatKamin/static-disjoint-pool
Extract Disjoint Pool into static lib
2 parents cfcb318 + a7f155a commit e7a709b

File tree

12 files changed

+100
-30
lines changed

12 files changed

+100
-30
lines changed

.github/workflows/basic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
-DUMF_FORMAT_CODE_STYLE=OFF
4747
-DUMF_DEVELOPER_MODE=ON
4848
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
49+
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
4950
5051
- name: Build UMF
5152
run: |

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
-DUMF_FORMAT_CODE_STYLE=OFF
3535
-DUMF_DEVELOPER_MODE=OFF
3636
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF
37+
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
3738
-DUMF_ENABLE_POOL_TRACKING=OFF
3839
3940
- name: Build UMF

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES)
1010

1111
include(CTest)
1212
include(CMakePackageConfigHelpers)
13+
include(GNUInstallDirs)
1314

1415
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1516
include(helpers)
1617

1718
# Build Options
1819
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
20+
option(UMF_BUILD_LIBUMF_POOL_DISJOINT "Build the libumf_pool_disjoint static library" OFF)
1921
option(UMF_BUILD_LIBUMF_POOL_JEMALLOC "Build the libumf_pool_jemalloc static library" OFF)
2022
option(UMF_BUILD_TESTS "Build UMF tests" ON)
2123
option(UMF_BUILD_BENCHMARKS "Build UMF benchmarks" OFF)
@@ -76,7 +78,7 @@ add_subdirectory(src)
7678
if(UMF_BUILD_TESTS)
7779
add_subdirectory(test)
7880
endif()
79-
if(UMF_BUILD_BENCHMARKS)
81+
if(UMF_BUILD_BENCHMARKS AND UMF_BUILD_LIBUMF_POOL_DISJOINT)
8082
if(LINUX)
8183
add_subdirectory(benchmark)
8284
else()

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ A memory provider that provides memory from an operating system.
2020

2121
## Memory pool managers
2222

23+
### libumf_pool_disjoint
24+
25+
TODO: Add a description
26+
27+
#### Requirements
28+
29+
To enable this feature, the `UMF_BUILD_LIBUMF_POOL_DISJOINT` option needs to be turned `ON`.
30+
2331
### libumf_pool_jemalloc (Linux-only)
2432

2533
libumf_pool_jemalloc is a [jemalloc](https://github.com/jemalloc/jemalloc)-based memory pool manager built as a separate static library.
@@ -43,6 +51,11 @@ Required packages:
4351
For development and contributions:
4452
- clang-format-15.0 (can be installed with `python -m pip install clang-format==15.0.7`)
4553

54+
### Benchmark
55+
56+
Disjoint Pool is a required dependency of the micro benchmark.
57+
In order to build the benchmark, the `UMF_BUILD_LIBUMF_POOL_DISJOINT` CMake configuration flag has to be turned `ON`.
58+
4659
### Windows
4760

4861
Generating Visual Studio Project. EXE and binaries will be in **build/bin/{build_config}**
@@ -87,6 +100,7 @@ List of options provided by CMake:
87100
| Name | Description | Values | Default |
88101
| - | - | - | - |
89102
| UMF_BUILD_SHARED_LIBRARY | Build UMF as shared library | ON/OFF | OFF |
103+
| UMF_BUILD_LIBUMF_POOL_DISJOINT | Build the libumf_pool_disjoint static library | ON/OFF | OFF |
90104
| UMF_BUILD_LIBUMF_POOL_JEMALLOC | Build the libumf_pool_jemalloc static library | ON/OFF | OFF |
91105
| UMF_BUILD_TESTS | Build UMF tests | ON/OFF | ON |
92106
| UMF_BUILD_BENCHMARKS | Build UMF benchmarks | ON/OFF | OFF |

benchmark/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
77
endif()
88

99
add_executable(ubench ubench.c)
10-
add_dependencies(ubench unified_memory_framework)
10+
add_dependencies(ubench
11+
unified_memory_framework
12+
disjoint_pool)
1113
target_include_directories(ubench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/)
1214
target_link_libraries(ubench
1315
unified_memory_framework
16+
disjoint_pool
1417
pthread
1518
m)

cmake/helpers.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function(add_umf_executable)
8888
endfunction()
8989

9090
function(add_umf_library)
91-
# NAME - a name of the executable
91+
# NAME - a name of the library
9292
# TYPE - type of the library (shared or static)
9393
# SRCS - source files
9494
# LIBS - libraries to be linked with

src/CMakeLists.txt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ set(UMF_SOURCES
88
memory_pool.c
99
memory_provider.c
1010
memory_provider_get_last_failed.c
11-
pool/pool_disjoint.cpp
1211
provider/provider_os_memory.c
1312
provider/provider_tracking.c
1413
critnib/critnib.c
@@ -60,18 +59,20 @@ endif()
6059

6160
add_library(${PROJECT_NAME}::unified_memory_framework ALIAS unified_memory_framework)
6261

63-
target_include_directories(unified_memory_framework PUBLIC
64-
${UMF_CMAKE_SOURCE_DIR}/include
65-
./common
66-
./critnib
67-
./provider
68-
./utils)
62+
target_include_directories(unified_memory_framework PUBLIC
63+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
64+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/common>
65+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/critnib>
66+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/provider>
67+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/utils>
68+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
69+
)
6970

70-
# libumf_pool_jemalloc
71-
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
72-
if(LINUX)
73-
add_umf_library(NAME pool_jemalloc TYPE STATIC SRCS pool/pool_jemalloc.c LIBS jemalloc)
74-
else()
75-
message(FATAL_ERROR "libumf_pool_jemalloc is supported on Linux only")
76-
endif()
77-
endif()
71+
install(TARGETS unified_memory_framework
72+
EXPORT ${PROJECT_NAME}-targets
73+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
74+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
75+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
76+
)
77+
78+
add_subdirectory(pool)

src/pool/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (C) 2023 Intel Corporation
2+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
# libumf_pool_disjoint
6+
if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
7+
add_umf_library(NAME disjoint_pool
8+
TYPE STATIC
9+
SRCS pool_disjoint.cpp)
10+
11+
add_library(${PROJECT_NAME}::disjoint_pool ALIAS disjoint_pool)
12+
13+
add_dependencies(disjoint_pool
14+
unified_memory_framework)
15+
16+
target_link_libraries(disjoint_pool PRIVATE
17+
unified_memory_framework)
18+
19+
target_include_directories(disjoint_pool PUBLIC
20+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/umf/pools>
21+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
22+
)
23+
24+
install(TARGETS disjoint_pool
25+
EXPORT ${PROJECT_NAME}-targets
26+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
27+
)
28+
endif()
29+
30+
# libumf_pool_jemalloc
31+
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
32+
if(LINUX)
33+
add_umf_library(NAME pool_jemalloc TYPE STATIC SRCS pool_jemalloc.c LIBS jemalloc)
34+
else()
35+
message(FATAL_ERROR "libumf_pool_jemalloc is supported on Linux only")
36+
endif()
37+
endif()

src/pool/pool_disjoint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
// TODO: replace with logger?
2323
#include <iostream>
2424

25+
#include "pool_disjoint.h"
2526
#include "umf.h"
26-
#include "umf/pools/pool_disjoint.h"
2727
#include "umf_helpers.hpp"
2828
#include "utils_math.h"
2929

test/CMakeLists.txt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ function(add_umf_test)
3939
add_umf_executable(NAME ${TEST_TARGET_NAME} SRCS ${ARG_SRCS} LIBS ${TEST_LIBS})
4040

4141
target_include_directories(${TEST_TARGET_NAME} PRIVATE
42-
${UMF_TEST_DIR}/common
4342
${UMF_CMAKE_SOURCE_DIR}/src
44-
${UMF_CMAKE_SOURCE_DIR}/src/pool/disjoint)
43+
${UMF_TEST_DIR}/common)
4544

4645
add_test(NAME ${TEST_NAME}
4746
COMMAND ${TEST_TARGET_NAME}
@@ -59,13 +58,25 @@ endfunction()
5958

6059
add_subdirectory(common)
6160

62-
add_umf_test(NAME base SRCS base.cpp)
63-
add_umf_test(NAME memoryPool SRCS memoryPoolAPI.cpp malloc_compliance_tests.cpp)
64-
add_umf_test(NAME memoryProvider SRCS memoryProviderAPI.cpp)
65-
add_umf_test(NAME disjointPool SRCS disjoint_pool.cpp malloc_compliance_tests.cpp)
66-
add_umf_test(NAME c_api_disjoint_pool SRCS c_api/disjoint_pool.c)
67-
add_umf_test(NAME memory_pool_internal SRCS memory_pool_internal.cpp)
61+
add_umf_test(NAME base
62+
SRCS base.cpp)
63+
add_umf_test(NAME memoryPool
64+
SRCS memoryPoolAPI.cpp malloc_compliance_tests.cpp)
65+
add_umf_test(NAME memoryProvider
66+
SRCS memoryProviderAPI.cpp)
67+
add_umf_test(NAME memory_pool_internal
68+
SRCS memory_pool_internal.cpp)
69+
70+
if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
71+
add_umf_test(NAME disjointPool
72+
SRCS disjoint_pool.cpp malloc_compliance_tests.cpp
73+
LIBS ${PROJECT_NAME}::disjoint_pool)
74+
add_umf_test(NAME c_api_disjoint_pool
75+
SRCS c_api/disjoint_pool.c
76+
LIBS ${PROJECT_NAME}::disjoint_pool)
77+
endif()
6878

6979
if(LINUX) # OS-specific functions are implemented only for Linux now
70-
add_umf_test(NAME provider_os_memory SRCS provider_os_memory.cpp)
80+
add_umf_test(NAME provider_os_memory
81+
SRCS provider_os_memory.cpp)
7182
endif()

test/c_api/disjoint_pool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
#include <stdlib.h>
66

7+
#include "pool_disjoint.h"
78
#include "provider_null.h"
89
#include "test_helpers.h"
9-
#include "umf/pools/pool_disjoint.h"
1010

1111
void test_disjoint_pool_default_params(void) {
1212
umf_memory_provider_handle_t provider = nullProviderCreate();

test/disjoint_pool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include "memoryPool.hpp"
66
#include "pool.hpp"
7+
#include "pool_disjoint.h"
78
#include "provider.hpp"
89
#include "provider_null.h"
910
#include "provider_trace.h"
10-
#include "umf/pools/pool_disjoint.h"
1111

1212
umf_disjoint_pool_params_t poolConfig() {
1313
umf_disjoint_pool_params_t config{};

0 commit comments

Comments
 (0)