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
|
/*
* 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 {
namespace {
struct call_proc_interface : public base_fixture {
using storage_type = typename env_t::storage_type;
storage_type in = env_t::make_storage(input);
storage_type out1 = env_t::make_storage();
storage_type out2 = env_t::make_storage();
void verify(storage_type actual, fun_t expected = {}) {
if (!expected)
expected = input;
env_t::verify(env_t::make_storage(expected), actual);
}
};
struct copy_twice_functor {
typedef in_accessor<0> in;
typedef inout_accessor<1> out1;
typedef inout_accessor<2> out2;
typedef make_param_list<in, out1, out2> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out1()) = eval(in());
eval(out2()) = eval(in());
}
};
struct call_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) {
call_proc<copy_functor_with_expression, x_interval>::with(eval, in(), out());
}
};
TEST_F(call_proc_interface, call_to_copy_functor_with_expression) {
run_computation<call_copy_functor_with_expression>(in, out1);
verify(out1);
}
struct call_copy_twice_functor {
typedef in_accessor<0> in;
typedef inout_accessor<1> out1;
typedef inout_accessor<2> out2;
typedef make_param_list<in, out1, out2> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
call_proc<copy_twice_functor, x_interval>::with(eval, in(), out1(), out2());
}
};
TEST_F(call_proc_interface, call_to_copy_twice_functor) {
run_computation<call_copy_twice_functor>(in, out1, out2);
verify(out1);
verify(out2);
}
struct call_with_offsets_copy_twice_functor {
typedef in_accessor<0, extent<0, 1, 0, 1>> in;
typedef inout_accessor<1> out1;
typedef inout_accessor<2> out2;
typedef make_param_list<in, out1, out2> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
call_proc<copy_twice_functor, x_interval>::with(eval, in(1, 1, 0), out1(), out2());
}
};
TEST_F(call_proc_interface, call_with_offsets_to_copy_twice_functor) {
run_computation<call_with_offsets_copy_twice_functor>(in, out1, out2);
verify(out1, shifted);
verify(out2, shifted);
}
struct call_proc_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) {
call_proc<copy_functor_default_interval>::with(eval, in(), out());
}
};
TEST_F(call_proc_interface, call_to_copy_functor_default_interval) {
run_computation<call_proc_copy_functor_default_interval>(in, out1);
verify(out1);
}
struct call_proc_copy_functor_default_interval_with_offset_in_k {
typedef in_accessor<0, extent<0, 0, 0, 0, 0, 1>> in;
typedef inout_accessor<1, extent<0, 0, 0, 0, 0, 1>> out;
typedef make_param_list<in, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
call_proc<copy_functor_default_interval>::at<0, 0, -1>::with(eval, in(0, 0, 1), out(0, 0, 1));
}
};
TEST_F(call_proc_interface, call_to_copy_functor_default_interval_with_offset_in_k) {
run_computation<call_proc_copy_functor_default_interval_with_offset_in_k>(in, out1);
verify(out1);
}
struct call_call_copy_twice_functor {
typedef in_accessor<0> in;
typedef inout_accessor<1> out1;
typedef inout_accessor<2> out2;
typedef make_param_list<in, out1, out2> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
call_proc<call_copy_twice_functor, x_interval>::with(eval, in(), out1(), out2());
}
};
TEST_F(call_proc_interface, call_to_call_to_copy_twice_functor) {
run_computation<call_call_copy_twice_functor>(in, out1, out2);
verify(out1);
verify(out2);
}
struct call_with_offsets_call_copy_twice_functor {
typedef in_accessor<0, extent<0, 1, 0, 1>> in;
typedef inout_accessor<1> out1;
typedef inout_accessor<2> out2;
typedef make_param_list<in, out1, out2> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
call_proc<call_copy_twice_functor, x_interval>::with(eval, in(1, 1, 0), out1(), out2());
}
};
TEST_F(call_proc_interface, call_with_offsets_to_call_to_copy_twice_functor) {
run_computation<call_with_offsets_call_copy_twice_functor>(in, out1, out2);
verify(out1, shifted);
verify(out2, shifted);
}
struct call_with_offsets_call_with_offsets_copy_twice_functor {
typedef in_accessor<0, extent<-1, 0, -1, 0>> in;
typedef inout_accessor<1> out1;
typedef inout_accessor<2> out2;
typedef make_param_list<in, out1, out2> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
call_proc<call_with_offsets_copy_twice_functor, x_interval>::with(
eval, in(-1, -1, 0), out1(), out2());
}
};
TEST_F(call_proc_interface, call_with_offsets_to_call_with_offsets_to_copy_twice_functor) {
run_computation<call_with_offsets_call_with_offsets_copy_twice_functor>(in, out1, out2);
verify(out1);
verify(out2);
}
struct call_with_local_variable {
typedef in_accessor<0> in;
typedef inout_accessor<1> out1;
typedef inout_accessor<2> out2;
typedef make_param_list<in, out1, out2> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
double local_in = 1;
double local_out = -1;
call_proc<copy_functor, x_interval>::with(eval, local_in, local_out);
if (local_out > 0.) {
eval(out1()) = eval(in());
}
}
};
TEST_F(call_proc_interface, call_using_local_variables) {
run_computation<call_with_local_variable>(in, out1, out2);
verify(out1);
}
struct functor_where_index_of_accessor_is_shifted_inner {
typedef inout_accessor<0> out;
typedef make_param_list<out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
eval(out()) = 1.;
}
};
struct functor_where_index_of_accessor_is_shifted {
typedef inout_accessor<0> local_out;
typedef inout_accessor<1> out;
typedef make_param_list<local_out, out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
call_proc<functor_where_index_of_accessor_is_shifted_inner, x_interval>::with(eval, out());
}
};
struct call_with_nested_calls_and_shifted_accessor_index {
typedef inout_accessor<0> out;
typedef make_param_list<out> param_list;
template <typename Evaluation>
GT_FUNCTION static void apply(Evaluation &eval, x_interval) {
double local_out;
call_proc<functor_where_index_of_accessor_is_shifted, x_interval>::with(eval, local_out, out());
}
};
TEST_F(call_proc_interface, call_using_local_variables_and_nested_call) {
run_computation<call_with_nested_calls_and_shifted_accessor_index>(out1);
verify(out1, [](int, int, int) { return 1; });
}
} // namespace
} // namespace cartesian
} // namespace stencil
} // namespace gridtools
|