#pragma once #if defined(__aarch64__) #include #elif defined(CPU_CAPABILITY_AVX512) #include #else #include #include #endif namespace at::vec { // See Note [CPU_CAPABILITY namespace] inline namespace CPU_CAPABILITY { inline std::ostream& operator<<(std::ostream& stream, const c10::qint32& val) { stream << val.val_; return stream; } inline std::ostream& operator<<(std::ostream& stream, const c10::qint8& val) { stream << static_cast(val.val_); return stream; } inline std::ostream& operator<<(std::ostream& stream, const c10::quint8& val) { stream << static_cast(val.val_); return stream; } template std::ostream& operator<<(std::ostream& stream, const Vectorized& vec) { T buf[Vectorized::size()]; vec.store(buf); stream << "vec["; for (int i = 0; i != Vectorized::size(); i++) { if (i != 0) { stream << ", "; } stream << buf[i]; } stream << "]"; return stream; } inline Vectorized convert_to_bool(Vectorized x) { __at_align__ bool buffer[x.size()]; x.ne(Vectorized(0)).store(buffer); Vectorized ret; static_assert(x.size() == ret.size()); std::memcpy(ret, buffer, ret.size() * sizeof(bool)); return ret; } template <> inline Vectorized Vectorized::loadu(const void* ptr) { // See NOTE [Loading boolean values] return convert_to_bool(Vectorized::loadu(ptr)); } template <> inline Vectorized Vectorized::loadu( const void* ptr, int64_t count) { // See NOTE [Loading boolean values] return convert_to_bool(Vectorized::loadu(ptr, count)); } template struct VecHoldType { using hold_type = typename VT::value_type; }; template <> struct VecHoldType> { using hold_type = BFloat16; }; template <> struct VecHoldType> { using hold_type = Half; }; template using vechold_type = typename VecHoldType::hold_type; } // namespace CPU_CAPABILITY } // namespace at::vec