stdgpu/execution.h Source File

stdgpu/execution.h Source File#

stdgpu: stdgpu/execution.h Source File
stdgpu Latest
Efficient STL-like Data Structures on the GPU
execution.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 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_EXECUTION_H
17#define STDGPU_EXECUTION_H
18
24#include <type_traits>
25
26#include <stdgpu/platform.h>
27#include <stdgpu/type_traits.h>
28
33#include <thrust/execution_policy.h>
34
35namespace stdgpu
36{
37
42template <typename T>
43struct is_execution_policy : std::is_base_of<thrust::execution_policy<T>, T>
44{
45};
46
48template <typename T>
49inline constexpr bool is_execution_policy_v = is_execution_policy<T>::value;
51
52} // namespace stdgpu
53
54namespace stdgpu::execution
55{
56
61template <typename T>
62using execution_policy = thrust::execution_policy<T>;
63
68using device_policy = std::remove_const_t<decltype(thrust::device)>;
69
70static_assert(is_execution_policy_v<remove_cvref_t<device_policy>>,
71 "stdgpu::execution::device_policy: Should be an execution policy but is not");
72
77using host_policy = std::remove_const_t<decltype(thrust::host)>;
78
79static_assert(is_execution_policy_v<remove_cvref_t<host_policy>>,
80 "stdgpu::execution::host_policy: Should be an execution policy but is not");
81
87
92constexpr host_policy host;
93
94} // namespace stdgpu::execution
95
96// execution_detail.cuh declares device-qualified functions, so include it only
97// when the device compiler is active (host-only translation units, e.g. plain
98// .cpp files in the CUDA backend, must not see the __device__ declarations).
99#if STDGPU_DETAIL_IS_DEVICE_COMPILED
100 #include <stdgpu/impl/execution_detail.cuh>
101#endif
102
103#endif // STDGPU_EXECUTION_H
thrust::execution_policy< T > execution_policy
The base execution policy class from which all policies are derived and custom ones must be derived.
Definition: execution.h:62
std::remove_const_t< decltype(thrust::host)> host_policy
The host execution policy class.
Definition: execution.h:77
constexpr device_policy device
The device execution policy.
Definition: execution.h:86
constexpr host_policy host
The host execution policy.
Definition: execution.h:92
std::remove_const_t< decltype(thrust::device)> device_policy
The device execution policy class.
Definition: execution.h:68
Type trait to check whether the provided class is an execution policy.
Definition: execution.h:44