Skip to content

Enable jemalloc pool on Windows #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ jobs:
windows-build:
name: Windows
env:
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows;${{github.workspace}}/build/vcpkg/packages/jemalloc_x64-windows"
strategy:
matrix:
os: ['windows-2019', 'windows-2022']
Expand Down Expand Up @@ -238,6 +238,7 @@ jobs:
-DUMF_DEVELOPER_MODE=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
-DUMF_BUILD_OS_MEMORY_PROVIDER=${{matrix.os_provider}}
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

Expand Down Expand Up @@ -273,6 +274,7 @@ jobs:
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
-DUMF_BUILD_OS_MEMORY_PROVIDER=OFF
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=OFF
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF

- name: Build UMF
run: cmake --build ${{env.BUILD_DIR}} -j $(sysctl -n hw.logicalcpu)
12 changes: 3 additions & 9 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ jobs:
name: Benchmarks
env:
BUILD_DIR : "${{github.workspace}}/build/"
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows;${{github.workspace}}/build/vcpkg/packages/jemalloc_x64-windows"
strategy:
matrix:
include:
- os: ubuntu-latest
pool_jemalloc: 'ON'

- os: windows-latest
pool_jemalloc: 'OFF'

os: ['ubuntu-latest', 'windows-latest']
runs-on: ${{matrix.os}}

steps:
Expand Down Expand Up @@ -60,7 +54,7 @@ jobs:
-DUMF_DEVELOPER_MODE=OFF
-DUMF_BUILD_OS_MEMORY_PROVIDER=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=${{matrix.pool_jemalloc}}
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_ENABLE_POOL_TRACKING=OFF
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
permissions:
security-events: write
env:
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows;${{github.workspace}}/build/vcpkg/packages/jemalloc_x64-windows"
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -73,6 +73,7 @@ jobs:
-DUMF_DEVELOPER_MODE=ON
-DUMF_ENABLE_POOL_TRACKING=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/pr_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,24 @@ jobs:
FastBuild:
name: Fast build
env:
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows;${{github.workspace}}/build/vcpkg/packages/jemalloc_x64-windows"
strategy:
matrix:
include:
- os: windows-latest
disjoint: 'OFF'
jemalloc: 'OFF'
# pure C build (Windows)
- os: windows-latest
disjoint: 'OFF'
jemalloc: 'OFF'
# Tests' building is off for a pure C build
extra_build_options: '-DUMF_BUILD_TESTS=OFF'
- os: ubuntu-latest
disjoint: 'ON'
jemalloc: 'ON'
# Windows doesn't recognize 'CMAKE_BUILD_TYPE', it uses '--config' param in build command
extra_build_options: '-DCMAKE_BUILD_TYPE=Release -DUMF_BUILD_BENCHMARKS=ON -DUMF_BUILD_BENCHMARKS_MT=ON'
# pure C build (Linux)
- os: ubuntu-latest
disjoint: 'OFF'
jemalloc: 'ON'
# Windows doesn't recognize 'CMAKE_BUILD_TYPE', it uses '--config' param in build command
# Tests' building is off for a pure C build
extra_build_options: '-DCMAKE_BUILD_TYPE=Release -DUMF_BUILD_BENCHMARKS=ON -DUMF_BUILD_TESTS=OFF'
Expand Down Expand Up @@ -74,7 +70,7 @@ jobs:
-DUMF_ENABLE_POOL_TRACKING=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=${{matrix.disjoint}}
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=${{matrix.jemalloc}}
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
-DUMF_BUILD_TESTS=ON
-DUMF_BUILD_EXAMPLES=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
Expand Down Expand Up @@ -109,6 +105,7 @@ jobs:
-DUMF_BUILD_TESTS=OFF
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=OFF
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF

- name: Check clang-format
run: cmake --build build --target clang-format-check
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
windows-build:
name: cl and clang-cl on Windows
env:
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows;${{github.workspace}}/build/vcpkg/packages/jemalloc_x64-windows"
strategy:
matrix:
compiler: [{c: cl, cxx: cl}, {c: clang-cl, cxx: clang-cl}]
Expand Down
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,36 @@ install(
TARGETS umf_headers
EXPORT ${PROJECT_NAME}-targets)

if(WINDOWS)
# set PATH to DLLs on Windows
set(DLL_PATH_LIST "PATH=path_list_append:../bin/$<CONFIG>")
endif()

if(UMF_BUILD_OS_MEMORY_PROVIDER AND (LINUX OR WINDOWS))
pkg_check_modules(LIBHWLOC hwloc)
if(NOT LIBHWLOC_FOUND)
find_package(LIBHWLOC REQUIRED hwloc)
endif()
# add PATH to DLL on Windows
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin")
endif()

if(UMF_BUILD_LIBUMF_POOL_SCALABLE AND (LINUX OR WINDOWS))
pkg_check_modules(TBB tbb)
if(NOT TBB_FOUND)
find_package(TBB REQUIRED tbb)
endif()
# add PATH to DLL on Windows
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${TBB_LIBRARY_DIRS}/../bin")
endif()

if(UMF_BUILD_LIBUMF_POOL_JEMALLOC AND (LINUX OR WINDOWS))
pkg_check_modules(JEMALLOC jemalloc)
if(NOT JEMALLOC_FOUND)
find_package(JEMALLOC REQUIRED jemalloc)
endif()
# add PATH to DLL on Windows
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${JEMALLOC_LIBRARY_DIRS}/../bin")
endif()

add_subdirectory(src)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ TODO: Add a description

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

#### libumf_pool_jemalloc (Linux-only)
#### libumf_pool_jemalloc

libumf_pool_jemalloc is a [jemalloc](https://github.com/jemalloc/jemalloc)-based memory pool manager built as a separate static library.
The `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option has to be turned `ON` to build this library.
Expand All @@ -168,7 +168,7 @@ The `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option has to be turned `ON` to build this

1) The `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option turned `ON`
2) Required packages:
- libjemalloc-dev
- libjemalloc-dev (Linux) or jemalloc (Windows)

#### libumf_pool_scalable

Expand Down
16 changes: 5 additions & 11 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ function(add_umf_benchmark)

if(WINDOWS)
# append PATH to DLLs
set(DLL_PATH_LIST "PATH=path_list_append:../bin/$<CONFIG>")
if(LIBHWLOC_LIBRARY_DIRS)
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin")
endif()
if(TBB_LIBRARY_DIRS)
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${TBB_LIBRARY_DIRS}/../bin")
endif()
set_property(TEST ${BENCH_NAME} PROPERTY ENVIRONMENT_MODIFICATION "${DLL_PATH_LIST}")
endif()

Expand All @@ -70,16 +63,17 @@ endfunction()

# optional libraries
if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} disjoint_pool)
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} disjoint_pool)
endif()
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} jemalloc_pool)
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} jemalloc_pool ${JEMALLOC_LIBRARIES})
set(LIB_DIRS_OPTIONAL ${LIB_DIRS_OPTIONAL} ${JEMALLOC_LIBRARY_DIRS})
endif()
if(UMF_BUILD_LIBUMF_POOL_SCALABLE)
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} scalable_pool)
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} scalable_pool)
endif()
if(LINUX)
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} m)
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} m)
endif()
if(UMF_BUILD_OS_MEMORY_PROVIDER)
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} ${LIBHWLOC_LIBRARIES})
Expand Down
48 changes: 48 additions & 0 deletions cmake/FindJEMALLOC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (C) 2024 Intel Corporation
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

message(STATUS "Checking for module 'jemalloc' using find_library()")

find_library(JEMALLOC_LIBRARY NAMES libjemalloc jemalloc)
set(JEMALLOC_LIBRARIES ${JEMALLOC_LIBRARY})

get_filename_component(JEMALLOC_LIB_DIR ${JEMALLOC_LIBRARIES} DIRECTORY)
set(JEMALLOC_LIBRARY_DIRS ${JEMALLOC_LIB_DIR})

find_file(JEMALLOC_HEADER NAMES "jemalloc/jemalloc.h")
if(JEMALLOC_HEADER)
get_filename_component(JEMALLOC_INCLUDE_DIR_TBB ${JEMALLOC_HEADER} DIRECTORY)
get_filename_component(JEMALLOC_INCLUDE_DIR ${JEMALLOC_INCLUDE_DIR_TBB} DIRECTORY)
set(JEMALLOC_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR})
else()
set(MSG_NOT_FOUND "<jemalloc/jemalloc.h> header NOT found (set CMAKE_PREFIX_PATH to point the location)")
if(JEMALLOC_FIND_REQUIRED)
message(FATAL_ERROR ${MSG_NOT_FOUND})
else()
message(WARNING ${MSG_NOT_FOUND})
endif()
endif()

if(WINDOWS)
find_file(JEMALLOC_DLL NAMES "bin/jemalloc.dll")
get_filename_component(JEMALLOC_DLL_DIR ${JEMALLOC_DLL} DIRECTORY)
set(JEMALLOC_DLL_DIRS ${JEMALLOC_DLL_DIR})
endif()

if(JEMALLOC_LIBRARY)
message(STATUS " Found jemalloc using find_library()")
message(STATUS " JEMALLOC_LIBRARIES = ${JEMALLOC_LIBRARIES}")
message(STATUS " JEMALLOC_INCLUDE_DIRS = ${JEMALLOC_INCLUDE_DIRS}")
message(STATUS " JEMALLOC_LIBRARY_DIRS = ${JEMALLOC_LIBRARY_DIRS}")
if(WINDOWS)
message(STATUS " JEMALLOC_DLL_DIRS = ${JEMALLOC_DLL_DIRS}")
endif()
else()
set(MSG_NOT_FOUND "jemalloc NOT found (set CMAKE_PREFIX_PATH to point the location)")
if(JEMALLOC_FIND_REQUIRED)
message(FATAL_ERROR ${MSG_NOT_FOUND})
else()
message(WARNING ${MSG_NOT_FOUND})
endif()
endif()
7 changes: 0 additions & 7 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ if(UMF_BUILD_OS_MEMORY_PROVIDER AND UMF_BUILD_LIBUMF_POOL_SCALABLE AND UMF_ENABL

if(WINDOWS)
# append PATH to DLLs
set(DLL_PATH_LIST "PATH=path_list_append:../bin/$<CONFIG>")
if(LIBHWLOC_LIBRARY_DIRS)
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin")
endif()
if(TBB_LIBRARY_DIRS)
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${TBB_LIBRARY_DIRS}/../bin")
endif()
set_property(TEST ${EXAMPLE_NAME} PROPERTY ENVIRONMENT_MODIFICATION "${DLL_PATH_LIST}")
endif()

Expand Down
5 changes: 3 additions & 2 deletions src/pool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ endif()

# libumf_pool_jemalloc
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
if(LINUX)
if(LINUX OR WINDOWS)
add_umf_library(NAME jemalloc_pool
TYPE STATIC
SRCS pool_jemalloc.c ${POOL_EXTRA_SRCS}
LIBS jemalloc umf_utils)
target_include_directories(jemalloc_pool PRIVATE ${JEMALLOC_INCLUDE_DIRS})
target_compile_definitions(jemalloc_pool PUBLIC ${POOL_COMPILE_DEFINITIONS})
add_library(${PROJECT_NAME}::jemalloc_pool ALIAS jemalloc_pool)
install(TARGETS jemalloc_pool
EXPORT ${PROJECT_NAME}-targets
)
else()
message(FATAL_ERROR "libumf_pool_jemalloc is supported on Linux only")
message(FATAL_ERROR "libumf_pool_jemalloc is supported on Linux and Windows only")
endif()
endif()

Expand Down
Loading