File indexing completed on 2026-08-16 08:20:29
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011
0012 #include "../utils/global_index.hpp"
0013 #include "../utils/hip_error_handling.hpp"
0014 #include "../utils/utils.hpp"
0015 #include "traccc/hip/utils/stream_wrapper.hpp"
0016
0017
0018 #include <vecmem/memory/memory_resource.hpp>
0019 #include <vecmem/memory/unique_ptr.hpp>
0020 #include <vecmem/utils/copy.hpp>
0021
0022
0023 #include <hip/hip_runtime.h>
0024
0025
0026 #include <concepts>
0027 #include <utility>
0028
0029 namespace traccc::hip {
0030
0031 namespace kernels {
0032
0033 template <typename CONTAINER, typename R, typename VIEW>
0034 requires std::regular_invocable<R, decltype(std::declval<CONTAINER>().at(0)),
0035 decltype(std::declval<CONTAINER>().at(0))> &&
0036 std::semiregular<R>
0037 __global__ void is_ordered_on_kernel(R relation, VIEW _in, bool* out) {
0038 const device::global_index_t tid = details::global_index1();
0039
0040 const CONTAINER in(_in);
0041
0042 if (tid > 0 && tid < in.size()) {
0043 if (!relation(in.at(tid - 1), in.at(tid))) {
0044 *out = false;
0045 }
0046 }
0047 }
0048
0049 }
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 template <typename CONTAINER, typename R, typename VIEW>
0076 requires std::regular_invocable<R, decltype(std::declval<CONTAINER>().at(0)),
0077 decltype(std::declval<CONTAINER>().at(0))> &&
0078 std::semiregular<R>
0079 bool is_ordered_on(R&& relation, vecmem::memory_resource& mr,
0080 const vecmem::copy& copy, const stream_wrapper& stream,
0081 const VIEW& view) {
0082
0083
0084 constexpr int block_size = 512;
0085
0086 hipStream_t hip_stream = details::get_stream(stream);
0087
0088
0089 const typename VIEW::size_type n = copy.get_size(view);
0090
0091
0092 if (n == 0) {
0093 return true;
0094 }
0095
0096
0097 vecmem::unique_alloc_ptr<bool> out = vecmem::make_unique_alloc<bool>(mr);
0098 bool initial_out = true;
0099 TRACCC_HIP_ERROR_CHECK(hipMemcpyAsync(out.get(), &initial_out, sizeof(bool),
0100 hipMemcpyHostToDevice, hip_stream));
0101
0102
0103 hipLaunchKernelGGL(kernels::is_ordered_on_kernel<CONTAINER>,
0104 (n + block_size - 1) / block_size, block_size, 0,
0105 hip_stream, relation, view, out.get());
0106 TRACCC_HIP_ERROR_CHECK(hipGetLastError());
0107
0108
0109 bool host_out;
0110
0111 TRACCC_HIP_ERROR_CHECK(hipMemcpyAsync(&host_out, out.get(), sizeof(bool),
0112 hipMemcpyDeviceToHost, hip_stream));
0113
0114 stream.synchronize();
0115
0116 return host_out;
0117 }
0118
0119 }