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 "../../device/cuda/src/sanity/contiguous_on.cuh"
0017 #include "traccc/definitions/qualifiers.hpp"
0018
0019
0020 #include <gtest/gtest.h>
0021
0022 struct int_identity_projection {
0023 TRACCC_HOST_DEVICE
0024 int operator()(const int& v) const { return v; }
0025 };
0026
0027 class CUDASanityContiguousOn : public testing::Test {
0028 protected:
0029 vecmem::cuda::device_memory_resource mr;
0030 vecmem::cuda::stream_wrapper vecmem_stream;
0031 traccc::cuda::stream_wrapper stream{vecmem_stream.stream()};
0032 vecmem::cuda::async_copy copy{stream.cudaStream()};
0033 };
0034
0035 TEST_F(CUDASanityContiguousOn, TrueOrdered) {
0036 std::vector<int> host_vector;
0037
0038 for (int i = 0; i < 5000; ++i) {
0039 for (int j = 0; j < i; ++j) {
0040 host_vector.push_back(i);
0041 }
0042 }
0043
0044 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0045 vecmem::copy::type::host_to_device);
0046 auto device_view = vecmem::get_data(device_data);
0047
0048 ASSERT_TRUE(traccc::cuda::is_contiguous_on<vecmem::device_vector<const int>>(
0049 int_identity_projection(), mr, copy, stream, device_view));
0050 }
0051
0052 TEST_F(CUDASanityContiguousOn, TrueRandom) {
0053 std::vector<int> host_vector;
0054
0055 for (int i : {603, 6432, 1, 3, 67, 2, 1111}) {
0056 for (int j = 0; j < i; ++j) {
0057 host_vector.push_back(i);
0058 }
0059 }
0060
0061 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0062 vecmem::copy::type::host_to_device);
0063 auto device_view = vecmem::get_data(device_data);
0064
0065 ASSERT_TRUE(traccc::cuda::is_contiguous_on<vecmem::device_vector<const int>>(
0066 int_identity_projection(), mr, copy, stream, device_view));
0067 }
0068
0069 TEST_F(CUDASanityContiguousOn, FalseOrdered) {
0070 std::vector<int> host_vector;
0071
0072 for (int i = 0; i < 5000; ++i) {
0073 if (i == 105) {
0074 host_vector.push_back(5);
0075 } else {
0076 for (int j = 0; j < i; ++j) {
0077 host_vector.push_back(i);
0078 }
0079 }
0080 }
0081
0082 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0083 vecmem::copy::type::host_to_device);
0084 auto device_view = vecmem::get_data(device_data);
0085
0086 ASSERT_FALSE(traccc::cuda::is_contiguous_on<vecmem::device_vector<const int>>(
0087 int_identity_projection(), mr, copy, stream, device_view));
0088 }
0089
0090 TEST_F(CUDASanityContiguousOn, FalseOrderedPathologicalFirst) {
0091 std::vector<int> host_vector;
0092
0093 host_vector.push_back(4000);
0094
0095 for (int i = 0; i < 5000; ++i) {
0096 for (int j = 0; j < i; ++j) {
0097 host_vector.push_back(i);
0098 }
0099 }
0100
0101 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0102 vecmem::copy::type::host_to_device);
0103 auto device_view = vecmem::get_data(device_data);
0104
0105 ASSERT_FALSE(traccc::cuda::is_contiguous_on<vecmem::device_vector<const int>>(
0106 int_identity_projection(), mr, copy, stream, device_view));
0107 }
0108
0109 TEST_F(CUDASanityContiguousOn, TrueOrderedPathologicalFirst) {
0110 std::vector<int> host_vector;
0111
0112 host_vector.push_back(6000);
0113
0114 for (int i = 0; i < 5000; ++i) {
0115 for (int j = 0; j < i; ++j) {
0116 host_vector.push_back(i);
0117 }
0118 }
0119
0120 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0121 vecmem::copy::type::host_to_device);
0122 auto device_view = vecmem::get_data(device_data);
0123
0124 ASSERT_TRUE(traccc::cuda::is_contiguous_on<vecmem::device_vector<const int>>(
0125 int_identity_projection(), mr, copy, stream, device_view));
0126 }
0127
0128 TEST_F(CUDASanityContiguousOn, FalseOrderedPathologicalLast) {
0129 std::vector<int> host_vector;
0130
0131 for (int i = 0; i < 5000; ++i) {
0132 for (int j = 0; j < i; ++j) {
0133 host_vector.push_back(i);
0134 }
0135 }
0136
0137 host_vector.push_back(2);
0138
0139 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0140 vecmem::copy::type::host_to_device);
0141 auto device_view = vecmem::get_data(device_data);
0142
0143 ASSERT_FALSE(traccc::cuda::is_contiguous_on<vecmem::device_vector<const int>>(
0144 int_identity_projection(), mr, copy, stream, device_view));
0145 }
0146
0147 TEST_F(CUDASanityContiguousOn, FalseRandom) {
0148 std::vector<int> host_vector;
0149
0150 for (int i : {603, 6432, 1, 3, 67, 1, 1111}) {
0151 for (int j = 0; j < i; ++j) {
0152 host_vector.push_back(i);
0153 }
0154 }
0155
0156 auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0157 vecmem::copy::type::host_to_device);
0158 auto device_view = vecmem::get_data(device_data);
0159
0160 ASSERT_FALSE(traccc::cuda::is_contiguous_on<vecmem::device_vector<const int>>(
0161 int_identity_projection(), mr, copy, stream, device_view));
0162 }