diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index 3445350325e0a..03dae0448f90f 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -82,6 +82,7 @@ if(MSVC) endif() endif() +include(FetchEmhash) include(FetchUnifiedRuntime) # The change in SYCL_MAJOR_VERSION must be accompanied with the same update in @@ -213,9 +214,6 @@ install(FILES DESTINATION "${SYCL_INCLUDE_DIR}/sycl" COMPONENT sycl-headers) -include(AddBoostMp11Headers) -include(FetchBoostUnorderedHeaders) - # This is workaround to detect changes (add or modify) in subtree which # are not detected by copy_directory command. # TODO: detect and process remove header/directory case @@ -250,7 +248,7 @@ add_custom_target(sycl-headers ${OUT_HEADERS_IN_SYCLCOMPAT_DIR} ${OUT_UR_HEADERS} sycl-device-aspect-macros-header - boost_mp11-headers) + ) add_custom_command( OUTPUT ${OUT_HEADERS_IN_SYCL_DIR} @@ -275,7 +273,6 @@ add_custom_command( install(DIRECTORY "${sycl_inc_dir}/sycl" DESTINATION ${SYCL_INCLUDE_DIR} COMPONENT sycl-headers) install(DIRECTORY "${sycl_inc_dir}/CL" DESTINATION ${SYCL_INCLUDE_DIR}/ COMPONENT sycl-headers) install(DIRECTORY "${sycl_inc_dir}/std" DESTINATION ${SYCL_INCLUDE_DIR} COMPONENT sycl-headers) -install(DIRECTORY ${BOOST_MP11_DESTINATION_DIR} DESTINATION ${SYCL_INCLUDE_DIR}/sycl/detail COMPONENT boost_mp11-headers) install(DIRECTORY "${sycl_inc_dir}/syclcompat" DESTINATION ${SYCL_INCLUDE_DIR} COMPONENT sycl-headers) install(FILES "${sycl_inc_dir}/syclcompat.hpp" DESTINATION ${SYCL_INCLUDE_DIR} COMPONENT sycl-headers) install(FILES "${UNIFIED_RUNTIME_INCLUDE_DIR}/ur_api.h" DESTINATION ${SYCL_INCLUDE_DIR} @@ -458,7 +455,6 @@ get_property(SYCL_TOOLCHAIN_DEPS GLOBAL PROPERTY SYCL_TOOLCHAIN_INSTALL_COMPONEN # Listed here are component names contributing the package set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS append-file - boost_mp11-headers clang clang-offload-wrapper clang-offload-bundler diff --git a/sycl/cmake/modules/AddBoostMp11Headers.cmake b/sycl/cmake/modules/AddBoostMp11Headers.cmake deleted file mode 100644 index 4d01c11545214..0000000000000 --- a/sycl/cmake/modules/AddBoostMp11Headers.cmake +++ /dev/null @@ -1,54 +0,0 @@ -# boost/mp11 headers import and preprocessing -# See more comments in cmake/modules/PreprocessBoostMp11Headers.cmake - -include(FetchContent) - -set(BOOST_MP11_GIT_REPO https://github.com/boostorg/mp11.git) -# Author: pdimov -# Date: Dec 31, 2023 -# Release: boost-1.85.0 -set(BOOST_MP11_GIT_TAG 863d8b8d2b20f2acd0b5870f23e553df9ce90e6c) - -# Either download from github or use existing if BOOST_MP11_SOURCE_DIR is set -if (NOT DEFINED BOOST_MP11_SOURCE_DIR) - message(STATUS "BOOST_MP11_SOURCE_DIR not set, downloading boost/mp11 headers from ${BOOST_MP11_GIT_REPO}") - - FetchContent_Declare(boost_mp11 - GIT_REPOSITORY ${BOOST_MP11_GIT_REPO} - GIT_TAG ${BOOST_MP11_GIT_TAG} - ) - FetchContent_GetProperties(boost_mp11) - FetchContent_MakeAvailable(boost_mp11) - - set(BOOST_MP11_SOURCE_DIR ${boost_mp11_SOURCE_DIR}) - set(BOOST_MP11_SRC_PATH ${BOOST_MP11_GIT_REPO}) - set(BOOST_MP11_SRC_ID "git commit hash: ${BOOST_MP11_GIT_TAG}") -else (NOT DEFINED BOOST_MP11_SOURCE_DIR) - message(STATUS "Using boost/mp11 headers from ${BOOST_MP11_SOURCE_DIR}") - set(BOOST_MP11_SRC_PATH ${BOOST_MP11_SOURCE_DIR}) - set(BOOST_MP11_SRC_ID "ID not set") -endif(NOT DEFINED BOOST_MP11_SOURCE_DIR) - -# Read all header file names into HEADERS_BOOST_MP11 -file(GLOB_RECURSE HEADERS_BOOST_MP11 CONFIGURE_DEPENDS "${BOOST_MP11_SOURCE_DIR}/include/boost/*") - -set(BOOST_MP11_DESTINATION_DIR ${SYCL_INCLUDE_BUILD_DIR}/sycl/detail/boost) -string(REPLACE "${BOOST_MP11_SOURCE_DIR}/include/boost" "${BOOST_MP11_DESTINATION_DIR}" - OUT_HEADERS_BOOST_MP11 "${HEADERS_BOOST_MP11}") - -# The target which produces preprocessed boost/mp11 headers -add_custom_target(boost_mp11-headers - DEPENDS ${OUT_HEADERS_BOOST_MP11}) - -# Run preprocessing on each header, output result into -# ${BOOST_MP11_DESTINATION_DIR} -add_custom_command( - OUTPUT ${OUT_HEADERS_BOOST_MP11} - DEPENDS ${HEADERS_BOOST_MP11} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/PreprocessBoostMp11Headers.cmake - COMMAND ${CMAKE_COMMAND} - -DIN=${BOOST_MP11_SOURCE_DIR}/include/boost - -DOUT=${BOOST_MP11_DESTINATION_DIR} - -DSRC_PATH="${BOOST_MP11_SRC_PATH}" - -DSRC_ID="${BOOST_MP11_SRC_ID}" - -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/PreprocessBoostMp11Headers.cmake - COMMENT "Preprocessing boost/mp11 headers ${BOOST_MP11_SOURCE_DIR}/include/boost -> ${BOOST_MP11_DESTINATION_DIR}...") diff --git a/sycl/cmake/modules/FetchBoostUnorderedHeaders.cmake b/sycl/cmake/modules/FetchBoostUnorderedHeaders.cmake deleted file mode 100644 index 5cabc6cccdbf6..0000000000000 --- a/sycl/cmake/modules/FetchBoostUnorderedHeaders.cmake +++ /dev/null @@ -1,101 +0,0 @@ -# Fetches the unordered boost module and its dependencies -function(add_boost_module_headers) - cmake_parse_arguments( - BOOST_MODULE # prefix - "" # options - "NAME;SRC_DIR;GIT_TAG;" # one value keywords - "" # multi-value keywords - ${ARGN}) # arguments - - if (NOT DEFINED BOOST_MODULE_SRC_DIR) - set(BOOST_MODULE_GIT_REPO "https://github.com/boostorg/${BOOST_MODULE_NAME}.git") - message(STATUS "Source dir not set for boost module ${BOOST_MODULE_NAME}, downloading headers from ${BOOST_MODULE_GIT_REPO}") - - set(BOOST_MODULE_FULL_NAME "boost_${BOOST_MODULE_NAME}") - FetchContent_Declare(${BOOST_MODULE_FULL_NAME} - GIT_REPOSITORY ${BOOST_MODULE_GIT_REPO} - GIT_TAG ${BOOST_MODULE_GIT_TAG} - ) - FetchContent_GetProperties(${BOOST_MODULE_FULL_NAME}) - FetchContent_MakeAvailable(${BOOST_MODULE_FULL_NAME}) - - set(BOOST_MODULE_SRC_DIR ${${BOOST_MODULE_FULL_NAME}_SOURCE_DIR}) - else (NOT DEFINED BOOST_MODULE_SRC_DIR) - message(STATUS "Using boost/${BOOST_MODULE_NAME} headers from ${BOOST_MODULE_SRC_DIR}") - endif(NOT DEFINED BOOST_MODULE_SRC_DIR) - - set(BOOST_UNORDERED_INCLUDE_DIRS ${BOOST_UNORDERED_INCLUDE_DIRS} "${BOOST_MODULE_SRC_DIR}/include" PARENT_SCOPE) -endfunction(add_boost_module_headers) - -set(BOOST_UNORDERED_GIT_TAG 5e6b9291deb55567d41416af1e77c2516dc1250f) -# Merge: 15cfef69 ccf9a76e -# Author: joaquintides -# Date: Sat Mar 16 09:18:41 2024 +0100 -# -# Merge pull request #238 from boostorg/fix/gh-237 -add_boost_module_headers(NAME "unordered" SRC_DIR ${BOOST_UNORDERED_SOURCE_DIR} GIT_TAG ${BOOST_UNORDERED_GIT_TAG}) - -set(BOOST_ASSERT_GIT_TAG 447e0b3a331930f8708ade0e42683d12de9dfbc3) -# Author: Peter Dimov -# Date: Sat Feb 3 20:43:55 2024 +0200 -# -# Use __builtin_FUNCSIG() under MSVC 19.35+. Fixes #35. -add_boost_module_headers(NAME "assert" SRC_DIR ${BOOST_ASSERT_SOURCE_DIR} GIT_TAG ${BOOST_ASSERT_GIT_TAG}) - -set(BOOST_CONFIG_GIT_TAG 11385ec21012926e15a612e3bf9f9a71403c1e5b) -# Merge: eef05e98 601598f8 -# Author: jzmaddock -# Date: Sun Feb 4 09:46:22 2024 +0000 -# -# Merge branch 'develop' -add_boost_module_headers(NAME "config" SRC_DIR ${BOOST_CONFIG_SOURCE_DIR} GIT_TAG ${BOOST_CONFIG_GIT_TAG}) - -set(BOOST_CONTAINER_HASH_GIT_TAG 6d214eb776456bf17fbee20780a034a23438084f) -# Author: Peter Dimov -# Date: Wed Mar 6 05:13:53 2024 +0200 -# -# Update .appveyor.yml -add_boost_module_headers(NAME "container_hash" SRC_DIR ${BOOST_CONTAINER_HASH_SOURCE_DIR} GIT_TAG ${BOOST_CONTAINER_HASH_GIT_TAG}) - -set(BOOST_CORE_GIT_TAG 083b41c17e34f1fc9b43ab796b40d0d8bece685c) -# Merge: 8cc2fda a973490 -# Author: Andrey Semashev -# Date: Tue Mar 19 18:10:04 2024 +0300 -# -# Merge pull request #169 from k3DW/feature/168 -add_boost_module_headers(NAME "core" SRC_DIR ${BOOST_CORE_SOURCE_DIR} GIT_TAG ${BOOST_CORE_GIT_TAG}) - -# Describe is a dependency of container_hash -set(BOOST_DESCRIBE_GIT_TAG 50719b212349f3d1268285c586331584d3dbfeb5) -# Author: Peter Dimov -# Date: Sat Mar 23 20:27:08 2024 +0200 -# -# Update .drone.jsonnet -add_boost_module_headers(NAME "describe" SRC_DIR ${BOOST_DESCRIBE_SOURCE_DIR} GIT_TAG ${BOOST_DESCRIBE_GIT_TAG}) - -# Reuse mp11 fetched earlier for DPC++ headers -set(BOOST_UNORDERED_INCLUDE_DIRS ${BOOST_UNORDERED_INCLUDE_DIRS} "${BOOST_MP11_SOURCE_DIR}/include/") - -set(BOOST_PREDEF_GIT_TAG 0fdfb49c3a6789e50169a44e88a07cc889001106) -# Merge: 392e4e7 614546d -# Author: Rene Rivera -# Date: Tue Oct 31 20:24:41 2023 -0500 -# -# Merge branch 'develop' -add_boost_module_headers(NAME "predef" SRC_DIR ${BOOST_PREDEF_SOURCE_DIR} GIT_TAG ${BOOST_PREDEF_GIT_TAG}) - -# Static assert is a dependency of core -set(BOOST_STATIC_ASSERT_GIT_TAG ba72d3340f3dc6e773868107f35902292f84b07e) -# Merge: 392e4e7 614546d -# Author: Rene Rivera -# Date: Tue Oct 31 20:24:41 2023 -0500 -# -# Merge branch 'develop' -add_boost_module_headers(NAME "static_assert" SRC_DIR ${BOOST_STATIC_ASSERT_SOURCE_DIR} GIT_TAG ${BOOST_STATIC_ASSERT_GIT_TAG}) - -set(BOOST_THROW_EXCEPTION_GIT_TAG 7c8ec2114bc1f9ab2a8afbd629b96fbdd5901294) -# Author: Peter Dimov -# Date: Sat Jan 6 19:41:56 2024 +0200 -# -# Add -Wundef to test/Jamfile -add_boost_module_headers(NAME "throw_exception" SRC_DIR ${BOOST_THROW_EXCEPTION_SOURCE_DIR} GIT_TAG ${BOOST_THROW_EXCEPTION_GIT_TAG}) diff --git a/sycl/cmake/modules/FetchEmhash.cmake b/sycl/cmake/modules/FetchEmhash.cmake new file mode 100644 index 0000000000000..df7da1cf7b95d --- /dev/null +++ b/sycl/cmake/modules/FetchEmhash.cmake @@ -0,0 +1,21 @@ +# Finds or fetches emhash. +find_file(EMHASH_SYS_LOC "hash_table8.hpp" PATH_SUFFIXES "emhash") +if(NOT EMHASH_SYS_LOC) + set(EMHASH_REPO https://github.com/ktprime/emhash) + message(STATUS "Will fetch emhash from ${EMHASH_REPO}") + FetchContent_Declare(emhash + GIT_REPOSITORY ${EMHASH_REPO} + GIT_TAG 3ba9abdfdc2e0430fcc2fd8993cad31945b6a02b + SOURCE_SUBDIR emhash + ) + FetchContent_MakeAvailable(emhash) + + # FetchContent downloads the files into a directory with + # '-src' as the suffix and emhash has the headers in the + # top level directory in the repo, so copy the headers to a directory + # named `emhash` so source files can include with + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/emhash) + file(GLOB HEADERS "${emhash_SOURCE_DIR}/*.h*") + file(COPY ${HEADERS} DESTINATION ${CMAKE_BINARY_DIR}/include/emhash) + set(SYCL_EMHASH_DIR ${CMAKE_BINARY_DIR}/include/ CACHE INTERNAL "") +endif() diff --git a/sycl/cmake/modules/FetchUnifiedRuntime.cmake b/sycl/cmake/modules/FetchUnifiedRuntime.cmake index e96eec28be350..00d6066317322 100644 --- a/sycl/cmake/modules/FetchUnifiedRuntime.cmake +++ b/sycl/cmake/modules/FetchUnifiedRuntime.cmake @@ -358,6 +358,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows) -DUMF_BUILD_SHARED_LIBRARY:BOOL=${UMF_BUILD_SHARED_LIBRARY} -DUMF_LINK_HWLOC_STATICALLY:BOOL=${UMF_LINK_HWLOC_STATICALLY} -DUMF_DISABLE_HWLOC:BOOL=${UMF_DISABLE_HWLOC} + -DSYCL_EMHASH_DIR:STRING=${SYCL_EMHASH_DIR} # Enable d suffix in UMF -DUMF_USE_DEBUG_POSTFIX:BOOL=ON ) diff --git a/sycl/cmake/modules/PreprocessBoostMp11Headers.cmake b/sycl/cmake/modules/PreprocessBoostMp11Headers.cmake deleted file mode 100644 index bb8127093216c..0000000000000 --- a/sycl/cmake/modules/PreprocessBoostMp11Headers.cmake +++ /dev/null @@ -1,105 +0,0 @@ -# Preprocess boost/mp11 headers to allow using specific version of mp11 (as -# defined in these project's cmake files) within SYCL library w/o risk of -# conflict with user program using another version of boost/mp11. Basically, -# this transformation moves all APIs from boost namespace to sycl::boost and -# adds SYCL_ prefix to boost macros names. See more specific comments in the -# code below. -# Variables which must be set by the caller to control behavior of this module: -# - IN -# The source directory with mp11 headers, must contain mp11.h. -# - OUT -# The destination directory where preprocessed source headers are put. -# - SRC_PATH -# An URL or directory name the source directory originates from. Used only in -# generated README text. -# - SRC_ID -# Git hash/tag or other ID identifying the original source. Used only in -# generated README text. -# -# Assumed to be invoked as a script: -# ${CMAKE_COMMAND} -DIN=... -DOUT=... -DSRC_PATH=... -DSRC_ID=... -P - -function(preprocess_mp11_header) - cmake_parse_arguments( - MP11_HDR # prefix - "" # options - "SRC_NAME;DST_NAME;IN_DIR" # one value keywords - "" # multi-value keywords - ${ARGN}) # arguments - file(READ ${MP11_HDR_SRC_NAME} FILE_CONTENTS) - - # 1) replace `BOOST_*` macros with `SYCL_BOOST_*`. - string(REGEX REPLACE - "([ \t\n\r!(])BOOST_" - "\\1SYCL_DETAIL_BOOST_" - FILE_CONTENTS "${FILE_CONTENTS}") - # 2) replace `namespace boost { ... }` with - # `namespace sycl { namespace detail { namespace boost { ... } } }` - string(REGEX REPLACE - "(\n[ \t]*namespace[ \t\n\r]+boost)" - "namespace sycl\n{\ninline namespace _V1\n{\nnamespace detail\n{\\1" - FILE_CONTENTS "${FILE_CONTENTS}") - # ... use '} // namespace boost' as a marker for end-of-scope '}' replacement - string(REGEX REPLACE - "(\n[ \t]*}[ \t]*//[ \t]*namespace[ \t]+boost[ \t]*\n)" - "\\1} // namespace detail\n} // namespace _V1\n} // namespace sycl\n" - FILE_CONTENTS "${FILE_CONTENTS}") - # 3) replace `boost` in `#include ` or `#include "boost/..."` with - # `sycl/detail/boost` - string(REGEX REPLACE - "(\n#include[ \t]*[<\"])boost" - "\\1sycl/detail/boost" - FILE_CONTENTS "${FILE_CONTENTS}") - - set(SYCL_DERIVED_COPYRIGHT_NOTICE "\ - // -*- C++ -*-\n\ - //===----------------------------------------------------------------------===//\n\ - // Modifications Copyright Intel Corporation 2022\n\ - // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n\ - //===----------------------------------------------------------------------===//\n\ - // Auto-generated from boost/mp11 sources https://github.com/boostorg/mp11\n\n") - - # 4) add proper copyright notice atop - string(PREPEND FILE_CONTENTS ${SYCL_DERIVED_COPYRIGHT_NOTICE}) - file(WRITE ${MP11_HDR_DST_NAME} "${FILE_CONTENTS}") -endfunction(preprocess_mp11_header) - -function(preprocess_mp11_headers) - cmake_parse_arguments( - MP11_HDRS # prefix - "" # options - "IN;OUT;SRC_PATH;SRC_ID" # one value keywords - "" # multi-value keywords - ${ARGN}) # arguments - - # 1) Perform necessary preprocessing of headers. - file(GLOB_RECURSE BOOST_MP11_SOURCES "${MP11_HDRS_IN}/*") - - foreach(SRC ${BOOST_MP11_SOURCES}) - string(REPLACE "${MP11_HDRS_IN}" "${MP11_HDRS_OUT}" DST "${SRC}") - preprocess_mp11_header( - SRC_NAME ${SRC} - DST_NAME ${DST} - IN_DIR ${MP11_HDRS_IN} - ) - endforeach(SRC ${BOOST_MP11_SOURCES}) - - # 2) Add SYCL_README.txt to the output directory root - set(SYCL_README_TEXT "\ - This directory contains boost/mp11 headers adapted for use in SYCL headers in\n\ - a way that does not conflict with potential use of boost in user code.\n\ - Particularly, `BOOST_*` macros are replaced with `SYCL_DETAIL_BOOST_*`, APIs\n\ - are moved into the top-level `sycl::detail` namespace. For example,\n\ - `sycl::detail::boost::mp11::mp_list`.\n") - - set(SYCL_README_FILE_NAME "${MP11_HDRS_OUT}/README.txt") - - file(WRITE ${SYCL_README_FILE_NAME} "${SYCL_README_TEXT}") -endfunction(preprocess_mp11_headers) - -preprocess_mp11_headers( - IN ${IN} - OUT ${OUT} - SRC_PATH ${SRC_PATH} - SRC_ID ${SRC_ID} -) diff --git a/sycl/source/CMakeLists.txt b/sycl/source/CMakeLists.txt index 20bf85f1b61ca..d7b68b781ee0f 100644 --- a/sycl/source/CMakeLists.txt +++ b/sycl/source/CMakeLists.txt @@ -149,6 +149,15 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME) target_include_directories(${LIB_OBJ_NAME} PRIVATE ${zstd_INCLUDE_DIR}) endif() + if (EMHASH_SYS_LOC) + # If we are using system emhash, include the system directory + # containing the emhash folder and note this location so + # other modules using emhash can find it. + cmake_path(GET EMHASH_SYS_LOC PARENT_PATH EMHASH_SYS_LOC) + set(SYCL_EMHASH_DIR ${EMHASH_SYS_LOC} CACHE INTERNAL "") + target_include_directories(${LIB_OBJ_NAME} PRIVATE ${EMHASH_SYS_LOC}) + endif() + # ur_win_proxy_loader if (WIN32) include_directories(${LLVM_EXTERNAL_SYCL_SOURCE_DIR}/ur_win_proxy_loader) diff --git a/sycl/source/detail/context_impl.cpp b/sycl/source/detail/context_impl.cpp index 9fe103986f913..0c3f1beee3544 100644 --- a/sycl/source/detail/context_impl.cpp +++ b/sycl/source/detail/context_impl.cpp @@ -530,7 +530,7 @@ std::optional context_impl::getProgramForDevImgs( auto KeyMappingsIt = KeyMap.find(OuterKey); assert(KeyMappingsIt != KeyMap.end()); - auto CachedProgIt = Cache.find(KeyMappingsIt->second); + auto CachedProgIt = Cache.find((*KeyMappingsIt).second); assert(CachedProgIt != Cache.end()); BuildRes = CachedProgIt->second; } diff --git a/sycl/source/detail/hashers.hpp b/sycl/source/detail/hashers.hpp new file mode 100644 index 0000000000000..021ddf2ece542 --- /dev/null +++ b/sycl/source/detail/hashers.hpp @@ -0,0 +1,48 @@ +//==--------------------- hashers.hpp --------------------------------------==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#pragma once +#include +#include +#include +namespace { +// https://stackoverflow.com/questions/35985960 +template inline void hash_combine(std::size_t &seed, const T &v) { + seed ^= std::hash{}(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); +} +} // namespace +namespace std { +// Hash functions used by the kernel/program cache data structures. +template struct hash> { + size_t operator()(const pair &v) const { + size_t seed = 0; + hash_combine(seed, v.first); + hash_combine(seed, v.second); + return seed; + } +}; + +template struct hash> { + size_t operator()(const set &v) const { + size_t seed = 0; + for (const auto &el : v) { + hash_combine(seed, el); + } + return seed; + } +}; + +template struct hash> { + size_t operator()(const vector &v) const { + size_t seed = 0; + for (const auto &el : v) { + hash_combine(seed, el); + } + return seed; + } +}; +} // namespace std diff --git a/sycl/source/detail/kernel_name_based_cache_t.hpp b/sycl/source/detail/kernel_name_based_cache_t.hpp index a3cc87e4abd2b..c28a00370244c 100644 --- a/sycl/source/detail/kernel_name_based_cache_t.hpp +++ b/sycl/source/detail/kernel_name_based_cache_t.hpp @@ -7,15 +7,15 @@ //===----------------------------------------------------------------------===// #pragma once +#include #include +#include #include #include #include #include -#include - namespace sycl { inline namespace _V1 { namespace detail { @@ -60,7 +60,7 @@ struct FastKernelCacheVal { using FastKernelCacheValPtr = std::shared_ptr; using FastKernelSubcacheMapT = - ::boost::unordered_flat_map; + emhash8::HashMap; using FastKernelSubcacheMutexT = SpinLock; using FastKernelSubcacheReadLockT = std::lock_guard; diff --git a/sycl/source/detail/kernel_program_cache.hpp b/sycl/source/detail/kernel_program_cache.hpp index 2585710e4781e..817fc87802612 100644 --- a/sycl/source/detail/kernel_program_cache.hpp +++ b/sycl/source/detail/kernel_program_cache.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -28,12 +29,10 @@ #include #include #include +#include #include #include -#include -#include - // For testing purposes class MockKernelProgramCache; @@ -184,8 +183,8 @@ class KernelProgramCache { }; struct ProgramCache { - ::boost::unordered_map Cache; - ::boost::unordered_multimap KeyMap; + emhash8::HashMap Cache; + UnorderedMultimap KeyMap; // Mapping between a UR program and its size. std::unordered_map ProgramSizeMap; @@ -225,10 +224,8 @@ class KernelProgramCache { }; using KernelBuildResultPtr = std::shared_ptr; - using KernelByNameT = - ::boost::unordered_map; - using KernelCacheT = - ::boost::unordered_map; + using KernelByNameT = emhash8::HashMap; + using KernelCacheT = emhash8::HashMap; class FastKernelSubcacheWrapper { public: @@ -286,7 +283,7 @@ class KernelProgramCache { }; using FastKernelCacheT = - ::boost::unordered_flat_map; + emhash8::HashMap; // DS to hold data and functions related to Program cache eviction. struct EvictionList { @@ -473,8 +470,9 @@ class KernelProgramCache { FastKernelSubcacheT *KernelSubcacheHint) { FastKernelCacheWriteLockT Lock(MFastKernelCacheMutex); if (!KernelSubcacheHint) { - auto It = MFastKernelCache.try_emplace(KernelName, KernelSubcacheHint, - getURContext()); + auto It = MFastKernelCache.try_emplace( + KernelName, + FastKernelSubcacheWrapper(KernelSubcacheHint, getURContext())); KernelSubcacheHint = &It.first->second.get(); } @@ -511,8 +509,9 @@ class KernelProgramCache { // if no insertion took place, then some other thread has already inserted // smth in the cache traceKernel("Kernel inserted.", KernelName, true); - auto It = MFastKernelCache.try_emplace(KernelName, KernelSubcacheHint, - getURContext()); + auto It = MFastKernelCache.try_emplace( + KernelName, + FastKernelSubcacheWrapper(KernelSubcacheHint, getURContext())); KernelSubcacheHint = &It.first->second.get(); FastKernelSubcacheWriteLockT SubcacheLock{KernelSubcacheHint->Mutex}; @@ -589,7 +588,7 @@ class KernelProgramCache { auto KeyMapItrRange = ProgCache.KeyMap.equal_range(CommonKey); for (auto KeyMapItr = KeyMapItrRange.first; KeyMapItr != KeyMapItrRange.second; ++KeyMapItr) { - if (KeyMapItr->second == CacheKey) { + if ((*KeyMapItr).second == CacheKey) { ProgCache.KeyMap.erase(KeyMapItr); break; } @@ -828,7 +827,7 @@ class KernelProgramCache { if (It == ProgCache.KeyMap.end()) return; - auto Key = It->second; + auto Key = (*It).second; removeProgramByKey(Key, ProgCache); { auto LockedEvictionList = acquireEvictionList(); diff --git a/sycl/source/detail/unordered_multimap.hpp b/sycl/source/detail/unordered_multimap.hpp new file mode 100644 index 0000000000000..4d495ed065407 --- /dev/null +++ b/sycl/source/detail/unordered_multimap.hpp @@ -0,0 +1,142 @@ +//==------------ unordered_multimap.hpp ----------------------------==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--------------------------------------------------------------===// +#pragma once +#include +#include + +#include +#include +namespace sycl { +inline namespace _V1 { +namespace detail { +// A simple implementation of an unordered multimap using a fast hashmap with +// the value type being a vector. +template class UnorderedMultimap { +private: + emhash8::HashMap> map; + + template + class multimap_iterator { + public: + using iterator_category = std::forward_iterator_tag; + using value_type = std::pair; + using reference = value_type; + using pointer = void; + using difference_type = std::ptrdiff_t; + + private: + MapIterator map_it, map_end; + VectorIterator vector_it; + + void skip_empty_vectors() { + while (map_it != map_end && vector_it == map_it->second.end()) { + ++map_it; + if (map_it != map_end) + vector_it = map_it->second.begin(); + } + } + + public: + multimap_iterator(MapIterator m_it, MapIterator m_end) + : map_it(m_it), map_end(m_end) { + if (map_it != map_end) { + vector_it = map_it->second.begin(); + skip_empty_vectors(); + } + } + + multimap_iterator(MapIterator m_it, MapIterator m_end, VectorIterator v_it) + : map_it(m_it), map_end(m_end), vector_it(v_it) {} + + reference operator*() const { return {map_it->first, *vector_it}; } + + multimap_iterator &operator++() { + ++vector_it; + skip_empty_vectors(); + return *this; + } + + bool operator==(const multimap_iterator &other) const { + return map_it == other.map_it && + (map_it == map_end || vector_it == other.vector_it); + } + bool operator!=(const multimap_iterator &other) const { + return !(*this == other); + } + + MapIterator get_map_iterator() const { return map_it; } + VectorIterator get_vector_iterator() const { return vector_it; } + }; + +public: + using iterator = multimap_iterator< + typename emhash8::HashMap>::iterator, + typename std::vector::iterator>; + using const_iterator = multimap_iterator< + typename emhash8::HashMap>::const_iterator, + typename std::vector::const_iterator>; + + void insert(const Key &key, const Value &value) { map[key].push_back(value); } + + size_t count(const Key &key) const { + auto it = map.find(key); + return (it != map.end()) ? it->second.size() : 0; + } + + template void emplace(const Key &key, Args &&...args) { + map[key].emplace_back(std::forward(args)...); + } + + iterator find(const Key &key) { + auto map_it = map.find(key); + if (map_it != map.end() && !map_it->second.empty()) + return iterator(map_it, map.end(), map_it->second.begin()); + return end(); + } + + const_iterator find(const Key &key) const { + auto map_it = map.find(key); + if (map_it != map.end() && !map_it->second.empty()) + return const_iterator(map_it, map.end(), map_it->second.begin()); + return end(); + } + + void erase(const Key &key) { map.erase(key); } + + iterator erase(iterator it) { + auto map_it = it.get_map_iterator(); + auto vector_it = it.get_vector_iterator(); + vector_it = map_it->second.erase(vector_it); + if (map_it->second.empty()) { + map_it = map.erase(map_it); + return iterator(map_it, map.end()); + } + return iterator(map_it, map.end(), vector_it); + } + + std::pair equal_range(const Key &key) { + auto map_it = map.find(key); + if (map_it == map.end()) + return {end(), end()}; + return {iterator(map_it, map.end(), map_it->second.begin()), + iterator(map_it, map.end(), map_it->second.end())}; + } + + std::vector &operator[](const Key &key) { return map[key]; } + + iterator begin() { return iterator(map.begin(), map.end()); } + iterator end() { return iterator(map.end(), map.end()); } + const_iterator begin() const { + return const_iterator(map.begin(), map.end()); + } + const_iterator end() const { return const_iterator(map.end(), map.end()); } +}; + +} // namespace detail +} // namespace _V1 +} // namespace sycl diff --git a/sycl/test/basic_tests/boost_mp11_import_sanity_check.cpp b/sycl/test/basic_tests/boost_mp11_import_sanity_check.cpp deleted file mode 100644 index fb547959499a1..0000000000000 --- a/sycl/test/basic_tests/boost_mp11_import_sanity_check.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// Modifications Copyright Intel Corporation 2022 -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -//===----------------------------------------------------------------------===// -// Based on boost/mp11 tests obtained from -// https://github.com/boostorg/mp11/blob/develop/test/mp_fill.cpp -// (git commit a231733). - -//===----------------------------------------------------------------------===// -// Copyright 2015 Peter Dimov. -// -// Distributed under the Boost Software License, Version 1.0. -// -// See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt -//===----------------------------------------------------------------------===// - -// RUN: %clangxx -fsycl -fsyntax-only -fsycl-targets=%sycl_triple %s - -// This is a sanity check test to verify that the automatic boost/mp11 import -// into SYCL is not badly broken. - -#include - -#include - -struct X1 {}; - -int main() { - using sycl::detail::boost::mp11::mp_fill; - using sycl::detail::boost::mp11::mp_list; - - using L1 = mp_list; - static_assert(std::is_same_v, mp_list>); - - // - - using L2 = std::tuple; - static_assert(std::is_same_v, std::tuple>); - - // - - using L3 = std::pair; - static_assert(std::is_same_v, std::pair>); - - return 0; -} diff --git a/xptifw/include/xpti_string_table.hpp b/xptifw/include/xpti_string_table.hpp index d9fa811c050e5..c8678bdff2505 100644 --- a/xptifw/include/xpti_string_table.hpp +++ b/xptifw/include/xpti_string_table.hpp @@ -5,8 +5,8 @@ // #pragma once -#include "hash_table7.hpp" #include "xpti/xpti_data_types.h" +#include #include #include diff --git a/xptifw/src/CMakeLists.txt b/xptifw/src/CMakeLists.txt index 308f47d962260..566a7f001a0f4 100644 --- a/xptifw/src/CMakeLists.txt +++ b/xptifw/src/CMakeLists.txt @@ -1,19 +1,11 @@ # Fetch third party headers include(FetchContent) -set(EMHASH_REPO https://github.com/ktprime/emhash) -message(STATUS "Will fetch emhash from ${EMHASH_REPO}") -FetchContent_Declare(emhash-headers - GIT_REPOSITORY ${EMHASH_REPO} - GIT_TAG 4fc20c7c9b048651c03258460e4662c8d3a04520 -) -FetchContent_GetProperties(emhash-headers) -if(NOT emhash-headers_POPULATED) - FetchContent_Populate(emhash-headers) +# The sycl target should download or find emhash. +if (NOT SYCL_EMHASH_DIR) + message(FATAL_ERROR "emhash headers not found") endif() -set(XPTIFW_EMHASH_HEADERS "${emhash-headers_SOURCE_DIR}") - set(PARALLEL_HASHMAP_REPO https://github.com/greg7mdp/parallel-hashmap.git) message(STATUS "Will fetch parallel-hashmap from ${PARALLEL_HASHMAP_REPO}") FetchContent_Declare(parallel-hashmap @@ -43,7 +35,7 @@ function(add_xpti_library LIB_NAME) target_compile_definitions(${LIB_NAME} PRIVATE -DXPTI_API_EXPORTS) target_include_directories(${LIB_NAME} PUBLIC $ - $ + $ $ $ ) diff --git a/xptifw/src/xpti_trace_framework.cpp b/xptifw/src/xpti_trace_framework.cpp index f0759acdb759d..a972da46900a3 100644 --- a/xptifw/src/xpti_trace_framework.cpp +++ b/xptifw/src/xpti_trace_framework.cpp @@ -14,12 +14,12 @@ /// metrics and events. #include "xpti/xpti_trace_framework.hpp" -#include "hash_table7.hpp" #include "parallel_hashmap/phmap.h" #include "xpti/xpti_trace_framework.h" #include "xpti_int64_hash_table.hpp" #include "xpti_object_table.hpp" #include "xpti_string_table.hpp" +#include #include #include