Skip to content

Commit 357f96b

Browse files
authored
[SYCL][CMake] Simplify emhash fetch code (intel#19894)
Upstream added a CMake install target, so now we can rely on that when using a system installed version, and we can create an interface target to emulate the real one when using FetchContent. The upstream CMake install target installs all files directly in the given prefix folder, so with `CMAKE_PREFIX_PATH=/usr` it will install `hash_table8.hpp` directly to `/usr`, not in an `emhash` subfolder. Since it seems that's how upstream wants this packaged, update our includes to remove the fake `emhash` subdirectory. Issue: intel#19635 --------- Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 3e875ec commit 357f96b

File tree

10 files changed

+20
-27
lines changed

10 files changed

+20
-27
lines changed

sycl/cmake/modules/AddSYCLUnitTest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ function(add_sycl_unittest_internal test_dirname link_variant is_preview)
121121
mockOpenCL
122122
LLVMTestingSupport
123123
OpenCL-Headers
124+
emhash::emhash
124125
unified-runtime::mock
125126
${SYCL_LINK_LIBS}
126127
)

sycl/cmake/modules/BuildUnifiedRuntime.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
216216
-DUMF_BUILD_SHARED_LIBRARY:BOOL=${UMF_BUILD_SHARED_LIBRARY}
217217
-DUMF_LINK_HWLOC_STATICALLY:BOOL=${UMF_LINK_HWLOC_STATICALLY}
218218
-DUMF_DISABLE_HWLOC:BOOL=${UMF_DISABLE_HWLOC}
219-
-DSYCL_EMHASH_DIR:STRING=${SYCL_EMHASH_DIR}
220219
# Enable d suffix in UMF
221220
-DUMF_USE_DEBUG_POSTFIX:BOOL=ON
222221
)
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
# Finds or fetches emhash.
2-
if(DEFINED SYCL_EMHASH_DIR OR DEFINED EMHASH_SYS_LOC)
2+
if(TARGET emhash::emhash)
33
return()
44
endif()
5-
find_file(EMHASH_SYS_LOC "hash_table8.hpp" PATH_SUFFIXES "emhash")
6-
if(NOT EMHASH_SYS_LOC)
5+
find_package(emhash QUIET)
6+
if(NOT emhash_FOUND)
77
set(EMHASH_REPO https://github.com/ktprime/emhash)
88
message(STATUS "Will fetch emhash from ${EMHASH_REPO}")
99
include(FetchContent)
1010
FetchContent_Declare(emhash
1111
GIT_REPOSITORY ${EMHASH_REPO}
12-
GIT_TAG 3ba9abdfdc2e0430fcc2fd8993cad31945b6a02b
12+
GIT_TAG 09fb0439de0c65e387498232c89d561ee95fbd60
1313
SOURCE_SUBDIR emhash
1414
)
1515
FetchContent_MakeAvailable(emhash)
1616

17-
# FetchContent downloads the files into a directory with
18-
# '-src' as the suffix and emhash has the headers in the
19-
# top level directory in the repo, so copy the headers to a directory
20-
# named `emhash` so source files can include with <emhash/header.hpp>
21-
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/emhash)
22-
file(GLOB HEADERS "${emhash_SOURCE_DIR}/*.h*")
23-
file(COPY ${HEADERS} DESTINATION ${CMAKE_BINARY_DIR}/include/emhash)
24-
set(SYCL_EMHASH_DIR ${CMAKE_BINARY_DIR}/include/ CACHE INTERNAL "")
17+
# The official cmake install target uses the 'emhash' namespace,
18+
# so emulate that here so client code can use a single target name for both cases.
19+
add_library(emhash INTERFACE)
20+
target_include_directories(emhash SYSTEM INTERFACE ${emhash_SOURCE_DIR})
21+
add_library(emhash::emhash ALIAS emhash)
2522
endif()

sycl/source/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,7 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
147147
target_include_directories(${LIB_OBJ_NAME} PRIVATE ${zstd_INCLUDE_DIR})
148148
endif()
149149

150-
if (EMHASH_SYS_LOC)
151-
# If we are using system emhash, include the system directory
152-
# containing the emhash folder and note this location so
153-
# other modules using emhash can find it.
154-
cmake_path(GET EMHASH_SYS_LOC PARENT_PATH EMHASH_SYS_LOC)
155-
set(SYCL_EMHASH_DIR ${EMHASH_SYS_LOC} CACHE INTERNAL "")
156-
target_include_directories(${LIB_OBJ_NAME} PRIVATE ${EMHASH_SYS_LOC})
157-
endif()
150+
target_link_libraries(${LIB_OBJ_NAME} PRIVATE emhash::emhash)
158151

159152
# ur_win_proxy_loader
160153
if (WIN32)

sycl/source/detail/device_kernel_info.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <detail/hashers.hpp>
1111
#include <detail/kernel_arg_mask.hpp>
12-
#include <emhash/hash_table8.hpp>
12+
#include <hash_table8.hpp>
1313
#include <sycl/detail/compile_time_kernel_info.hpp>
1414
#include <sycl/detail/kernel_name_str_t.hpp>
1515
#include <sycl/detail/spinlock.hpp>

sycl/source/detail/unordered_multimap.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===--------------------------------------------------------------===//
88
#pragma once
99
#include <detail/hashers.hpp>
10-
#include <emhash/hash_table8.hpp>
10+
#include <hash_table8.hpp>
1111

1212
#include <utility>
1313
#include <vector>

sycl/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ if(SYCL_ENABLE_EXTENSION_JIT)
2020
list(APPEND test_includes ${LLVM_EXTERNAL_SYCL_JIT_SOURCE_DIR}/jit-compiler/include)
2121
list(APPEND test_includes ${LLVM_EXTERNAL_SYCL_JIT_SOURCE_DIR}/common/include)
2222
endif(SYCL_ENABLE_EXTENSION_JIT)
23+
get_target_property(EMHASH_INCLUDES emhash::emhash INTERFACE_INCLUDE_DIRECTORIES)
24+
list(APPEND test_includes ${EMHASH_INCLUDES})
2325
list(JOIN test_includes ":" TEST_INCLUDE_PATH)
2426

2527
configure_lit_site_cfg(

xptifw/include/xpti_string_table.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "parallel_hashmap/phmap.h"
99
#include "xpti/xpti_data_types.h"
10-
#include <emhash/hash_table7.hpp>
10+
#include <hash_table7.hpp>
1111

1212
#include <atomic>
1313
#include <shared_mutex>

xptifw/src/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include(FetchContent)
33

44
# The sycl target should download or find emhash but may not
55
# for standalone builds.
6-
if (NOT SYCL_EMHASH_DIR)
6+
if (NOT TARGET emhash::emhash)
77
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../../sycl/cmake/modules")
88
include(FetchEmhash)
99
endif()
@@ -37,11 +37,12 @@ function(add_xpti_library LIB_NAME)
3737
target_compile_definitions(${LIB_NAME} PRIVATE -DXPTI_API_EXPORTS)
3838
target_include_directories(${LIB_NAME} PUBLIC
3939
$<BUILD_INTERFACE:${XPTIFW_DIR}/include>
40-
$<BUILD_INTERFACE:${SYCL_EMHASH_DIR}>
4140
$<BUILD_INTERFACE:${XPTIFW_PARALLEL_HASHMAP_HEADERS}>
4241
$<BUILD_INTERFACE:${XPTI_DIR}/include>
4342
)
4443

44+
target_link_libraries(${LIB_NAME} PUBLIC emhash::emhash)
45+
4546
find_package(Threads REQUIRED)
4647
target_link_libraries(${LIB_NAME} PUBLIC ${CMAKE_DL_LIBS} Threads::Threads)
4748

xptifw/src/xpti_trace_framework.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "xpti_int64_hash_table.hpp"
2020
#include "xpti_object_table.hpp"
2121
#include "xpti_string_table.hpp"
22-
#include <emhash/hash_table7.hpp>
22+
#include <hash_table7.hpp>
2323

2424
#include <algorithm>
2525
#include <array>

0 commit comments

Comments
 (0)