Skip to content

Commit fe3aea6

Browse files
authored
Merge pull request #1432 from lukaszstolarczuk/fetch-content-example
Test FetchContent of UMF on Linux and Windows in CI
2 parents d678be9 + 2d10feb commit fe3aea6

File tree

4 files changed

+175
-9
lines changed

4 files changed

+175
-9
lines changed

.github/workflows/nightly.yml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ jobs:
109109

110110
# Build and test UMF with different CMake generators on Windows
111111
Windows-generators:
112+
env:
113+
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"
114+
VCPKG_PATH_NO_HWLOC: "${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows;${{github.workspace}}/build/vcpkg/packages/jemalloc_x64-windows"
112115
strategy:
113116
matrix:
114117
build_type: [Debug, Release]
@@ -127,18 +130,12 @@ jobs:
127130
with:
128131
fetch-depth: 0
129132

130-
- name: Set VCPKG_PATH with hwloc
131-
if: matrix.static_hwloc == 'OFF'
132-
run: echo "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" >> $env:GITHUB_ENV
133-
134133
- name: Set VCPKG_PATH without hwloc
135134
if: matrix.static_hwloc == 'ON'
136-
run: echo "VCPKG_PATH=${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows;${{github.workspace}}/build/vcpkg/packages/jemalloc_x64-windows" >> $env:GITHUB_ENV
135+
run: echo "VCPKG_PATH=${{env.VCPKG_PATH_NO_HWLOC}}" >> $env:GITHUB_ENV
137136

138137
- name: Initialize vcpkg
139138
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
140-
env:
141-
VCPKG_PATH: ${{env.VCPKG_PATH}}
142139
with:
143140
vcpkgGitCommitId: ea2a964f9303270322cf3f2d51c265ba146c422d # 1.04.2025
144141
vcpkgDirectory: ${{env.BUILD_DIR}}/vcpkg
@@ -201,6 +198,30 @@ jobs:
201198
${{ matrix.umfd_lib == 'ON' && '--umfd-lib' || ''}}
202199
${{ matrix.static_hwloc == 'ON' && '--hwloc' || '' }}
203200
201+
- name: Configure the fetch_content example
202+
if: matrix.static_hwloc == 'OFF'
203+
working-directory: ${{github.workspace}}/examples/fetch_content
204+
# Fetch_Content the UMF code from the current repository (-DUMF_REPO="${{github.workspace}}")
205+
run: >
206+
cmake
207+
-B build
208+
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
209+
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
210+
-DUMF_REPO="${{github.workspace}}"
211+
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
212+
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
213+
-G "${{matrix.generator}}"
214+
215+
- name: Build the fetch_content example
216+
if: matrix.static_hwloc == 'OFF'
217+
working-directory: ${{github.workspace}}/examples/fetch_content
218+
run: cmake --build build --config ${{matrix.build_type}} -j $env:NUMBER_OF_PROCESSORS
219+
220+
- name: Run the fetch_content example
221+
if: matrix.static_hwloc == 'OFF'
222+
working-directory: ${{github.workspace}}/examples/fetch_content/build
223+
run: ctest -V
224+
204225
# Build and test UMF with Intel C++ Compiler (ICX) on Windows
205226
Windows-icx:
206227
env:

examples/fetch_content/CMakeLists.txt

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
# This example shows and tests usage of FetchContent module. It downloads and
6+
# builds the UMF library defined in UMF_REPO CMake variable (or UMF from
7+
# upstream repo URL, by default).
8+
9+
cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
10+
project(umf_example_fetch_content LANGUAGES C)
11+
enable_testing()
12+
13+
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
14+
set(LINUX TRUE)
15+
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
16+
set(WINDOWS TRUE)
17+
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
18+
set(MACOSX TRUE)
19+
else()
20+
message(FATAL_ERROR "Unknown OS type")
21+
endif()
22+
23+
set(UMF_EXAMPLE_DIR "${CMAKE_SOURCE_DIR}/..")
24+
list(APPEND CMAKE_MODULE_PATH "${UMF_EXAMPLE_DIR}/cmake")
25+
message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
26+
27+
include("fetch_umf.cmake")
28+
29+
find_package(PkgConfig)
30+
pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
31+
if(NOT LIBHWLOC_FOUND)
32+
find_package(LIBHWLOC 2.3.0 REQUIRED hwloc)
33+
endif()
34+
35+
pkg_check_modules(TBB tbb)
36+
if(NOT TBB_FOUND)
37+
find_package(TBB REQUIRED tbb)
38+
endif()
39+
40+
# build the example
41+
set(EXAMPLE_NAME umf_example_fetch_content)
42+
# reusing the basic.c source file from the basic example
43+
add_executable(${EXAMPLE_NAME} ${CMAKE_SOURCE_DIR}/../basic/basic.c)
44+
target_include_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_INCLUDE_DIRS})
45+
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
46+
target_link_libraries(${EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARIES} hwloc)
47+
48+
message(STATUS "LIBUMF_INCLUDE_DIRS=${LIBUMF_INCLUDE_DIRS}")
49+
message(STATUS "LIBUMF_LIBRARIES=${LIBUMF_LIBRARIES}")
50+
message(STATUS "LIBUMF_LIBRARY_DIRS=${LIBUMF_LIBRARY_DIRS}")
51+
message(STATUS "LIBHWLOC_LIBRARY_DIRS=${LIBHWLOC_LIBRARY_DIRS}")
52+
53+
# an optional part - adds a test of this example
54+
add_test(
55+
NAME ${EXAMPLE_NAME}
56+
COMMAND ${EXAMPLE_NAME}
57+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
58+
59+
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example-standalone")
60+
61+
if(LINUX)
62+
# set LD_LIBRARY_PATH
63+
set_property(
64+
TEST ${EXAMPLE_NAME}
65+
PROPERTY
66+
ENVIRONMENT_MODIFICATION
67+
"LD_LIBRARY_PATH=path_list_append:${LIBUMF_LIBRARY_DIRS};LD_LIBRARY_PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}"
68+
)
69+
elseif(WINDOWS)
70+
# add PATH to DLL on Windows
71+
set(DLL_PATH_LIST
72+
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_DLL_DIRS};PATH=path_list_append:${TBB_DLL_DIRS}"
73+
)
74+
75+
message(STATUS "DLL_PATH_LIST=${DLL_PATH_LIST}")
76+
77+
# append PATH to DLLs NOTE: this would work only for the CMake ver >= #
78+
# 3.22. For the older versions, the PATH variable should be set in the test
79+
# script)
80+
set_property(TEST ${EXAMPLE_NAME} PROPERTY ENVIRONMENT_MODIFICATION
81+
"${DLL_PATH_LIST}")
82+
endif()
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
message(STATUS "Downloading Unified Memory Framework ...")
6+
7+
include(FetchContent)
8+
9+
if(NOT DEFINED UMF_REPO)
10+
set(UMF_REPO "https://github.com/oneapi-src/unified-memory-framework.git")
11+
elseif(WINDOWS)
12+
string(REPLACE "\\" "/" OUT_UMF_REPO "${UMF_REPO}")
13+
message(
14+
STATUS
15+
"Replaced \"${UMF_REPO}\" with \"${OUT_UMF_REPO}\" for Windows compatibility"
16+
)
17+
set(UMF_REPO "${OUT_UMF_REPO}")
18+
endif()
19+
20+
if(NOT DEFINED UMF_TAG)
21+
set(UMF_TAG HEAD)
22+
endif()
23+
24+
message(
25+
STATUS
26+
"Will fetch Unified Memory Framework from ${UMF_REPO} at ${UMF_TAG} ..."
27+
)
28+
message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
29+
30+
FetchContent_Declare(
31+
unified-memory-framework
32+
GIT_REPOSITORY ${UMF_REPO}
33+
GIT_TAG ${UMF_TAG})
34+
35+
set(UMF_BUILD_TESTS
36+
OFF
37+
CACHE INTERNAL "Do not build UMF tests")
38+
set(UMF_BUILD_EXAMPLES
39+
OFF
40+
CACHE INTERNAL "Do not build UMF examples")
41+
set(UMF_BUILD_SHARED_LIBRARY
42+
OFF
43+
CACHE INTERNAL "Build UMF shared library")
44+
set(UMF_BUILD_LIBUMF_POOL_DISJOINT
45+
ON
46+
CACHE INTERNAL "Build Disjoint Pool")
47+
set(UMF_BUILD_CUDA_PROVIDER
48+
OFF
49+
CACHE INTERNAL "Do not build CUDA provider")
50+
set(UMF_BUILD_LEVEL_ZERO_PROVIDER
51+
OFF
52+
CACHE INTERNAL "Do not build L0 provider")
53+
set(UMF_DISABLE_HWLOC
54+
OFF
55+
CACHE INTERNAL "Enable HWLOC support")
56+
set(UMF_LINK_HWLOC_STATICALLY
57+
OFF
58+
CACHE INTERNAL "UMF_LINK_HWLOC_STATICALLY=OFF")
59+
60+
FetchContent_MakeAvailable(unified-memory-framework)
61+
62+
set(LIBUMF_INCLUDE_DIRS ${unified-memory-framework_SOURCE_DIR}/include)
63+
set(LIBUMF_LIBRARIES umf::umf umf::headers)

test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,11 @@ if(LINUX
677677
set(EXAMPLES "")
678678

679679
if(UMF_POOL_SCALABLE_ENABLED)
680-
set(EXAMPLES ${EXAMPLES} basic custom_file_provider)
680+
set(EXAMPLES ${EXAMPLES} basic fetch_content custom_file_provider)
681681
else()
682682
message(
683683
STATUS
684-
"The basic and custom_file_provider examples require TBB to be installed and added to the default library search path - skipping"
684+
"The basic, fetch_content, and custom_file_provider examples require TBB to be installed and added to the default library search path - skipping"
685685
)
686686
endif()
687687

0 commit comments

Comments
 (0)