File: stencil_select.hpp

package info (click to toggle)
gridtools 2.3.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,480 kB
  • sloc: cpp: 228,792; python: 17,561; javascript: 9,164; ansic: 4,101; sh: 850; makefile: 231; f90: 201
file content (232 lines) | stat: -rw-r--r-- 6,683 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
 * GridTools
 *
 * Copyright (c) 2014-2023, ETH Zurich
 * All rights reserved.
 *
 * Please, refer to the LICENSE file in the root directory.
 * SPDX-License-Identifier: BSD-3-Clause
 */
#pragma once

#include <type_traits>

#include <gridtools/meta.hpp>

// stencil backend
#if defined(GT_STENCIL_CPU_KFIRST)
#ifndef GT_STORAGE_CPU_KFIRST
#define GT_STORAGE_CPU_KFIRST
#endif
#ifndef GT_TIMER_OMP
#define GT_TIMER_OMP
#endif
#include <gridtools/stencil/cpu_kfirst.hpp>
namespace {
    using stencil_backend_t = gridtools::stencil::cpu_kfirst<>;
}
#elif defined(GT_STENCIL_CPU_KFIRST_HPX)
#ifndef GT_STORAGE_CPU_KFIRST
#define GT_STORAGE_CPU_KFIRST
#endif
#ifndef GT_TIMER_OMP
#define GT_TIMER_OMP
#endif
#include <gridtools/stencil/cpu_kfirst.hpp>
#include <gridtools/thread_pool/hpx.hpp>
#include <hpx/hpx_start.hpp>
#include <hpx/include/apply.hpp>
namespace {
    using stencil_backend_t = gridtools::stencil::cpu_kfirst<gridtools::integral_constant<int, 8>,
        gridtools::integral_constant<int, 8>,
        gridtools::thread_pool::hpx>;
}
#elif defined(GT_STENCIL_NAIVE)
#ifndef GT_STORAGE_CPU_KFIRST
#define GT_STORAGE_CPU_KFIRST
#endif
#ifndef GT_TIMER_DUMMY
#define GT_TIMER_DUMMY
#endif
#include <gridtools/stencil/naive.hpp>
namespace {
    using stencil_backend_t = gridtools::stencil::naive;
}
#elif defined(GT_STENCIL_CPU_IFIRST)
#ifndef GT_STORAGE_CPU_IFIRST
#define GT_STORAGE_CPU_IFIRST
#endif
#ifndef GT_TIMER_OMP
#define GT_TIMER_OMP
#endif
#include <gridtools/stencil/cpu_ifirst.hpp>
namespace {
    using stencil_backend_t = gridtools::stencil::cpu_ifirst<>;
}
#elif defined(GT_STENCIL_CPU_IFIRST_HPX)
#ifndef GT_STORAGE_CPU_IFIRST
#define GT_STORAGE_CPU_IFIRST
#endif
#ifndef GT_TIMER_OMP
#define GT_TIMER_OMP
#endif
#include <gridtools/stencil/cpu_ifirst.hpp>
#include <gridtools/thread_pool/hpx.hpp>
#include <hpx/hpx_start.hpp>
#include <hpx/include/apply.hpp>
namespace {
    using stencil_backend_t = gridtools::stencil::cpu_ifirst<gridtools::thread_pool::hpx>;
}
#elif defined(GT_STENCIL_GPU)
#ifndef GT_STORAGE_GPU
#define GT_STORAGE_GPU
#endif
#ifndef GT_TIMER_CUDA
#define GT_TIMER_CUDA
#endif
#include <gridtools/stencil/gpu.hpp>
namespace {
    using stencil_backend_t = gridtools::stencil::gpu<>;
}
#elif defined(GT_STENCIL_GPU_HORIZONTAL)
#ifndef GT_STORAGE_GPU
#define GT_STORAGE_GPU
#endif
#ifndef GT_TIMER_CUDA
#define GT_TIMER_CUDA
#endif
#include <gridtools/stencil/gpu_horizontal.hpp>
namespace {
    using stencil_backend_t = gridtools::stencil::gpu_horizontal<>;
}
#endif

#include "storage_select.hpp"
#include "timer_select.hpp"

#if defined(GT_STENCIL_CPU_KFIRST_HPX) || defined(GT_STENCIL_CPU_IFIRST_HPX)
inline bool &hpx_started() {
    static bool res = false;
    return res;
}

inline void hpx_start(int argc, char **argv) {
    if (hpx_started())
        return;
    ::hpx::start(nullptr, argc, argv);
    hpx_started() = true;
}

inline void hpx_stop() {
    if (!hpx_started())
        return;
    ::hpx::apply([] { return hpx::finalize(); });
    ::hpx::stop();
    hpx_started() = false;
}
#endif

namespace gridtools {
    namespace stencil {

        struct naive;
        storage::cpu_kfirst backend_storage_traits(naive);
        timer_dummy backend_timer_impl(naive);
        inline char const *backend_name(naive const &) { return "naive"; }

        namespace cpu_kfirst_backend {
            template <class, class, class>
            struct cpu_kfirst;

            template <class I, class J, class T>
            storage::cpu_kfirst backend_storage_traits(cpu_kfirst<I, J, T>);

            template <class I, class J, class T>
            timer_omp backend_timer_impl(cpu_kfirst<I, J, T>);

            template <class I, class J, class T>
            char const *backend_name(cpu_kfirst<I, J, T> const &) {
                return "cpu_kfirst";
            }

#if defined(GT_STENCIL_CPU_KFIRST_HPX)
            template <class I, class J>
            char const *backend_name(cpu_kfirst<I, J, thread_pool::hpx> const &) {
                return "cpu_kfirst_hpx";
            }

            template <class I, class J>
            void backend_init(cpu_kfirst<I, J, thread_pool::hpx>, int &argc, char **argv) {
                hpx_start(argc, argv);
            }

            template <class I, class J>
            void backend_finalize(cpu_kfirst<I, J, thread_pool::hpx>) {
                hpx_stop();
            }
#endif
        } // namespace cpu_kfirst_backend

        namespace cpu_ifirst_backend {
            template <class>
            struct cpu_ifirst;

            template <class T>
            storage::cpu_ifirst backend_storage_traits(cpu_ifirst<T>);

            template <class T>
            std::false_type backend_supports_icosahedral(cpu_ifirst<T>);

            template <class T>
            timer_omp backend_timer_impl(cpu_ifirst<T>);

            template <class T>
            char const *backend_name(cpu_ifirst<T> const &) {
                return "cpu_ifirst";
            }

#if defined(GT_STENCIL_CPU_IFIRST_HPX)
            inline char const *backend_name(cpu_ifirst<thread_pool::hpx> const &) { return "cpu_ifirst_hpx"; }

            inline void backend_init(cpu_ifirst<thread_pool::hpx>, int &argc, char **argv) { hpx_start(argc, argv); }

            inline void backend_finalize(cpu_ifirst<thread_pool::hpx>) { hpx_stop(); }
#endif
        } // namespace cpu_ifirst_backend

        namespace gpu_backend {
            template <class, class, class>
            struct gpu;

            template <class I, class J, class K>
            storage::gpu backend_storage_traits(gpu<I, J, K>);

            template <class I, class J, class K>
            timer_cuda backend_timer_impl(gpu<I, J, K>);

            template <class I, class J, class K>
            char const *backend_name(gpu<I, J, K> const &) {
                return "gpu";
            }
        } // namespace gpu_backend

        namespace gpu_horizontal_backend {
            template <class, class, class>
            struct gpu_horizontal;

            template <class I, class J, class K>
            storage::gpu backend_storage_traits(gpu_horizontal<I, J, K>);

            template <class I, class J, class K>
            std::false_type backend_supports_vertical_stencils(gpu_horizontal<I, J, K>);

            template <class I, class J, class K>
            timer_cuda backend_timer_impl(gpu_horizontal<I, J, K>);

            template <class I, class J, class K>
            char const *backend_name(gpu_horizontal<I, J, K> const &) {
                return "gpu_horizontal";
            }
        } // namespace gpu_horizontal_backend
    }     // namespace stencil
} // namespace gridtools