|
| 1 | +/** Copyright 2022 Jakob Krude, Benjamin Worpitz, Bernhard Manfred Gruber, Sergei Bastrakov |
| 2 | + * |
| 3 | + * This file is part of alpaka. |
| 4 | + * |
| 5 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | + */ |
| 9 | + |
| 10 | +#include "Buffer.hpp" |
| 11 | +#include "DataGen.hpp" |
| 12 | +#include "Defines.hpp" |
| 13 | +#include "Functor.hpp" |
| 14 | + |
| 15 | +#include <alpaka/math/Complex.hpp> |
| 16 | +#include <alpaka/test/KernelExecutionFixture.hpp> |
| 17 | +#include <alpaka/test/acc/TestAccs.hpp> |
| 18 | +#include <alpaka/test/queue/Queue.hpp> |
| 19 | + |
| 20 | +#include <catch2/catch.hpp> |
| 21 | + |
| 22 | +#include <cmath> |
| 23 | + |
| 24 | +using TestAccs = alpaka::test::EnabledAccs<alpaka::DimInt<1u>, std::size_t>; |
| 25 | + |
| 26 | +namespace custom |
| 27 | +{ |
| 28 | + enum Custom |
| 29 | + { |
| 30 | + Abs, |
| 31 | + Acos, |
| 32 | + Arg, |
| 33 | + Asin, |
| 34 | + Atan, |
| 35 | + Atan2, |
| 36 | + Cbrt, |
| 37 | + Ceil, |
| 38 | + Conj, |
| 39 | + Cos, |
| 40 | + Erf, |
| 41 | + Exp, |
| 42 | + Floor, |
| 43 | + Fmod, |
| 44 | + Log, |
| 45 | + Max, |
| 46 | + Min, |
| 47 | + Pow, |
| 48 | + Remainder, |
| 49 | + Round, |
| 50 | + Lround, |
| 51 | + Llround, |
| 52 | + Rsqrt, |
| 53 | + Sin, |
| 54 | + Sincos, |
| 55 | + Sqrt, |
| 56 | + Tan, |
| 57 | + Trunc, |
| 58 | + |
| 59 | + Arg1 = 1024, |
| 60 | + Arg2 = 2048, |
| 61 | + Arg3 = 4096, |
| 62 | + }; |
| 63 | + |
| 64 | + // struct Custom |
| 65 | + //{ |
| 66 | + //}; |
| 67 | + |
| 68 | + ALPAKA_FN_HOST_ACC auto abs(Custom c); |
| 69 | + ALPAKA_FN_HOST_ACC auto abs(Custom c) |
| 70 | + { |
| 71 | + return Custom::Abs | c; |
| 72 | + } |
| 73 | + |
| 74 | + ALPAKA_FN_HOST_ACC auto acos(Custom c); |
| 75 | + ALPAKA_FN_HOST_ACC auto acos(Custom c) |
| 76 | + { |
| 77 | + return Custom::Acos | c; |
| 78 | + } |
| 79 | + |
| 80 | + ALPAKA_FN_HOST_ACC auto arg(Custom c); |
| 81 | + ALPAKA_FN_HOST_ACC auto arg(Custom c) |
| 82 | + { |
| 83 | + return Custom::Arg | c; |
| 84 | + } |
| 85 | + |
| 86 | + ALPAKA_FN_HOST_ACC auto asin(Custom c); |
| 87 | + ALPAKA_FN_HOST_ACC auto asin(Custom c) |
| 88 | + { |
| 89 | + return Custom::Asin | c; |
| 90 | + } |
| 91 | + |
| 92 | + ALPAKA_FN_HOST_ACC auto atan(Custom c); |
| 93 | + ALPAKA_FN_HOST_ACC auto atan(Custom c) |
| 94 | + { |
| 95 | + return Custom::Atan | c; |
| 96 | + } |
| 97 | + |
| 98 | + ALPAKA_FN_HOST_ACC auto atan2(Custom a, Custom b); |
| 99 | + ALPAKA_FN_HOST_ACC auto atan2(Custom a, Custom b) |
| 100 | + { |
| 101 | + return Custom::Atan2 | a | b; |
| 102 | + } |
| 103 | + |
| 104 | + ALPAKA_FN_HOST_ACC auto cbrt(Custom c); |
| 105 | + ALPAKA_FN_HOST_ACC auto cbrt(Custom c) |
| 106 | + { |
| 107 | + return Custom::Cbrt | c; |
| 108 | + } |
| 109 | + |
| 110 | + ALPAKA_FN_HOST_ACC auto ceil(Custom c); |
| 111 | + ALPAKA_FN_HOST_ACC auto ceil(Custom c) |
| 112 | + { |
| 113 | + return Custom::Ceil | c; |
| 114 | + } |
| 115 | + |
| 116 | + ALPAKA_FN_HOST_ACC auto conj(Custom c); |
| 117 | + ALPAKA_FN_HOST_ACC auto conj(Custom c) |
| 118 | + { |
| 119 | + return Custom::Conj | c; |
| 120 | + } |
| 121 | + |
| 122 | + ALPAKA_FN_HOST_ACC auto cos(Custom c); |
| 123 | + ALPAKA_FN_HOST_ACC auto cos(Custom c) |
| 124 | + { |
| 125 | + return Custom::Cos | c; |
| 126 | + } |
| 127 | + |
| 128 | + ALPAKA_FN_HOST_ACC auto erf(Custom c); |
| 129 | + ALPAKA_FN_HOST_ACC auto erf(Custom c) |
| 130 | + { |
| 131 | + return Custom::Erf | c; |
| 132 | + } |
| 133 | + |
| 134 | + ALPAKA_FN_HOST_ACC auto exp(Custom c); |
| 135 | + ALPAKA_FN_HOST_ACC auto exp(Custom c) |
| 136 | + { |
| 137 | + return Custom::Exp | c; |
| 138 | + } |
| 139 | + |
| 140 | + ALPAKA_FN_HOST_ACC auto floor(Custom c); |
| 141 | + ALPAKA_FN_HOST_ACC auto floor(Custom c) |
| 142 | + { |
| 143 | + return Custom::Floor | c; |
| 144 | + } |
| 145 | + |
| 146 | + ALPAKA_FN_HOST_ACC auto fmod(Custom a, Custom b); |
| 147 | + ALPAKA_FN_HOST_ACC auto fmod(Custom a, Custom b) |
| 148 | + { |
| 149 | + return Custom::Fmod | a | b; |
| 150 | + } |
| 151 | + |
| 152 | + ALPAKA_FN_HOST_ACC auto log(Custom c); |
| 153 | + ALPAKA_FN_HOST_ACC auto log(Custom c) |
| 154 | + { |
| 155 | + return Custom::Log | c; |
| 156 | + } |
| 157 | + |
| 158 | + ALPAKA_FN_HOST_ACC auto max(Custom a, Custom b); |
| 159 | + ALPAKA_FN_HOST_ACC auto max(Custom a, Custom b) |
| 160 | + { |
| 161 | + return Custom::Max | a | b; |
| 162 | + } |
| 163 | + |
| 164 | + ALPAKA_FN_HOST_ACC auto min(Custom a, Custom b); |
| 165 | + ALPAKA_FN_HOST_ACC auto min(Custom a, Custom b) |
| 166 | + { |
| 167 | + return Custom::Min | a | b; |
| 168 | + } |
| 169 | + |
| 170 | + ALPAKA_FN_HOST_ACC auto pow(Custom a, Custom b); |
| 171 | + ALPAKA_FN_HOST_ACC auto pow(Custom a, Custom b) |
| 172 | + { |
| 173 | + return Custom::Pow | a | b; |
| 174 | + } |
| 175 | + |
| 176 | + ALPAKA_FN_HOST_ACC auto remainder(Custom a, Custom b); |
| 177 | + ALPAKA_FN_HOST_ACC auto remainder(Custom a, Custom b) |
| 178 | + { |
| 179 | + return Custom::Remainder | a | b; |
| 180 | + } |
| 181 | + |
| 182 | + ALPAKA_FN_HOST_ACC auto round(Custom c); |
| 183 | + ALPAKA_FN_HOST_ACC auto round(Custom c) |
| 184 | + { |
| 185 | + return Custom::Round | c; |
| 186 | + } |
| 187 | + |
| 188 | + ALPAKA_FN_HOST_ACC auto lround(Custom c); |
| 189 | + ALPAKA_FN_HOST_ACC auto lround(Custom c) |
| 190 | + { |
| 191 | + return Custom::Lround | c; |
| 192 | + } |
| 193 | + |
| 194 | + ALPAKA_FN_HOST_ACC auto llround(Custom c); |
| 195 | + ALPAKA_FN_HOST_ACC auto llround(Custom c) |
| 196 | + { |
| 197 | + return Custom::Llround | c; |
| 198 | + } |
| 199 | + |
| 200 | + ALPAKA_FN_HOST_ACC auto rsqrt(Custom c); |
| 201 | + ALPAKA_FN_HOST_ACC auto rsqrt(Custom c) |
| 202 | + { |
| 203 | + return Custom::Rsqrt | c; |
| 204 | + } |
| 205 | + |
| 206 | + ALPAKA_FN_HOST_ACC auto sin(Custom c); |
| 207 | + ALPAKA_FN_HOST_ACC auto sin(Custom c) |
| 208 | + { |
| 209 | + return Custom::Sin | c; |
| 210 | + } |
| 211 | + |
| 212 | + ALPAKA_FN_HOST_ACC void sincos(Custom c, Custom& a, Custom& b); |
| 213 | + ALPAKA_FN_HOST_ACC void sincos(Custom c, Custom& a, Custom& b) |
| 214 | + { |
| 215 | + a = static_cast<Custom>(Custom::Sincos | c | Custom::Arg2); |
| 216 | + b = static_cast<Custom>(Custom::Sincos | c | Custom::Arg3); |
| 217 | + } |
| 218 | + |
| 219 | + ALPAKA_FN_HOST_ACC auto sqrt(Custom c); |
| 220 | + ALPAKA_FN_HOST_ACC auto sqrt(Custom c) |
| 221 | + { |
| 222 | + return Custom::Sqrt | c; |
| 223 | + } |
| 224 | + |
| 225 | + ALPAKA_FN_HOST_ACC auto tan(Custom c); |
| 226 | + ALPAKA_FN_HOST_ACC auto tan(Custom c) |
| 227 | + { |
| 228 | + return Custom::Tan | c; |
| 229 | + } |
| 230 | + |
| 231 | + ALPAKA_FN_HOST_ACC auto trunc(Custom c); |
| 232 | + ALPAKA_FN_HOST_ACC auto trunc(Custom c) |
| 233 | + { |
| 234 | + return Custom::Trunc | c; |
| 235 | + } |
| 236 | +} // namespace custom |
| 237 | + |
| 238 | +struct AdlKernel |
| 239 | +{ |
| 240 | + template<typename Acc> |
| 241 | + ALPAKA_FN_ACC void operator()(Acc const& acc, bool* success) const noexcept |
| 242 | + { |
| 243 | + using custom::Custom; |
| 244 | + |
| 245 | + ALPAKA_CHECK(*success, alpaka::math::abs(acc, Custom::Arg1) == (Custom::Abs | Custom::Arg1)); |
| 246 | + ALPAKA_CHECK(*success, alpaka::math::acos(acc, Custom::Arg1) == (Custom::Acos | Custom::Arg1)); |
| 247 | + ALPAKA_CHECK(*success, alpaka::math::arg(acc, Custom::Arg1) == (Custom::Arg | Custom::Arg1)); |
| 248 | + ALPAKA_CHECK(*success, alpaka::math::asin(acc, Custom::Arg1) == (Custom::Asin | Custom::Arg1)); |
| 249 | + ALPAKA_CHECK(*success, alpaka::math::atan(acc, Custom::Arg1) == (Custom::Atan | Custom::Arg1)); |
| 250 | + ALPAKA_CHECK(*success, alpaka::math::cbrt(acc, Custom::Arg1) == (Custom::Cbrt | Custom::Arg1)); |
| 251 | + ALPAKA_CHECK(*success, alpaka::math::ceil(acc, Custom::Arg1) == (Custom::Ceil | Custom::Arg1)); |
| 252 | + ALPAKA_CHECK(*success, alpaka::math::conj(acc, Custom::Arg1) == (Custom::Conj | Custom::Arg1)); |
| 253 | + ALPAKA_CHECK(*success, alpaka::math::cos(acc, Custom::Arg1) == (Custom::Cos | Custom::Arg1)); |
| 254 | + ALPAKA_CHECK(*success, alpaka::math::erf(acc, Custom::Arg1) == (Custom::Erf | Custom::Arg1)); |
| 255 | + ALPAKA_CHECK(*success, alpaka::math::exp(acc, Custom::Arg1) == (Custom::Exp | Custom::Arg1)); |
| 256 | + ALPAKA_CHECK(*success, alpaka::math::floor(acc, Custom::Arg1) == (Custom::Floor | Custom::Arg1)); |
| 257 | + ALPAKA_CHECK(*success, alpaka::math::log(acc, Custom::Arg1) == (Custom::Log | Custom::Arg1)); |
| 258 | + ALPAKA_CHECK(*success, alpaka::math::round(acc, Custom::Arg1) == (Custom::Round | Custom::Arg1)); |
| 259 | + ALPAKA_CHECK(*success, alpaka::math::lround(acc, Custom::Arg1) == (Custom::Lround | Custom::Arg1)); |
| 260 | + ALPAKA_CHECK(*success, alpaka::math::llround(acc, Custom::Arg1) == (Custom::Llround | Custom::Arg1)); |
| 261 | + ALPAKA_CHECK(*success, alpaka::math::rsqrt(acc, Custom::Arg1) == (Custom::Rsqrt | Custom::Arg1)); |
| 262 | + ALPAKA_CHECK(*success, alpaka::math::sin(acc, Custom::Arg1) == (Custom::Sin | Custom::Arg1)); |
| 263 | + ALPAKA_CHECK(*success, alpaka::math::sqrt(acc, Custom::Arg1) == (Custom::Sqrt | Custom::Arg1)); |
| 264 | + ALPAKA_CHECK(*success, alpaka::math::tan(acc, Custom::Arg1) == (Custom::Tan | Custom::Arg1)); |
| 265 | + ALPAKA_CHECK(*success, alpaka::math::trunc(acc, Custom::Arg1) == (Custom::Trunc | Custom::Arg1)); |
| 266 | + |
| 267 | + ALPAKA_CHECK( |
| 268 | + *success, |
| 269 | + alpaka::math::atan2(acc, Custom::Arg1, Custom::Arg2) == (Custom::Atan2 | Custom::Arg1 | Custom::Arg2)); |
| 270 | + ALPAKA_CHECK( |
| 271 | + *success, |
| 272 | + alpaka::math::fmod(acc, Custom::Arg1, Custom::Arg2) == (Custom::Fmod | Custom::Arg1 | Custom::Arg2)); |
| 273 | + ALPAKA_CHECK( |
| 274 | + *success, |
| 275 | + alpaka::math::max(acc, Custom::Arg1, Custom::Arg2) == (Custom::Max | Custom::Arg1 | Custom::Arg2)); |
| 276 | + ALPAKA_CHECK( |
| 277 | + *success, |
| 278 | + alpaka::math::min(acc, Custom::Arg1, Custom::Arg2) == (Custom::Min | Custom::Arg1 | Custom::Arg2)); |
| 279 | + ALPAKA_CHECK( |
| 280 | + *success, |
| 281 | + alpaka::math::pow(acc, Custom::Arg1, Custom::Arg2) == (Custom::Pow | Custom::Arg1 | Custom::Arg2)); |
| 282 | + ALPAKA_CHECK( |
| 283 | + *success, |
| 284 | + alpaka::math::remainder(acc, Custom::Arg1, Custom::Arg2) |
| 285 | + == (Custom::Remainder | Custom::Arg1 | Custom::Arg2)); |
| 286 | + |
| 287 | + Custom a, b; |
| 288 | + alpaka::math::sincos(acc, Custom::Arg1, a, b); |
| 289 | + ALPAKA_CHECK(*success, a == (Custom::Sincos | Custom::Arg1 | Custom::Arg2)); |
| 290 | + ALPAKA_CHECK(*success, b == (Custom::Sincos | Custom::Arg1 | Custom::Arg3)); |
| 291 | + } |
| 292 | +}; |
| 293 | + |
| 294 | +TEMPLATE_LIST_TEST_CASE("mathOps", "[math] [operator] [adl]", TestAccs) |
| 295 | +{ |
| 296 | + using Acc = TestType; |
| 297 | + using Dim = alpaka::Dim<Acc>; |
| 298 | + using Idx = alpaka::Idx<Acc>; |
| 299 | + auto fixture = alpaka::test::KernelExecutionFixture<Acc>{alpaka::Vec<Dim, Idx>::ones()}; |
| 300 | + REQUIRE(fixture(AdlKernel{})); |
| 301 | +} |
0 commit comments