alpaka
Abstraction Library for Parallel Kernel Acceleration
QueueRegistry.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Axel Huebl, Benjamin Worpitz, Jeffrey Kelling
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/core/Common.hpp"
8 
9 #include <deque>
10 #include <functional>
11 #include <memory>
12 #include <mutex>
13 
14 namespace alpaka::detail
15 {
16  //! The CPU/GPU device queue registry implementation.
17  //!
18  //! @tparam TQueue queue implementation
19  template<typename TQueue>
21  {
22  ALPAKA_FN_HOST auto getAllExistingQueues() const -> std::vector<std::shared_ptr<TQueue>>
23  {
24  std::vector<std::shared_ptr<TQueue>> vspQueues;
25 
26  std::lock_guard<std::mutex> lk(m_Mutex);
27  vspQueues.reserve(std::size(m_queues));
28 
29  for(auto it = std::begin(m_queues); it != std::end(m_queues);)
30  {
31  auto spQueue = it->lock();
32  if(spQueue)
33  {
34  vspQueues.emplace_back(std::move(spQueue));
35  ++it;
36  }
37  else
38  {
39  it = m_queues.erase(it);
40  }
41  }
42  return vspQueues;
43  }
44 
45  //! Registers the given queue on this device.
46  //! NOTE: Every queue has to be registered for correct functionality of device wait operations!
47  ALPAKA_FN_HOST auto registerQueue(std::shared_ptr<TQueue> const& spQueue) const -> void
48  {
49  std::lock_guard<std::mutex> lk(m_Mutex);
50 
51  // Register this queue on the device.
52  m_queues.push_back(spQueue);
53  }
54 
55  private:
56  std::mutex mutable m_Mutex;
57  std::deque<std::weak_ptr<TQueue>> mutable m_queues;
58  };
59 } // namespace alpaka::detail
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
ALPAKA_FN_HOST auto end(TView &view) -> Iterator< TView >
Definition: Iterator.hpp:139
ALPAKA_FN_HOST auto begin(TView &view) -> Iterator< TView >
Definition: Iterator.hpp:133
The CPU/GPU device queue registry implementation.
ALPAKA_FN_HOST auto getAllExistingQueues() const -> std::vector< std::shared_ptr< TQueue >>
ALPAKA_FN_HOST auto registerQueue(std::shared_ptr< TQueue > const &spQueue) const -> void
Registers the given queue on this device. NOTE: Every queue has to be registered for correct function...