File indexing completed on 2026-07-26 08:22:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <vecmem/containers/device_vector.hpp>
0011 #include <vecmem/memory/cuda/device_memory_resource.hpp>
0012 #include <vecmem/utils/cuda/async_copy.hpp>
0013 #include <vecmem/utils/cuda/stream_wrapper.hpp>
0014
0015
0016 #include <traccc/definitions/qualifiers.hpp>
0017
0018 #include "../../device/cuda/src/sanity/ordered_on.cuh"
0019
0020
0021 #include <gtest/gtest.h>
0022
0023 struct int_lt_relation {
0024 TRACCC_HOST_DEVICE
0025 bool operator()(const int& a, const int& b) const { return a < b; }
0026 };
0027
0028 struct int_leq_relation {
0029 TRACCC_HOST_DEVICE
0030 bool operator()(const int& a, const int& b) const { return a <= b; }
0031 };
0032
0033 class CUDASanityOrderedOn : public testing::Test {
0034 protected:
0035 vecmem::cuda::device_memory_resource mr;
0036 vecmem::cuda::stream_wrapper vecmem_stream;
0037 traccc::cuda::stream_wrapper stream{vecmem_stream.stream()};
0038 vecmem::cuda::async_copy copy{stream.cudaStream()};
0039 };
0040
0041 TEST_F(CUDASanityOrderedOn, TrueConsecutiveNoRepeatsLeq) {
0042 std::vector<int> host_vector;
0043
0044 for (int i = 0; i < 500000; ++i) {
0045 host_vector.push_back(i);
0046 }
0047
0048 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0049 vecmem::copy::type::host_to_device);
0050 auto device_view = vecmem::get_data(device_data);
0051
0052 ASSERT_TRUE(traccc::cuda::is_ordered_on<vecmem::device_vector<const int>>(
0053 int_leq_relation(), mr, copy, stream, device_view));
0054 }
0055
0056 TEST_F(CUDASanityOrderedOn, TrueConsecutiveNoRepeatsLt) {
0057 std::vector<int> host_vector;
0058
0059 for (int i = 0; i < 500000; ++i) {
0060 host_vector.push_back(i);
0061 }
0062
0063 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0064 vecmem::copy::type::host_to_device);
0065 auto device_view = vecmem::get_data(device_data);
0066
0067 ASSERT_TRUE(traccc::cuda::is_ordered_on<vecmem::device_vector<const int>>(
0068 int_lt_relation(), mr, copy, stream, device_view));
0069 }
0070
0071 TEST_F(CUDASanityOrderedOn, TrueConsecutiveRepeatsLeq) {
0072 std::vector<int> host_vector;
0073
0074 for (int i = 0; i < 5000; ++i) {
0075 for (int j = 0; j < i; ++j) {
0076 host_vector.push_back(i);
0077 }
0078 }
0079
0080 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0081 vecmem::copy::type::host_to_device);
0082 auto device_view = vecmem::get_data(device_data);
0083
0084 ASSERT_TRUE(traccc::cuda::is_ordered_on<vecmem::device_vector<const int>>(
0085 int_leq_relation(), mr, copy, stream, device_view));
0086 }
0087
0088 TEST_F(CUDASanityOrderedOn, FalseConsecutiveRepeatLt) {
0089 std::vector<int> host_vector;
0090
0091 for (int i = 0; i < 5000; ++i) {
0092 for (int j = 0; j < i; ++j) {
0093 host_vector.push_back(i);
0094 }
0095 }
0096
0097 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0098 vecmem::copy::type::host_to_device);
0099 auto device_view = vecmem::get_data(device_data);
0100
0101 ASSERT_FALSE(traccc::cuda::is_ordered_on<vecmem::device_vector<const int>>(
0102 int_lt_relation(), mr, copy, stream, device_view));
0103 }
0104
0105 TEST_F(CUDASanityOrderedOn, TrueConsecutivePathologicalFirstLeq) {
0106 std::vector<int> host_vector;
0107
0108 host_vector.push_back(4000);
0109
0110 for (int i = 0; i < 5000; ++i) {
0111 for (int j = 0; j < i; ++j) {
0112 host_vector.push_back(i);
0113 }
0114 }
0115
0116 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0117 vecmem::copy::type::host_to_device);
0118 auto device_view = vecmem::get_data(device_data);
0119
0120 ASSERT_FALSE(traccc::cuda::is_ordered_on<vecmem::device_vector<const int>>(
0121 int_leq_relation(), mr, copy, stream, device_view));
0122 }
0123
0124 TEST_F(CUDASanityOrderedOn, TrueConsecutivePathologicalLastLeq) {
0125 std::vector<int> host_vector;
0126
0127 host_vector.push_back(2000);
0128
0129 for (int i = 0; i < 5000; ++i) {
0130 for (int j = 0; j < i; ++j) {
0131 host_vector.push_back(i);
0132 }
0133 }
0134
0135 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0136 vecmem::copy::type::host_to_device);
0137 auto device_view = vecmem::get_data(device_data);
0138
0139 ASSERT_FALSE(traccc::cuda::is_ordered_on<vecmem::device_vector<const int>>(
0140 int_leq_relation(), mr, copy, stream, device_view));
0141 }