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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
/*
* 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
*/
#include <gtest/gtest.h>
#include <gridtools/stencil/cartesian.hpp>
#include "test_call_interfaces.hpp"
namespace gridtools {
namespace stencil {
namespace cartesian {
struct call_interface : base_fixture {
fun_t incremented = [this](int i, int j, int k) { return input(i, j, k) + 1; };
template <class Fun>
void do_test(fun_t expected = {}) const {
auto out = env_t::make_storage(0);
run_computation<Fun>(env_t::make_storage(input), out);
if (!expected)
expected = input;
env_t::verify(expected, out);
}
};
struct copy_functor_with_add {
typedef inout_accessor<0> out;
typedef in_accessor<1> in1;
typedef in_accessor<2> in2;
typedef make_param_list<out, in1, in2> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = eval(in1()) + eval(in2());
}
};
// The implementation is different depending on the position of the out accessor in the callee, as the
// position of the input accessors in the call has to be shifted when it is not in the last position.
struct copy_functor_with_out_first {
typedef inout_accessor<0> out;
typedef in_accessor<1> in;
typedef make_param_list<out, in> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = eval(in());
}
};
struct call_copy_functor {
typedef in_accessor<0> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<copy_functor, x_interval>::with(eval, in());
}
};
TEST_F(call_interface, call_to_copy_functor) { do_test<call_copy_functor>(); }
struct call_copy_functor_with_local_variable {
typedef in_accessor<0> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
double local = 1.;
eval(out()) = call<copy_functor_with_add, x_interval>::with(eval, in(), local);
}
};
TEST_F(call_interface, call_to_copy_functor_with_local_variable) {
do_test<call_copy_functor_with_local_variable>(incremented);
}
struct call_copy_functor_with_local_variable2 {
typedef in_accessor<0> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
double local = 1.;
eval(out()) = call<copy_functor_with_add, x_interval>::with(eval, local, in());
}
};
TEST_F(call_interface, call_to_copy_functor_with_local_variable2) {
do_test<call_copy_functor_with_local_variable2>(incremented);
}
struct call_copy_functor_with_out_first {
typedef in_accessor<0> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<copy_functor_with_out_first, x_interval>::with(eval, in());
}
};
TEST_F(call_interface, call_to_copy_functor_with_out_first) { do_test<call_copy_functor_with_out_first>(); }
struct call_proc_copy_functor_with_expression {
typedef in_accessor<0> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<copy_functor_with_expression, x_interval>::with(eval, in());
}
};
TEST_F(call_interface, call_to_copy_functor_with_expression) {
do_test<call_proc_copy_functor_with_expression>();
}
struct call_at_copy_functor {
typedef in_accessor<0, extent<0, 1, 0, 1>> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<copy_functor, x_interval>::at<1, 1, 0>::with(eval, in());
}
};
TEST_F(call_interface, call_at_to_copy_functor) { do_test<call_at_copy_functor>(shifted); }
struct call_with_offsets_copy_functor {
typedef in_accessor<0, extent<0, 1, 0, 1>> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<copy_functor, x_interval>::with(eval, in(1, 1, 0));
}
};
TEST_F(call_interface, call_with_offsets_to_copy_functor) {
do_test<call_with_offsets_copy_functor>(shifted);
}
struct call_at_with_offsets_copy_functor {
typedef in_accessor<0, extent<0, 1, 0, 1>> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<copy_functor, x_interval>::at<-1, -1, 0>::with(eval, in(1, 1, 0));
}
};
TEST_F(call_interface, call_at_with_offsets_to_copy_functor) {
do_test<call_at_with_offsets_copy_functor>();
}
struct call_copy_functor_default_interval {
typedef in_accessor<0> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval) {
eval(out()) = call<copy_functor_default_interval>::with(eval, in());
}
};
TEST_F(call_interface, call_to_copy_functor_default_interval) {
do_test<call_copy_functor_default_interval>();
}
struct call_copy_functor_default_interval_from_smaller_interval {
typedef in_accessor<0> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval::modify<1, -1>) {
eval(out()) = call<copy_functor_default_interval>::with(eval, in());
}
};
TEST_F(call_interface, call_to_copy_functor_default_interval_from_smaller_interval) {
do_test<call_copy_functor_default_interval_from_smaller_interval>(
[this](int i, int j, int k) { return k > 0 && k < env_t::k_size() - 1 ? input(i, j, k) : 0; });
}
struct call_copy_functor_default_interval_with_offset_in_k {
typedef in_accessor<0, extent<0, 0, 0, 0, 0, 1>> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval) {
eval(out()) = call<copy_functor_default_interval>::at<0, 0, -1>::with(eval, in(0, 0, 1));
}
};
TEST_F(call_interface, call_to_copy_functor_default_interval_with_offset_in_k) {
do_test<call_copy_functor_default_interval_with_offset_in_k>();
}
struct call_call_copy_functor {
typedef in_accessor<0> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<call_copy_functor, x_interval>::with(eval, in());
}
};
TEST_F(call_interface, call_to_call_to_copy_functor) { do_test<call_call_copy_functor>(); }
struct call_call_at_copy_functor {
typedef in_accessor<0, extent<0, 1, 0, 1>> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<call_at_copy_functor, x_interval>::with(eval, in());
}
};
TEST_F(call_interface, call_to_call_at_to_copy_functor) { do_test<call_call_at_copy_functor>(shifted); }
struct call_call_with_offsets_copy_functor {
typedef in_accessor<0, extent<0, 1, 0, 1>> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<call_with_offsets_copy_functor, x_interval>::with(eval, in());
}
};
TEST_F(call_interface, call_to_call_with_offsets_to_copy_functor) {
do_test<call_call_with_offsets_copy_functor>(shifted);
}
struct call_at_call_copy_functor {
typedef in_accessor<0, extent<0, 1, 0, 1>> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<call_copy_functor, x_interval>::at<1, 1, 0>::with(eval, in());
}
};
TEST_F(call_interface, call_at_to_call_to_copy_functor) { do_test<call_at_call_copy_functor>(shifted); }
struct call_at_call_at_copy_functor {
typedef in_accessor<0, extent<-1, 0, -1, 0>> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<call_at_copy_functor, x_interval>::at<-1, -1, 0>::with(eval, in());
}
};
TEST_F(call_interface, call_at_to_call_at_to_copy_functor) { do_test<call_at_call_at_copy_functor>(); }
struct call_with_offsets_call_at_copy_functor {
typedef in_accessor<0, extent<-1, 0, -1, 0>> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<call_at_copy_functor, x_interval>::with(eval, in(-1, -1, 0));
}
};
TEST_F(call_interface, call_with_offsets_to_call_at_to_copy_functor) {
do_test<call_with_offsets_call_at_copy_functor>();
}
struct call_at_call_with_offsets_copy_functor {
typedef in_accessor<0, extent<-1, 0, -1, 0>> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<call_with_offsets_copy_functor, x_interval>::at<-1, -1, 0>::with(eval, in());
}
};
TEST_F(call_interface, call_at_to_call_with_offsets_to_copy_functor) {
do_test<call_at_call_with_offsets_copy_functor>();
}
struct call_with_offsets_call_with_offsets_copy_functor {
typedef in_accessor<0, extent<-1, 0, -1, 0>> in;
typedef inout_accessor<1> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = call<call_with_offsets_copy_functor, x_interval>::with(eval, in(-1, -1, 0));
}
};
TEST_F(call_interface, call_with_offsets_to_call_with_offsets_to_copy_functor) {
do_test<call_with_offsets_call_with_offsets_copy_functor>();
}
} // namespace cartesian
} // namespace stencil
} // namespace gridtools
|