rocPRIM
future_value.hpp
1 // Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef ROCPRIM_TYPES_FUTURE_VALUE_HPP_
22 #define ROCPRIM_TYPES_FUTURE_VALUE_HPP_
23 
24 #include "../config.hpp"
25 
28 
29 BEGIN_ROCPRIM_NAMESPACE
30 
54 template <typename T, typename Iter = T*>
56 {
57 public:
58  using value_type = T;
59  using iterator_type = Iter;
60 
63  explicit ROCPRIM_HOST_DEVICE future_value(const Iter iter)
64  : iter_ {iter}
65  {
66  }
67 
70  ROCPRIM_HOST_DEVICE operator T()
71  {
72  return *iter_;
73  }
74 
77  ROCPRIM_HOST_DEVICE operator T() const
78  {
79  return *iter_;
80  }
81 private:
82  Iter iter_;
83 };
84 
85 namespace detail
86 {
89  template <typename T>
90  ROCPRIM_HOST_DEVICE T get_input_value(const T value)
91  {
92  return value;
93  }
94 
95  template <typename T, typename Iter>
96  ROCPRIM_HOST_DEVICE T get_input_value(::rocprim::future_value<T, Iter> future) {
97  return future;
98  }
99 
100  template <class T>
102  using value_type = T;
103  };
104 
105  template <class T, typename Iter>
106  struct input_value_traits<::rocprim::future_value<T, Iter>>
107  {
108  using value_type = T;
109  using iterator_type = Iter;
110  };
111 
112  template <typename T>
113  using input_type_t = typename input_value_traits<T>::value_type;
114 
115  template <typename T>
116  using input_iterator_t = typename input_value_traits<T>::iterator_type;
117 }
118 
119 END_ROCPRIM_NAMESPACE
120 
122 // end of group utilsmodule
123 
124 #endif
ROCPRIM_HOST_DEVICE future_value(const Iter iter)
Constructs a future value.
Definition: future_value.hpp:63
Definition: future_value.hpp:101
T value_type
The type of the value this future will store.
Definition: future_value.hpp:58
ROCPRIM_HOST_DEVICE T get_input_value(const T value)
Used for unpacking a future_value, basically just a cast but its more explicit this way...
Definition: future_value.hpp:90
Deprecated: Configuration of device-level scan primitives.
Definition: block_histogram.hpp:62
Allows passing values that are not yet known at launch time as paramters to device algorithms...
Definition: future_value.hpp:55
Iter iterator_type
An iterator type that can point at the value_type.
Definition: future_value.hpp:59