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-2021 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 // System include(s)
0010 #include <string>
0011 
0012 // Acts include(s)
0013 #include "Acts/Utilities/Logger.hpp"
0014 
0015 // SYCL plugin include(s)
0016 #include "Acts/Plugins/Sycl/Utilities/DeviceSelector.hpp"
0017 #include "Acts/Plugins/Sycl/Utilities/QueueWrapper.hpp"
0018 
0019 // SYCL include
0020 #include <CL/sycl.hpp>
0021 
0022 namespace Acts::Sycl {
0023 
0024 QueueWrapper::QueueWrapper(const std::string& deviceNameSubstring,
0025                            std::unique_ptr<const Logger> incomingLogger)
0026     : m_queue(nullptr), m_ownsQueue(true), m_logger(std::move(incomingLogger)) {
0027   // SYCL kernel exceptions are asynchronous
0028   auto exception_handler = [this](cl::sycl::exception_list exceptions) {
0029     for (std::exception_ptr const& e : exceptions) {
0030       try {
0031         std::rethrow_exception(e);
0032       } catch (std::exception& e) {
0033         ACTS_FATAL("Caught asynchronous (kernel) SYCL exception:\n" << e.what())
0034       }
0035     }
0036   };
0037 
0038   // Create queue with custom device selector
0039   m_queue = new cl::sycl::queue(DeviceSelector(deviceNameSubstring),
0040                                 exception_handler);
0041   m_ownsQueue = true;
0042 
0043   // See which device we are running on.
0044   ACTS_INFO("Running on: "
0045             << m_queue->get_device().get_info<cl::sycl::info::device::name>());
0046 }
0047 
0048 QueueWrapper::QueueWrapper(cl::sycl::queue& queue,
0049                            std::unique_ptr<const Logger> incomingLogger)
0050     : m_queue(&queue),
0051       m_ownsQueue(false),
0052       m_logger(std::move(incomingLogger)) {}
0053 
0054 QueueWrapper::QueueWrapper(QueueWrapper&& parent) noexcept
0055     : m_queue(parent.m_queue),
0056       m_ownsQueue(parent.m_ownsQueue),
0057       m_logger(std::move(parent.m_logger)) {
0058   parent.m_queue = nullptr;
0059   parent.m_ownsQueue = false;
0060 }
0061 
0062 QueueWrapper::QueueWrapper(const QueueWrapper& other)
0063     : m_queue(other.m_queue),
0064       m_ownsQueue(false),
0065       m_logger(getDefaultLogger("Sycl::QueueWrapper", Logging::INFO)) {}
0066 
0067 QueueWrapper::~QueueWrapper() {
0068   if (m_ownsQueue && (m_queue != nullptr)) {
0069     delete m_queue;
0070   }
0071 }
0072 
0073 QueueWrapper& QueueWrapper::operator=(QueueWrapper&& rhs) noexcept {
0074   // Check whether we have to do anything
0075   if (this == &rhs) {
0076     return *this;
0077   }
0078 
0079   // Destroy this queue,
0080   if (m_ownsQueue && (m_queue != nullptr)) {
0081     delete m_queue;
0082   }
0083 
0084   // Perform the move
0085   m_queue = rhs.m_queue;
0086   m_ownsQueue = rhs.m_ownsQueue;
0087   m_logger = std::move(rhs.m_logger);
0088   rhs.m_queue = nullptr;
0089   rhs.m_ownsQueue = false;
0090 
0091   // Return this object.
0092   return *this;
0093 }
0094 
0095 QueueWrapper& QueueWrapper::operator=(const QueueWrapper& other) {
0096   // Check whether we have to do anything
0097   if (this == &other) {
0098     return *this;
0099   }
0100 
0101   m_queue = other.m_queue;
0102   m_ownsQueue = false;
0103   return *this;
0104 }
0105 
0106 const cl::sycl::queue* QueueWrapper::getQueue() const {
0107   return m_queue;
0108 }
0109 
0110 cl::sycl::queue* QueueWrapper::getQueue() {
0111   return m_queue;
0112 }
0113 
0114 const cl::sycl::queue* QueueWrapper::operator->() const {
0115   return m_queue;
0116 }
0117 
0118 cl::sycl::queue* QueueWrapper::operator->() {
0119   return m_queue;
0120 }
0121 
0122 const cl::sycl::queue& QueueWrapper::operator*() const {
0123   return *m_queue;
0124 }
0125 
0126 cl::sycl::queue& QueueWrapper::operator*() {
0127   return *m_queue;
0128 }
0129 
0130 }  // namespace Acts::Sycl