Skip to content

Enable OS memory provider on Windows #268

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 3 commits into from
Mar 5, 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
14 changes: 14 additions & 0 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ jobs:

windows-build:
name: Windows
env:
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
strategy:
matrix:
os: ['windows-2019', 'windows-2022']
Expand Down Expand Up @@ -208,11 +210,23 @@ jobs:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Initialize vcpkg
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
with:
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
vcpkgDirectory: ${{github.workspace}}/build/vcpkg
vcpkgJsonGlob: '**/vcpkg.json'

- name: Install dependencies
run: vcpkg install
shell: pwsh # Specifies PowerShell as the shell for running the script.

- name: Configure build
run: >
cmake
-B ${{env.BUILD_DIR}}
${{matrix.toolset}}
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
-DUMF_BUILD_TESTS=OFF
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=OFF
-DUMF_BUILD_OS_MEMORY_PROVIDER=ON
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
Expand Down Expand Up @@ -67,3 +68,63 @@ jobs:
- name: Run MT benchmarks
working-directory: ${{github.workspace}}/build
run: ./benchmark/multithread_bench

benchmarks-windows:
name: Windows
env:
BUILD_DIR : "${{github.workspace}}/build/"
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
strategy:
fail-fast: false
matrix:
build_type: [Release]
compiler: [{c: cl, cxx: cl}]
shared_library: ['ON', 'OFF']
runs-on: 'windows-2022'

steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Initialize vcpkg
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
with:
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
vcpkgDirectory: ${{github.workspace}}/build/vcpkg
vcpkgJsonGlob: '**/vcpkg.json'

- name: Install dependencies
run: vcpkg install
shell: pwsh # Specifies PowerShell as the shell for running the script.

- name: Configure build
run: >
cmake
-B ${{env.BUILD_DIR}}
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
-DUMF_BUILD_BENCHMARKS=ON
-DUMF_BUILD_BENCHMARKS_MT=OFF
-DUMF_BUILD_TESTS=OFF
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=OFF
-DUMF_BUILD_OS_MEMORY_PROVIDER=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=OFF
-DUMF_ENABLE_POOL_TRACKING=OFF

- name: Build UMF
run: cmake --build ${{env.BUILD_DIR}} --config ${{matrix.build_type}} -j $Env:NUMBER_OF_PROCESSORS

- name: Run benchmarks
working-directory: ${{env.BUILD_DIR}}
shell: pwsh # Specifies PowerShell as the shell for running the script.
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"
.\benchmark\${{matrix.build_type}}\ubench.exe
16 changes: 16 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
name: Analyze
permissions:
security-events: write
env:
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
strategy:
fail-fast: false
matrix:
Expand All @@ -41,6 +43,19 @@ jobs:
with:
languages: cpp

- name: Initialize vcpkg
if: ${{ matrix.os == 'windows-latest' }}
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
with:
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
vcpkgDirectory: ${{github.workspace}}/build/vcpkg
vcpkgJsonGlob: '**/vcpkg.json'

- name: Install dependencies
if: ${{ matrix.os == 'windows-latest' }}
run: vcpkg install
shell: pwsh # Specifies PowerShell as the shell for running the script.

- name: Install apt packages
if: matrix.os == 'ubuntu-latest'
run: |
Expand All @@ -55,6 +70,7 @@ jobs:
cmake
-B ${{github.workspace}}/build
${{matrix.extra_build_option}}
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=ON
-DUMF_ENABLE_POOL_TRACKING=ON
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/pr_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ permissions:
jobs:
FastBuild:
name: Fast build
env:
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
strategy:
matrix:
include:
Expand Down Expand Up @@ -47,6 +49,19 @@ jobs:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Initialize vcpkg
if: ${{ matrix.os == 'windows-latest' }}
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
with:
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
vcpkgDirectory: ${{github.workspace}}/build/vcpkg
vcpkgJsonGlob: '**/vcpkg.json'

- name: Install dependencies
if: ${{ matrix.os == 'windows-latest' }}
run: vcpkg install
shell: pwsh # Specifies PowerShell as the shell for running the script.

- name: Install apt packages
if: matrix.os == 'ubuntu-latest'
run: |
Expand All @@ -57,6 +72,7 @@ jobs:
run: >
cmake
-B ${{github.workspace}}/build
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
-DUMF_FORMAT_CODE_STYLE=OFF
-DUMF_DEVELOPER_MODE=ON
-DUMF_ENABLE_POOL_TRACKING=ON
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ jobs:

windows-build:
name: cl and clang-cl on Windows
env:
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
strategy:
matrix:
compiler: [{c: cl, cxx: cl}, {c: clang-cl, cxx: clang-cl}]
Expand All @@ -131,12 +133,24 @@ jobs:
arch: x64
toolset: 14.38.33130

- name: Initialize vcpkg
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
with:
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
vcpkgDirectory: ${{github.workspace}}/build/vcpkg
vcpkgJsonGlob: '**/vcpkg.json'

- name: Install dependencies
run: vcpkg install
shell: pwsh # Specifies PowerShell as the shell for running the script.

- name: Configure build
run: >
cmake
-B ${{env.BUILD_DIR}}
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
-DUMF_BUILD_SHARED_LIBRARY=OFF
-DUMF_ENABLE_POOL_TRACKING=OFF
-DUMF_FORMAT_CODE_STYLE=OFF
Expand Down
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,22 @@ install(
TARGETS umf_headers
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)
endif()

add_subdirectory(src)

if(UMF_BUILD_TESTS)
add_subdirectory(test)
endif()

if(UMF_BUILD_BENCHMARKS)
if(LINUX)
if(LINUX OR WINDOWS)
add_subdirectory(benchmark)
else()
message(FATAL_ERROR "benchmarks are supported on Linux only")
message(FATAL_ERROR "benchmarks are supported on Linux and Windows only")
endif()
endif()

Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,16 @@ More detailed documentation is available here: https://oneapi-src.github.io/unif

### Memory providers

#### OS memory provider (Linux-only yet)
#### OS memory provider

A memory provider that provides memory from an operating system.

##### Requirements

1) Linux OS
2) The `UMF_BUILD_OS_MEMORY_PROVIDER` option turned `ON` (by default)
3) Required packages:
- libhwloc-dev
4) Required packages for tests:
1) The `UMF_BUILD_OS_MEMORY_PROVIDER` option turned `ON` (by default)
2) Required packages:
- libhwloc-dev (Linux) / hwloc (Windows)
3) Required packages for tests (Linux-only yet):
- libnuma-dev

### Memory pool managers
Expand Down
10 changes: 7 additions & 3 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,29 @@ endif()

add_executable(ubench ubench.c)

if(LINUX)
set(LIBS_LINUX m)
endif()

add_dependencies(ubench
umf
${LIBS_OPTIONAL})

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

target_link_libraries(ubench
umf
${LIBS_OPTIONAL}
${CMAKE_THREAD_LIBS_INIT}
m)
${LIBS_LINUX})

if (UMF_BUILD_BENCHMARKS_MT)
add_executable(multithread_bench multithread.cpp)
target_link_libraries(multithread_bench
umf
${LIBS_OPTIONAL}
pthread
m)
${LIBS_LINUX})
target_include_directories(multithread_bench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/)
endif()

Expand Down
10 changes: 7 additions & 3 deletions benchmark/ubench.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
#endif

#include <stdbool.h>

#ifndef _WIN32
#include <unistd.h>
#endif

#include "ubench.h"
#include "utils_common.h"

// BENCHMARK CONFIG
#define N_ITERATIONS 1000
#define ALLOC_SIZE (getpagesize())
#define ALLOC_SIZE (util_get_page_size())

// OS MEMORY PROVIDER CONFIG
#define OS_MEMORY_PROVIDER_TRACE (0)
Expand Down Expand Up @@ -65,7 +69,7 @@ static void do_benchmark(alloc_t *array, size_t iters, malloc_t malloc_f,
}

static alloc_t *alloc_array(size_t iters) {
Alloc_size = ALLOC_SIZE;
Alloc_size = (int)ALLOC_SIZE;
alloc_t *array = malloc(iters * sizeof(alloc_t));
if (array == NULL) {
perror("malloc() failed");
Expand Down Expand Up @@ -223,7 +227,7 @@ UBENCH_EX(simple, disjoint_pool_with_os_memory_provider) {
exit(-1);
}

umf_disjoint_pool_params_t disjoint_memory_pool_params = {};
umf_disjoint_pool_params_t disjoint_memory_pool_params = {0};
disjoint_memory_pool_params.SlabMinSize = DISJOINT_POOL_SLAB_MIN_SIZE;
disjoint_memory_pool_params.MaxPoolableSize =
DISJOINT_POOL_MAX_POOLABLE_SIZE;
Expand Down
15 changes: 15 additions & 0 deletions cmake/FindLIBHWLOC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,23 @@ 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_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)
get_filename_component(LIBHWLOC_DLL_DIR ${LIBHWLOC_DLL} DIRECTORY)
set(LIBHWLOC_DLL_DIRS ${LIBHWLOC_DLL_DIR})
endif()

if(LIBHWLOC_LIBRARY)
message(STATUS " Found libhwloc using find_library()")
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
if(WINDOWS)
message(STATUS " LIBHWLOC_DLL_DIRS = ${LIBHWLOC_DLL_DIRS}")
endif()
else()
set(MSG_NOT_FOUND "libhwloc NOT found (set CMAKE_PREFIX_PATH to point the location)")
if(LIBHWLOC_FIND_REQUIRED)
Expand Down
Loading