Skip to content

Commit df7d857

Browse files
authored
Merge pull request #268 from ldorau/Enable_OS_memory_provider_on_Windows
Enable OS memory provider on Windows
2 parents b9fff3f + 66d38de commit df7d857

17 files changed

+343
-31
lines changed

.github/workflows/basic.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ jobs:
177177

178178
windows-build:
179179
name: Windows
180+
env:
181+
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
180182
strategy:
181183
matrix:
182184
os: ['windows-2019', 'windows-2022']
@@ -211,11 +213,23 @@ jobs:
211213
- name: Checkout
212214
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
213215

216+
- name: Initialize vcpkg
217+
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
218+
with:
219+
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
220+
vcpkgDirectory: ${{github.workspace}}/build/vcpkg
221+
vcpkgJsonGlob: '**/vcpkg.json'
222+
223+
- name: Install dependencies
224+
run: vcpkg install
225+
shell: pwsh # Specifies PowerShell as the shell for running the script.
226+
214227
- name: Configure build
215228
run: >
216229
cmake
217230
-B ${{env.BUILD_DIR}}
218231
${{matrix.toolset}}
232+
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
219233
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
220234
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
221235
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}

.github/workflows/benchmarks.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
-DUMF_BUILD_TESTS=OFF
4040
-DUMF_FORMAT_CODE_STYLE=OFF
4141
-DUMF_DEVELOPER_MODE=OFF
42+
-DUMF_BUILD_OS_MEMORY_PROVIDER=ON
4243
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
4344
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
4445
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
@@ -68,3 +69,63 @@ jobs:
6869
- name: Run MT benchmarks
6970
working-directory: ${{github.workspace}}/build
7071
run: ./benchmark/multithread_bench
72+
73+
benchmarks-windows:
74+
name: Windows
75+
env:
76+
BUILD_DIR : "${{github.workspace}}/build/"
77+
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
78+
strategy:
79+
fail-fast: false
80+
matrix:
81+
build_type: [Release]
82+
compiler: [{c: cl, cxx: cl}]
83+
shared_library: ['ON', 'OFF']
84+
runs-on: 'windows-2022'
85+
86+
steps:
87+
- name: Checkout
88+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
89+
90+
- name: Initialize vcpkg
91+
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
92+
with:
93+
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
94+
vcpkgDirectory: ${{github.workspace}}/build/vcpkg
95+
vcpkgJsonGlob: '**/vcpkg.json'
96+
97+
- name: Install dependencies
98+
run: vcpkg install
99+
shell: pwsh # Specifies PowerShell as the shell for running the script.
100+
101+
- name: Configure build
102+
run: >
103+
cmake
104+
-B ${{env.BUILD_DIR}}
105+
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
106+
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
107+
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
108+
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
109+
-DUMF_BUILD_BENCHMARKS=ON
110+
-DUMF_BUILD_BENCHMARKS_MT=OFF
111+
-DUMF_BUILD_TESTS=OFF
112+
-DUMF_FORMAT_CODE_STYLE=OFF
113+
-DUMF_DEVELOPER_MODE=OFF
114+
-DUMF_BUILD_OS_MEMORY_PROVIDER=ON
115+
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
116+
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF
117+
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=OFF
118+
-DUMF_ENABLE_POOL_TRACKING=OFF
119+
120+
- name: Build UMF
121+
run: cmake --build ${{env.BUILD_DIR}} --config ${{matrix.build_type}} -j $Env:NUMBER_OF_PROCESSORS
122+
123+
- name: Run benchmarks
124+
working-directory: ${{env.BUILD_DIR}}
125+
shell: pwsh # Specifies PowerShell as the shell for running the script.
126+
run: |
127+
# add path to umf.dll
128+
$env:PATH += ";${{env.BUILD_DIR}}\bin\${{matrix.build_type}}"
129+
# add path to hwloc-15.dll
130+
$env:PATH += ";${{env.HWLOC_PATH}}\bin"
131+
.\benchmark\${{matrix.build_type}}\ubench.exe

.github/workflows/codeql.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
name: Analyze
2020
permissions:
2121
security-events: write
22+
env:
23+
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
2224
strategy:
2325
fail-fast: false
2426
matrix:
@@ -41,6 +43,19 @@ jobs:
4143
with:
4244
languages: cpp
4345

46+
- name: Initialize vcpkg
47+
if: ${{ matrix.os == 'windows-latest' }}
48+
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
49+
with:
50+
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
51+
vcpkgDirectory: ${{github.workspace}}/build/vcpkg
52+
vcpkgJsonGlob: '**/vcpkg.json'
53+
54+
- name: Install dependencies
55+
if: ${{ matrix.os == 'windows-latest' }}
56+
run: vcpkg install
57+
shell: pwsh # Specifies PowerShell as the shell for running the script.
58+
4459
- name: Install apt packages
4560
if: matrix.os == 'ubuntu-latest'
4661
run: |
@@ -55,6 +70,7 @@ jobs:
5570
cmake
5671
-B ${{github.workspace}}/build
5772
${{matrix.extra_build_option}}
73+
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
5874
-DUMF_FORMAT_CODE_STYLE=OFF
5975
-DUMF_DEVELOPER_MODE=ON
6076
-DUMF_ENABLE_POOL_TRACKING=ON

.github/workflows/pr_push.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ permissions:
1313
jobs:
1414
FastBuild:
1515
name: Fast build
16+
env:
17+
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
1618
strategy:
1719
matrix:
1820
include:
@@ -47,6 +49,19 @@ jobs:
4749
- name: Checkout repository
4850
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
4951

52+
- name: Initialize vcpkg
53+
if: ${{ matrix.os == 'windows-latest' }}
54+
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
55+
with:
56+
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
57+
vcpkgDirectory: ${{github.workspace}}/build/vcpkg
58+
vcpkgJsonGlob: '**/vcpkg.json'
59+
60+
- name: Install dependencies
61+
if: ${{ matrix.os == 'windows-latest' }}
62+
run: vcpkg install
63+
shell: pwsh # Specifies PowerShell as the shell for running the script.
64+
5065
- name: Install apt packages
5166
if: matrix.os == 'ubuntu-latest'
5267
run: |
@@ -57,6 +72,7 @@ jobs:
5772
run: >
5873
cmake
5974
-B ${{github.workspace}}/build
75+
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
6076
-DUMF_FORMAT_CODE_STYLE=OFF
6177
-DUMF_DEVELOPER_MODE=ON
6278
-DUMF_ENABLE_POOL_TRACKING=ON

.github/workflows/sanitizers.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ jobs:
110110

111111
windows-build:
112112
name: cl and clang-cl on Windows
113+
env:
114+
HWLOC_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows"
113115
strategy:
114116
matrix:
115117
compiler: [{c: cl, cxx: cl}, {c: clang-cl, cxx: clang-cl}]
@@ -133,12 +135,24 @@ jobs:
133135
arch: x64
134136
toolset: 14.38.33130
135137

138+
- name: Initialize vcpkg
139+
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
140+
with:
141+
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
142+
vcpkgDirectory: ${{github.workspace}}/build/vcpkg
143+
vcpkgJsonGlob: '**/vcpkg.json'
144+
145+
- name: Install dependencies
146+
run: vcpkg install
147+
shell: pwsh # Specifies PowerShell as the shell for running the script.
148+
136149
- name: Configure build
137150
run: >
138151
cmake
139152
-B ${{env.BUILD_DIR}}
140153
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
141154
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
155+
-DCMAKE_PREFIX_PATH=${{env.HWLOC_PATH}}
142156
-DUMF_BUILD_SHARED_LIBRARY=OFF
143157
-DUMF_ENABLE_POOL_TRACKING=OFF
144158
-DUMF_FORMAT_CODE_STYLE=OFF

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,22 @@ install(
112112
TARGETS umf_headers
113113
EXPORT ${PROJECT_NAME}-targets)
114114

115+
if(UMF_BUILD_OS_MEMORY_PROVIDER AND (LINUX OR WINDOWS))
116+
# Do not use pkgconfig, because it sets wrong paths on Windows
117+
find_package(LIBHWLOC REQUIRED hwloc)
118+
endif()
119+
115120
add_subdirectory(src)
116121

117122
if(UMF_BUILD_TESTS)
118123
add_subdirectory(test)
119124
endif()
120125

121126
if(UMF_BUILD_BENCHMARKS)
122-
if(LINUX)
127+
if(LINUX OR WINDOWS)
123128
add_subdirectory(benchmark)
124129
else()
125-
message(FATAL_ERROR "benchmarks are supported on Linux only")
130+
message(FATAL_ERROR "benchmarks are supported on Linux and Windows only")
126131
endif()
127132
endif()
128133

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,16 @@ More detailed documentation is available here: https://oneapi-src.github.io/unif
117117

118118
### Memory providers
119119

120-
#### OS memory provider (Linux-only yet)
120+
#### OS memory provider
121121

122122
A memory provider that provides memory from an operating system.
123123

124124
##### Requirements
125125

126-
1) Linux OS
127-
2) The `UMF_BUILD_OS_MEMORY_PROVIDER` option turned `ON` (by default)
128-
3) Required packages:
129-
- libhwloc-dev
130-
4) Required packages for tests:
126+
1) The `UMF_BUILD_OS_MEMORY_PROVIDER` option turned `ON` (by default)
127+
2) Required packages:
128+
- libhwloc-dev (Linux) / hwloc (Windows)
129+
3) Required packages for tests (Linux-only yet):
131130
- libnuma-dev
132131

133132
#### Level Zero memory provider (Linux-only yet)

benchmark/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,29 @@ endif()
2222

2323
add_executable(ubench ubench.c)
2424

25+
if(LINUX)
26+
set(LIBS_LINUX m)
27+
endif()
28+
2529
add_dependencies(ubench
2630
umf
2731
${LIBS_OPTIONAL})
2832

29-
target_include_directories(ubench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/)
33+
target_include_directories(ubench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/ ${UMF_CMAKE_SOURCE_DIR}/src/utils/)
3034

3135
target_link_libraries(ubench
3236
umf
3337
${LIBS_OPTIONAL}
3438
${CMAKE_THREAD_LIBS_INIT}
35-
m)
39+
${LIBS_LINUX})
3640

3741
if (UMF_BUILD_BENCHMARKS_MT)
3842
add_executable(multithread_bench multithread.cpp)
3943
target_link_libraries(multithread_bench
4044
umf
4145
${LIBS_OPTIONAL}
4246
pthread
43-
m)
47+
${LIBS_LINUX})
4448
target_include_directories(multithread_bench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/)
4549
endif()
4650

benchmark/ubench.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@
2424
#endif
2525

2626
#include <stdbool.h>
27+
28+
#ifndef _WIN32
2729
#include <unistd.h>
30+
#endif
2831

2932
#include "ubench.h"
33+
#include "utils_common.h"
3034

3135
// BENCHMARK CONFIG
3236
#define N_ITERATIONS 1000
33-
#define ALLOC_SIZE (getpagesize())
37+
#define ALLOC_SIZE (util_get_page_size())
3438

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

6771
static alloc_t *alloc_array(size_t iters) {
68-
Alloc_size = ALLOC_SIZE;
72+
Alloc_size = (int)ALLOC_SIZE;
6973
alloc_t *array = malloc(iters * sizeof(alloc_t));
7074
if (array == NULL) {
7175
perror("malloc() failed");
@@ -223,7 +227,7 @@ UBENCH_EX(simple, disjoint_pool_with_os_memory_provider) {
223227
exit(-1);
224228
}
225229

226-
umf_disjoint_pool_params_t disjoint_memory_pool_params = {};
230+
umf_disjoint_pool_params_t disjoint_memory_pool_params = {0};
227231
disjoint_memory_pool_params.SlabMinSize = DISJOINT_POOL_SLAB_MIN_SIZE;
228232
disjoint_memory_pool_params.MaxPoolableSize =
229233
DISJOINT_POOL_MAX_POOLABLE_SIZE;

cmake/FindLIBHWLOC.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,23 @@ message(STATUS "Checking for module 'libhwloc' using find_library()")
77
find_library(LIBHWLOC_LIBRARY NAMES libhwloc hwloc)
88
set(LIBHWLOC_LIBRARIES ${LIBHWLOC_LIBRARY})
99

10+
find_file(LIBHWLOC_HEADER NAMES hwloc.h HINTS /usr/include/ ${CMAKE_PREFIX_PATH}/include)
11+
get_filename_component(LIBHWLOC_INCLUDE_DIR ${LIBHWLOC_HEADER} DIRECTORY)
12+
set(LIBHWLOC_INCLUDE_DIRS ${LIBHWLOC_INCLUDE_DIR})
13+
14+
if(WINDOWS)
15+
find_file(LIBHWLOC_DLL NAMES hwloc-15.dll libhwloc-15.dll HINTS ${CMAKE_PREFIX_PATH}/bin)
16+
get_filename_component(LIBHWLOC_DLL_DIR ${LIBHWLOC_DLL} DIRECTORY)
17+
set(LIBHWLOC_DLL_DIRS ${LIBHWLOC_DLL_DIR})
18+
endif()
19+
1020
if(LIBHWLOC_LIBRARY)
1121
message(STATUS " Found libhwloc using find_library()")
22+
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
23+
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
24+
if(WINDOWS)
25+
message(STATUS " LIBHWLOC_DLL_DIRS = ${LIBHWLOC_DLL_DIRS}")
26+
endif()
1227
else()
1328
set(MSG_NOT_FOUND "libhwloc NOT found (set CMAKE_PREFIX_PATH to point the location)")
1429
if(LIBHWLOC_FIND_REQUIRED)

0 commit comments

Comments
 (0)