Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:14

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // SYCL include(s).
0012 #include <sycl/sycl.hpp>
0013 
0014 // System include(s).
0015 #include <cstddef>
0016 
0017 namespace detray::test::sycl {
0018 
0019 /// Execute a test functor using SYCL, on @c array_sizes threads
0020 template <class functor_t, class... Args>
0021 void execute_sycl_test(::sycl::queue& queue, std::size_t array_sizes,
0022                        Args... args) {
0023   // Submit a kernel that would run the specified functor.
0024   queue
0025       .submit([&](::sycl::handler& h) {
0026         // Use parallel_for without specifying a "kernel class" explicitly.
0027         // Unfortunately the functor_t class is too complicated, and DPC++
0028         // dies on it. While providing a unique simple class for every
0029         // template specialisation is also pretty impossible. :-(
0030         h.parallel_for(::sycl::range<1>(array_sizes), [=](::sycl::item<1> id) {
0031           // Find the current index that we need to
0032           // process.
0033           const std::size_t i = id[0];
0034           if (i >= array_sizes) {
0035             return;
0036           }
0037           // Execute the test functor for this index. Note
0038           // that std::forward cannot be used here, as the
0039           // function arguments are passed through as
0040           // copies to the SYCL kernel. So perfect
0041           // forwarding is out of question.
0042           functor_t()(i, args...);
0043         });
0044       })
0045       .wait_and_throw();
0046 }
0047 
0048 }  // namespace detray::test::sycl