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
100template <typename ExecutionPolicy,
101 typename Iterator,
102 typename T,
103 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
104void
105fill(ExecutionPolicy&& policy, Iterator begin, Iterator end, const T& value);
106
120template <typename ExecutionPolicy,
121 typename Iterator,
122 typename Size,
123 typename T,
124 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
125Iterator
126fill_n(ExecutionPolicy&& policy, Iterator begin, Size n, const T& value);
127
140template <typename ExecutionPolicy,
141 typename InputIt,
142 typename OutputIt,
143 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
144OutputIt
145copy(ExecutionPolicy&& policy, InputIt begin, InputIt end, OutputIt output_begin);
146
160template <typename ExecutionPolicy,
161 typename InputIt,
162 typename Size,
163 typename OutputIt,
164 STDGPU_DETAIL_OVERLOAD_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
165OutputIt
166copy_n(ExecutionPolicy&& policy, InputIt begin, Size n, OutputIt output_begin);
167
168} // namespace stdgpu
169
170#include <stdgpu/impl/algorithm_detail.h>
171
172#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