Skip to content

Enable pool scalable on Windows #251

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
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
7 changes: 5 additions & 2 deletions .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:
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
strategy:
matrix:
os: ['windows-2019', 'windows-2022']
Expand Down Expand Up @@ -229,14 +229,15 @@ jobs:
cmake
-B ${{env.BUILD_DIR}}
${{matrix.toolset}}
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
-DUMF_ENABLE_POOL_TRACKING=${{matrix.pool_tracking}}
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_BUILD_OS_MEMORY_PROVIDER=${{matrix.os_provider}}
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

Expand Down Expand Up @@ -270,6 +271,8 @@ jobs:
-DUMF_DEVELOPER_MODE=ON
-DUMF_ENABLE_POOL_TRACKING=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
-DUMF_BUILD_OS_MEMORY_PROVIDER=OFF
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=OFF

- name: Build UMF
run: cmake --build ${{env.BUILD_DIR}} -j $(sysctl -n hw.logicalcpu)
9 changes: 5 additions & 4 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ jobs:
name: Windows
env:
BUILD_DIR : "${{github.workspace}}/build/"
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
VCPKG_PATH_BIN: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows/bin;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows/bin"
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -104,7 +105,7 @@ jobs:
-B ${{env.BUILD_DIR}}
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
-DUMF_BUILD_BENCHMARKS=ON
-DUMF_BUILD_BENCHMARKS_MT=OFF
Expand All @@ -126,6 +127,6 @@ jobs:
run: |
# add path to umf.dll
$env:PATH += ";${{env.BUILD_DIR}}\bin\${{matrix.build_type}}"
# add path to hwloc-15.dll
$env:PATH += ";${{env.HWLOC_PATH}}\bin"
# add path to DLL directories
$env:PATH += ";${{env.VCPKG_PATH_BIN}}"
.\benchmark\${{matrix.build_type}}\ubench.exe
10 changes: 4 additions & 6 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ jobs:
permissions:
security-events: write
env:
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
pool_scalable: 'ON'
# Windows doesn't recognize 'CMAKE_BUILD_TYPE', it uses '--config' param in build command
extra_build_option: ['-DCMAKE_BUILD_TYPE=Release']
extra_build_option: '-DCMAKE_BUILD_TYPE=Release'
- os: windows-latest
pool_scalable: 'OFF'
runs-on: ${{matrix.os}}

steps:
Expand Down Expand Up @@ -70,11 +68,11 @@ jobs:
cmake
-B ${{github.workspace}}/build
${{matrix.extra_build_option}}
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=ON
-DUMF_ENABLE_POOL_TRACKING=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=${{matrix.pool_scalable}}
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF

- name: Build
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/pr_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,26 @@ jobs:
FastBuild:
name: Fast build
env:
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
strategy:
matrix:
include:
- os: windows-latest
pool_scalable: 'OFF'
disjoint: 'OFF'
jemalloc: 'OFF'
# pure C build (Windows)
- os: windows-latest
pool_scalable: 'OFF'
disjoint: 'OFF'
jemalloc: 'OFF'
# Tests' building is off for a pure C build
extra_build_options: '-DUMF_BUILD_TESTS=OFF'
- os: ubuntu-latest
pool_scalable: 'ON'
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
pool_scalable: 'ON'
disjoint: 'OFF'
jemalloc: 'ON'
# Windows doesn't recognize 'CMAKE_BUILD_TYPE', it uses '--config' param in build command
Expand Down Expand Up @@ -72,11 +68,11 @@ jobs:
run: >
cmake
-B ${{github.workspace}}/build
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=ON
-DUMF_ENABLE_POOL_TRACKING=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=${{matrix.pool_scalable}}
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=${{matrix.disjoint}}
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=${{matrix.jemalloc}}
-DUMF_BUILD_TESTS=ON
Expand All @@ -89,7 +85,7 @@ jobs:

- name: Run examples
working-directory: ${{github.workspace}}/build
run: ctest --output-on-failure --test-dir examples
run: ctest --output-on-failure --test-dir examples -C Release

CodeStyle:
name: Coding style
Expand All @@ -112,6 +108,7 @@ jobs:
-DUMF_BUILD_OS_MEMORY_PROVIDER=OFF
-DUMF_BUILD_TESTS=OFF
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=OFF

- name: Check clang-format
run: cmake --build build --target clang-format-check
Expand Down
4 changes: 2 additions & 2 deletions .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:
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
strategy:
matrix:
compiler: [{c: cl, cxx: cl}, {c: clang-cl, cxx: clang-cl}]
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:
-B ${{env.BUILD_DIR}}
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
-DUMF_BUILD_SHARED_LIBRARY=OFF
-DUMF_ENABLE_POOL_TRACKING=OFF
-DUMF_FORMAT_CODE_STYLE=OFF
Expand Down
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,17 @@ install(
EXPORT ${PROJECT_NAME}-targets)

if(UMF_BUILD_OS_MEMORY_PROVIDER AND (LINUX OR WINDOWS))
# Do not use pkgconfig, because it sets wrong paths on Windows
find_package(LIBHWLOC REQUIRED hwloc)
pkg_check_modules(LIBHWLOC hwloc)
if(NOT LIBHWLOC_FOUND)
find_package(LIBHWLOC REQUIRED hwloc)
endif()
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()
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 @@ -170,7 +170,7 @@ The `UMF_BUILD_LIBUMF_POOL_JEMALLOC` option has to be turned `ON` to build this
2) Required packages:
- libjemalloc-dev

#### libumf_pool_scalable (Linux-only)
#### libumf_pool_scalable

libumf_pool_scalable is a [oneTBB](https://github.com/oneapi-src/oneTBB)-based memory pool manager built as a separate static library.
The `UMF_BUILD_LIBUMF_POOL_SCALABLE` option has to be turned `ON` to build this library.
Expand All @@ -179,7 +179,7 @@ The `UMF_BUILD_LIBUMF_POOL_SCALABLE` option has to be turned `ON` to build this

1) The `UMF_BUILD_LIBUMF_POOL_SCALABLE` option turned `ON`
2) Required packages:
- libtbb-dev (libraries: libtbbmalloc.so.2)
- libtbb-dev (libtbbmalloc.so.2) on Linux or tbb (tbbmalloc.dll) on Windows

### Memspaces (Linux-only)

Expand Down
8 changes: 8 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ add_dependencies(ubench
umf
${LIBS_OPTIONAL})

if(UMF_BUILD_OS_MEMORY_PROVIDER)
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} ${LIBHWLOC_LIBRARIES})
set(LIB_DIRS_OPTIONAL ${LIB_DIRS_OPTIONAL} ${LIBHWLOC_LIBRARY_DIRS})
endif()

target_include_directories(ubench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/ ${UMF_CMAKE_SOURCE_DIR}/src/utils/)

target_link_directories(ubench PRIVATE ${LIB_DIRS_OPTIONAL})

target_link_libraries(ubench
umf
${LIBS_OPTIONAL}
Expand All @@ -40,6 +47,7 @@ target_link_libraries(ubench

if (UMF_BUILD_BENCHMARKS_MT)
add_executable(multithread_bench multithread.cpp)
target_link_directories(multithread_bench PRIVATE ${LIB_DIRS_OPTIONAL})
target_link_libraries(multithread_bench
umf
${LIBS_OPTIONAL}
Expand Down
8 changes: 6 additions & 2 deletions cmake/FindLIBHWLOC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ message(STATUS "Checking for module 'libhwloc' using find_library()")
find_library(LIBHWLOC_LIBRARY NAMES libhwloc hwloc)
set(LIBHWLOC_LIBRARIES ${LIBHWLOC_LIBRARY})

find_file(LIBHWLOC_HEADER NAMES hwloc.h HINTS /usr/include/ ${CMAKE_PREFIX_PATH}/include)
get_filename_component(LIBHWLOC_LIB_DIR ${LIBHWLOC_LIBRARIES} DIRECTORY)
set(LIBHWLOC_LIBRARY_DIRS ${LIBHWLOC_LIB_DIR})

find_file(LIBHWLOC_HEADER NAMES hwloc.h)
get_filename_component(LIBHWLOC_INCLUDE_DIR ${LIBHWLOC_HEADER} DIRECTORY)
set(LIBHWLOC_INCLUDE_DIRS ${LIBHWLOC_INCLUDE_DIR})

if(WINDOWS)
find_file(LIBHWLOC_DLL NAMES hwloc-15.dll libhwloc-15.dll HINTS ${CMAKE_PREFIX_PATH}/bin)
find_file(LIBHWLOC_DLL NAMES "bin/hwloc-15.dll" "bin/libhwloc-15.dll")
get_filename_component(LIBHWLOC_DLL_DIR ${LIBHWLOC_DLL} DIRECTORY)
set(LIBHWLOC_DLL_DIRS ${LIBHWLOC_DLL_DIR})
endif()
Expand All @@ -21,6 +24,7 @@ if(LIBHWLOC_LIBRARY)
message(STATUS " Found libhwloc using find_library()")
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
message(STATUS " LIBHWLOC_LIBRARY_DIRS = ${LIBHWLOC_LIBRARY_DIRS}")
if(WINDOWS)
message(STATUS " LIBHWLOC_DLL_DIRS = ${LIBHWLOC_DLL_DIRS}")
endif()
Expand Down
48 changes: 48 additions & 0 deletions cmake/FindTBB.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 'tbb' using find_library()")

find_library(TBB_LIBRARY NAMES tbbmalloc tbbmalloc)
set(TBB_LIBRARIES ${TBB_LIBRARY})

get_filename_component(TBB_LIB_DIR ${TBB_LIBRARIES} DIRECTORY)
set(TBB_LIBRARY_DIRS ${TBB_LIB_DIR})

find_file(TBB_HEADER NAMES "tbb/scalable_allocator.h")
if(TBB_HEADER)
get_filename_component(TBB_INCLUDE_DIR_TBB ${TBB_HEADER} DIRECTORY)
get_filename_component(TBB_INCLUDE_DIR ${TBB_INCLUDE_DIR_TBB} DIRECTORY)
set(TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR})
else()
set(MSG_NOT_FOUND "<tbb/scalable_allocator.h> header NOT found (set CMAKE_PREFIX_PATH to point the location)")
if(TBB_FIND_REQUIRED)
message(FATAL_ERROR ${MSG_NOT_FOUND})
else()
message(WARNING ${MSG_NOT_FOUND})
endif()
endif()

if(WINDOWS)
find_file(TBB_DLL NAMES "bin/tbbmalloc.dll")
get_filename_component(TBB_DLL_DIR ${TBB_DLL} DIRECTORY)
set(TBB_DLL_DIRS ${TBB_DLL_DIR})
endif()

if(TBB_LIBRARY)
message(STATUS " Found tbb using find_library()")
message(STATUS " TBB_LIBRARIES = ${TBB_LIBRARIES}")
message(STATUS " TBB_INCLUDE_DIRS = ${TBB_INCLUDE_DIRS}")
message(STATUS " TBB_LIBRARY_DIRS = ${TBB_LIBRARY_DIRS}")
if(WINDOWS)
message(STATUS " TBB_DLL_DIRS = ${TBB_DLL_DIRS}")
endif()
else()
set(MSG_NOT_FOUND "tbb NOT found (set CMAKE_PREFIX_PATH to point the location)")
if(TBB_FIND_REQUIRED)
message(FATAL_ERROR ${MSG_NOT_FOUND})
else()
message(WARNING ${MSG_NOT_FOUND})
endif()
endif()
22 changes: 19 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,39 @@
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

if(UMF_BUILD_OS_MEMORY_PROVIDER
AND UMF_BUILD_LIBUMF_POOL_SCALABLE
AND UMF_ENABLE_POOL_TRACKING)
if(UMF_BUILD_OS_MEMORY_PROVIDER AND UMF_BUILD_LIBUMF_POOL_SCALABLE AND UMF_ENABLE_POOL_TRACKING)
set(EXAMPLE_NAME umf_example_basic)

add_umf_executable(NAME ${EXAMPLE_NAME}
SRCS basic/basic.c
LIBS umf
${LIBHWLOC_LIBRARIES}
scalable_pool)

target_include_directories(${EXAMPLE_NAME} PRIVATE
${UMF_CMAKE_SOURCE_DIR}/src/utils
${UMF_CMAKE_SOURCE_DIR}/include)

target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})

add_test(NAME ${EXAMPLE_NAME}
COMMAND ${EXAMPLE_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example")

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()

install(FILES basic/basic.c
DESTINATION "${CMAKE_INSTALL_DOCDIR}/examples")

Expand Down
8 changes: 6 additions & 2 deletions examples/basic/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <stdio.h>
#include <string.h>

#include "utils_common.h"

int main(void) {
// A result object for storing UMF API result status
umf_result_t res;
Expand Down Expand Up @@ -45,9 +47,11 @@ int main(void) {
goto memory_provider_destroy;
}

const char *strSource = "Allocated memory at";

// Write to the allocated memory
memset(ptr_provider, '\0', alloc_size);
strcpy(ptr_provider, "Allocated memory at");
util_strncpy(ptr_provider, alloc_size, strSource, strlen(strSource) + 1);
printf("%s %p with the memory provider at %p\n", (char *)ptr_provider,
(void *)ptr_provider, (void *)provider);

Expand Down Expand Up @@ -83,7 +87,7 @@ int main(void) {
}

// Write a string to allocated memory
strcpy(ptr, "Allocated memory at");
util_strncpy(ptr, alloc_size, strSource, strlen(strSource) + 1);
printf("%s %p\n", ptr, (void *)ptr);

// Retrieve a memory pool from a pointer, available with memory tracking
Expand Down
Loading