Back to home page

EIC code displayed by LXR

 
 

    


Warning, /acts/Traccc/tests/sycl/test_sanity_ordered_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/ordered_on.hpp"
0019 
0020 // GTest include(s).
0021 #include <gtest/gtest.h>
0022 
0023 struct int_lt_relation {
0024   bool operator()(const int& a, const int& b) const { return a < b; }
0025 };
0026 
0027 struct int_leq_relation {
0028   bool operator()(const int& a, const int& b) const { return a <= b; }
0029 };
0030 
0031 class SYCLSanityOrderedOn : public testing::Test {
0032  protected:
0033   ::sycl::queue queue;
0034   vecmem::sycl::device_memory_resource mr{&queue};
0035   vecmem::sycl::async_copy copy{&queue};
0036 };
0037 
0038 TEST_F(SYCLSanityOrderedOn, TrueConsecutiveNoRepeatsLeq) {
0039   std::vector<int> host_vector;
0040 
0041   for (int i = 0; i < 500000; ++i) {
0042     host_vector.push_back(i);
0043   }
0044 
0045   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0046                              vecmem::copy::type::host_to_device);
0047   auto device_view = vecmem::get_data(device_data);
0048 
0049   ASSERT_TRUE(traccc::sycl::is_ordered_on<vecmem::device_vector<const int>>(
0050       int_leq_relation(), mr, copy, queue, device_view));
0051 }
0052 
0053 TEST_F(SYCLSanityOrderedOn, TrueConsecutiveNoRepeatsLt) {
0054   std::vector<int> host_vector;
0055 
0056   for (int i = 0; i < 500000; ++i) {
0057     host_vector.push_back(i);
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_ordered_on<vecmem::device_vector<const int>>(
0065       int_lt_relation(), mr, copy, queue, device_view));
0066 }
0067 
0068 TEST_F(SYCLSanityOrderedOn, TrueConsecutiveRepeatsLeq) {
0069   std::vector<int> host_vector;
0070 
0071   for (int i = 0; i < 5000; ++i) {
0072     for (int j = 0; j < i; ++j) {
0073       host_vector.push_back(i);
0074     }
0075   }
0076 
0077   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0078                              vecmem::copy::type::host_to_device);
0079   auto device_view = vecmem::get_data(device_data);
0080 
0081   ASSERT_TRUE(traccc::sycl::is_ordered_on<vecmem::device_vector<const int>>(
0082       int_leq_relation(), mr, copy, queue, device_view));
0083 }
0084 
0085 TEST_F(SYCLSanityOrderedOn, FalseConsecutiveRepeatLt) {
0086   std::vector<int> host_vector;
0087 
0088   for (int i = 0; i < 5000; ++i) {
0089     for (int j = 0; j < i; ++j) {
0090       host_vector.push_back(i);
0091     }
0092   }
0093 
0094   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0095                              vecmem::copy::type::host_to_device);
0096   auto device_view = vecmem::get_data(device_data);
0097 
0098   ASSERT_FALSE(traccc::sycl::is_ordered_on<vecmem::device_vector<const int>>(
0099       int_lt_relation(), mr, copy, queue, device_view));
0100 }
0101 
0102 TEST_F(SYCLSanityOrderedOn, TrueConsecutivePathologicalFirstLeq) {
0103   std::vector<int> host_vector;
0104 
0105   host_vector.push_back(4000);
0106 
0107   for (int i = 0; i < 5000; ++i) {
0108     for (int j = 0; j < i; ++j) {
0109       host_vector.push_back(i);
0110     }
0111   }
0112 
0113   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0114                              vecmem::copy::type::host_to_device);
0115   auto device_view = vecmem::get_data(device_data);
0116 
0117   ASSERT_FALSE(traccc::sycl::is_ordered_on<vecmem::device_vector<const int>>(
0118       int_leq_relation(), mr, copy, queue, device_view));
0119 }
0120 
0121 TEST_F(SYCLSanityOrderedOn, TrueConsecutivePathologicalLastLeq) {
0122   std::vector<int> host_vector;
0123 
0124   host_vector.push_back(2000);
0125 
0126   for (int i = 0; i < 5000; ++i) {
0127     for (int j = 0; j < i; ++j) {
0128       host_vector.push_back(i);
0129     }
0130   }
0131 
0132   auto device_data = copy.to(vecmem::get_data(host_vector), mr,
0133                              vecmem::copy::type::host_to_device);
0134   auto device_view = vecmem::get_data(device_data);
0135 
0136   ASSERT_FALSE(traccc::sycl::is_ordered_on<vecmem::device_vector<const int>>(
0137       int_leq_relation(), mr, copy, queue, device_view));
0138 }