//@HEADER // ************************************************************************ // // Kokkos v. 4.0 // Copyright (2022) National Technology & Engineering // Solutions of Sandia, LLC (NTESS). // // Under the terms of Contract DE-NA0003525 with NTESS, // the U.S. Government retains certain rights in this software. // // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. // See https://kokkos.org/LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //@HEADER #ifndef KOKKOSBATCHED_VECTOR_SIMD_MATH_HPP #define KOKKOSBATCHED_VECTOR_SIMD_MATH_HPP /// \author Kyungjoo Kim (kyukim@sandia.gov) #include "Kokkos_Complex.hpp" namespace KokkosBatched { #define KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) Vector, l> #define KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) \ typename std::enable_if::value, Vector, l> >::type /// simd template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) sqrt(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::sqrt(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) cbrt(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::cbrt(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) log(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::log(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) log10(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::log10(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T, l) exp(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::exp(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T0, l) pow(const Vector, l> &a, const Vector, l> &b) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::pow(a[i], b[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T0, l) pow(const T0 &a, const Vector, l> &b) { return pow(Vector, l>(a), b); } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE(T0, l) pow(const Vector, l> &a, const T1 &b) { return pow(a, Vector, l>(b)); } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) sin(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::sin(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) cos(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::cos(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) tan(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::tan(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) sinh(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::sinh(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) cosh(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::cosh(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) tanh(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::tanh(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) asin(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::asin(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) acos(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::acos(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) atan(const Vector, l> &a) { typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = ats::atan(a[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) atan2(const Vector, l> &a, const Vector, l> &b) { // typedef Kokkos::ArithTraits ats; Vector, l> r_val; #if defined(KOKKOS_ENABLE_PRAGMA_IVDEP) #pragma ivdep #endif #if defined(KOKKOS_ENABLE_PRAGMA_VECTOR) #pragma vector always #endif for (int i = 0; i < l; ++i) r_val[i] = std::atan2(a[i], b[i]); return r_val; } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) atan2(const T &a, const Vector, l> &b) { return atan2(Vector, l>(a), b); } template KOKKOS_INLINE_FUNCTION static KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE(T, l) atan2(const Vector, l> &a, const T &b) { return atan2(a, Vector, l>(b)); } #undef KOKKOSKERNELS_SIMD_MATH_RETURN_TYPE #undef KOKKOSKERNELS_SIMD_MATH_RETURN_FLOAT_TYPE } // namespace KokkosBatched #endif