EIC 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 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& deviceNameSubtring) {
25  initialize(deviceNameSubtring);
26 }
27 
29  : m_queue(parent.m_queue), m_ownsQueue(parent.m_ownsQueue) {
30  parent.m_queue = nullptr;
31  parent.m_ownsQueue = false;
32 }
33 
35  m_queue = other.m_queue;
36  m_ownsQueue = false;
37 }
38 
40  if (m_ownsQueue && (m_queue != nullptr)) {
41  delete m_queue;
42  }
43 };
44 
46  // Check whether we have to do anything
47  if (this == &rhs) {
48  return *this;
49  }
50 
51  // Destroy this queue,
52  if (m_ownsQueue && (m_queue != nullptr)) {
53  delete m_queue;
54  }
55 
56  // Perform the move
57  m_queue = rhs.m_queue;
58  m_ownsQueue = rhs.m_ownsQueue;
59  rhs.m_queue = nullptr;
60  rhs.m_ownsQueue = false;
61 
62  // Return this object.
63  return *this;
64 };
65 
67  // Check whether we have to do anything
68  if (this == &other) {
69  return *this;
70  }
71 
72  m_queue = other.m_queue;
73  m_ownsQueue = false;
74  return *this;
75 };
76 
77 cl::sycl::queue* QueueWrapper::getQueue() const {
78  return m_queue;
79 }
80 
81 void QueueWrapper::initialize(const std::string& deviceNameSubstring) {
82  // SYCL kernel exceptions are asynchronous
83  auto exception_handler = [](cl::sycl::exception_list exceptions) {
84  for (std::exception_ptr const& e : exceptions) {
85  try {
86  std::rethrow_exception(e);
87  } catch (std::exception& e) {
90  ACTS_FATAL("Caught asynchronous (kernel) SYCL exception:\n" << e.what())
91  }
92  }
93  };
94 
97  // Create queue with custom device selector
98  m_queue = new cl::sycl::queue(DeviceSelector(deviceNameSubstring),
99  exception_handler);
100 
101  m_ownsQueue = true;
102 
103  // See which device we are running on.
104  ACTS_INFO("Running on: "
105  << m_queue->get_device().get_info<cl::sycl::info::device::name>());
106 };
107 
108 } // namespace Acts::Sycl