Back to home page

EIC code displayed by LXR

 
 

    


Warning, /acts/Traccc/tests/sycl/test_sanity_contiguous_on.sycl is written in an unsupported language. File is not indexed.

0001 /*
0002  * traccc library, part of the ACTS project (R&D line)
0003  *
0004  * (c) 2024-2026 CERN for the benefit of the ACTS project
0005  *
0006  * Mozilla Public License Version 2.0
0007  */
0008 
0009 // System include
0010 #include <sycl/sycl.hpp>
0011 
0012 // vecmem includes
0013 #include <vecmem/containers/device_vector.hpp>
0014 #include <vecmem/memory/sycl/device_memory_resource.hpp>
0015 #include <vecmem/utils/sycl/async_copy.hpp>
0016 
0017 // traccc includes
0018 #include "../../device/sycl/src/sanity/contiguous_on.hpp"
0019 
0020 // GTest include(s).
0021 #include <gtest/gtest.h>
0022 
0023 struct int_identity_projection {
0024   int operator()(const int& v) const { return v; }
0025 };
0026 
0027 class SYCLSanityContiguousOn : public testing::Test {
0028  protected:
0029   ::sycl::queue queue;
0030   vecmem::sycl::device_memory_resource mr{&queue};
0031   vecmem::sycl::async_copy copy{&queue};
0032 };
0033 
0034 TEST_F(SYCLSanityContiguousOn, TrueOrdered) {
0035   std::vector<int> host_vector;
0036 
0037   for (int i = 0; i < 5000; ++i) {
0038     for (int j = 0; j < i; ++j) {
0039       host_vector.push_back(i);
0040     }
0041   }
0042 
0043   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0044                              vecmem::copy::type::host_to_device);
0045   auto device_view = vecmem::get_data(device_data);
0046 
0047   ASSERT_TRUE(traccc::sycl::is_contiguous_on<vecmem::device_vector<const int>>(
0048       int_identity_projection(), mr, copy, queue, device_view));
0049 }
0050 
0051 TEST_F(SYCLSanityContiguousOn, TrueRandom) {
0052   std::vector<int> host_vector;
0053 
0054   for (int i : {603, 6432, 1, 3, 67, 2, 1111}) {
0055     for (int j = 0; j < i; ++j) {
0056       host_vector.push_back(i);
0057     }
0058   }
0059 
0060   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0061                              vecmem::copy::type::host_to_device);
0062   auto device_view = vecmem::get_data(device_data);
0063 
0064   ASSERT_TRUE(traccc::sycl::is_contiguous_on<vecmem::device_vector<const int>>(
0065       int_identity_projection(), mr, copy, queue, device_view));
0066 }
0067 
0068 TEST_F(SYCLSanityContiguousOn, FalseOrdered) {
0069   std::vector<int> host_vector;
0070 
0071   for (int i = 0; i < 5000; ++i) {
0072     if (i == 105) {
0073       host_vector.push_back(5);
0074     } else {
0075       for (int j = 0; j < i; ++j) {
0076         host_vector.push_back(i);
0077       }
0078     }
0079   }
0080 
0081   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0082                              vecmem::copy::type::host_to_device);
0083   auto device_view = vecmem::get_data(device_data);
0084 
0085   ASSERT_FALSE(traccc::sycl::is_contiguous_on<vecmem::device_vector<const int>>(
0086       int_identity_projection(), mr, copy, queue, device_view));
0087 }
0088 
0089 TEST_F(SYCLSanityContiguousOn, FalseOrderedPathologicalFirst) {
0090   std::vector<int> host_vector;
0091 
0092   host_vector.push_back(4000);
0093 
0094   for (int i = 0; i < 5000; ++i) {
0095     for (int j = 0; j < i; ++j) {
0096       host_vector.push_back(i);
0097     }
0098   }
0099 
0100   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0101                              vecmem::copy::type::host_to_device);
0102   auto device_view = vecmem::get_data(device_data);
0103 
0104   ASSERT_FALSE(traccc::sycl::is_contiguous_on<vecmem::device_vector<const int>>(
0105       int_identity_projection(), mr, copy, queue, device_view));
0106 }
0107 
0108 TEST_F(SYCLSanityContiguousOn, TrueOrderedPathologicalFirst) {
0109   std::vector<int> host_vector;
0110 
0111   host_vector.push_back(6000);
0112 
0113   for (int i = 0; i < 5000; ++i) {
0114     for (int j = 0; j < i; ++j) {
0115       host_vector.push_back(i);
0116     }
0117   }
0118 
0119   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0120                              vecmem::copy::type::host_to_device);
0121   auto device_view = vecmem::get_data(device_data);
0122 
0123   ASSERT_TRUE(traccc::sycl::is_contiguous_on<vecmem::device_vector<const int>>(
0124       int_identity_projection(), mr, copy, queue, device_view));
0125 }
0126 
0127 TEST_F(SYCLSanityContiguousOn, FalseOrderedPathologicalLast) {
0128   std::vector<int> host_vector;
0129 
0130   for (int i = 0; i < 5000; ++i) {
0131     for (int j = 0; j < i; ++j) {
0132       host_vector.push_back(i);
0133     }
0134   }
0135 
0136   host_vector.push_back(2);
0137 
0138   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0139                              vecmem::copy::type::host_to_device);
0140   auto device_view = vecmem::get_data(device_data);
0141 
0142   ASSERT_FALSE(traccc::sycl::is_contiguous_on<vecmem::device_vector<const int>>(
0143       int_identity_projection(), mr, copy, queue, device_view));
0144 }
0145 
0146 TEST_F(SYCLSanityContiguousOn, FalseRandom) {
0147   std::vector<int> host_vector;
0148 
0149   for (int i : {603, 6432, 1, 3, 67, 1, 1111}) {
0150     for (int j = 0; j < i; ++j) {
0151       host_vector.push_back(i);
0152     }
0153   }
0154 
0155   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0156                              vecmem::copy::type::host_to_device);
0157   auto device_view = vecmem::get_data(device_data);
0158 
0159   ASSERT_FALSE(traccc::sycl::is_contiguous_on<vecmem::device_vector<const int>>(
0160       int_identity_projection(), mr, copy, queue, device_view));
0161 }