Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueueWrapper.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file QueueWrapper.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020-2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 // System include(s)
10 #include <string>
11 
12 // Acts include(s)
14 
15 // SYCL plugin include(s)
18 
19 // SYCL include
20 #include <CL/sycl.hpp>
21 
22 namespace Acts::Sycl {
23 
24 QueueWrapper::QueueWrapper(const std::string& deviceNameSubstring,
25  std::unique_ptr<const Logger> incomingLogger)
26  : m_queue(nullptr), m_ownsQueue(true), m_logger(std::move(incomingLogger)) {
27  // SYCL kernel exceptions are asynchronous
28  auto exception_handler = [this](cl::sycl::exception_list exceptions) {
29  for (std::exception_ptr const& e : exceptions) {
30  try {
31  std::rethrow_exception(e);
32  } catch (std::exception& e) {
33  ACTS_FATAL("Caught asynchronous (kernel) SYCL exception:\n" << e.what())
34  }
35  }
36  };
37 
38  // Create queue with custom device selector
39  m_queue = new cl::sycl::queue(DeviceSelector(deviceNameSubstring),
40  exception_handler);
41  m_ownsQueue = true;
42 
43  // See which device we are running on.
44  ACTS_INFO("Running on: "
45  << m_queue->get_device().get_info<cl::sycl::info::device::name>());
46 }
47 
48 QueueWrapper::QueueWrapper(cl::sycl::queue& queue,
49  std::unique_ptr<const Logger> incomingLogger)
50  : m_queue(&queue),
52  m_logger(std::move(incomingLogger)) {}
53 
55  : m_queue(parent.m_queue),
56  m_ownsQueue(parent.m_ownsQueue),
57  m_logger(std::move(parent.m_logger)) {
58  parent.m_queue = nullptr;
59  parent.m_ownsQueue = false;
60 }
61 
63  : m_queue(other.m_queue),
64  m_ownsQueue(false),
65  m_logger(getDefaultLogger("Sycl::QueueWrapper", Logging::INFO)) {}
66 
68  if (m_ownsQueue && (m_queue != nullptr)) {
69  delete m_queue;
70  }
71 }
72 
74  // Check whether we have to do anything
75  if (this == &rhs) {
76  return *this;
77  }
78 
79  // Destroy this queue,
80  if (m_ownsQueue && (m_queue != nullptr)) {
81  delete m_queue;
82  }
83 
84  // Perform the move
85  m_queue = rhs.m_queue;
86  m_ownsQueue = rhs.m_ownsQueue;
87  m_logger = std::move(rhs.m_logger);
88  rhs.m_queue = nullptr;
89  rhs.m_ownsQueue = false;
90 
91  // Return this object.
92  return *this;
93 }
94 
96  // Check whether we have to do anything
97  if (this == &other) {
98  return *this;
99  }
100 
101  m_queue = other.m_queue;
102  m_ownsQueue = false;
103  return *this;
104 }
105 
106 const cl::sycl::queue* QueueWrapper::getQueue() const {
107  return m_queue;
108 }
109 
110 cl::sycl::queue* QueueWrapper::getQueue() {
111  return m_queue;
112 }
113 
114 const cl::sycl::queue* QueueWrapper::operator->() const {
115  return m_queue;
116 }
117 
118 cl::sycl::queue* QueueWrapper::operator->() {
119  return m_queue;
120 }
121 
122 const cl::sycl::queue& QueueWrapper::operator*() const {
123  return *m_queue;
124 }
125 
126 cl::sycl::queue& QueueWrapper::operator*() {
127  return *m_queue;
128 }
129 
130 } // namespace Acts::Sycl