From a8a5b330a546b0d44d6617d9cf80ab1411311c4c Mon Sep 17 00:00:00 2001 From: "Fedorov, Andrey" Date: Tue, 31 Aug 2021 15:12:30 +0300 Subject: [PATCH 01/16] initial commit for group sort implementation Signed-off-by: Fedorov, Andrey --- .../CL/sycl/detail/group_sort_impl.hpp | 232 ++++++++++++++++++ .../CL/sycl/detail/group_sort_util.hpp | 30 +++ sycl/include/CL/sycl/group_algorithm.hpp | 1 + .../experimental/group_helpers_sorters.hpp | 91 +++++++ sycl/include/sycl/ext/oneapi/group_sort.hpp | 136 ++++++++++ 5 files changed, 490 insertions(+) create mode 100644 sycl/include/CL/sycl/detail/group_sort_impl.hpp create mode 100644 sycl/include/CL/sycl/detail/group_sort_util.hpp create mode 100644 sycl/include/sycl/ext/oneapi/experimental/group_helpers_sorters.hpp create mode 100644 sycl/include/sycl/ext/oneapi/group_sort.hpp diff --git a/sycl/include/CL/sycl/detail/group_sort_impl.hpp b/sycl/include/CL/sycl/detail/group_sort_impl.hpp new file mode 100644 index 0000000000000..b9b52f8aa5008 --- /dev/null +++ b/sycl/include/CL/sycl/detail/group_sort_impl.hpp @@ -0,0 +1,232 @@ +//==------------ group_sort_impl.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 +// +//===----------------------------------------------------------------------===// +// This file includes some functions for group sorting algorithm implementations +// + +#pragma once + +#include "group_sort_util.hpp" + +__SYCL_INLINE_NAMESPACE(cl) { +namespace sycl { +namespace detail { + +// ---- merge sort implementation + +// following to functions could be useless if std::[lower|upper]_bound worked well +template +std::size_t +my_lower_bound(Acc acc, const std::size_t first, const std::size_t last, const Value& value, Compare comp) +{ + const std::size_t n = last - first; + const std::size_t cur = n; + const std::size_t it; + while (n > 0) + { + it = first; + cur = n / 2; + it += cur; + if (comp(acc[it], value)) + { + n -= cur + 1, first = ++it; + } + else + n = cur; + } + return first; +} + +template +std::size_t +my_upper_bound(Acc acc, const std::size_t first, const std::size_t last, const Value& value, Compare comp) +{ + return my_lower_bound(acc, first, last, value, [comp](auto x, auto y){return !comp(y, x);}); +} + +// swap for all data types including tuple-like types +template +void my_swap(T& a, T& b) +{ + std::swap(a, b); +} + +template