alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
QueueGenericThreadsNonBlocking.hpp
Go to the documentation of this file.
1/* Copyright 2023 Benjamin Worpitz, Matthias Werner, Jan Stephan, Bernhard Manfred Gruber, Jeffrey Kelling
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
14
15#include <future>
16#include <memory>
17#include <mutex>
18#include <thread>
19#include <tuple>
20#include <type_traits>
21
22namespace alpaka
23{
24 template<typename TDev>
25 class EventGenericThreads;
26
27 namespace generic
28 {
29 namespace detail
30 {
31#if BOOST_COMP_CLANG
32// avoid diagnostic warning: "has no out-of-line virtual method definitions; its vtable will be emitted in every
33// translation unit [-Werror,-Wweak-vtables]" https://stackoverflow.com/a/29288300
34# pragma clang diagnostic push
35# pragma clang diagnostic ignored "-Wweak-vtables"
36#endif
37 //! The CPU device queue implementation.
38 template<typename TDev>
40#if BOOST_COMP_CLANG
41# pragma clang diagnostic pop
42#endif
43 {
44 public:
45 explicit QueueGenericThreadsNonBlockingImpl(TDev dev) : m_dev(std::move(dev))
46 {
47 }
48
55
59
61 {
62 alpaka::enqueue(*this, ev);
63 }
64
65 void wait(EventGenericThreads<TDev> const& ev) final
66 {
67 alpaka::wait(*this, ev);
68 }
69
70 public:
71 TDev const m_dev; //!< The device this queue is bound to.
73 };
74 } // namespace detail
75 } // namespace generic
76
77 //! The CPU device queue.
78 template<typename TDev>
80 : public interface::Implements<ConceptCurrentThreadWaitFor, QueueGenericThreadsNonBlocking<TDev>>
81 , public interface::Implements<ConceptQueue, QueueGenericThreadsNonBlocking<TDev>>
82 , public interface::Implements<ConceptGetDev, QueueGenericThreadsNonBlocking<TDev>>
83 {
84 public:
85 explicit QueueGenericThreadsNonBlocking(TDev const& dev)
86 : m_spQueueImpl(std::make_shared<generic::detail::QueueGenericThreadsNonBlockingImpl<TDev>>(dev))
87 {
89
90 dev.registerQueue(m_spQueueImpl);
91 }
92
93 auto operator==(QueueGenericThreadsNonBlocking<TDev> const& rhs) const -> bool
94 {
95 return (m_spQueueImpl == rhs.m_spQueueImpl);
96 }
97
98 auto operator!=(QueueGenericThreadsNonBlocking<TDev> const& rhs) const -> bool
99 {
100 return !((*this) == rhs);
101 }
102
103 public:
104 std::shared_ptr<generic::detail::QueueGenericThreadsNonBlockingImpl<TDev>> m_spQueueImpl;
105 };
106
107 namespace trait
108 {
109 //! The CPU non-blocking device queue device type trait specialization.
110 template<typename TDev>
112 {
113 using type = TDev;
114 };
115
116 //! The CPU non-blocking device queue device get trait specialization.
117 template<typename TDev>
119 {
121 {
122 return queue.m_spQueueImpl->m_dev;
123 }
124 };
125
126 //! The CPU non-blocking device queue event type trait specialization.
127 template<typename TDev>
132
133 //! The CPU non-blocking device queue enqueue trait specialization.
134 //! This default implementation for all tasks directly invokes the function call operator of the task.
135 template<typename TDev, typename TTask>
137 {
138 ALPAKA_FN_HOST static auto enqueue(QueueGenericThreadsNonBlocking<TDev>& queue, TTask const& task) -> void
139 {
140 queue.m_spQueueImpl->m_workerThread.submit(task);
141 }
142 };
143
144 //! The CPU non-blocking device queue test trait specialization.
145 template<typename TDev>
147 {
149 {
150 return queue.m_spQueueImpl->m_workerThread.empty();
151 }
152 };
153 } // namespace trait
154} // namespace alpaka
155
#define ALPAKA_DEBUG_FULL_LOG_SCOPE
Definition Debug.hpp:62
auto operator==(QueueGenericThreadsNonBlocking< TDev > const &rhs) const -> bool
std::shared_ptr< generic::detail::QueueGenericThreadsNonBlockingImpl< TDev > > m_spQueueImpl
auto operator!=(QueueGenericThreadsNonBlocking< TDev > const &rhs) const -> bool
auto operator=(QueueGenericThreadsNonBlockingImpl &&) -> QueueGenericThreadsNonBlockingImpl< TDev > &=delete
QueueGenericThreadsNonBlockingImpl(QueueGenericThreadsNonBlockingImpl< TDev > const &)=delete
void enqueue(EventGenericThreads< TDev > &ev) final
enqueue the event
void wait(EventGenericThreads< TDev > const &ev) final
waiting for the event
QueueGenericThreadsNonBlockingImpl(QueueGenericThreadsNonBlockingImpl< TDev > &&)=delete
auto operator=(QueueGenericThreadsNonBlockingImpl< TDev > const &) -> QueueGenericThreadsNonBlockingImpl< TDev > &=delete
#define ALPAKA_FN_HOST
Definition Common.hpp:40
The alpaka accelerator library.
ALPAKA_FN_HOST auto enqueue(TQueue &queue, TTask &&task) -> void
Queues the given task in the given queue.
Definition Traits.hpp:47
ALPAKA_FN_HOST auto wait(TAwaited const &awaited) -> void
Waits the thread for the completion of the given awaited action to complete.
Definition Traits.hpp:34
STL namespace.
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition Interface.hpp:15
The device type trait.
Definition Traits.hpp:23
static ALPAKA_FN_HOST auto empty(QueueGenericThreadsNonBlocking< TDev > const &queue) -> bool
The queue empty trait.
Definition Traits.hpp:31
static ALPAKA_FN_HOST auto enqueue(QueueGenericThreadsNonBlocking< TDev > &queue, TTask const &task) -> void
The queue enqueue trait.
Definition Traits.hpp:27
The event type trait.
Definition Traits.hpp:17
static ALPAKA_FN_HOST auto getDev(QueueGenericThreadsNonBlocking< TDev > const &queue) -> TDev
The device get trait.
Definition Traits.hpp:27