Skip to content

Commit 06407ab

Browse files
authored
[UR][CMake] Improve handling of UMF and hdr_histogram (#19705)
First, add support for pre-installed `hdr_histogram`. Second, make `UR_USE_EXTERNAL_UMF` on by default and have it fallback to `FetchContent` if it is not found instead of erroring. The user can disable it to force `FetchContent` even if they have a preinstalled version. We don't need repo or tag variables because the user can just set `FETCHCONTENT_SOURCE_DIR_UNIFIED-MEMORY-FRAMEWORK`, and this matches how we handle other deps. Issue: #19635 --------- Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 9f8e480 commit 06407ab

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

sycl/cmake/modules/FetchUnifiedRuntime.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
426426
endif()
427427
endif()
428428

429-
if(NOT UR_USE_EXTERNAL_UMF)
429+
if(TARGET umf)
430430
install(TARGETS umf
431431
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT unified-memory-framework
432432
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT unified-memory-framework

unified-runtime/source/common/CMakeLists.txt

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,41 @@ target_include_directories(ur_common PUBLIC
3636
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
3737
)
3838

39-
message(STATUS "Download Unified Memory Framework from github.com")
40-
if (NOT DEFINED UMF_REPO)
41-
set(UMF_REPO "https://github.com/oneapi-src/unified-memory-framework.git")
42-
endif()
43-
44-
if (NOT DEFINED UMF_TAG)
45-
# commit 1de269c00e46b7cbdbafa2247812c8c4bb4ed4a5
46-
# Author: Łukasz Stolarczuk <[email protected]>
47-
# Date: Mon Jul 21 15:42:59 2025 +0200
48-
# 1.0.0 release
49-
set(UMF_TAG v1.0.0)
50-
endif()
51-
52-
message(STATUS "Will fetch Unified Memory Framework from ${UMF_REPO}")
53-
54-
include(FetchContent)
55-
FetchContent_Declare(unified-memory-framework
56-
GIT_REPOSITORY ${UMF_REPO}
57-
GIT_TAG ${UMF_TAG}
58-
)
5939

6040
if (UR_STATIC_ADAPTER_L0)
6141
if (UMF_BUILD_SHARED_LIBRARY)
6242
message(STATUS "Static adapter is not compatible with shared UMF, switching to fully statically linked UMF")
6343
set(UMF_BUILD_SHARED_LIBRARY OFF)
6444
endif()
6545
endif()
46+
47+
set(UR_USE_EXTERNAL_UMF ON CACHE BOOL "Use a pre-built UMF if available")
6648

67-
set(UR_USE_EXTERNAL_UMF OFF CACHE BOOL "Use a pre-built UMF")
68-
69-
if (UR_USE_EXTERNAL_UMF)
70-
find_package(umf REQUIRED)
49+
if(UR_USE_EXTERNAL_UMF)
50+
find_package(umf 1.0.0 QUIET)
51+
endif()
52+
if(umf_FOUND)
53+
message(STATUS "Using preinstalled UMF at ${umf_DIR}, ignoring UMF build related options")
7154
# Add an alias matching the FetchContent case
7255
add_library(umf::headers ALIAS umf::umf_headers)
7356
else()
57+
set(UMF_REPO "https://github.com/oneapi-src/unified-memory-framework.git")
58+
59+
# commit 1de269c00e46b7cbdbafa2247812c8c4bb4ed4a5
60+
# Author: Łukasz Stolarczuk <[email protected]>
61+
# Date: Mon Jul 21 15:42:59 2025 +0200
62+
# 1.0.0 release
63+
set(UMF_TAG v1.0.0)
64+
65+
if(NOT FETCHCONTENT_SOURCE_DIR_UNIFIED-MEMORY-FRAMEWORK)
66+
message(STATUS "Will fetch Unified Memory Framework from ${UMF_REPO}")
67+
endif()
68+
69+
include(FetchContent)
70+
FetchContent_Declare(unified-memory-framework
71+
GIT_REPOSITORY ${UMF_REPO}
72+
GIT_TAG ${UMF_TAG}
73+
)
7474
set(UMF_BUILD_TESTS OFF CACHE INTERNAL "Build UMF tests")
7575
set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "Build UMF examples")
7676
set(UMF_BUILD_SHARED_LIBRARY ${UMF_BUILD_SHARED_LIBRARY} CACHE INTERNAL "Build UMF shared library")
@@ -80,6 +80,10 @@ else()
8080
endif()
8181

8282
if(UR_ENABLE_LATENCY_HISTOGRAM)
83+
find_package(hdr_histogram QUIET)
84+
if(hdr_histogram_FOUND)
85+
set(hdr_histogram_SOURCE_DIR "${hdr_histogram_DIR}")
86+
else()
8387
set(HDR_HISTOGRAM_BUILD_STATIC CACHE INTERNAL ON "")
8488
set(HDR_HISTOGRAM_BUILD_SHARED CACHE INTERNAL OFF "")
8589

@@ -91,10 +95,10 @@ if(UR_ENABLE_LATENCY_HISTOGRAM)
9195

9296
FetchContent_MakeAvailable(hdr_histogram)
9397
FetchContent_GetProperties(hdr_histogram)
94-
95-
target_link_libraries(ur_common PUBLIC hdr_histogram_static)
96-
target_include_directories(ur_common PUBLIC $<BUILD_INTERFACE:${hdr_histogram_SOURCE_DIR}/include>)
97-
target_compile_options(ur_common PUBLIC -DUR_ENABLE_LATENCY_HISTOGRAM=1)
98+
endif()
99+
target_link_libraries(ur_common PUBLIC hdr_histogram_static)
100+
target_include_directories(ur_common PUBLIC $<BUILD_INTERFACE:${hdr_histogram_SOURCE_DIR}/include>)
101+
target_compile_options(ur_common PUBLIC -DUR_ENABLE_LATENCY_HISTOGRAM=1)
98102
endif()
99103

100104
target_link_libraries(ur_common PUBLIC

0 commit comments

Comments
 (0)