| 1 |
//@HEADER |
| 2 |
// ************************************************************************ |
| 3 |
// |
| 4 |
// Kokkos v. 4.0 |
| 5 |
// Copyright (2022) National Technology & Engineering |
| 6 |
// Solutions of Sandia, LLC (NTESS). |
| 7 |
// |
| 8 |
// Under the terms of Contract DE-NA0003525 with NTESS, |
| 9 |
// the U.S. Government retains certain rights in this software. |
| 10 |
// |
| 11 |
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. |
| 12 |
// See https://kokkos.org/LICENSE for license information. |
| 13 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 14 |
// |
| 15 |
//@HEADER |
| 16 |
#ifndef KOKKOSBATCHED_VECTOR_SIMD_MATH_HPP |
| 17 |
#define KOKKOSBATCHED_VECTOR_SIMD_MATH_HPP |
| 18 |
|
| 19 |
/// \author Kyungjoo Kim ([email protected]) |
| 20 |
|
| 21 |
#include "Kokkos_Complex.hpp" |
| 22 |
|
| 23 |
namespace KokkosBatched { |
| 24 |
|
| 25 |
#define KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) Vector<SIMD<T>, l> |
| 26 |
#define KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) \ |
| 27 |
typename std::enable_if<!std::is_integral<T>::value, Vector<SIMD<T>, l> >::type |
| 28 |
|
| 29 |
/// simd |
| 30 |
|
| 31 |
template <typename T, int l> |
| 32 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) sqrt(const Vector<SIMD<T>, l> &a) { |
| 33 |
typedef Kokkos::ArithTraits<T> ats; |
| 34 |
Vector<SIMD<T>, l> r_val; |
| 35 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 36 |
#pragma ivdep |
| 37 |
#endif |
| 38 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 39 |
#pragma vector always |
| 40 |
#endif |
| 41 |
for (int i = 0; i < l; ++i) r_val[i] = ats::sqrt(a[i]); |
| 42 |
|
| 43 |
return r_val; |
| 44 |
} |
| 45 |
|
| 46 |
template <typename T, int l> |
| 47 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) cbrt(const Vector<SIMD<T>, l> &a) { |
| 48 |
typedef Kokkos::ArithTraits<T> ats; |
| 49 |
Vector<SIMD<T>, l> r_val; |
| 50 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 51 |
#pragma ivdep |
| 52 |
#endif |
| 53 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 54 |
#pragma vector always |
| 55 |
#endif |
| 56 |
for (int i = 0; i < l; ++i) r_val[i] = ats::cbrt(a[i]); |
| 57 |
|
| 58 |
return r_val; |
| 59 |
} |
| 60 |
|
| 61 |
template <typename T, int l> |
| 62 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) log(const Vector<SIMD<T>, l> &a) { |
| 63 |
typedef Kokkos::ArithTraits<T> ats; |
| 64 |
Vector<SIMD<T>, l> r_val; |
| 65 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 66 |
#pragma ivdep |
| 67 |
#endif |
| 68 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 69 |
#pragma vector always |
| 70 |
#endif |
| 71 |
for (int i = 0; i < l; ++i) r_val[i] = ats::log(a[i]); |
| 72 |
|
| 73 |
return r_val; |
| 74 |
} |
| 75 |
|
| 76 |
template <typename T, int l> |
| 77 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) log10(const Vector<SIMD<T>, l> &a) { |
| 78 |
typedef Kokkos::ArithTraits<T> ats; |
| 79 |
Vector<SIMD<T>, l> r_val; |
| 80 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 81 |
#pragma ivdep |
| 82 |
#endif |
| 83 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 84 |
#pragma vector always |
| 85 |
#endif |
| 86 |
for (int i = 0; i < l; ++i) r_val[i] = ats::log10(a[i]); |
| 87 |
|
| 88 |
return r_val; |
| 89 |
} |
| 90 |
|
| 91 |
template <typename T, int l> |
| 92 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) exp(const Vector<SIMD<T>, l> &a) { |
| 93 |
typedef Kokkos::ArithTraits<T> ats; |
| 94 |
Vector<SIMD<T>, l> r_val; |
| 95 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 96 |
#pragma ivdep |
| 97 |
#endif |
| 98 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 99 |
#pragma vector always |
| 100 |
#endif |
| 101 |
for (int i = 0; i < l; ++i) r_val[i] = ats::exp(a[i]); |
| 102 |
|
| 103 |
return r_val; |
| 104 |
} |
| 105 |
|
| 106 |
template <typename T0, typename T1, int l> |
| 107 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T0, l) |
| 108 |
pow(const Vector<SIMD<T0>, l> &a, const Vector<SIMD<T1>, l> &b) { |
| 109 |
typedef Kokkos::ArithTraits<T0> ats; |
| 110 |
Vector<SIMD<T0>, l> r_val; |
| 111 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 112 |
#pragma ivdep |
| 113 |
#endif |
| 114 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 115 |
#pragma vector always |
| 116 |
#endif |
| 117 |
for (int i = 0; i < l; ++i) r_val[i] = ats::pow(a[i], b[i]); |
| 118 |
|
| 119 |
return r_val; |
| 120 |
} |
| 121 |
|
| 122 |
template <typename T0, typename T1, int l> |
| 123 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T0, l) |
| 124 |
pow(const T0 &a, const Vector<SIMD<T1>, l> &b) { |
| 125 |
return pow(Vector<SIMD<T0>, l>(a), b); |
| 126 |
} |
| 127 |
|
| 128 |
template <typename T0, typename T1, int l> |
| 129 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T0, l) |
| 130 |
pow(const Vector<SIMD<T0>, l> &a, const T1 &b) { |
| 131 |
return pow(a, Vector<SIMD<T1>, l>(b)); |
| 132 |
} |
| 133 |
|
| 134 |
template <typename T, int l> |
| 135 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) sin(const Vector<SIMD<T>, l> &a) { |
| 136 |
typedef Kokkos::ArithTraits<T> ats; |
| 137 |
Vector<SIMD<T>, l> r_val; |
| 138 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 139 |
#pragma ivdep |
| 140 |
#endif |
| 141 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 142 |
#pragma vector always |
| 143 |
#endif |
| 144 |
for (int i = 0; i < l; ++i) r_val[i] = ats::sin(a[i]); |
| 145 |
|
| 146 |
return r_val; |
| 147 |
} |
| 148 |
|
| 149 |
template <typename T, int l> |
| 150 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) cos(const Vector<SIMD<T>, l> &a) { |
| 151 |
typedef Kokkos::ArithTraits<T> ats; |
| 152 |
Vector<SIMD<T>, l> r_val; |
| 153 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 154 |
#pragma ivdep |
| 155 |
#endif |
| 156 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 157 |
#pragma vector always |
| 158 |
#endif |
| 159 |
for (int i = 0; i < l; ++i) r_val[i] = ats::cos(a[i]); |
| 160 |
|
| 161 |
return r_val; |
| 162 |
} |
| 163 |
|
| 164 |
template <typename T, int l> |
| 165 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) tan(const Vector<SIMD<T>, l> &a) { |
| 166 |
typedef Kokkos::ArithTraits<T> ats; |
| 167 |
Vector<SIMD<T>, l> r_val; |
| 168 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 169 |
#pragma ivdep |
| 170 |
#endif |
| 171 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 172 |
#pragma vector always |
| 173 |
#endif |
| 174 |
for (int i = 0; i < l; ++i) r_val[i] = ats::tan(a[i]); |
| 175 |
|
| 176 |
return r_val; |
| 177 |
} |
| 178 |
|
| 179 |
template <typename T, int l> |
| 180 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) sinh(const Vector<SIMD<T>, l> &a) { |
| 181 |
typedef Kokkos::ArithTraits<T> ats; |
| 182 |
Vector<SIMD<T>, l> r_val; |
| 183 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 184 |
#pragma ivdep |
| 185 |
#endif |
| 186 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 187 |
#pragma vector always |
| 188 |
#endif |
| 189 |
for (int i = 0; i < l; ++i) r_val[i] = ats::sinh(a[i]); |
| 190 |
|
| 191 |
return r_val; |
| 192 |
} |
| 193 |
|
| 194 |
template <typename T, int l> |
| 195 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) cosh(const Vector<SIMD<T>, l> &a) { |
| 196 |
typedef Kokkos::ArithTraits<T> ats; |
| 197 |
Vector<SIMD<T>, l> r_val; |
| 198 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 199 |
#pragma ivdep |
| 200 |
#endif |
| 201 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 202 |
#pragma vector always |
| 203 |
#endif |
| 204 |
for (int i = 0; i < l; ++i) r_val[i] = ats::cosh(a[i]); |
| 205 |
|
| 206 |
return r_val; |
| 207 |
} |
| 208 |
|
| 209 |
template <typename T, int l> |
| 210 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) tanh(const Vector<SIMD<T>, l> &a) { |
| 211 |
typedef Kokkos::ArithTraits<T> ats; |
| 212 |
Vector<SIMD<T>, l> r_val; |
| 213 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 214 |
#pragma ivdep |
| 215 |
#endif |
| 216 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 217 |
#pragma vector always |
| 218 |
#endif |
| 219 |
for (int i = 0; i < l; ++i) r_val[i] = ats::tanh(a[i]); |
| 220 |
|
| 221 |
return r_val; |
| 222 |
} |
| 223 |
|
| 224 |
template <typename T, int l> |
| 225 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) asin(const Vector<SIMD<T>, l> &a) { |
| 226 |
typedef Kokkos::ArithTraits<T> ats; |
| 227 |
Vector<SIMD<T>, l> r_val; |
| 228 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 229 |
#pragma ivdep |
| 230 |
#endif |
| 231 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 232 |
#pragma vector always |
| 233 |
#endif |
| 234 |
for (int i = 0; i < l; ++i) r_val[i] = ats::asin(a[i]); |
| 235 |
|
| 236 |
return r_val; |
| 237 |
} |
| 238 |
|
| 239 |
template <typename T, int l> |
| 240 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) acos(const Vector<SIMD<T>, l> &a) { |
| 241 |
typedef Kokkos::ArithTraits<T> ats; |
| 242 |
Vector<SIMD<T>, l> r_val; |
| 243 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 244 |
#pragma ivdep |
| 245 |
#endif |
| 246 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 247 |
#pragma vector always |
| 248 |
#endif |
| 249 |
for (int i = 0; i < l; ++i) r_val[i] = ats::acos(a[i]); |
| 250 |
|
| 251 |
return r_val; |
| 252 |
} |
| 253 |
|
| 254 |
template <typename T, int l> |
| 255 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) atan(const Vector<SIMD<T>, l> &a) { |
| 256 |
typedef Kokkos::ArithTraits<T> ats; |
| 257 |
Vector<SIMD<T>, l> r_val; |
| 258 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 259 |
#pragma ivdep |
| 260 |
#endif |
| 261 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 262 |
#pragma vector always |
| 263 |
#endif |
| 264 |
for (int i = 0; i < l; ++i) r_val[i] = ats::atan(a[i]); |
| 265 |
|
| 266 |
return r_val; |
| 267 |
} |
| 268 |
|
| 269 |
template <typename T, int l> |
| 270 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) |
| 271 |
atan2(const Vector<SIMD<T>, l> &a, const Vector<SIMD<T>, l> &b) { |
| 272 |
// typedef Kokkos::ArithTraits<T> ats; |
| 273 |
Vector<SIMD<T>, l> r_val; |
| 274 |
#if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) |
| 275 |
#pragma ivdep |
| 276 |
#endif |
| 277 |
#if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) |
| 278 |
#pragma vector always |
| 279 |
#endif |
| 280 |
for (int i = 0; i < l; ++i) r_val[i] = std::atan2(a[i], b[i]); |
| 281 |
|
| 282 |
return r_val; |
| 283 |
} |
| 284 |
|
| 285 |
template <typename T, int l> |
| 286 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) |
| 287 |
atan2(const T &a, const Vector<SIMD<T>, l> &b) { |
| 288 |
return atan2(Vector<SIMD<T>, l>(a), b); |
| 289 |
} |
| 290 |
|
| 291 |
template <typename T, int l> |
| 292 |
KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) |
| 293 |
atan2(const Vector<SIMD<T>, l> &a, const T &b) { |
| 294 |
return atan2(a, Vector<SIMD<T>, l>(b)); |
| 295 |
} |
| 296 |
|
| 297 |
#undef KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE |
| 298 |
#undef KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE |
| 299 |
} // namespace KokkosBatched |
| 300 |
|
| 301 |
#endif |