Skip to content

Add test for FetchContent of UMF on Linux and Windows #1384

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,30 @@ jobs:
${{ matrix.umfd_lib == 'ON' && '--umfd-lib' || ''}}
${{ matrix.static_hwloc == 'ON' && '--hwloc' || '' }}

- name: Set VCPKG_PATH with hwloc for the fetch_content example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have a step like this, I guess we could just do the same as in that step: add if: matrix.static_hwloc == 'OFF' to the fetch_content example's configure/build/execution steps

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fetch_content example always requires hwloc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'm just saying, we could test that example only in cases where the job already have VCPKG_PATH set

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

- name: Configure the fetch_content example
working-directory: ${{github.workspace}}/examples/fetch_content
# Fetch_Content the UMF code from the current repository (-DUMF_REPO="${{github.workspace}}")
run: >
cmake
-B ${{github.workspace}}/examples/fetch_content/build
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
-DUMF_REPO="${{github.workspace}}"
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-G "${{matrix.generator}}"

- name: Build the fetch_content example
working-directory: ${{github.workspace}}/examples/fetch_content
run: cmake --build ${{github.workspace}}/examples/fetch_content/build --config ${{matrix.build_type}} -j $env:NUMBER_OF_PROCESSORS

- name: Run the fetch_content example
working-directory: ${{github.workspace}}/examples/fetch_content/build
run: ctest -V

# Build and test UMF with Intel C++ Compiler (ICX) on Windows
Windows-icx:
env:
Expand Down
73 changes: 73 additions & 0 deletions examples/fetch_content/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (C) 2025 Intel Corporation
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could add a short description why do we have this example

cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
project(umf_example_fetch_content LANGUAGES C)
enable_testing()

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LINUX TRUE)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(WINDOWS TRUE)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
else()
message(FATAL_ERROR "Unknown OS type")
endif()

set(UMF_EXAMPLE_DIR "${CMAKE_SOURCE_DIR}/..")
list(APPEND CMAKE_MODULE_PATH "${UMF_EXAMPLE_DIR}/cmake")
message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")

include("fetch_umf.cmake")

find_package(PkgConfig)
pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
if(NOT LIBHWLOC_FOUND)
find_package(LIBHWLOC 2.3.0 REQUIRED hwloc)
endif()

pkg_check_modules(TBB tbb)
if(NOT TBB_FOUND)
find_package(TBB REQUIRED tbb)
endif()

# build the example
set(EXAMPLE_NAME umf_example_fetch_content)
# reusing the basic.c source file from the basic example
add_executable(${EXAMPLE_NAME} ${CMAKE_SOURCE_DIR}/../basic/basic.c)
target_include_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_INCLUDE_DIRS})
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
target_link_libraries(${EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARIES} hwloc)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add printing of PATHs found in this example and used above..?

// e.g. like here: https://github.com/lukaszstolarczuk/unified-memory-framework/actions/runs/16051712582/job/45295762065#step:11:4353

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which paths exactly do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly which umf is used (so LIBUMF_INCLUDE_DIRS, but also btw we could print LIBHWLOC_LIBRARY_DIRS and LIBUMF_LIBRARIES) - see my example CI run (link above)

# an optional part - adds a test of this example
add_test(
NAME ${EXAMPLE_NAME}
COMMAND ${EXAMPLE_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

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

if(LINUX)
# set LD_LIBRARY_PATH
set_property(
TEST ${EXAMPLE_NAME}
PROPERTY
ENVIRONMENT_MODIFICATION
"LD_LIBRARY_PATH=path_list_append:${LIBUMF_LIBRARY_DIRS};LD_LIBRARY_PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}"
)
elseif(WINDOWS)
# add PATH to DLL on Windows
set(DLL_PATH_LIST
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_DLL_DIRS};PATH=path_list_append:${TBB_DLL_DIRS}"
)

message(STATUS "DLL_PATH_LIST=${DLL_PATH_LIST}")

# append PATH to DLLs NOTE: this would work only for the CMake ver >= #
# 3.22. For the older versions, the PATH variable should be set in the test
# script)
set_property(TEST ${EXAMPLE_NAME} PROPERTY ENVIRONMENT_MODIFICATION
"${DLL_PATH_LIST}")
endif()
64 changes: 64 additions & 0 deletions examples/fetch_content/fetch_umf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (C) 2025 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a general note, not neccessarily needed to be done in this PR - so now, as we test it, perhaps we should add a README section about integration (e.g. like in UR repo: https://github.com/oneapi-src/unified-runtime?tab=readme-ov-file#integration)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can consider that. The question is if it should be the recommended way to integrate UMF.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm yeah, probably we shouldn't say that it's recommended

# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

message(STATUS "Downloading Unified Memory Framework ...")

include(FetchContent)

if(NOT DEFINED UMF_REPO)
set(UMF_REPO "https://github.com/oneapi-src/unified-memory-framework.git")
elseif(WINDOWS)
string(REPLACE "\\" "/" OUT_UMF_REPO "${UMF_REPO}")
message(
STATUS
"Replaced \"${UMF_REPO}\" with \"${OUT_UMF_REPO}\" for Windows compatibility"
)
set(UMF_REPO "${OUT_UMF_REPO}")
endif()

if(NOT DEFINED UMF_TAG)
set(UMF_TAG HEAD)
endif()

message(
STATUS
"Will fetch Unified Memory Framework from ${UMF_REPO} at ${UMF_TAG} ..."
)
message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")

FetchContent_Declare(
unified-memory-framework
GIT_REPOSITORY ${UMF_REPO}
GIT_TAG ${UMF_TAG})

set(UMF_BUILD_TESTS
OFF
CACHE INTERNAL "Do not build UMF tests")
set(UMF_BUILD_EXAMPLES
OFF
CACHE INTERNAL "Do not build UMF examples")
set(UMF_BUILD_SHARED_LIBRARY
OFF
CACHE INTERNAL "Build UMF shared library")
set(UMF_BUILD_LIBUMF_POOL_DISJOINT
ON
CACHE INTERNAL "Build Disjoint Pool")
set(UMF_BUILD_CUDA_PROVIDER
OFF
CACHE INTERNAL "Do not build CUDA provider")
set(UMF_BUILD_LEVEL_ZERO_PROVIDER
OFF
CACHE INTERNAL "Do not build L0 provider")
set(UMF_DISABLE_HWLOC
OFF
CACHE INTERNAL "Enable HWLOC support")
set(UMF_LINK_HWLOC_STATICALLY
OFF
CACHE INTERNAL "UMF_LINK_HWLOC_STATICALLY=OFF")

FetchContent_MakeAvailable(unified-memory-framework)
FetchContent_GetProperties(unified-memory-framework)

set(LIBUMF_INCLUDE_DIRS ${unified-memory-framework_SOURCE_DIR}/include)
set(LIBUMF_LIBRARIES umf::umf umf::headers)
4 changes: 2 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,11 @@ if(LINUX
set(EXAMPLES "")

if(UMF_POOL_SCALABLE_ENABLED)
set(EXAMPLES ${EXAMPLES} basic custom_file_provider)
set(EXAMPLES ${EXAMPLES} basic fetch_content custom_file_provider)
else()
message(
STATUS
"The basic and custom_file_provider examples require TBB to be installed and added to the default library search path - skipping"
"The basic, fetch_content and custom_file_provider examples require TBB to be installed and added to the default library search path - skipping"
)
endif()

Expand Down
Loading