From a2a793038a6cd700df1f73879e4575aa91eb34ae Mon Sep 17 00:00:00 2001 From: Johan511 Date: Sat, 19 Aug 2023 18:47:08 +0530 Subject: [PATCH 01/19] pulls simd sort --- CMakeLists.txt | 20 +++++++++++ cmake/FindSimdSort.cmake | 54 ++++++++++++++++++++++++++++ cmake/HPX_SetupSimdSort.cmake | 66 +++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 cmake/FindSimdSort.cmake create mode 100644 cmake/HPX_SetupSimdSort.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c934e21328b..c478df9b42f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -544,6 +544,26 @@ hpx_option( ADVANCED ) +hpx_option( + HPX_WITH_FETCH_SIMD_SORT + BOOL + "Use FetchContent to fetch Eve. By default an installed Eve will be used. (default: On)" + ON + CATEGORY "Build Targets" + ADVANCED +) +hpx_option( + HPX_WITH_SIMD_SORT_TAG STRING "Eve repository tag or branch" "v2.0" + CATEGORY "Build Targets" + ADVANCED +) + +if(HPX_WITH_FETCH_SIMD_SORT) + include(HPX_SetupSimdSort) +else() + find_package(SimdSort) +endif() + # ############################################################################## # HPX CUDA configuration # ############################################################################## diff --git a/cmake/FindSimdSort.cmake b/cmake/FindSimdSort.cmake new file mode 100644 index 000000000000..7e680f993835 --- /dev/null +++ b/cmake/FindSimdSort.cmake @@ -0,0 +1,54 @@ +# Copyright (c) 2022 Srinivas Yadav +# +# SPDX-License-Identifier: BSL-1.0 +# 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) + +if(NOT TARGET SimdSort::simdsort) + find_path( + SIMD_SORT_INCLUDE_DIR simd_sort/simd_sort.hpp + HINTS "${SIMD_SORT_ROOT}" ENV SIMD_SORT_ROOT "${HPX_SIMD_SORT_ROOT}" + PATH_SUFFIXES include + ) + + if(NOT SIMD_SORT_INCLUDE_DIR) + hpx_error("Simd Sort not found") + endif() + + # Set EVE_ROOT in case the other hints are used + if(SIMD_SORT) + # The call to file is for compatibility with windows paths + file(TO_CMAKE_PATH ${SIMD_SORT} SIMD_SORT) + elseif("$ENV{SIMD_SORT}") + file(TO_CMAKE_PATH $ENV{SIMD_SORT} SIMD_SORT) + else() + file(TO_CMAKE_PATH "${SIMD_SORT_INCLUDE_DIR}" SIMD_SORT_INCLUDE_DIR) + string(REPLACE "/include" "" SIMD_SORT_ROOT "${SIMD_SORT_INCLUDE_DIR}") + endif() + + # if(SIMD_SORT_INCLUDE_DIR AND EXISTS + # "${SIMD_SORT_INCLUDE_DIR}/eve/version.hpp") # Matches a line of the form: # + # # #define EVE_VERSION "AA.BB.CC.DD" # # with arbitrary whitespace between + # the tokens file( STRINGS "${SIMD_SORT_INCLUDE_DIR}/eve/version.hpp" + # EVE_VERSION_DEFINE_LINE REGEX "#define[ \t]+EVE_LIB_VERSION[ + # \t]+\"+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\"[ \t]*" ) # Extracts the dotted + # version number in quotation marks as # SIMD_SORT_VERSION_STRING string(REGEX + # REPLACE "#define EVE_LIB_VERSION \"([0-9]+\.[0-9]+\.[0-9]+\.[0-9])\"" "\\1" + # SIMD_SORT_VERSION_STRING "${EVE_VERSION_DEFINE_LINE}" ) else() hpx_error( "Could + # not find EVE_ROOT/include/eve/version.hpp. Please check your eve + # installation" ) endif() + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( + SimdSort + REQUIRED_VARS SIMD_SORT_INCLUDE_DIR + VERSION_VAR SIMD_SORT_VERSION_STRING + ) + + add_library(SimdSort::simdsort INTERFACE IMPORTED) + target_include_directories( + SimdSort::simdsort SYSTEM INTERFACE ${SIMD_SORT_INCLUDE_DIR} + ) + + mark_as_advanced(SIMD_SORT_ROOT SIMD_SORT_INCLUDE_DIR SIMD_SORT_VERSION_STRING) +endif() diff --git a/cmake/HPX_SetupSimdSort.cmake b/cmake/HPX_SetupSimdSort.cmake new file mode 100644 index 000000000000..a10bd521bbf1 --- /dev/null +++ b/cmake/HPX_SetupSimdSort.cmake @@ -0,0 +1,66 @@ +# Copyright (c) 2022 Srinivas Yadav +# +# SPDX-License-Identifier: BSL-1.0 +# 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) + +if(HPX_WITH_FETCH_SIMD_SORT) + if(FETCHCONTENT_SOURCE_DIR_SIMD_SORT) + hpx_info( + "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, EVE will be used through CMake's FetchContent and installed alongside HPX (FETCHCONTENT_SOURCE_DIR_EVE=${FETCHCONTENT_SOURCE_DIR_EVE})" + ) + else() + hpx_info( + "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, EVE will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_SIMD_SORT_TAG=${HPX_WITH_SIMD_SORT_TAG})" + ) + endif() + include(FetchContent) + fetchcontent_declare( + simdsort + GIT_REPOSITORY https://github.com/intel/x86-simd-sort + GIT_TAG ${HPX_WITH_SIMD_SORT_TAG} + ) + + fetchcontent_getproperties(simdsort) + if(NOT simdsort_POPULATED) + fetchcontent_populate(simdsort) + endif() + set(SIMD_SORT_ROOT ${simdsort_SOURCE_DIR}) + + add_library(simdsort INTERFACE) + target_include_directories( + simdsort SYSTEM INTERFACE $ + $ + ) + + install( + TARGETS simdsort + EXPORT HPXSimdSortTarget + COMPONENT core + ) + + install( + DIRECTORY ${SIMD_SORT_ROOT}/include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT core + FILES_MATCHING + PATTERN "*.hpp" + PATTERN "*.ipp" + ) + + export( + TARGETS simdsort + NAMESPACE SimdSort:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}/HPXSimdSortTarget.cmake" + ) + + install( + EXPORT HPXSimdSortTarget + NAMESPACE SimdSort:: + FILE HPXSimdSortTarget.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${HPX_PACKAGE_NAME} + ) + + add_library(SimdSort::simdsort ALIAS simdsort) + +endif() From fb85580aeb2d8428e43992b9d455ca20abc7b627 Mon Sep 17 00:00:00 2001 From: Johan511 Date: Sat, 19 Aug 2023 18:48:47 +0530 Subject: [PATCH 02/19] cmake format --- cmake/FindSimdSort.cmake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmake/FindSimdSort.cmake b/cmake/FindSimdSort.cmake index 7e680f993835..00c470ef744a 100644 --- a/cmake/FindSimdSort.cmake +++ b/cmake/FindSimdSort.cmake @@ -34,8 +34,8 @@ if(NOT TARGET SimdSort::simdsort) # \t]+\"+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\"[ \t]*" ) # Extracts the dotted # version number in quotation marks as # SIMD_SORT_VERSION_STRING string(REGEX # REPLACE "#define EVE_LIB_VERSION \"([0-9]+\.[0-9]+\.[0-9]+\.[0-9])\"" "\\1" - # SIMD_SORT_VERSION_STRING "${EVE_VERSION_DEFINE_LINE}" ) else() hpx_error( "Could - # not find EVE_ROOT/include/eve/version.hpp. Please check your eve + # SIMD_SORT_VERSION_STRING "${EVE_VERSION_DEFINE_LINE}" ) else() hpx_error( + # "Could not find EVE_ROOT/include/eve/version.hpp. Please check your eve # installation" ) endif() include(FindPackageHandleStandardArgs) @@ -50,5 +50,7 @@ if(NOT TARGET SimdSort::simdsort) SimdSort::simdsort SYSTEM INTERFACE ${SIMD_SORT_INCLUDE_DIR} ) - mark_as_advanced(SIMD_SORT_ROOT SIMD_SORT_INCLUDE_DIR SIMD_SORT_VERSION_STRING) + mark_as_advanced( + SIMD_SORT_ROOT SIMD_SORT_INCLUDE_DIR SIMD_SORT_VERSION_STRING + ) endif() From fd13408a442d527f8021a120664e10f8976bc08a Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S <69986621+Johan511@users.noreply.github.com> Date: Sun, 20 Aug 2023 00:08:06 +0530 Subject: [PATCH 03/19] Update CMakeLists.txt Co-authored-by: Hartmut Kaiser --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c478df9b42f0..150b3ce7e535 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -547,7 +547,7 @@ hpx_option( hpx_option( HPX_WITH_FETCH_SIMD_SORT BOOL - "Use FetchContent to fetch Eve. By default an installed Eve will be used. (default: On)" + "Use FetchContent to fetch x86-simd-sort. By default an installed x86-simd-sort will be used. (default: On)" ON CATEGORY "Build Targets" ADVANCED From 8c88a4833748d622c0b3163ef3f4295be1a30462 Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S <69986621+Johan511@users.noreply.github.com> Date: Sun, 20 Aug 2023 00:08:12 +0530 Subject: [PATCH 04/19] Update CMakeLists.txt Co-authored-by: Hartmut Kaiser --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 150b3ce7e535..63dae428b517 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -553,7 +553,7 @@ hpx_option( ADVANCED ) hpx_option( - HPX_WITH_SIMD_SORT_TAG STRING "Eve repository tag or branch" "v2.0" + HPX_WITH_SIMD_SORT_TAG STRING "x86-simd-sort repository tag or branch" "v2.0" CATEGORY "Build Targets" ADVANCED ) From 66835a08de9f10587adf308bab2ef0a243faddfd Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S <69986621+Johan511@users.noreply.github.com> Date: Sun, 20 Aug 2023 00:08:18 +0530 Subject: [PATCH 05/19] Update cmake/HPX_SetupSimdSort.cmake Co-authored-by: Hartmut Kaiser --- cmake/HPX_SetupSimdSort.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/HPX_SetupSimdSort.cmake b/cmake/HPX_SetupSimdSort.cmake index a10bd521bbf1..9831ead8c45d 100644 --- a/cmake/HPX_SetupSimdSort.cmake +++ b/cmake/HPX_SetupSimdSort.cmake @@ -7,7 +7,7 @@ if(HPX_WITH_FETCH_SIMD_SORT) if(FETCHCONTENT_SOURCE_DIR_SIMD_SORT) hpx_info( - "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, EVE will be used through CMake's FetchContent and installed alongside HPX (FETCHCONTENT_SOURCE_DIR_EVE=${FETCHCONTENT_SOURCE_DIR_EVE})" + "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be used through CMake's FetchContent and installed alongside HPX (FETCHCONTENT_SOURCE_DIR_EVE=${FETCHCONTENT_SOURCE_DIR_EVE})" ) else() hpx_info( From 4b199bc0da1427b7ca746c915bed0943676c89fc Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S <69986621+Johan511@users.noreply.github.com> Date: Sun, 20 Aug 2023 00:08:25 +0530 Subject: [PATCH 06/19] Update cmake/HPX_SetupSimdSort.cmake Co-authored-by: Hartmut Kaiser --- cmake/HPX_SetupSimdSort.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/HPX_SetupSimdSort.cmake b/cmake/HPX_SetupSimdSort.cmake index 9831ead8c45d..08d5d6509dc3 100644 --- a/cmake/HPX_SetupSimdSort.cmake +++ b/cmake/HPX_SetupSimdSort.cmake @@ -11,7 +11,7 @@ if(HPX_WITH_FETCH_SIMD_SORT) ) else() hpx_info( - "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, EVE will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_SIMD_SORT_TAG=${HPX_WITH_SIMD_SORT_TAG})" + "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_SIMD_SORT_TAG=${HPX_WITH_SIMD_SORT_TAG})" ) endif() include(FetchContent) From 82d15373ac757f7e425545f4016018ad3361125b Mon Sep 17 00:00:00 2001 From: Johan511 Date: Tue, 29 Aug 2023 11:53:34 +0530 Subject: [PATCH 07/19] simd sort fetched as intended --- CMakeLists.txt | 19 +++++++++++---- cmake/FindSimdSort.cmake | 24 ++++--------------- cmake/HPX_SetupSimdSort.cmake | 11 +++++---- libs/CMakeLists.txt | 4 ++++ libs/core/algorithms/CMakeLists.txt | 1 + .../parallel/algorithms/detail/simd_sort.hpp | 0 6 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 63dae428b517..e4dedf6cf784 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -547,7 +547,7 @@ hpx_option( hpx_option( HPX_WITH_FETCH_SIMD_SORT BOOL - "Use FetchContent to fetch x86-simd-sort. By default an installed x86-simd-sort will be used. (default: On)" + "Use FetchContent to fetch x86-simd-sort. By default an installed x86-simd-sort will be used. (default: On). It has support only for AVX-512 registers. If the architecture has no AVX-512 registers, simd-sort won't be used" ON CATEGORY "Build Targets" ADVANCED @@ -558,12 +558,23 @@ hpx_option( ADVANCED ) -if(HPX_WITH_FETCH_SIMD_SORT) - include(HPX_SetupSimdSort) +# simd sort supports only avx-512 registers +if(__AVX512F__) + set(HPX_WITH_SIMD_SORT ON) + if(HPX_WITH_FETCH_SIMD_SORT) + include(HPX_SetupSimdSort) + else() + find_package(SimdSort) + endif() else() - find_package(SimdSort) + set(HPX_WITH_SIMD_SORT OFF) + set(HPX_WITH_FETCH_SIMD_SORT OFF) endif() +# debug message to be removed before merge +message(WARNING "HPX_WITH_SIMD_SORT : ${HPX_WITH_SIMD_SORT}") +message(WARNING "HPX_WITH_FETCH_SIMD_SORT : ${HPX_WITH_FETCH_SIMD_SORT}") + # ############################################################################## # HPX CUDA configuration # ############################################################################## diff --git a/cmake/FindSimdSort.cmake b/cmake/FindSimdSort.cmake index 00c470ef744a..3b747c16c8d2 100644 --- a/cmake/FindSimdSort.cmake +++ b/cmake/FindSimdSort.cmake @@ -1,21 +1,19 @@ -# Copyright (c) 2022 Srinivas Yadav +# Copyright (c) 2023 Hari Hara Naveen S # # SPDX-License-Identifier: BSL-1.0 # 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) if(NOT TARGET SimdSort::simdsort) - find_path( - SIMD_SORT_INCLUDE_DIR simd_sort/simd_sort.hpp - HINTS "${SIMD_SORT_ROOT}" ENV SIMD_SORT_ROOT "${HPX_SIMD_SORT_ROOT}" - PATH_SUFFIXES include + find_path(SIMD_SORT_INCLUDE_DIR avx512-16bit-qsort.hpp + HINTS "${SIMD_SORT_ROOT}" ENV SIMD_SORT_ROOT + "${HPX_SIMD_SORT_ROOT}" ) if(NOT SIMD_SORT_INCLUDE_DIR) hpx_error("Simd Sort not found") endif() - # Set EVE_ROOT in case the other hints are used if(SIMD_SORT) # The call to file is for compatibility with windows paths file(TO_CMAKE_PATH ${SIMD_SORT} SIMD_SORT) @@ -23,21 +21,9 @@ if(NOT TARGET SimdSort::simdsort) file(TO_CMAKE_PATH $ENV{SIMD_SORT} SIMD_SORT) else() file(TO_CMAKE_PATH "${SIMD_SORT_INCLUDE_DIR}" SIMD_SORT_INCLUDE_DIR) - string(REPLACE "/include" "" SIMD_SORT_ROOT "${SIMD_SORT_INCLUDE_DIR}") + string(REPLACE "/src" "" SIMD_SORT_ROOT "${SIMD_SORT_INCLUDE_DIR}") endif() - # if(SIMD_SORT_INCLUDE_DIR AND EXISTS - # "${SIMD_SORT_INCLUDE_DIR}/eve/version.hpp") # Matches a line of the form: # - # # #define EVE_VERSION "AA.BB.CC.DD" # # with arbitrary whitespace between - # the tokens file( STRINGS "${SIMD_SORT_INCLUDE_DIR}/eve/version.hpp" - # EVE_VERSION_DEFINE_LINE REGEX "#define[ \t]+EVE_LIB_VERSION[ - # \t]+\"+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\"[ \t]*" ) # Extracts the dotted - # version number in quotation marks as # SIMD_SORT_VERSION_STRING string(REGEX - # REPLACE "#define EVE_LIB_VERSION \"([0-9]+\.[0-9]+\.[0-9]+\.[0-9])\"" "\\1" - # SIMD_SORT_VERSION_STRING "${EVE_VERSION_DEFINE_LINE}" ) else() hpx_error( - # "Could not find EVE_ROOT/include/eve/version.hpp. Please check your eve - # installation" ) endif() - include(FindPackageHandleStandardArgs) find_package_handle_standard_args( SimdSort diff --git a/cmake/HPX_SetupSimdSort.cmake b/cmake/HPX_SetupSimdSort.cmake index 08d5d6509dc3..11e55827ac7d 100644 --- a/cmake/HPX_SetupSimdSort.cmake +++ b/cmake/HPX_SetupSimdSort.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Srinivas Yadav +# Copyright (c) 2023 Hari Hara Naveen S # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -7,13 +7,14 @@ if(HPX_WITH_FETCH_SIMD_SORT) if(FETCHCONTENT_SOURCE_DIR_SIMD_SORT) hpx_info( - "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be used through CMake's FetchContent and installed alongside HPX (FETCHCONTENT_SOURCE_DIR_EVE=${FETCHCONTENT_SOURCE_DIR_EVE})" + "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be used through CMake's FetchContent and installed alongside HPX (FETCHCONTENT_SOURCE_DIR_SIMD_SORT=${FETCHCONTENT_SOURCE_DIR_SIMD_SORT})" ) else() hpx_info( "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_SIMD_SORT_TAG=${HPX_WITH_SIMD_SORT_TAG})" ) endif() + include(FetchContent) fetchcontent_declare( simdsort @@ -29,7 +30,7 @@ if(HPX_WITH_FETCH_SIMD_SORT) add_library(simdsort INTERFACE) target_include_directories( - simdsort SYSTEM INTERFACE $ + simdsort SYSTEM INTERFACE $ $ ) @@ -40,12 +41,12 @@ if(HPX_WITH_FETCH_SIMD_SORT) ) install( - DIRECTORY ${SIMD_SORT_ROOT}/include/ + DIRECTORY ${SIMD_SORT_ROOT}/src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT core FILES_MATCHING PATTERN "*.hpp" - PATTERN "*.ipp" + PATTERN "*.h" ) export( diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 3f5e4546c3ec..5753b9b1bcdc 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -372,6 +372,10 @@ if("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "SVE") target_link_libraries(hpx_core PUBLIC SVE::sve) endif() +if(HPX_WITH_SIMD_SORT) + target_link_libraries(hpx_core PUBLIC SimdSort::simdsort) +endif() + if(HPX_WITH_ITTNOTIFY) target_link_libraries(hpx_core PUBLIC Amplifier::amplifier) endif() diff --git a/libs/core/algorithms/CMakeLists.txt b/libs/core/algorithms/CMakeLists.txt index 6d10912d4d63..1c30f69f2e75 100644 --- a/libs/core/algorithms/CMakeLists.txt +++ b/libs/core/algorithms/CMakeLists.txt @@ -26,6 +26,7 @@ set(algorithms_headers hpx/parallel/algorithms/detail/dispatch.hpp hpx/parallel/algorithms/detail/distance.hpp hpx/parallel/algorithms/detail/equal.hpp + hpx/parallel/algorithms/detail/simd_sort.hpp hpx/parallel/algorithms/detail/fill.hpp hpx/parallel/algorithms/detail/find.hpp hpx/parallel/algorithms/detail/generate.hpp diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp new file mode 100644 index 000000000000..e69de29bb2d1 From 058d42861bf76eab70cec95ed0fd879d6ea15345 Mon Sep 17 00:00:00 2001 From: Johan511 Date: Tue, 29 Aug 2023 16:34:34 +0530 Subject: [PATCH 08/19] simd sort --- libs/core/algorithms/CMakeLists.txt | 1 + .../parallel/algorithms/detail/simd_sort.hpp | 41 +++++++++++++++++++ .../include/hpx/parallel/algorithms/sort.hpp | 16 ++++++++ 3 files changed, 58 insertions(+) diff --git a/libs/core/algorithms/CMakeLists.txt b/libs/core/algorithms/CMakeLists.txt index 1c30f69f2e75..59da77201999 100644 --- a/libs/core/algorithms/CMakeLists.txt +++ b/libs/core/algorithms/CMakeLists.txt @@ -42,6 +42,7 @@ set(algorithms_headers hpx/parallel/algorithms/detail/sample_sort.hpp hpx/parallel/algorithms/detail/search.hpp hpx/parallel/algorithms/detail/set_operation.hpp + hpx/parallel/algorithms/detail/simd_sort.hpp hpx/parallel/algorithms/detail/spin_sort.hpp hpx/parallel/algorithms/detail/transfer.hpp hpx/parallel/algorithms/detail/upper_lower_bound.hpp diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp index e69de29bb2d1..ee7771586055 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp @@ -0,0 +1,41 @@ +#pragma once + +namespace hpx::parallel::util { + // TODO : add support for _Float16, need compile time test as _Float16 is not always supported + template + struct is_simd_sortable + : std::integral_constant::type>::value || + std::is_same::type>::value || + std::is_same::type>::value || + std::is_same::type>::value || + std::is_same::type>::value || + std::is_same::type>::value || + std::is_same::type>::value || + std::is_same::type>::value> + { + }; + + template + constexpr bool is_simd_sortable_v = is_simd_sortable::value; +} // namespace hpx::parallel::util + +#if (HPX_WITH_SIMD_SORT) + +namespace hpx::parallel::util { + template + void simd_quicksort(T* arr, int64_t arrsize) + { + static_assert(hpx::parallel::util::is_simd_sortable_v); + return avx512_qsort(arr, arrsize); + } +} // namespace hpx::parallel::util +#endif diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp index 300f0d8da2d3..32f80f2c82fe 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp @@ -159,6 +159,7 @@ namespace hpx { #include #include #include +#include #include #include #include @@ -464,6 +465,21 @@ namespace hpx { HPX_MOVE(comp), hpx::identity_v); } } sort{}; + +#if (HPX_WITH_SIMD_SORT) + template && + hpx::is_invocable_v, + hpx::traits::iter_value_t>)> + parallel::util::detail::algorithm_result_t tag_invoke(hpx::sort_t, + hpx::execution::unsequenced_policy, RandomIt first, RandomIt last, + Comp comp = Comp()) + { + return hpx::parallel::util::simd_quicksort( + std::addressof(*first), std::distance(first, last)); + } +#endif + } // namespace hpx #endif // DOXYGEN From 1f92c0faf94132ad2f78c407ac4fb399df9d617e Mon Sep 17 00:00:00 2001 From: Johan511 Date: Tue, 29 Aug 2023 17:52:40 +0530 Subject: [PATCH 09/19] fixed inspect errors --- .../hpx/parallel/algorithms/detail/simd_sort.hpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp index ee7771586055..a65df1b956c2 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp @@ -1,7 +1,17 @@ +// Copyright (c) 2023 Hari Hara Naveen S +// +// SPDX-License-Identifier: BSL-1.0 +// 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) + +#include +#include + #pragma once namespace hpx::parallel::util { - // TODO : add support for _Float16, need compile time test as _Float16 is not always supported + // TODO : add support for _Float16 + // need compile time test as _Float16 is not always supported template struct is_simd_sortable : std::integral_constant Date: Tue, 29 Aug 2023 18:08:22 +0530 Subject: [PATCH 10/19] fixed missing header --- .../include/hpx/parallel/algorithms/detail/simd_sort.hpp | 1 - libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp index a65df1b956c2..10c2794b4d19 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp @@ -4,7 +4,6 @@ // 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) -#include #include #pragma once diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp index 32f80f2c82fe..a848cf34312f 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp @@ -173,6 +173,7 @@ namespace hpx { #include #include #include +#include #include #include From 4e315b9b5916ca3ffa11f4a3de9d77ba56cab5a5 Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S Date: Wed, 13 Sep 2023 12:05:58 -0500 Subject: [PATCH 11/19] examples throwing linker error Signed-off-by: Hari Hara Naveen S --- CMakeLists.txt | 13 ++++++++----- cmake/templates/HPXConfig.cmake.in | 2 ++ libs/core/algorithms/CMakeLists.txt | 1 - .../hpx/parallel/algorithms/detail/simd_sort.hpp | 7 ++++++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4dedf6cf784..995931340198 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -558,18 +558,21 @@ hpx_option( ADVANCED ) +add_compile_options(-march=native) + # simd sort supports only avx-512 registers -if(__AVX512F__) +# if(__AVX512F__) set(HPX_WITH_SIMD_SORT ON) if(HPX_WITH_FETCH_SIMD_SORT) include(HPX_SetupSimdSort) else() find_package(SimdSort) endif() -else() - set(HPX_WITH_SIMD_SORT OFF) - set(HPX_WITH_FETCH_SIMD_SORT OFF) -endif() + +# else() + # set(HPX_WITH_SIMD_SORT OFF) + # set(HPX_WITH_FETCH_SIMD_SORT OFF) +# endif() # debug message to be removed before merge message(WARNING "HPX_WITH_SIMD_SORT : ${HPX_WITH_SIMD_SORT}") diff --git a/cmake/templates/HPXConfig.cmake.in b/cmake/templates/HPXConfig.cmake.in index c3f0ae31b8f7..303a65c1f557 100644 --- a/cmake/templates/HPXConfig.cmake.in +++ b/cmake/templates/HPXConfig.cmake.in @@ -77,6 +77,8 @@ if("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "SVE") endif() endif() +include("${CMAKE_CURRENT_LIST_DIR}/HPXSimdSortTarget.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/HPXInternalTargets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/HPXTargets.cmake") diff --git a/libs/core/algorithms/CMakeLists.txt b/libs/core/algorithms/CMakeLists.txt index 59da77201999..1c30f69f2e75 100644 --- a/libs/core/algorithms/CMakeLists.txt +++ b/libs/core/algorithms/CMakeLists.txt @@ -42,7 +42,6 @@ set(algorithms_headers hpx/parallel/algorithms/detail/sample_sort.hpp hpx/parallel/algorithms/detail/search.hpp hpx/parallel/algorithms/detail/set_operation.hpp - hpx/parallel/algorithms/detail/simd_sort.hpp hpx/parallel/algorithms/detail/spin_sort.hpp hpx/parallel/algorithms/detail/transfer.hpp hpx/parallel/algorithms/detail/upper_lower_bound.hpp diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp index 10c2794b4d19..bec099e2e49c 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp @@ -4,9 +4,14 @@ // 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) +#pragma once + +// #include +// #include +#include + #include -#pragma once namespace hpx::parallel::util { // TODO : add support for _Float16 From 2ef787200aa94fa6474d1806548ed0a751109dfe Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S Date: Thu, 14 Sep 2023 08:35:53 -0500 Subject: [PATCH 12/19] added compile definitions for simd sort Signed-off-by: Hari Hara Naveen S --- CMakeLists.txt | 30 +++++++------------ cmake/FindSimdSort.cmake | 4 +-- cmake/HPX_AddConfigTest.cmake | 9 ++++++ .../parallel/algorithms/detail/simd_sort.hpp | 7 ++--- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 995931340198..df71ccc5f3c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -545,7 +545,7 @@ hpx_option( ) hpx_option( - HPX_WITH_FETCH_SIMD_SORT + HPX_WITH_SIMD_SORT BOOL "Use FetchContent to fetch x86-simd-sort. By default an installed x86-simd-sort will be used. (default: On). It has support only for AVX-512 registers. If the architecture has no AVX-512 registers, simd-sort won't be used" ON @@ -553,30 +553,22 @@ hpx_option( ADVANCED ) hpx_option( - HPX_WITH_SIMD_SORT_TAG STRING "x86-simd-sort repository tag or branch" "v2.0" + HPX_WITH_SIMD_SORT_TAG STRING "x86-simd-sort repository tag or branch" + "1b396372e2bc10fd883d49e28dfc2a5ea5d2e194" CATEGORY "Build Targets" ADVANCED ) -add_compile_options(-march=native) +hpx_check_for_32bit_simd_sort(DEFINITIONS HPX_HAVE_AVX512F) -# simd sort supports only avx-512 registers -# if(__AVX512F__) - set(HPX_WITH_SIMD_SORT ON) - if(HPX_WITH_FETCH_SIMD_SORT) - include(HPX_SetupSimdSort) - else() - find_package(SimdSort) - endif() - -# else() - # set(HPX_WITH_SIMD_SORT OFF) - # set(HPX_WITH_FETCH_SIMD_SORT OFF) -# endif() +if(NOT (HPX_WITH_AVX512F)) + set(HPX_WITH_SIMD_SORT Off) +endif() -# debug message to be removed before merge -message(WARNING "HPX_WITH_SIMD_SORT : ${HPX_WITH_SIMD_SORT}") -message(WARNING "HPX_WITH_FETCH_SIMD_SORT : ${HPX_WITH_FETCH_SIMD_SORT}") +if(HPX_WITH_SIMD_SORT) + hpx_add_config_define(HPX_HAVE_SIMD_SORT) + include(HPX_SetupSimdSort) +endif() # ############################################################################## # HPX CUDA configuration diff --git a/cmake/FindSimdSort.cmake b/cmake/FindSimdSort.cmake index 3b747c16c8d2..e8ed4796ba5b 100644 --- a/cmake/FindSimdSort.cmake +++ b/cmake/FindSimdSort.cmake @@ -31,9 +31,9 @@ if(NOT TARGET SimdSort::simdsort) VERSION_VAR SIMD_SORT_VERSION_STRING ) - add_library(SimdSort::simdsort INTERFACE IMPORTED) + add_library(SimdSort::simdsort PRIVATE IMPORTED) target_include_directories( - SimdSort::simdsort SYSTEM INTERFACE ${SIMD_SORT_INCLUDE_DIR} + SimdSort::simdsort SYSTEM PRIVATE ${SIMD_SORT_INCLUDE_DIR} ) mark_as_advanced( diff --git a/cmake/HPX_AddConfigTest.cmake b/cmake/HPX_AddConfigTest.cmake index e6d29636388a..ac2b1baaf755 100644 --- a/cmake/HPX_AddConfigTest.cmake +++ b/cmake/HPX_AddConfigTest.cmake @@ -713,3 +713,12 @@ function(hpx_check_for_stable_inplace_merge) FILE ${ARGN} ) endfunction() + +# ############################################################################## +function(hpx_check_avx512f) + add_hpx_config_test( + HPX_WITH_AVX512F + SOURCE cmake/tests/avx512f.cpp + FILE ${ARGN} CXXFLAGS -mavx512f + ) +endfunction() diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp index bec099e2e49c..e605649d4ca4 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp @@ -6,13 +6,12 @@ #pragma once -// #include -// #include +#ifdef HPX_HAVE_SIMD_SORT +#include #include #include - namespace hpx::parallel::util { // TODO : add support for _Float16 // need compile time test as _Float16 is not always supported @@ -42,7 +41,7 @@ namespace hpx::parallel::util { constexpr bool is_simd_sortable_v = is_simd_sortable::value; } // namespace hpx::parallel::util -#if (HPX_WITH_SIMD_SORT) +// #if (HPX_WITH_SIMD_SORT) namespace hpx::parallel::util { template From f158dda62097202a140d6693b4c478df29c9ebe7 Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S Date: Thu, 14 Sep 2023 09:11:50 -0500 Subject: [PATCH 13/19] integrated simd sort Signed-off-by: Hari Hara Naveen S --- CMakeLists.txt | 7 +- cmake/FindSimdSort.cmake | 4 +- cmake/HPX_AddConfigTest.cmake | 2 +- cmake/HPX_SetupSimdSort.cmake | 101 +++++++++--------- .../parallel/algorithms/detail/simd_sort.hpp | 2 - 5 files changed, 57 insertions(+), 59 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df71ccc5f3c8..a9bb0789c4f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -559,15 +559,18 @@ hpx_option( ADVANCED ) -hpx_check_for_32bit_simd_sort(DEFINITIONS HPX_HAVE_AVX512F) +hpx_check_for_avx512f(DEFINITIONS HPX_HAVE_AVX512F) if(NOT (HPX_WITH_AVX512F)) set(HPX_WITH_SIMD_SORT Off) endif() + if(HPX_WITH_SIMD_SORT) - hpx_add_config_define(HPX_HAVE_SIMD_SORT) include(HPX_SetupSimdSort) + hpx_add_config_define(HPX_HAVE_SIMD_SORT) + add_compile_options(-mavx512f) + MESSAGE("HPX_WITH_SIMD_SORT : ${HPX_WITH_SIMD_SORT}") endif() # ############################################################################## diff --git a/cmake/FindSimdSort.cmake b/cmake/FindSimdSort.cmake index e8ed4796ba5b..3b747c16c8d2 100644 --- a/cmake/FindSimdSort.cmake +++ b/cmake/FindSimdSort.cmake @@ -31,9 +31,9 @@ if(NOT TARGET SimdSort::simdsort) VERSION_VAR SIMD_SORT_VERSION_STRING ) - add_library(SimdSort::simdsort PRIVATE IMPORTED) + add_library(SimdSort::simdsort INTERFACE IMPORTED) target_include_directories( - SimdSort::simdsort SYSTEM PRIVATE ${SIMD_SORT_INCLUDE_DIR} + SimdSort::simdsort SYSTEM INTERFACE ${SIMD_SORT_INCLUDE_DIR} ) mark_as_advanced( diff --git a/cmake/HPX_AddConfigTest.cmake b/cmake/HPX_AddConfigTest.cmake index ac2b1baaf755..57ed28c2f25f 100644 --- a/cmake/HPX_AddConfigTest.cmake +++ b/cmake/HPX_AddConfigTest.cmake @@ -715,7 +715,7 @@ function(hpx_check_for_stable_inplace_merge) endfunction() # ############################################################################## -function(hpx_check_avx512f) +function(hpx_check_for_avx512f) add_hpx_config_test( HPX_WITH_AVX512F SOURCE cmake/tests/avx512f.cpp diff --git a/cmake/HPX_SetupSimdSort.cmake b/cmake/HPX_SetupSimdSort.cmake index 11e55827ac7d..b9f75a59ffdd 100644 --- a/cmake/HPX_SetupSimdSort.cmake +++ b/cmake/HPX_SetupSimdSort.cmake @@ -4,64 +4,61 @@ # 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) -if(HPX_WITH_FETCH_SIMD_SORT) - if(FETCHCONTENT_SOURCE_DIR_SIMD_SORT) - hpx_info( - "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be used through CMake's FetchContent and installed alongside HPX (FETCHCONTENT_SOURCE_DIR_SIMD_SORT=${FETCHCONTENT_SOURCE_DIR_SIMD_SORT})" - ) - else() - hpx_info( - "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_SIMD_SORT_TAG=${HPX_WITH_SIMD_SORT_TAG})" - ) - endif() - - include(FetchContent) - fetchcontent_declare( - simdsort - GIT_REPOSITORY https://github.com/intel/x86-simd-sort - GIT_TAG ${HPX_WITH_SIMD_SORT_TAG} +if(FETCHCONTENT_SOURCE_DIR_SIMD_SORT) + hpx_info( + "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be used through CMake's FetchContent and installed alongside HPX (FETCHCONTENT_SOURCE_DIR_SIMD_SORT=${FETCHCONTENT_SOURCE_DIR_SIMD_SORT})" + ) +else() + hpx_info( + "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_SIMD_SORT_TAG=${HPX_WITH_SIMD_SORT_TAG})" ) +endif() - fetchcontent_getproperties(simdsort) - if(NOT simdsort_POPULATED) - fetchcontent_populate(simdsort) - endif() - set(SIMD_SORT_ROOT ${simdsort_SOURCE_DIR}) +include(FetchContent) +fetchcontent_declare( + simdsort + GIT_REPOSITORY https://github.com/intel/x86-simd-sort + GIT_TAG ${HPX_WITH_SIMD_SORT_TAG} +) - add_library(simdsort INTERFACE) - target_include_directories( - simdsort SYSTEM INTERFACE $ - $ - ) +fetchcontent_getproperties(simdsort) +if(NOT simdsort_POPULATED) + fetchcontent_populate(simdsort) +endif() +set(SIMD_SORT_ROOT ${simdsort_SOURCE_DIR}) - install( - TARGETS simdsort - EXPORT HPXSimdSortTarget - COMPONENT core - ) +add_library(simdsort INTERFACE) +target_include_directories( + simdsort SYSTEM INTERFACE $ + $ +) - install( - DIRECTORY ${SIMD_SORT_ROOT}/src/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - COMPONENT core - FILES_MATCHING - PATTERN "*.hpp" - PATTERN "*.h" - ) +install( + TARGETS simdsort + EXPORT HPXSimdSortTarget + COMPONENT core +) - export( - TARGETS simdsort - NAMESPACE SimdSort:: - FILE "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}/HPXSimdSortTarget.cmake" - ) +install( + DIRECTORY ${SIMD_SORT_ROOT}/src/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT core + FILES_MATCHING + PATTERN "*.hpp" + PATTERN "*.h" +) - install( - EXPORT HPXSimdSortTarget - NAMESPACE SimdSort:: - FILE HPXSimdSortTarget.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${HPX_PACKAGE_NAME} - ) +export( + TARGETS simdsort + NAMESPACE SimdSort:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}/HPXSimdSortTarget.cmake" +) - add_library(SimdSort::simdsort ALIAS simdsort) +install( + EXPORT HPXSimdSortTarget + NAMESPACE SimdSort:: + FILE HPXSimdSortTarget.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${HPX_PACKAGE_NAME} +) -endif() +add_library(SimdSort::simdsort ALIAS simdsort) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp index e605649d4ca4..9ac338d62df0 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp @@ -41,8 +41,6 @@ namespace hpx::parallel::util { constexpr bool is_simd_sortable_v = is_simd_sortable::value; } // namespace hpx::parallel::util -// #if (HPX_WITH_SIMD_SORT) - namespace hpx::parallel::util { template void simd_quicksort(T* arr, int64_t arrsize) From 9493bce1e0a926f84fd1819285671e1d3aba5dc8 Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S Date: Thu, 14 Sep 2023 09:16:31 -0500 Subject: [PATCH 14/19] added missing config file Signed-off-by: Hari Hara Naveen S --- cmake/tests/avx512f.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 cmake/tests/avx512f.cpp diff --git a/cmake/tests/avx512f.cpp b/cmake/tests/avx512f.cpp new file mode 100644 index 000000000000..9189e25c71be --- /dev/null +++ b/cmake/tests/avx512f.cpp @@ -0,0 +1,8 @@ +#include + +int main() +{ +#ifndef __AVX512F__ + static_assert(false); +#endif +} From 3db90f70429111052d65ccd1f62a70008fbb648b Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S Date: Thu, 14 Sep 2023 10:19:00 -0500 Subject: [PATCH 15/19] fixed typo Signed-off-by: Hari Hara Naveen S --- .../hpx/parallel/algorithms/detail/simd_sort.hpp | 2 ++ .../include/hpx/parallel/algorithms/sort.hpp | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp index 9ac338d62df0..cfd4a32a9def 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp @@ -9,6 +9,7 @@ #ifdef HPX_HAVE_SIMD_SORT #include #include +#endif #include @@ -41,6 +42,7 @@ namespace hpx::parallel::util { constexpr bool is_simd_sortable_v = is_simd_sortable::value; } // namespace hpx::parallel::util +#ifdef HPX_HAVE_SIMD_SORT namespace hpx::parallel::util { template void simd_quicksort(T* arr, int64_t arrsize) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp index a848cf34312f..1bd596ac7706 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp @@ -159,8 +159,8 @@ namespace hpx { #include #include #include -#include #include +#include #include #include #include @@ -467,14 +467,14 @@ namespace hpx { } } sort{}; -#if (HPX_WITH_SIMD_SORT) +#ifdef HPX_HAVE_SIMD_SORT template && + HPX_CONCEPT_REQUIRES_( + hpx::traits::is_random_access_iterator_v&& hpx::is_invocable_v, hpx::traits::iter_value_t>)> - parallel::util::detail::algorithm_result_t tag_invoke(hpx::sort_t, - hpx::execution::unsequenced_policy, RandomIt first, RandomIt last, - Comp comp = Comp()) + void tag_invoke(hpx::sort_t, hpx::execution::unsequenced_policy, + RandomIt first, RandomIt last, Comp comp = Comp()) { return hpx::parallel::util::simd_quicksort( std::addressof(*first), std::distance(first, last)); From 42562a0b6e84ebd91dd1a8eb8f144958d7a9a025 Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S Date: Thu, 14 Sep 2023 12:08:20 -0500 Subject: [PATCH 16/19] fixing unused param error Signed-off-by: Hari Hara Naveen S --- .../algorithms/include/hpx/parallel/algorithms/sort.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp index 1bd596ac7706..f3337bce7cfb 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/sort.hpp @@ -470,11 +470,9 @@ namespace hpx { #ifdef HPX_HAVE_SIMD_SORT template && - hpx::is_invocable_v, - hpx::traits::iter_value_t>)> + hpx::traits::is_random_access_iterator_v)> void tag_invoke(hpx::sort_t, hpx::execution::unsequenced_policy, - RandomIt first, RandomIt last, Comp comp = Comp()) + RandomIt first, RandomIt last, Comp) { return hpx::parallel::util::simd_quicksort( std::addressof(*first), std::distance(first, last)); From 47687615999dad59a07d356ff751b09337fbd1fa Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S Date: Sat, 16 Sep 2023 15:30:07 -0500 Subject: [PATCH 17/19] changed native arch to avx512f Signed-off-by: Hari Hara Naveen S --- CMakeLists.txt | 4 +--- cmake/HPX_AddConfigTest.cmake | 2 +- .../include/hpx/parallel/algorithms/detail/simd_sort.hpp | 8 ++++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9bb0789c4f4..23b5a62a1478 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -561,16 +561,14 @@ hpx_option( hpx_check_for_avx512f(DEFINITIONS HPX_HAVE_AVX512F) -if(NOT (HPX_WITH_AVX512F)) +if(NOT HPX_WITH_AVX512F) set(HPX_WITH_SIMD_SORT Off) endif() - if(HPX_WITH_SIMD_SORT) include(HPX_SetupSimdSort) hpx_add_config_define(HPX_HAVE_SIMD_SORT) add_compile_options(-mavx512f) - MESSAGE("HPX_WITH_SIMD_SORT : ${HPX_WITH_SIMD_SORT}") endif() # ############################################################################## diff --git a/cmake/HPX_AddConfigTest.cmake b/cmake/HPX_AddConfigTest.cmake index 57ed28c2f25f..e7b650a0ba8c 100644 --- a/cmake/HPX_AddConfigTest.cmake +++ b/cmake/HPX_AddConfigTest.cmake @@ -719,6 +719,6 @@ function(hpx_check_for_avx512f) add_hpx_config_test( HPX_WITH_AVX512F SOURCE cmake/tests/avx512f.cpp - FILE ${ARGN} CXXFLAGS -mavx512f + FILE ${ARGN} CXXFLAGS -mavx512f ) endfunction() diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp index cfd4a32a9def..7e0585632ef3 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/simd_sort.hpp @@ -51,4 +51,12 @@ namespace hpx::parallel::util { return avx512_qsort(arr, arrsize); } } // namespace hpx::parallel::util +#else +namespace hpx::parallel::util { + template + void simd_quicksort(T* arr, int64_t arrsize) + { + static_assert(false); + } +} // namespace hpx::parallel::util #endif From 25534b361c81bf44e84868cb6457bed3ccf208eb Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S Date: Sat, 16 Sep 2023 15:31:17 -0500 Subject: [PATCH 18/19] better diagnostic Signed-off-by: Hari Hara Naveen S --- cmake/HPX_SetupSimdSort.cmake | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/cmake/HPX_SetupSimdSort.cmake b/cmake/HPX_SetupSimdSort.cmake index b9f75a59ffdd..b8bea3866395 100644 --- a/cmake/HPX_SetupSimdSort.cmake +++ b/cmake/HPX_SetupSimdSort.cmake @@ -4,15 +4,9 @@ # 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) -if(FETCHCONTENT_SOURCE_DIR_SIMD_SORT) - hpx_info( - "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be used through CMake's FetchContent and installed alongside HPX (FETCHCONTENT_SOURCE_DIR_SIMD_SORT=${FETCHCONTENT_SOURCE_DIR_SIMD_SORT})" - ) -else() - hpx_info( - "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_SIMD_SORT_TAG=${HPX_WITH_SIMD_SORT_TAG})" - ) -endif() +hpx_info( + "HPX_WITH_FETCH_SIMD_SORT=${HPX_WITH_FETCH_SIMD_SORT}, x86-simd-sort will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_SIMD_SORT_TAG=${HPX_WITH_SIMD_SORT_TAG})" +) include(FetchContent) fetchcontent_declare( From 1c18b4a29c8806e696b4139e117f2b5448a2285b Mon Sep 17 00:00:00 2001 From: Hari Hara Naveen S Date: Thu, 19 Oct 2023 09:41:54 -0500 Subject: [PATCH 19/19] return 0 added Signed-off-by: Hari Hara Naveen S --- cmake/tests/avx512f.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/tests/avx512f.cpp b/cmake/tests/avx512f.cpp index 9189e25c71be..c614f2afd91e 100644 --- a/cmake/tests/avx512f.cpp +++ b/cmake/tests/avx512f.cpp @@ -1,8 +1,7 @@ -#include - int main() { #ifndef __AVX512F__ static_assert(false); #endif + return 0; }