alpaka
Abstraction Library for Parallel Kernel Acceleration
Traits.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Benjamin Worpitz, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/core/Common.hpp"
9 #include "alpaka/wait/Traits.hpp"
10 
11 #include <type_traits>
12 #include <utility>
13 
14 namespace alpaka
15 {
16  struct ConceptQueue;
17 
18  //! True if TQueue is a queue, i.e. if it implements the ConceptQueue concept.
19  template<typename TQueue>
21 
22  //! The queue traits.
23  namespace trait
24  {
25  //! The queue enqueue trait.
26  template<typename TQueue, typename TTask, typename TSfinae = void>
27  struct Enqueue;
28 
29  //! The queue empty trait.
30  template<typename TQueue, typename TSfinae = void>
31  struct Empty;
32 
33  //! Queue for an accelerator
34  template<typename TAcc, typename TProperty, typename TSfinae = void>
35  struct QueueType;
36  } // namespace trait
37 
38  //! Queues the given task in the given queue.
39  //!
40  //! Special Handling for events:
41  //! If the event has previously been queued, then this call will overwrite any existing state of the event.
42  //! Any subsequent calls which examine the status of event will only examine the completion of this most recent
43  //! call to enqueue.
44  //! If a queue is waiting for an event the latter's event state at the time of the API call to wait() will be
45  //! used to release the queue.
46  template<typename TQueue, typename TTask>
47  ALPAKA_FN_HOST auto enqueue(TQueue& queue, TTask&& task) -> void
48  {
49  trait::Enqueue<TQueue, std::decay_t<TTask>>::enqueue(queue, std::forward<TTask>(task));
50  }
51 
52  //! Tests if the queue is empty (all ops in the given queue have been completed).
53  //!
54  //! \warning This function is allowed to return false negatives. An empty queue can reported as
55  //! non empty because the status information are not fully propagated by the used alpaka backend.
56  //! \return true queue is empty else false.
57  template<typename TQueue>
58  ALPAKA_FN_HOST auto empty(TQueue const& queue) -> bool
59  {
62  }
63 
64  //! Queue based on the environment and a property
65  //!
66  //! \tparam TEnv Environment type, e.g. accelerator, device or a platform.
67  //! trait::QueueType must be specialized for TEnv
68  //! \tparam TProperty Property to define the behavior of TEnv.
69  template<typename TEnv, typename TProperty>
71 } // namespace alpaka
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
typename detail::ImplementationBaseType< TInterface, TDerived >::type ImplementationBase
Returns the type that implements the given interface in the inheritance hierarchy.
Definition: Interface.hpp:66
The alpaka accelerator library.
typename trait::QueueType< TEnv, TProperty >::type Queue
Queue based on the environment and a property.
Definition: Traits.hpp:70
constexpr bool isQueue
True if TQueue is a queue, i.e. if it implements the ConceptQueue concept.
Definition: Traits.hpp:20
ALPAKA_FN_HOST auto empty(TQueue const &queue) -> bool
Tests if the queue is empty (all ops in the given queue have been completed).
Definition: Traits.hpp:58
ALPAKA_FN_HOST auto enqueue(TQueue &queue, TTask &&task) -> void
Queues the given task in the given queue.
Definition: Traits.hpp:47
Checks whether the interface is implemented by the given class.
Definition: Interface.hpp:21
The queue empty trait.
Definition: Traits.hpp:31
The queue enqueue trait.
Definition: Traits.hpp:27
Queue for an accelerator.
Definition: Traits.hpp:35