stdgpu/algorithm.h Source File

stdgpu/algorithm.h Source File#

stdgpu: stdgpu/algorithm.h Source File
stdgpu Latest
Efficient STL-like Data Structures on the GPU
algorithm.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Patrick Stotko
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef STDGPU_ALGORITHM_H
17#define STDGPU_ALGORITHM_H
18
28#include <stdgpu/execution.h>
29#include <stdgpu/platform.h>
30
31namespace stdgpu
32{
33
42template <class T>
43constexpr STDGPU_HOST_DEVICE const T&
44min(const T& a, const T& b);
45
54template <class T>
55constexpr STDGPU_HOST_DEVICE const T&
56max(const T& a, const T& b);
57
68template <class T>
69/*constexpr*/ STDGPU_HOST_DEVICE const T&
70clamp(const T& v, const T& lower, const T& upper);
71
82template <typename IndexType,
83 typename ExecutionPolicy,
84 typename UnaryFunction,
85 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
86void
87for_each_index(ExecutionPolicy&& policy, IndexType size, UnaryFunction f);
88
89#ifdef STDGPU_RUN_DOXYGEN
90
102template <typename ExecutionPolicy,
103 typename Iterator,
104 typename T,
105 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
106void
107fill(ExecutionPolicy&& policy, Iterator begin, Iterator end, const T& value);
108
122template <typename ExecutionPolicy,
123 typename Iterator,
124 typename Size,
125 typename T,
126 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
127Iterator
128fill_n(ExecutionPolicy&& policy, Iterator begin, Size n, const T& value);
129
142template <typename ExecutionPolicy,
143 typename InputIt,
144 typename OutputIt,
145 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
146OutputIt
147copy(ExecutionPolicy&& policy, InputIt begin, InputIt end, OutputIt output_begin);
148
162template <typename ExecutionPolicy,
163 typename InputIt,
164 typename Size,
165 typename OutputIt,
166 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
167OutputIt
168copy_n(ExecutionPolicy&& policy, InputIt begin, Size n, OutputIt output_begin);
169
170#endif
171
173namespace adl_barrier
174{
175
176template <typename ExecutionPolicy,
177 typename Iterator,
178 typename T,
179 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
180void
181fill(ExecutionPolicy&& policy, Iterator begin, Iterator end, const T& value);
182
183template <typename ExecutionPolicy,
184 typename Iterator,
185 typename Size,
186 typename T,
187 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
188Iterator
189fill_n(ExecutionPolicy&& policy, Iterator begin, Size n, const T& value);
190
191template <typename ExecutionPolicy,
192 typename InputIt,
193 typename OutputIt,
194 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
195OutputIt
196copy(ExecutionPolicy&& policy, InputIt begin, InputIt end, OutputIt output_begin);
197
198template <typename ExecutionPolicy,
199 typename InputIt,
200 typename Size,
201 typename OutputIt,
202 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
203OutputIt
204copy_n(ExecutionPolicy&& policy, InputIt begin, Size n, OutputIt output_begin);
205
206} // namespace adl_barrier
207
208using namespace adl_barrier;
210
211} // namespace stdgpu
212
213#include <stdgpu/impl/algorithm_detail.h>
214
215#endif // STDGPU_ALGORITHM_H
STDGPU_HOST_DEVICE const T & clamp(const T &v, const T &lower, const T &upper)
Clamps a value to the given range.
constexpr STDGPU_HOST_DEVICE const T & min(const T &a, const T &b)
Computes the minimum of the given values.
Iterator fill_n(ExecutionPolicy &&policy, Iterator begin, Size n, const T &value)
Writes the given value into the given range using the copy assignment operator.
OutputIt copy_n(ExecutionPolicy &&policy, InputIt begin, Size n, OutputIt output_begin)
Copies all elements of the input range to the output range using the copy assignment operator.
void for_each_index(ExecutionPolicy &&policy, IndexType size, UnaryFunction f)
Calls the given unary function with an index from the range [0, size)
void fill(ExecutionPolicy &&policy, Iterator begin, Iterator end, const T &value)
Writes the given value into the given range using the copy assignment operator.
constexpr STDGPU_HOST_DEVICE const T & max(const T &a, const T &b)
Computes the maximum of the given values.
OutputIt copy(ExecutionPolicy &&policy, InputIt begin, InputIt end, OutputIt output_begin)
Copies all elements of the input range to the output range using the copy assignment operator.
index64_t size(T *array)
Finds the size (number of elements) of the given dynamically allocated array.
#define STDGPU_HOST_DEVICE
Platform-independent host device function annotation.
Definition: platform.h:77