//@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_HPP #define KOKKOSBATCHED_VECTOR_HPP /// \author Kyungjoo Kim (kyukim@sandia.gov) #include "KokkosBatched_Util.hpp" // forward declaration namespace KokkosBatched { template class Vector; template struct is_vector, l>> : public std::true_type {}; template struct DefaultVectorLength { enum : int { value = 1 }; }; template <> struct DefaultVectorLength { #if defined(__AVX512F__) enum : int{value = 16}; #elif defined(__AVX__) || defined(__AVX2__) enum : int{value = 8}; #elif defined(__ARM_ARCH) enum : int{value = 8}; #else enum : int { value = 8 }; #endif }; template <> struct DefaultVectorLength { #if defined(__AVX512F__) enum : int{value = 8}; #elif defined(__AVX__) || defined(__AVX2__) enum : int{value = 4}; #elif defined(__ARM_ARCH) enum : int{value = 4}; #else enum : int { value = 4 }; #endif }; template <> struct DefaultVectorLength, Kokkos::HostSpace> { #if defined(__AVX512F__) enum : int{value = 8}; #elif defined(__AVX__) || defined(__AVX2__) enum : int{value = 4}; #elif defined(__ARM_ARCH) enum : int{value = 4}; #else enum : int { value = 4 }; #endif }; template <> struct DefaultVectorLength, Kokkos::HostSpace> { #if defined(__AVX512F__) enum : int{value = 4}; #elif defined(__AVX__) || defined(__AVX2__) enum : int{value = 2}; #elif defined(__ARM_ARCH) enum : int{value = 2}; #else enum : int { value = 2 }; #endif }; #if defined(KOKKOS_ENABLE_CUDA) template <> struct DefaultVectorLength { enum : int { value = 8 }; }; template <> struct DefaultVectorLength { enum : int { value = 8 }; }; template <> struct DefaultVectorLength, Kokkos::CudaSpace> { enum : int { value = 8 }; }; template <> struct DefaultVectorLength, Kokkos::CudaSpace> { enum : int { value = 8 }; }; template <> struct DefaultVectorLength { enum : int { value = 8 }; }; template <> struct DefaultVectorLength { enum : int { value = 8 }; }; template <> struct DefaultVectorLength, Kokkos::CudaUVMSpace> { enum : int { value = 8 }; }; template <> struct DefaultVectorLength, Kokkos::CudaUVMSpace> { enum : int { value = 8 }; }; #endif #if defined(KOKKOS_ENABLE_HIP) template <> struct DefaultVectorLength { enum : int { value = 16 }; }; template <> struct DefaultVectorLength { enum : int { value = 16 }; }; template <> struct DefaultVectorLength, Kokkos::HIPSpace> { enum : int { value = 16 }; }; template <> struct DefaultVectorLength, Kokkos::HIPSpace> { enum : int { value = 16 }; }; #endif template struct DefaultInternalVectorLength { enum : int { value = 1 }; }; template struct DefaultInternalVectorLength { enum : int { value = DefaultVectorLength::value }; }; #if defined(KOKKOS_ENABLE_CUDA) template <> struct DefaultInternalVectorLength { enum : int { value = 4 }; }; template <> struct DefaultInternalVectorLength { enum : int { value = 2 }; }; template <> struct DefaultInternalVectorLength, Kokkos::CudaSpace> { enum : int { value = 2 }; }; template <> struct DefaultInternalVectorLength, Kokkos::CudaSpace> { enum : int { value = 1 }; }; template <> struct DefaultInternalVectorLength { enum : int { value = 4 }; }; template <> struct DefaultInternalVectorLength { enum : int { value = 2 }; }; template <> struct DefaultInternalVectorLength, Kokkos::CudaUVMSpace> { enum : int { value = 2 }; }; template <> struct DefaultInternalVectorLength, Kokkos::CudaUVMSpace> { enum : int { value = 1 }; }; #endif #if defined(KOKKOS_ENABLE_HIP) template <> struct DefaultInternalVectorLength { enum : int { value = 8 }; }; template <> struct DefaultInternalVectorLength { enum : int { value = 4 }; }; template <> struct DefaultInternalVectorLength, Kokkos::HIPSpace> { enum : int { value = 4 }; }; template <> struct DefaultInternalVectorLength, Kokkos::HIPSpace> { enum : int { value = 2 }; }; #endif template struct MagnitudeScalarType; template <> struct MagnitudeScalarType { typedef float type; }; template <> struct MagnitudeScalarType { typedef double type; }; template <> struct MagnitudeScalarType> { typedef float type; }; template <> struct MagnitudeScalarType> { typedef double type; }; template struct MagnitudeScalarType, l>> { typedef float type; }; template struct MagnitudeScalarType, l>> { typedef double type; }; template struct MagnitudeScalarType>, l>> { typedef float type; }; template struct MagnitudeScalarType>, l>> { typedef double type; }; } // namespace KokkosBatched #include "KokkosBatched_Vector_SIMD.hpp" // arith traits overload for vector types namespace Kokkos { // do not use Vector alone as other can use the name. template class ArithTraits, l>> { public: typedef typename ArithTraits::val_type val_scalar_type; typedef typename ArithTraits::mag_type mag_scalar_type; typedef KokkosBatched::Vector, l> val_type; typedef KokkosBatched::Vector, l> mag_type; static KOKKOS_FORCEINLINE_FUNCTION mag_type real(const val_type &val) { return val; } static KOKKOS_FORCEINLINE_FUNCTION val_type conj(const val_type &val) { return val; } static KOKKOS_FORCEINLINE_FUNCTION val_type abs(const val_type &val) { using KAT = ArithTraits; val_type v{}; for (int i = 0; i < l; ++i) { v[i] = KAT::abs(val[i]); } return v; } static const bool is_specialized = ArithTraits::is_specialized; static const bool is_signed = ArithTraits::is_signed; static const bool is_integer = ArithTraits::is_integer; static const bool is_exact = ArithTraits::is_exact; static const bool is_complex = ArithTraits::is_complex; }; template class ArithTraits>, l>> { public: typedef typename ArithTraits::val_type val_scalar_type; typedef typename ArithTraits::mag_type mag_scalar_type; typedef KokkosBatched::Vector>, l> val_type; typedef KokkosBatched::Vector, l> mag_type; static KOKKOS_FORCEINLINE_FUNCTION mag_type real(const val_type &val) { mag_type r_val; for (int i = 0; i < l; ++i) { r_val[i] = val[i].real(); } return r_val; } static KOKKOS_FORCEINLINE_FUNCTION mag_type imag(const val_type &val) { mag_type r_val; for (int i = 0; i < l; ++i) { r_val[i] = val[i].imag(); } return r_val; } static KOKKOS_FORCEINLINE_FUNCTION val_type conj(const val_type &val) { using KAT = ArithTraits; val_type v{}; for (int i = 0; i < l; ++i) { v[i] = KAT::conj(val[i]); } return v; } static KOKKOS_FORCEINLINE_FUNCTION val_type abs(const val_type &val) { using KAT = ArithTraits; val_type v{}; for (int i = 0; i < l; ++i) { v[i] = KAT::abs(val[i]); } return v; } }; } // namespace Kokkos #endif