Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:13

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // SYCL include(s).
0012 #include <CL/sycl.hpp>
0013 
0014 // System include(s).
0015 #include <cstddef>
0016 #include <memory>
0017 
0018 namespace Acts::Sycl {
0019 
0020 namespace detail {
0021 
0022 /// Deleter functor for the smart pointer type(s)
0023 class DeviceArrayDeleter {
0024  public:
0025   /// Constructor, with the queue that the memory was allocated on/with
0026   DeviceArrayDeleter(cl::sycl::queue& queue) : m_queue(&queue) {}
0027   /// Operator performing the deletion of the memory
0028   void operator()(void* ptr) {
0029     if (ptr != nullptr) {
0030       cl::sycl::free(ptr, *m_queue);
0031     }
0032   }
0033 
0034  private:
0035   /// The queue that manages the memory area in question
0036   cl::sycl::queue* m_queue;
0037 };  // class DeviceArrayDeleter
0038 
0039 }  // namespace detail
0040 
0041 /// Convenience type for using (primitive) variable arrays on a SYCL device
0042 template <typename T>
0043 using device_array = std::unique_ptr<T, detail::DeviceArrayDeleter>;
0044 
0045 /// Function creating a primitive array in SYCL device memory
0046 template <typename T>
0047 device_array<T> make_device_array(std::size_t size, cl::sycl::queue& queue) {
0048   return device_array<T>(cl::sycl::malloc_device<T>(size, queue),
0049                          detail::DeviceArrayDeleter(queue));
0050 }
0051 
0052 }  // namespace Acts::Sycl