Viskores  1.0
Hints.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_internal_Hints_h
19 #define viskores_cont_internal_Hints_h
20 
21 #include <viskores/Assert.h>
22 #include <viskores/List.h>
23 
25 
26 namespace viskores
27 {
28 namespace cont
29 {
30 namespace internal
31 {
32 
44 template <typename Derived_, typename Tag_, typename DeviceList_>
45 struct HintBase
46 {
47  using Derived = Derived_;
48  using Tag = Tag_;
49  using DeviceList = DeviceList_;
50 };
51 
52 struct HintTagThreadsPerBlock
53 {
54 };
55 
60 template <viskores::IdComponent MaxThreads_, typename DeviceList_ = viskores::ListUniversal>
61 struct HintThreadsPerBlock
62  : HintBase<HintThreadsPerBlock<MaxThreads_, DeviceList_>, HintTagThreadsPerBlock, DeviceList_>
63 {
64  static constexpr viskores::IdComponent MaxThreads = MaxThreads_;
65 };
66 
72 template <typename... Hints>
73 struct HintList : viskores::List<Hints...>
74 {
75  using List = viskores::List<Hints...>;
76 };
77 
78 template <typename T>
79 struct IsHintList : std::false_type
80 {
81 };
82 template <typename... Hints>
83 struct IsHintList<HintList<Hints...>> : std::true_type
84 {
85 };
86 
93 #define VISKORES_IS_HINT_LIST(T) \
94  VISKORES_STATIC_ASSERT(::viskores::cont::internal::IsHintList<T>::value)
95 
96 namespace detail
97 {
98 
99 template <typename Device, typename HintTag>
100 struct FindHintOperators
101 {
103 
104  template <typename Hint>
105  using HintMatches =
106  viskores::internal::meta::And<std::is_same<typename Hint::Tag, HintTag>,
108  template <typename Found, typename Next>
109  using ReduceOperator = typename std::conditional<HintMatches<Next>::value, Next, Found>::type;
110 };
111 
112 } // namespace detail
113 
124 template <typename HList, typename DefaultHint, typename Device>
125 using HintFind = viskores::ListReduce<
126  typename HList::List,
127  detail::FindHintOperators<Device, typename DefaultHint::Tag>::template ReduceOperator,
128  DefaultHint>;
129 
130 }
131 }
132 } // namespace viskores::cont::internal
133 
134 #endif // viskores_cont_internal_Hints_h
viskores::ListReduce
typename detail::ListReduceImpl< List, Operator, Initial >::type ListReduce
Reduces a list to a single type using an operator.
Definition: List.h:840
viskores::ListHas
typename detail::ListHasImpl< List, T >::type ListHas
Checks to see if the given T is in the list pointed to by List.
Definition: List.h:596
DeviceAdapterTag.h
Assert.h
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::List
A template used to hold a list of types.
Definition: List.h:47
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
VISKORES_IS_DEVICE_ADAPTER_TAG
#define VISKORES_IS_DEVICE_ADAPTER_TAG(tag)
Checks that the argument is a proper device adapter tag.
Definition: DeviceAdapterTag.h:208
List.h