alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
DevGenericImpl.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
9
10#include <deque>
11#include <functional>
12#include <memory>
13#include <mutex>
14#include <optional>
15
16namespace alpaka::detail
17{
18
19 //! The CPU/GPU device queue registry implementation.
20 //!
21 //! @tparam TQueue queue implementation
22 template<typename TQueue>
24 {
25 ALPAKA_FN_HOST auto getAllExistingQueues() const -> std::vector<std::shared_ptr<TQueue>>
26 {
27 std::vector<std::shared_ptr<TQueue>> vspQueues;
28
29 std::lock_guard<std::mutex> lk(m_Mutex);
30 vspQueues.reserve(std::size(m_queues));
31
32 for(auto it = std::begin(m_queues); it != std::end(m_queues);)
33 {
34 auto spQueue = it->lock();
35 if(spQueue)
36 {
37 vspQueues.emplace_back(std::move(spQueue));
38 ++it;
39 }
40 else
41 {
42 it = m_queues.erase(it);
43 }
44 }
45 return vspQueues;
46 }
47
48 //! Registers the given queue on this device.
49 //! NOTE: Every queue has to be registered for correct functionality of device wait operations!
50 ALPAKA_FN_HOST auto registerQueue(std::shared_ptr<TQueue> const& spQueue) const -> void
51 {
52 std::lock_guard<std::mutex> lk(m_Mutex);
53
54 // Register this queue on the device.
55 m_queues.push_back(spQueue);
56 }
57
58 template<typename TDev>
59 auto deviceProperties(TDev const& device) -> std::optional<alpaka::DeviceProperties>&
60 {
61 std::call_once(
62 m_onceFlag,
63 [&]() noexcept
64 {
65 m_deviceProperties = std::make_optional<alpaka::DeviceProperties>();
66 TDev::setDeviceProperties(device, *m_deviceProperties);
67 });
68
69 return m_deviceProperties;
70 }
71
72 private:
73 std::mutex mutable m_Mutex;
74 std::once_flag m_onceFlag;
75 std::optional<alpaka::DeviceProperties> m_deviceProperties;
76 std::deque<std::weak_ptr<TQueue>> mutable m_queues;
77 };
78} // namespace alpaka::detail
#define ALPAKA_FN_HOST
Definition Common.hpp:40
STL namespace.
The CPU/GPU device queue registry implementation.
auto deviceProperties(TDev const &device) -> std::optional< alpaka::DeviceProperties > &
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...
ALPAKA_FN_HOST auto getAllExistingQueues() const -> std::vector< std::shared_ptr< TQueue > >