Skip to content

Commit

Permalink
Merge pull request #73 from PatKamin/static-disjoint-pool
Browse files Browse the repository at this point in the history
Extract Disjoint Pool into static lib
  • Loading branch information
bratpiorka authored Dec 21, 2023
2 parents cfcb318 + a7f155a commit e7a709b
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 30 deletions.
1 change: 1 addition & 0 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=ON
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
- name: Build UMF
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=OFF
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_ENABLE_POOL_TRACKING=OFF
- name: Build UMF
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES)

include(CTest)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

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

# Build Options
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
option(UMF_BUILD_LIBUMF_POOL_DISJOINT "Build the libumf_pool_disjoint static library" OFF)
option(UMF_BUILD_LIBUMF_POOL_JEMALLOC "Build the libumf_pool_jemalloc static library" OFF)
option(UMF_BUILD_TESTS "Build UMF tests" ON)
option(UMF_BUILD_BENCHMARKS "Build UMF benchmarks" OFF)
Expand Down Expand Up @@ -76,7 +78,7 @@ add_subdirectory(src)
if(UMF_BUILD_TESTS)
add_subdirectory(test)
endif()
if(UMF_BUILD_BENCHMARKS)
if(UMF_BUILD_BENCHMARKS AND UMF_BUILD_LIBUMF_POOL_DISJOINT)
if(LINUX)
add_subdirectory(benchmark)
else()
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ A memory provider that provides memory from an operating system.

## Memory pool managers

### libumf_pool_disjoint

TODO: Add a description

#### Requirements

To enable this feature, the `UMF_BUILD_LIBUMF_POOL_DISJOINT` option needs to be turned `ON`.

### libumf_pool_jemalloc (Linux-only)

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

### Benchmark

Disjoint Pool is a required dependency of the micro benchmark.
In order to build the benchmark, the `UMF_BUILD_LIBUMF_POOL_DISJOINT` CMake configuration flag has to be turned `ON`.

### Windows

Generating Visual Studio Project. EXE and binaries will be in **build/bin/{build_config}**
Expand Down Expand Up @@ -87,6 +100,7 @@ List of options provided by CMake:
| Name | Description | Values | Default |
| - | - | - | - |
| UMF_BUILD_SHARED_LIBRARY | Build UMF as shared library | ON/OFF | OFF |
| UMF_BUILD_LIBUMF_POOL_DISJOINT | Build the libumf_pool_disjoint static library | ON/OFF | OFF |
| UMF_BUILD_LIBUMF_POOL_JEMALLOC | Build the libumf_pool_jemalloc static library | ON/OFF | OFF |
| UMF_BUILD_TESTS | Build UMF tests | ON/OFF | ON |
| UMF_BUILD_BENCHMARKS | Build UMF benchmarks | ON/OFF | OFF |
Expand Down
5 changes: 4 additions & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
endif()

add_executable(ubench ubench.c)
add_dependencies(ubench unified_memory_framework)
add_dependencies(ubench
unified_memory_framework
disjoint_pool)
target_include_directories(ubench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/)
target_link_libraries(ubench
unified_memory_framework
disjoint_pool
pthread
m)
2 changes: 1 addition & 1 deletion cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function(add_umf_executable)
endfunction()

function(add_umf_library)
# NAME - a name of the executable
# NAME - a name of the library
# TYPE - type of the library (shared or static)
# SRCS - source files
# LIBS - libraries to be linked with
Expand Down
31 changes: 16 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(UMF_SOURCES
memory_pool.c
memory_provider.c
memory_provider_get_last_failed.c
pool/pool_disjoint.cpp
provider/provider_os_memory.c
provider/provider_tracking.c
critnib/critnib.c
Expand Down Expand Up @@ -60,18 +59,20 @@ endif()

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

target_include_directories(unified_memory_framework PUBLIC
${UMF_CMAKE_SOURCE_DIR}/include
./common
./critnib
./provider
./utils)
target_include_directories(unified_memory_framework PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/common>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/critnib>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/provider>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/utils>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

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

add_subdirectory(pool)
37 changes: 37 additions & 0 deletions src/pool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (C) 2023 Intel Corporation
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# libumf_pool_disjoint
if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
add_umf_library(NAME disjoint_pool
TYPE STATIC
SRCS pool_disjoint.cpp)

add_library(${PROJECT_NAME}::disjoint_pool ALIAS disjoint_pool)

add_dependencies(disjoint_pool
unified_memory_framework)

target_link_libraries(disjoint_pool PRIVATE
unified_memory_framework)

target_include_directories(disjoint_pool PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/umf/pools>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

install(TARGETS disjoint_pool
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()

# libumf_pool_jemalloc
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
if(LINUX)
add_umf_library(NAME pool_jemalloc TYPE STATIC SRCS pool_jemalloc.c LIBS jemalloc)
else()
message(FATAL_ERROR "libumf_pool_jemalloc is supported on Linux only")
endif()
endif()
2 changes: 1 addition & 1 deletion src/pool/pool_disjoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
// TODO: replace with logger?
#include <iostream>

#include "pool_disjoint.h"
#include "umf.h"
#include "umf/pools/pool_disjoint.h"
#include "umf_helpers.hpp"
#include "utils_math.h"

Expand Down
29 changes: 20 additions & 9 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ function(add_umf_test)
add_umf_executable(NAME ${TEST_TARGET_NAME} SRCS ${ARG_SRCS} LIBS ${TEST_LIBS})

target_include_directories(${TEST_TARGET_NAME} PRIVATE
${UMF_TEST_DIR}/common
${UMF_CMAKE_SOURCE_DIR}/src
${UMF_CMAKE_SOURCE_DIR}/src/pool/disjoint)
${UMF_TEST_DIR}/common)

add_test(NAME ${TEST_NAME}
COMMAND ${TEST_TARGET_NAME}
Expand All @@ -59,13 +58,25 @@ endfunction()

add_subdirectory(common)

add_umf_test(NAME base SRCS base.cpp)
add_umf_test(NAME memoryPool SRCS memoryPoolAPI.cpp malloc_compliance_tests.cpp)
add_umf_test(NAME memoryProvider SRCS memoryProviderAPI.cpp)
add_umf_test(NAME disjointPool SRCS disjoint_pool.cpp malloc_compliance_tests.cpp)
add_umf_test(NAME c_api_disjoint_pool SRCS c_api/disjoint_pool.c)
add_umf_test(NAME memory_pool_internal SRCS memory_pool_internal.cpp)
add_umf_test(NAME base
SRCS base.cpp)
add_umf_test(NAME memoryPool
SRCS memoryPoolAPI.cpp malloc_compliance_tests.cpp)
add_umf_test(NAME memoryProvider
SRCS memoryProviderAPI.cpp)
add_umf_test(NAME memory_pool_internal
SRCS memory_pool_internal.cpp)

if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
add_umf_test(NAME disjointPool
SRCS disjoint_pool.cpp malloc_compliance_tests.cpp
LIBS ${PROJECT_NAME}::disjoint_pool)
add_umf_test(NAME c_api_disjoint_pool
SRCS c_api/disjoint_pool.c
LIBS ${PROJECT_NAME}::disjoint_pool)
endif()

if(LINUX) # OS-specific functions are implemented only for Linux now
add_umf_test(NAME provider_os_memory SRCS provider_os_memory.cpp)
add_umf_test(NAME provider_os_memory
SRCS provider_os_memory.cpp)
endif()
2 changes: 1 addition & 1 deletion test/c_api/disjoint_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include <stdlib.h>

#include "pool_disjoint.h"
#include "provider_null.h"
#include "test_helpers.h"
#include "umf/pools/pool_disjoint.h"

void test_disjoint_pool_default_params(void) {
umf_memory_provider_handle_t provider = nullProviderCreate();
Expand Down
2 changes: 1 addition & 1 deletion test/disjoint_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

#include "memoryPool.hpp"
#include "pool.hpp"
#include "pool_disjoint.h"
#include "provider.hpp"
#include "provider_null.h"
#include "provider_trace.h"
#include "umf/pools/pool_disjoint.h"

umf_disjoint_pool_params_t poolConfig() {
umf_disjoint_pool_params_t config{};
Expand Down

0 comments on commit e7a709b

Please sign in to comment.