Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/missing_vst1_neon.h +8 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vec256.h +289 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vec256_complex_float.h +468 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vec256_float.h +565 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vec256_float_neon.h +879 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_common_vsx.h +246 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_complex_float_vsx.h +628 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_float_vsx.h +449 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_int16_vsx.h +368 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_int32_vsx.h +298 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_int64_vsx.h +251 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_qint32_vsx.h +245 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_quint8_vsx.h +407 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/zarch/vec256_zarch.h +2797 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec512/vec512.h +263 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec512/vec512_int.h +1448 -0
- vllm/lib/python3.10/site-packages/wandb/integration/keras/__init__.py +11 -0
- vllm/lib/python3.10/site-packages/wandb/integration/keras/callbacks/model_checkpoint.py +188 -0
- vllm/lib/python3.10/site-packages/wandb/integration/sacred/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/integration/sagemaker/config.py +58 -0
- vllm/lib/python3.10/site-packages/wandb/integration/sb3/__init__.py +3 -0
- vllm/lib/python3.10/site-packages/wandb/integration/sb3/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/integration/sb3/__pycache__/sb3.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/integration/sb3/sb3.py +147 -0
- vllm/lib/python3.10/site-packages/wandb/integration/yolov8/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/integration/yolov8/yolov8.py +284 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/__init__.py +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/ast.py +1349 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/lexer.py +435 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/location.py +30 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/source.py +18 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor_meta.py +82 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__init__.py +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/assert_valid_name.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/ast_from_value.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/ast_to_code.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/ast_to_dict.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/base.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/build_ast_schema.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/build_client_schema.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/concat_ast.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/extend_schema.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/get_field_def.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/get_operation_ast.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/introspection_query.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/is_valid_literal_value.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/is_valid_value.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/quoted_or_list.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/schema_printer.cpython-310.pyc +0 -0
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/missing_vst1_neon.h
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Workaround for missing vst1q_f32_x2 in gcc-8. */
|
| 2 |
+
|
| 3 |
+
__extension__ extern __inline void
|
| 4 |
+
__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
|
| 5 |
+
vst1q_f32_x2 (float32_t * __a, float32x4x2_t val)
|
| 6 |
+
{
|
| 7 |
+
asm volatile("st1 {%S1.4s - %T1.4s}, %0" : "=Q" (*__a) : "w" (val));
|
| 8 |
+
}
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vec256.h
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// DO NOT DEFINE STATIC DATA IN THIS HEADER!
|
| 4 |
+
// See Note [Do not compile initializers with AVX]
|
| 5 |
+
|
| 6 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 7 |
+
|
| 8 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 9 |
+
#if !(defined(__VSX__) || defined(CPU_CAPABILITY_VSX) || defined(CPU_CAPABILITY_ZVECTOR))
|
| 10 |
+
#include <ATen/cpu/vec/vec256/vec256_float.h>
|
| 11 |
+
#include <ATen/cpu/vec/vec256/vec256_float_neon.h>
|
| 12 |
+
#include <ATen/cpu/vec/vec256/vec256_bfloat16.h>
|
| 13 |
+
#include <ATen/cpu/vec/vec256/vec256_double.h>
|
| 14 |
+
#include <ATen/cpu/vec/vec256/vec256_int.h>
|
| 15 |
+
#include <ATen/cpu/vec/vec256/vec256_qint.h>
|
| 16 |
+
#include <ATen/cpu/vec/vec256/vec256_complex_float.h>
|
| 17 |
+
#include <ATen/cpu/vec/vec256/vec256_complex_double.h>
|
| 18 |
+
#elif defined(__VSX__) || defined(CPU_CAPABILITY_VSX)
|
| 19 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_common_vsx.h>
|
| 20 |
+
#else
|
| 21 |
+
#include <ATen/cpu/vec/vec256/zarch/vec256_zarch.h>
|
| 22 |
+
#include <ATen/cpu/vec/vec256/vec256_bfloat16.h>
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
#include <algorithm>
|
| 26 |
+
#include <cstddef>
|
| 27 |
+
#include <cstdint>
|
| 28 |
+
#include <cstring>
|
| 29 |
+
#include <ostream>
|
| 30 |
+
|
| 31 |
+
namespace at::vec {
|
| 32 |
+
|
| 33 |
+
// Note [CPU_CAPABILITY namespace]
|
| 34 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 35 |
+
// This header, and all of its subheaders, will be compiled with
|
| 36 |
+
// different architecture flags for each supported set of vector
|
| 37 |
+
// intrinsics. So we need to make sure they aren't inadvertently
|
| 38 |
+
// linked together. We do this by declaring objects in an `inline
|
| 39 |
+
// namespace` which changes the name mangling, but can still be
|
| 40 |
+
// accessed as `at::vec`.
|
| 41 |
+
inline namespace CPU_CAPABILITY {
|
| 42 |
+
|
| 43 |
+
inline std::ostream& operator<<(std::ostream& stream, const c10::qint32& val) {
|
| 44 |
+
stream << val.val_;
|
| 45 |
+
return stream;
|
| 46 |
+
}
|
| 47 |
+
inline std::ostream& operator<<(std::ostream& stream, const c10::qint8& val) {
|
| 48 |
+
stream << static_cast<int>(val.val_);
|
| 49 |
+
return stream;
|
| 50 |
+
}
|
| 51 |
+
inline std::ostream& operator<<(std::ostream& stream, const c10::quint8& val) {
|
| 52 |
+
stream << static_cast<unsigned int>(val.val_);
|
| 53 |
+
return stream;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
template <typename T>
|
| 57 |
+
std::ostream& operator<<(std::ostream& stream, const Vectorized<T>& vec) {
|
| 58 |
+
T buf[Vectorized<T>::size()];
|
| 59 |
+
vec.store(buf);
|
| 60 |
+
stream << "vec[";
|
| 61 |
+
for (int i = 0; i != Vectorized<T>::size(); i++) {
|
| 62 |
+
if (i != 0) {
|
| 63 |
+
stream << ", ";
|
| 64 |
+
}
|
| 65 |
+
stream << buf[i];
|
| 66 |
+
}
|
| 67 |
+
stream << "]";
|
| 68 |
+
return stream;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
#if defined(CPU_CAPABILITY_AVX2) && !defined(_MSC_VER)
|
| 73 |
+
|
| 74 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CAST (AVX2) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 75 |
+
|
| 76 |
+
template<>
|
| 77 |
+
inline Vectorized<float> cast<float, double>(const Vectorized<double>& src) {
|
| 78 |
+
return _mm256_castpd_ps(src);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
template<>
|
| 82 |
+
inline Vectorized<double> cast<double, float>(const Vectorized<float>& src) {
|
| 83 |
+
return _mm256_castps_pd(src);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
template<>
|
| 87 |
+
inline Vectorized<float> cast<float, int32_t>(const Vectorized<int32_t>& src) {
|
| 88 |
+
return _mm256_castsi256_ps(src);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
template<>
|
| 92 |
+
inline Vectorized<double> cast<double, int64_t>(const Vectorized<int64_t>& src) {
|
| 93 |
+
return _mm256_castsi256_pd(src);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GATHER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 97 |
+
|
| 98 |
+
template<int64_t scale = 1>
|
| 99 |
+
std::enable_if_t<scale == 1 || scale == 2 || scale == 4 || scale == 8, Vectorized<double>>
|
| 100 |
+
inline gather(const double* base_addr, const Vectorized<int64_t>& vindex) {
|
| 101 |
+
return _mm256_i64gather_pd(base_addr, vindex, scale);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
template<int64_t scale = 1>
|
| 105 |
+
std::enable_if_t<scale == 1 || scale == 2 || scale == 4 || scale == 8, Vectorized<float>>
|
| 106 |
+
inline gather(const float* base_addr, const Vectorized<int32_t>& vindex) {
|
| 107 |
+
return _mm256_i32gather_ps(base_addr, vindex, scale);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MASK GATHER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 111 |
+
|
| 112 |
+
template<int64_t scale = 1>
|
| 113 |
+
std::enable_if_t<scale == 1 || scale == 2 || scale == 4 || scale == 8, Vectorized<double>>
|
| 114 |
+
inline mask_gather(const Vectorized<double>& src, const double* base_addr,
|
| 115 |
+
const Vectorized<int64_t>& vindex, Vectorized<double>& mask) {
|
| 116 |
+
return _mm256_mask_i64gather_pd(src, base_addr, vindex, mask, scale);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
template<int64_t scale = 1>
|
| 120 |
+
std::enable_if_t<scale == 1 || scale == 2 || scale == 4 || scale == 8, Vectorized<float>>
|
| 121 |
+
inline mask_gather(const Vectorized<float>& src, const float* base_addr,
|
| 122 |
+
const Vectorized<int32_t>& vindex, Vectorized<float>& mask) {
|
| 123 |
+
return _mm256_mask_i32gather_ps(src, base_addr, vindex, mask, scale);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONVERT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 127 |
+
|
| 128 |
+
// Only works for inputs in the range: [-2^51, 2^51]
|
| 129 |
+
// From: https://stackoverflow.com/a/41148578
|
| 130 |
+
template<>
|
| 131 |
+
Vectorized<int64_t>
|
| 132 |
+
inline convert_to_int_of_same_size<double>(const Vectorized<double> &src) {
|
| 133 |
+
auto x = _mm256_add_pd(src, _mm256_set1_pd(0x0018000000000000));
|
| 134 |
+
return _mm256_sub_epi64(
|
| 135 |
+
_mm256_castpd_si256(x),
|
| 136 |
+
_mm256_castpd_si256(_mm256_set1_pd(0x0018000000000000))
|
| 137 |
+
);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
template<>
|
| 141 |
+
Vectorized<int32_t>
|
| 142 |
+
inline convert_to_int_of_same_size<float>(const Vectorized<float> &src) {
|
| 143 |
+
return _mm256_cvttps_epi32(src);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTERLEAVE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 147 |
+
|
| 148 |
+
template <>
|
| 149 |
+
std::pair<Vectorized<double>, Vectorized<double>>
|
| 150 |
+
inline interleave2<double>(const Vectorized<double>& a, const Vectorized<double>& b) {
|
| 151 |
+
// inputs:
|
| 152 |
+
// a = {a0, a1, a3, a3}
|
| 153 |
+
// b = {b0, b1, b2, b3}
|
| 154 |
+
|
| 155 |
+
// swap lanes:
|
| 156 |
+
// a_swapped = {a0, a1, b0, b1}
|
| 157 |
+
// b_swapped = {a2, a3, b2, b3}
|
| 158 |
+
auto a_swapped = _mm256_permute2f128_pd(a, b, 0b0100000); // 0, 2. 4 bits apart
|
| 159 |
+
auto b_swapped = _mm256_permute2f128_pd(a, b, 0b0110001); // 1, 3. 4 bits apart
|
| 160 |
+
|
| 161 |
+
// group cols crossing lanes:
|
| 162 |
+
// return {a0, b0, a1, b1}
|
| 163 |
+
// {a2, b2, a3, b3}
|
| 164 |
+
return std::make_pair(_mm256_permute4x64_pd(a_swapped, 0b11011000), // 0, 2, 1, 3
|
| 165 |
+
_mm256_permute4x64_pd(b_swapped, 0b11011000)); // 0, 2, 1, 3
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
template <>
|
| 169 |
+
std::pair<Vectorized<float>, Vectorized<float>>
|
| 170 |
+
inline interleave2<float>(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 171 |
+
// inputs:
|
| 172 |
+
// a = {a0, a1, a2, a3, a4, a5, a6, a7}
|
| 173 |
+
// b = {b0, b1, b2, b3, b4, b5, b6, b7}
|
| 174 |
+
|
| 175 |
+
// swap lanes:
|
| 176 |
+
// a_swapped = {a0, a1, a2, a3, b0, b1, b2, b3}
|
| 177 |
+
// b_swapped = {a4, a5, a6, a7, b4, b5, b6, b7}
|
| 178 |
+
// TODO: can we support caching this?
|
| 179 |
+
auto a_swapped = _mm256_permute2f128_ps(a, b, 0b0100000); // 0, 2. 4 bits apart
|
| 180 |
+
auto b_swapped = _mm256_permute2f128_ps(a, b, 0b0110001); // 1, 3. 4 bits apart
|
| 181 |
+
|
| 182 |
+
// group cols crossing lanes:
|
| 183 |
+
// return {a0, b0, a1, b1, a2, b2, a3, b3}
|
| 184 |
+
// {a4, b4, a5, b5, a6, b6, a7, b7}
|
| 185 |
+
const __m256i group_ctrl = _mm256_setr_epi32(0, 4, 1, 5, 2, 6, 3, 7);
|
| 186 |
+
return std::make_pair(_mm256_permutevar8x32_ps(a_swapped, group_ctrl),
|
| 187 |
+
_mm256_permutevar8x32_ps(b_swapped, group_ctrl));
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DEINTERLEAVE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 191 |
+
|
| 192 |
+
template <>
|
| 193 |
+
std::pair<Vectorized<double>, Vectorized<double>>
|
| 194 |
+
inline deinterleave2<double>(const Vectorized<double>& a, const Vectorized<double>& b) {
|
| 195 |
+
// inputs:
|
| 196 |
+
// a = {a0, b0, a1, b1}
|
| 197 |
+
// b = {a2, b2, a3, b3}
|
| 198 |
+
|
| 199 |
+
// group cols crossing lanes:
|
| 200 |
+
// a_grouped = {a0, a1, b0, b1}
|
| 201 |
+
// b_grouped = {a2, a3, b2, b3}
|
| 202 |
+
auto a_grouped = _mm256_permute4x64_pd(a, 0b11011000); // 0, 2, 1, 3
|
| 203 |
+
auto b_grouped = _mm256_permute4x64_pd(b, 0b11011000); // 0, 2, 1, 3
|
| 204 |
+
|
| 205 |
+
// swap lanes:
|
| 206 |
+
// return {a0, a1, a2, a3}
|
| 207 |
+
// {b0, b1, b2, b3}
|
| 208 |
+
return std::make_pair(_mm256_permute2f128_pd(a_grouped, b_grouped, 0b0100000), // 0, 2. 4 bits apart
|
| 209 |
+
_mm256_permute2f128_pd(a_grouped, b_grouped, 0b0110001)); // 1, 3. 4 bits apart
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
template <>
|
| 213 |
+
std::pair<Vectorized<float>, Vectorized<float>>
|
| 214 |
+
inline deinterleave2<float>(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 215 |
+
// inputs:
|
| 216 |
+
// a = {a0, b0, a1, b1, a2, b2, a3, b3}
|
| 217 |
+
// b = {a4, b4, a5, b5, a6, b6, a7, b7}
|
| 218 |
+
|
| 219 |
+
// group cols crossing lanes:
|
| 220 |
+
// a_grouped = {a0, a1, a2, a3, b0, b1, b2, b3}
|
| 221 |
+
// b_grouped = {a4, a5, a6, a7, b4, b5, b6, b7}
|
| 222 |
+
// TODO: can we support caching this?
|
| 223 |
+
const __m256i group_ctrl = _mm256_setr_epi32(0, 2, 4, 6, 1, 3, 5, 7);
|
| 224 |
+
auto a_grouped = _mm256_permutevar8x32_ps(a, group_ctrl);
|
| 225 |
+
auto b_grouped = _mm256_permutevar8x32_ps(b, group_ctrl);
|
| 226 |
+
|
| 227 |
+
// swap lanes:
|
| 228 |
+
// return {a0, a1, a2, a3, a4, a5, a6, a7}
|
| 229 |
+
// {b0, b1, b2, b3, b4, b5, b6, b7}
|
| 230 |
+
return std::make_pair(_mm256_permute2f128_ps(a_grouped, b_grouped, 0b0100000), // 0, 2. 4 bits apart
|
| 231 |
+
_mm256_permute2f128_ps(a_grouped, b_grouped, 0b0110001)); // 1, 3. 4 bits apart
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FLIP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 235 |
+
|
| 236 |
+
template<>
|
| 237 |
+
inline Vectorized<float> flip(const Vectorized<float> & v) {
|
| 238 |
+
const __m256i mask_float = _mm256_set_epi32(0, 1, 2, 3, 4, 5, 6, 7);
|
| 239 |
+
return _mm256_permutevar8x32_ps(v, mask_float);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
template<>
|
| 243 |
+
inline Vectorized<double> flip(const Vectorized<double> & v) {
|
| 244 |
+
return _mm256_permute4x64_pd(v, 27); // 27 == _MM_SHUFFLE(0, 1, 2, 3)
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
template<>
|
| 248 |
+
inline Vectorized<int64_t> flip(const Vectorized<int64_t> & v) {
|
| 249 |
+
return _mm256_permute4x64_epi64(v, 27); // 27 == _MM_SHUFFLE(0, 1, 2, 3)
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
template<>
|
| 253 |
+
inline Vectorized<int32_t> flip(const Vectorized<int32_t> & v) {
|
| 254 |
+
const __m256i mask_int32 = _mm256_set_epi32(0, 1, 2, 3, 4, 5, 6, 7);
|
| 255 |
+
return _mm256_permutevar8x32_epi32(v, mask_int32);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
template<>
|
| 259 |
+
inline Vectorized<int16_t> flip(const Vectorized<int16_t> & v) {
|
| 260 |
+
const __m256i mask = _mm256_set_epi8(
|
| 261 |
+
1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14,
|
| 262 |
+
1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14
|
| 263 |
+
);
|
| 264 |
+
auto reversed = _mm256_shuffle_epi8(v, mask);
|
| 265 |
+
return _mm256_permute2x128_si256(reversed, reversed, 1);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
inline __m256i flip8(const __m256i & v) {
|
| 269 |
+
const __m256i mask_int8 = _mm256_set_epi8(
|
| 270 |
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
| 271 |
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
|
| 272 |
+
);
|
| 273 |
+
auto reversed = _mm256_shuffle_epi8(v, mask_int8);
|
| 274 |
+
return _mm256_permute2x128_si256(reversed, reversed, 1);
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
template<>
|
| 278 |
+
inline Vectorized<int8_t> flip(const Vectorized<int8_t> & v) {
|
| 279 |
+
return flip8(v);
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
template<>
|
| 283 |
+
inline Vectorized<uint8_t> flip(const Vectorized<uint8_t> & v) {
|
| 284 |
+
return flip8(v);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
#endif // (defined(CPU_CAPABILITY_AVX2) && !defined(_MSC_VER)
|
| 288 |
+
|
| 289 |
+
}} // namepsace at::vec::CPU_CAPABILITY
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vec256_complex_float.h
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// DO NOT DEFINE STATIC DATA IN THIS HEADER!
|
| 4 |
+
// See Note [Do not compile initializers with AVX]
|
| 5 |
+
|
| 6 |
+
#include <c10/util/complex.h>
|
| 7 |
+
#include <c10/util/irange.h>
|
| 8 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 9 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 10 |
+
#if defined(CPU_CAPABILITY_AVX2) && !defined(_MSC_VER)
|
| 11 |
+
#include <sleef.h>
|
| 12 |
+
#endif
|
| 13 |
+
|
| 14 |
+
namespace at::vec {
|
| 15 |
+
// See Note [CPU_CAPABILITY namespace]
|
| 16 |
+
inline namespace CPU_CAPABILITY {
|
| 17 |
+
|
| 18 |
+
#if defined(CPU_CAPABILITY_AVX2) && !defined(_MSC_VER)
|
| 19 |
+
|
| 20 |
+
template <> class Vectorized<c10::complex<float>> {
|
| 21 |
+
private:
|
| 22 |
+
__m256 values;
|
| 23 |
+
public:
|
| 24 |
+
using value_type = c10::complex<float>;
|
| 25 |
+
using size_type = int;
|
| 26 |
+
static constexpr size_type size() {
|
| 27 |
+
return 4;
|
| 28 |
+
}
|
| 29 |
+
Vectorized() {}
|
| 30 |
+
Vectorized(__m256 v) : values(v) {}
|
| 31 |
+
Vectorized(c10::complex<float> val) {
|
| 32 |
+
float real_value = val.real();
|
| 33 |
+
float imag_value = val.imag();
|
| 34 |
+
values = _mm256_setr_ps(real_value, imag_value,
|
| 35 |
+
real_value, imag_value,
|
| 36 |
+
real_value, imag_value,
|
| 37 |
+
real_value, imag_value
|
| 38 |
+
);
|
| 39 |
+
}
|
| 40 |
+
Vectorized(c10::complex<float> val1, c10::complex<float> val2, c10::complex<float> val3, c10::complex<float> val4) {
|
| 41 |
+
values = _mm256_setr_ps(val1.real(), val1.imag(),
|
| 42 |
+
val2.real(), val2.imag(),
|
| 43 |
+
val3.real(), val3.imag(),
|
| 44 |
+
val4.real(), val4.imag()
|
| 45 |
+
);
|
| 46 |
+
}
|
| 47 |
+
operator __m256() const {
|
| 48 |
+
return values;
|
| 49 |
+
}
|
| 50 |
+
template <int64_t mask>
|
| 51 |
+
static Vectorized<c10::complex<float>> blend(const Vectorized<c10::complex<float>>& a, const Vectorized<c10::complex<float>>& b) {
|
| 52 |
+
// convert c10::complex<V> index mask to V index mask: xy -> xxyy
|
| 53 |
+
static_assert(mask > -1 && mask < 16, "Unexpected mask range");
|
| 54 |
+
switch (mask) {
|
| 55 |
+
case 0:
|
| 56 |
+
return a;
|
| 57 |
+
case 1:
|
| 58 |
+
return _mm256_blend_ps(a.values, b.values, 0x03); //b0000 0001 = b0000 0011
|
| 59 |
+
case 2:
|
| 60 |
+
return _mm256_blend_ps(a.values, b.values, 0x0C); //b0000 0010 = b0000 1100
|
| 61 |
+
case 3:
|
| 62 |
+
return _mm256_blend_ps(a.values, b.values, 0x0F); //b0000 0011 = b0000 1111
|
| 63 |
+
case 4:
|
| 64 |
+
return _mm256_blend_ps(a.values, b.values, 0x30); //b0000 0100 = b0011 0000
|
| 65 |
+
case 5:
|
| 66 |
+
return _mm256_blend_ps(a.values, b.values, 0x33); //b0000 0101 = b0011 0011
|
| 67 |
+
case 6:
|
| 68 |
+
return _mm256_blend_ps(a.values, b.values, 0x3C); //b0000 0110 = b0011 1100
|
| 69 |
+
case 7:
|
| 70 |
+
return _mm256_blend_ps(a.values, b.values, 0x3F); //b0000 0111 = b0011 1111
|
| 71 |
+
case 8:
|
| 72 |
+
return _mm256_blend_ps(a.values, b.values, 0xC0); //b0000 1000 = b1100 0000
|
| 73 |
+
case 9:
|
| 74 |
+
return _mm256_blend_ps(a.values, b.values, 0xC3); //b0000 1001 = b1100 0011
|
| 75 |
+
case 10:
|
| 76 |
+
return _mm256_blend_ps(a.values, b.values, 0xCC); //b0000 1010 = b1100 1100
|
| 77 |
+
case 11:
|
| 78 |
+
return _mm256_blend_ps(a.values, b.values, 0xCF); //b0000 1011 = b1100 1111
|
| 79 |
+
case 12:
|
| 80 |
+
return _mm256_blend_ps(a.values, b.values, 0xF0); //b0000 1100 = b1111 0000
|
| 81 |
+
case 13:
|
| 82 |
+
return _mm256_blend_ps(a.values, b.values, 0xF3); //b0000 1101 = b1111 0011
|
| 83 |
+
case 14:
|
| 84 |
+
return _mm256_blend_ps(a.values, b.values, 0xFC); //b0000 1110 = b1111 1100
|
| 85 |
+
default: break;
|
| 86 |
+
}
|
| 87 |
+
return b;
|
| 88 |
+
}
|
| 89 |
+
static Vectorized<c10::complex<float>> blendv(const Vectorized<c10::complex<float>>& a, const Vectorized<c10::complex<float>>& b,
|
| 90 |
+
const Vectorized<c10::complex<float>>& mask) {
|
| 91 |
+
// convert c10::complex<V> index mask to V index mask: xy -> xxyy
|
| 92 |
+
auto mask_ = _mm256_unpacklo_ps(mask.values, mask.values);
|
| 93 |
+
return _mm256_blendv_ps(a.values, b.values, mask_);
|
| 94 |
+
|
| 95 |
+
}
|
| 96 |
+
template<typename step_t>
|
| 97 |
+
static Vectorized<c10::complex<float>> arange(c10::complex<float> base = 0., step_t step = static_cast<step_t>(1)) {
|
| 98 |
+
return Vectorized<c10::complex<float>>(base,
|
| 99 |
+
base + step,
|
| 100 |
+
base + c10::complex<float>(2)*step,
|
| 101 |
+
base + c10::complex<float>(3)*step);
|
| 102 |
+
}
|
| 103 |
+
static Vectorized<c10::complex<float>> set(const Vectorized<c10::complex<float>>& a, const Vectorized<c10::complex<float>>& b,
|
| 104 |
+
int64_t count = size()) {
|
| 105 |
+
switch (count) {
|
| 106 |
+
case 0:
|
| 107 |
+
return a;
|
| 108 |
+
case 1:
|
| 109 |
+
return blend<1>(a, b);
|
| 110 |
+
case 2:
|
| 111 |
+
return blend<3>(a, b);
|
| 112 |
+
case 3:
|
| 113 |
+
return blend<7>(a, b);
|
| 114 |
+
}
|
| 115 |
+
return b;
|
| 116 |
+
}
|
| 117 |
+
static Vectorized<c10::complex<float>> loadu(const void* ptr, int64_t count = size()) {
|
| 118 |
+
if (count == size())
|
| 119 |
+
return _mm256_loadu_ps(reinterpret_cast<const float*>(ptr));
|
| 120 |
+
|
| 121 |
+
__at_align__ float tmp_values[2*size()];
|
| 122 |
+
// Ensure uninitialized memory does not change the output value See https://github.com/pytorch/pytorch/issues/32502
|
| 123 |
+
// for more details. We do not initialize arrays to zero using "={0}" because gcc would compile it to two
|
| 124 |
+
// instructions while a loop would be compiled to one instruction.
|
| 125 |
+
for (const auto i : c10::irange(2*size())) {
|
| 126 |
+
tmp_values[i] = 0.0;
|
| 127 |
+
}
|
| 128 |
+
std::memcpy(
|
| 129 |
+
tmp_values,
|
| 130 |
+
reinterpret_cast<const float*>(ptr),
|
| 131 |
+
count * sizeof(c10::complex<float>));
|
| 132 |
+
return _mm256_load_ps(tmp_values);
|
| 133 |
+
}
|
| 134 |
+
void store(void* ptr, int count = size()) const {
|
| 135 |
+
if (count == size()) {
|
| 136 |
+
_mm256_storeu_ps(reinterpret_cast<float*>(ptr), values);
|
| 137 |
+
} else if (count > 0) {
|
| 138 |
+
float tmp_values[2*size()];
|
| 139 |
+
_mm256_storeu_ps(reinterpret_cast<float*>(tmp_values), values);
|
| 140 |
+
std::memcpy(ptr, tmp_values, count * sizeof(c10::complex<float>));
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
const c10::complex<float>& operator[](int idx) const = delete;
|
| 144 |
+
c10::complex<float>& operator[](int idx) = delete;
|
| 145 |
+
Vectorized<c10::complex<float>> map(c10::complex<float> (*const f)(const c10::complex<float> &)) const {
|
| 146 |
+
__at_align__ c10::complex<float> tmp[size()];
|
| 147 |
+
store(tmp);
|
| 148 |
+
for (const auto i : c10::irange(size())) {
|
| 149 |
+
tmp[i] = f(tmp[i]);
|
| 150 |
+
}
|
| 151 |
+
return loadu(tmp);
|
| 152 |
+
}
|
| 153 |
+
__m256 abs_2_() const {
|
| 154 |
+
auto val_2 = _mm256_mul_ps(values, values); // a*a b*b
|
| 155 |
+
auto ret = _mm256_hadd_ps(val_2, val_2); // a*a+b*b a*a+b*b
|
| 156 |
+
return _mm256_permute_ps(ret, 0xD8);
|
| 157 |
+
}
|
| 158 |
+
__m256 abs_() const {
|
| 159 |
+
auto real = _mm256_moveldup_ps(values); // real real
|
| 160 |
+
auto imag = _mm256_movehdup_ps(values); // imag imag
|
| 161 |
+
return Sleef_hypotf8_u05(real, imag); // abs abs
|
| 162 |
+
}
|
| 163 |
+
Vectorized<c10::complex<float>> abs() const {
|
| 164 |
+
const __m256 real_mask = _mm256_castsi256_ps(_mm256_setr_epi32(0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000,
|
| 165 |
+
0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000));
|
| 166 |
+
return _mm256_and_ps(abs_(), real_mask); // abs 0
|
| 167 |
+
}
|
| 168 |
+
__m256 angle_() const {
|
| 169 |
+
//angle = atan2(b/a)
|
| 170 |
+
auto b_a = _mm256_permute_ps(values, 0xB1); // b a
|
| 171 |
+
return Sleef_atan2f8_u10(values, b_a); // 90-angle angle
|
| 172 |
+
}
|
| 173 |
+
Vectorized<c10::complex<float>> angle() const {
|
| 174 |
+
const __m256 real_mask = _mm256_castsi256_ps(_mm256_setr_epi32(0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000,
|
| 175 |
+
0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000));
|
| 176 |
+
auto angle = _mm256_permute_ps(angle_(), 0xB1); // angle 90-angle
|
| 177 |
+
return _mm256_and_ps(angle, real_mask); // angle 0
|
| 178 |
+
}
|
| 179 |
+
Vectorized<c10::complex<float>> sgn() const {
|
| 180 |
+
auto abs = abs_();
|
| 181 |
+
auto zero = _mm256_setzero_ps();
|
| 182 |
+
auto mask = _mm256_cmp_ps(abs, zero, _CMP_EQ_OQ);
|
| 183 |
+
auto div = values / abs;
|
| 184 |
+
return _mm256_blendv_ps(div, zero, mask);
|
| 185 |
+
}
|
| 186 |
+
__m256 real_() const {
|
| 187 |
+
const __m256 real_mask = _mm256_castsi256_ps(_mm256_setr_epi32(0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000,
|
| 188 |
+
0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000));
|
| 189 |
+
return _mm256_and_ps(values, real_mask);
|
| 190 |
+
}
|
| 191 |
+
Vectorized<c10::complex<float>> real() const {
|
| 192 |
+
return real_();
|
| 193 |
+
}
|
| 194 |
+
__m256 imag_() const {
|
| 195 |
+
const __m256 imag_mask = _mm256_castsi256_ps(_mm256_setr_epi32(0x00000000, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF,
|
| 196 |
+
0x00000000, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF));
|
| 197 |
+
return _mm256_and_ps(values, imag_mask);
|
| 198 |
+
}
|
| 199 |
+
Vectorized<c10::complex<float>> imag() const {
|
| 200 |
+
return _mm256_permute_ps(imag_(), 0xB1); //b a
|
| 201 |
+
}
|
| 202 |
+
__m256 conj_() const {
|
| 203 |
+
const __m256 sign_mask = _mm256_setr_ps(0.0, -0.0, 0.0, -0.0, 0.0, -0.0, 0.0, -0.0);
|
| 204 |
+
return _mm256_xor_ps(values, sign_mask); // a -b
|
| 205 |
+
}
|
| 206 |
+
Vectorized<c10::complex<float>> conj() const {
|
| 207 |
+
return conj_();
|
| 208 |
+
}
|
| 209 |
+
Vectorized<c10::complex<float>> log() const {
|
| 210 |
+
// Most trigonomic ops use the log() op to improve complex number performance.
|
| 211 |
+
return map(std::log);
|
| 212 |
+
}
|
| 213 |
+
Vectorized<c10::complex<float>> log2() const {
|
| 214 |
+
const __m256 log2_ = _mm256_set1_ps(std::log(2));
|
| 215 |
+
return _mm256_div_ps(log(), log2_);
|
| 216 |
+
}
|
| 217 |
+
Vectorized<c10::complex<float>> log10() const {
|
| 218 |
+
const __m256 log10_ = _mm256_set1_ps(std::log(10));
|
| 219 |
+
return _mm256_div_ps(log(), log10_);
|
| 220 |
+
}
|
| 221 |
+
Vectorized<c10::complex<float>> log1p() const {
|
| 222 |
+
return map(std::log1p);
|
| 223 |
+
}
|
| 224 |
+
Vectorized<c10::complex<float>> asin() const {
|
| 225 |
+
// asin(x)
|
| 226 |
+
// = -i*ln(iz + sqrt(1 -z^2))
|
| 227 |
+
// = -i*ln((ai - b) + sqrt(1 - (a + bi)*(a + bi)))
|
| 228 |
+
// = -i*ln((-b + ai) + sqrt(1 - (a**2 - b**2) - 2*abi))
|
| 229 |
+
const __m256 one = _mm256_set1_ps(1);
|
| 230 |
+
|
| 231 |
+
auto conj = conj_();
|
| 232 |
+
auto b_a = _mm256_permute_ps(conj, 0xB1); //-b a
|
| 233 |
+
auto ab = _mm256_mul_ps(conj, b_a); //-ab -ab
|
| 234 |
+
auto im = _mm256_add_ps(ab, ab); //-2ab -2ab
|
| 235 |
+
|
| 236 |
+
auto val_2 = _mm256_mul_ps(values, values); // a*a b*b
|
| 237 |
+
auto re = _mm256_hsub_ps(val_2, _mm256_permute_ps(val_2, 0xB1)); // a*a-b*b b*b-a*a
|
| 238 |
+
re = _mm256_permute_ps(re, 0xD8);
|
| 239 |
+
re = _mm256_sub_ps(one, re);
|
| 240 |
+
|
| 241 |
+
auto root = Vectorized(_mm256_blend_ps(re, im, 0xAA)).sqrt(); //sqrt(re + i*im)
|
| 242 |
+
auto ln = Vectorized(_mm256_add_ps(b_a, root)).log(); //ln(iz + sqrt())
|
| 243 |
+
return Vectorized(_mm256_permute_ps(ln.values, 0xB1)).conj(); //-i*ln()
|
| 244 |
+
}
|
| 245 |
+
Vectorized<c10::complex<float>> acos() const {
|
| 246 |
+
return map(std::acos);
|
| 247 |
+
}
|
| 248 |
+
Vectorized<c10::complex<float>> atan() const;
|
| 249 |
+
Vectorized<c10::complex<float>> atanh() const {
|
| 250 |
+
return map(std::atanh);
|
| 251 |
+
}
|
| 252 |
+
Vectorized<c10::complex<float>> exp() const {
|
| 253 |
+
//exp(a + bi)
|
| 254 |
+
// = exp(a)*(cos(b) + sin(b)i)
|
| 255 |
+
auto exp = Sleef_expf8_u10(values); //exp(a) exp(b)
|
| 256 |
+
exp = _mm256_blend_ps(exp, _mm256_permute_ps(exp, 0xB1), 0xAA); //exp(a) exp(a)
|
| 257 |
+
|
| 258 |
+
auto sin_cos = Sleef_sincosf8_u10(values); //[sin(a), cos(a)] [sin(b), cos(b)]
|
| 259 |
+
auto cos_sin = _mm256_blend_ps(_mm256_permute_ps(sin_cos.y, 0xB1),
|
| 260 |
+
sin_cos.x, 0xAA); //cos(b) sin(b)
|
| 261 |
+
return _mm256_mul_ps(exp, cos_sin);
|
| 262 |
+
}
|
| 263 |
+
Vectorized<c10::complex<float>> exp2() const {
|
| 264 |
+
// Use identity 2**x = exp(log(2) * x)
|
| 265 |
+
const __m256 ln_2 = _mm256_set1_ps(c10::ln_2<float>);
|
| 266 |
+
Vectorized<c10::complex<float>> scaled_values = _mm256_mul_ps(values, ln_2);
|
| 267 |
+
return scaled_values.exp();
|
| 268 |
+
}
|
| 269 |
+
Vectorized<c10::complex<float>> expm1() const {
|
| 270 |
+
return map(std::expm1);
|
| 271 |
+
}
|
| 272 |
+
Vectorized<c10::complex<float>> sin() const {
|
| 273 |
+
return map(std::sin);
|
| 274 |
+
}
|
| 275 |
+
Vectorized<c10::complex<float>> sinh() const {
|
| 276 |
+
return map(std::sinh);
|
| 277 |
+
}
|
| 278 |
+
Vectorized<c10::complex<float>> cos() const {
|
| 279 |
+
return map(std::cos);
|
| 280 |
+
}
|
| 281 |
+
Vectorized<c10::complex<float>> cosh() const {
|
| 282 |
+
return map(std::cosh);
|
| 283 |
+
}
|
| 284 |
+
Vectorized<c10::complex<float>> ceil() const {
|
| 285 |
+
return _mm256_ceil_ps(values);
|
| 286 |
+
}
|
| 287 |
+
Vectorized<c10::complex<float>> floor() const {
|
| 288 |
+
return _mm256_floor_ps(values);
|
| 289 |
+
}
|
| 290 |
+
Vectorized<c10::complex<float>> neg() const {
|
| 291 |
+
auto zero = _mm256_setzero_ps();
|
| 292 |
+
return _mm256_sub_ps(zero, values);
|
| 293 |
+
}
|
| 294 |
+
Vectorized<c10::complex<float>> round() const {
|
| 295 |
+
return _mm256_round_ps(values, (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC));
|
| 296 |
+
}
|
| 297 |
+
Vectorized<c10::complex<float>> tan() const {
|
| 298 |
+
return map(std::tan);
|
| 299 |
+
}
|
| 300 |
+
Vectorized<c10::complex<float>> tanh() const {
|
| 301 |
+
return map(std::tanh);
|
| 302 |
+
}
|
| 303 |
+
Vectorized<c10::complex<float>> trunc() const {
|
| 304 |
+
return _mm256_round_ps(values, (_MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC));
|
| 305 |
+
}
|
| 306 |
+
Vectorized<c10::complex<float>> sqrt() const {
|
| 307 |
+
return map(std::sqrt);
|
| 308 |
+
}
|
| 309 |
+
Vectorized<c10::complex<float>> reciprocal() const;
|
| 310 |
+
Vectorized<c10::complex<float>> rsqrt() const {
|
| 311 |
+
return sqrt().reciprocal();
|
| 312 |
+
}
|
| 313 |
+
Vectorized<c10::complex<float>> pow(const Vectorized<c10::complex<float>> &exp) const {
|
| 314 |
+
__at_align__ c10::complex<float> x_tmp[size()];
|
| 315 |
+
__at_align__ c10::complex<float> y_tmp[size()];
|
| 316 |
+
store(x_tmp);
|
| 317 |
+
exp.store(y_tmp);
|
| 318 |
+
for (const auto i : c10::irange(size())) {
|
| 319 |
+
x_tmp[i] = std::pow(x_tmp[i], y_tmp[i]);
|
| 320 |
+
}
|
| 321 |
+
return loadu(x_tmp);
|
| 322 |
+
}
|
| 323 |
+
// Comparison using the _CMP_**_OQ predicate.
|
| 324 |
+
// `O`: get false if an operand is NaN
|
| 325 |
+
// `Q`: do not raise if an operand is NaN
|
| 326 |
+
Vectorized<c10::complex<float>> operator==(const Vectorized<c10::complex<float>>& other) const {
|
| 327 |
+
return _mm256_cmp_ps(values, other.values, _CMP_EQ_OQ);
|
| 328 |
+
}
|
| 329 |
+
Vectorized<c10::complex<float>> operator!=(const Vectorized<c10::complex<float>>& other) const {
|
| 330 |
+
return _mm256_cmp_ps(values, other.values, _CMP_NEQ_UQ);
|
| 331 |
+
}
|
| 332 |
+
Vectorized<c10::complex<float>> operator<(const Vectorized<c10::complex<float>>& /*other*/) const {
|
| 333 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 334 |
+
}
|
| 335 |
+
Vectorized<c10::complex<float>> operator<=(const Vectorized<c10::complex<float>>& /*other*/) const {
|
| 336 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 337 |
+
}
|
| 338 |
+
Vectorized<c10::complex<float>> operator>(const Vectorized<c10::complex<float>>& /*other*/) const {
|
| 339 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 340 |
+
}
|
| 341 |
+
Vectorized<c10::complex<float>> operator>=(const Vectorized<c10::complex<float>>& /*other*/) const {
|
| 342 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
Vectorized<c10::complex<float>> eq(const Vectorized<c10::complex<float>>& other) const;
|
| 346 |
+
Vectorized<c10::complex<float>> ne(const Vectorized<c10::complex<float>>& other) const;
|
| 347 |
+
};
|
| 348 |
+
|
| 349 |
+
template <> Vectorized<c10::complex<float>> inline operator+(const Vectorized<c10::complex<float>> &a, const Vectorized<c10::complex<float>> &b) {
|
| 350 |
+
return _mm256_add_ps(a, b);
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
template <> Vectorized<c10::complex<float>> inline operator-(const Vectorized<c10::complex<float>> &a, const Vectorized<c10::complex<float>> &b) {
|
| 354 |
+
return _mm256_sub_ps(a, b);
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
template <> Vectorized<c10::complex<float>> inline operator*(const Vectorized<c10::complex<float>> &a, const Vectorized<c10::complex<float>> &b) {
|
| 358 |
+
//(a + bi) * (c + di) = (ac - bd) + (ad + bc)i
|
| 359 |
+
const __m256 sign_mask = _mm256_setr_ps(0.0, -0.0, 0.0, -0.0, 0.0, -0.0, 0.0, -0.0);
|
| 360 |
+
auto ac_bd = _mm256_mul_ps(a, b); //ac bd
|
| 361 |
+
|
| 362 |
+
auto d_c = _mm256_permute_ps(b, 0xB1); //d c
|
| 363 |
+
d_c = _mm256_xor_ps(sign_mask, d_c); //d -c
|
| 364 |
+
auto ad_bc = _mm256_mul_ps(a, d_c); //ad -bc
|
| 365 |
+
|
| 366 |
+
auto ret = _mm256_hsub_ps(ac_bd, ad_bc); //ac - bd ad + bc
|
| 367 |
+
ret = _mm256_permute_ps(ret, 0xD8);
|
| 368 |
+
return ret;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
template <> Vectorized<c10::complex<float>> inline operator/(const Vectorized<c10::complex<float>> &a, const Vectorized<c10::complex<float>> &b) {
|
| 372 |
+
//re + im*i = (a + bi) / (c + di)
|
| 373 |
+
auto mask = _mm256_set1_ps(-0.f);
|
| 374 |
+
auto fabs_cd = _mm256_andnot_ps(mask, b); // |c| |d|
|
| 375 |
+
auto fabs_dc = _mm256_permute_ps(fabs_cd, 0xB1); // |d| |c|
|
| 376 |
+
auto scale = _mm256_rcp_ps(_mm256_max_ps(fabs_cd, fabs_dc)); // 1/sc 1/sc
|
| 377 |
+
auto a2 = _mm256_mul_ps(a, scale); // a/sc b/sc
|
| 378 |
+
auto b2 = _mm256_mul_ps(b, scale); // c/sc d/sc
|
| 379 |
+
auto acbd2 = _mm256_mul_ps(a2, b2);
|
| 380 |
+
|
| 381 |
+
const __m256 sign_mask = _mm256_setr_ps(-0.0, 0.0, -0.0, 0.0, -0.0, 0.0, -0.0, 0.0);
|
| 382 |
+
auto dc2 = _mm256_permute_ps(b2, 0xB1); // d/sc c/sc
|
| 383 |
+
dc2 = _mm256_xor_ps(sign_mask, dc2); // -d/|c,d| c/sc
|
| 384 |
+
auto adbc2 = _mm256_mul_ps(a2, dc2); //-ad/sc^2 bc/sc^2
|
| 385 |
+
auto res2 = _mm256_hadd_ps(acbd2, adbc2); //(ac+bd)/sc^2 (bc-ad)/sc^2
|
| 386 |
+
res2 = _mm256_permute_ps(res2, 0xD8);
|
| 387 |
+
|
| 388 |
+
// get the denominator
|
| 389 |
+
auto denom2 = Vectorized<c10::complex<float>>(b2).abs_2_(); // (c^2+d^2)/sc^2 (c^2+d^2)/sc^2
|
| 390 |
+
res2 = _mm256_div_ps(res2, denom2);
|
| 391 |
+
return res2;
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
// reciprocal. Implement this here so we can use multiplication.
|
| 395 |
+
inline Vectorized<c10::complex<float>> Vectorized<c10::complex<float>>::reciprocal() const {
|
| 396 |
+
//re + im*i = (a + bi) / (c + di)
|
| 397 |
+
//re = (ac + bd)/abs_2() = c/abs_2()
|
| 398 |
+
//im = (bc - ad)/abs_2() = d/abs_2()
|
| 399 |
+
const __m256 sign_mask = _mm256_setr_ps(0.0, -0.0, 0.0, -0.0, 0.0, -0.0, 0.0, -0.0);
|
| 400 |
+
auto c_d = _mm256_xor_ps(sign_mask, values); //c -d
|
| 401 |
+
return _mm256_div_ps(c_d, abs_2_());
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
inline Vectorized<c10::complex<float>> Vectorized<c10::complex<float>>::atan() const {
|
| 405 |
+
// atan(x) = i/2 * ln((i + z)/(i - z))
|
| 406 |
+
const __m256 i = _mm256_setr_ps(0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
|
| 407 |
+
const Vectorized i_half = _mm256_setr_ps(0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5);
|
| 408 |
+
|
| 409 |
+
auto sum = Vectorized(_mm256_add_ps(i, values)); // a 1+b
|
| 410 |
+
auto sub = Vectorized(_mm256_sub_ps(i, values)); // -a 1-b
|
| 411 |
+
auto ln = (sum/sub).log(); // ln((i + z)/(i - z))
|
| 412 |
+
return i_half*ln; // i/2*ln()
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
template <>
|
| 416 |
+
Vectorized<c10::complex<float>> inline maximum(const Vectorized<c10::complex<float>>& a, const Vectorized<c10::complex<float>>& b) {
|
| 417 |
+
auto abs_a = a.abs_2_();
|
| 418 |
+
auto abs_b = b.abs_2_();
|
| 419 |
+
auto mask = _mm256_cmp_ps(abs_a, abs_b, _CMP_LT_OQ);
|
| 420 |
+
auto max = _mm256_blendv_ps(a, b, mask);
|
| 421 |
+
// Exploit the fact that all-ones is a NaN.
|
| 422 |
+
auto isnan = _mm256_cmp_ps(abs_a, abs_b, _CMP_UNORD_Q);
|
| 423 |
+
return _mm256_or_ps(max, isnan);
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
template <>
|
| 427 |
+
Vectorized<c10::complex<float>> inline minimum(const Vectorized<c10::complex<float>>& a, const Vectorized<c10::complex<float>>& b) {
|
| 428 |
+
auto abs_a = a.abs_2_();
|
| 429 |
+
auto abs_b = b.abs_2_();
|
| 430 |
+
auto mask = _mm256_cmp_ps(abs_a, abs_b, _CMP_GT_OQ);
|
| 431 |
+
auto min = _mm256_blendv_ps(a, b, mask);
|
| 432 |
+
// Exploit the fact that all-ones is a NaN.
|
| 433 |
+
auto isnan = _mm256_cmp_ps(abs_a, abs_b, _CMP_UNORD_Q);
|
| 434 |
+
return _mm256_or_ps(min, isnan);
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
template <>
|
| 438 |
+
Vectorized<c10::complex<float>> inline operator&(const Vectorized<c10::complex<float>>& a, const Vectorized<c10::complex<float>>& b) {
|
| 439 |
+
return _mm256_and_ps(a, b);
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
template <>
|
| 443 |
+
Vectorized<c10::complex<float>> inline operator|(const Vectorized<c10::complex<float>>& a, const Vectorized<c10::complex<float>>& b) {
|
| 444 |
+
return _mm256_or_ps(a, b);
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
template <>
|
| 448 |
+
Vectorized<c10::complex<float>> inline operator^(const Vectorized<c10::complex<float>>& a, const Vectorized<c10::complex<float>>& b) {
|
| 449 |
+
return _mm256_xor_ps(a, b);
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
inline Vectorized<c10::complex<float>> Vectorized<c10::complex<float>>::eq(
|
| 453 |
+
const Vectorized<c10::complex<float>>& other) const {
|
| 454 |
+
auto eq = (*this == other); // compares real and imag individually
|
| 455 |
+
// If both real numbers and imag numbers are equal, then the complex numbers are equal
|
| 456 |
+
return (eq.real() & eq.imag()) & Vectorized<c10::complex<float>>(_mm256_set1_ps(1.0f));
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
inline Vectorized<c10::complex<float>> Vectorized<c10::complex<float>>::ne(
|
| 460 |
+
const Vectorized<c10::complex<float>>& other) const {
|
| 461 |
+
auto ne = (*this != other); // compares real and imag individually
|
| 462 |
+
// If either real numbers or imag numbers are not equal, then the complex numbers are not equal
|
| 463 |
+
return (ne.real() | ne.imag()) & Vectorized<c10::complex<float>>(_mm256_set1_ps(1.0f));
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
#endif
|
| 467 |
+
|
| 468 |
+
}} // namespace at::vec::CPU_CAPABILITY
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vec256_float.h
ADDED
|
@@ -0,0 +1,565 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// DO NOT DEFINE STATIC DATA IN THIS HEADER!
|
| 4 |
+
// See Note [Do not compile initializers with AVX]
|
| 5 |
+
|
| 6 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 7 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 8 |
+
#include <c10/util/irange.h>
|
| 9 |
+
#if defined(CPU_CAPABILITY_AVX2) && !defined(_MSC_VER)
|
| 10 |
+
#include <sleef.h>
|
| 11 |
+
#endif
|
| 12 |
+
|
| 13 |
+
namespace at::vec {
|
| 14 |
+
// See Note [CPU_CAPABILITY namespace]
|
| 15 |
+
inline namespace CPU_CAPABILITY {
|
| 16 |
+
|
| 17 |
+
#if defined(CPU_CAPABILITY_AVX2) && !defined(_MSC_VER)
|
| 18 |
+
|
| 19 |
+
template <> class Vectorized<float> {
|
| 20 |
+
private:
|
| 21 |
+
__m256 values;
|
| 22 |
+
public:
|
| 23 |
+
using value_type = float;
|
| 24 |
+
using size_type = int;
|
| 25 |
+
static constexpr size_type size() {
|
| 26 |
+
return 8;
|
| 27 |
+
}
|
| 28 |
+
Vectorized() {}
|
| 29 |
+
Vectorized(__m256 v) : values(v) {}
|
| 30 |
+
Vectorized(float val) {
|
| 31 |
+
values = _mm256_set1_ps(val);
|
| 32 |
+
}
|
| 33 |
+
Vectorized(float val1, float val2, float val3, float val4,
|
| 34 |
+
float val5, float val6, float val7, float val8) {
|
| 35 |
+
values = _mm256_setr_ps(val1, val2, val3, val4, val5, val6, val7, val8);
|
| 36 |
+
}
|
| 37 |
+
operator __m256() const {
|
| 38 |
+
return values;
|
| 39 |
+
}
|
| 40 |
+
template <int64_t mask>
|
| 41 |
+
static Vectorized<float> blend(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 42 |
+
return _mm256_blend_ps(a.values, b.values, mask);
|
| 43 |
+
}
|
| 44 |
+
static Vectorized<float> blendv(const Vectorized<float>& a, const Vectorized<float>& b,
|
| 45 |
+
const Vectorized<float>& mask) {
|
| 46 |
+
return _mm256_blendv_ps(a.values, b.values, mask.values);
|
| 47 |
+
}
|
| 48 |
+
template<typename step_t>
|
| 49 |
+
static Vectorized<float> arange(float base = 0.f, step_t step = static_cast<step_t>(1)) {
|
| 50 |
+
return Vectorized<float>(
|
| 51 |
+
base, base + step, base + 2 * step, base + 3 * step,
|
| 52 |
+
base + 4 * step, base + 5 * step, base + 6 * step, base + 7 * step);
|
| 53 |
+
}
|
| 54 |
+
static Vectorized<float> set(const Vectorized<float>& a, const Vectorized<float>& b,
|
| 55 |
+
int64_t count = size()) {
|
| 56 |
+
switch (count) {
|
| 57 |
+
case 0:
|
| 58 |
+
return a;
|
| 59 |
+
case 1:
|
| 60 |
+
return blend<1>(a, b);
|
| 61 |
+
case 2:
|
| 62 |
+
return blend<3>(a, b);
|
| 63 |
+
case 3:
|
| 64 |
+
return blend<7>(a, b);
|
| 65 |
+
case 4:
|
| 66 |
+
return blend<15>(a, b);
|
| 67 |
+
case 5:
|
| 68 |
+
return blend<31>(a, b);
|
| 69 |
+
case 6:
|
| 70 |
+
return blend<63>(a, b);
|
| 71 |
+
case 7:
|
| 72 |
+
return blend<127>(a, b);
|
| 73 |
+
}
|
| 74 |
+
return b;
|
| 75 |
+
}
|
| 76 |
+
static Vectorized<float> loadu(const void* ptr, int64_t count = size()) {
|
| 77 |
+
if (count == size())
|
| 78 |
+
return _mm256_loadu_ps(reinterpret_cast<const float*>(ptr));
|
| 79 |
+
__at_align__ float tmp_values[size()];
|
| 80 |
+
// Ensure uninitialized memory does not change the output value See https://github.com/pytorch/pytorch/issues/32502
|
| 81 |
+
// for more details. We do not initialize arrays to zero using "={0}" because gcc would compile it to two
|
| 82 |
+
// instructions while a loop would be compiled to one instruction.
|
| 83 |
+
for (const auto i : c10::irange(size())) {
|
| 84 |
+
tmp_values[i] = 0.0;
|
| 85 |
+
}
|
| 86 |
+
std::memcpy(
|
| 87 |
+
tmp_values, reinterpret_cast<const float*>(ptr), count * sizeof(float));
|
| 88 |
+
return _mm256_loadu_ps(tmp_values);
|
| 89 |
+
}
|
| 90 |
+
void store(void* ptr, int64_t count = size()) const {
|
| 91 |
+
if (count == size()) {
|
| 92 |
+
_mm256_storeu_ps(reinterpret_cast<float*>(ptr), values);
|
| 93 |
+
} else if (count > 0) {
|
| 94 |
+
float tmp_values[size()];
|
| 95 |
+
_mm256_storeu_ps(reinterpret_cast<float*>(tmp_values), values);
|
| 96 |
+
std::memcpy(ptr, tmp_values, count * sizeof(float));
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
const float& operator[](int idx) const = delete;
|
| 100 |
+
float& operator[](int idx) = delete;
|
| 101 |
+
int zero_mask() const {
|
| 102 |
+
// returns an integer mask where all zero elements are translated to 1-bit and others are translated to 0-bit
|
| 103 |
+
__m256 cmp = _mm256_cmp_ps(values, _mm256_set1_ps(0.0f), _CMP_EQ_OQ);
|
| 104 |
+
return _mm256_movemask_ps(cmp);
|
| 105 |
+
}
|
| 106 |
+
Vectorized<float> isnan() const {
|
| 107 |
+
return _mm256_cmp_ps(values, _mm256_set1_ps(0.0f), _CMP_UNORD_Q);
|
| 108 |
+
}
|
| 109 |
+
Vectorized<float> map(float (*const f)(float)) const {
|
| 110 |
+
__at_align__ float tmp[size()];
|
| 111 |
+
store(tmp);
|
| 112 |
+
for (const auto i : c10::irange(size())) {
|
| 113 |
+
tmp[i] = f(tmp[i]);
|
| 114 |
+
}
|
| 115 |
+
return loadu(tmp);
|
| 116 |
+
}
|
| 117 |
+
Vectorized<float> abs() const {
|
| 118 |
+
auto mask = _mm256_set1_ps(-0.f);
|
| 119 |
+
return _mm256_andnot_ps(mask, values);
|
| 120 |
+
}
|
| 121 |
+
Vectorized<float> angle() const {
|
| 122 |
+
const auto zero_vec = _mm256_set1_ps(0.f);
|
| 123 |
+
const auto nan_vec = _mm256_set1_ps(NAN);
|
| 124 |
+
const auto not_nan_mask = _mm256_cmp_ps(values, values, _CMP_EQ_OQ);
|
| 125 |
+
const auto nan_mask = _mm256_cmp_ps(not_nan_mask, zero_vec, _CMP_EQ_OQ);
|
| 126 |
+
const auto pi = _mm256_set1_ps(c10::pi<float>);
|
| 127 |
+
|
| 128 |
+
const auto neg_mask = _mm256_cmp_ps(values, zero_vec, _CMP_LT_OQ);
|
| 129 |
+
auto angle = _mm256_blendv_ps(zero_vec, pi, neg_mask);
|
| 130 |
+
angle = _mm256_blendv_ps(angle, nan_vec, nan_mask);
|
| 131 |
+
return angle;
|
| 132 |
+
}
|
| 133 |
+
Vectorized<float> real() const {
|
| 134 |
+
return *this;
|
| 135 |
+
}
|
| 136 |
+
Vectorized<float> imag() const {
|
| 137 |
+
return _mm256_set1_ps(0);
|
| 138 |
+
}
|
| 139 |
+
Vectorized<float> conj() const {
|
| 140 |
+
return *this;
|
| 141 |
+
}
|
| 142 |
+
Vectorized<float> acos() const {
|
| 143 |
+
return Vectorized<float>(Sleef_acosf8_u10(values));
|
| 144 |
+
}
|
| 145 |
+
Vectorized<float> asin() const {
|
| 146 |
+
return Vectorized<float>(Sleef_asinf8_u10(values));
|
| 147 |
+
}
|
| 148 |
+
Vectorized<float> atan() const {
|
| 149 |
+
return Vectorized<float>(Sleef_atanf8_u10(values));
|
| 150 |
+
}
|
| 151 |
+
Vectorized<float> atanh() const {
|
| 152 |
+
return Vectorized<float>(Sleef_atanhf8_u10(values));
|
| 153 |
+
}
|
| 154 |
+
Vectorized<float> atan2(const Vectorized<float> &b) const {
|
| 155 |
+
return Vectorized<float>(Sleef_atan2f8_u10(values, b));
|
| 156 |
+
}
|
| 157 |
+
Vectorized<float> copysign(const Vectorized<float> &sign) const {
|
| 158 |
+
return Vectorized<float>(Sleef_copysignf8(values, sign));
|
| 159 |
+
}
|
| 160 |
+
Vectorized<float> erf() const {
|
| 161 |
+
// constants
|
| 162 |
+
const auto neg_zero_vec = _mm256_set1_ps(-0.f);
|
| 163 |
+
const auto one_vec = _mm256_set1_ps(1.0f);
|
| 164 |
+
const auto p = _mm256_set1_ps(0.3275911f);
|
| 165 |
+
const auto p1 = _mm256_set1_ps(0.254829592f);
|
| 166 |
+
const auto p2 = _mm256_set1_ps(-0.284496736f);
|
| 167 |
+
const auto p3 = _mm256_set1_ps(1.421413741f);
|
| 168 |
+
const auto p4 = _mm256_set1_ps(-1.453152027f);
|
| 169 |
+
const auto p5 = _mm256_set1_ps(1.061405429f);
|
| 170 |
+
// sign(x)
|
| 171 |
+
auto sign_mask = _mm256_and_ps(neg_zero_vec, values);
|
| 172 |
+
auto abs_vec = _mm256_xor_ps(sign_mask, values);
|
| 173 |
+
// t = 1 / (p * abs(x) + 1)
|
| 174 |
+
auto tmp0 = _mm256_fmadd_ps(p, abs_vec, one_vec);
|
| 175 |
+
auto t = _mm256_div_ps(one_vec, tmp0);
|
| 176 |
+
// r = p5 * t ^ 4 + p4 * t ^ 3 + p3 * t ^ 2 + p2 * t + p1
|
| 177 |
+
auto tmp1 = _mm256_fmadd_ps(p5, t, p4);
|
| 178 |
+
auto tmp2 = _mm256_fmadd_ps(tmp1, t, p3);
|
| 179 |
+
auto tmp3 = _mm256_fmadd_ps(tmp2, t, p2);
|
| 180 |
+
auto r = _mm256_fmadd_ps(tmp3, t, p1);
|
| 181 |
+
// - exp(- x * x)
|
| 182 |
+
auto pow_2 = _mm256_mul_ps(values, values);
|
| 183 |
+
auto neg_pow_2 = _mm256_xor_ps(neg_zero_vec, pow_2);
|
| 184 |
+
// auto tmp4 = exp(neg_pow_2);
|
| 185 |
+
auto tmp4 = Vectorized<float>(Sleef_expf8_u10(neg_pow_2));
|
| 186 |
+
auto tmp5 = _mm256_xor_ps(neg_zero_vec, tmp4);
|
| 187 |
+
// erf(x) = sign(x) * (1 - r * t * exp(- x * x))
|
| 188 |
+
auto tmp6 = _mm256_mul_ps(tmp5, t);
|
| 189 |
+
auto tmp7 = _mm256_fmadd_ps(tmp6, r, one_vec);
|
| 190 |
+
return _mm256_xor_ps(sign_mask, tmp7);
|
| 191 |
+
}
|
| 192 |
+
Vectorized<float> erfc() const {
|
| 193 |
+
return Vectorized<float>(Sleef_erfcf8_u15(values));
|
| 194 |
+
}
|
| 195 |
+
Vectorized<float> erfinv() const {
|
| 196 |
+
return map(calc_erfinv);
|
| 197 |
+
}
|
| 198 |
+
Vectorized<float> exp() const {
|
| 199 |
+
return Vectorized<float>(Sleef_expf8_u10(values));
|
| 200 |
+
}
|
| 201 |
+
Vectorized<float> exp2() const {
|
| 202 |
+
return Vectorized<float>(Sleef_exp2f8_u10(values));
|
| 203 |
+
}
|
| 204 |
+
Vectorized<float> expm1() const {
|
| 205 |
+
return Vectorized<float>(Sleef_expm1f8_u10(values));
|
| 206 |
+
}
|
| 207 |
+
Vectorized<float> fmod(const Vectorized<float>& q) const {
|
| 208 |
+
return Vectorized<float>(Sleef_fmodf8(values, q));
|
| 209 |
+
}
|
| 210 |
+
Vectorized<float> log() const {
|
| 211 |
+
return Vectorized<float>(Sleef_logf8_u10(values));
|
| 212 |
+
}
|
| 213 |
+
Vectorized<float> log2() const {
|
| 214 |
+
return Vectorized<float>(Sleef_log2f8_u10(values));
|
| 215 |
+
}
|
| 216 |
+
Vectorized<float> log10() const {
|
| 217 |
+
return Vectorized<float>(Sleef_log10f8_u10(values));
|
| 218 |
+
}
|
| 219 |
+
Vectorized<float> log1p() const {
|
| 220 |
+
return Vectorized<float>(Sleef_log1pf8_u10(values));
|
| 221 |
+
}
|
| 222 |
+
Vectorized<float> frac() const;
|
| 223 |
+
Vectorized<float> sin() const {
|
| 224 |
+
return Vectorized<float>(Sleef_sinf8_u35(values));
|
| 225 |
+
}
|
| 226 |
+
Vectorized<float> sinh() const {
|
| 227 |
+
return Vectorized<float>(Sleef_sinhf8_u10(values));
|
| 228 |
+
}
|
| 229 |
+
Vectorized<float> cos() const {
|
| 230 |
+
return Vectorized<float>(Sleef_cosf8_u35(values));
|
| 231 |
+
}
|
| 232 |
+
Vectorized<float> cosh() const {
|
| 233 |
+
return Vectorized<float>(Sleef_coshf8_u10(values));
|
| 234 |
+
}
|
| 235 |
+
Vectorized<float> ceil() const {
|
| 236 |
+
return _mm256_ceil_ps(values);
|
| 237 |
+
}
|
| 238 |
+
Vectorized<float> floor() const {
|
| 239 |
+
return _mm256_floor_ps(values);
|
| 240 |
+
}
|
| 241 |
+
Vectorized<float> hypot(const Vectorized<float> &b) const {
|
| 242 |
+
return Vectorized<float>(Sleef_hypotf8_u05(values, b));
|
| 243 |
+
}
|
| 244 |
+
Vectorized<float> i0() const {
|
| 245 |
+
return map(calc_i0);
|
| 246 |
+
}
|
| 247 |
+
Vectorized<float> i0e() const {
|
| 248 |
+
return map(calc_i0e);
|
| 249 |
+
}
|
| 250 |
+
Vectorized<float> digamma() const {
|
| 251 |
+
return map(calc_digamma);
|
| 252 |
+
}
|
| 253 |
+
Vectorized<float> igamma(const Vectorized<float> &x) const {
|
| 254 |
+
__at_align__ float tmp[size()];
|
| 255 |
+
__at_align__ float tmp_x[size()];
|
| 256 |
+
store(tmp);
|
| 257 |
+
x.store(tmp_x);
|
| 258 |
+
for (const auto i : c10::irange(size())) {
|
| 259 |
+
tmp[i] = calc_igamma(tmp[i], tmp_x[i]);
|
| 260 |
+
}
|
| 261 |
+
return loadu(tmp);
|
| 262 |
+
}
|
| 263 |
+
Vectorized<float> igammac(const Vectorized<float> &x) const {
|
| 264 |
+
__at_align__ float tmp[size()];
|
| 265 |
+
__at_align__ float tmp_x[size()];
|
| 266 |
+
store(tmp);
|
| 267 |
+
x.store(tmp_x);
|
| 268 |
+
for (const auto i : c10::irange(size())) {
|
| 269 |
+
tmp[i] = calc_igammac(tmp[i], tmp_x[i]);
|
| 270 |
+
}
|
| 271 |
+
return loadu(tmp);
|
| 272 |
+
}
|
| 273 |
+
Vectorized<float> neg() const {
|
| 274 |
+
return _mm256_xor_ps(_mm256_set1_ps(-0.f), values);
|
| 275 |
+
}
|
| 276 |
+
Vectorized<float> nextafter(const Vectorized<float> &b) const {
|
| 277 |
+
return Vectorized<float>(Sleef_nextafterf8(values, b));
|
| 278 |
+
}
|
| 279 |
+
Vectorized<float> round() const {
|
| 280 |
+
return _mm256_round_ps(values, (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC));
|
| 281 |
+
}
|
| 282 |
+
Vectorized<float> tan() const {
|
| 283 |
+
return Vectorized<float>(Sleef_tanf8_u10(values));
|
| 284 |
+
}
|
| 285 |
+
Vectorized<float> tanh() const {
|
| 286 |
+
return Vectorized<float>(Sleef_tanhf8_u10(values));
|
| 287 |
+
}
|
| 288 |
+
Vectorized<float> trunc() const {
|
| 289 |
+
return _mm256_round_ps(values, (_MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC));
|
| 290 |
+
}
|
| 291 |
+
Vectorized<float> lgamma() const {
|
| 292 |
+
return Vectorized<float>(Sleef_lgammaf8_u10(values));
|
| 293 |
+
}
|
| 294 |
+
Vectorized<float> sqrt() const {
|
| 295 |
+
return _mm256_sqrt_ps(values);
|
| 296 |
+
}
|
| 297 |
+
Vectorized<float> reciprocal() const {
|
| 298 |
+
return _mm256_div_ps(_mm256_set1_ps(1), values);
|
| 299 |
+
}
|
| 300 |
+
Vectorized<float> rsqrt() const {
|
| 301 |
+
return _mm256_div_ps(_mm256_set1_ps(1), _mm256_sqrt_ps(values));
|
| 302 |
+
}
|
| 303 |
+
Vectorized<float> pow(const Vectorized<float> &b) const {
|
| 304 |
+
return Vectorized<float>(Sleef_powf8_u10(values, b));
|
| 305 |
+
}
|
| 306 |
+
// Comparison using the _CMP_**_OQ predicate.
|
| 307 |
+
// `O`: get false if an operand is NaN
|
| 308 |
+
// `Q`: do not raise if an operand is NaN
|
| 309 |
+
Vectorized<float> operator==(const Vectorized<float>& other) const {
|
| 310 |
+
return _mm256_cmp_ps(values, other.values, _CMP_EQ_OQ);
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
Vectorized<float> operator!=(const Vectorized<float>& other) const {
|
| 314 |
+
return _mm256_cmp_ps(values, other.values, _CMP_NEQ_UQ);
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
Vectorized<float> operator<(const Vectorized<float>& other) const {
|
| 318 |
+
return _mm256_cmp_ps(values, other.values, _CMP_LT_OQ);
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
Vectorized<float> operator<=(const Vectorized<float>& other) const {
|
| 322 |
+
return _mm256_cmp_ps(values, other.values, _CMP_LE_OQ);
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
Vectorized<float> operator>(const Vectorized<float>& other) const {
|
| 326 |
+
return _mm256_cmp_ps(values, other.values, _CMP_GT_OQ);
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
Vectorized<float> operator>=(const Vectorized<float>& other) const {
|
| 330 |
+
return _mm256_cmp_ps(values, other.values, _CMP_GE_OQ);
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
Vectorized<float> eq(const Vectorized<float>& other) const;
|
| 334 |
+
Vectorized<float> ne(const Vectorized<float>& other) const;
|
| 335 |
+
Vectorized<float> gt(const Vectorized<float>& other) const;
|
| 336 |
+
Vectorized<float> ge(const Vectorized<float>& other) const;
|
| 337 |
+
Vectorized<float> lt(const Vectorized<float>& other) const;
|
| 338 |
+
Vectorized<float> le(const Vectorized<float>& other) const;
|
| 339 |
+
};
|
| 340 |
+
|
| 341 |
+
template <>
|
| 342 |
+
Vectorized<float> inline operator+(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 343 |
+
return _mm256_add_ps(a, b);
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
template <>
|
| 347 |
+
Vectorized<float> inline operator-(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 348 |
+
return _mm256_sub_ps(a, b);
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
template <>
|
| 352 |
+
Vectorized<float> inline operator*(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 353 |
+
return _mm256_mul_ps(a, b);
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
template <>
|
| 357 |
+
Vectorized<float> inline operator/(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 358 |
+
return _mm256_div_ps(a, b);
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
// frac. Implement this here so we can use subtraction
|
| 362 |
+
inline Vectorized<float> Vectorized<float>::frac() const {
|
| 363 |
+
return *this - this->trunc();
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
// Implements the IEEE 754 201X `maximum` operation, which propagates NaN if
|
| 367 |
+
// either input is a NaN.
|
| 368 |
+
template <>
|
| 369 |
+
Vectorized<float> inline maximum(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 370 |
+
Vectorized<float> max = _mm256_max_ps(a, b);
|
| 371 |
+
Vectorized<float> isnan = _mm256_cmp_ps(a, b, _CMP_UNORD_Q);
|
| 372 |
+
// Exploit the fact that all-ones is a NaN.
|
| 373 |
+
return _mm256_or_ps(max, isnan);
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
// Implements the IEEE 754 201X `minimum` operation, which propagates NaN if
|
| 377 |
+
// either input is a NaN.
|
| 378 |
+
template <>
|
| 379 |
+
Vectorized<float> inline minimum(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 380 |
+
Vectorized<float> min = _mm256_min_ps(a, b);
|
| 381 |
+
Vectorized<float> isnan = _mm256_cmp_ps(a, b, _CMP_UNORD_Q);
|
| 382 |
+
// Exploit the fact that all-ones is a NaN.
|
| 383 |
+
return _mm256_or_ps(min, isnan);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
template <>
|
| 387 |
+
Vectorized<float> inline clamp(const Vectorized<float>& a, const Vectorized<float>& min, const Vectorized<float>& max) {
|
| 388 |
+
return _mm256_min_ps(max, _mm256_max_ps(min, a));
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
template <>
|
| 392 |
+
Vectorized<float> inline clamp_max(const Vectorized<float>& a, const Vectorized<float>& max) {
|
| 393 |
+
return _mm256_min_ps(max, a);
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
template <>
|
| 397 |
+
Vectorized<float> inline clamp_min(const Vectorized<float>& a, const Vectorized<float>& min) {
|
| 398 |
+
return _mm256_max_ps(min, a);
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
template <>
|
| 402 |
+
Vectorized<float> inline operator&(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 403 |
+
return _mm256_and_ps(a, b);
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
template <>
|
| 407 |
+
Vectorized<float> inline operator|(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 408 |
+
return _mm256_or_ps(a, b);
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
template <>
|
| 412 |
+
Vectorized<float> inline operator^(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 413 |
+
return _mm256_xor_ps(a, b);
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
inline Vectorized<float> Vectorized<float>::eq(const Vectorized<float>& other) const {
|
| 417 |
+
return (*this == other) & Vectorized<float>(1.0f);
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
inline Vectorized<float> Vectorized<float>::ne(const Vectorized<float>& other) const {
|
| 421 |
+
return (*this != other) & Vectorized<float>(1.0f);
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
inline Vectorized<float> Vectorized<float>::gt(const Vectorized<float>& other) const {
|
| 425 |
+
return (*this > other) & Vectorized<float>(1.0f);
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
inline Vectorized<float> Vectorized<float>::ge(const Vectorized<float>& other) const {
|
| 429 |
+
return (*this >= other) & Vectorized<float>(1.0f);
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
inline Vectorized<float> Vectorized<float>::lt(const Vectorized<float>& other) const {
|
| 433 |
+
return (*this < other) & Vectorized<float>(1.0f);
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
inline Vectorized<float> Vectorized<float>::le(const Vectorized<float>& other) const {
|
| 437 |
+
return (*this <= other) & Vectorized<float>(1.0f);
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
template <>
|
| 441 |
+
inline void convert(const float* src, float* dst, int64_t n) {
|
| 442 |
+
int64_t i;
|
| 443 |
+
#pragma unroll
|
| 444 |
+
for (i = 0; i <= (n - Vectorized<float>::size()); i += Vectorized<float>::size()) {
|
| 445 |
+
_mm256_storeu_ps(dst + i, _mm256_loadu_ps(src + i));
|
| 446 |
+
}
|
| 447 |
+
#pragma unroll
|
| 448 |
+
for (; i < n; i++) {
|
| 449 |
+
dst[i] = src[i];
|
| 450 |
+
}
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
template <>
|
| 455 |
+
Vectorized<float> inline fmadd(const Vectorized<float>& a, const Vectorized<float>& b, const Vectorized<float>& c) {
|
| 456 |
+
return _mm256_fmadd_ps(a, b, c);
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
template <>
|
| 460 |
+
Vectorized<float> inline fmsub(const Vectorized<float>& a, const Vectorized<float>& b, const Vectorized<float>& c) {
|
| 461 |
+
return _mm256_fmsub_ps(a, b, c);
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
// Used by Inductor CPP codegen
|
| 465 |
+
template<>
|
| 466 |
+
inline void transpose_mxn<float, 8, 8>(
|
| 467 |
+
const float* src,
|
| 468 |
+
int64_t ld_src,
|
| 469 |
+
float* dst,
|
| 470 |
+
int64_t ld_dst) {
|
| 471 |
+
// load from src to registers
|
| 472 |
+
// a: a0 a1 a2 a3 a4 a5 a6 a7
|
| 473 |
+
// b: b0 b1 b2 b3 b4 b5 b6 b7
|
| 474 |
+
// c: c0 c1 c2 c3 c4 c5 c6 c7
|
| 475 |
+
// d: d0 d1 d2 d3 d4 d5 d6 d7
|
| 476 |
+
// e: e0 e1 e2 e3 e4 e5 e6 e7
|
| 477 |
+
// f: f0 f1 f2 f3 f4 f5 f6 f7
|
| 478 |
+
// g: g0 g1 g2 g3 g4 g5 g6 g7
|
| 479 |
+
// h: h0 h1 h2 h3 h4 h5 h6 h7
|
| 480 |
+
__m256 a = _mm256_loadu_ps(&src[0 * ld_src]);
|
| 481 |
+
__m256 b = _mm256_loadu_ps(&src[1 * ld_src]);
|
| 482 |
+
__m256 c = _mm256_loadu_ps(&src[2 * ld_src]);
|
| 483 |
+
__m256 d = _mm256_loadu_ps(&src[3 * ld_src]);
|
| 484 |
+
__m256 e = _mm256_loadu_ps(&src[4 * ld_src]);
|
| 485 |
+
__m256 f = _mm256_loadu_ps(&src[5 * ld_src]);
|
| 486 |
+
__m256 g = _mm256_loadu_ps(&src[6 * ld_src]);
|
| 487 |
+
__m256 h = _mm256_loadu_ps(&src[7 * ld_src]);
|
| 488 |
+
|
| 489 |
+
__m256 ta, tb, tc, td, te, tf, tg, th;
|
| 490 |
+
// unpacking and interleaving 32-bit elements
|
| 491 |
+
// a0 b0 a1 b1 a4 b4 a5 b5
|
| 492 |
+
// a2 b2 a3 b3 a6 b6 a7 b7
|
| 493 |
+
// c0 d0 c1 d1 ...
|
| 494 |
+
// c2 d2 c3 d3 ...
|
| 495 |
+
// e0 f0 e1 f1 ...
|
| 496 |
+
// e2 f2 e3 f3 ...
|
| 497 |
+
// g0 h0 g1 h1 ...
|
| 498 |
+
// g2 h2 g3 h3 ...
|
| 499 |
+
ta = _mm256_unpacklo_ps(a, b);
|
| 500 |
+
tb = _mm256_unpackhi_ps(a, b);
|
| 501 |
+
tc = _mm256_unpacklo_ps(c, d);
|
| 502 |
+
td = _mm256_unpackhi_ps(c, d);
|
| 503 |
+
te = _mm256_unpacklo_ps(e, f);
|
| 504 |
+
tf = _mm256_unpackhi_ps(e, f);
|
| 505 |
+
tg = _mm256_unpacklo_ps(g, h);
|
| 506 |
+
th = _mm256_unpackhi_ps(g, h);
|
| 507 |
+
|
| 508 |
+
// unpacking and interleaving 64-bit elements
|
| 509 |
+
// a0 b0 c0 d0 a4 b4 c4 d4
|
| 510 |
+
// a1 b1 c1 d1 ...
|
| 511 |
+
// a2 b2 c2 d2 ...
|
| 512 |
+
// a3 b3 c3 d3 ...
|
| 513 |
+
// e0 f0 g0 h0 e4 f4 g4 h4
|
| 514 |
+
// e1 f1 g1 h1 ...
|
| 515 |
+
// e2 f2 g2 h2 ...
|
| 516 |
+
// e3 f3 g3 h3 ...
|
| 517 |
+
a = _mm256_castpd_ps(
|
| 518 |
+
_mm256_unpacklo_pd(_mm256_castps_pd(ta), _mm256_castps_pd(tc)));
|
| 519 |
+
b = _mm256_castpd_ps(
|
| 520 |
+
_mm256_unpackhi_pd(_mm256_castps_pd(ta), _mm256_castps_pd(tc)));
|
| 521 |
+
c = _mm256_castpd_ps(
|
| 522 |
+
_mm256_unpacklo_pd(_mm256_castps_pd(tb), _mm256_castps_pd(td)));
|
| 523 |
+
d = _mm256_castpd_ps(
|
| 524 |
+
_mm256_unpackhi_pd(_mm256_castps_pd(tb), _mm256_castps_pd(td)));
|
| 525 |
+
e = _mm256_castpd_ps(
|
| 526 |
+
_mm256_unpacklo_pd(_mm256_castps_pd(te), _mm256_castps_pd(tg)));
|
| 527 |
+
f = _mm256_castpd_ps(
|
| 528 |
+
_mm256_unpackhi_pd(_mm256_castps_pd(te), _mm256_castps_pd(tg)));
|
| 529 |
+
g = _mm256_castpd_ps(
|
| 530 |
+
_mm256_unpacklo_pd(_mm256_castps_pd(tf), _mm256_castps_pd(th)));
|
| 531 |
+
h = _mm256_castpd_ps(
|
| 532 |
+
_mm256_unpackhi_pd(_mm256_castps_pd(tf), _mm256_castps_pd(th)));
|
| 533 |
+
|
| 534 |
+
// shuffle 128-bits (composed of 4 32-bit elements)
|
| 535 |
+
// a0 b0 c0 d0 e0 f0 g0 h0
|
| 536 |
+
// a1 b1 c1 d1 ...
|
| 537 |
+
// a2 b2 c2 d2 ...
|
| 538 |
+
// a3 b3 c3 d3 ...
|
| 539 |
+
// a4 b4 c4 d4 ...
|
| 540 |
+
// a5 b5 c5 d5 ...
|
| 541 |
+
// a6 b6 c6 d6 ...
|
| 542 |
+
// a7 b7 c7 d7 ...
|
| 543 |
+
ta = _mm256_permute2f128_ps(a, e, 0x20);
|
| 544 |
+
tb = _mm256_permute2f128_ps(b, f, 0x20);
|
| 545 |
+
tc = _mm256_permute2f128_ps(c, g, 0x20);
|
| 546 |
+
td = _mm256_permute2f128_ps(d, h, 0x20);
|
| 547 |
+
te = _mm256_permute2f128_ps(a, e, 0x31);
|
| 548 |
+
tf = _mm256_permute2f128_ps(b, f, 0x31);
|
| 549 |
+
tg = _mm256_permute2f128_ps(c, g, 0x31);
|
| 550 |
+
th = _mm256_permute2f128_ps(d, h, 0x31);
|
| 551 |
+
|
| 552 |
+
// store from registers to dst
|
| 553 |
+
_mm256_storeu_ps(&dst[0 * ld_dst], ta);
|
| 554 |
+
_mm256_storeu_ps(&dst[1 * ld_dst], tb);
|
| 555 |
+
_mm256_storeu_ps(&dst[2 * ld_dst], tc);
|
| 556 |
+
_mm256_storeu_ps(&dst[3 * ld_dst], td);
|
| 557 |
+
_mm256_storeu_ps(&dst[4 * ld_dst], te);
|
| 558 |
+
_mm256_storeu_ps(&dst[5 * ld_dst], tf);
|
| 559 |
+
_mm256_storeu_ps(&dst[6 * ld_dst], tg);
|
| 560 |
+
_mm256_storeu_ps(&dst[7 * ld_dst], th);
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
#endif
|
| 564 |
+
|
| 565 |
+
}} // namespace at::vec::CPU_CAPABILITY
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vec256_float_neon.h
ADDED
|
@@ -0,0 +1,879 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ATIC DATA IN THIS HEADER!
|
| 4 |
+
// See Note [Do not compile initializers with AVX]
|
| 5 |
+
|
| 6 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 7 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 8 |
+
#include <c10/util/irange.h>
|
| 9 |
+
|
| 10 |
+
#if defined(__aarch64__) && defined(AT_BUILD_ARM_VEC256_WITH_SLEEF)
|
| 11 |
+
#include <sleef.h>
|
| 12 |
+
#endif
|
| 13 |
+
|
| 14 |
+
// Sleef offers vectorized versions of some transcedentals
|
| 15 |
+
// such as sin, cos, tan etc..
|
| 16 |
+
// However for now opting for STL, since we are not building
|
| 17 |
+
// with Sleef for mobile yet.
|
| 18 |
+
|
| 19 |
+
namespace at::vec {
|
| 20 |
+
// See Note [CPU_CAPABILITY namespace]
|
| 21 |
+
inline namespace CPU_CAPABILITY {
|
| 22 |
+
|
| 23 |
+
// Right now contains only aarch64 implementation.
|
| 24 |
+
// Due to follow two reasons aarch32 is not currently supported.
|
| 25 |
+
// 1. Due to difference in ISA been aarch32 and aarch64, intrinsics
|
| 26 |
+
// that work for aarch64 dont work for aarch32.
|
| 27 |
+
// 2. Android NDK r21 has problems with compiling aarch32.
|
| 28 |
+
// Clang seg faults.
|
| 29 |
+
// https://github.com/android/ndk/issues/1248
|
| 30 |
+
// https://bugs.llvm.org/show_bug.cgi?id=45824
|
| 31 |
+
// Most likely we will do aarch32 support with inline asm.
|
| 32 |
+
#if defined(__aarch64__)
|
| 33 |
+
|
| 34 |
+
#ifdef __BIG_ENDIAN__
|
| 35 |
+
#error "Big endian is not supported."
|
| 36 |
+
#endif
|
| 37 |
+
|
| 38 |
+
#if defined(AT_BUILD_ARM_VEC256_WITH_SLEEF)
|
| 39 |
+
#define USE_SLEEF(sleef_code, non_sleef_code) sleef_code
|
| 40 |
+
#else
|
| 41 |
+
#define USE_SLEEF(sleef_code, non_sleef_code) non_sleef_code
|
| 42 |
+
#endif
|
| 43 |
+
|
| 44 |
+
template<int index, bool mask_val>
|
| 45 |
+
struct BlendRegs {
|
| 46 |
+
static float32x4_t impl(
|
| 47 |
+
const float32x4_t& a, const float32x4_t& b, float32x4_t& res);
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
template<int index>
|
| 51 |
+
struct BlendRegs<index, true>{
|
| 52 |
+
static float32x4_t impl(
|
| 53 |
+
const float32x4_t& a, const float32x4_t& b, float32x4_t& res) {
|
| 54 |
+
return vsetq_lane_f32(vgetq_lane_f32(b, index), res, index);
|
| 55 |
+
}
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
template<int index>
|
| 59 |
+
struct BlendRegs<index, false>{
|
| 60 |
+
static float32x4_t impl(
|
| 61 |
+
const float32x4_t& a, const float32x4_t& b, float32x4_t& res) {
|
| 62 |
+
return vsetq_lane_f32(vgetq_lane_f32(a, index), res, index);
|
| 63 |
+
}
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
template <> class Vectorized<float> {
|
| 67 |
+
private:
|
| 68 |
+
float32x4x2_t values;
|
| 69 |
+
public:
|
| 70 |
+
using value_type = float;
|
| 71 |
+
using size_type = int;
|
| 72 |
+
static constexpr size_type size() {
|
| 73 |
+
return 8;
|
| 74 |
+
}
|
| 75 |
+
Vectorized() {}
|
| 76 |
+
Vectorized(float32x4x2_t v) : values(v) {}
|
| 77 |
+
Vectorized(float val) : values{vdupq_n_f32(val), vdupq_n_f32(val) } {}
|
| 78 |
+
Vectorized(float val0, float val1, float val2, float val3,
|
| 79 |
+
float val4, float val5, float val6, float val7) :
|
| 80 |
+
values{val0, val1, val2, val3, val4, val5, val6, val7} {}
|
| 81 |
+
Vectorized(float32x4_t val0, float32x4_t val1) : values{val0, val1} {}
|
| 82 |
+
operator float32x4x2_t() const {
|
| 83 |
+
return values;
|
| 84 |
+
}
|
| 85 |
+
template <int64_t mask>
|
| 86 |
+
static Vectorized<float> blend(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 87 |
+
Vectorized<float> vec;
|
| 88 |
+
// 0.
|
| 89 |
+
vec.values.val[0] =
|
| 90 |
+
BlendRegs<0, (mask & 0x01)!=0>::impl(
|
| 91 |
+
a.values.val[0], b.values.val[0], vec.values.val[0]);
|
| 92 |
+
vec.values.val[0] =
|
| 93 |
+
BlendRegs<1, (mask & 0x02)!=0>::impl(
|
| 94 |
+
a.values.val[0], b.values.val[0], vec.values.val[0]);
|
| 95 |
+
vec.values.val[0] =
|
| 96 |
+
BlendRegs<2, (mask & 0x04)!=0>::impl(
|
| 97 |
+
a.values.val[0], b.values.val[0], vec.values.val[0]);
|
| 98 |
+
vec.values.val[0] =
|
| 99 |
+
BlendRegs<3, (mask & 0x08)!=0>::impl(
|
| 100 |
+
a.values.val[0], b.values.val[0], vec.values.val[0]);
|
| 101 |
+
// 1.
|
| 102 |
+
vec.values.val[1] =
|
| 103 |
+
BlendRegs<0, (mask & 0x10)!=0>::impl(
|
| 104 |
+
a.values.val[1], b.values.val[1], vec.values.val[1]);
|
| 105 |
+
vec.values.val[1] =
|
| 106 |
+
BlendRegs<1, (mask & 0x20)!=0>::impl(
|
| 107 |
+
a.values.val[1], b.values.val[1], vec.values.val[1]);
|
| 108 |
+
vec.values.val[1] =
|
| 109 |
+
BlendRegs<2, (mask & 0x40)!=0>::impl(
|
| 110 |
+
a.values.val[1], b.values.val[1], vec.values.val[1]);
|
| 111 |
+
vec.values.val[1] =
|
| 112 |
+
BlendRegs<3, (mask & 0x80)!=0>::impl(
|
| 113 |
+
a.values.val[1], b.values.val[1], vec.values.val[1]);
|
| 114 |
+
return vec;
|
| 115 |
+
}
|
| 116 |
+
static Vectorized<float> blendv(const Vectorized<float>& a, const Vectorized<float>& b,
|
| 117 |
+
const Vectorized<float>& mask) {
|
| 118 |
+
// TODO
|
| 119 |
+
// NB: This requires that each value, i.e., each uint value,
|
| 120 |
+
// of the mask either all be zeros or all be 1s.
|
| 121 |
+
// We perhaps need some kind of an assert?
|
| 122 |
+
// But that will affect performance.
|
| 123 |
+
Vectorized<float> vec(mask.values);
|
| 124 |
+
vec.values.val[0] = vbslq_f32(
|
| 125 |
+
vreinterpretq_u32_f32(vec.values.val[0]),
|
| 126 |
+
b.values.val[0],
|
| 127 |
+
a.values.val[0]);
|
| 128 |
+
vec.values.val[1] = vbslq_f32(
|
| 129 |
+
vreinterpretq_u32_f32(vec.values.val[1]),
|
| 130 |
+
b.values.val[1],
|
| 131 |
+
a.values.val[1]);
|
| 132 |
+
return vec;
|
| 133 |
+
}
|
| 134 |
+
template<typename step_t>
|
| 135 |
+
static Vectorized<float> arange(float base = 0.f, step_t step = static_cast<step_t>(1)) {
|
| 136 |
+
const Vectorized<float> base_vec(base);
|
| 137 |
+
const Vectorized<float> step_vec(step);
|
| 138 |
+
const Vectorized<float> step_sizes(0, 1, 2, 3, 4, 5, 6, 7);
|
| 139 |
+
return fmadd(step_sizes, step_vec, base_vec);
|
| 140 |
+
}
|
| 141 |
+
static Vectorized<float> set(const Vectorized<float>& a, const Vectorized<float>& b,
|
| 142 |
+
int64_t count = size()) {
|
| 143 |
+
switch (count) {
|
| 144 |
+
case 0:
|
| 145 |
+
return a;
|
| 146 |
+
case 1:
|
| 147 |
+
{
|
| 148 |
+
Vectorized<float> vec;
|
| 149 |
+
static uint32x4_t mask_low = {0xFFFFFFFF, 0x0, 0x0, 0x0};
|
| 150 |
+
vec.values.val[0] = vreinterpretq_f32_u32(mask_low);
|
| 151 |
+
vec.values.val[1] = a.values.val[1];
|
| 152 |
+
vec.values.val[0] = vbslq_f32(
|
| 153 |
+
vreinterpretq_u32_f32(vec.values.val[0]),
|
| 154 |
+
b.values.val[0],
|
| 155 |
+
a.values.val[0]);
|
| 156 |
+
return vec;
|
| 157 |
+
}
|
| 158 |
+
case 2:
|
| 159 |
+
{
|
| 160 |
+
Vectorized<float> vec;
|
| 161 |
+
static uint32x4_t mask_low = {0xFFFFFFFF, 0xFFFFFFFF, 0x0, 0x0};
|
| 162 |
+
vec.values.val[0] = vreinterpretq_f32_u32(mask_low);
|
| 163 |
+
vec.values.val[1] = a.values.val[1];
|
| 164 |
+
vec.values.val[0] = vbslq_f32(
|
| 165 |
+
vreinterpretq_u32_f32(vec.values.val[0]),
|
| 166 |
+
b.values.val[0],
|
| 167 |
+
a.values.val[0]);
|
| 168 |
+
return vec;
|
| 169 |
+
}
|
| 170 |
+
case 3:
|
| 171 |
+
{
|
| 172 |
+
Vectorized<float> vec;
|
| 173 |
+
static uint32x4_t mask_low = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0};
|
| 174 |
+
vec.values.val[0] = vreinterpretq_f32_u32(mask_low);
|
| 175 |
+
vec.values.val[1] = a.values.val[1];
|
| 176 |
+
vec.values.val[0] = vbslq_f32(
|
| 177 |
+
vreinterpretq_u32_f32(vec.values.val[0]),
|
| 178 |
+
b.values.val[0],
|
| 179 |
+
a.values.val[0]);
|
| 180 |
+
return vec;
|
| 181 |
+
}
|
| 182 |
+
case 4:
|
| 183 |
+
return Vectorized<float>(b.values.val[0], a.values.val[1]);
|
| 184 |
+
case 5:
|
| 185 |
+
{
|
| 186 |
+
Vectorized<float> vec;
|
| 187 |
+
static uint32x4_t mask_high = {0xFFFFFFFF, 0x0, 0x0, 0x0};
|
| 188 |
+
vec.values.val[0] = b.values.val[0];
|
| 189 |
+
vec.values.val[1] = vreinterpretq_f32_u32(mask_high);
|
| 190 |
+
vec.values.val[1] = vbslq_f32(
|
| 191 |
+
vreinterpretq_u32_f32(vec.values.val[1]),
|
| 192 |
+
b.values.val[1],
|
| 193 |
+
a.values.val[1]);
|
| 194 |
+
return vec;
|
| 195 |
+
}
|
| 196 |
+
case 6:
|
| 197 |
+
{
|
| 198 |
+
Vectorized<float> vec;
|
| 199 |
+
static uint32x4_t mask_high = {0xFFFFFFFF, 0xFFFFFFFF, 0x0, 0x0};
|
| 200 |
+
vec.values.val[0] = b.values.val[0];
|
| 201 |
+
vec.values.val[1] = vreinterpretq_f32_u32(mask_high);
|
| 202 |
+
vec.values.val[1] = vbslq_f32(
|
| 203 |
+
vreinterpretq_u32_f32(vec.values.val[1]),
|
| 204 |
+
b.values.val[1],
|
| 205 |
+
a.values.val[1]);
|
| 206 |
+
return vec;
|
| 207 |
+
}
|
| 208 |
+
case 7:
|
| 209 |
+
{
|
| 210 |
+
Vectorized<float> vec;
|
| 211 |
+
static uint32x4_t mask_high = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0};
|
| 212 |
+
vec.values.val[0] = b.values.val[0];
|
| 213 |
+
vec.values.val[1] = vreinterpretq_f32_u32(mask_high);
|
| 214 |
+
vec.values.val[1] = vbslq_f32(
|
| 215 |
+
vreinterpretq_u32_f32(vec.values.val[1]),
|
| 216 |
+
b.values.val[1],
|
| 217 |
+
a.values.val[1]);
|
| 218 |
+
return vec;
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
return b;
|
| 222 |
+
}
|
| 223 |
+
static Vectorized<float> loadu(const void* ptr, int64_t count = size()) {
|
| 224 |
+
if (count == size()) {
|
| 225 |
+
return vld1q_f32_x2(reinterpret_cast<const float*>(ptr));
|
| 226 |
+
}
|
| 227 |
+
else if (count == (size() >> 1)) {
|
| 228 |
+
Vectorized<float> res;
|
| 229 |
+
res.values.val[0] = vld1q_f32(reinterpret_cast<const float*>(ptr));
|
| 230 |
+
res.values.val[1] = vdupq_n_f32(0.f);
|
| 231 |
+
return res;
|
| 232 |
+
}
|
| 233 |
+
else {
|
| 234 |
+
__at_align__ float tmp_values[size()];
|
| 235 |
+
for (const auto i : c10::irange(size())) {
|
| 236 |
+
tmp_values[i] = 0.0;
|
| 237 |
+
}
|
| 238 |
+
std::memcpy(
|
| 239 |
+
tmp_values,
|
| 240 |
+
reinterpret_cast<const float*>(ptr),
|
| 241 |
+
count * sizeof(float));
|
| 242 |
+
return vld1q_f32_x2(reinterpret_cast<const float*>(tmp_values));
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
void store(void* ptr, int64_t count = size()) const {
|
| 246 |
+
if (count == size()) {
|
| 247 |
+
vst1q_f32_x2(reinterpret_cast<float*>(ptr), values);
|
| 248 |
+
}
|
| 249 |
+
else if (count == (size() >> 1)) {
|
| 250 |
+
vst1q_f32(reinterpret_cast<float*>(ptr), values.val[0]);
|
| 251 |
+
}
|
| 252 |
+
else {
|
| 253 |
+
float tmp_values[size()];
|
| 254 |
+
vst1q_f32_x2(reinterpret_cast<float*>(tmp_values), values);
|
| 255 |
+
std::memcpy(ptr, tmp_values, count * sizeof(float));
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
+
inline const float32x4_t& get_low() const {
|
| 259 |
+
return values.val[0];
|
| 260 |
+
}
|
| 261 |
+
inline float32x4_t& get_low() {
|
| 262 |
+
return values.val[0];
|
| 263 |
+
}
|
| 264 |
+
inline const float32x4_t& get_high() const {
|
| 265 |
+
return values.val[1];
|
| 266 |
+
}
|
| 267 |
+
inline float32x4_t& get_high() {
|
| 268 |
+
return values.val[1];
|
| 269 |
+
}
|
| 270 |
+
// Very slow implementation of indexing.
|
| 271 |
+
// Only required because vec256_qint refers to this.
|
| 272 |
+
// Once we specialize that implementation for ARM
|
| 273 |
+
// this should be removed. TODO (kimishpatel)
|
| 274 |
+
float operator[](int idx) const {
|
| 275 |
+
__at_align__ float tmp[size()];
|
| 276 |
+
store(tmp);
|
| 277 |
+
return tmp[idx];
|
| 278 |
+
}
|
| 279 |
+
float operator[](int idx) {
|
| 280 |
+
__at_align__ float tmp[size()];
|
| 281 |
+
store(tmp);
|
| 282 |
+
return tmp[idx];
|
| 283 |
+
}
|
| 284 |
+
// For boolean version where we want to if any 1/all zero
|
| 285 |
+
// etc. can be done faster in a different way.
|
| 286 |
+
int zero_mask() const {
|
| 287 |
+
__at_align__ float tmp[size()];
|
| 288 |
+
store(tmp);
|
| 289 |
+
int mask = 0;
|
| 290 |
+
for (int i = 0; i < size(); ++ i) {
|
| 291 |
+
if (tmp[i] == 0.f) {
|
| 292 |
+
mask |= (1 << i);
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
return mask;
|
| 296 |
+
}
|
| 297 |
+
Vectorized<float> isnan() const {
|
| 298 |
+
__at_align__ float tmp[size()];
|
| 299 |
+
__at_align__ float res[size()];
|
| 300 |
+
store(tmp);
|
| 301 |
+
for (const auto i : c10::irange(size())) {
|
| 302 |
+
if (_isnan(tmp[i])) {
|
| 303 |
+
std::memset(static_cast<void*>(&res[i]), 0xFF, sizeof(float));
|
| 304 |
+
} else {
|
| 305 |
+
std::memset(static_cast<void*>(&res[i]), 0, sizeof(float));
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
return loadu(res);
|
| 309 |
+
};
|
| 310 |
+
Vectorized<float> map(float (*const f)(float)) const {
|
| 311 |
+
__at_align__ float tmp[size()];
|
| 312 |
+
store(tmp);
|
| 313 |
+
for (const auto i : c10::irange(size())) {
|
| 314 |
+
tmp[i] = f(tmp[i]);
|
| 315 |
+
}
|
| 316 |
+
return loadu(tmp);
|
| 317 |
+
}
|
| 318 |
+
Vectorized<float> abs() const {
|
| 319 |
+
return Vectorized<float>(vabsq_f32(values.val[0]), vabsq_f32(values.val[1]));
|
| 320 |
+
}
|
| 321 |
+
Vectorized<float> angle() const {
|
| 322 |
+
auto zero = Vectorized<float>(0);
|
| 323 |
+
auto pi = Vectorized<float>(c10::pi<float>);
|
| 324 |
+
auto tmp = blendv(zero, pi, *this < zero);
|
| 325 |
+
return blendv(tmp, *this, isnan());
|
| 326 |
+
}
|
| 327 |
+
Vectorized<float> real() const {
|
| 328 |
+
return *this;
|
| 329 |
+
}
|
| 330 |
+
Vectorized<float> imag() const {
|
| 331 |
+
return Vectorized<float>(0.f);
|
| 332 |
+
}
|
| 333 |
+
Vectorized<float> conj() const {
|
| 334 |
+
return *this;
|
| 335 |
+
}
|
| 336 |
+
Vectorized<float> acos() const {
|
| 337 |
+
return USE_SLEEF(
|
| 338 |
+
Vectorized<float>(Sleef_acosf4_u10(values.val[0]), Sleef_acosf4_u10(values.val[1])),
|
| 339 |
+
map(std::acos)
|
| 340 |
+
);
|
| 341 |
+
}
|
| 342 |
+
Vectorized<float> asin() const {
|
| 343 |
+
return USE_SLEEF(
|
| 344 |
+
Vectorized<float>(Sleef_asinf4_u10(values.val[0]), Sleef_asinf4_u10(values.val[1])),
|
| 345 |
+
map(std::asin)
|
| 346 |
+
);
|
| 347 |
+
}
|
| 348 |
+
Vectorized<float> atan() const {
|
| 349 |
+
return USE_SLEEF(
|
| 350 |
+
Vectorized<float>(Sleef_atanf4_u10(values.val[0]), Sleef_atanf4_u10(values.val[1])),
|
| 351 |
+
map(std::atan)
|
| 352 |
+
);
|
| 353 |
+
}
|
| 354 |
+
Vectorized<float> atanh() const {
|
| 355 |
+
return USE_SLEEF(
|
| 356 |
+
Vectorized<float>(Sleef_atanhf4_u10(values.val[0]), Sleef_atanhf4_u10(values.val[1])),
|
| 357 |
+
map(std::atanh)
|
| 358 |
+
);
|
| 359 |
+
}
|
| 360 |
+
Vectorized<float> atan2(const Vectorized<float> &exp) const {
|
| 361 |
+
USE_SLEEF(
|
| 362 |
+
{
|
| 363 |
+
return Vectorized<float>(Sleef_atan2f4_u10(values.val[0], exp.values.val[0]),
|
| 364 |
+
Sleef_atan2f4_u10(values.val[1], exp.values.val[1]));
|
| 365 |
+
},
|
| 366 |
+
{
|
| 367 |
+
__at_align__ float tmp[size()];
|
| 368 |
+
__at_align__ float tmp_exp[size()];
|
| 369 |
+
store(tmp);
|
| 370 |
+
exp.store(tmp_exp);
|
| 371 |
+
for (const auto i : c10::irange(size())) {
|
| 372 |
+
tmp[i] = std::atan2(tmp[i], tmp_exp[i]);
|
| 373 |
+
}
|
| 374 |
+
return loadu(tmp);
|
| 375 |
+
}
|
| 376 |
+
)
|
| 377 |
+
}
|
| 378 |
+
Vectorized<float> copysign(const Vectorized<float> &sign) const {
|
| 379 |
+
USE_SLEEF(
|
| 380 |
+
{
|
| 381 |
+
return Vectorized<float>(Sleef_copysignf4(values.val[0], sign.values.val[0]),
|
| 382 |
+
Sleef_copysignf4(values.val[1], sign.values.val[1]));
|
| 383 |
+
},
|
| 384 |
+
{
|
| 385 |
+
__at_align__ float tmp[size()];
|
| 386 |
+
__at_align__ float tmp_sign[size()];
|
| 387 |
+
store(tmp);
|
| 388 |
+
sign.store(tmp_sign);
|
| 389 |
+
for (size_type i = 0; i < size(); i++) {
|
| 390 |
+
tmp[i] = std::copysign(tmp[i], tmp_sign[i]);
|
| 391 |
+
}
|
| 392 |
+
return loadu(tmp);
|
| 393 |
+
}
|
| 394 |
+
)
|
| 395 |
+
}
|
| 396 |
+
Vectorized<float> erf() const;
|
| 397 |
+
Vectorized<float> erfc() const {
|
| 398 |
+
return USE_SLEEF(
|
| 399 |
+
Vectorized<float>(Sleef_erfcf4_u15(values.val[0]), Sleef_erfcf4_u15(values.val[1])),
|
| 400 |
+
map(std::erfc)
|
| 401 |
+
);
|
| 402 |
+
}
|
| 403 |
+
Vectorized<float> erfinv() const {
|
| 404 |
+
return map(calc_erfinv);
|
| 405 |
+
}
|
| 406 |
+
Vectorized<float> exp() const {
|
| 407 |
+
return USE_SLEEF(
|
| 408 |
+
Vectorized<float>(Sleef_expf4_u10(values.val[0]), Sleef_expf4_u10(values.val[1])),
|
| 409 |
+
map(std::exp)
|
| 410 |
+
);
|
| 411 |
+
}
|
| 412 |
+
Vectorized<float> exp2() const {
|
| 413 |
+
return USE_SLEEF(
|
| 414 |
+
Vectorized<float>(Sleef_exp2f4_u10(values.val[0]), Sleef_exp2f4_u10(values.val[1])),
|
| 415 |
+
map(std::exp2)
|
| 416 |
+
);
|
| 417 |
+
}
|
| 418 |
+
Vectorized<float> expm1() const {
|
| 419 |
+
return USE_SLEEF(
|
| 420 |
+
Vectorized<float>(Sleef_expm1f4_u10(values.val[0]), Sleef_expm1f4_u10(values.val[1])),
|
| 421 |
+
map(std::expm1)
|
| 422 |
+
);
|
| 423 |
+
}
|
| 424 |
+
Vectorized<float> fmod(const Vectorized<float>& q) const {
|
| 425 |
+
USE_SLEEF(
|
| 426 |
+
{
|
| 427 |
+
return Vectorized<float>(Sleef_fmodf4(values.val[0], q.values.val[0]),
|
| 428 |
+
Sleef_fmodf4(values.val[1], q.values.val[1]));
|
| 429 |
+
},
|
| 430 |
+
{
|
| 431 |
+
__at_align__ float tmp[size()];
|
| 432 |
+
__at_align__ float tmp_q[size()];
|
| 433 |
+
store(tmp);
|
| 434 |
+
q.store(tmp_q);
|
| 435 |
+
for (const auto i : c10::irange(size())) {
|
| 436 |
+
tmp[i] = std::fmod(tmp[i], tmp_q[i]);
|
| 437 |
+
}
|
| 438 |
+
return loadu(tmp);
|
| 439 |
+
}
|
| 440 |
+
)
|
| 441 |
+
}
|
| 442 |
+
Vectorized<float> hypot(const Vectorized<float> &b) const {
|
| 443 |
+
USE_SLEEF(
|
| 444 |
+
{
|
| 445 |
+
return Vectorized<float>(Sleef_hypotf4_u05(values.val[0], b.values.val[0]),
|
| 446 |
+
Sleef_hypotf4_u05(values.val[1], b.values.val[1]));
|
| 447 |
+
},
|
| 448 |
+
{
|
| 449 |
+
__at_align__ float tmp[size()];
|
| 450 |
+
__at_align__ float tmp_b[size()];
|
| 451 |
+
store(tmp);
|
| 452 |
+
b.store(tmp_b);
|
| 453 |
+
for (const auto i : c10::irange(size())) {
|
| 454 |
+
tmp[i] = std::hypot(tmp[i], tmp_b[i]);
|
| 455 |
+
}
|
| 456 |
+
return loadu(tmp);
|
| 457 |
+
}
|
| 458 |
+
)
|
| 459 |
+
}
|
| 460 |
+
Vectorized<float> i0() const {
|
| 461 |
+
return map(calc_i0);
|
| 462 |
+
}
|
| 463 |
+
Vectorized<float> i0e() const {
|
| 464 |
+
return map(calc_i0e);
|
| 465 |
+
}
|
| 466 |
+
Vectorized<float> digamma() const {
|
| 467 |
+
return map(calc_digamma);
|
| 468 |
+
}
|
| 469 |
+
Vectorized<float> igamma(const Vectorized<float> &x) const {
|
| 470 |
+
__at_align__ float tmp[size()];
|
| 471 |
+
__at_align__ float tmp_x[size()];
|
| 472 |
+
store(tmp);
|
| 473 |
+
x.store(tmp_x);
|
| 474 |
+
for (const auto i : c10::irange(size())) {
|
| 475 |
+
tmp[i] = calc_igamma(tmp[i], tmp_x[i]);
|
| 476 |
+
}
|
| 477 |
+
return loadu(tmp);
|
| 478 |
+
}
|
| 479 |
+
Vectorized<float> igammac(const Vectorized<float> &x) const {
|
| 480 |
+
__at_align__ float tmp[size()];
|
| 481 |
+
__at_align__ float tmp_x[size()];
|
| 482 |
+
store(tmp);
|
| 483 |
+
x.store(tmp_x);
|
| 484 |
+
for (const auto i : c10::irange(size())) {
|
| 485 |
+
tmp[i] = calc_igammac(tmp[i], tmp_x[i]);
|
| 486 |
+
}
|
| 487 |
+
return loadu(tmp);
|
| 488 |
+
}
|
| 489 |
+
Vectorized<float> log() const {
|
| 490 |
+
return USE_SLEEF(
|
| 491 |
+
Vectorized<float>(Sleef_logf4_u10(values.val[0]), Sleef_logf4_u10(values.val[1])),
|
| 492 |
+
map(std::log)
|
| 493 |
+
);
|
| 494 |
+
}
|
| 495 |
+
Vectorized<float> log10() const {
|
| 496 |
+
return USE_SLEEF(
|
| 497 |
+
Vectorized<float>(Sleef_log10f4_u10(values.val[0]), Sleef_log10f4_u10(values.val[1])),
|
| 498 |
+
map(std::log10)
|
| 499 |
+
);
|
| 500 |
+
}
|
| 501 |
+
Vectorized<float> log1p() const {
|
| 502 |
+
return USE_SLEEF(
|
| 503 |
+
Vectorized<float>(Sleef_log1pf4_u10(values.val[0]), Sleef_log1pf4_u10(values.val[1])),
|
| 504 |
+
map(std::log1p)
|
| 505 |
+
);
|
| 506 |
+
}
|
| 507 |
+
Vectorized<float> log2() const {
|
| 508 |
+
return USE_SLEEF(
|
| 509 |
+
Vectorized<float>(Sleef_log2f4_u10(values.val[0]), Sleef_log2f4_u10(values.val[1])),
|
| 510 |
+
map(std::log2)
|
| 511 |
+
);
|
| 512 |
+
}
|
| 513 |
+
Vectorized<float> nextafter(const Vectorized<float> &b) const {
|
| 514 |
+
USE_SLEEF(
|
| 515 |
+
{
|
| 516 |
+
return Vectorized<float>(Sleef_nextafterf4(values.val[0], b.values.val[0]),
|
| 517 |
+
Sleef_nextafterf4(values.val[1], b.values.val[1]));
|
| 518 |
+
},
|
| 519 |
+
{
|
| 520 |
+
__at_align__ float tmp[size()];
|
| 521 |
+
__at_align__ float tmp_b[size()];
|
| 522 |
+
store(tmp);
|
| 523 |
+
b.store(tmp_b);
|
| 524 |
+
for (const auto i : c10::irange(size())) {
|
| 525 |
+
tmp[i] = std::nextafter(tmp[i], tmp_b[i]);
|
| 526 |
+
}
|
| 527 |
+
return loadu(tmp);
|
| 528 |
+
}
|
| 529 |
+
)
|
| 530 |
+
}
|
| 531 |
+
Vectorized<float> frac() const;
|
| 532 |
+
Vectorized<float> sin() const {
|
| 533 |
+
return USE_SLEEF(
|
| 534 |
+
Vectorized<float>(Sleef_sinf4_u10(values.val[0]), Sleef_sinf4_u10(values.val[1])),
|
| 535 |
+
map(std::sin)
|
| 536 |
+
);
|
| 537 |
+
}
|
| 538 |
+
Vectorized<float> sinh() const {
|
| 539 |
+
return USE_SLEEF(
|
| 540 |
+
Vectorized<float>(Sleef_sinhf4_u10(values.val[0]), Sleef_sinhf4_u10(values.val[1])),
|
| 541 |
+
map(std::sinh)
|
| 542 |
+
);
|
| 543 |
+
}
|
| 544 |
+
Vectorized<float> cos() const {
|
| 545 |
+
return USE_SLEEF(
|
| 546 |
+
Vectorized<float>(Sleef_cosf4_u10(values.val[0]), Sleef_cosf4_u10(values.val[1])),
|
| 547 |
+
map(std::cos)
|
| 548 |
+
);
|
| 549 |
+
}
|
| 550 |
+
Vectorized<float> cosh() const {
|
| 551 |
+
return USE_SLEEF(
|
| 552 |
+
Vectorized<float>(Sleef_coshf4_u10(values.val[0]), Sleef_coshf4_u10(values.val[1])),
|
| 553 |
+
map(std::cosh)
|
| 554 |
+
);
|
| 555 |
+
}
|
| 556 |
+
Vectorized<float> ceil() const {
|
| 557 |
+
return map(at::native::ceil_impl);
|
| 558 |
+
}
|
| 559 |
+
Vectorized<float> floor() const {
|
| 560 |
+
return map(at::native::floor_impl);
|
| 561 |
+
}
|
| 562 |
+
Vectorized<float> neg() const {
|
| 563 |
+
return Vectorized<float>(
|
| 564 |
+
vnegq_f32(values.val[0]),
|
| 565 |
+
vnegq_f32(values.val[1]));
|
| 566 |
+
}
|
| 567 |
+
Vectorized<float> round() const {
|
| 568 |
+
// We do not use std::round because we would like to round midway numbers to the nearest even integer.
|
| 569 |
+
return map(at::native::round_impl);
|
| 570 |
+
}
|
| 571 |
+
Vectorized<float> tan() const {
|
| 572 |
+
return USE_SLEEF(
|
| 573 |
+
Vectorized<float>(Sleef_tanf4_u10(values.val[0]), Sleef_tanf4_u10(values.val[1])),
|
| 574 |
+
map(std::tan)
|
| 575 |
+
);
|
| 576 |
+
}
|
| 577 |
+
Vectorized<float> tanh() const {
|
| 578 |
+
return USE_SLEEF(
|
| 579 |
+
Vectorized<float>(Sleef_tanhf4_u10(values.val[0]), Sleef_tanhf4_u10(values.val[1])),
|
| 580 |
+
map(std::tanh)
|
| 581 |
+
);
|
| 582 |
+
}
|
| 583 |
+
Vectorized<float> trunc() const {
|
| 584 |
+
float32x4_t r0 = vrndq_f32(values.val[0]);
|
| 585 |
+
float32x4_t r1 = vrndq_f32(values.val[1]);
|
| 586 |
+
return Vectorized<float>(r0, r1);
|
| 587 |
+
}
|
| 588 |
+
Vectorized<float> lgamma() const {
|
| 589 |
+
return USE_SLEEF(
|
| 590 |
+
Vectorized<float>(Sleef_lgammaf4_u10(values.val[0]), Sleef_lgammaf4_u10(values.val[1])),
|
| 591 |
+
map(std::lgamma)
|
| 592 |
+
);
|
| 593 |
+
}
|
| 594 |
+
Vectorized<float> sqrt() const {
|
| 595 |
+
return Vectorized<float>(
|
| 596 |
+
vsqrtq_f32(values.val[0]),
|
| 597 |
+
vsqrtq_f32(values.val[1]));
|
| 598 |
+
}
|
| 599 |
+
Vectorized<float> reciprocal() const {
|
| 600 |
+
auto r0 = vdivq_f32(vdupq_n_f32(1.0f), values.val[0]);
|
| 601 |
+
auto r1 = vdivq_f32(vdupq_n_f32(1.0f), values.val[1]);
|
| 602 |
+
return Vectorized<float>(r0, r1);
|
| 603 |
+
}
|
| 604 |
+
Vectorized<float> rsqrt() const {
|
| 605 |
+
return this->sqrt().reciprocal();
|
| 606 |
+
}
|
| 607 |
+
Vectorized<float> pow(const Vectorized<float> &exp) const {
|
| 608 |
+
USE_SLEEF(
|
| 609 |
+
{
|
| 610 |
+
return Vectorized<float>(Sleef_powf4_u10(values.val[0], exp.values.val[0]),
|
| 611 |
+
Sleef_powf4_u10(values.val[1], exp.values.val[1]));
|
| 612 |
+
},
|
| 613 |
+
{
|
| 614 |
+
__at_align__ float tmp[size()];
|
| 615 |
+
__at_align__ float tmp_exp[size()];
|
| 616 |
+
store(tmp);
|
| 617 |
+
exp.store(tmp_exp);
|
| 618 |
+
for (const auto i : c10::irange(size())) {
|
| 619 |
+
tmp[i] = std::pow(tmp[i], tmp_exp[i]);
|
| 620 |
+
}
|
| 621 |
+
return loadu(tmp);
|
| 622 |
+
}
|
| 623 |
+
)
|
| 624 |
+
}
|
| 625 |
+
Vectorized<float> operator==(const Vectorized<float>& other) const {
|
| 626 |
+
float32x4_t r0 =
|
| 627 |
+
vreinterpretq_f32_u32(vceqq_f32(values.val[0], other.values.val[0]));
|
| 628 |
+
float32x4_t r1 =
|
| 629 |
+
vreinterpretq_f32_u32(vceqq_f32(values.val[1], other.values.val[1]));
|
| 630 |
+
return Vectorized<float>(r0, r1);
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
Vectorized<float> operator!=(const Vectorized<float>& other) const {
|
| 634 |
+
float32x4_t r0 = vreinterpretq_f32_u32(
|
| 635 |
+
vmvnq_u32(vceqq_f32(values.val[0], other.values.val[0])));
|
| 636 |
+
float32x4_t r1 = vreinterpretq_f32_u32(
|
| 637 |
+
vmvnq_u32(vceqq_f32(values.val[1], other.values.val[1])));
|
| 638 |
+
return Vectorized<float>(r0, r1);
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
Vectorized<float> operator<(const Vectorized<float>& other) const {
|
| 642 |
+
float32x4_t r0 =
|
| 643 |
+
vreinterpretq_f32_u32(vcltq_f32(values.val[0], other.values.val[0]));
|
| 644 |
+
float32x4_t r1 =
|
| 645 |
+
vreinterpretq_f32_u32(vcltq_f32(values.val[1], other.values.val[1]));
|
| 646 |
+
return Vectorized<float>(r0, r1);
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
Vectorized<float> operator<=(const Vectorized<float>& other) const {
|
| 650 |
+
float32x4_t r0 =
|
| 651 |
+
vreinterpretq_f32_u32(vcleq_f32(values.val[0], other.values.val[0]));
|
| 652 |
+
float32x4_t r1 =
|
| 653 |
+
vreinterpretq_f32_u32(vcleq_f32(values.val[1], other.values.val[1]));
|
| 654 |
+
return Vectorized<float>(r0, r1);
|
| 655 |
+
}
|
| 656 |
+
|
| 657 |
+
Vectorized<float> operator>(const Vectorized<float>& other) const {
|
| 658 |
+
float32x4_t r0 =
|
| 659 |
+
vreinterpretq_f32_u32(vcgtq_f32(values.val[0], other.values.val[0]));
|
| 660 |
+
float32x4_t r1 =
|
| 661 |
+
vreinterpretq_f32_u32(vcgtq_f32(values.val[1], other.values.val[1]));
|
| 662 |
+
return Vectorized<float>(r0, r1);
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
Vectorized<float> operator>=(const Vectorized<float>& other) const {
|
| 666 |
+
float32x4_t r0 =
|
| 667 |
+
vreinterpretq_f32_u32(vcgeq_f32(values.val[0], other.values.val[0]));
|
| 668 |
+
float32x4_t r1 =
|
| 669 |
+
vreinterpretq_f32_u32(vcgeq_f32(values.val[1], other.values.val[1]));
|
| 670 |
+
return Vectorized<float>(r0, r1);
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
Vectorized<float> eq(const Vectorized<float>& other) const;
|
| 674 |
+
Vectorized<float> ne(const Vectorized<float>& other) const;
|
| 675 |
+
Vectorized<float> gt(const Vectorized<float>& other) const;
|
| 676 |
+
Vectorized<float> ge(const Vectorized<float>& other) const;
|
| 677 |
+
Vectorized<float> lt(const Vectorized<float>& other) const;
|
| 678 |
+
Vectorized<float> le(const Vectorized<float>& other) const;
|
| 679 |
+
};
|
| 680 |
+
|
| 681 |
+
template <>
|
| 682 |
+
Vectorized<float> inline operator+(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 683 |
+
float32x4_t r0 = vaddq_f32(a.get_low(), b.get_low());
|
| 684 |
+
float32x4_t r1 = vaddq_f32(a.get_high(), b.get_high());
|
| 685 |
+
return Vectorized<float>(r0, r1);
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
template <>
|
| 689 |
+
Vectorized<float> inline operator-(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 690 |
+
float32x4_t r0 = vsubq_f32(a.get_low(), b.get_low());
|
| 691 |
+
float32x4_t r1 = vsubq_f32(a.get_high(), b.get_high());
|
| 692 |
+
return Vectorized<float>(r0, r1);
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
template <>
|
| 696 |
+
Vectorized<float> inline operator*(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 697 |
+
float32x4_t r0 = vmulq_f32(a.get_low(), b.get_low());
|
| 698 |
+
float32x4_t r1 = vmulq_f32(a.get_high(), b.get_high());
|
| 699 |
+
return Vectorized<float>(r0, r1);
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
template <>
|
| 703 |
+
Vectorized<float> inline operator/(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 704 |
+
float32x4_t r0 = vdivq_f32(a.get_low(), b.get_low());
|
| 705 |
+
float32x4_t r1 = vdivq_f32(a.get_high(), b.get_high());
|
| 706 |
+
return Vectorized<float>(r0, r1);
|
| 707 |
+
}
|
| 708 |
+
|
| 709 |
+
// frac. Implement this here so we can use subtraction
|
| 710 |
+
inline Vectorized<float> Vectorized<float>::frac() const {
|
| 711 |
+
return *this - this->trunc();
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
// Implements the IEEE 754 201X `maximum` operation, which propagates NaN if
|
| 715 |
+
// either input is a NaN.
|
| 716 |
+
template <>
|
| 717 |
+
Vectorized<float> inline maximum(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 718 |
+
float32x4_t r0 = vmaxq_f32(a.get_low(), b.get_low());
|
| 719 |
+
float32x4_t r1 = vmaxq_f32(a.get_high(), b.get_high());
|
| 720 |
+
return Vectorized<float>(r0, r1);
|
| 721 |
+
}
|
| 722 |
+
|
| 723 |
+
// Implements the IEEE 754 201X `minimum` operation, which propagates NaN if
|
| 724 |
+
// either input is a NaN.
|
| 725 |
+
template <>
|
| 726 |
+
Vectorized<float> inline minimum(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 727 |
+
float32x4_t r0 = vminq_f32(a.get_low(), b.get_low());
|
| 728 |
+
float32x4_t r1 = vminq_f32(a.get_high(), b.get_high());
|
| 729 |
+
return Vectorized<float>(r0, r1);
|
| 730 |
+
}
|
| 731 |
+
|
| 732 |
+
template <>
|
| 733 |
+
Vectorized<float> inline clamp(const Vectorized<float>& a, const Vectorized<float>& min, const Vectorized<float>& max) {
|
| 734 |
+
return minimum(max, maximum(min, a));
|
| 735 |
+
}
|
| 736 |
+
|
| 737 |
+
template <>
|
| 738 |
+
Vectorized<float> inline clamp_max(const Vectorized<float>& a, const Vectorized<float>& max) {
|
| 739 |
+
return minimum(max, a);
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
template <>
|
| 743 |
+
Vectorized<float> inline clamp_min(const Vectorized<float>& a, const Vectorized<float>& min) {
|
| 744 |
+
return maximum(min, a);
|
| 745 |
+
}
|
| 746 |
+
|
| 747 |
+
template <>
|
| 748 |
+
Vectorized<float> inline operator&(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 749 |
+
float32x4_t r0 = vreinterpretq_f32_u32(vandq_u32(
|
| 750 |
+
vreinterpretq_u32_f32(a.get_low()),
|
| 751 |
+
vreinterpretq_u32_f32(b.get_low())));
|
| 752 |
+
float32x4_t r1 = vreinterpretq_f32_u32(vandq_u32(
|
| 753 |
+
vreinterpretq_u32_f32(a.get_high()),
|
| 754 |
+
vreinterpretq_u32_f32(b.get_high())));
|
| 755 |
+
return Vectorized<float>(r0, r1);
|
| 756 |
+
}
|
| 757 |
+
|
| 758 |
+
template <>
|
| 759 |
+
Vectorized<float> inline operator|(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 760 |
+
float32x4_t r0 = vreinterpretq_f32_u32(vorrq_u32(
|
| 761 |
+
vreinterpretq_u32_f32(a.get_low()),
|
| 762 |
+
vreinterpretq_u32_f32(b.get_low())));
|
| 763 |
+
float32x4_t r1 = vreinterpretq_f32_u32(vorrq_u32(
|
| 764 |
+
vreinterpretq_u32_f32(a.get_high()),
|
| 765 |
+
vreinterpretq_u32_f32(b.get_high())));
|
| 766 |
+
return Vectorized<float>(r0, r1);
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
template <>
|
| 770 |
+
Vectorized<float> inline operator^(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 771 |
+
float32x4_t r0 = vreinterpretq_f32_u32(veorq_u32(
|
| 772 |
+
vreinterpretq_u32_f32(a.get_low()),
|
| 773 |
+
vreinterpretq_u32_f32(b.get_low())));
|
| 774 |
+
float32x4_t r1 = vreinterpretq_f32_u32(veorq_u32(
|
| 775 |
+
vreinterpretq_u32_f32(a.get_high()),
|
| 776 |
+
vreinterpretq_u32_f32(b.get_high())));
|
| 777 |
+
return Vectorized<float>(r0, r1);
|
| 778 |
+
}
|
| 779 |
+
|
| 780 |
+
inline Vectorized<float> Vectorized<float>::eq(const Vectorized<float>& other) const {
|
| 781 |
+
return (*this == other) & Vectorized<float>(1.0f);
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
inline Vectorized<float> Vectorized<float>::ne(const Vectorized<float>& other) const {
|
| 785 |
+
return (*this != other) & Vectorized<float>(1.0f);
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
inline Vectorized<float> Vectorized<float>::gt(const Vectorized<float>& other) const {
|
| 789 |
+
return (*this > other) & Vectorized<float>(1.0f);
|
| 790 |
+
}
|
| 791 |
+
|
| 792 |
+
inline Vectorized<float> Vectorized<float>::ge(const Vectorized<float>& other) const {
|
| 793 |
+
return (*this >= other) & Vectorized<float>(1.0f);
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
inline Vectorized<float> Vectorized<float>::lt(const Vectorized<float>& other) const {
|
| 797 |
+
return (*this < other) & Vectorized<float>(1.0f);
|
| 798 |
+
}
|
| 799 |
+
|
| 800 |
+
inline Vectorized<float> Vectorized<float>::le(const Vectorized<float>& other) const {
|
| 801 |
+
return (*this <= other) & Vectorized<float>(1.0f);
|
| 802 |
+
}
|
| 803 |
+
|
| 804 |
+
template <>
|
| 805 |
+
inline void convert(const float* src, int32_t* dst, int64_t n) {
|
| 806 |
+
int64_t i;
|
| 807 |
+
#pragma unroll
|
| 808 |
+
for (i = 0; i <= (n - Vectorized<float>::size()); i += Vectorized<float>::size()) {
|
| 809 |
+
vst1q_s32(dst + i, vcvtq_s32_f32(vld1q_f32(src + i)));
|
| 810 |
+
vst1q_s32(dst + i + 4, vcvtq_s32_f32(vld1q_f32(src + i + 4)));
|
| 811 |
+
}
|
| 812 |
+
#pragma unroll
|
| 813 |
+
for (; i < n; i++) {
|
| 814 |
+
dst[i] = static_cast<int32_t>(src[i]);
|
| 815 |
+
}
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
template <>
|
| 819 |
+
inline void convert(const int32_t* src, float* dst, int64_t n) {
|
| 820 |
+
int64_t i;
|
| 821 |
+
#pragma unroll
|
| 822 |
+
for (i = 0; i <= (n - Vectorized<float>::size()); i += Vectorized<float>::size()) {
|
| 823 |
+
vst1q_f32(dst + i, vcvtq_f32_s32(vld1q_s32(src + i)));
|
| 824 |
+
vst1q_f32(dst + i + 4, vcvtq_f32_s32(vld1q_s32(src + i + 4)));
|
| 825 |
+
}
|
| 826 |
+
#pragma unroll
|
| 827 |
+
for (; i < n; i++) {
|
| 828 |
+
dst[i] = static_cast<float>(src[i]);
|
| 829 |
+
}
|
| 830 |
+
}
|
| 831 |
+
|
| 832 |
+
template <>
|
| 833 |
+
Vectorized<float> inline fmadd(const Vectorized<float>& a, const Vectorized<float>& b, const Vectorized<float>& c) {
|
| 834 |
+
float32x4_t r0 = vfmaq_f32(c.get_low(), a.get_low(), b.get_low());
|
| 835 |
+
float32x4_t r1 = vfmaq_f32(c.get_high(), a.get_high(), b.get_high());
|
| 836 |
+
return Vectorized<float>(r0, r1);
|
| 837 |
+
}
|
| 838 |
+
|
| 839 |
+
template <>
|
| 840 |
+
Vectorized<float> inline fmsub(const Vectorized<float>& a, const Vectorized<float>& b, const Vectorized<float>& c) {
|
| 841 |
+
float32x4_t r0 = vfmsq_f32(c.get_low(), a.get_low(), b.get_low());
|
| 842 |
+
float32x4_t r1 = vfmsq_f32(c.get_high(), a.get_high(), b.get_high());
|
| 843 |
+
return Vectorized<float>(r0, r1);
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
inline Vectorized<float> Vectorized<float>::erf() const{
|
| 847 |
+
// constants
|
| 848 |
+
const Vectorized<float> neg_zero_vec(-0.f);
|
| 849 |
+
const Vectorized<float> one_vec(1.0f);
|
| 850 |
+
const Vectorized<float> p(0.3275911f);
|
| 851 |
+
const Vectorized<float> p1(0.254829592f);
|
| 852 |
+
const Vectorized<float> p2(-0.284496736f);
|
| 853 |
+
const Vectorized<float> p3(1.421413741f);
|
| 854 |
+
const Vectorized<float> p4(-1.453152027f);
|
| 855 |
+
const Vectorized<float> p5(1.061405429f);
|
| 856 |
+
// sign(x)
|
| 857 |
+
auto sign_mask = neg_zero_vec & *this;
|
| 858 |
+
auto abs_vec = this->abs();
|
| 859 |
+
// t = 1 / (p * abs(x) + 1)
|
| 860 |
+
auto tmp0 = fmadd(p, abs_vec, one_vec);
|
| 861 |
+
auto t = one_vec / tmp0;
|
| 862 |
+
// r = p5 * t ^ 4 + p4 * t ^ 3 + p3 * t ^ 2 + p2 * t + p1
|
| 863 |
+
auto tmp1 = fmadd(p5, t, p4);
|
| 864 |
+
auto tmp2 = fmadd(tmp1, t, p3);
|
| 865 |
+
auto tmp3 = fmadd(tmp2, t, p2);
|
| 866 |
+
auto r = fmadd(tmp3, t, p1);
|
| 867 |
+
// - exp(- x * x)
|
| 868 |
+
auto pow_2 = (*this) * (*this);
|
| 869 |
+
auto neg_pow_2 = pow_2 ^ neg_zero_vec;
|
| 870 |
+
auto tmp4 = neg_pow_2.map(std::exp); // This can be swapped for a faster implementation of exp.
|
| 871 |
+
auto tmp5 = tmp4 ^ neg_zero_vec;
|
| 872 |
+
// erf(x) = sign(x) * (1 - r * t * exp(- x * x))
|
| 873 |
+
auto tmp6 = t * tmp5;
|
| 874 |
+
auto tmp7 = fmadd(tmp6, r, one_vec);
|
| 875 |
+
return tmp7 ^ sign_mask;
|
| 876 |
+
}
|
| 877 |
+
#endif /* defined(aarch64) */
|
| 878 |
+
|
| 879 |
+
}} // namespace at::vec::CPU_CAPABILITY
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_common_vsx.h
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 4 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 5 |
+
#include <ATen/cpu/vec/vec256/vsx/vsx_helpers.h>
|
| 6 |
+
|
| 7 |
+
// Note: header order is important here
|
| 8 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_double_vsx.h>
|
| 9 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_float_vsx.h>
|
| 10 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_int16_vsx.h>
|
| 11 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_int32_vsx.h>
|
| 12 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_int64_vsx.h>
|
| 13 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_qint32_vsx.h>
|
| 14 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_qint8_vsx.h>
|
| 15 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_quint8_vsx.h>
|
| 16 |
+
|
| 17 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_complex_float_vsx.h>
|
| 18 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_complex_double_vsx.h>
|
| 19 |
+
|
| 20 |
+
#include <ATen/cpu/vec/vec256/vsx/vec256_bfloat16_vsx.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
namespace vec {
|
| 24 |
+
|
| 25 |
+
inline namespace CPU_CAPABILITY {
|
| 26 |
+
|
| 27 |
+
DEFINE_CLAMP_FUNCS(c10::quint8)
|
| 28 |
+
DEFINE_CLAMP_FUNCS(c10::qint8)
|
| 29 |
+
DEFINE_CLAMP_FUNCS(c10::qint32)
|
| 30 |
+
DEFINE_CLAMP_FUNCS(int16_t)
|
| 31 |
+
DEFINE_CLAMP_FUNCS(int32_t)
|
| 32 |
+
DEFINE_CLAMP_FUNCS(int64_t)
|
| 33 |
+
DEFINE_CLAMP_FUNCS(float)
|
| 34 |
+
DEFINE_CLAMP_FUNCS(double)
|
| 35 |
+
|
| 36 |
+
template <>
|
| 37 |
+
Vectorized<double> C10_ALWAYS_INLINE fmadd(
|
| 38 |
+
const Vectorized<double>& a,
|
| 39 |
+
const Vectorized<double>& b,
|
| 40 |
+
const Vectorized<double>& c) {
|
| 41 |
+
return Vectorized<double>{
|
| 42 |
+
vec_madd(a.vec0(), b.vec0(), c.vec0()),
|
| 43 |
+
vec_madd(a.vec1(), b.vec1(), c.vec1())};
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
template <>
|
| 47 |
+
Vectorized<int64_t> C10_ALWAYS_INLINE fmadd(
|
| 48 |
+
const Vectorized<int64_t>& a,
|
| 49 |
+
const Vectorized<int64_t>& b,
|
| 50 |
+
const Vectorized<int64_t>& c) {
|
| 51 |
+
return Vectorized<int64_t>{
|
| 52 |
+
a.vec0() * b.vec0() + c.vec0(), a.vec1() * b.vec1() + c.vec1()};
|
| 53 |
+
}
|
| 54 |
+
template <>
|
| 55 |
+
Vectorized<int32_t> C10_ALWAYS_INLINE fmadd(
|
| 56 |
+
const Vectorized<int32_t>& a,
|
| 57 |
+
const Vectorized<int32_t>& b,
|
| 58 |
+
const Vectorized<int32_t>& c) {
|
| 59 |
+
return Vectorized<int32_t>{
|
| 60 |
+
a.vec0() * b.vec0() + c.vec0(), a.vec1() * b.vec1() + c.vec1()};
|
| 61 |
+
}
|
| 62 |
+
template <>
|
| 63 |
+
Vectorized<int16_t> C10_ALWAYS_INLINE fmadd(
|
| 64 |
+
const Vectorized<int16_t>& a,
|
| 65 |
+
const Vectorized<int16_t>& b,
|
| 66 |
+
const Vectorized<int16_t>& c) {
|
| 67 |
+
return Vectorized<int16_t>{
|
| 68 |
+
a.vec0() * b.vec0() + c.vec0(), a.vec1() * b.vec1() + c.vec1()};
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
DEFINE_REINTERPRET_CAST_TO_ALL_FUNCS(float)
|
| 72 |
+
DEFINE_REINTERPRET_CAST_TO_ALL_FUNCS(double)
|
| 73 |
+
DEFINE_REINTERPRET_CAST_TO_ALL_FUNCS(int64_t)
|
| 74 |
+
DEFINE_REINTERPRET_CAST_TO_ALL_FUNCS(int32_t)
|
| 75 |
+
DEFINE_REINTERPRET_CAST_TO_ALL_FUNCS(int16_t)
|
| 76 |
+
|
| 77 |
+
template <>
|
| 78 |
+
Vectorized<int64_t> C10_ALWAYS_INLINE
|
| 79 |
+
convert_to_int_of_same_size<double>(const Vectorized<double>& src) {
|
| 80 |
+
return Vectorized<int64_t>{vec_signed(src.vec0()), vec_signed(src.vec1())};
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
template <>
|
| 84 |
+
Vectorized<int32_t> C10_ALWAYS_INLINE
|
| 85 |
+
convert_to_int_of_same_size<float>(
|
| 86 |
+
const Vectorized<float>& src) {
|
| 87 |
+
return Vectorized<int32_t>{vec_signed(src.vec0()), vec_signed(src.vec1())};
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
template <>
|
| 91 |
+
inline void convert(const int32_t* src, float* dst, int64_t n) {
|
| 92 |
+
// int32_t and float have same size
|
| 93 |
+
int64_t i;
|
| 94 |
+
for (i = 0; i <= (n - Vectorized<float>::size()); i += Vectorized<float>::size()) {
|
| 95 |
+
const int32_t* src_a = src + i;
|
| 96 |
+
float* dst_a = dst + i;
|
| 97 |
+
vint32 input_vec0 = vec_vsx_ld(offset0, reinterpret_cast<const vint32*>(src_a));
|
| 98 |
+
vint32 input_vec1 =
|
| 99 |
+
vec_vsx_ld(offset16, reinterpret_cast<const vint32*>(src_a));
|
| 100 |
+
vfloat32 c0 = vec_float(input_vec0);
|
| 101 |
+
vfloat32 c1 = vec_float(input_vec1);
|
| 102 |
+
vec_vsx_st(c0, offset0, dst_a);
|
| 103 |
+
vec_vsx_st(c1, offset16, dst_a);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
for (; i < n; i++) {
|
| 107 |
+
dst[i] = static_cast<float>(src[i]);
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
template <>
|
| 112 |
+
inline void convert(const int64_t* src, double* dst, int64_t n) {
|
| 113 |
+
int64_t i;
|
| 114 |
+
for (i = 0; i <= (n - Vectorized<double>::size()); i += Vectorized<double>::size()) {
|
| 115 |
+
const int64_t* src_a = src + i;
|
| 116 |
+
double* dst_a = dst + i;
|
| 117 |
+
vint64 input_vec0 =
|
| 118 |
+
vec_vsx_ld(offset0, reinterpret_cast<const vint64*>(src_a));
|
| 119 |
+
vint64 input_vec1 =
|
| 120 |
+
vec_vsx_ld(offset16, reinterpret_cast<const vint64*>(src_a));
|
| 121 |
+
vfloat64 c0 = vec_double(input_vec0);
|
| 122 |
+
vfloat64 c1 = vec_double(input_vec1);
|
| 123 |
+
vec_vsx_st(c0, offset0, reinterpret_cast<double*>(dst_a));
|
| 124 |
+
vec_vsx_st(c1, offset16, reinterpret_cast<double*>(dst_a));
|
| 125 |
+
}
|
| 126 |
+
for (; i < n; i++) {
|
| 127 |
+
dst[i] = static_cast<double>(src[i]);
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
//Generic implementation to fix compiler error
|
| 131 |
+
//TO-DO : Add optimized version for ppc64
|
| 132 |
+
inline std::tuple<Vectorized<float>, Vectorized<float>> convert_half_float(
|
| 133 |
+
const Vectorized<Half>& a) {
|
| 134 |
+
constexpr int64_t K = Vectorized<Half>::size();
|
| 135 |
+
__at_align__ float arr[K];
|
| 136 |
+
__at_align__ Half arr2[K];
|
| 137 |
+
a.store(arr2);
|
| 138 |
+
convert(arr2, arr, K);
|
| 139 |
+
return std::make_tuple(
|
| 140 |
+
Vectorized<float>::loadu(arr),
|
| 141 |
+
Vectorized<float>::loadu(arr + Vectorized<float>::size()));
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
inline Vectorized<Half> convert_float_half(
|
| 145 |
+
const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 146 |
+
constexpr int64_t K = Vectorized<Half>::size();
|
| 147 |
+
__at_align__ float arr[K];
|
| 148 |
+
__at_align__ Half arr2[K];
|
| 149 |
+
a.store(arr);
|
| 150 |
+
b.store(arr + Vectorized<float>::size());
|
| 151 |
+
convert(arr, arr2, K);
|
| 152 |
+
return Vectorized<Half>::loadu(arr2);
|
| 153 |
+
};
|
| 154 |
+
|
| 155 |
+
template <>
|
| 156 |
+
std::pair<Vectorized<double>, Vectorized<double>> inline interleave2<double>(
|
| 157 |
+
const Vectorized<double>& a,
|
| 158 |
+
const Vectorized<double>& b) {
|
| 159 |
+
// inputs:
|
| 160 |
+
// a = {a0, a1, a2, a3}
|
| 161 |
+
// b = {b0, b1, b2, b3}
|
| 162 |
+
|
| 163 |
+
vfloat64 ab00 = vec_xxpermdi(a.vec0(), b.vec0(), 0);
|
| 164 |
+
vfloat64 ab11 = vec_xxpermdi(a.vec0(), b.vec0(), 3);
|
| 165 |
+
vfloat64 ab2_00 = vec_xxpermdi(a.vec1(), b.vec1(), 0);
|
| 166 |
+
vfloat64 ab2_11 = vec_xxpermdi(a.vec1(), b.vec1(), 3);
|
| 167 |
+
// return {a0, b0, a1, b1}
|
| 168 |
+
// {a2, b2, a3, b3}
|
| 169 |
+
return std::make_pair(
|
| 170 |
+
Vectorized<double>{ab00, ab11}, Vectorized<double>{ab2_00, ab2_11});
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
template <>
|
| 174 |
+
std::pair<Vectorized<double>, Vectorized<double>> inline deinterleave2<double>(
|
| 175 |
+
const Vectorized<double>& a,
|
| 176 |
+
const Vectorized<double>& b) {
|
| 177 |
+
// inputs:
|
| 178 |
+
// a = {a0, b0, a1, b1}
|
| 179 |
+
// b = {a2, b2, a3, b3}
|
| 180 |
+
vfloat64 aa01 = vec_xxpermdi(a.vec0(), a.vec1(), 0);
|
| 181 |
+
vfloat64 aa23 = vec_xxpermdi(b.vec0(), b.vec1(), 0);
|
| 182 |
+
|
| 183 |
+
vfloat64 bb_01 = vec_xxpermdi(a.vec0(), a.vec1(), 3);
|
| 184 |
+
vfloat64 bb_23 = vec_xxpermdi(b.vec0(), b.vec1(), 3);
|
| 185 |
+
|
| 186 |
+
// swap lanes:
|
| 187 |
+
// return {a0, a1, a2, a3}
|
| 188 |
+
// {b0, b1, b2, b3}
|
| 189 |
+
return std::make_pair(
|
| 190 |
+
Vectorized<double>{aa01, aa23}, Vectorized<double>{bb_01, bb_23});
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
template <>
|
| 194 |
+
std::pair<Vectorized<float>, Vectorized<float>> inline interleave2<float>(
|
| 195 |
+
const Vectorized<float>& a,
|
| 196 |
+
const Vectorized<float>& b) {
|
| 197 |
+
// inputs:
|
| 198 |
+
// a = {a0, a1, a2, a3,, a4, a5, a6, a7}
|
| 199 |
+
// b = {b0, b1, b2, b3,, b4, b5, b6, b7}
|
| 200 |
+
|
| 201 |
+
vfloat32 ab0011 = vec_mergeh(a.vec0(), b.vec0());
|
| 202 |
+
vfloat32 ab2233 = vec_mergel(a.vec0(), b.vec0());
|
| 203 |
+
|
| 204 |
+
vfloat32 ab2_0011 = vec_mergeh(a.vec1(), b.vec1());
|
| 205 |
+
vfloat32 ab2_2233 = vec_mergel(a.vec1(), b.vec1());
|
| 206 |
+
// group cols crossing lanes:
|
| 207 |
+
// return {a0, b0, a1, b1,, a2, b2, a3, b3}
|
| 208 |
+
// {a4, b4, a5, b5,, a6, b6, a7, b7}
|
| 209 |
+
|
| 210 |
+
return std::make_pair(
|
| 211 |
+
Vectorized<float>{ab0011, ab2233}, Vectorized<float>{ab2_0011, ab2_2233});
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
template <>
|
| 215 |
+
std::pair<Vectorized<float>, Vectorized<float>> inline deinterleave2<float>(
|
| 216 |
+
const Vectorized<float>& a,
|
| 217 |
+
const Vectorized<float>& b) {
|
| 218 |
+
// inputs:
|
| 219 |
+
// a = {a0, b0, a1, b1,, a2, b2, a3, b3}
|
| 220 |
+
// b = {a4, b4, a5, b5,, a6, b6, a7, b7}
|
| 221 |
+
|
| 222 |
+
// {a0,a2,b0,b2} {a1,a3,b1,b3}
|
| 223 |
+
vfloat32 a0a2b0b2 = vec_mergeh(a.vec0(), a.vec1());
|
| 224 |
+
vfloat32 a1a3b1b3 = vec_mergel(a.vec0(), a.vec1());
|
| 225 |
+
|
| 226 |
+
vfloat32 aa0123 = vec_mergeh(a0a2b0b2, a1a3b1b3);
|
| 227 |
+
vfloat32 bb0123 = vec_mergel(a0a2b0b2, a1a3b1b3);
|
| 228 |
+
|
| 229 |
+
vfloat32 a0a2b0b2_2 = vec_mergeh(b.vec0(), b.vec1());
|
| 230 |
+
vfloat32 a1a3b1b3_2 = vec_mergel(b.vec0(), b.vec1());
|
| 231 |
+
|
| 232 |
+
vfloat32 aa0123_2 = vec_mergeh(a0a2b0b2_2, a1a3b1b3_2);
|
| 233 |
+
vfloat32 bb0123_2 = vec_mergel(a0a2b0b2_2, a1a3b1b3_2);
|
| 234 |
+
|
| 235 |
+
// it could be done with vec_perm ,too
|
| 236 |
+
// swap lanes:
|
| 237 |
+
// return {a0, a1, a2, a3,, a4, a5, a6, a7}
|
| 238 |
+
// {b0, b1, b2, b3,, b4, b5, b6, b7}
|
| 239 |
+
|
| 240 |
+
return std::make_pair(
|
| 241 |
+
Vectorized<float>{aa0123, aa0123_2}, Vectorized<float>{bb0123, bb0123_2});
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
} // namespace
|
| 245 |
+
} // namespace vec
|
| 246 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_complex_float_vsx.h
ADDED
|
@@ -0,0 +1,628 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#pragma once
|
| 3 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 4 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 5 |
+
#include <ATen/cpu/vec/vec256/vsx/vsx_helpers.h>
|
| 6 |
+
#include <c10/util/complex.h>
|
| 7 |
+
#include <c10/util/irange.h>
|
| 8 |
+
|
| 9 |
+
namespace at {
|
| 10 |
+
namespace vec {
|
| 11 |
+
// See Note [CPU_CAPABILITY namespace]
|
| 12 |
+
inline namespace CPU_CAPABILITY {
|
| 13 |
+
using ComplexFlt = c10::complex<float>;
|
| 14 |
+
|
| 15 |
+
template <>
|
| 16 |
+
class Vectorized<ComplexFlt> {
|
| 17 |
+
private:
|
| 18 |
+
union {
|
| 19 |
+
struct {
|
| 20 |
+
vfloat32 _vec0;
|
| 21 |
+
vfloat32 _vec1;
|
| 22 |
+
};
|
| 23 |
+
struct {
|
| 24 |
+
vbool32 _vecb0;
|
| 25 |
+
vbool32 _vecb1;
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
} __attribute__((__may_alias__));
|
| 29 |
+
|
| 30 |
+
public:
|
| 31 |
+
using value_type = ComplexFlt;
|
| 32 |
+
using vec_internal_type = vfloat32;
|
| 33 |
+
using vec_internal_mask_type = vbool32;
|
| 34 |
+
using size_type = int;
|
| 35 |
+
|
| 36 |
+
static constexpr size_type size() {
|
| 37 |
+
return 4;
|
| 38 |
+
}
|
| 39 |
+
Vectorized() {}
|
| 40 |
+
|
| 41 |
+
C10_ALWAYS_INLINE Vectorized(vfloat32 v) : _vec0{v}, _vec1{v} {}
|
| 42 |
+
C10_ALWAYS_INLINE Vectorized(vbool32 vmask) : _vecb0{vmask}, _vecb1{vmask} {}
|
| 43 |
+
C10_ALWAYS_INLINE Vectorized(vfloat32 v1, vfloat32 v2) : _vec0{v1}, _vec1{v2} {}
|
| 44 |
+
C10_ALWAYS_INLINE Vectorized(vbool32 v1, vbool32 v2) : _vecb0{v1}, _vecb1{v2} {}
|
| 45 |
+
|
| 46 |
+
Vectorized(ComplexFlt val) {
|
| 47 |
+
float real_value = val.real();
|
| 48 |
+
float imag_value = val.imag();
|
| 49 |
+
_vec0 = vfloat32{real_value, imag_value, real_value, imag_value};
|
| 50 |
+
_vec1 = vfloat32{real_value, imag_value, real_value, imag_value};
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
Vectorized(ComplexFlt val1, ComplexFlt val2, ComplexFlt val3, ComplexFlt val4) {
|
| 54 |
+
_vec0 = vfloat32{val1.real(), val1.imag(), val2.real(), val2.imag()};
|
| 55 |
+
_vec1 = vfloat32{val3.real(), val3.imag(), val4.real(), val4.imag()};
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
template <uint64_t mask>
|
| 59 |
+
static std::enable_if_t<blendChoiceComplex(mask) == 0, Vectorized<ComplexFlt>>
|
| 60 |
+
C10_ALWAYS_INLINE
|
| 61 |
+
blend(const Vectorized<ComplexFlt>& a, const Vectorized<ComplexFlt>& b) {
|
| 62 |
+
return a;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
template <uint64_t mask>
|
| 66 |
+
static std::enable_if_t<blendChoiceComplex(mask) == 1, Vectorized<ComplexFlt>>
|
| 67 |
+
C10_ALWAYS_INLINE
|
| 68 |
+
blend(const Vectorized<ComplexFlt>& a, const Vectorized<ComplexFlt>& b) {
|
| 69 |
+
return b;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
template <uint64_t mask>
|
| 73 |
+
static std::enable_if_t<blendChoiceComplex(mask) == 2, Vectorized<ComplexFlt>>
|
| 74 |
+
C10_ALWAYS_INLINE
|
| 75 |
+
blend(const Vectorized<ComplexFlt>& a, const Vectorized<ComplexFlt>& b) {
|
| 76 |
+
return {b._vec0, a._vec1};
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
template <uint64_t mask>
|
| 80 |
+
static std::enable_if_t<blendChoiceComplex(mask) == 3, Vectorized<ComplexFlt>>
|
| 81 |
+
C10_ALWAYS_INLINE
|
| 82 |
+
blend(const Vectorized<ComplexFlt>& a, const Vectorized<ComplexFlt>& b) {
|
| 83 |
+
return {a._vec0, b._vec1};
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
template <uint64_t mask>
|
| 87 |
+
static std::enable_if_t<blendChoiceComplex(mask) == 4, Vectorized<ComplexFlt>>
|
| 88 |
+
C10_ALWAYS_INLINE
|
| 89 |
+
blend(const Vectorized<ComplexFlt>& a, const Vectorized<ComplexFlt>& b) {
|
| 90 |
+
const vbool32 mask_1st = VsxComplexMask1(mask);
|
| 91 |
+
return {(vfloat32)vec_sel(a._vec0, b._vec0, mask_1st), a._vec1};
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
template <uint64_t mask>
|
| 95 |
+
static std::enable_if_t<blendChoiceComplex(mask) == 5, Vectorized<ComplexFlt>>
|
| 96 |
+
C10_ALWAYS_INLINE
|
| 97 |
+
blend(const Vectorized<ComplexFlt>& a, const Vectorized<ComplexFlt>& b) {
|
| 98 |
+
const vbool32 mask_1st = VsxComplexMask1(mask);
|
| 99 |
+
return {(vfloat32)vec_sel(a._vec0, b._vec0, mask_1st), b._vec1};
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
template <uint64_t mask>
|
| 103 |
+
static std::enable_if_t<blendChoiceComplex(mask) == 6, Vectorized<ComplexFlt>>
|
| 104 |
+
C10_ALWAYS_INLINE
|
| 105 |
+
blend(const Vectorized<ComplexFlt>& a, const Vectorized<ComplexFlt>& b) {
|
| 106 |
+
const vbool32 mask_2nd = VsxComplexMask2(mask);
|
| 107 |
+
// generated masks
|
| 108 |
+
return {a._vec0, (vfloat32)vec_sel(a._vec1, b._vec1, mask_2nd)};
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
template <uint64_t mask>
|
| 112 |
+
static std::enable_if_t<blendChoiceComplex(mask) == 7, Vectorized<ComplexFlt>>
|
| 113 |
+
C10_ALWAYS_INLINE
|
| 114 |
+
blend(const Vectorized<ComplexFlt>& a, const Vectorized<ComplexFlt>& b) {
|
| 115 |
+
const vbool32 mask_2nd = VsxComplexMask2(mask);
|
| 116 |
+
// generated masks
|
| 117 |
+
return {b._vec0, (vfloat32)vec_sel(a._vec1, b._vec1, mask_2nd)};
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
template <uint64_t mask>
|
| 121 |
+
static std::enable_if_t<blendChoiceComplex(mask) == 8, Vectorized<ComplexFlt>>
|
| 122 |
+
C10_ALWAYS_INLINE
|
| 123 |
+
blend(const Vectorized<ComplexFlt>& a, const Vectorized<ComplexFlt>& b) {
|
| 124 |
+
const vbool32 mask_1st = VsxComplexMask1(mask);
|
| 125 |
+
const vbool32 mask_2nd = VsxComplexMask2(mask);
|
| 126 |
+
return {
|
| 127 |
+
(vfloat32)vec_sel(a._vec0, b._vec0, mask_1st),
|
| 128 |
+
(vfloat32)vec_sel(a._vec1, b._vec1, mask_2nd)};
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
template <int64_t mask>
|
| 132 |
+
static Vectorized<ComplexFlt> C10_ALWAYS_INLINE
|
| 133 |
+
el_blend(const Vectorized<ComplexFlt>& a, const Vectorized<ComplexFlt>& b) {
|
| 134 |
+
const vbool32 mask_1st = VsxMask1(mask);
|
| 135 |
+
const vbool32 mask_2nd = VsxMask2(mask);
|
| 136 |
+
return {
|
| 137 |
+
(vfloat32)vec_sel(a._vec0, b._vec0, mask_1st),
|
| 138 |
+
(vfloat32)vec_sel(a._vec1, b._vec1, mask_2nd)};
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
static Vectorized<ComplexFlt> blendv(
|
| 142 |
+
const Vectorized<ComplexFlt>& a,
|
| 143 |
+
const Vectorized<ComplexFlt>& b,
|
| 144 |
+
const Vectorized<ComplexFlt>& mask) {
|
| 145 |
+
// convert std::complex<V> index mask to V index mask: xy -> xxyy
|
| 146 |
+
auto mask_complex = Vectorized<ComplexFlt>(
|
| 147 |
+
vec_mergeh(mask._vec0, mask._vec0), vec_mergeh(mask._vec1, mask._vec1));
|
| 148 |
+
return {
|
| 149 |
+
vec_sel(a._vec0, b._vec0, reinterpret_cast<vbool32>(mask_complex._vec0)),
|
| 150 |
+
vec_sel(a._vec1, b._vec1, reinterpret_cast<vbool32>(mask_complex._vec1)),
|
| 151 |
+
};
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
static Vectorized<ComplexFlt> elwise_blendv(
|
| 155 |
+
const Vectorized<ComplexFlt>& a,
|
| 156 |
+
const Vectorized<ComplexFlt>& b,
|
| 157 |
+
const Vectorized<ComplexFlt>& mask) {
|
| 158 |
+
return {
|
| 159 |
+
vec_sel(a._vec0, b._vec0, reinterpret_cast<vbool32>(mask._vec0)),
|
| 160 |
+
vec_sel(a._vec1, b._vec1, reinterpret_cast<vbool32>(mask._vec1)),
|
| 161 |
+
};
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
template <typename step_t>
|
| 165 |
+
static Vectorized<ComplexFlt> arange(
|
| 166 |
+
ComplexFlt base = 0.,
|
| 167 |
+
step_t step = static_cast<step_t>(1)) {
|
| 168 |
+
return Vectorized<ComplexFlt>(
|
| 169 |
+
base,
|
| 170 |
+
base + step,
|
| 171 |
+
base + ComplexFlt(2) * step,
|
| 172 |
+
base + ComplexFlt(3) * step);
|
| 173 |
+
}
|
| 174 |
+
static Vectorized<ComplexFlt> set(
|
| 175 |
+
const Vectorized<ComplexFlt>& a,
|
| 176 |
+
const Vectorized<ComplexFlt>& b,
|
| 177 |
+
int64_t count = size()) {
|
| 178 |
+
switch (count) {
|
| 179 |
+
case 0:
|
| 180 |
+
return a;
|
| 181 |
+
case 1:
|
| 182 |
+
return blend<1>(a, b);
|
| 183 |
+
case 2:
|
| 184 |
+
return blend<3>(a, b);
|
| 185 |
+
case 3:
|
| 186 |
+
return blend<7>(a, b);
|
| 187 |
+
}
|
| 188 |
+
return b;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
static Vectorized<value_type> C10_ALWAYS_INLINE
|
| 192 |
+
loadu(const void* ptr, int count = size()) {
|
| 193 |
+
if (count == size()) {
|
| 194 |
+
return {
|
| 195 |
+
vec_vsx_ld(offset0, reinterpret_cast<const float*>(ptr)),
|
| 196 |
+
vec_vsx_ld(offset16, reinterpret_cast<const float*>(ptr))};
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
__at_align__ value_type tmp_values[size()] = {};
|
| 200 |
+
std::memcpy(tmp_values, ptr, std::min(count, size()) * sizeof(value_type));
|
| 201 |
+
|
| 202 |
+
return {
|
| 203 |
+
vec_vsx_ld(offset0, reinterpret_cast<const float*>(tmp_values)),
|
| 204 |
+
vec_vsx_ld(offset16, reinterpret_cast<const float*>(tmp_values))};
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
void C10_ALWAYS_INLINE store(void* ptr, int count = size()) const {
|
| 208 |
+
if (count == size()) {
|
| 209 |
+
vec_vsx_st(_vec0, offset0, reinterpret_cast<float*>(ptr));
|
| 210 |
+
vec_vsx_st(_vec1, offset16, reinterpret_cast<float*>(ptr));
|
| 211 |
+
} else if (count > 0) {
|
| 212 |
+
__at_align__ value_type tmp_values[size()];
|
| 213 |
+
vec_vsx_st(_vec0, offset0, reinterpret_cast<float*>(tmp_values));
|
| 214 |
+
vec_vsx_st(_vec1, offset16, reinterpret_cast<float*>(tmp_values));
|
| 215 |
+
std::memcpy(
|
| 216 |
+
ptr, tmp_values, std::min(count, size()) * sizeof(value_type));
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
const ComplexFlt& operator[](int idx) const = delete;
|
| 221 |
+
ComplexFlt& operator[](int idx) = delete;
|
| 222 |
+
|
| 223 |
+
Vectorized<ComplexFlt> map(ComplexFlt (*const f)(ComplexFlt)) const {
|
| 224 |
+
__at_align__ ComplexFlt tmp[size()];
|
| 225 |
+
store(tmp);
|
| 226 |
+
for (const auto i : c10::irange(size())) {
|
| 227 |
+
tmp[i] = f(tmp[i]);
|
| 228 |
+
}
|
| 229 |
+
return loadu(tmp);
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
Vectorized<ComplexFlt> map(ComplexFlt (*const f)(const ComplexFlt&)) const {
|
| 233 |
+
__at_align__ ComplexFlt tmp[size()];
|
| 234 |
+
store(tmp);
|
| 235 |
+
for (const auto i : c10::irange(size())) {
|
| 236 |
+
tmp[i] = f(tmp[i]);
|
| 237 |
+
}
|
| 238 |
+
return loadu(tmp);
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
static Vectorized<ComplexFlt> horizontal_add_permD8(
|
| 242 |
+
Vectorized<ComplexFlt>& first,
|
| 243 |
+
Vectorized<ComplexFlt>& second) {
|
| 244 |
+
// we will simulate it differently with 6 instructions total
|
| 245 |
+
// lets permute second so that we can add it getting horizontal sums
|
| 246 |
+
auto first_perm = first.el_swapped(); // 2perm
|
| 247 |
+
auto second_perm = second.el_swapped(); // 2perm
|
| 248 |
+
// sum
|
| 249 |
+
auto first_ret = first + first_perm; // 2add
|
| 250 |
+
auto second_ret = second + second_perm; // 2 add
|
| 251 |
+
// now lets choose evens
|
| 252 |
+
return el_mergee(first_ret, second_ret); // 2 mergee's
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
static Vectorized<ComplexFlt> horizontal_sub_permD8(
|
| 256 |
+
Vectorized<ComplexFlt>& first,
|
| 257 |
+
Vectorized<ComplexFlt>& second) {
|
| 258 |
+
// we will simulate it differently with 6 instructions total
|
| 259 |
+
// lets permute second so that we can add it getting horizontal sums
|
| 260 |
+
auto first_perm = first.el_swapped(); // 2perm
|
| 261 |
+
auto second_perm = second.el_swapped(); // 2perm
|
| 262 |
+
// sum
|
| 263 |
+
auto first_ret = first - first_perm; // 2sub
|
| 264 |
+
auto second_ret = second - second_perm; // 2 sub
|
| 265 |
+
// now lets choose evens
|
| 266 |
+
return el_mergee(first_ret, second_ret); // 2 mergee's
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
Vectorized<ComplexFlt> abs_2_() const {
|
| 270 |
+
auto a = (*this).elwise_mult(*this);
|
| 271 |
+
auto permuted = a.el_swapped();
|
| 272 |
+
a = a + permuted;
|
| 273 |
+
return a.el_mergee();
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
Vectorized<ComplexFlt> abs_() const {
|
| 277 |
+
auto ret = abs_2_();
|
| 278 |
+
return ret.elwise_sqrt();
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
Vectorized<ComplexFlt> abs() const {
|
| 282 |
+
return abs_() & real_mask;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
Vectorized<ComplexFlt> real_() const {
|
| 286 |
+
return *this & real_mask;
|
| 287 |
+
}
|
| 288 |
+
Vectorized<ComplexFlt> real() const {
|
| 289 |
+
return *this & real_mask;
|
| 290 |
+
}
|
| 291 |
+
Vectorized<ComplexFlt> imag_() const {
|
| 292 |
+
return *this & imag_mask;
|
| 293 |
+
}
|
| 294 |
+
Vectorized<ComplexFlt> imag() const {
|
| 295 |
+
// we can use swap_mask or sldwi
|
| 296 |
+
auto ret = imag_();
|
| 297 |
+
return {
|
| 298 |
+
vec_sldw(ret._vec0, ret._vec0, 3), vec_sldw(ret._vec1, ret._vec1, 3)};
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
Vectorized<ComplexFlt> conj_() const {
|
| 302 |
+
return *this ^ isign_mask;
|
| 303 |
+
}
|
| 304 |
+
Vectorized<ComplexFlt> conj() const {
|
| 305 |
+
return *this ^ isign_mask;
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
Vectorized<ComplexFlt> log() const {
|
| 309 |
+
// Most trigonomic ops use the log() op to improve complex number
|
| 310 |
+
// performance.
|
| 311 |
+
return map(std::log);
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
Vectorized<ComplexFlt> log2() const {
|
| 315 |
+
// log2eB_inv
|
| 316 |
+
auto ret = log();
|
| 317 |
+
return ret.elwise_mult(log2e_inv);
|
| 318 |
+
}
|
| 319 |
+
Vectorized<ComplexFlt> log10() const {
|
| 320 |
+
auto ret = log();
|
| 321 |
+
return ret.elwise_mult(log10e_inv);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
Vectorized<ComplexFlt> log1p() const {
|
| 325 |
+
return map(std::log1p);
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
Vectorized<ComplexFlt> el_swapped() const {
|
| 329 |
+
vfloat32 v0 = vec_perm(_vec0, _vec0, swap_mask);
|
| 330 |
+
vfloat32 v1 = vec_perm(_vec1, _vec1, swap_mask);
|
| 331 |
+
return {v0, v1};
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
Vectorized<ComplexFlt> el_mergee() const {
|
| 335 |
+
// as mergee phased in , we can use vec_perm with mask
|
| 336 |
+
return {vec_mergee(_vecb0, _vecb0), vec_mergee(_vecb1, _vecb1)};
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
Vectorized<ComplexFlt> el_mergeo() const {
|
| 340 |
+
// as mergeo phased in , we can use vec_perm with mask
|
| 341 |
+
return {vec_mergeo(_vecb0, _vecb0), vec_mergeo(_vecb1, _vecb1)};
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
Vectorized<ComplexFlt> el_madd(
|
| 345 |
+
const Vectorized<ComplexFlt>& multiplier,
|
| 346 |
+
const Vectorized<ComplexFlt>& val) const {
|
| 347 |
+
return {
|
| 348 |
+
vec_madd(_vec0, multiplier._vec0, val._vec0),
|
| 349 |
+
vec_madd(_vec1, multiplier._vec1, val._vec1)};
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
static Vectorized<ComplexFlt> el_mergee(
|
| 353 |
+
Vectorized<ComplexFlt>& first,
|
| 354 |
+
Vectorized<ComplexFlt>& second) {
|
| 355 |
+
// as mergee phased in , we can use vec_perm with mask
|
| 356 |
+
return {
|
| 357 |
+
vec_mergee(first._vecb0, second._vecb0),
|
| 358 |
+
vec_mergee(first._vecb1, second._vecb1)};
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
Vectorized<ComplexFlt> angle_() const {
|
| 362 |
+
// angle = atan2(b/a)
|
| 363 |
+
// auto b_a = _mm256_permute_ps(values, 0xB1); // b a
|
| 364 |
+
// return Sleef_atan2f8_u10(values, b_a); // 90-angle angle
|
| 365 |
+
Vectorized<ComplexFlt> ret;
|
| 366 |
+
for (int i = 0; i < 4; i += 2) {
|
| 367 |
+
ret._vec0[i] = std::atan2(_vec0[i + 1], _vec0[i]);
|
| 368 |
+
ret._vec1[i] = std::atan2(_vec1[i + 1], _vec1[i]);
|
| 369 |
+
}
|
| 370 |
+
return ret;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
Vectorized<ComplexFlt> angle() const {
|
| 374 |
+
return angle_() & real_mask;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
Vectorized<ComplexFlt> sin() const {
|
| 378 |
+
return map(std::sin);
|
| 379 |
+
}
|
| 380 |
+
Vectorized<ComplexFlt> sinh() const {
|
| 381 |
+
return map(std::sinh);
|
| 382 |
+
}
|
| 383 |
+
Vectorized<ComplexFlt> cos() const {
|
| 384 |
+
return map(std::cos);
|
| 385 |
+
}
|
| 386 |
+
Vectorized<ComplexFlt> cosh() const {
|
| 387 |
+
return map(std::cosh);
|
| 388 |
+
}
|
| 389 |
+
Vectorized<ComplexFlt> ceil() const {
|
| 390 |
+
return {vec_ceil(_vec0), vec_ceil(_vec1)};
|
| 391 |
+
}
|
| 392 |
+
Vectorized<ComplexFlt> floor() const {
|
| 393 |
+
return {vec_floor(_vec0), vec_floor(_vec1)};
|
| 394 |
+
}
|
| 395 |
+
Vectorized<ComplexFlt> neg() const {
|
| 396 |
+
auto z = Vectorized<ComplexFlt>(zero);
|
| 397 |
+
return z - *this;
|
| 398 |
+
}
|
| 399 |
+
Vectorized<ComplexFlt> round() const {
|
| 400 |
+
return {vec_round(_vec0), vec_round(_vec1)};
|
| 401 |
+
}
|
| 402 |
+
Vectorized<ComplexFlt> tan() const {
|
| 403 |
+
return map(std::tan);
|
| 404 |
+
}
|
| 405 |
+
Vectorized<ComplexFlt> tanh() const {
|
| 406 |
+
return map(std::tanh);
|
| 407 |
+
}
|
| 408 |
+
Vectorized<ComplexFlt> trunc() const {
|
| 409 |
+
return {vec_trunc(_vec0), vec_trunc(_vec1)};
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
Vectorized<ComplexFlt> elwise_sqrt() const {
|
| 413 |
+
return {vec_sqrt(_vec0), vec_sqrt(_vec1)};
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
Vectorized<ComplexFlt> sqrt() const {
|
| 417 |
+
return map(std::sqrt);
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
Vectorized<ComplexFlt> reciprocal() const {
|
| 421 |
+
// re + im*i = (a + bi) / (c + di)
|
| 422 |
+
// re = (ac + bd)/abs_2() = c/abs_2()
|
| 423 |
+
// im = (bc - ad)/abs_2() = d/abs_2()
|
| 424 |
+
auto c_d = *this ^ isign_mask; // c -d
|
| 425 |
+
auto abs = abs_2_();
|
| 426 |
+
return c_d.elwise_div(abs);
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
Vectorized<ComplexFlt> rsqrt() const {
|
| 430 |
+
return sqrt().reciprocal();
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
Vectorized<ComplexFlt> pow(const Vectorized<ComplexFlt>& exp) const {
|
| 434 |
+
__at_align__ ComplexFlt x_tmp[size()];
|
| 435 |
+
__at_align__ ComplexFlt y_tmp[size()];
|
| 436 |
+
store(x_tmp);
|
| 437 |
+
exp.store(y_tmp);
|
| 438 |
+
for (const auto i : c10::irange(size())) {
|
| 439 |
+
x_tmp[i] = std::pow(x_tmp[i], y_tmp[i]);
|
| 440 |
+
}
|
| 441 |
+
return loadu(x_tmp);
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
Vectorized<ComplexFlt> atan() const {
|
| 445 |
+
// atan(x) = i/2 * ln((i + z)/(i - z))
|
| 446 |
+
auto ione = Vectorized(imag_one);
|
| 447 |
+
auto sum = ione + *this;
|
| 448 |
+
auto sub = ione - *this;
|
| 449 |
+
auto ln = (sum / sub).log(); // ln((i + z)/(i - z))
|
| 450 |
+
return ln * imag_half; // i/2*ln()
|
| 451 |
+
}
|
| 452 |
+
Vectorized<ComplexFlt> atanh() const {
|
| 453 |
+
return map(std::atanh);
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
Vectorized<ComplexFlt> acos() const {
|
| 457 |
+
// acos(x) = pi/2 - asin(x)
|
| 458 |
+
return Vectorized(pi_2) - asin();
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
Vectorized<ComplexFlt> inline operator*(const Vectorized<ComplexFlt>& b) const {
|
| 462 |
+
//(a + bi) * (c + di) = (ac - bd) + (ad + bc)i
|
| 463 |
+
|
| 464 |
+
#if 1
|
| 465 |
+
// this is more vsx friendly than simulating horizontal from x86
|
| 466 |
+
|
| 467 |
+
auto vi = b.el_mergeo();
|
| 468 |
+
auto vr = b.el_mergee();
|
| 469 |
+
vi = vi ^ rsign_mask;
|
| 470 |
+
auto ret = elwise_mult(vr);
|
| 471 |
+
auto vx_swapped = el_swapped();
|
| 472 |
+
ret = vx_swapped.el_madd(vi, ret);
|
| 473 |
+
return ret;
|
| 474 |
+
|
| 475 |
+
#else
|
| 476 |
+
|
| 477 |
+
auto ac_bd = elwise_mult(b);
|
| 478 |
+
auto d_c = b.el_swapped();
|
| 479 |
+
d_c = d_c ^ isign_mask;
|
| 480 |
+
auto ad_bc = elwise_mult(d_c);
|
| 481 |
+
auto ret = horizontal_sub_permD8(ac_bd, ad_bc);
|
| 482 |
+
return ret;
|
| 483 |
+
#endif
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
Vectorized<ComplexFlt> inline operator/(const Vectorized<ComplexFlt>& b) const {
|
| 487 |
+
// re + im*i = (a + bi) / (c + di)
|
| 488 |
+
// re = (ac + bd)/abs_2()
|
| 489 |
+
// im = (bc - ad)/abs_2()
|
| 490 |
+
#if 1
|
| 491 |
+
auto vi = b.el_mergeo();
|
| 492 |
+
auto vr = b.el_mergee();
|
| 493 |
+
auto abs_b = b.abs_2_();
|
| 494 |
+
vi = vi ^ isign_mask;
|
| 495 |
+
auto ret = elwise_mult(vr);
|
| 496 |
+
auto vx_swapped = el_swapped();
|
| 497 |
+
ret = vx_swapped.el_madd(vi, ret);
|
| 498 |
+
ret = ret.elwise_div(abs_b);
|
| 499 |
+
#else
|
| 500 |
+
// Vectorized x86 simulation
|
| 501 |
+
auto ac_bd = elwise_mult(b);
|
| 502 |
+
auto d_c = b.el_swapped();
|
| 503 |
+
d_c = d_c ^ rsign_mask;
|
| 504 |
+
auto ad_bc = elwise_mult(d_c);
|
| 505 |
+
auto abs_b = b.abs_2_();
|
| 506 |
+
auto re_im = horizontal_add_permD8(ac_bd, ad_bc);
|
| 507 |
+
auto ret = re_im.elwise_div(abs_b);
|
| 508 |
+
#endif
|
| 509 |
+
return ret;
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
Vectorized<ComplexFlt> asin() const {
|
| 513 |
+
// asin(x)
|
| 514 |
+
// = -i*ln(iz + sqrt(1 -z^2))
|
| 515 |
+
// = -i*ln((ai - b) + sqrt(1 - (a + bi)*(a + bi)))
|
| 516 |
+
// = -i*ln((-b + ai) + sqrt(1 - (a**2 - b**2) - 2*abi))
|
| 517 |
+
|
| 518 |
+
#if 1
|
| 519 |
+
auto conj = conj_();
|
| 520 |
+
auto b_a = conj.el_swapped();
|
| 521 |
+
auto ab = conj.elwise_mult(b_a);
|
| 522 |
+
auto im = ab + ab;
|
| 523 |
+
auto val_2 = (*this).elwise_mult(*this);
|
| 524 |
+
auto val_2_swapped = val_2.el_swapped();
|
| 525 |
+
auto re = horizontal_sub_permD8(val_2, val_2_swapped);
|
| 526 |
+
re = Vectorized<ComplexFlt>(one) - re;
|
| 527 |
+
auto root = el_blend<0xAA>(re, im).sqrt();
|
| 528 |
+
auto ln = (b_a + root).log();
|
| 529 |
+
return ln.el_swapped().conj();
|
| 530 |
+
#else
|
| 531 |
+
return map(std::asin);
|
| 532 |
+
#endif
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
Vectorized<ComplexFlt> exp() const {
|
| 536 |
+
return map(std::exp);
|
| 537 |
+
}
|
| 538 |
+
Vectorized<ComplexFlt> exp2() const {
|
| 539 |
+
return map(exp2_impl);
|
| 540 |
+
}
|
| 541 |
+
Vectorized<ComplexFlt> expm1() const {
|
| 542 |
+
return map(std::expm1);
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
Vectorized<ComplexFlt> eq(const Vectorized<ComplexFlt>& other) const {
|
| 546 |
+
auto eq = (*this == other); // compares real and imag individually
|
| 547 |
+
// If both real numbers and imag numbers are equal, then the complex numbers are equal
|
| 548 |
+
return (eq.real() & eq.imag()) & one;
|
| 549 |
+
}
|
| 550 |
+
Vectorized<ComplexFlt> ne(const Vectorized<ComplexFlt>& other) const {
|
| 551 |
+
auto ne = (*this != other); // compares real and imag individually
|
| 552 |
+
// If either real numbers or imag numbers are not equal, then the complex numbers are not equal
|
| 553 |
+
return (ne.real() | ne.imag()) & one;
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
Vectorized<ComplexFlt> sgn() const {
|
| 557 |
+
return map(at::native::sgn_impl);
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
Vectorized<ComplexFlt> operator<(const Vectorized<ComplexFlt>& other) const {
|
| 561 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 562 |
+
}
|
| 563 |
+
|
| 564 |
+
Vectorized<ComplexFlt> operator<=(const Vectorized<ComplexFlt>& other) const {
|
| 565 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
Vectorized<ComplexFlt> operator>(const Vectorized<ComplexFlt>& other) const {
|
| 569 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
Vectorized<ComplexFlt> operator>=(const Vectorized<ComplexFlt>& other) const {
|
| 573 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
DEFINE_MEMBER_OP(operator==, ComplexFlt, vec_cmpeq)
|
| 577 |
+
DEFINE_MEMBER_OP(operator!=, ComplexFlt, vec_cmpne)
|
| 578 |
+
|
| 579 |
+
DEFINE_MEMBER_OP(operator+, ComplexFlt, vec_add)
|
| 580 |
+
DEFINE_MEMBER_OP(operator-, ComplexFlt, vec_sub)
|
| 581 |
+
DEFINE_MEMBER_OP(operator&, ComplexFlt, vec_and)
|
| 582 |
+
DEFINE_MEMBER_OP(operator|, ComplexFlt, vec_or)
|
| 583 |
+
DEFINE_MEMBER_OP(operator^, ComplexFlt, vec_xor)
|
| 584 |
+
// elementwise helpers
|
| 585 |
+
DEFINE_MEMBER_OP(elwise_mult, ComplexFlt, vec_mul)
|
| 586 |
+
DEFINE_MEMBER_OP(elwise_div, ComplexFlt, vec_div)
|
| 587 |
+
DEFINE_MEMBER_OP(elwise_gt, ComplexFlt, vec_cmpgt)
|
| 588 |
+
DEFINE_MEMBER_OP(elwise_ge, ComplexFlt, vec_cmpge)
|
| 589 |
+
DEFINE_MEMBER_OP(elwise_lt, ComplexFlt, vec_cmplt)
|
| 590 |
+
DEFINE_MEMBER_OP(elwise_le, ComplexFlt, vec_cmple)
|
| 591 |
+
};
|
| 592 |
+
|
| 593 |
+
template <>
|
| 594 |
+
Vectorized<ComplexFlt> inline maximum(
|
| 595 |
+
const Vectorized<ComplexFlt>& a,
|
| 596 |
+
const Vectorized<ComplexFlt>& b) {
|
| 597 |
+
auto abs_a = a.abs_2_();
|
| 598 |
+
auto abs_b = b.abs_2_();
|
| 599 |
+
// auto mask = _mm256_cmp_ps(abs_a, abs_b, _CMP_LT_OQ);
|
| 600 |
+
// auto max = _mm256_blendv_ps(a, b, mask);
|
| 601 |
+
auto mask = abs_a.elwise_lt(abs_b);
|
| 602 |
+
auto max = Vectorized<ComplexFlt>::elwise_blendv(a, b, mask);
|
| 603 |
+
|
| 604 |
+
return max;
|
| 605 |
+
// Exploit the fact that all-ones is a NaN.
|
| 606 |
+
// auto isnan = _mm256_cmp_ps(abs_a, abs_b, _CMP_UNORD_Q);
|
| 607 |
+
// return _mm256_or_ps(max, isnan);
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
template <>
|
| 611 |
+
Vectorized<ComplexFlt> inline minimum(
|
| 612 |
+
const Vectorized<ComplexFlt>& a,
|
| 613 |
+
const Vectorized<ComplexFlt>& b) {
|
| 614 |
+
auto abs_a = a.abs_2_();
|
| 615 |
+
auto abs_b = b.abs_2_();
|
| 616 |
+
// auto mask = _mm256_cmp_ps(abs_a, abs_b, _CMP_GT_OQ);
|
| 617 |
+
// auto min = _mm256_blendv_ps(a, b, mask);
|
| 618 |
+
auto mask = abs_a.elwise_gt(abs_b);
|
| 619 |
+
auto min = Vectorized<ComplexFlt>::elwise_blendv(a, b, mask);
|
| 620 |
+
return min;
|
| 621 |
+
// Exploit the fact that all-ones is a NaN.
|
| 622 |
+
// auto isnan = _mm256_cmp_ps(abs_a, abs_b, _CMP_UNORD_Q);
|
| 623 |
+
// return _mm256_or_ps(min, isnan);
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
} // namespace
|
| 627 |
+
} // namespace vec
|
| 628 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_float_vsx.h
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 3 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 4 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 5 |
+
#include <ATen/cpu/vec/vec256/vsx/vsx_helpers.h>
|
| 6 |
+
#include <sleef.h>
|
| 7 |
+
namespace at {
|
| 8 |
+
namespace vec {
|
| 9 |
+
// See Note [CPU_CAPABILITY namespace]
|
| 10 |
+
|
| 11 |
+
inline namespace CPU_CAPABILITY {
|
| 12 |
+
|
| 13 |
+
template <>
|
| 14 |
+
class Vectorized<float> {
|
| 15 |
+
private:
|
| 16 |
+
union {
|
| 17 |
+
struct {
|
| 18 |
+
vfloat32 _vec0;
|
| 19 |
+
vfloat32 _vec1;
|
| 20 |
+
};
|
| 21 |
+
struct {
|
| 22 |
+
vbool32 _vecb0;
|
| 23 |
+
vbool32 _vecb1;
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
} __attribute__((__may_alias__));
|
| 27 |
+
|
| 28 |
+
public:
|
| 29 |
+
using value_type = float;
|
| 30 |
+
using vec_internal_type = vfloat32;
|
| 31 |
+
using vec_internal_mask_type = vbool32;
|
| 32 |
+
using size_type = int;
|
| 33 |
+
|
| 34 |
+
static constexpr size_type size() {
|
| 35 |
+
return 8;
|
| 36 |
+
}
|
| 37 |
+
Vectorized() {}
|
| 38 |
+
|
| 39 |
+
C10_ALWAYS_INLINE Vectorized(vfloat32 v) : _vec0{v}, _vec1{v} {}
|
| 40 |
+
C10_ALWAYS_INLINE Vectorized(vbool32 vmask) : _vecb0{vmask}, _vecb1{vmask} {}
|
| 41 |
+
C10_ALWAYS_INLINE Vectorized(vfloat32 v1, vfloat32 v2) : _vec0{v1}, _vec1{v2} {}
|
| 42 |
+
C10_ALWAYS_INLINE Vectorized(vbool32 v1, vbool32 v2) : _vecb0{v1}, _vecb1{v2} {}
|
| 43 |
+
C10_ALWAYS_INLINE Vectorized(float scalar)
|
| 44 |
+
: _vec0{vec_splats(scalar)}, _vec1{vec_splats(scalar)} {}
|
| 45 |
+
C10_ALWAYS_INLINE Vectorized(
|
| 46 |
+
float scalar1,
|
| 47 |
+
float scalar2,
|
| 48 |
+
float scalar3,
|
| 49 |
+
float scalar4,
|
| 50 |
+
float scalar5,
|
| 51 |
+
float scalar6,
|
| 52 |
+
float scalar7,
|
| 53 |
+
float scalar8)
|
| 54 |
+
: _vec0{vfloat32{scalar1, scalar2, scalar3, scalar4}},
|
| 55 |
+
_vec1{vfloat32{scalar5, scalar6, scalar7, scalar8}} {}
|
| 56 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec0() const {
|
| 57 |
+
return _vec0;
|
| 58 |
+
}
|
| 59 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec1() const {
|
| 60 |
+
return _vec1;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
template <int64_t mask>
|
| 64 |
+
static std::enable_if_t<blendChoice(mask) == 0, Vectorized<float>> C10_ALWAYS_INLINE
|
| 65 |
+
blend(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 66 |
+
return a;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
template <int64_t mask>
|
| 70 |
+
static std::enable_if_t<blendChoice(mask) == 1, Vectorized<float>> C10_ALWAYS_INLINE
|
| 71 |
+
blend(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 72 |
+
return b;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
template <int64_t mask>
|
| 76 |
+
static std::enable_if_t<blendChoice(mask) == 2, Vectorized<float>> C10_ALWAYS_INLINE
|
| 77 |
+
blend(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 78 |
+
return {b._vec0, a._vec1};
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
template <int64_t mask>
|
| 82 |
+
static std::enable_if_t<blendChoice(mask) == 3, Vectorized<float>> C10_ALWAYS_INLINE
|
| 83 |
+
blend(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 84 |
+
return {a._vec0, b._vec1};
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
template <int64_t mask>
|
| 88 |
+
static std::enable_if_t<blendChoice(mask) == 4, Vectorized<float>> C10_ALWAYS_INLINE
|
| 89 |
+
blend(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 90 |
+
const vbool32 mask_1st = VsxMask1(mask);
|
| 91 |
+
return {(vfloat32)vec_sel(a._vec0, b._vec0, mask_1st), a._vec1};
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
template <int64_t mask>
|
| 95 |
+
static std::enable_if_t<blendChoice(mask) == 5, Vectorized<float>> C10_ALWAYS_INLINE
|
| 96 |
+
blend(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 97 |
+
const vbool32 mask_1st = VsxMask1(mask);
|
| 98 |
+
return {(vfloat32)vec_sel(a._vec0, b._vec0, mask_1st), b._vec1};
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
template <int64_t mask>
|
| 102 |
+
static std::enable_if_t<blendChoice(mask) == 6, Vectorized<float>> C10_ALWAYS_INLINE
|
| 103 |
+
blend(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 104 |
+
const vbool32 mask_2nd = VsxMask2(mask);
|
| 105 |
+
// generated masks
|
| 106 |
+
return {a._vec0, (vfloat32)vec_sel(a._vec1, b._vec1, mask_2nd)};
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
template <int64_t mask>
|
| 110 |
+
static std::enable_if_t<blendChoice(mask) == 7, Vectorized<float>> C10_ALWAYS_INLINE
|
| 111 |
+
blend(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 112 |
+
const vbool32 mask_2nd = VsxMask2(mask);
|
| 113 |
+
// generated masks
|
| 114 |
+
return {b._vec0, (vfloat32)vec_sel(a._vec1, b._vec1, mask_2nd)};
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
template <int64_t mask>
|
| 118 |
+
static std::enable_if_t<blendChoice(mask) == 8, Vectorized<float>> C10_ALWAYS_INLINE
|
| 119 |
+
blend(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 120 |
+
const vbool32 mask_1st = VsxMask1(mask);
|
| 121 |
+
const vbool32 mask_2nd = VsxMask2(mask);
|
| 122 |
+
return {
|
| 123 |
+
(vfloat32)vec_sel(a._vec0, b._vec0, mask_1st),
|
| 124 |
+
(vfloat32)vec_sel(a._vec1, b._vec1, mask_2nd)};
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
static Vectorized<float> C10_ALWAYS_INLINE blendv(
|
| 128 |
+
const Vectorized<float>& a,
|
| 129 |
+
const Vectorized<float>& b,
|
| 130 |
+
const Vectorized<float>& mask) {
|
| 131 |
+
// the mask used here returned by comparision of vec256
|
| 132 |
+
// assuming this we can use the same mask directly with vec_sel
|
| 133 |
+
return {
|
| 134 |
+
vec_sel(a._vec0, b._vec0, mask._vecb0),
|
| 135 |
+
vec_sel(a._vec1, b._vec1, mask._vecb1)};
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
template <typename step_t>
|
| 139 |
+
static Vectorized<float> arange(float base = 0.f, step_t step = static_cast<step_t>(1)) {
|
| 140 |
+
return Vectorized<float>(
|
| 141 |
+
base,
|
| 142 |
+
base + step,
|
| 143 |
+
base + 2 * step,
|
| 144 |
+
base + 3 * step,
|
| 145 |
+
base + 4 * step,
|
| 146 |
+
base + 5 * step,
|
| 147 |
+
base + 6 * step,
|
| 148 |
+
base + 7 * step);
|
| 149 |
+
}
|
| 150 |
+
static Vectorized<float> set(
|
| 151 |
+
const Vectorized<float>& a,
|
| 152 |
+
const Vectorized<float>& b,
|
| 153 |
+
size_t count = size()) {
|
| 154 |
+
switch (count) {
|
| 155 |
+
case 0:
|
| 156 |
+
return a;
|
| 157 |
+
case 1:
|
| 158 |
+
return blend<1>(a, b);
|
| 159 |
+
case 2:
|
| 160 |
+
return blend<3>(a, b);
|
| 161 |
+
case 3:
|
| 162 |
+
return blend<7>(a, b);
|
| 163 |
+
case 4:
|
| 164 |
+
return blend<15>(a, b);
|
| 165 |
+
case 5:
|
| 166 |
+
return blend<31>(a, b);
|
| 167 |
+
case 6:
|
| 168 |
+
return blend<63>(a, b);
|
| 169 |
+
case 7:
|
| 170 |
+
return blend<127>(a, b);
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
return b;
|
| 174 |
+
}
|
| 175 |
+
static Vectorized<value_type> C10_ALWAYS_INLINE
|
| 176 |
+
loadu(const void* ptr, int count = size()) {
|
| 177 |
+
if (count == size()) {
|
| 178 |
+
return {
|
| 179 |
+
vec_vsx_ld(offset0, reinterpret_cast<const value_type*>(ptr)),
|
| 180 |
+
vec_vsx_ld(offset16, reinterpret_cast<const value_type*>(ptr))};
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
__at_align__ value_type tmp_values[size()] = {};
|
| 184 |
+
std::memcpy(tmp_values, ptr, std::min(count, size()) * sizeof(value_type));
|
| 185 |
+
|
| 186 |
+
return {vec_vsx_ld(offset0, tmp_values), vec_vsx_ld(offset16, tmp_values)};
|
| 187 |
+
}
|
| 188 |
+
void C10_ALWAYS_INLINE store(void* ptr, int count = size()) const {
|
| 189 |
+
if (count == size()) {
|
| 190 |
+
vec_vsx_st(_vec0, offset0, reinterpret_cast<value_type*>(ptr));
|
| 191 |
+
vec_vsx_st(_vec1, offset16, reinterpret_cast<value_type*>(ptr));
|
| 192 |
+
} else if (count > 0) {
|
| 193 |
+
__at_align__ value_type tmp_values[size()];
|
| 194 |
+
vec_vsx_st(_vec0, offset0, tmp_values);
|
| 195 |
+
vec_vsx_st(_vec1, offset16, tmp_values);
|
| 196 |
+
std::memcpy(
|
| 197 |
+
ptr, tmp_values, std::min(count, size()) * sizeof(value_type));
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
const float& operator[](int idx) const = delete;
|
| 202 |
+
float& operator[](int idx) = delete;
|
| 203 |
+
|
| 204 |
+
Vectorized<float> map(float (*const f)(float)) const {
|
| 205 |
+
Vectorized<float> ret;
|
| 206 |
+
for (int i = 0; i < size() / 2; i++) {
|
| 207 |
+
ret._vec0[i] = f(_vec0[i]);
|
| 208 |
+
}
|
| 209 |
+
for (int i = 0; i < size() / 2; i++) {
|
| 210 |
+
ret._vec1[i] = f(_vec1[i]);
|
| 211 |
+
}
|
| 212 |
+
return ret;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
Vectorized<float> mapbi(float (*const f)(float, float), const Vectorized<float>& other)
|
| 216 |
+
const {
|
| 217 |
+
Vectorized<float> ret;
|
| 218 |
+
for (int i = 0; i < size() / 2; i++) {
|
| 219 |
+
ret._vec0[i] = f(_vec0[i], other._vec0[i]);
|
| 220 |
+
}
|
| 221 |
+
for (int i = 0; i < size() / 2; i++) {
|
| 222 |
+
ret._vec1[i] = f(_vec1[i], other._vec1[i]);
|
| 223 |
+
}
|
| 224 |
+
return ret;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
Vectorized<float> _nor() const {
|
| 228 |
+
return {vec_nor(_vec0, _vec0), vec_nor(_vec1, _vec1)};
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
Vectorized<float> isnan() const {
|
| 232 |
+
auto x = *this;
|
| 233 |
+
auto ret = (x == x);
|
| 234 |
+
return ret._nor();
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
Vectorized<float> _isinf() const {
|
| 238 |
+
auto x = *this;
|
| 239 |
+
return (x == v_inf) | (x == v_minus_inf);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
int zero_mask() const {
|
| 243 |
+
// returns an integer mask where all zero elements are translated to 1-bit
|
| 244 |
+
// and others are translated to 0-bit
|
| 245 |
+
//__m256 cmp = _mm256_cmp_ps(values, _mm256_set1_ps(0.0f), _CMP_EQ_OQ);
|
| 246 |
+
auto cmp = (*this == zero);
|
| 247 |
+
// return _mm256_movemask_ps(cmp);
|
| 248 |
+
// possible simulation //mask= lvsl ( 0 ) vbpermq( vec, mask <<5)
|
| 249 |
+
vuint64 result0 = vec_vbpermq((vuint8)cmp._vecb0, mask_zero_bits);
|
| 250 |
+
vuint64 result1 = vec_vbpermq((vuint8)cmp._vecb1, mask_zero_bits);
|
| 251 |
+
return (result0[1] >> 12 | (result1[1] >> 8));
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
Vectorized<float> C10_ALWAYS_INLINE abs() const {
|
| 255 |
+
return {vec_abs(_vec0), vec_abs(_vec1)};
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
Vectorized<float> C10_ALWAYS_INLINE acos() const {
|
| 259 |
+
return {Sleef_acosf4_u10(_vec0), Sleef_acosf4_u10(_vec1)};
|
| 260 |
+
}
|
| 261 |
+
Vectorized<float> C10_ALWAYS_INLINE asin() const {
|
| 262 |
+
return {Sleef_asinf4_u10(_vec0), Sleef_asinf4_u10(_vec1)};
|
| 263 |
+
}
|
| 264 |
+
Vectorized<float> atan() const {
|
| 265 |
+
return {Sleef_atanf4_u10(_vec0), Sleef_atanf4_u10(_vec1)};
|
| 266 |
+
}
|
| 267 |
+
Vectorized<float> atanh() const {
|
| 268 |
+
return {Sleef_atanhf4_u10(_vec0), Sleef_atanhf4_u10(_vec1)};
|
| 269 |
+
}
|
| 270 |
+
Vectorized<float> atan2(const Vectorized<float>& b) const {
|
| 271 |
+
return {Sleef_atan2f4_u10(_vec0, b._vec0), Sleef_atan2f4_u10(_vec1, b._vec1)};
|
| 272 |
+
}
|
| 273 |
+
Vectorized<float> copysign(const Vectorized<float> &sign) const {
|
| 274 |
+
return {Sleef_copysignf4(_vec0, sign._vec0), Sleef_copysignf4(_vec1, sign._vec1)};
|
| 275 |
+
}
|
| 276 |
+
Vectorized<float> lgamma() const {
|
| 277 |
+
return {Sleef_lgammaf4_u10(_vec0), Sleef_lgammaf4_u10(_vec1)};
|
| 278 |
+
}
|
| 279 |
+
Vectorized<float> erf() const {
|
| 280 |
+
return {Sleef_erff4_u10(_vec0), Sleef_erff4_u10(_vec1)};
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
Vectorized<float> erfc() const {
|
| 284 |
+
return {Sleef_erfcf4_u15(_vec0), Sleef_erfcf4_u15(_vec1)};
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
Vectorized<float> erfinv() const {
|
| 288 |
+
return map(calc_erfinv);
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
Vectorized<float> angle() const {
|
| 292 |
+
auto tmp = blendv(
|
| 293 |
+
Vectorized<float>(0), Vectorized<float>(c10::pi<float>), *this < Vectorized<float>(0));
|
| 294 |
+
return blendv(tmp, *this, isnan());
|
| 295 |
+
}
|
| 296 |
+
Vectorized<float> real() const {
|
| 297 |
+
return *this;
|
| 298 |
+
}
|
| 299 |
+
Vectorized<float> imag() const {
|
| 300 |
+
return Vectorized<float>{0};
|
| 301 |
+
}
|
| 302 |
+
Vectorized<float> conj() const {
|
| 303 |
+
return *this;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
Vectorized<float> C10_ALWAYS_INLINE exp() const {
|
| 307 |
+
return {Sleef_expf4_u10(_vec0), Sleef_expf4_u10(_vec1)};
|
| 308 |
+
}
|
| 309 |
+
Vectorized<float> C10_ALWAYS_INLINE exp2() const {
|
| 310 |
+
return {Sleef_exp2f4_u10(_vec0), Sleef_exp2f4_u10(_vec1)};
|
| 311 |
+
}
|
| 312 |
+
Vectorized<float> expm1() const {
|
| 313 |
+
return {Sleef_expm1f4_u10(_vec0), Sleef_expm1f4_u10(_vec1)};
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
Vectorized<float> C10_ALWAYS_INLINE log() const {
|
| 317 |
+
return {Sleef_logf4_u10(_vec0), Sleef_logf4_u10(_vec1)};
|
| 318 |
+
}
|
| 319 |
+
Vectorized<float> C10_ALWAYS_INLINE log10() const {
|
| 320 |
+
return {Sleef_log10f4_u10(_vec0), Sleef_log10f4_u10(_vec1)};
|
| 321 |
+
}
|
| 322 |
+
Vectorized<float> C10_ALWAYS_INLINE log1p() const {
|
| 323 |
+
return {Sleef_log1pf4_u10(_vec0), Sleef_log1pf4_u10(_vec1)};
|
| 324 |
+
}
|
| 325 |
+
Vectorized<float> C10_ALWAYS_INLINE log2() const {
|
| 326 |
+
return {Sleef_log2f4_u10(_vec0), Sleef_log2f4_u10(_vec1)};
|
| 327 |
+
}
|
| 328 |
+
Vectorized<float> C10_ALWAYS_INLINE ceil() const {
|
| 329 |
+
return {vec_ceil(_vec0), vec_ceil(_vec1)};
|
| 330 |
+
}
|
| 331 |
+
Vectorized<float> C10_ALWAYS_INLINE cos() const {
|
| 332 |
+
return {Sleef_cosf4_u10(_vec0), Sleef_cosf4_u10(_vec1)};
|
| 333 |
+
}
|
| 334 |
+
Vectorized<float> C10_ALWAYS_INLINE cosh() const {
|
| 335 |
+
return {Sleef_coshf4_u10(_vec0), Sleef_coshf4_u10(_vec1)};
|
| 336 |
+
}
|
| 337 |
+
Vectorized<float> C10_ALWAYS_INLINE floor() const {
|
| 338 |
+
return {vec_floor(_vec0), vec_floor(_vec1)};
|
| 339 |
+
}
|
| 340 |
+
Vectorized<float> C10_ALWAYS_INLINE neg() const {
|
| 341 |
+
return {vec_neg(_vec0), vec_neg(_vec1)};
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
Vectorized<float> C10_ALWAYS_INLINE round() const {
|
| 345 |
+
return {vec_round(_vec0), vec_round(_vec1)};
|
| 346 |
+
}
|
| 347 |
+
Vectorized<float> C10_ALWAYS_INLINE sin() const {
|
| 348 |
+
return {Sleef_sinf4_u10(_vec0), Sleef_sinf4_u10(_vec1)};
|
| 349 |
+
}
|
| 350 |
+
Vectorized<float> C10_ALWAYS_INLINE sinh() const {
|
| 351 |
+
return {Sleef_sinhf4_u10(_vec0), Sleef_sinhf4_u10(_vec1)};
|
| 352 |
+
}
|
| 353 |
+
Vectorized<float> C10_ALWAYS_INLINE tan() const {
|
| 354 |
+
return {Sleef_tanf4_u10(_vec0), Sleef_tanf4_u10(_vec1)};
|
| 355 |
+
}
|
| 356 |
+
Vectorized<float> C10_ALWAYS_INLINE tanh() const {
|
| 357 |
+
return {Sleef_tanhf4_u10(_vec0), Sleef_tanhf4_u10(_vec1)};
|
| 358 |
+
}
|
| 359 |
+
Vectorized<float> C10_ALWAYS_INLINE trunc() const {
|
| 360 |
+
return {vec_trunc(_vec0), vec_trunc(_vec1)};
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
Vectorized<float> C10_ALWAYS_INLINE frac() const {
|
| 364 |
+
return *this - trunc();
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
Vectorized<float> C10_ALWAYS_INLINE sqrt() const {
|
| 368 |
+
return {vec_sqrt(_vec0), vec_sqrt(_vec1)};
|
| 369 |
+
}
|
| 370 |
+
Vectorized<float> C10_ALWAYS_INLINE reciprocal() const {
|
| 371 |
+
return Vectorized<float>(one) / (*this);
|
| 372 |
+
}
|
| 373 |
+
Vectorized<float> C10_ALWAYS_INLINE rsqrt() const {
|
| 374 |
+
return sqrt().reciprocal();
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
Vectorized<float> C10_ALWAYS_INLINE pow(const Vectorized<float>& exp) const {
|
| 378 |
+
return {Sleef_powf4_u10(_vec0, exp._vec0), Sleef_powf4_u10(_vec1, exp._vec1)};
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
Vectorized<float> fmod(const Vectorized<float>& b) const {
|
| 382 |
+
return {Sleef_fmodf4(_vec0, b._vec0),Sleef_fmodf4(_vec1, b._vec1)};
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
Vectorized<float> hypot(const Vectorized<float>& b) const {
|
| 386 |
+
return {Sleef_hypotf4_u05(_vec0, b._vec0), Sleef_hypotf4_u05(_vec1, b._vec1)};
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
Vectorized<float> nextafter(const Vectorized<float>& b) const {
|
| 390 |
+
return {Sleef_nextafterf4(_vec0, b._vec0), Sleef_nextafterf4(_vec1, b._vec1)};
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
Vectorized<float> igamma(const Vectorized<float>& x) const {
|
| 394 |
+
return mapbi(calc_igamma, x);
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
Vectorized<float> igammac(const Vectorized<float>& x) const {
|
| 398 |
+
return mapbi(calc_igammac, x);
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
Vectorized<float> i0() const {
|
| 402 |
+
return map(calc_i0);
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
Vectorized<float> i0e() const {
|
| 406 |
+
return map(calc_i0e);
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
Vectorized<float> digamma() const {
|
| 410 |
+
return map(calc_digamma);
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
DEFINE_MEMBER_OP(operator==, float, vec_cmpeq)
|
| 414 |
+
DEFINE_MEMBER_OP(operator!=, float, vec_cmpne)
|
| 415 |
+
DEFINE_MEMBER_OP(operator<, float, vec_cmplt)
|
| 416 |
+
DEFINE_MEMBER_OP(operator<=, float, vec_cmple)
|
| 417 |
+
DEFINE_MEMBER_OP(operator>, float, vec_cmpgt)
|
| 418 |
+
DEFINE_MEMBER_OP(operator>=, float, vec_cmpge)
|
| 419 |
+
DEFINE_MEMBER_OP_AND_ONE(eq, float, vec_cmpeq)
|
| 420 |
+
DEFINE_MEMBER_OP_AND_ONE(ne, float, vec_cmpne)
|
| 421 |
+
DEFINE_MEMBER_OP_AND_ONE(lt, float, vec_cmplt)
|
| 422 |
+
DEFINE_MEMBER_OP_AND_ONE(le, float, vec_cmple)
|
| 423 |
+
DEFINE_MEMBER_OP_AND_ONE(gt, float, vec_cmpgt)
|
| 424 |
+
DEFINE_MEMBER_OP_AND_ONE(ge, float, vec_cmpge)
|
| 425 |
+
DEFINE_MEMBER_OP(operator+, float, vec_add)
|
| 426 |
+
DEFINE_MEMBER_OP(operator-, float, vec_sub)
|
| 427 |
+
DEFINE_MEMBER_OP(operator*, float, vec_mul)
|
| 428 |
+
DEFINE_MEMBER_OP(operator/, float, vec_div)
|
| 429 |
+
DEFINE_MEMBER_OP(maximum, float, vec_max_nan2)
|
| 430 |
+
DEFINE_MEMBER_OP(minimum, float, vec_min_nan2)
|
| 431 |
+
DEFINE_MEMBER_OP(operator&, float, vec_and)
|
| 432 |
+
DEFINE_MEMBER_OP(operator|, float, vec_or)
|
| 433 |
+
DEFINE_MEMBER_OP(operator^, float, vec_xor)
|
| 434 |
+
DEFINE_MEMBER_TERNARY_OP(madd, float, vec_madd)
|
| 435 |
+
};
|
| 436 |
+
|
| 437 |
+
template <>
|
| 438 |
+
Vectorized<float> inline maximum(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 439 |
+
return a.maximum(b);
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
template <>
|
| 443 |
+
Vectorized<float> inline minimum(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 444 |
+
return a.minimum(b);
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
} // namespace
|
| 448 |
+
} // namespace vec
|
| 449 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_int16_vsx.h
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 4 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 5 |
+
#include <ATen/cpu/vec/vec256/vsx/vsx_helpers.h>
|
| 6 |
+
namespace at {
|
| 7 |
+
namespace vec {
|
| 8 |
+
// See Note [CPU_CAPABILITY namespace]
|
| 9 |
+
inline namespace CPU_CAPABILITY {
|
| 10 |
+
|
| 11 |
+
template <>
|
| 12 |
+
class Vectorized<int16_t> {
|
| 13 |
+
private:
|
| 14 |
+
union {
|
| 15 |
+
struct {
|
| 16 |
+
vint16 _vec0;
|
| 17 |
+
vint16 _vec1;
|
| 18 |
+
};
|
| 19 |
+
struct {
|
| 20 |
+
vbool16 _vecb0;
|
| 21 |
+
vbool16 _vecb1;
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
} __attribute__((__may_alias__));
|
| 25 |
+
|
| 26 |
+
public:
|
| 27 |
+
using value_type = int16_t;
|
| 28 |
+
using vec_internal_type = vint16;
|
| 29 |
+
using vec_internal_mask_type = vbool16;
|
| 30 |
+
using size_type = int;
|
| 31 |
+
static constexpr size_type size() {
|
| 32 |
+
return 16;
|
| 33 |
+
}
|
| 34 |
+
Vectorized() {}
|
| 35 |
+
C10_ALWAYS_INLINE Vectorized(vint16 v) : _vec0{v}, _vec1{v} {}
|
| 36 |
+
C10_ALWAYS_INLINE Vectorized(vbool16 vmask) : _vecb0{vmask}, _vecb1{vmask} {}
|
| 37 |
+
C10_ALWAYS_INLINE Vectorized(vint16 v1, vint16 v2) : _vec0{v1}, _vec1{v2} {}
|
| 38 |
+
C10_ALWAYS_INLINE Vectorized(vbool16 v1, vbool16 v2) : _vecb0{v1}, _vecb1{v2} {}
|
| 39 |
+
C10_ALWAYS_INLINE Vectorized(int16_t scalar)
|
| 40 |
+
: _vec0{vec_splats(scalar)}, _vec1{vec_splats(scalar)} {}
|
| 41 |
+
|
| 42 |
+
C10_ALWAYS_INLINE Vectorized(
|
| 43 |
+
int16_t scalar1,
|
| 44 |
+
int16_t scalar2,
|
| 45 |
+
int16_t scalar3,
|
| 46 |
+
int16_t scalar4,
|
| 47 |
+
int16_t scalar5,
|
| 48 |
+
int16_t scalar6,
|
| 49 |
+
int16_t scalar7,
|
| 50 |
+
int16_t scalar8,
|
| 51 |
+
int16_t scalar9,
|
| 52 |
+
int16_t scalar10,
|
| 53 |
+
int16_t scalar11,
|
| 54 |
+
int16_t scalar12,
|
| 55 |
+
int16_t scalar13,
|
| 56 |
+
int16_t scalar14,
|
| 57 |
+
int16_t scalar15,
|
| 58 |
+
int16_t scalar16)
|
| 59 |
+
: _vec0{vint16{
|
| 60 |
+
scalar1,
|
| 61 |
+
scalar2,
|
| 62 |
+
scalar3,
|
| 63 |
+
scalar4,
|
| 64 |
+
scalar5,
|
| 65 |
+
scalar6,
|
| 66 |
+
scalar7,
|
| 67 |
+
scalar8}},
|
| 68 |
+
_vec1{vint16{
|
| 69 |
+
scalar9,
|
| 70 |
+
scalar10,
|
| 71 |
+
scalar11,
|
| 72 |
+
scalar12,
|
| 73 |
+
scalar13,
|
| 74 |
+
scalar14,
|
| 75 |
+
scalar15,
|
| 76 |
+
scalar16}} {}
|
| 77 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec0() const {
|
| 78 |
+
return _vec0;
|
| 79 |
+
}
|
| 80 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec1() const {
|
| 81 |
+
return _vec1;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
template <uint64_t mask>
|
| 85 |
+
static std::enable_if_t<mask == 0, Vectorized<int16_t>> C10_ALWAYS_INLINE
|
| 86 |
+
blend(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 87 |
+
return a;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
template <uint64_t mask>
|
| 91 |
+
static std::enable_if_t<(mask & 65535) == 65535, Vectorized<int16_t>>
|
| 92 |
+
C10_ALWAYS_INLINE blend(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 93 |
+
return b;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
template <uint64_t mask>
|
| 97 |
+
static std::enable_if_t<mask == 255, Vectorized<int16_t>> C10_ALWAYS_INLINE
|
| 98 |
+
blend(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 99 |
+
return {b._vec0, a._vec1};
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
template <uint64_t mask>
|
| 103 |
+
static std::enable_if_t<(mask > 0 && mask < 255), Vectorized<int16_t>>
|
| 104 |
+
C10_ALWAYS_INLINE blend(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 105 |
+
constexpr int16_t g0 = (mask & 1) * 0xffff;
|
| 106 |
+
constexpr int16_t g1 = ((mask & 2) >> 1) * 0xffff;
|
| 107 |
+
constexpr int16_t g2 = ((mask & 4) >> 2) * 0xffff;
|
| 108 |
+
constexpr int16_t g3 = ((mask & 8) >> 3) * 0xffff;
|
| 109 |
+
constexpr int16_t g4 = ((mask & 16) >> 4) * 0xffff;
|
| 110 |
+
constexpr int16_t g5 = ((mask & 32) >> 5) * 0xffff;
|
| 111 |
+
constexpr int16_t g6 = ((mask & 64) >> 6) * 0xffff;
|
| 112 |
+
constexpr int16_t g7 = ((mask & 128) >> 7) * 0xffff;
|
| 113 |
+
const vint16 mask_1st = vint16{g0, g1, g2, g3, g4, g5, g6, g7};
|
| 114 |
+
|
| 115 |
+
return {(vint16)vec_sel(a._vec0, b._vec0, (vbool16)mask_1st), a._vec1};
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
template <uint64_t mask>
|
| 119 |
+
static std::enable_if_t<
|
| 120 |
+
(mask > 255 && (mask & 65535) != 65535 && ((mask & 255) == 255)),
|
| 121 |
+
Vectorized<int16_t>>
|
| 122 |
+
C10_ALWAYS_INLINE blend(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 123 |
+
constexpr int16_t g0_2 = (mask & 1) * 0xffff;
|
| 124 |
+
constexpr int16_t g1_2 = ((mask & 2) >> 1) * 0xffff;
|
| 125 |
+
constexpr int16_t g2_2 = ((mask & 4) >> 2) * 0xffff;
|
| 126 |
+
constexpr int16_t g3_2 = ((mask & 8) >> 3) * 0xffff;
|
| 127 |
+
constexpr int16_t g4_2 = ((mask & 16) >> 4) * 0xffff;
|
| 128 |
+
constexpr int16_t g5_2 = ((mask & 32) >> 5) * 0xffff;
|
| 129 |
+
constexpr int16_t g6_2 = ((mask & 64) >> 6) * 0xffff;
|
| 130 |
+
constexpr int16_t g7_2 = ((mask & 128) >> 7) * 0xffff;
|
| 131 |
+
|
| 132 |
+
const vint16 mask_2nd =
|
| 133 |
+
vint16{g0_2, g1_2, g2_2, g3_2, g4_2, g5_2, g6_2, g7_2};
|
| 134 |
+
// generated masks
|
| 135 |
+
return {b._vec0, (vint16)vec_sel(a._vec1, b._vec1, (vbool16)mask_2nd)};
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
template <uint64_t mask>
|
| 139 |
+
static std::enable_if_t<
|
| 140 |
+
(mask > 255 && ((mask & 65535) != 65535) && ((mask & 255) == 0)),
|
| 141 |
+
Vectorized<int16_t>>
|
| 142 |
+
C10_ALWAYS_INLINE blend(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 143 |
+
constexpr int16_t mask2 = (mask & 65535) >> 16;
|
| 144 |
+
constexpr int16_t g0_2 = (mask & 1) * 0xffff;
|
| 145 |
+
constexpr int16_t g1_2 = ((mask & 2) >> 1) * 0xffff;
|
| 146 |
+
constexpr int16_t g2_2 = ((mask & 4) >> 2) * 0xffff;
|
| 147 |
+
constexpr int16_t g3_2 = ((mask & 8) >> 3) * 0xffff;
|
| 148 |
+
constexpr int16_t g4_2 = ((mask & 16) >> 4) * 0xffff;
|
| 149 |
+
constexpr int16_t g5_2 = ((mask & 32) >> 5) * 0xffff;
|
| 150 |
+
constexpr int16_t g6_2 = ((mask & 64) >> 6) * 0xffff;
|
| 151 |
+
constexpr int16_t g7_2 = ((mask & 128) >> 7) * 0xffff;
|
| 152 |
+
|
| 153 |
+
const vint16 mask_2nd =
|
| 154 |
+
vint16{g0_2, g1_2, g2_2, g3_2, g4_2, g5_2, g6_2, g7_2};
|
| 155 |
+
// generated masks
|
| 156 |
+
return {a, (vint16)vec_sel(a._vec1, b._vec1, (vbool16)mask_2nd)};
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
template <uint64_t mask>
|
| 160 |
+
static std::enable_if_t<
|
| 161 |
+
(mask > 255 && ((mask & 65535) != 65535) && ((mask & 255) != 0) &&
|
| 162 |
+
((mask & 255) != 255)),
|
| 163 |
+
Vectorized<int16_t>>
|
| 164 |
+
C10_ALWAYS_INLINE blend(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 165 |
+
constexpr int16_t g0 = (mask & 1) * 0xffff;
|
| 166 |
+
constexpr int16_t g1 = ((mask & 2) >> 1) * 0xffff;
|
| 167 |
+
constexpr int16_t g2 = ((mask & 4) >> 2) * 0xffff;
|
| 168 |
+
constexpr int16_t g3 = ((mask & 8) >> 3) * 0xffff;
|
| 169 |
+
constexpr int16_t g4 = ((mask & 16) >> 4) * 0xffff;
|
| 170 |
+
constexpr int16_t g5 = ((mask & 32) >> 5) * 0xffff;
|
| 171 |
+
constexpr int16_t g6 = ((mask & 64) >> 6) * 0xffff;
|
| 172 |
+
constexpr int16_t g7 = ((mask & 128) >> 7) * 0xffff;
|
| 173 |
+
constexpr int16_t mask2 = (mask & 65535) >> 16;
|
| 174 |
+
constexpr int16_t g0_2 = (mask & 1) * 0xffff;
|
| 175 |
+
constexpr int16_t g1_2 = ((mask & 2) >> 1) * 0xffff;
|
| 176 |
+
constexpr int16_t g2_2 = ((mask & 4) >> 2) * 0xffff;
|
| 177 |
+
constexpr int16_t g3_2 = ((mask & 8) >> 3) * 0xffff;
|
| 178 |
+
constexpr int16_t g4_2 = ((mask & 16) >> 4) * 0xffff;
|
| 179 |
+
constexpr int16_t g5_2 = ((mask & 32) >> 5) * 0xffff;
|
| 180 |
+
constexpr int16_t g6_2 = ((mask & 64) >> 6) * 0xffff;
|
| 181 |
+
constexpr int16_t g7_2 = ((mask & 128) >> 7) * 0xffff;
|
| 182 |
+
|
| 183 |
+
const vint16 mask_1st = vint16{g0, g1, g2, g3, g4, g5, g6, g7};
|
| 184 |
+
const vint16 mask_2nd =
|
| 185 |
+
vint16{g0_2, g1_2, g2_2, g3_2, g4_2, g5_2, g6_2, g7_2};
|
| 186 |
+
// generated masks
|
| 187 |
+
return {
|
| 188 |
+
(vint16)vec_sel(a._vec0, b._vec0, (vbool16)mask_1st),
|
| 189 |
+
(vint16)vec_sel(a._vec1, b._vec1, (vbool16)mask_2nd)};
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
static Vectorized<int16_t> C10_ALWAYS_INLINE blendv(
|
| 193 |
+
const Vectorized<int16_t>& a,
|
| 194 |
+
const Vectorized<int16_t>& b,
|
| 195 |
+
const Vectorized<int16_t>& mask) {
|
| 196 |
+
// the mask used here returned by comparision of vec256
|
| 197 |
+
// assuming this we can use the same mask directly with vec_sel
|
| 198 |
+
// warning intel style mask will not work properly
|
| 199 |
+
return {
|
| 200 |
+
vec_sel(a._vec0, b._vec0, mask._vecb0),
|
| 201 |
+
vec_sel(a._vec1, b._vec1, mask._vecb1)};
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
template <typename step_t>
|
| 205 |
+
static Vectorized<int16_t> arange(int16_t base = 0, step_t step = static_cast<step_t>(1)) {
|
| 206 |
+
return Vectorized<int16_t>(
|
| 207 |
+
base,
|
| 208 |
+
base + step,
|
| 209 |
+
base + 2 * step,
|
| 210 |
+
base + 3 * step,
|
| 211 |
+
base + 4 * step,
|
| 212 |
+
base + 5 * step,
|
| 213 |
+
base + 6 * step,
|
| 214 |
+
base + 7 * step,
|
| 215 |
+
base + 8 * step,
|
| 216 |
+
base + 9 * step,
|
| 217 |
+
base + 10 * step,
|
| 218 |
+
base + 11 * step,
|
| 219 |
+
base + 12 * step,
|
| 220 |
+
base + 13 * step,
|
| 221 |
+
base + 14 * step,
|
| 222 |
+
base + 15 * step);
|
| 223 |
+
}
|
| 224 |
+
static Vectorized<int16_t> set(
|
| 225 |
+
const Vectorized<int16_t>& a,
|
| 226 |
+
const Vectorized<int16_t>& b,
|
| 227 |
+
size_t count = size()) {
|
| 228 |
+
switch (count) {
|
| 229 |
+
case 0:
|
| 230 |
+
return a;
|
| 231 |
+
case 1:
|
| 232 |
+
return blend<1>(a, b);
|
| 233 |
+
case 2:
|
| 234 |
+
return blend<3>(a, b);
|
| 235 |
+
case 3:
|
| 236 |
+
return blend<7>(a, b);
|
| 237 |
+
case 4:
|
| 238 |
+
return blend<15>(a, b);
|
| 239 |
+
case 5:
|
| 240 |
+
return blend<31>(a, b);
|
| 241 |
+
case 6:
|
| 242 |
+
return blend<63>(a, b);
|
| 243 |
+
case 7:
|
| 244 |
+
return blend<127>(a, b);
|
| 245 |
+
case 8:
|
| 246 |
+
return blend<255>(a, b);
|
| 247 |
+
case 9:
|
| 248 |
+
return blend<511>(a, b);
|
| 249 |
+
case 10:
|
| 250 |
+
return blend<1023>(a, b);
|
| 251 |
+
case 11:
|
| 252 |
+
return blend<2047>(a, b);
|
| 253 |
+
case 12:
|
| 254 |
+
return blend<4095>(a, b);
|
| 255 |
+
case 13:
|
| 256 |
+
return blend<8191>(a, b);
|
| 257 |
+
case 14:
|
| 258 |
+
return blend<16383>(a, b);
|
| 259 |
+
case 15:
|
| 260 |
+
return blend<32767>(a, b);
|
| 261 |
+
}
|
| 262 |
+
return b;
|
| 263 |
+
}
|
| 264 |
+
static Vectorized<value_type> C10_ALWAYS_INLINE
|
| 265 |
+
loadu(const void* ptr, int count = size()) {
|
| 266 |
+
if (count == size()) {
|
| 267 |
+
return {
|
| 268 |
+
vec_vsx_ld(offset0, reinterpret_cast<const value_type*>(ptr)),
|
| 269 |
+
vec_vsx_ld(offset16, reinterpret_cast<const value_type*>(ptr))};
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
__at_align__ value_type tmp_values[size()] = {};
|
| 273 |
+
std::memcpy(tmp_values, ptr, std::min(count, size()) * sizeof(value_type));
|
| 274 |
+
|
| 275 |
+
return {vec_vsx_ld(offset0, tmp_values), vec_vsx_ld(offset16, tmp_values)};
|
| 276 |
+
}
|
| 277 |
+
void C10_ALWAYS_INLINE store(void* ptr, int count = size()) const {
|
| 278 |
+
if (count == size()) {
|
| 279 |
+
vec_vsx_st(_vec0, offset0, reinterpret_cast<value_type*>(ptr));
|
| 280 |
+
vec_vsx_st(_vec1, offset16, reinterpret_cast<value_type*>(ptr));
|
| 281 |
+
} else if (count > 0) {
|
| 282 |
+
__at_align__ value_type tmp_values[size()];
|
| 283 |
+
vec_vsx_st(_vec0, offset0, tmp_values);
|
| 284 |
+
vec_vsx_st(_vec1, offset16, tmp_values);
|
| 285 |
+
std::memcpy(ptr, tmp_values, std::min(count, size()) * sizeof(value_type));
|
| 286 |
+
}
|
| 287 |
+
}
|
| 288 |
+
const int16_t& operator[](int idx) const = delete;
|
| 289 |
+
int16_t& operator[](int idx) = delete;
|
| 290 |
+
|
| 291 |
+
Vectorized<int16_t> angle() const {
|
| 292 |
+
return blendv(
|
| 293 |
+
Vectorized<int16_t>(0), Vectorized<int16_t>(c10::pi<int16_t>), *this < Vectorized<int16_t>(0));
|
| 294 |
+
}
|
| 295 |
+
Vectorized<int16_t> real() const {
|
| 296 |
+
return *this;
|
| 297 |
+
}
|
| 298 |
+
Vectorized<int16_t> imag() const {
|
| 299 |
+
return Vectorized<int16_t>{0};
|
| 300 |
+
}
|
| 301 |
+
Vectorized<int16_t> conj() const {
|
| 302 |
+
return *this;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
Vectorized<int16_t> C10_ALWAYS_INLINE abs() const {
|
| 306 |
+
return {vec_abs(_vec0), vec_abs(_vec1)};
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
Vectorized<int16_t> C10_ALWAYS_INLINE neg() const {
|
| 310 |
+
return {vec_neg(_vec0), vec_neg(_vec1)};
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
DEFINE_MEMBER_UNARY_OP(operator~, int16_t, vec_not)
|
| 314 |
+
DEFINE_MEMBER_OP(operator==, int16_t, vec_cmpeq)
|
| 315 |
+
DEFINE_MEMBER_OP(operator!=, int16_t, vec_cmpne)
|
| 316 |
+
DEFINE_MEMBER_OP(operator<, int16_t, vec_cmplt)
|
| 317 |
+
DEFINE_MEMBER_OP(operator<=, int16_t, vec_cmple)
|
| 318 |
+
DEFINE_MEMBER_OP(operator>, int16_t, vec_cmpgt)
|
| 319 |
+
DEFINE_MEMBER_OP(operator>=, int16_t, vec_cmpge)
|
| 320 |
+
DEFINE_MEMBER_OP_AND_ONE(eq, int16_t, vec_cmpeq)
|
| 321 |
+
DEFINE_MEMBER_OP_AND_ONE(ne, int16_t, vec_cmpne)
|
| 322 |
+
DEFINE_MEMBER_OP_AND_ONE(lt, int16_t, vec_cmplt)
|
| 323 |
+
DEFINE_MEMBER_OP_AND_ONE(le, int16_t, vec_cmple)
|
| 324 |
+
DEFINE_MEMBER_OP_AND_ONE(gt, int16_t, vec_cmpgt)
|
| 325 |
+
DEFINE_MEMBER_OP_AND_ONE(ge, int16_t, vec_cmpge)
|
| 326 |
+
DEFINE_MEMBER_OP(operator+, int16_t, vec_add)
|
| 327 |
+
DEFINE_MEMBER_OP(operator-, int16_t, vec_sub)
|
| 328 |
+
DEFINE_MEMBER_OP(operator*, int16_t, vec_mul)
|
| 329 |
+
DEFINE_MEMBER_EMULATE_BINARY_OP(operator/, int16_t, /)
|
| 330 |
+
DEFINE_MEMBER_OP(maximum, int16_t, vec_max)
|
| 331 |
+
DEFINE_MEMBER_OP(minimum, int16_t, vec_min)
|
| 332 |
+
DEFINE_MEMBER_OP(operator&, int16_t, vec_and)
|
| 333 |
+
DEFINE_MEMBER_OP(operator|, int16_t, vec_or)
|
| 334 |
+
DEFINE_MEMBER_OP(operator^, int16_t, vec_xor)
|
| 335 |
+
};
|
| 336 |
+
|
| 337 |
+
template <>
|
| 338 |
+
Vectorized<int16_t> inline operator<<(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 339 |
+
vuint16 shift_vec0 = reinterpret_cast<vuint16>(b.vec0());
|
| 340 |
+
vuint16 shift_vec1 = reinterpret_cast<vuint16>(b.vec1());
|
| 341 |
+
return Vectorized<int16_t>{vec_sl(a.vec0(), shift_vec0), vec_sl(a.vec1(), shift_vec1)};
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
template <>
|
| 345 |
+
Vectorized<int16_t> inline operator>>(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 346 |
+
vuint16 shift_vec0 = reinterpret_cast<vuint16>(b.vec0());
|
| 347 |
+
vuint16 shift_vec1 = reinterpret_cast<vuint16>(b.vec1()) ;
|
| 348 |
+
return Vectorized<int16_t>{vec_sr(a.vec0(), shift_vec0), vec_sr(a.vec1(), shift_vec1)};
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
template <>
|
| 352 |
+
Vectorized<int16_t> inline maximum(
|
| 353 |
+
const Vectorized<int16_t>& a,
|
| 354 |
+
const Vectorized<int16_t>& b) {
|
| 355 |
+
return a.maximum(b);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
template <>
|
| 359 |
+
Vectorized<int16_t> inline minimum(
|
| 360 |
+
const Vectorized<int16_t>& a,
|
| 361 |
+
const Vectorized<int16_t>& b) {
|
| 362 |
+
return a.minimum(b);
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
} // namespace
|
| 367 |
+
} // namespace vec
|
| 368 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_int32_vsx.h
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 4 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 5 |
+
#include <ATen/cpu/vec/vec256/vsx/vsx_helpers.h>
|
| 6 |
+
namespace at {
|
| 7 |
+
namespace vec {
|
| 8 |
+
// See Note [CPU_CAPABILITY namespace]
|
| 9 |
+
inline namespace CPU_CAPABILITY {
|
| 10 |
+
|
| 11 |
+
template <>
|
| 12 |
+
class Vectorized<int32_t> {
|
| 13 |
+
private:
|
| 14 |
+
union {
|
| 15 |
+
struct {
|
| 16 |
+
vint32 _vec0;
|
| 17 |
+
vint32 _vec1;
|
| 18 |
+
};
|
| 19 |
+
struct {
|
| 20 |
+
vbool32 _vecb0;
|
| 21 |
+
vbool32 _vecb1;
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
} __attribute__((__may_alias__));
|
| 25 |
+
|
| 26 |
+
public:
|
| 27 |
+
using value_type = int32_t;
|
| 28 |
+
using vec_internal_type = vint32;
|
| 29 |
+
using vec_internal_mask_type = vbool32;
|
| 30 |
+
using size_type = int;
|
| 31 |
+
static constexpr size_type size() {
|
| 32 |
+
return 8;
|
| 33 |
+
}
|
| 34 |
+
Vectorized() {}
|
| 35 |
+
C10_ALWAYS_INLINE Vectorized(vint32 v) : _vec0{v}, _vec1{v} {}
|
| 36 |
+
C10_ALWAYS_INLINE Vectorized(vbool32 vmask) : _vecb0{vmask}, _vecb1{vmask} {}
|
| 37 |
+
C10_ALWAYS_INLINE Vectorized(vint32 v1, vint32 v2) : _vec0{v1}, _vec1{v2} {}
|
| 38 |
+
C10_ALWAYS_INLINE Vectorized(vbool32 v1, vbool32 v2) : _vecb0{v1}, _vecb1{v2} {}
|
| 39 |
+
C10_ALWAYS_INLINE Vectorized(int32_t scalar)
|
| 40 |
+
: _vec0{vec_splats(scalar)}, _vec1{vec_splats(scalar)} {}
|
| 41 |
+
C10_ALWAYS_INLINE Vectorized(
|
| 42 |
+
int32_t scalar1,
|
| 43 |
+
int32_t scalar2,
|
| 44 |
+
int32_t scalar3,
|
| 45 |
+
int32_t scalar4,
|
| 46 |
+
int32_t scalar5,
|
| 47 |
+
int32_t scalar6,
|
| 48 |
+
int32_t scalar7,
|
| 49 |
+
int32_t scalar8)
|
| 50 |
+
: _vec0{vint32{scalar1, scalar2, scalar3, scalar4}},
|
| 51 |
+
_vec1{vint32{scalar5, scalar6, scalar7, scalar8}} {}
|
| 52 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec0() const {
|
| 53 |
+
return _vec0;
|
| 54 |
+
}
|
| 55 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec1() const {
|
| 56 |
+
return _vec1;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
template <uint64_t mask>
|
| 60 |
+
static std::enable_if_t<mask == 0, Vectorized<int32_t>> C10_ALWAYS_INLINE
|
| 61 |
+
blend(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 62 |
+
return a;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
template <uint64_t mask>
|
| 66 |
+
static std::enable_if_t<(mask & 255) == 255, Vectorized<int32_t>> C10_ALWAYS_INLINE
|
| 67 |
+
blend(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 68 |
+
return b;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
template <uint64_t mask>
|
| 72 |
+
static std::enable_if_t<mask == 15, Vectorized<int32_t>> C10_ALWAYS_INLINE
|
| 73 |
+
blend(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 74 |
+
return {b._vec0, a._vec1};
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
template <uint64_t mask>
|
| 78 |
+
static std::enable_if_t<(mask > 0 && mask < 15), Vectorized<int32_t>>
|
| 79 |
+
C10_ALWAYS_INLINE blend(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 80 |
+
constexpr uint32_t g0 = (mask & 1) * 0xffffffff;
|
| 81 |
+
constexpr uint32_t g1 = ((mask & 2) >> 1) * 0xffffffff;
|
| 82 |
+
constexpr uint32_t g2 = ((mask & 4) >> 2) * 0xffffffff;
|
| 83 |
+
constexpr uint32_t g3 = ((mask & 8) >> 3) * 0xffffffff;
|
| 84 |
+
const vbool32 mask_1st = (vbool32){g0, g1, g2, g3};
|
| 85 |
+
|
| 86 |
+
return {(vint32)vec_sel(a._vec0, b._vec0, (vbool32)mask_1st), a._vec1};
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
template <uint64_t mask>
|
| 90 |
+
static std::enable_if_t<
|
| 91 |
+
(mask > 15 && (mask & 255) != 255 && ((mask & 15) == 15)),
|
| 92 |
+
Vectorized<int32_t>>
|
| 93 |
+
C10_ALWAYS_INLINE blend(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 94 |
+
constexpr uint32_t mask2 = (mask & 255) >> 4;
|
| 95 |
+
constexpr uint32_t g0_2 = (mask2 & 1) * 0xffffffff;
|
| 96 |
+
constexpr uint32_t g1_2 = ((mask2 & 2) >> 1) * 0xffffffff;
|
| 97 |
+
constexpr uint32_t g2_2 = ((mask2 & 4) >> 2) * 0xffffffff;
|
| 98 |
+
constexpr uint32_t g3_2 = ((mask2 & 8) >> 3) * 0xffffffff;
|
| 99 |
+
|
| 100 |
+
const vbool32 mask_2nd = (vbool32){g0_2, g1_2, g2_2, g3_2};
|
| 101 |
+
// generated masks
|
| 102 |
+
return {b._vec0, (vint32)vec_sel(a._vec1, b._vec1, (vbool32)mask_2nd)};
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
template <uint64_t mask>
|
| 106 |
+
static std::enable_if_t<
|
| 107 |
+
(mask > 15 && ((mask & 255) != 255) && ((mask & 15) == 0)),
|
| 108 |
+
Vectorized<int32_t>>
|
| 109 |
+
C10_ALWAYS_INLINE blend(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 110 |
+
constexpr uint32_t mask2 = (mask & 255) >> 4;
|
| 111 |
+
constexpr uint32_t g0_2 = (mask2 & 1) * 0xffffffff;
|
| 112 |
+
constexpr uint32_t g1_2 = ((mask2 & 2) >> 1) * 0xffffffff;
|
| 113 |
+
constexpr uint32_t g2_2 = ((mask2 & 4) >> 2) * 0xffffffff;
|
| 114 |
+
constexpr uint32_t g3_2 = ((mask2 & 8) >> 3) * 0xffffffff;
|
| 115 |
+
|
| 116 |
+
const vbool32 mask_2nd = (vbool32){g0_2, g1_2, g2_2, g3_2};
|
| 117 |
+
// generated masks
|
| 118 |
+
return {a, (vint32)vec_sel(a._vec1, b._vec1, (vbool32)mask_2nd)};
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
template <uint64_t mask>
|
| 122 |
+
static std::enable_if_t<
|
| 123 |
+
(mask > 15 && ((mask & 255) != 255) && ((mask & 15) != 0) &&
|
| 124 |
+
((mask & 15) != 15)),
|
| 125 |
+
Vectorized<int32_t>>
|
| 126 |
+
C10_ALWAYS_INLINE blend(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 127 |
+
constexpr uint32_t g0 = (mask & 1) * 0xffffffff;
|
| 128 |
+
constexpr uint32_t g1 = ((mask & 2) >> 1) * 0xffffffff;
|
| 129 |
+
constexpr uint32_t g2 = ((mask & 4) >> 2) * 0xffffffff;
|
| 130 |
+
constexpr uint32_t g3 = ((mask & 8) >> 3) * 0xffffffff;
|
| 131 |
+
constexpr uint32_t mask2 = (mask & 255) >> 4;
|
| 132 |
+
constexpr uint32_t g0_2 = (mask2 & 1) * 0xffffffff;
|
| 133 |
+
constexpr uint32_t g1_2 = ((mask2 & 2) >> 1) * 0xffffffff;
|
| 134 |
+
constexpr uint32_t g2_2 = ((mask2 & 4) >> 2) * 0xffffffff;
|
| 135 |
+
constexpr uint32_t g3_2 = ((mask2 & 8) >> 3) * 0xffffffff;
|
| 136 |
+
|
| 137 |
+
const vbool32 mask_1st = (vbool32){g0, g1, g2, g3};
|
| 138 |
+
const vbool32 mask_2nd = (vbool32){g0_2, g1_2, g2_2, g3_2};
|
| 139 |
+
// generated masks
|
| 140 |
+
return {
|
| 141 |
+
(vint32)vec_sel(a._vec0, b._vec0, (vbool32)mask_1st),
|
| 142 |
+
(vint32)vec_sel(a._vec1, b._vec1, (vbool32)mask_2nd)};
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
static Vectorized<int32_t> C10_ALWAYS_INLINE blendv(
|
| 146 |
+
const Vectorized<int32_t>& a,
|
| 147 |
+
const Vectorized<int32_t>& b,
|
| 148 |
+
const Vectorized<int32_t>& mask) {
|
| 149 |
+
// the mask used here returned by comparision of vec256
|
| 150 |
+
// assuming this we can use the same mask directly with vec_sel
|
| 151 |
+
// warning intel style mask will not work properly
|
| 152 |
+
return {
|
| 153 |
+
vec_sel(a._vec0, b._vec0, mask._vecb0),
|
| 154 |
+
vec_sel(a._vec1, b._vec1, mask._vecb1)};
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
template <typename step_t>
|
| 158 |
+
static Vectorized<int32_t> arange(int32_t base = 0.f, step_t step = static_cast<step_t>(1)) {
|
| 159 |
+
return Vectorized<int32_t>(
|
| 160 |
+
base,
|
| 161 |
+
base + step,
|
| 162 |
+
base + 2 * step,
|
| 163 |
+
base + 3 * step,
|
| 164 |
+
base + 4 * step,
|
| 165 |
+
base + 5 * step,
|
| 166 |
+
base + 6 * step,
|
| 167 |
+
base + 7 * step);
|
| 168 |
+
}
|
| 169 |
+
static Vectorized<int32_t> set(
|
| 170 |
+
const Vectorized<int32_t>& a,
|
| 171 |
+
const Vectorized<int32_t>& b,
|
| 172 |
+
size_t count = size()) {
|
| 173 |
+
switch (count) {
|
| 174 |
+
case 0:
|
| 175 |
+
return a;
|
| 176 |
+
case 1:
|
| 177 |
+
return blend<1>(a, b);
|
| 178 |
+
case 2:
|
| 179 |
+
return blend<3>(a, b);
|
| 180 |
+
case 3:
|
| 181 |
+
return blend<7>(a, b);
|
| 182 |
+
case 4:
|
| 183 |
+
return blend<15>(a, b);
|
| 184 |
+
case 5:
|
| 185 |
+
return blend<31>(a, b);
|
| 186 |
+
case 6:
|
| 187 |
+
return blend<63>(a, b);
|
| 188 |
+
case 7:
|
| 189 |
+
return blend<127>(a, b);
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
return b;
|
| 193 |
+
}
|
| 194 |
+
static Vectorized<value_type> C10_ALWAYS_INLINE
|
| 195 |
+
loadu(const void* ptr, int count = size()) {
|
| 196 |
+
if (count == size()) {
|
| 197 |
+
return {
|
| 198 |
+
vec_vsx_ld(offset0, reinterpret_cast<const value_type*>(ptr)),
|
| 199 |
+
vec_vsx_ld(offset16, reinterpret_cast<const value_type*>(ptr))};
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
__at_align__ value_type tmp_values[size()] = {};
|
| 203 |
+
std::memcpy(tmp_values, ptr, std::min(count, size()) * sizeof(value_type));
|
| 204 |
+
|
| 205 |
+
return {vec_vsx_ld(offset0, tmp_values), vec_vsx_ld(offset16, tmp_values)};
|
| 206 |
+
}
|
| 207 |
+
void C10_ALWAYS_INLINE store(void* ptr, int count = size()) const {
|
| 208 |
+
if (count == size()) {
|
| 209 |
+
vec_vsx_st(_vec0, offset0, reinterpret_cast<value_type*>(ptr));
|
| 210 |
+
vec_vsx_st(_vec1, offset16, reinterpret_cast<value_type*>(ptr));
|
| 211 |
+
} else if (count > 0) {
|
| 212 |
+
__at_align__ value_type tmp_values[size()];
|
| 213 |
+
vec_vsx_st(_vec0, offset0, tmp_values);
|
| 214 |
+
vec_vsx_st(_vec1, offset16, tmp_values);
|
| 215 |
+
std::memcpy(
|
| 216 |
+
ptr, tmp_values, std::min(count, size()) * sizeof(value_type));
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
const int32_t& operator[](int idx) const = delete;
|
| 220 |
+
int32_t& operator[](int idx) = delete;
|
| 221 |
+
|
| 222 |
+
Vectorized<int32_t> angle() const {
|
| 223 |
+
return blendv(
|
| 224 |
+
Vectorized<int32_t>(0), Vectorized<int32_t>(c10::pi<int32_t>), *this < Vectorized<int32_t>(0));
|
| 225 |
+
}
|
| 226 |
+
Vectorized<int32_t> real() const {
|
| 227 |
+
return *this;
|
| 228 |
+
}
|
| 229 |
+
Vectorized<int32_t> imag() const {
|
| 230 |
+
return Vectorized<int32_t>{0};
|
| 231 |
+
}
|
| 232 |
+
Vectorized<int32_t> conj() const {
|
| 233 |
+
return *this;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
Vectorized<int32_t> C10_ALWAYS_INLINE abs() const {
|
| 237 |
+
return {vec_abs(_vec0), vec_abs(_vec1)};
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
Vectorized<int32_t> C10_ALWAYS_INLINE neg() const {
|
| 241 |
+
return {vec_neg(_vec0), vec_neg(_vec1)};
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
DEFINE_MEMBER_UNARY_OP(operator~, int32_t, vec_not)
|
| 245 |
+
DEFINE_MEMBER_OP(operator==, int32_t, vec_cmpeq)
|
| 246 |
+
DEFINE_MEMBER_OP(operator!=, int32_t, vec_cmpne)
|
| 247 |
+
DEFINE_MEMBER_OP(operator<, int32_t, vec_cmplt)
|
| 248 |
+
DEFINE_MEMBER_OP(operator<=, int32_t, vec_cmple)
|
| 249 |
+
DEFINE_MEMBER_OP(operator>, int32_t, vec_cmpgt)
|
| 250 |
+
DEFINE_MEMBER_OP(operator>=, int32_t, vec_cmpge)
|
| 251 |
+
DEFINE_MEMBER_OP_AND_ONE(eq, int32_t, vec_cmpeq)
|
| 252 |
+
DEFINE_MEMBER_OP_AND_ONE(ne, int32_t, vec_cmpne)
|
| 253 |
+
DEFINE_MEMBER_OP_AND_ONE(lt, int32_t, vec_cmplt)
|
| 254 |
+
DEFINE_MEMBER_OP_AND_ONE(le, int32_t, vec_cmple)
|
| 255 |
+
DEFINE_MEMBER_OP_AND_ONE(gt, int32_t, vec_cmpgt)
|
| 256 |
+
DEFINE_MEMBER_OP_AND_ONE(ge, int32_t, vec_cmpge)
|
| 257 |
+
DEFINE_MEMBER_OP(operator+, int32_t, vec_add)
|
| 258 |
+
DEFINE_MEMBER_OP(operator-, int32_t, vec_sub)
|
| 259 |
+
DEFINE_MEMBER_OP(operator*, int32_t, vec_mul)
|
| 260 |
+
DEFINE_MEMBER_EMULATE_BINARY_OP(operator/, int32_t, /)
|
| 261 |
+
DEFINE_MEMBER_OP(maximum, int32_t, vec_max)
|
| 262 |
+
DEFINE_MEMBER_OP(minimum, int32_t, vec_min)
|
| 263 |
+
DEFINE_MEMBER_OP(operator&, int32_t, vec_and)
|
| 264 |
+
DEFINE_MEMBER_OP(operator|, int32_t, vec_or)
|
| 265 |
+
DEFINE_MEMBER_OP(operator^, int32_t, vec_xor)
|
| 266 |
+
};
|
| 267 |
+
|
| 268 |
+
template <>
|
| 269 |
+
Vectorized<int32_t> inline operator<<(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 270 |
+
vuint32 shift_vec0 = reinterpret_cast<vuint32>(b.vec0());
|
| 271 |
+
vuint32 shift_vec1 = reinterpret_cast<vuint32>(b.vec1()) ;
|
| 272 |
+
return Vectorized<int32_t>{vec_sl(a.vec0(), shift_vec0), vec_sl(a.vec1(), shift_vec1)};
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
template <>
|
| 276 |
+
Vectorized<int32_t> inline operator>>(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 277 |
+
vuint32 shift_vec0 = reinterpret_cast<vuint32>(b.vec0());
|
| 278 |
+
vuint32 shift_vec1 = reinterpret_cast<vuint32>(b.vec1()) ;
|
| 279 |
+
return Vectorized<int32_t>{vec_sr(a.vec0(), shift_vec0), vec_sr(a.vec1(), shift_vec1)};
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
template <>
|
| 283 |
+
Vectorized<int32_t> inline maximum(
|
| 284 |
+
const Vectorized<int32_t>& a,
|
| 285 |
+
const Vectorized<int32_t>& b) {
|
| 286 |
+
return a.maximum(b);
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
template <>
|
| 290 |
+
Vectorized<int32_t> inline minimum(
|
| 291 |
+
const Vectorized<int32_t>& a,
|
| 292 |
+
const Vectorized<int32_t>& b) {
|
| 293 |
+
return a.minimum(b);
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
} // namespace
|
| 297 |
+
} // namespace vec
|
| 298 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_int64_vsx.h
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 4 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 5 |
+
#include <ATen/cpu/vec/vec256/vsx/vsx_helpers.h>
|
| 6 |
+
namespace at {
|
| 7 |
+
namespace vec {
|
| 8 |
+
// See Note [CPU_CAPABILITY namespace]
|
| 9 |
+
inline namespace CPU_CAPABILITY {
|
| 10 |
+
|
| 11 |
+
template <>
|
| 12 |
+
class Vectorized<int64_t> {
|
| 13 |
+
private:
|
| 14 |
+
union {
|
| 15 |
+
struct {
|
| 16 |
+
vint64 _vec0;
|
| 17 |
+
vint64 _vec1;
|
| 18 |
+
};
|
| 19 |
+
struct {
|
| 20 |
+
vbool64 _vecb0;
|
| 21 |
+
vbool64 _vecb1;
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
} __attribute__((__may_alias__));
|
| 25 |
+
|
| 26 |
+
public:
|
| 27 |
+
using value_type = int64_t;
|
| 28 |
+
using vec_internal_type = vint64;
|
| 29 |
+
using vec_internal_mask_type = vbool64;
|
| 30 |
+
using size_type = int;
|
| 31 |
+
using ElementType = signed long long;
|
| 32 |
+
static constexpr size_type size() {
|
| 33 |
+
return 4;
|
| 34 |
+
}
|
| 35 |
+
Vectorized() {}
|
| 36 |
+
C10_ALWAYS_INLINE Vectorized(vint64 v) : _vec0{v}, _vec1{v} {}
|
| 37 |
+
C10_ALWAYS_INLINE Vectorized(vbool64 vmask) : _vecb0{vmask}, _vecb1{vmask} {}
|
| 38 |
+
C10_ALWAYS_INLINE Vectorized(vint64 v1, vint64 v2) : _vec0{v1}, _vec1{v2} {}
|
| 39 |
+
C10_ALWAYS_INLINE Vectorized(vbool64 v1, vbool64 v2) : _vecb0{v1}, _vecb1{v2} {}
|
| 40 |
+
C10_ALWAYS_INLINE Vectorized(int64_t scalar)
|
| 41 |
+
: _vec0{vec_splats(scalar)}, _vec1{vec_splats(scalar)} {}
|
| 42 |
+
C10_ALWAYS_INLINE Vectorized(
|
| 43 |
+
int64_t scalar1,
|
| 44 |
+
int64_t scalar2,
|
| 45 |
+
int64_t scalar3,
|
| 46 |
+
int64_t scalar4)
|
| 47 |
+
: _vec0{vint64{scalar1, scalar2}}, _vec1{vint64{scalar3, scalar4}} {}
|
| 48 |
+
|
| 49 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec0() const {
|
| 50 |
+
return _vec0;
|
| 51 |
+
}
|
| 52 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec1() const {
|
| 53 |
+
return _vec1;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
template <uint64_t mask>
|
| 57 |
+
static std::enable_if_t<mask == 0, Vectorized<int64_t>> C10_ALWAYS_INLINE
|
| 58 |
+
blend(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 59 |
+
return a;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
template <uint64_t mask>
|
| 63 |
+
static std::enable_if_t<mask == 3, Vectorized<int64_t>> C10_ALWAYS_INLINE
|
| 64 |
+
blend(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 65 |
+
return {b._vec0, a._vec1};
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
template <uint64_t mask>
|
| 69 |
+
static std::enable_if_t<(mask & 15) == 15, Vectorized<int64_t>> C10_ALWAYS_INLINE
|
| 70 |
+
blend(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 71 |
+
return b;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
template <uint64_t mask>
|
| 75 |
+
static std::enable_if_t<(mask > 0 && mask < 3), Vectorized<int64_t>> C10_ALWAYS_INLINE
|
| 76 |
+
blend(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 77 |
+
constexpr uint64_t g0 = (mask & 1) * 0xffffffffffffffff;
|
| 78 |
+
constexpr uint64_t g1 = ((mask & 2) >> 1) * 0xffffffffffffffff;
|
| 79 |
+
const vbool64 mask_1st = (vbool64){g0, g1};
|
| 80 |
+
return {(vint64)vec_sel(a._vec0, b._vec0, (vbool64)mask_1st), a._vec1};
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
template <uint64_t mask>
|
| 84 |
+
static std::enable_if_t<(mask > 3) && (mask & 3) == 0, Vectorized<int64_t>>
|
| 85 |
+
C10_ALWAYS_INLINE blend(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 86 |
+
constexpr uint64_t g0_2 = ((mask & 4) >> 2) * 0xffffffffffffffff;
|
| 87 |
+
constexpr uint64_t g1_2 = ((mask & 8) >> 3) * 0xffffffffffffffff;
|
| 88 |
+
|
| 89 |
+
const vbool64 mask_2nd = (vbool64){g0_2, g1_2};
|
| 90 |
+
return {a._vec0, (vint64)vec_sel(a._vec1, b._vec1, (vbool64)mask_2nd)};
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
template <uint64_t mask>
|
| 94 |
+
static std::enable_if_t<
|
| 95 |
+
(mask > 3) && (mask & 3) != 0 && (mask & 15) != 15,
|
| 96 |
+
Vectorized<int64_t>>
|
| 97 |
+
C10_ALWAYS_INLINE blend(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 98 |
+
constexpr uint64_t g0 = (mask & 1) * 0xffffffffffffffff;
|
| 99 |
+
constexpr uint64_t g1 = ((mask & 2) >> 1) * 0xffffffffffffffff;
|
| 100 |
+
constexpr uint64_t g0_2 = ((mask & 4) >> 2) * 0xffffffffffffffff;
|
| 101 |
+
constexpr uint64_t g1_2 = ((mask & 8) >> 3) * 0xffffffffffffffff;
|
| 102 |
+
|
| 103 |
+
const vbool64 mask_1st = (vbool64){g0, g1};
|
| 104 |
+
const vbool64 mask_2nd = (vbool64){g0_2, g1_2};
|
| 105 |
+
return {
|
| 106 |
+
(vint64)vec_sel(a._vec0, b._vec0, (vbool64)mask_1st),
|
| 107 |
+
(vint64)vec_sel(a._vec1, b._vec1, (vbool64)mask_2nd)};
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
static Vectorized<int64_t> C10_ALWAYS_INLINE blendv(
|
| 111 |
+
const Vectorized<int64_t>& a,
|
| 112 |
+
const Vectorized<int64_t>& b,
|
| 113 |
+
const Vectorized<int64_t>& mask) {
|
| 114 |
+
// the mask used here returned by comparision of vec256
|
| 115 |
+
|
| 116 |
+
return {
|
| 117 |
+
vec_sel(a._vec0, b._vec0, mask._vecb0),
|
| 118 |
+
vec_sel(a._vec1, b._vec1, mask._vecb1)};
|
| 119 |
+
}
|
| 120 |
+
template <typename step_t>
|
| 121 |
+
static Vectorized<int64_t> arange(int64_t base = 0., step_t step = static_cast<step_t>(1)) {
|
| 122 |
+
return Vectorized<int64_t>(base, base + step, base + 2 * step, base + 3 * step);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
static Vectorized<int64_t> C10_ALWAYS_INLINE
|
| 126 |
+
set(const Vectorized<int64_t>& a,
|
| 127 |
+
const Vectorized<int64_t>& b,
|
| 128 |
+
size_t count = size()) {
|
| 129 |
+
switch (count) {
|
| 130 |
+
case 0:
|
| 131 |
+
return a;
|
| 132 |
+
case 1:
|
| 133 |
+
return blend<1>(a, b);
|
| 134 |
+
case 2:
|
| 135 |
+
return blend<3>(a, b);
|
| 136 |
+
case 3:
|
| 137 |
+
return blend<7>(a, b);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
return b;
|
| 141 |
+
}
|
| 142 |
+
static Vectorized<value_type> C10_ALWAYS_INLINE
|
| 143 |
+
loadu(const void* ptr, int count = size()) {
|
| 144 |
+
if (count == size()) {
|
| 145 |
+
static_assert(sizeof(double) == sizeof(value_type));
|
| 146 |
+
const double* dptr = reinterpret_cast<const double*>(ptr);
|
| 147 |
+
return {// treat it as double load
|
| 148 |
+
(vint64)vec_vsx_ld(offset0, dptr),
|
| 149 |
+
(vint64)vec_vsx_ld(offset16, dptr)};
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
__at_align__ double tmp_values[size()] = {};
|
| 153 |
+
std::memcpy(tmp_values, ptr, std::min(count, size()) * sizeof(value_type));
|
| 154 |
+
|
| 155 |
+
return {
|
| 156 |
+
(vint64)vec_vsx_ld(offset0, tmp_values),
|
| 157 |
+
(vint64)vec_vsx_ld(offset16, tmp_values)};
|
| 158 |
+
}
|
| 159 |
+
void C10_ALWAYS_INLINE store(void* ptr, int count = size()) const {
|
| 160 |
+
if (count == size()) {
|
| 161 |
+
double* dptr = reinterpret_cast<double*>(ptr);
|
| 162 |
+
vec_vsx_st((vfloat64)_vec0, offset0, dptr);
|
| 163 |
+
vec_vsx_st((vfloat64)_vec1, offset16, dptr);
|
| 164 |
+
} else if (count > 0) {
|
| 165 |
+
__at_align__ double tmp_values[size()];
|
| 166 |
+
vec_vsx_st((vfloat64)_vec0, offset0, tmp_values);
|
| 167 |
+
vec_vsx_st((vfloat64)_vec1, offset16, tmp_values);
|
| 168 |
+
std::memcpy(
|
| 169 |
+
ptr, tmp_values, std::min(count, size()) * sizeof(value_type));
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
const int64_t& operator[](int idx) const = delete;
|
| 173 |
+
int64_t& operator[](int idx) = delete;
|
| 174 |
+
|
| 175 |
+
Vectorized<int64_t> angle() const {
|
| 176 |
+
return blendv(
|
| 177 |
+
Vectorized<int64_t>(0), Vectorized<int64_t>(c10::pi<int64_t>), *this < Vectorized<int64_t>(0));
|
| 178 |
+
}
|
| 179 |
+
Vectorized<int64_t> real() const {
|
| 180 |
+
return *this;
|
| 181 |
+
}
|
| 182 |
+
Vectorized<int64_t> imag() const {
|
| 183 |
+
return Vectorized<int64_t>{0};
|
| 184 |
+
}
|
| 185 |
+
Vectorized<int64_t> conj() const {
|
| 186 |
+
return *this;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
Vectorized<int64_t> C10_ALWAYS_INLINE abs() const {
|
| 190 |
+
return {vec_abs(_vec0), vec_abs(_vec1)};
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
Vectorized<int64_t> C10_ALWAYS_INLINE neg() const {
|
| 194 |
+
return {vec_neg(_vec0), vec_neg(_vec1)};
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
DEFINE_MEMBER_UNARY_OP(operator~, int64_t, vec_not)
|
| 198 |
+
DEFINE_MEMBER_OP(operator==, int64_t, vec_cmpeq)
|
| 199 |
+
DEFINE_MEMBER_OP(operator!=, int64_t, vec_cmpne)
|
| 200 |
+
DEFINE_MEMBER_OP(operator<, int64_t, vec_cmplt)
|
| 201 |
+
DEFINE_MEMBER_OP(operator<=, int64_t, vec_cmple)
|
| 202 |
+
DEFINE_MEMBER_OP(operator>, int64_t, vec_cmpgt)
|
| 203 |
+
DEFINE_MEMBER_OP(operator>=, int64_t, vec_cmpge)
|
| 204 |
+
DEFINE_MEMBER_OP_AND_ONE(eq, int64_t, vec_cmpeq)
|
| 205 |
+
DEFINE_MEMBER_OP_AND_ONE(ne, int64_t, vec_cmpne)
|
| 206 |
+
DEFINE_MEMBER_OP_AND_ONE(lt, int64_t, vec_cmplt)
|
| 207 |
+
DEFINE_MEMBER_OP_AND_ONE(le, int64_t, vec_cmple)
|
| 208 |
+
DEFINE_MEMBER_OP_AND_ONE(gt, int64_t, vec_cmpgt)
|
| 209 |
+
DEFINE_MEMBER_OP_AND_ONE(ge, int64_t, vec_cmpge)
|
| 210 |
+
DEFINE_MEMBER_OP(operator+, int64_t, vec_add)
|
| 211 |
+
DEFINE_MEMBER_OP(operator-, int64_t, vec_sub)
|
| 212 |
+
DEFINE_MEMBER_OP(operator*, int64_t, vec_mul)
|
| 213 |
+
DEFINE_MEMBER_OP(operator/, int64_t, vec_div)
|
| 214 |
+
DEFINE_MEMBER_OP(maximum, int64_t, vec_max)
|
| 215 |
+
DEFINE_MEMBER_OP(minimum, int64_t, vec_min)
|
| 216 |
+
DEFINE_MEMBER_OP(operator&, int64_t, vec_and)
|
| 217 |
+
DEFINE_MEMBER_OP(operator|, int64_t, vec_or)
|
| 218 |
+
DEFINE_MEMBER_OP(operator^, int64_t, vec_xor)
|
| 219 |
+
};
|
| 220 |
+
|
| 221 |
+
template <>
|
| 222 |
+
Vectorized<int64_t> inline operator<<(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 223 |
+
vuint64 shift_vec0 = reinterpret_cast<vuint64>(b.vec0());
|
| 224 |
+
vuint64 shift_vec1 = reinterpret_cast<vuint64>(b.vec1()) ;
|
| 225 |
+
return Vectorized<int64_t>{vec_sl(a.vec0(), shift_vec0), vec_sl(a.vec1(), shift_vec1)};
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
template <>
|
| 229 |
+
Vectorized<int64_t> inline operator>>(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 230 |
+
vuint64 shift_vec0 = reinterpret_cast<vuint64>(b.vec0());
|
| 231 |
+
vuint64 shift_vec1 = reinterpret_cast<vuint64>(b.vec1()) ;
|
| 232 |
+
return Vectorized<int64_t>{vec_sr(a.vec0(), shift_vec0), vec_sr(a.vec1(), shift_vec1)};
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
template <>
|
| 236 |
+
Vectorized<int64_t> inline maximum(
|
| 237 |
+
const Vectorized<int64_t>& a,
|
| 238 |
+
const Vectorized<int64_t>& b) {
|
| 239 |
+
return a.maximum(b);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
template <>
|
| 243 |
+
Vectorized<int64_t> inline minimum(
|
| 244 |
+
const Vectorized<int64_t>& a,
|
| 245 |
+
const Vectorized<int64_t>& b) {
|
| 246 |
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 4 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 5 |
+
#include <ATen/cpu/vec/vec256/vsx/vsx_helpers.h>
|
| 6 |
+
#include <c10/util/qint32.h>
|
| 7 |
+
#include <array>
|
| 8 |
+
|
| 9 |
+
// This file defines Vectorized<> for the quantized types.
|
| 10 |
+
//
|
| 11 |
+
//
|
| 12 |
+
// Currently, we simply use these classes as efficient converters between
|
| 13 |
+
// the quantized types and Vectorized<float>, usually in bandwidth-bound cases
|
| 14 |
+
// where doing the arithmetic in full-precision is acceptable (e.g.
|
| 15 |
+
// elementwise operators).
|
| 16 |
+
//
|
| 17 |
+
//
|
| 18 |
+
// Conversions are as follows:
|
| 19 |
+
// Vectorized<qint32> -> 1x Vectorized<float>
|
| 20 |
+
//
|
| 21 |
+
// The size of the returned float vector is specified by the special
|
| 22 |
+
// constexpr function float_num_vecs. The type of the value returned
|
| 23 |
+
// from dequantize (and expected as an argument to quantize) is
|
| 24 |
+
// specified by float_vec_return_type.
|
| 25 |
+
//
|
| 26 |
+
// When writing kernels with these vectors, it is expected that floating-
|
| 27 |
+
// point operations will be carried out in a loop over Vectorized<T>::float_num_vecs
|
| 28 |
+
// iterations.
|
| 29 |
+
|
| 30 |
+
namespace at {
|
| 31 |
+
namespace vec {
|
| 32 |
+
inline namespace CPU_CAPABILITY {
|
| 33 |
+
|
| 34 |
+
template <>
|
| 35 |
+
struct Vectorized<c10::qint32> {
|
| 36 |
+
private:
|
| 37 |
+
union {
|
| 38 |
+
struct {
|
| 39 |
+
vint32 _vec0;
|
| 40 |
+
vint32 _vec1;
|
| 41 |
+
};
|
| 42 |
+
struct {
|
| 43 |
+
vbool32 _vecb0;
|
| 44 |
+
vbool32 _vecb1;
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
} __attribute__((__may_alias__));
|
| 48 |
+
|
| 49 |
+
public:
|
| 50 |
+
Vectorized() {}
|
| 51 |
+
|
| 52 |
+
using size_type = int;
|
| 53 |
+
static constexpr size_type size() {
|
| 54 |
+
return 8;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
static constexpr size_t float_num_vecs() {
|
| 58 |
+
return 1;
|
| 59 |
+
}
|
| 60 |
+
static constexpr int int_num_vecs() {
|
| 61 |
+
return 1;
|
| 62 |
+
}
|
| 63 |
+
using float_vec_return_type = std::array<Vectorized<float>, 1>;
|
| 64 |
+
using int_vec_return_type = std::array<Vectorized<c10::qint32>, 1>;
|
| 65 |
+
using value_type = c10::qint32::underlying;
|
| 66 |
+
using vec_internal_type = vint32;
|
| 67 |
+
using vec_internal_mask_type = vbool32;
|
| 68 |
+
C10_ALWAYS_INLINE Vectorized(vint32 v) : _vec0{v}, _vec1{v} {}
|
| 69 |
+
C10_ALWAYS_INLINE Vectorized(vbool32 vmask) : _vecb0{vmask}, _vecb1{vmask} {}
|
| 70 |
+
C10_ALWAYS_INLINE Vectorized(vint32 v1, vint32 v2) : _vec0{v1}, _vec1{v2} {}
|
| 71 |
+
C10_ALWAYS_INLINE Vectorized(vbool32 v1, vbool32 v2) : _vecb0{v1}, _vecb1{v2} {}
|
| 72 |
+
|
| 73 |
+
Vectorized(const c10::qint32& val)
|
| 74 |
+
: _vec0(vec_splats(val.val_)), _vec1(vec_splats(val.val_)) {}
|
| 75 |
+
|
| 76 |
+
static Vectorized<c10::qint32> C10_ALWAYS_INLINE
|
| 77 |
+
loadu(const void* ptr, int count = size()) {
|
| 78 |
+
if (count == size()) {
|
| 79 |
+
return {
|
| 80 |
+
vec_vsx_ld(offset0, reinterpret_cast<const value_type*>(ptr)),
|
| 81 |
+
vec_vsx_ld(offset16, reinterpret_cast<const value_type*>(ptr))};
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
__at_align__ value_type tmp_values[size()] = {};
|
| 85 |
+
std::memcpy(tmp_values, ptr, std::min(count, size()) * sizeof(value_type));
|
| 86 |
+
|
| 87 |
+
return {vec_vsx_ld(offset0, tmp_values), vec_vsx_ld(offset16, tmp_values)};
|
| 88 |
+
}
|
| 89 |
+
void C10_ALWAYS_INLINE store(void* ptr, int count = size()) const {
|
| 90 |
+
if (count == size()) {
|
| 91 |
+
vec_vsx_st(_vec0, offset0, reinterpret_cast<value_type*>(ptr));
|
| 92 |
+
vec_vsx_st(_vec1, offset16, reinterpret_cast<value_type*>(ptr));
|
| 93 |
+
} else if (count > 0) {
|
| 94 |
+
__at_align__ value_type tmp_values[size()];
|
| 95 |
+
vec_vsx_st(_vec0, offset0, tmp_values);
|
| 96 |
+
vec_vsx_st(_vec1, offset16, tmp_values);
|
| 97 |
+
std::memcpy(
|
| 98 |
+
ptr, tmp_values, std::min(count, size()) * sizeof(value_type));
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec0() const {
|
| 103 |
+
return _vec0;
|
| 104 |
+
}
|
| 105 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec1() const {
|
| 106 |
+
return _vec1;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
float_vec_return_type dequantize(
|
| 110 |
+
Vectorized<float> scale,
|
| 111 |
+
Vectorized<float> zero_point,
|
| 112 |
+
Vectorized<float> scale_zp_premul) const {
|
| 113 |
+
vfloat32 float_vals0 = vec_float(_vec0);
|
| 114 |
+
vfloat32 float_vals1 = vec_float(_vec1);
|
| 115 |
+
vfloat32 scale_vec0 = scale.vec0();
|
| 116 |
+
vfloat32 scale_vec1 = scale.vec1();
|
| 117 |
+
vfloat32 scale_zp_premul0 = scale_zp_premul.vec0();
|
| 118 |
+
vfloat32 scale_zp_premul1 = scale_zp_premul.vec1();
|
| 119 |
+
return {Vectorized<float>{
|
| 120 |
+
vec_madd(scale_vec0, float_vals0, scale_zp_premul0),
|
| 121 |
+
vec_madd(scale_vec1, float_vals1, scale_zp_premul1)}};
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
float_vec_return_type dequantize(
|
| 125 |
+
Vectorized<float> scale,
|
| 126 |
+
Vectorized<float> zero_point) const {
|
| 127 |
+
vfloat32 float_vals0 = vec_float(_vec0);
|
| 128 |
+
vfloat32 float_vals1 = vec_float(_vec1);
|
| 129 |
+
vfloat32 scale_vec0 = scale.vec0();
|
| 130 |
+
vfloat32 scale_vec1 = scale.vec1();
|
| 131 |
+
vfloat32 zero_point0 = zero_point.vec0();
|
| 132 |
+
vfloat32 zero_point1 = zero_point.vec1();
|
| 133 |
+
return {Vectorized<float>{
|
| 134 |
+
(float_vals0 - zero_point0) * scale_vec0,
|
| 135 |
+
(float_vals1 - zero_point1) * scale_vec1}};
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
static Vectorized<c10::qint32> quantize(
|
| 139 |
+
const float_vec_return_type& rhs,
|
| 140 |
+
float scale,
|
| 141 |
+
int32_t zero_point,
|
| 142 |
+
float inverse_scale) {
|
| 143 |
+
Vectorized<c10::qint32> retval;
|
| 144 |
+
|
| 145 |
+
const vint32 vmin = vec_splats(std::numeric_limits<value_type>::min());
|
| 146 |
+
const vint32 vmax = vec_splats(std::numeric_limits<value_type>::max());
|
| 147 |
+
vfloat32 inverse_scale_v = vec_splats(inverse_scale);
|
| 148 |
+
vfloat32 vec_zero_point = vec_splats((float)(zero_point));
|
| 149 |
+
Vectorized<float> vf0 = rhs[0];
|
| 150 |
+
|
| 151 |
+
vfloat32 vecf0 = vf0.vec0();
|
| 152 |
+
vfloat32 vecf1 = vf0.vec1();
|
| 153 |
+
vecf0 = vec_mul(vecf0, inverse_scale_v);
|
| 154 |
+
vecf1 = vec_mul(vecf1, inverse_scale_v);
|
| 155 |
+
vecf0 = vec_add(vec_rint(vecf0), vec_zero_point);
|
| 156 |
+
vecf1 = vec_add(vec_rint(vecf1), vec_zero_point);
|
| 157 |
+
vint32 veci0 = vec_signed(vecf0);
|
| 158 |
+
vint32 veci1 = vec_signed(vecf1);
|
| 159 |
+
|
| 160 |
+
veci0 = vec_max(veci0, vmin);
|
| 161 |
+
veci1 = vec_max(veci1, vmin);
|
| 162 |
+
veci0 = vec_min(veci0, vmax);
|
| 163 |
+
veci1 = vec_min(veci1, vmax);
|
| 164 |
+
|
| 165 |
+
return {veci0, veci1};
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
Vectorized<c10::qint32> relu(Vectorized<c10::qint32> zero_point) const {
|
| 169 |
+
return {vec_max(_vec0, zero_point._vec0), vec_max(_vec1, zero_point._vec1)};
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
Vectorized<c10::qint32> relu6(
|
| 173 |
+
Vectorized<c10::qint32> zero_point,
|
| 174 |
+
Vectorized<c10::qint32> q_six) const {
|
| 175 |
+
vint32 max0 = vec_max(_vec0, zero_point._vec0);
|
| 176 |
+
vint32 max1 = vec_max(_vec1, zero_point._vec1);
|
| 177 |
+
return {vec_min(max0, q_six._vec0), vec_min(max1, q_six._vec1)};
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
int_vec_return_type widening_subtract(Vectorized<c10::qint32> b) const {
|
| 181 |
+
return {*this - b};
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
static Vectorized<c10::qint32> requantize_from_int(
|
| 185 |
+
const int_vec_return_type& inp,
|
| 186 |
+
float multiplier,
|
| 187 |
+
int32_t zero_point) {
|
| 188 |
+
const vint32 vmin = vec_splats(std::numeric_limits<value_type>::min());
|
| 189 |
+
const vint32 vmax = vec_splats(std::numeric_limits<value_type>::max());
|
| 190 |
+
vfloat32 vec_mult = vec_splats(multiplier);
|
| 191 |
+
vint32 vec_zero_point = vec_splats(zero_point);
|
| 192 |
+
Vectorized<c10::qint32> vi = inp[0];
|
| 193 |
+
vfloat32 vecf0 = vec_float(vi.vec0());
|
| 194 |
+
vfloat32 vecf1 = vec_float(vi.vec1());
|
| 195 |
+
|
| 196 |
+
vecf0 = vec_mul(vecf0, vec_mult);
|
| 197 |
+
vecf1 = vec_mul(vecf1, vec_mult);
|
| 198 |
+
|
| 199 |
+
vecf0 = vec_rint(vecf0);
|
| 200 |
+
vecf1 = vec_rint(vecf1);
|
| 201 |
+
|
| 202 |
+
vint32 veci0 = vec_add(vec_signed(vecf0),vec_zero_point);
|
| 203 |
+
vint32 veci1 = vec_add(vec_signed(vecf1),vec_zero_point);
|
| 204 |
+
|
| 205 |
+
veci0 = vec_max(veci0, vmin);
|
| 206 |
+
veci1 = vec_max(veci1, vmin);
|
| 207 |
+
veci0 = vec_min(veci0, vmax);
|
| 208 |
+
veci1 = vec_min(veci1, vmax);
|
| 209 |
+
|
| 210 |
+
return {veci0, veci1};
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
DEFINE_MEMBER_OP(operator==, c10::qint32, vec_cmpeq)
|
| 214 |
+
DEFINE_MEMBER_OP(operator!=, c10::qint32, vec_cmpne)
|
| 215 |
+
DEFINE_MEMBER_OP(operator<, c10::qint32, vec_cmplt)
|
| 216 |
+
DEFINE_MEMBER_OP(operator<=, c10::qint32, vec_cmple)
|
| 217 |
+
DEFINE_MEMBER_OP(operator>, c10::qint32, vec_cmpgt)
|
| 218 |
+
DEFINE_MEMBER_OP(operator>=, c10::qint32, vec_cmpge)
|
| 219 |
+
DEFINE_MEMBER_OP(operator+, c10::qint32, vec_add)
|
| 220 |
+
DEFINE_MEMBER_OP(operator-, c10::qint32, vec_sub)
|
| 221 |
+
DEFINE_MEMBER_OP(operator*, c10::qint32, vec_mul)
|
| 222 |
+
DEFINE_MEMBER_EMULATE_BINARY_OP(operator/, c10::qint32, /)
|
| 223 |
+
DEFINE_MEMBER_OP(maximum, c10::qint32, vec_max)
|
| 224 |
+
DEFINE_MEMBER_OP(minimum, c10::qint32, vec_min)
|
| 225 |
+
DEFINE_MEMBER_OP(operator&, c10::qint32, vec_and)
|
| 226 |
+
DEFINE_MEMBER_OP(operator|, c10::qint32, vec_or)
|
| 227 |
+
DEFINE_MEMBER_OP(operator^, c10::qint32, vec_xor)
|
| 228 |
+
};
|
| 229 |
+
|
| 230 |
+
template <>
|
| 231 |
+
Vectorized<c10::qint32> inline maximum(
|
| 232 |
+
const Vectorized<c10::qint32>& a,
|
| 233 |
+
const Vectorized<c10::qint32>& b) {
|
| 234 |
+
return a.maximum(b);
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
template <>
|
| 238 |
+
Vectorized<c10::qint32> inline minimum(
|
| 239 |
+
const Vectorized<c10::qint32>& a,
|
| 240 |
+
const Vectorized<c10::qint32>& b) {
|
| 241 |
+
return a.minimum(b);
|
| 242 |
+
}
|
| 243 |
+
} // namespace
|
| 244 |
+
} // namespace vec
|
| 245 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/vsx/vec256_quint8_vsx.h
ADDED
|
@@ -0,0 +1,407 @@
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 4 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 5 |
+
#include <ATen/cpu/vec/vec256/vsx/vsx_helpers.h>
|
| 6 |
+
|
| 7 |
+
#include <c10/util/irange.h>
|
| 8 |
+
#include <c10/util/quint8.h>
|
| 9 |
+
#include <array>
|
| 10 |
+
|
| 11 |
+
// This file defines Vectorized<> for the quantized types.
|
| 12 |
+
//
|
| 13 |
+
//
|
| 14 |
+
// Currently, we simply use these classes as efficient converters between
|
| 15 |
+
// the quantized types and Vectorized<float>, usually in bandwidth-bound cases
|
| 16 |
+
// where doing the arithmetic in full-precision is acceptable (e.g.
|
| 17 |
+
// elementwise operators).
|
| 18 |
+
//
|
| 19 |
+
//
|
| 20 |
+
// Conversions are as follows:
|
| 21 |
+
// Vectorized<quint8> -> 4x Vectorized<float>
|
| 22 |
+
//
|
| 23 |
+
// The size of the returned float vector is specified by the special
|
| 24 |
+
// constexpr function float_num_vecs. The type of the value returned
|
| 25 |
+
// from dequantize (and expected as an argument to quantize) is
|
| 26 |
+
// specified by float_vec_return_type.
|
| 27 |
+
//
|
| 28 |
+
// When writing kernels with these vectors, it is expected that floating-
|
| 29 |
+
// point operations will be carried out in a loop over Vectorized<T>::float_num_vecs
|
| 30 |
+
// iterations.
|
| 31 |
+
|
| 32 |
+
namespace at {
|
| 33 |
+
namespace vec {
|
| 34 |
+
inline namespace CPU_CAPABILITY {
|
| 35 |
+
|
| 36 |
+
const vint16 mask_unsigned = vec_splats((short int)0xFF);
|
| 37 |
+
template <>
|
| 38 |
+
struct Vectorized<c10::quint8> {
|
| 39 |
+
private:
|
| 40 |
+
union {
|
| 41 |
+
struct {
|
| 42 |
+
vuint8 _vec0;
|
| 43 |
+
vuint8 _vec1;
|
| 44 |
+
};
|
| 45 |
+
struct {
|
| 46 |
+
vbool8 _vecb0;
|
| 47 |
+
vbool8 _vecb1;
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
} __attribute__((__may_alias__));
|
| 51 |
+
|
| 52 |
+
public:
|
| 53 |
+
Vectorized() {}
|
| 54 |
+
using size_type = int;
|
| 55 |
+
static constexpr size_type size() {
|
| 56 |
+
return 32;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
static constexpr size_t float_num_vecs() {
|
| 60 |
+
return 4;
|
| 61 |
+
}
|
| 62 |
+
static constexpr int int_num_vecs() {
|
| 63 |
+
return 4;
|
| 64 |
+
}
|
| 65 |
+
using float_vec_return_type = std::array<Vectorized<float>, 4>;
|
| 66 |
+
using int_vec_return_type = std::array<Vectorized<c10::qint32>, 4>;
|
| 67 |
+
using value_type = typename c10::quint8::underlying;
|
| 68 |
+
using vec_internal_type = vuint8;
|
| 69 |
+
using vec_internal_mask_type = vbool8;
|
| 70 |
+
// Broadcast constructor
|
| 71 |
+
C10_ALWAYS_INLINE Vectorized(const c10::quint8& val)
|
| 72 |
+
: _vec0(vec_splats(val.val_)), _vec1(vec_splats(val.val_)) {}
|
| 73 |
+
|
| 74 |
+
C10_ALWAYS_INLINE Vectorized(const Vectorized<c10::quint8>& other)
|
| 75 |
+
: _vec0{other._vec0}, _vec1(other._vec1) {}
|
| 76 |
+
|
| 77 |
+
C10_ALWAYS_INLINE Vectorized(vuint8 v) : _vec0{v}, _vec1{v} {}
|
| 78 |
+
C10_ALWAYS_INLINE Vectorized(vbool8 vmask) : _vecb0{vmask}, _vecb1{vmask} {}
|
| 79 |
+
C10_ALWAYS_INLINE Vectorized(vuint8 v1, vuint8 v2) : _vec0{v1}, _vec1{v2} {}
|
| 80 |
+
C10_ALWAYS_INLINE Vectorized(vbool8 v1, vbool8 v2) : _vecb0{v1}, _vecb1{v2} {}
|
| 81 |
+
|
| 82 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec0() const {
|
| 83 |
+
return _vec0;
|
| 84 |
+
}
|
| 85 |
+
C10_ALWAYS_INLINE const vec_internal_type& vec1() const {
|
| 86 |
+
return _vec1;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
static C10_ALWAYS_INLINE Vectorized<c10::quint8> loadu(
|
| 90 |
+
const void* ptr,
|
| 91 |
+
int count = size()) {
|
| 92 |
+
if (count == size()) {
|
| 93 |
+
return {
|
| 94 |
+
vec_vsx_ld(offset0, reinterpret_cast<const value_type*>(ptr)),
|
| 95 |
+
vec_vsx_ld(offset16, reinterpret_cast<const value_type*>(ptr))};
|
| 96 |
+
}
|
| 97 |
+
__at_align__ value_type tmp_values[size()];
|
| 98 |
+
std::memcpy(tmp_values, ptr, std::min(count, size()) * sizeof(value_type));
|
| 99 |
+
return {vec_vsx_ld(offset0, tmp_values), vec_vsx_ld(offset16, tmp_values)};
|
| 100 |
+
}
|
| 101 |
+
void C10_ALWAYS_INLINE store(void* ptr, int count = size()) const {
|
| 102 |
+
if (count == size()) {
|
| 103 |
+
vec_vsx_st(_vec0, offset0, reinterpret_cast<value_type*>(ptr));
|
| 104 |
+
vec_vsx_st(_vec1, offset16, reinterpret_cast<value_type*>(ptr));
|
| 105 |
+
} else if (count > 0) {
|
| 106 |
+
__at_align__ value_type tmp_values[size()];
|
| 107 |
+
vec_vsx_st(_vec0, offset0, tmp_values);
|
| 108 |
+
vec_vsx_st(_vec1, offset16, tmp_values);
|
| 109 |
+
std::memcpy(
|
| 110 |
+
ptr, tmp_values, std::min(count, size()) * sizeof(value_type));
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
public:
|
| 115 |
+
float_vec_return_type C10_ALWAYS_INLINE dequantize(
|
| 116 |
+
Vectorized<float> scale,
|
| 117 |
+
Vectorized<float> zero_point,
|
| 118 |
+
Vectorized<float> scale_zp_premul) const {
|
| 119 |
+
// unpacking unsigned as signed
|
| 120 |
+
vint16 vecshi0 = vec_unpackh((vint8)_vec0);
|
| 121 |
+
vint16 vecshi1 = vec_unpackl((vint8)_vec0);
|
| 122 |
+
|
| 123 |
+
vint16 vecshi2 = vec_unpackh((vint8)_vec1);
|
| 124 |
+
vint16 vecshi3 = vec_unpackl((vint8)_vec1);
|
| 125 |
+
|
| 126 |
+
// signed -> unsigned
|
| 127 |
+
vecshi0 = vec_and(vecshi0, mask_unsigned);
|
| 128 |
+
vecshi1 = vec_and(vecshi1, mask_unsigned);
|
| 129 |
+
|
| 130 |
+
vecshi2 = vec_and(vecshi2, mask_unsigned);
|
| 131 |
+
vecshi3 = vec_and(vecshi3, mask_unsigned);
|
| 132 |
+
|
| 133 |
+
vint32 veci0 = vec_unpackh(vecshi0);
|
| 134 |
+
vint32 veci1 = vec_unpackl(vecshi0);
|
| 135 |
+
|
| 136 |
+
vint32 veci2 = vec_unpackh(vecshi1);
|
| 137 |
+
vint32 veci3 = vec_unpackl(vecshi1);
|
| 138 |
+
|
| 139 |
+
vint32 veci4 = vec_unpackh(vecshi2);
|
| 140 |
+
vint32 veci5 = vec_unpackl(vecshi2);
|
| 141 |
+
|
| 142 |
+
vint32 veci6 = vec_unpackh(vecshi3);
|
| 143 |
+
vint32 veci7 = vec_unpackl(vecshi3);
|
| 144 |
+
|
| 145 |
+
vfloat32 vecf0_0 = vec_float(veci0);
|
| 146 |
+
vfloat32 vecf1_0 = vec_float(veci1);
|
| 147 |
+
|
| 148 |
+
vfloat32 vecf0_1 = vec_float(veci2);
|
| 149 |
+
vfloat32 vecf1_1 = vec_float(veci3);
|
| 150 |
+
|
| 151 |
+
vfloat32 vecf0_2 = vec_float(veci4);
|
| 152 |
+
vfloat32 vecf1_2 = vec_float(veci5);
|
| 153 |
+
|
| 154 |
+
vfloat32 vecf0_3 = vec_float(veci6);
|
| 155 |
+
vfloat32 vecf1_3 = vec_float(veci7);
|
| 156 |
+
vfloat32 scale_vec0 = scale.vec0();
|
| 157 |
+
vfloat32 scale_vec1 = scale.vec1();
|
| 158 |
+
vfloat32 scale_zp_premul0 = scale_zp_premul.vec0();
|
| 159 |
+
vfloat32 scale_zp_premul1 = scale_zp_premul.vec1();
|
| 160 |
+
return {
|
| 161 |
+
Vectorized<float>{
|
| 162 |
+
vec_madd(scale_vec0, vecf0_0, scale_zp_premul0),
|
| 163 |
+
vec_madd(scale_vec1, vecf1_0, scale_zp_premul1)},
|
| 164 |
+
Vectorized<float>{
|
| 165 |
+
vec_madd(scale_vec0, vecf0_1, scale_zp_premul0),
|
| 166 |
+
vec_madd(scale_vec1, vecf1_1, scale_zp_premul1)},
|
| 167 |
+
Vectorized<float>{
|
| 168 |
+
vec_madd(scale_vec0, vecf0_2, scale_zp_premul0),
|
| 169 |
+
vec_madd(scale_vec1, vecf1_2, scale_zp_premul1)},
|
| 170 |
+
Vectorized<float>{
|
| 171 |
+
vec_madd(scale_vec0, vecf0_3, scale_zp_premul0),
|
| 172 |
+
vec_madd(scale_vec1, vecf1_3, scale_zp_premul1)}};
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
static Vectorized<c10::quint8> quantize(
|
| 176 |
+
const float_vec_return_type& rhs,
|
| 177 |
+
float scale,
|
| 178 |
+
int32_t zero_point,
|
| 179 |
+
float inverse_scale) {
|
| 180 |
+
// constexpr int32_t min_val = std::numeric_limits<value_type>::min();
|
| 181 |
+
// constexpr int32_t max_val = std::numeric_limits<value_type>::max();
|
| 182 |
+
|
| 183 |
+
vfloat32 vec_inverse = vec_splats(inverse_scale);
|
| 184 |
+
vfloat32 vec_zero_point = vec_splats((float)zero_point);
|
| 185 |
+
// vuint32 vmin = vec_splats(min_val);
|
| 186 |
+
// vuint32 vmax = vec_splats(max_val);
|
| 187 |
+
Vectorized<float> vf0 = rhs[0];
|
| 188 |
+
Vectorized<float> vf1 = rhs[1];
|
| 189 |
+
Vectorized<float> vf2 = rhs[2];
|
| 190 |
+
Vectorized<float> vf3 = rhs[3];
|
| 191 |
+
vfloat32 vecf0 = vf0.vec0();
|
| 192 |
+
vfloat32 vecf1 = vf0.vec1();
|
| 193 |
+
vfloat32 vecf2 = vf1.vec0();
|
| 194 |
+
vfloat32 vecf3 = vf1.vec1();
|
| 195 |
+
|
| 196 |
+
vfloat32 vecf4 = vf2.vec0();
|
| 197 |
+
vfloat32 vecf5 = vf2.vec1();
|
| 198 |
+
vfloat32 vecf6 = vf3.vec0();
|
| 199 |
+
vfloat32 vecf7 = vf3.vec1();
|
| 200 |
+
|
| 201 |
+
vecf0 = vec_mul(vecf0, vec_inverse);
|
| 202 |
+
vecf1 = vec_mul(vecf1, vec_inverse);
|
| 203 |
+
vecf2 = vec_mul(vecf2, vec_inverse);
|
| 204 |
+
vecf3 = vec_mul(vecf3, vec_inverse);
|
| 205 |
+
|
| 206 |
+
vecf4 = vec_mul(vecf4, vec_inverse);
|
| 207 |
+
vecf5 = vec_mul(vecf5, vec_inverse);
|
| 208 |
+
vecf6 = vec_mul(vecf6, vec_inverse);
|
| 209 |
+
vecf7 = vec_mul(vecf7, vec_inverse);
|
| 210 |
+
|
| 211 |
+
vecf0 = vec_add(vec_rint(vecf0), vec_zero_point);
|
| 212 |
+
vecf1 = vec_add(vec_rint(vecf1), vec_zero_point);
|
| 213 |
+
vecf2 = vec_add(vec_rint(vecf2), vec_zero_point);
|
| 214 |
+
vecf3 = vec_add(vec_rint(vecf3), vec_zero_point);
|
| 215 |
+
|
| 216 |
+
vecf4 = vec_add(vec_rint(vecf4), vec_zero_point);
|
| 217 |
+
vecf5 = vec_add(vec_rint(vecf5), vec_zero_point);
|
| 218 |
+
vecf6 = vec_add(vec_rint(vecf6), vec_zero_point);
|
| 219 |
+
vecf7 = vec_add(vec_rint(vecf7), vec_zero_point);
|
| 220 |
+
|
| 221 |
+
vint32 veci0 = vec_signed(vecf0);
|
| 222 |
+
vint32 veci1 = vec_signed(vecf1);
|
| 223 |
+
vint32 veci2 = vec_signed(vecf2);
|
| 224 |
+
vint32 veci3 = vec_signed(vecf3);
|
| 225 |
+
|
| 226 |
+
vint32 veci4 = vec_signed(vecf4);
|
| 227 |
+
vint32 veci5 = vec_signed(vecf5);
|
| 228 |
+
vint32 veci6 = vec_signed(vecf6);
|
| 229 |
+
vint32 veci7 = vec_signed(vecf7);
|
| 230 |
+
|
| 231 |
+
vint16 vecshi0 = vec_packs(veci0, veci1);
|
| 232 |
+
vint16 vecshi1 = vec_packs(veci2, veci3);
|
| 233 |
+
vint16 vecshi2 = vec_packs(veci4, veci5);
|
| 234 |
+
vint16 vecshi3 = vec_packs(veci6, veci7);
|
| 235 |
+
|
| 236 |
+
vuint8 vec0 = vec_packsu(vecshi0, vecshi1);
|
| 237 |
+
vuint8 vec1 = vec_packsu(vecshi2, vecshi3);
|
| 238 |
+
|
| 239 |
+
return {vec0, vec1};
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
Vectorized<c10::quint8> C10_ALWAYS_INLINE relu(Vectorized<c10::quint8> zero_point) const {
|
| 243 |
+
return {vec_max(_vec0, zero_point._vec0), vec_max(_vec1, zero_point._vec1)};
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
Vectorized<c10::quint8> C10_ALWAYS_INLINE
|
| 247 |
+
relu6(Vectorized<c10::quint8> zero_point, Vectorized<c10::quint8> q_six) const {
|
| 248 |
+
vuint8 max0 = vec_max(_vec0, zero_point._vec0);
|
| 249 |
+
vuint8 max1 = vec_max(_vec1, zero_point._vec1);
|
| 250 |
+
return {vec_min(max0, q_six._vec0), vec_min(max1, q_six._vec1)};
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
int_vec_return_type widening_subtract(Vectorized<c10::quint8> b) const {
|
| 254 |
+
vint16 vecshi0 = vec_unpackh((vint8)_vec0);
|
| 255 |
+
vint16 vecBshi0 = vec_unpackh((vint8)b._vec0);
|
| 256 |
+
vint16 vecshi1 = vec_unpackl((vint8)_vec0);
|
| 257 |
+
vint16 vecBshi1 = vec_unpackl((vint8)b._vec0);
|
| 258 |
+
|
| 259 |
+
vint16 vecshi2 = vec_unpackh((vint8)_vec1);
|
| 260 |
+
vint16 vecBshi2 = vec_unpackh((vint8)b._vec1);
|
| 261 |
+
vint16 vecshi3 = vec_unpackl((vint8)_vec1);
|
| 262 |
+
vint16 vecBshi3 = vec_unpackl((vint8)b._vec1);
|
| 263 |
+
|
| 264 |
+
vecshi0 = vec_and(vecshi0, mask_unsigned);
|
| 265 |
+
vecBshi0 = vec_and(vecBshi0, mask_unsigned);
|
| 266 |
+
vecshi1 = vec_and(vecshi1, mask_unsigned);
|
| 267 |
+
vecBshi1 = vec_and(vecBshi1, mask_unsigned);
|
| 268 |
+
|
| 269 |
+
vecshi2 = vec_and(vecshi2, mask_unsigned);
|
| 270 |
+
vecBshi2 = vec_and(vecBshi2, mask_unsigned);
|
| 271 |
+
vecshi3 = vec_and(vecshi3, mask_unsigned);
|
| 272 |
+
vecBshi3 = vec_and(vecBshi3, mask_unsigned);
|
| 273 |
+
|
| 274 |
+
vint32 veci0 = vec_unpackh(vecshi0);
|
| 275 |
+
vint32 vecBi0 = vec_unpackh(vecBshi0);
|
| 276 |
+
vint32 veci1 = vec_unpackl(vecshi0);
|
| 277 |
+
vint32 vecBi1 = vec_unpackl(vecBshi0);
|
| 278 |
+
|
| 279 |
+
vint32 veci2 = vec_unpackh(vecshi1);
|
| 280 |
+
vint32 vecBi2 = vec_unpackh(vecBshi1);
|
| 281 |
+
vint32 veci3 = vec_unpackl(vecshi1);
|
| 282 |
+
vint32 vecBi3 = vec_unpackl(vecBshi1);
|
| 283 |
+
|
| 284 |
+
vint32 veci4 = vec_unpackh(vecshi2);
|
| 285 |
+
vint32 vecBi4 = vec_unpackh(vecBshi2);
|
| 286 |
+
vint32 veci5 = vec_unpackl(vecshi2);
|
| 287 |
+
vint32 vecBi5 = vec_unpackl(vecBshi2);
|
| 288 |
+
|
| 289 |
+
vint32 veci6 = vec_unpackh(vecshi3);
|
| 290 |
+
vint32 vecBi6 = vec_unpackh(vecBshi3);
|
| 291 |
+
vint32 veci7 = vec_unpackl(vecshi3);
|
| 292 |
+
vint32 vecBi7 = vec_unpackl(vecBshi3);
|
| 293 |
+
|
| 294 |
+
return {
|
| 295 |
+
Vectorized<c10::qint32>(veci0 - vecBi0, veci1 - vecBi1),
|
| 296 |
+
Vectorized<c10::qint32>(veci2 - vecBi2, veci3 - vecBi3),
|
| 297 |
+
Vectorized<c10::qint32>(veci4 - vecBi4, veci5 - vecBi5),
|
| 298 |
+
Vectorized<c10::qint32>(veci6 - vecBi6, veci7 - vecBi7)};
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
static Vectorized<c10::quint8> requantize_from_int(
|
| 302 |
+
const int_vec_return_type& inp,
|
| 303 |
+
float multiplier,
|
| 304 |
+
int32_t zero_point) {
|
| 305 |
+
vfloat32 vec_multiplier = vec_splats(multiplier);
|
| 306 |
+
vint32 vec_zero_point = vec_splats(zero_point);
|
| 307 |
+
|
| 308 |
+
Vectorized<c10::qint32> vi0 = inp[0];
|
| 309 |
+
Vectorized<c10::qint32> vi1 = inp[1];
|
| 310 |
+
Vectorized<c10::qint32> vi2 = inp[2];
|
| 311 |
+
Vectorized<c10::qint32> vi3 = inp[3];
|
| 312 |
+
|
| 313 |
+
vfloat32 vecf0 = vec_float(vi0.vec0());
|
| 314 |
+
vfloat32 vecf1 = vec_float(vi0.vec1());
|
| 315 |
+
vfloat32 vecf2 = vec_float(vi1.vec0());
|
| 316 |
+
vfloat32 vecf3 = vec_float(vi1.vec1());
|
| 317 |
+
|
| 318 |
+
vfloat32 vecf4 = vec_float(vi2.vec0());
|
| 319 |
+
vfloat32 vecf5 = vec_float(vi2.vec1());
|
| 320 |
+
vfloat32 vecf6 = vec_float(vi3.vec0());
|
| 321 |
+
vfloat32 vecf7 = vec_float(vi3.vec1());
|
| 322 |
+
|
| 323 |
+
vecf0 = vec_mul(vecf0, vec_multiplier);
|
| 324 |
+
vecf1 = vec_mul(vecf1, vec_multiplier);
|
| 325 |
+
vecf2 = vec_mul(vecf2, vec_multiplier);
|
| 326 |
+
vecf3 = vec_mul(vecf3, vec_multiplier);
|
| 327 |
+
|
| 328 |
+
vecf4 = vec_mul(vecf4, vec_multiplier);
|
| 329 |
+
vecf5 = vec_mul(vecf5, vec_multiplier);
|
| 330 |
+
vecf6 = vec_mul(vecf6, vec_multiplier);
|
| 331 |
+
vecf7 = vec_mul(vecf7, vec_multiplier);
|
| 332 |
+
|
| 333 |
+
vecf0 = vec_rint(vecf0);
|
| 334 |
+
vecf1 = vec_rint(vecf1);
|
| 335 |
+
vecf2 = vec_rint(vecf2);
|
| 336 |
+
vecf3 = vec_rint(vecf3);
|
| 337 |
+
|
| 338 |
+
vecf4 = vec_rint(vecf4);
|
| 339 |
+
vecf5 = vec_rint(vecf5);
|
| 340 |
+
vecf6 = vec_rint(vecf6);
|
| 341 |
+
vecf7 = vec_rint(vecf7);
|
| 342 |
+
|
| 343 |
+
vint32 veci0 = vec_signed(vecf0);
|
| 344 |
+
vint32 veci1 = vec_signed(vecf1);
|
| 345 |
+
vint32 veci2 = vec_signed(vecf2);
|
| 346 |
+
vint32 veci3 = vec_signed(vecf3);
|
| 347 |
+
|
| 348 |
+
vint32 veci4 = vec_signed(vecf4);
|
| 349 |
+
vint32 veci5 = vec_signed(vecf5);
|
| 350 |
+
vint32 veci6 = vec_signed(vecf6);
|
| 351 |
+
vint32 veci7 = vec_signed(vecf7);
|
| 352 |
+
|
| 353 |
+
veci0 = vec_add(veci0, vec_zero_point);
|
| 354 |
+
veci1 = vec_add(veci1, vec_zero_point);
|
| 355 |
+
veci2 = vec_add(veci2, vec_zero_point);
|
| 356 |
+
veci3 = vec_add(veci3, vec_zero_point);
|
| 357 |
+
|
| 358 |
+
veci4 = vec_add(veci4, vec_zero_point);
|
| 359 |
+
veci5 = vec_add(veci5, vec_zero_point);
|
| 360 |
+
veci6 = vec_add(veci6, vec_zero_point);
|
| 361 |
+
veci7 = vec_add(veci7, vec_zero_point);
|
| 362 |
+
|
| 363 |
+
vint16 vecshi0 = vec_packs(veci0, veci1);
|
| 364 |
+
vint16 vecshi1 = vec_packs(veci2, veci3);
|
| 365 |
+
vint16 vecshi2 = vec_packs(veci4, veci5);
|
| 366 |
+
vint16 vecshi3 = vec_packs(veci6, veci7);
|
| 367 |
+
|
| 368 |
+
vuint8 vec0 = vec_packsu(vecshi0, vecshi1);
|
| 369 |
+
vuint8 vec1 = vec_packsu(vecshi2, vecshi3);
|
| 370 |
+
|
| 371 |
+
return {vec0, vec1};
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
DEFINE_MEMBER_OP(operator==, c10::quint8, vec_cmpeq)
|
| 375 |
+
DEFINE_MEMBER_OP(operator!=, c10::quint8, vec_cmpne)
|
| 376 |
+
DEFINE_MEMBER_OP(operator<, c10::quint8, vec_cmplt)
|
| 377 |
+
DEFINE_MEMBER_OP(operator<=, c10::quint8, vec_cmple)
|
| 378 |
+
DEFINE_MEMBER_OP(operator>, c10::quint8, vec_cmpgt)
|
| 379 |
+
DEFINE_MEMBER_OP(operator>=, c10::quint8, vec_cmpge)
|
| 380 |
+
DEFINE_MEMBER_OP(operator+, c10::quint8, vec_add)
|
| 381 |
+
DEFINE_MEMBER_OP(operator-, c10::quint8, vec_sub)
|
| 382 |
+
DEFINE_MEMBER_OP(operator*, c10::quint8, vec_mul)
|
| 383 |
+
DEFINE_MEMBER_EMULATE_BINARY_OP(operator/, c10::quint8, /)
|
| 384 |
+
DEFINE_MEMBER_OP(maximum, c10::quint8, vec_max)
|
| 385 |
+
DEFINE_MEMBER_OP(minimum, c10::quint8, vec_min)
|
| 386 |
+
DEFINE_MEMBER_OP(operator&, c10::quint8, vec_and)
|
| 387 |
+
DEFINE_MEMBER_OP(operator|, c10::quint8, vec_or)
|
| 388 |
+
DEFINE_MEMBER_OP(operator^, c10::quint8, vec_xor)
|
| 389 |
+
};
|
| 390 |
+
|
| 391 |
+
template <>
|
| 392 |
+
Vectorized<c10::quint8> inline maximum(
|
| 393 |
+
const Vectorized<c10::quint8>& a,
|
| 394 |
+
const Vectorized<c10::quint8>& b) {
|
| 395 |
+
return a.maximum(b);
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
template <>
|
| 399 |
+
Vectorized<c10::quint8> inline minimum(
|
| 400 |
+
const Vectorized<c10::quint8>& a,
|
| 401 |
+
const Vectorized<c10::quint8>& b) {
|
| 402 |
+
return a.minimum(b);
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
} // namespace
|
| 406 |
+
} // namespace vec
|
| 407 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec256/zarch/vec256_zarch.h
ADDED
|
@@ -0,0 +1,2797 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 1 |
+
#include <cmath>
|
| 2 |
+
#include <cstring>
|
| 3 |
+
#include <limits>
|
| 4 |
+
#include <type_traits>
|
| 5 |
+
#include <utility>
|
| 6 |
+
#if defined(__clang__)
|
| 7 |
+
#include <sleef.h>
|
| 8 |
+
#elif defined(__GNUC__) || defined(__GNUG__)
|
| 9 |
+
#include <sleef.h>
|
| 10 |
+
#include <vecintrin.h>
|
| 11 |
+
#endif
|
| 12 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 13 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 14 |
+
#include <c10/util/complex.h>
|
| 15 |
+
|
| 16 |
+
#define SLEEF_MEMORY_WORKAROUND
|
| 17 |
+
|
| 18 |
+
namespace at {
|
| 19 |
+
namespace vec {
|
| 20 |
+
|
| 21 |
+
// See Note [CPU_CAPABILITY namespace]
|
| 22 |
+
inline namespace CPU_CAPABILITY {
|
| 23 |
+
|
| 24 |
+
template <typename T>
|
| 25 |
+
constexpr bool is_zarch_implemented() {
|
| 26 |
+
return (
|
| 27 |
+
std::is_same<T, float>::value || std::is_same<T, double>::value ||
|
| 28 |
+
std::is_same<T, int8_t>::value || std::is_same<T, uint8_t>::value ||
|
| 29 |
+
std::is_same<T, uint16_t>::value || std::is_same<T, int16_t>::value ||
|
| 30 |
+
std::is_same<T, int32_t>::value || std::is_same<T, int64_t>::value);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
template <typename T>
|
| 34 |
+
constexpr bool is_zarch_implemented_quant() {
|
| 35 |
+
return (
|
| 36 |
+
std::is_same<T, c10::qint32>::value ||
|
| 37 |
+
std::is_same<T, c10::qint8>::value ||
|
| 38 |
+
std::is_same<T, c10::quint8>::value);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
template <typename T>
|
| 42 |
+
constexpr bool is_zarch_implemented_complex() {
|
| 43 |
+
return std::is_same<T, c10::complex<float>>::value ||
|
| 44 |
+
std::is_same<T, c10::complex<double>>::value;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
constexpr int offset0 = 0;
|
| 48 |
+
constexpr int offset16 = 16;
|
| 49 |
+
|
| 50 |
+
template <int N>
|
| 51 |
+
struct VecBinaryType {
|
| 52 |
+
using type __attribute__((vector_size(16))) = uintmax_t;
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
template <>
|
| 56 |
+
struct VecBinaryType<8> {
|
| 57 |
+
using type = __attribute__((vector_size(16))) unsigned long long;
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
template <>
|
| 61 |
+
struct VecBinaryType<4> {
|
| 62 |
+
using type = __attribute__((vector_size(16))) unsigned int;
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
template <>
|
| 66 |
+
struct VecBinaryType<2> {
|
| 67 |
+
using type = __attribute__((vector_size(16))) unsigned short;
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
template <>
|
| 71 |
+
struct VecBinaryType<1> {
|
| 72 |
+
using type = __attribute__((vector_size(16))) unsigned char;
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
template <typename T>
|
| 76 |
+
struct VecInnerType {
|
| 77 |
+
using Type __attribute__((vector_size(16))) = T;
|
| 78 |
+
using BinaryType = typename VecBinaryType<sizeof(T)>::type;
|
| 79 |
+
using ElementType = T;
|
| 80 |
+
static constexpr int size = 16 / sizeof(T);
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
// define for int64_t properly for load
|
| 84 |
+
template <>
|
| 85 |
+
struct VecInnerType<int64_t> {
|
| 86 |
+
using Type = __attribute__((vector_size(16))) signed long long;
|
| 87 |
+
using ElementType = signed long long;
|
| 88 |
+
using BinaryType = typename VecBinaryType<sizeof(signed long long)>::type;
|
| 89 |
+
static constexpr int size = 16 / sizeof(signed long long);
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
template <typename T>
|
| 93 |
+
using ZSimdVect = typename VecInnerType<T>::Type;
|
| 94 |
+
template <typename T>
|
| 95 |
+
using ZSimdVectBinary = typename VecInnerType<T>::BinaryType;
|
| 96 |
+
template <typename T>
|
| 97 |
+
using ZSimdVectElement = typename VecInnerType<T>::ElementType;
|
| 98 |
+
|
| 99 |
+
constexpr int blendChoiceInner(
|
| 100 |
+
const uint64_t mask,
|
| 101 |
+
const uint64_t half1 = 0xF,
|
| 102 |
+
const uint64_t half2 = 0xF0) {
|
| 103 |
+
uint64_t none = 0;
|
| 104 |
+
uint64_t both = half1 | half2;
|
| 105 |
+
// clamp it between 0 and both
|
| 106 |
+
auto res_mask = mask & both;
|
| 107 |
+
// return (a._vec0, a._vec1)
|
| 108 |
+
if (res_mask == none)
|
| 109 |
+
return 0;
|
| 110 |
+
// return (b._vec0,b._vec1)
|
| 111 |
+
else if (res_mask == both)
|
| 112 |
+
return 1;
|
| 113 |
+
// return (b._vec0, a._vec1)
|
| 114 |
+
else if (res_mask == half1)
|
| 115 |
+
return 2;
|
| 116 |
+
// return (a._vec0,b._vec1)
|
| 117 |
+
else if (res_mask == half2)
|
| 118 |
+
return 3;
|
| 119 |
+
// return (*_vec0,a._vec1)
|
| 120 |
+
else if (res_mask > 0 && res_mask < half1)
|
| 121 |
+
return 4;
|
| 122 |
+
// return (*_vec0,b._vec1)
|
| 123 |
+
else if ((res_mask & half2) == half2)
|
| 124 |
+
return 5;
|
| 125 |
+
// return (a._vec0,*_vec1)
|
| 126 |
+
else if ((res_mask & half1) == 0 && res_mask > half1)
|
| 127 |
+
return 6;
|
| 128 |
+
// return (b._vec0,*_vec1)
|
| 129 |
+
else if ((res_mask & half1) == half1 && res_mask > half1)
|
| 130 |
+
return 7;
|
| 131 |
+
// return (*_vec0,*_vec1)
|
| 132 |
+
return 8;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// it can be used to emulate blend faster
|
| 136 |
+
template <int Z>
|
| 137 |
+
constexpr int blendChoice(const uint64_t mask) {
|
| 138 |
+
static_assert(Z < 1 || Z > 8, "not implemented");
|
| 139 |
+
return blendChoiceInner(mask);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
template <>
|
| 143 |
+
constexpr int blendChoice<1>(const uint64_t mask) {
|
| 144 |
+
return blendChoiceInner(mask, 0x0000FFFF, 0xFFFF0000);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
template <>
|
| 148 |
+
constexpr int blendChoice<2>(const uint64_t mask) {
|
| 149 |
+
return blendChoiceInner(mask, 0x00FF, 0xFF00);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
template <>
|
| 153 |
+
constexpr int blendChoice<4>(const uint64_t mask) {
|
| 154 |
+
return blendChoiceInner(mask, 0xF, 0xF0);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
template <>
|
| 158 |
+
constexpr int blendChoice<8>(const uint64_t mask) {
|
| 159 |
+
// clamp it 0 and 0xF
|
| 160 |
+
return blendChoiceInner(mask, 0x3, 0xC);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
template <int N>
|
| 164 |
+
constexpr auto GetMask1(const uint64_t mask) {
|
| 165 |
+
return typename VecBinaryType<N>::type{};
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
template <int N>
|
| 169 |
+
constexpr auto GetMask2(const uint64_t mask) {
|
| 170 |
+
return typename VecBinaryType<N>::type{};
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
template <>
|
| 174 |
+
constexpr auto GetMask1<1>(const uint64_t mask) {
|
| 175 |
+
constexpr uint8_t t = (int)0xFF;
|
| 176 |
+
uint8_t g0 = (mask & 1) * t;
|
| 177 |
+
uint8_t g1 = ((mask & 2) >> 1) * t;
|
| 178 |
+
uint8_t g2 = ((mask & 4) >> 2) * t;
|
| 179 |
+
uint8_t g3 = ((mask & 8) >> 3) * t;
|
| 180 |
+
uint8_t g4 = ((mask & 16) >> 4) * t;
|
| 181 |
+
uint8_t g5 = ((mask & 32) >> 5) * t;
|
| 182 |
+
uint8_t g6 = ((mask & 64) >> 6) * t;
|
| 183 |
+
uint8_t g7 = ((mask & 128) >> 7) * t;
|
| 184 |
+
uint8_t g8 = ((mask & 256) >> 8) * t;
|
| 185 |
+
uint8_t g9 = ((mask & 512) >> 9) * t;
|
| 186 |
+
uint8_t g10 = ((mask & 1024) >> 10) * t;
|
| 187 |
+
uint8_t g11 = ((mask & 2048) >> 11) * t;
|
| 188 |
+
uint8_t g12 = ((mask & 4096) >> 12) * t;
|
| 189 |
+
uint8_t g13 = ((mask & 8192) >> 13) * t;
|
| 190 |
+
uint8_t g14 = ((mask & 16384) >> 14) * t;
|
| 191 |
+
uint8_t g15 = ((mask & 32768) >> 15) * t;
|
| 192 |
+
return (typename VecBinaryType<1>::type){
|
| 193 |
+
g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11, g12, g13, g14, g15};
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
template <>
|
| 197 |
+
constexpr auto GetMask2<1>(const uint64_t mask) {
|
| 198 |
+
uint64_t mask2 = (mask & 0xFFFFFFFF) >> 16;
|
| 199 |
+
return GetMask1<1>(mask2);
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
template <>
|
| 203 |
+
constexpr auto GetMask1<2>(const uint64_t mask) {
|
| 204 |
+
constexpr uint16_t t = (int)0xFFFF;
|
| 205 |
+
uint16_t g0 = (mask & 1) * t;
|
| 206 |
+
uint16_t g1 = ((mask & 2) >> 1) * t;
|
| 207 |
+
uint16_t g2 = ((mask & 4) >> 2) * t;
|
| 208 |
+
uint16_t g3 = ((mask & 8) >> 3) * t;
|
| 209 |
+
uint16_t g4 = ((mask & 16) >> 4) * t;
|
| 210 |
+
uint16_t g5 = ((mask & 32) >> 5) * t;
|
| 211 |
+
uint16_t g6 = ((mask & 64) >> 6) * t;
|
| 212 |
+
uint16_t g7 = ((mask & 128) >> 7) * t;
|
| 213 |
+
return (typename VecBinaryType<2>::type){g0, g1, g2, g3, g4, g5, g6, g7};
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
template <>
|
| 217 |
+
constexpr auto GetMask2<2>(const uint64_t mask) {
|
| 218 |
+
uint64_t mask2 = (mask & 0xFFFF) >> 8;
|
| 219 |
+
return GetMask1<2>(mask2);
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
template <>
|
| 223 |
+
constexpr auto GetMask1<4>(const uint64_t mask) {
|
| 224 |
+
uint32_t g0 = (mask & 1) * 0xffffffff;
|
| 225 |
+
uint32_t g1 = ((mask & 2) >> 1) * 0xffffffff;
|
| 226 |
+
uint32_t g2 = ((mask & 4) >> 2) * 0xffffffff;
|
| 227 |
+
uint32_t g3 = ((mask & 8) >> 3) * 0xffffffff;
|
| 228 |
+
return (typename VecBinaryType<4>::type){g0, g1, g2, g3};
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
template <>
|
| 232 |
+
constexpr auto GetMask2<4>(const uint64_t mask) {
|
| 233 |
+
uint64_t mask2 = (mask & 0xFF) >> 4;
|
| 234 |
+
return GetMask1<4>(mask2);
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
template <>
|
| 238 |
+
constexpr auto GetMask1<8>(const uint64_t mask) {
|
| 239 |
+
uint64_t g0 = (mask & 1) * 0xffffffffffffffff;
|
| 240 |
+
uint64_t g1 = ((mask & 2) >> 1) * 0xffffffffffffffff;
|
| 241 |
+
return (typename VecBinaryType<8>::type){g0, g1};
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
template <>
|
| 245 |
+
constexpr auto GetMask2<8>(const uint64_t mask) {
|
| 246 |
+
uint64_t mask2 = (mask & 0xF) >> 2;
|
| 247 |
+
return GetMask1<8>(mask2);
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
template <int Z>
|
| 251 |
+
constexpr int maskForComplex(uint32_t mask) {
|
| 252 |
+
return 0;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
template <>
|
| 256 |
+
constexpr int maskForComplex<8>(uint32_t mask) {
|
| 257 |
+
mask = mask & 0xF;
|
| 258 |
+
int complex_mask = 0;
|
| 259 |
+
if (mask & 1)
|
| 260 |
+
complex_mask |= 3;
|
| 261 |
+
if (mask & 2)
|
| 262 |
+
complex_mask |= (3 << 2);
|
| 263 |
+
if (mask & 4)
|
| 264 |
+
complex_mask |= (3 << 4);
|
| 265 |
+
if (mask & 8)
|
| 266 |
+
complex_mask |= (3 << 6);
|
| 267 |
+
return complex_mask;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
template <>
|
| 271 |
+
constexpr int maskForComplex<16>(uint32_t mask) {
|
| 272 |
+
mask = mask & 0x3;
|
| 273 |
+
int complex_mask = 0;
|
| 274 |
+
if (mask & 1)
|
| 275 |
+
complex_mask |= 3;
|
| 276 |
+
if (mask & 2)
|
| 277 |
+
complex_mask |= (3 << 2);
|
| 278 |
+
return complex_mask;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
template <typename T = c10::complex<float>>
|
| 282 |
+
constexpr int blend_choice() {
|
| 283 |
+
return 0xAA;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
template <>
|
| 287 |
+
constexpr int blend_choice<c10::complex<double>>() {
|
| 288 |
+
return 0x0A;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
constexpr int64_t allbitset(int16_t x) {
|
| 292 |
+
int64_t onex = 1;
|
| 293 |
+
return (onex << x) - onex;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
namespace { /* unnamed namespace */
|
| 297 |
+
|
| 298 |
+
ZSimdVect<float> vec_mergee(ZSimdVect<float> x, ZSimdVect<float> y) {
|
| 299 |
+
constexpr ZSimdVectBinary<uint8_t> mergee_mask{
|
| 300 |
+
0, 1, 2, 3, 16, 17, 18, 19, 8, 9, 10, 11, 24, 25, 26, 27};
|
| 301 |
+
return vec_perm(x, y, mergee_mask);
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
ZSimdVect<double> vec_mergee(ZSimdVect<double> x, ZSimdVect<double> y) {
|
| 305 |
+
return vec_mergeh(x, y);
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
ZSimdVect<float> vec_mergeo(ZSimdVect<float> x, ZSimdVect<float> y) {
|
| 309 |
+
constexpr ZSimdVectBinary<uint8_t> mergeo_mask{
|
| 310 |
+
4, 5, 6, 7, 20, 21, 22, 23, 12, 13, 14, 15, 28, 29, 30, 31};
|
| 311 |
+
return vec_perm(x, y, mergeo_mask);
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
ZSimdVect<double> vec_mergeo(ZSimdVect<double> x, ZSimdVect<double> y) {
|
| 315 |
+
return vec_mergel(x, y);
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
} /* unnamed namespace */
|
| 319 |
+
|
| 320 |
+
//
|
| 321 |
+
template <typename T>
|
| 322 |
+
constexpr auto GetBpermZeroMask() {
|
| 323 |
+
return ZSimdVectBinary<uint8_t>{
|
| 324 |
+
128,
|
| 325 |
+
128,
|
| 326 |
+
128,
|
| 327 |
+
128,
|
| 328 |
+
128,
|
| 329 |
+
128,
|
| 330 |
+
128,
|
| 331 |
+
128,
|
| 332 |
+
128,
|
| 333 |
+
128,
|
| 334 |
+
128,
|
| 335 |
+
128,
|
| 336 |
+
96,
|
| 337 |
+
64,
|
| 338 |
+
32,
|
| 339 |
+
0};
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
template <>
|
| 343 |
+
constexpr auto GetBpermZeroMask<double>() {
|
| 344 |
+
return ZSimdVectBinary<uint8_t>{
|
| 345 |
+
128,
|
| 346 |
+
128,
|
| 347 |
+
128,
|
| 348 |
+
128,
|
| 349 |
+
128,
|
| 350 |
+
128,
|
| 351 |
+
128,
|
| 352 |
+
128,
|
| 353 |
+
128,
|
| 354 |
+
128,
|
| 355 |
+
128,
|
| 356 |
+
128,
|
| 357 |
+
128,
|
| 358 |
+
128,
|
| 359 |
+
64,
|
| 360 |
+
0};
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
constexpr auto GetSwapMaskFloat() {
|
| 364 |
+
return ZSimdVectBinary<uint8_t>{
|
| 365 |
+
4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11};
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
template <typename T>
|
| 369 |
+
struct Vectorized<T, std::enable_if_t<is_zarch_implemented<T>()>> {
|
| 370 |
+
public:
|
| 371 |
+
using value_type = T;
|
| 372 |
+
using vtype = ZSimdVect<T>;
|
| 373 |
+
using vmaskType = ZSimdVectBinary<T>;
|
| 374 |
+
using size_type = int;
|
| 375 |
+
// because of gcc inconsistency for int64_t we are obliged to use this, not
|
| 376 |
+
// value_type
|
| 377 |
+
using ElementType = ZSimdVectElement<T>;
|
| 378 |
+
using vinner_data = std::pair<vtype, vtype>;
|
| 379 |
+
|
| 380 |
+
private:
|
| 381 |
+
vtype _vec0;
|
| 382 |
+
vtype _vec1;
|
| 383 |
+
|
| 384 |
+
public:
|
| 385 |
+
static constexpr size_type size() {
|
| 386 |
+
return VECTOR_WIDTH / sizeof(ElementType);
|
| 387 |
+
}
|
| 388 |
+
Vectorized() {}
|
| 389 |
+
|
| 390 |
+
C10_ALWAYS_INLINE Vectorized(vtype v) : _vec0{v}, _vec1{v} {}
|
| 391 |
+
C10_ALWAYS_INLINE Vectorized(const vinner_data &v) : _vec0{v.first}, _vec1{v.second} {}
|
| 392 |
+
C10_ALWAYS_INLINE Vectorized(vtype v1, vtype v2) : _vec0{v1}, _vec1{v2} {}
|
| 393 |
+
C10_ALWAYS_INLINE Vectorized(T s)
|
| 394 |
+
: _vec0{vec_splats((ElementType)s)}, _vec1{vec_splats((ElementType)s)} {}
|
| 395 |
+
|
| 396 |
+
static Vectorized<value_type> C10_ALWAYS_INLINE
|
| 397 |
+
loadu(const void* ptr, int count = size()) {
|
| 398 |
+
if (count == size()) {
|
| 399 |
+
return {
|
| 400 |
+
vec_xl(offset0, reinterpret_cast<const ElementType*>(ptr)),
|
| 401 |
+
vec_xl(offset16, reinterpret_cast<const ElementType*>(ptr))};
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
__at_align__ ElementType tmp_values[size()] = {};
|
| 405 |
+
std::memcpy(tmp_values, ptr, std::min(count, size()) * sizeof(ElementType));
|
| 406 |
+
|
| 407 |
+
return {
|
| 408 |
+
vec_xl(offset0, reinterpret_cast<const ElementType*>(tmp_values)),
|
| 409 |
+
vec_xl(offset16, reinterpret_cast<const ElementType*>(tmp_values))};
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
static Vectorized<value_type> C10_ALWAYS_INLINE
|
| 413 |
+
loadu_one_fourth(const void* ptr) {
|
| 414 |
+
// load only first 8 bytes
|
| 415 |
+
// only intended to be used with uint8_t
|
| 416 |
+
return loadu(ptr, 8 / sizeof(ElementType));
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
void C10_ALWAYS_INLINE store(void* ptr, int count = size()) const {
|
| 420 |
+
if (count == size()) {
|
| 421 |
+
vec_xst(_vec0, offset0, reinterpret_cast<ElementType*>(ptr));
|
| 422 |
+
vec_xst(_vec1, offset16, reinterpret_cast<ElementType*>(ptr));
|
| 423 |
+
} else if (count > 0) {
|
| 424 |
+
__at_align__ ElementType tmp_values[size()];
|
| 425 |
+
vec_xst(_vec0, offset0, reinterpret_cast<ElementType*>(tmp_values));
|
| 426 |
+
vec_xst(_vec1, offset16, reinterpret_cast<ElementType*>(tmp_values));
|
| 427 |
+
std::memcpy(
|
| 428 |
+
ptr, tmp_values, std::min(count, size()) * sizeof(ElementType));
|
| 429 |
+
}
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
C10_ALWAYS_INLINE const vtype& vec0() const {
|
| 433 |
+
return _vec0;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
C10_ALWAYS_INLINE const vtype& vec1() const {
|
| 437 |
+
return _vec1;
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
C10_ALWAYS_INLINE vinner_data data() const {
|
| 441 |
+
return std::make_pair<>(_vec0, _vec1);
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
C10_ALWAYS_INLINE operator vinner_data() const {
|
| 445 |
+
return data();
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
C10_ALWAYS_INLINE const vmaskType vecb0() const {
|
| 449 |
+
return (vmaskType)_vec0;
|
| 450 |
+
}
|
| 451 |
+
C10_ALWAYS_INLINE const vmaskType vecb1() const {
|
| 452 |
+
return (vmaskType)_vec1;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
static Vectorized<T> C10_ALWAYS_INLINE blendv(
|
| 456 |
+
const Vectorized<T>& a,
|
| 457 |
+
const Vectorized<T>& b,
|
| 458 |
+
const Vectorized<T>& mask) {
|
| 459 |
+
return {
|
| 460 |
+
vec_sel(a._vec0, b._vec0, mask.vecb0()),
|
| 461 |
+
vec_sel(a._vec1, b._vec1, mask.vecb1())};
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
template <typename U = T, std::enable_if_t<(sizeof(U) == 8), int> = 0>
|
| 465 |
+
C10_ALWAYS_INLINE Vectorized(T s1, T s2, T s3, T s4)
|
| 466 |
+
: _vec0{s1, s2}, _vec1{s3, s4} {}
|
| 467 |
+
|
| 468 |
+
template <typename U = T, std::enable_if_t<(sizeof(U) == 4), int> = 0>
|
| 469 |
+
C10_ALWAYS_INLINE Vectorized(T s1, T s2, T s3, T s4, T s5, T s6, T s7, T s8)
|
| 470 |
+
: _vec0{s1, s2, s3, s4}, _vec1{s5, s6, s7, s8} {}
|
| 471 |
+
|
| 472 |
+
template <typename U = T, std::enable_if_t<(sizeof(U) == 2), int> = 0>
|
| 473 |
+
C10_ALWAYS_INLINE Vectorized(
|
| 474 |
+
T s1,
|
| 475 |
+
T s2,
|
| 476 |
+
T s3,
|
| 477 |
+
T s4,
|
| 478 |
+
T s5,
|
| 479 |
+
T s6,
|
| 480 |
+
T s7,
|
| 481 |
+
T s8,
|
| 482 |
+
T s9,
|
| 483 |
+
T s10,
|
| 484 |
+
T s11,
|
| 485 |
+
T s12,
|
| 486 |
+
T s13,
|
| 487 |
+
T s14,
|
| 488 |
+
T s15,
|
| 489 |
+
T s16)
|
| 490 |
+
: _vec0{s1, s2, s3, s4, s5, s6, s7, s8},
|
| 491 |
+
_vec1{s9, s10, s11, s12, s13, s14, s15, s16} {}
|
| 492 |
+
|
| 493 |
+
template <typename U = T, std::enable_if_t<(sizeof(U) == 1), int> = 0>
|
| 494 |
+
C10_ALWAYS_INLINE Vectorized(
|
| 495 |
+
T s1,
|
| 496 |
+
T s2,
|
| 497 |
+
T s3,
|
| 498 |
+
T s4,
|
| 499 |
+
T s5,
|
| 500 |
+
T s6,
|
| 501 |
+
T s7,
|
| 502 |
+
T s8,
|
| 503 |
+
T s9,
|
| 504 |
+
T s10,
|
| 505 |
+
T s11,
|
| 506 |
+
T s12,
|
| 507 |
+
T s13,
|
| 508 |
+
T s14,
|
| 509 |
+
T s15,
|
| 510 |
+
T s16,
|
| 511 |
+
T s17,
|
| 512 |
+
T s18,
|
| 513 |
+
T s19,
|
| 514 |
+
T s20,
|
| 515 |
+
T s21,
|
| 516 |
+
T s22,
|
| 517 |
+
T s23,
|
| 518 |
+
T s24,
|
| 519 |
+
T s25,
|
| 520 |
+
T s26,
|
| 521 |
+
T s27,
|
| 522 |
+
T s28,
|
| 523 |
+
T s29,
|
| 524 |
+
T s30,
|
| 525 |
+
T s31,
|
| 526 |
+
T s32)
|
| 527 |
+
: _vec0{s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16},
|
| 528 |
+
_vec1{
|
| 529 |
+
s17,
|
| 530 |
+
s18,
|
| 531 |
+
s19,
|
| 532 |
+
s20,
|
| 533 |
+
s21,
|
| 534 |
+
s22,
|
| 535 |
+
s23,
|
| 536 |
+
s24,
|
| 537 |
+
s25,
|
| 538 |
+
s26,
|
| 539 |
+
s27,
|
| 540 |
+
s28,
|
| 541 |
+
s29,
|
| 542 |
+
s30,
|
| 543 |
+
s31,
|
| 544 |
+
s32} {}
|
| 545 |
+
|
| 546 |
+
template <typename step_t, typename U = T>
|
| 547 |
+
static std::enable_if_t<sizeof(U) == 8, Vectorized<T>> arange(
|
| 548 |
+
T base = 0,
|
| 549 |
+
step_t step = static_cast<step_t>(1)) {
|
| 550 |
+
return Vectorized<T>(base, base + step, base + 2 * step, base + 3 * step);
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
template <typename step_t, typename U = T>
|
| 554 |
+
static std::enable_if_t<sizeof(U) == 4, Vectorized<T>> arange(
|
| 555 |
+
T base = 0,
|
| 556 |
+
step_t step = static_cast<step_t>(1)) {
|
| 557 |
+
return Vectorized<T>(
|
| 558 |
+
base,
|
| 559 |
+
base + step,
|
| 560 |
+
base + 2 * step,
|
| 561 |
+
base + 3 * step,
|
| 562 |
+
base + 4 * step,
|
| 563 |
+
base + 5 * step,
|
| 564 |
+
base + 6 * step,
|
| 565 |
+
base + 7 * step);
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
template <typename step_t, typename U = T>
|
| 569 |
+
static std::enable_if_t<sizeof(U) == 2, Vectorized<T>> arange(
|
| 570 |
+
T base = 0,
|
| 571 |
+
step_t step = static_cast<step_t>(1)) {
|
| 572 |
+
return Vectorized<T>(
|
| 573 |
+
base,
|
| 574 |
+
base + step,
|
| 575 |
+
base + 2 * step,
|
| 576 |
+
base + 3 * step,
|
| 577 |
+
base + 4 * step,
|
| 578 |
+
base + 5 * step,
|
| 579 |
+
base + 6 * step,
|
| 580 |
+
base + 7 * step,
|
| 581 |
+
base + 8 * step,
|
| 582 |
+
base + 9 * step,
|
| 583 |
+
base + 10 * step,
|
| 584 |
+
base + 11 * step,
|
| 585 |
+
base + 12 * step,
|
| 586 |
+
base + 13 * step,
|
| 587 |
+
base + 14 * step,
|
| 588 |
+
base + 15 * step);
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
template <typename step_t, typename U = T>
|
| 592 |
+
static std::enable_if_t<sizeof(U) == 1, Vectorized<T>> arange(
|
| 593 |
+
T base = 0,
|
| 594 |
+
step_t step = static_cast<step_t>(1)) {
|
| 595 |
+
return Vectorized<T>(
|
| 596 |
+
base,
|
| 597 |
+
base + step,
|
| 598 |
+
base + 2 * step,
|
| 599 |
+
base + 3 * step,
|
| 600 |
+
base + 4 * step,
|
| 601 |
+
base + 5 * step,
|
| 602 |
+
base + 6 * step,
|
| 603 |
+
base + 7 * step,
|
| 604 |
+
base + 8 * step,
|
| 605 |
+
base + 9 * step,
|
| 606 |
+
base + 10 * step,
|
| 607 |
+
base + 11 * step,
|
| 608 |
+
base + 12 * step,
|
| 609 |
+
base + 13 * step,
|
| 610 |
+
base + 14 * step,
|
| 611 |
+
base + 15 * step,
|
| 612 |
+
base + 16 * step,
|
| 613 |
+
base + 17 * step,
|
| 614 |
+
base + 18 * step,
|
| 615 |
+
base + 19 * step,
|
| 616 |
+
base + 20 * step,
|
| 617 |
+
base + 21 * step,
|
| 618 |
+
base + 22 * step,
|
| 619 |
+
base + 23 * step,
|
| 620 |
+
base + 24 * step,
|
| 621 |
+
base + 25 * step,
|
| 622 |
+
base + 26 * step,
|
| 623 |
+
base + 27 * step,
|
| 624 |
+
base + 28 * step,
|
| 625 |
+
base + 29 * step,
|
| 626 |
+
base + 30 * step,
|
| 627 |
+
base + 31 * step);
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
// blend section
|
| 631 |
+
template <int64_t mask>
|
| 632 |
+
static std::enable_if_t<blendChoice<sizeof(T)>(mask) == 0, Vectorized<T>>
|
| 633 |
+
C10_ALWAYS_INLINE blend(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 634 |
+
return a;
|
| 635 |
+
}
|
| 636 |
+
|
| 637 |
+
template <int64_t mask>
|
| 638 |
+
static std::enable_if_t<blendChoice<sizeof(T)>(mask) == 1, Vectorized<T>>
|
| 639 |
+
C10_ALWAYS_INLINE blend(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 640 |
+
return b;
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
template <int64_t mask>
|
| 644 |
+
static std::enable_if_t<blendChoice<sizeof(T)>(mask) == 2, Vectorized<T>>
|
| 645 |
+
C10_ALWAYS_INLINE blend(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 646 |
+
return {b._vec0, a._vec1};
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
template <int64_t mask>
|
| 650 |
+
static std::enable_if_t<blendChoice<sizeof(T)>(mask) == 3, Vectorized<T>>
|
| 651 |
+
C10_ALWAYS_INLINE blend(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 652 |
+
return {a._vec0, b._vec1};
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
template <int64_t mask>
|
| 656 |
+
static std::enable_if_t<blendChoice<sizeof(T)>(mask) == 4, Vectorized<T>>
|
| 657 |
+
C10_ALWAYS_INLINE blend(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 658 |
+
const vmaskType mask_1st = GetMask1<sizeof(T)>(mask);
|
| 659 |
+
return {(vtype)vec_sel(a._vec0, b._vec0, mask_1st), a._vec1};
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
template <int64_t mask>
|
| 663 |
+
static std::enable_if_t<blendChoice<sizeof(T)>(mask) == 5, Vectorized<T>>
|
| 664 |
+
C10_ALWAYS_INLINE blend(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 665 |
+
const vmaskType mask_1st = GetMask1<sizeof(T)>(mask);
|
| 666 |
+
return {(vtype)vec_sel(a._vec0, b._vec0, mask_1st), b._vec1};
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
template <int64_t mask>
|
| 670 |
+
static std::enable_if_t<blendChoice<sizeof(T)>(mask) == 6, Vectorized<T>>
|
| 671 |
+
C10_ALWAYS_INLINE blend(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 672 |
+
const vmaskType mask_2nd = GetMask2<sizeof(T)>(mask);
|
| 673 |
+
// generated masks
|
| 674 |
+
return {a._vec0, (vtype)vec_sel(a._vec1, b._vec1, mask_2nd)};
|
| 675 |
+
}
|
| 676 |
+
|
| 677 |
+
template <int64_t mask>
|
| 678 |
+
static std::enable_if_t<blendChoice<sizeof(T)>(mask) == 7, Vectorized<T>>
|
| 679 |
+
C10_ALWAYS_INLINE blend(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 680 |
+
const vmaskType mask_2nd = GetMask2<sizeof(T)>(mask);
|
| 681 |
+
// generated masks
|
| 682 |
+
return {b._vec0, (vtype)vec_sel(a._vec1, b._vec1, mask_2nd)};
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
template <int64_t mask>
|
| 686 |
+
static std::enable_if_t<blendChoice<sizeof(T)>(mask) == 8, Vectorized<T>>
|
| 687 |
+
C10_ALWAYS_INLINE blend(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 688 |
+
const vmaskType mask_1st = GetMask1<sizeof(T)>(mask);
|
| 689 |
+
const vmaskType mask_2nd = GetMask2<sizeof(T)>(mask);
|
| 690 |
+
return {
|
| 691 |
+
(vtype)vec_sel(a._vec0, b._vec0, mask_1st),
|
| 692 |
+
(vtype)vec_sel(a._vec1, b._vec1, mask_2nd)};
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
template <int16_t Z, int16_t C>
|
| 696 |
+
static inline std::enable_if_t<(Z >= C), Vectorized<T>> set_inner(
|
| 697 |
+
const Vectorized<T>& a,
|
| 698 |
+
const Vectorized<T>& b,
|
| 699 |
+
size_t count) {
|
| 700 |
+
return b;
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
template <int16_t Z, int16_t C>
|
| 704 |
+
static inline std::enable_if_t<(Z < C), Vectorized<T>> set_inner(
|
| 705 |
+
const Vectorized<T>& a,
|
| 706 |
+
const Vectorized<T>& b,
|
| 707 |
+
size_t count) {
|
| 708 |
+
if (count == Z)
|
| 709 |
+
return blend<allbitset(Z)>(a, b);
|
| 710 |
+
else
|
| 711 |
+
return set_inner<Z + 1, C>(a, b, count);
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
static Vectorized<T> set(
|
| 715 |
+
const Vectorized<T>& a,
|
| 716 |
+
const Vectorized<T>& b,
|
| 717 |
+
size_t count = size()) {
|
| 718 |
+
if (count == 0)
|
| 719 |
+
return a;
|
| 720 |
+
return set_inner<1, size()>(a, b, count);
|
| 721 |
+
}
|
| 722 |
+
|
| 723 |
+
const ElementType& operator[](int idx) const = delete;
|
| 724 |
+
ElementType& operator[](int idx) = delete;
|
| 725 |
+
|
| 726 |
+
Vectorized<T> C10_ALWAYS_INLINE operator+(const Vectorized<T>& other) const {
|
| 727 |
+
return Vectorized<T>{_vec0 + other._vec0, _vec1 + other._vec1};
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
Vectorized<T> C10_ALWAYS_INLINE operator-(const Vectorized<T>& other) const {
|
| 731 |
+
return Vectorized<T>{_vec0 - other._vec0, _vec1 - other._vec1};
|
| 732 |
+
}
|
| 733 |
+
|
| 734 |
+
Vectorized<T> C10_ALWAYS_INLINE operator*(const Vectorized<T>& other) const {
|
| 735 |
+
return Vectorized<T>{_vec0 * other._vec0, _vec1 * other._vec1};
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
Vectorized<T> C10_ALWAYS_INLINE operator/(const Vectorized<T>& other) const {
|
| 739 |
+
return Vectorized<T>{_vec0 / other._vec0, _vec1 / other._vec1};
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
Vectorized<T> C10_ALWAYS_INLINE operator&(const Vectorized<T>& other) const {
|
| 743 |
+
return Vectorized<T>{
|
| 744 |
+
(vtype)(vecb0() & other.vecb0()), (vtype)(vecb1() & other.vecb1())};
|
| 745 |
+
}
|
| 746 |
+
|
| 747 |
+
Vectorized<T> C10_ALWAYS_INLINE operator|(const Vectorized<T>& other) const {
|
| 748 |
+
return Vectorized<T>{
|
| 749 |
+
(vtype)(vecb0() | other.vecb0()), (vtype)(vecb1() | other.vecb1())};
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
Vectorized<T> C10_ALWAYS_INLINE operator^(const Vectorized<T>& other) const {
|
| 753 |
+
return Vectorized<T>{
|
| 754 |
+
(vtype)(vecb0() ^ other.vecb0()), (vtype)(vecb1() ^ other.vecb1())};
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
Vectorized<T> C10_ALWAYS_INLINE operator<<(const Vectorized<T> &other) const {
|
| 758 |
+
constexpr ElementType max_shift = sizeof(ElementType) * CHAR_BIT;
|
| 759 |
+
|
| 760 |
+
ElementType a_array[Vectorized<T>::size()];
|
| 761 |
+
ElementType b_array[Vectorized<T>::size()];
|
| 762 |
+
ElementType c_array[Vectorized<T>::size()];
|
| 763 |
+
|
| 764 |
+
store(a_array);
|
| 765 |
+
other.store(b_array);
|
| 766 |
+
|
| 767 |
+
for (int i = 0; i != Vectorized<T>::size(); i++) {
|
| 768 |
+
T shift = b_array[i];
|
| 769 |
+
if ((static_cast<std::make_signed_t<T>>(shift) < 0) || (shift >= max_shift)) {
|
| 770 |
+
c_array[i] = 0;
|
| 771 |
+
} else {
|
| 772 |
+
c_array[i] = static_cast<std::make_unsigned_t<T>>(a_array[i]) << shift;
|
| 773 |
+
}
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
return loadu(c_array);
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
Vectorized<T> C10_ALWAYS_INLINE operator>>(const Vectorized<T> &other) const {
|
| 780 |
+
// right shift value to retain sign bit for signed and no bits for unsigned
|
| 781 |
+
constexpr ElementType max_shift = sizeof(T) * CHAR_BIT - std::is_signed_v<T>;
|
| 782 |
+
|
| 783 |
+
ElementType a_array[Vectorized<T>::size()];
|
| 784 |
+
ElementType b_array[Vectorized<T>::size()];
|
| 785 |
+
ElementType c_array[Vectorized<T>::size()];
|
| 786 |
+
|
| 787 |
+
store(a_array);
|
| 788 |
+
other.store(b_array);
|
| 789 |
+
|
| 790 |
+
for (int i = 0; i != Vectorized<T>::size(); i++) {
|
| 791 |
+
T shift = b_array[i];
|
| 792 |
+
if ((static_cast<std::make_signed_t<T>>(shift) < 0) || (shift >= max_shift)) {
|
| 793 |
+
c_array[i] = a_array[i] >> max_shift;
|
| 794 |
+
} else {
|
| 795 |
+
c_array[i] = a_array[i] >> shift;
|
| 796 |
+
}
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
return loadu(c_array);
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
Vectorized<T> _not() const {
|
| 803 |
+
return {(vtype)vec_nor(vecb0(), vecb0()), (vtype)vec_nor(vecb1(), vecb1())};
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
Vectorized<T> C10_ALWAYS_INLINE operator==(const Vectorized<T>& other) const {
|
| 807 |
+
return Vectorized<T>{
|
| 808 |
+
vec_cmpeq(_vec0, other._vec0), vec_cmpeq(_vec1, other._vec1)};
|
| 809 |
+
}
|
| 810 |
+
|
| 811 |
+
Vectorized<T> C10_ALWAYS_INLINE operator!=(const Vectorized<T>& other) const {
|
| 812 |
+
return Vectorized<T>{
|
| 813 |
+
vec_cmpeq(_vec0, other._vec0), vec_cmpeq(_vec1, other._vec1)}
|
| 814 |
+
._not();
|
| 815 |
+
}
|
| 816 |
+
Vectorized<T> C10_ALWAYS_INLINE operator>(const Vectorized<T>& other) const {
|
| 817 |
+
return Vectorized<T>{
|
| 818 |
+
vec_cmpgt(_vec0, other._vec0), vec_cmpgt(_vec1, other._vec1)};
|
| 819 |
+
}
|
| 820 |
+
Vectorized<T> C10_ALWAYS_INLINE operator>=(const Vectorized<T>& other) const {
|
| 821 |
+
return Vectorized<T>{
|
| 822 |
+
vec_cmpge(_vec0, other._vec0), vec_cmpge(_vec1, other._vec1)};
|
| 823 |
+
}
|
| 824 |
+
|
| 825 |
+
Vectorized<T> C10_ALWAYS_INLINE operator<(const Vectorized<T>& other) const {
|
| 826 |
+
return Vectorized<T>{
|
| 827 |
+
vec_cmplt(_vec0, other._vec0), vec_cmplt(_vec1, other._vec1)};
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
Vectorized<T> C10_ALWAYS_INLINE operator<=(const Vectorized<T>& other) const {
|
| 831 |
+
return Vectorized<T>{
|
| 832 |
+
vec_cmple(_vec0, other._vec0), vec_cmple(_vec1, other._vec1)};
|
| 833 |
+
}
|
| 834 |
+
|
| 835 |
+
Vectorized<T> C10_ALWAYS_INLINE eq(const Vectorized<T>& other) const {
|
| 836 |
+
return (*this == other) & Vectorized<T>((T)1.0);
|
| 837 |
+
}
|
| 838 |
+
Vectorized<T> C10_ALWAYS_INLINE ne(const Vectorized<T>& other) const {
|
| 839 |
+
return (*this != other) & Vectorized<T>((T)1.0);
|
| 840 |
+
}
|
| 841 |
+
Vectorized<T> C10_ALWAYS_INLINE gt(const Vectorized<T>& other) const {
|
| 842 |
+
return (*this > other) & Vectorized<T>((T)1.0);
|
| 843 |
+
}
|
| 844 |
+
Vectorized<T> C10_ALWAYS_INLINE ge(const Vectorized<T>& other) const {
|
| 845 |
+
return (*this >= other) & Vectorized<T>((T)1.0);
|
| 846 |
+
}
|
| 847 |
+
Vectorized<T> C10_ALWAYS_INLINE lt(const Vectorized<T>& other) const {
|
| 848 |
+
return (*this < other) & Vectorized<T>((T)1.0);
|
| 849 |
+
}
|
| 850 |
+
Vectorized<T> C10_ALWAYS_INLINE le(const Vectorized<T>& other) const {
|
| 851 |
+
return (*this <= other) & Vectorized<T>((T)1.0);
|
| 852 |
+
}
|
| 853 |
+
|
| 854 |
+
template <
|
| 855 |
+
typename U = T,
|
| 856 |
+
std::enable_if_t<!std::is_unsigned<U>::value, int> = 0>
|
| 857 |
+
Vectorized<U> C10_ALWAYS_INLINE abs() const {
|
| 858 |
+
return {vec_abs(_vec0), vec_abs(_vec1)};
|
| 859 |
+
}
|
| 860 |
+
|
| 861 |
+
template <
|
| 862 |
+
typename U = T,
|
| 863 |
+
std::enable_if_t<std::is_unsigned<U>::value, int> = 0>
|
| 864 |
+
Vectorized<U> C10_ALWAYS_INLINE abs() const {
|
| 865 |
+
return {_vec0, _vec1};
|
| 866 |
+
}
|
| 867 |
+
|
| 868 |
+
Vectorized<T> C10_ALWAYS_INLINE neg() const {
|
| 869 |
+
return {-_vec0, -_vec1};
|
| 870 |
+
}
|
| 871 |
+
|
| 872 |
+
Vectorized<T> isnan() const {
|
| 873 |
+
auto x = *this;
|
| 874 |
+
auto ret = (x == x);
|
| 875 |
+
return ret._not();
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
template <
|
| 879 |
+
typename U = T,
|
| 880 |
+
std::enable_if_t<std::is_floating_point<U>::value, int> = 0>
|
| 881 |
+
Vectorized<U> angle() const {
|
| 882 |
+
auto tmp = blendv(
|
| 883 |
+
Vectorized<U>(0), Vectorized<U>(c10::pi<U>), *this < Vectorized<U>(0));
|
| 884 |
+
return blendv(tmp, *this, isnan());
|
| 885 |
+
}
|
| 886 |
+
|
| 887 |
+
template <
|
| 888 |
+
typename U = T,
|
| 889 |
+
std::enable_if_t<!std::is_floating_point<U>::value, int> = 0>
|
| 890 |
+
Vectorized<U> angle() const {
|
| 891 |
+
return blendv(
|
| 892 |
+
Vectorized<U>(0), Vectorized<U>(c10::pi<U>), *this < Vectorized<U>(0));
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
Vectorized<T> real() const {
|
| 896 |
+
return *this;
|
| 897 |
+
}
|
| 898 |
+
Vectorized<T> imag() const {
|
| 899 |
+
return Vectorized<T>{0};
|
| 900 |
+
}
|
| 901 |
+
Vectorized<T> conj() const {
|
| 902 |
+
return *this;
|
| 903 |
+
}
|
| 904 |
+
|
| 905 |
+
template <
|
| 906 |
+
typename U = T,
|
| 907 |
+
std::enable_if_t<std::is_floating_point<U>::value, int> = 0>
|
| 908 |
+
int zero_mask() const {
|
| 909 |
+
auto cmp = (*this == Vectorized<U>(0));
|
| 910 |
+
constexpr auto mask_zero_bits = GetBpermZeroMask<U>();
|
| 911 |
+
ZSimdVectBinary<uint64_t> result0 =
|
| 912 |
+
vec_bperm_u128((ZSimdVectBinary<uint8_t>)cmp.vecb0(), mask_zero_bits);
|
| 913 |
+
ZSimdVectBinary<uint64_t> result1 =
|
| 914 |
+
vec_bperm_u128((ZSimdVectBinary<uint8_t>)cmp.vecb1(), mask_zero_bits);
|
| 915 |
+
return (result0[0] | (result1[0] << (size() / 2)));
|
| 916 |
+
}
|
| 917 |
+
|
| 918 |
+
Vectorized<T> C10_ALWAYS_INLINE floor() const {
|
| 919 |
+
return {vec_floor(_vec0), vec_floor(_vec1)};
|
| 920 |
+
}
|
| 921 |
+
|
| 922 |
+
Vectorized<T> C10_ALWAYS_INLINE ceil() const {
|
| 923 |
+
return {vec_ceil(_vec0), vec_ceil(_vec1)};
|
| 924 |
+
}
|
| 925 |
+
|
| 926 |
+
Vectorized<T> C10_ALWAYS_INLINE round() const {
|
| 927 |
+
return {vec_round(_vec0), vec_round(_vec1)};
|
| 928 |
+
}
|
| 929 |
+
|
| 930 |
+
Vectorized<T> C10_ALWAYS_INLINE rint() const {
|
| 931 |
+
return {vec_rint(_vec0), vec_rint(_vec1)};
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
Vectorized<T> C10_ALWAYS_INLINE trunc() const {
|
| 935 |
+
return {vec_trunc(_vec0), vec_trunc(_vec1)};
|
| 936 |
+
}
|
| 937 |
+
|
| 938 |
+
Vectorized<T> C10_ALWAYS_INLINE frac() const {
|
| 939 |
+
return *this - trunc();
|
| 940 |
+
}
|
| 941 |
+
|
| 942 |
+
Vectorized<T> C10_ALWAYS_INLINE sqrt() const {
|
| 943 |
+
return {vec_sqrt(_vec0), vec_sqrt(_vec1)};
|
| 944 |
+
}
|
| 945 |
+
Vectorized<T> C10_ALWAYS_INLINE reciprocal() const {
|
| 946 |
+
return Vectorized<T>((T)1) / (*this);
|
| 947 |
+
}
|
| 948 |
+
Vectorized<T> C10_ALWAYS_INLINE rsqrt() const {
|
| 949 |
+
return sqrt().reciprocal();
|
| 950 |
+
}
|
| 951 |
+
|
| 952 |
+
template <
|
| 953 |
+
typename U = T,
|
| 954 |
+
std::enable_if_t<std::is_same<U, float>::value, int> = 0>
|
| 955 |
+
inline Vectorized<T> mapOrdinary(float (*const f)(float)) const {
|
| 956 |
+
float a00 = f(_vec0[0]);
|
| 957 |
+
float a01 = f(_vec0[1]);
|
| 958 |
+
float a02 = f(_vec0[2]);
|
| 959 |
+
float a03 = f(_vec0[3]);
|
| 960 |
+
float a10 = f(_vec1[0]);
|
| 961 |
+
float a11 = f(_vec1[1]);
|
| 962 |
+
float a12 = f(_vec1[2]);
|
| 963 |
+
float a13 = f(_vec1[3]);
|
| 964 |
+
return Vectorized<T>{a00, a01, a02, a03, a10, a11, a12, a13};
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
template <
|
| 968 |
+
typename U = T,
|
| 969 |
+
std::enable_if_t<std::is_same<U, double>::value, int> = 0>
|
| 970 |
+
inline Vectorized<T> mapOrdinary(double (*const f)(double)) const {
|
| 971 |
+
return Vectorized<T>(f(_vec0[0]), f(_vec0[1]), f(_vec1[0]), f(_vec1[1]));
|
| 972 |
+
}
|
| 973 |
+
|
| 974 |
+
template <
|
| 975 |
+
typename U = T,
|
| 976 |
+
std::enable_if_t<std::is_same<U, float>::value, int> = 0>
|
| 977 |
+
inline Vectorized<T> mapOrdinary(
|
| 978 |
+
float (*const f)(float, float),
|
| 979 |
+
const Vectorized<T>& b) const {
|
| 980 |
+
float a00 = f(_vec0[0], b._vec0[0]);
|
| 981 |
+
float a01 = f(_vec0[1], b._vec0[1]);
|
| 982 |
+
float a02 = f(_vec0[2], b._vec0[2]);
|
| 983 |
+
float a03 = f(_vec0[3], b._vec0[3]);
|
| 984 |
+
float a10 = f(_vec1[0], b._vec1[0]);
|
| 985 |
+
float a11 = f(_vec1[1], b._vec1[1]);
|
| 986 |
+
float a12 = f(_vec1[2], b._vec1[2]);
|
| 987 |
+
float a13 = f(_vec1[3], b._vec1[3]);
|
| 988 |
+
return Vectorized<T>{a00, a01, a02, a03, a10, a11, a12, a13};
|
| 989 |
+
}
|
| 990 |
+
|
| 991 |
+
template <
|
| 992 |
+
typename U = T,
|
| 993 |
+
std::enable_if_t<std::is_same<U, double>::value, int> = 0>
|
| 994 |
+
inline Vectorized<T> mapOrdinary(
|
| 995 |
+
double (*const f)(double, double),
|
| 996 |
+
const Vectorized<T>& b) const {
|
| 997 |
+
return Vectorized<T>(
|
| 998 |
+
f(_vec0[0], b._vec0[0]),
|
| 999 |
+
f(_vec0[1], b._vec0[1]),
|
| 1000 |
+
f(_vec1[0], b._vec1[0]),
|
| 1001 |
+
f(_vec1[1], b._vec1[1]));
|
| 1002 |
+
}
|
| 1003 |
+
|
| 1004 |
+
template <
|
| 1005 |
+
typename FloatOp,
|
| 1006 |
+
typename DoubleOp,
|
| 1007 |
+
typename U = T,
|
| 1008 |
+
std::enable_if_t<std::is_same<U, float>::value, int> = 0>
|
| 1009 |
+
inline Vectorized<T> mapSleef(FloatOp f, DoubleOp d) const {
|
| 1010 |
+
vtype a0 = f(_vec0);
|
| 1011 |
+
vtype a1 = f(_vec1);
|
| 1012 |
+
return Vectorized<T>{a0, a1};
|
| 1013 |
+
}
|
| 1014 |
+
|
| 1015 |
+
template <
|
| 1016 |
+
typename FloatOp,
|
| 1017 |
+
typename DoubleOp,
|
| 1018 |
+
typename U = T,
|
| 1019 |
+
std::enable_if_t<std::is_same<U, double>::value, int> = 0>
|
| 1020 |
+
inline Vectorized<T> mapSleef(FloatOp f, DoubleOp d) const {
|
| 1021 |
+
return Vectorized<T>(d(_vec0), d(_vec1));
|
| 1022 |
+
}
|
| 1023 |
+
|
| 1024 |
+
template <
|
| 1025 |
+
typename FloatOp,
|
| 1026 |
+
typename DoubleOp,
|
| 1027 |
+
typename U = T,
|
| 1028 |
+
std::enable_if_t<std::is_same<U, float>::value, int> = 0>
|
| 1029 |
+
inline Vectorized<T> mapSleef(FloatOp f, DoubleOp d, const Vectorized<T>& b)
|
| 1030 |
+
const {
|
| 1031 |
+
vtype a0 = f(_vec0, b._vec0);
|
| 1032 |
+
vtype a1 = f(_vec1, b._vec1);
|
| 1033 |
+
return Vectorized<T>{a0, a1};
|
| 1034 |
+
}
|
| 1035 |
+
|
| 1036 |
+
template <
|
| 1037 |
+
typename FloatOp,
|
| 1038 |
+
typename DoubleOp,
|
| 1039 |
+
typename U = T,
|
| 1040 |
+
std::enable_if_t<std::is_same<U, double>::value, int> = 0>
|
| 1041 |
+
inline Vectorized<T> mapSleef(FloatOp f, DoubleOp d, const Vectorized<T>& b)
|
| 1042 |
+
const {
|
| 1043 |
+
return Vectorized<T>(d(_vec0, b._vec0), d(_vec1, b._vec1));
|
| 1044 |
+
}
|
| 1045 |
+
|
| 1046 |
+
Vectorized<T> acos() const {
|
| 1047 |
+
return mapSleef(Sleef_acosf4_u10, Sleef_acosd2_u10);
|
| 1048 |
+
}
|
| 1049 |
+
Vectorized<T> asin() const {
|
| 1050 |
+
return mapSleef(Sleef_asinf4_u10, Sleef_asind2_u10);
|
| 1051 |
+
}
|
| 1052 |
+
Vectorized<T> atan() const {
|
| 1053 |
+
return mapSleef(Sleef_atanf4_u10, Sleef_atand2_u10);
|
| 1054 |
+
}
|
| 1055 |
+
Vectorized<T> atanh() const {
|
| 1056 |
+
return mapSleef(Sleef_atanhf4_u10, Sleef_atanhd2_u10);
|
| 1057 |
+
}
|
| 1058 |
+
|
| 1059 |
+
Vectorized<T> erf() const {
|
| 1060 |
+
return mapSleef(Sleef_erff4_u10, Sleef_erfd2_u10);
|
| 1061 |
+
}
|
| 1062 |
+
Vectorized<T> erfc() const {
|
| 1063 |
+
return mapSleef(Sleef_erfcf4_u15, Sleef_erfcd2_u15);
|
| 1064 |
+
}
|
| 1065 |
+
|
| 1066 |
+
Vectorized<T> exp() const {
|
| 1067 |
+
return mapSleef(Sleef_expf4_u10, Sleef_expd2_u10);
|
| 1068 |
+
}
|
| 1069 |
+
Vectorized<T> exp2() const {
|
| 1070 |
+
return mapSleef(Sleef_exp2f4_u10, Sleef_exp2d2_u10);
|
| 1071 |
+
}
|
| 1072 |
+
Vectorized<T> expm1() const {
|
| 1073 |
+
return mapSleef(Sleef_expm1f4_u10, Sleef_expm1d2_u10);
|
| 1074 |
+
}
|
| 1075 |
+
|
| 1076 |
+
Vectorized<T> log() const {
|
| 1077 |
+
return mapSleef(Sleef_logf4_u10, Sleef_logd2_u10);
|
| 1078 |
+
}
|
| 1079 |
+
Vectorized<T> log2() const {
|
| 1080 |
+
return mapSleef(Sleef_log2f4_u10, Sleef_log2d2_u10);
|
| 1081 |
+
}
|
| 1082 |
+
Vectorized<T> log10() const {
|
| 1083 |
+
return mapSleef(Sleef_log10f4_u10, Sleef_log10d2_u10);
|
| 1084 |
+
}
|
| 1085 |
+
Vectorized<T> log1p() const {
|
| 1086 |
+
return mapSleef(Sleef_log1pf4_u10, Sleef_log1pd2_u10);
|
| 1087 |
+
}
|
| 1088 |
+
|
| 1089 |
+
Vectorized<T> sin() const {
|
| 1090 |
+
#ifndef SLEEF_MEMORY_WORKAROUND
|
| 1091 |
+
return mapSleef(Sleef_sinf4_u10, Sleef_sind2_u10);
|
| 1092 |
+
#else
|
| 1093 |
+
return mapOrdinary(std::sin);
|
| 1094 |
+
#endif
|
| 1095 |
+
}
|
| 1096 |
+
Vectorized<T> sinh() const {
|
| 1097 |
+
return mapSleef(Sleef_sinhf4_u10, Sleef_sinhd2_u10);
|
| 1098 |
+
}
|
| 1099 |
+
Vectorized<T> cos() const {
|
| 1100 |
+
#ifndef SLEEF_MEMORY_WORKAROUND
|
| 1101 |
+
return mapSleef(Sleef_cosf4_u10, Sleef_cosd2_u10);
|
| 1102 |
+
#else
|
| 1103 |
+
return mapOrdinary(std::cos);
|
| 1104 |
+
#endif
|
| 1105 |
+
}
|
| 1106 |
+
Vectorized<T> cosh() const {
|
| 1107 |
+
return mapSleef(Sleef_coshf4_u10, Sleef_coshd2_u10);
|
| 1108 |
+
}
|
| 1109 |
+
|
| 1110 |
+
Vectorized<T> tan() const {
|
| 1111 |
+
#ifndef SLEEF_MEMORY_WORKAROUND
|
| 1112 |
+
return mapSleef(Sleef_tanf4_u10, Sleef_tand2_u10);
|
| 1113 |
+
#else
|
| 1114 |
+
return mapOrdinary(std::tan);
|
| 1115 |
+
#endif
|
| 1116 |
+
}
|
| 1117 |
+
Vectorized<T> tanh() const {
|
| 1118 |
+
return mapSleef(Sleef_tanhf4_u10, Sleef_tanhd2_u10);
|
| 1119 |
+
}
|
| 1120 |
+
|
| 1121 |
+
Vectorized<T> lgamma() const {
|
| 1122 |
+
return mapSleef(Sleef_lgammaf4_u10, Sleef_lgammad2_u10);
|
| 1123 |
+
}
|
| 1124 |
+
|
| 1125 |
+
Vectorized<T> atan2(const Vectorized<T>& b) const {
|
| 1126 |
+
return mapSleef(Sleef_atan2f4_u10, Sleef_atan2d2_u10, b);
|
| 1127 |
+
}
|
| 1128 |
+
Vectorized<T> copysign(const Vectorized<T>& sign) const {
|
| 1129 |
+
return mapSleef(Sleef_copysignf4, Sleef_copysignd2, sign);
|
| 1130 |
+
}
|
| 1131 |
+
Vectorized<T> fmod(const Vectorized<T>& q) const {
|
| 1132 |
+
return mapSleef(Sleef_fmodf4, Sleef_fmodd2, q);
|
| 1133 |
+
}
|
| 1134 |
+
|
| 1135 |
+
Vectorized<T> hypot(const Vectorized<T>& b) const {
|
| 1136 |
+
return mapSleef(Sleef_hypotf4_u05, Sleef_hypotd2_u05, b);
|
| 1137 |
+
}
|
| 1138 |
+
|
| 1139 |
+
Vectorized<T> pow(const Vectorized<T>& b) const {
|
| 1140 |
+
return mapSleef(Sleef_powf4_u10, Sleef_powd2_u10, b);
|
| 1141 |
+
}
|
| 1142 |
+
|
| 1143 |
+
Vectorized<T> nextafter(const Vectorized<T>& b) const {
|
| 1144 |
+
return mapSleef(Sleef_nextafterf4, Sleef_nextafterd2, b);
|
| 1145 |
+
}
|
| 1146 |
+
|
| 1147 |
+
Vectorized<T> erfinv() const {
|
| 1148 |
+
return mapOrdinary(calc_erfinv);
|
| 1149 |
+
}
|
| 1150 |
+
|
| 1151 |
+
Vectorized<T> digamma() const {
|
| 1152 |
+
return mapOrdinary(calc_digamma);
|
| 1153 |
+
}
|
| 1154 |
+
|
| 1155 |
+
Vectorized<T> igamma(const Vectorized<T>& x) const {
|
| 1156 |
+
return mapOrdinary(calc_igamma, x);
|
| 1157 |
+
}
|
| 1158 |
+
|
| 1159 |
+
Vectorized<T> igammac(const Vectorized<T>& x) const {
|
| 1160 |
+
return mapOrdinary(calc_igammac, x);
|
| 1161 |
+
}
|
| 1162 |
+
|
| 1163 |
+
Vectorized<T> i0() const {
|
| 1164 |
+
return mapOrdinary(calc_i0);
|
| 1165 |
+
}
|
| 1166 |
+
|
| 1167 |
+
Vectorized<T> i0e() const {
|
| 1168 |
+
return mapOrdinary(calc_i0e);
|
| 1169 |
+
}
|
| 1170 |
+
|
| 1171 |
+
template <
|
| 1172 |
+
typename U = T,
|
| 1173 |
+
std::enable_if_t<!std::is_floating_point<U>::value, int> = 0>
|
| 1174 |
+
Vectorized<T> minimum(const Vectorized<T>& other) const {
|
| 1175 |
+
return {vec_min(_vec0, other._vec0), vec_min(_vec1, other._vec1)};
|
| 1176 |
+
}
|
| 1177 |
+
|
| 1178 |
+
/* Propagates NaN if either input is a NaN. */
|
| 1179 |
+
template <
|
| 1180 |
+
typename U = T,
|
| 1181 |
+
std::enable_if_t<std::is_floating_point<U>::value, int> = 0>
|
| 1182 |
+
Vectorized<T> minimum(const Vectorized<T>& other) const {
|
| 1183 |
+
Vectorized<T> tmp = {vec_min(_vec0, other._vec0), vec_min(_vec1, other._vec1)};
|
| 1184 |
+
tmp = blendv(tmp, *this, isnan());
|
| 1185 |
+
return blendv(tmp, other, other.isnan());
|
| 1186 |
+
}
|
| 1187 |
+
|
| 1188 |
+
template <
|
| 1189 |
+
typename U = T,
|
| 1190 |
+
std::enable_if_t<!std::is_floating_point<U>::value, int> = 0>
|
| 1191 |
+
Vectorized<T> maximum(const Vectorized<T>& other) const {
|
| 1192 |
+
return {vec_max(_vec0, other._vec0), vec_max(_vec1, other._vec1)};
|
| 1193 |
+
}
|
| 1194 |
+
|
| 1195 |
+
/* Propagates NaN if either input is a NaN. */
|
| 1196 |
+
template <
|
| 1197 |
+
typename U = T,
|
| 1198 |
+
std::enable_if_t<std::is_floating_point<U>::value, int> = 0>
|
| 1199 |
+
Vectorized<T> maximum(const Vectorized<T>& other) const {
|
| 1200 |
+
Vectorized<T> tmp = {vec_max(_vec0, other._vec0), vec_max(_vec1, other._vec1)};
|
| 1201 |
+
tmp = blendv(tmp, *this, isnan());
|
| 1202 |
+
return blendv(tmp, other, other.isnan());
|
| 1203 |
+
}
|
| 1204 |
+
|
| 1205 |
+
template <
|
| 1206 |
+
typename U = T,
|
| 1207 |
+
std::enable_if_t<!std::is_floating_point<U>::value, int> = 0>
|
| 1208 |
+
Vectorized<T> clamp_min(const Vectorized<T>& min) const {
|
| 1209 |
+
return {vec_max(_vec0, min._vec0), vec_max(_vec1, min._vec1)};
|
| 1210 |
+
}
|
| 1211 |
+
|
| 1212 |
+
/* Keeps NaN if actual value is NaN */
|
| 1213 |
+
template <
|
| 1214 |
+
typename U = T,
|
| 1215 |
+
std::enable_if_t<std::is_floating_point<U>::value, int> = 0>
|
| 1216 |
+
Vectorized<T> clamp_min(const Vectorized<T>& min) const {
|
| 1217 |
+
Vectorized<T> tmp = {vec_max(_vec0, min._vec0), vec_max(_vec1, min._vec1)};
|
| 1218 |
+
return blendv(tmp, *this, isnan());
|
| 1219 |
+
}
|
| 1220 |
+
|
| 1221 |
+
template <
|
| 1222 |
+
typename U = T,
|
| 1223 |
+
std::enable_if_t<!std::is_floating_point<U>::value, int> = 0>
|
| 1224 |
+
Vectorized<T> clamp_max(const Vectorized<T>& max) const {
|
| 1225 |
+
return {vec_min(_vec0, max._vec0), vec_min(_vec1, max._vec1)};
|
| 1226 |
+
}
|
| 1227 |
+
|
| 1228 |
+
/* Keeps NaN if actual value is NaN */
|
| 1229 |
+
template <
|
| 1230 |
+
typename U = T,
|
| 1231 |
+
std::enable_if_t<std::is_floating_point<U>::value, int> = 0>
|
| 1232 |
+
Vectorized<T> clamp_max(const Vectorized<T>& max) const {
|
| 1233 |
+
Vectorized<T> tmp = {vec_min(_vec0, max._vec0), vec_min(_vec1, max._vec1)};
|
| 1234 |
+
return blendv(tmp, *this, isnan());
|
| 1235 |
+
}
|
| 1236 |
+
|
| 1237 |
+
template <
|
| 1238 |
+
typename U = T,
|
| 1239 |
+
std::enable_if_t<std::is_same<U, float>::value, int> = 0>
|
| 1240 |
+
Vectorized<T> swapped() const {
|
| 1241 |
+
auto swap_mask = GetSwapMaskFloat();
|
| 1242 |
+
vtype v0 = vec_perm(_vec0, _vec0, swap_mask);
|
| 1243 |
+
vtype v1 = vec_perm(_vec1, _vec1, swap_mask);
|
| 1244 |
+
return {v0, v1};
|
| 1245 |
+
}
|
| 1246 |
+
|
| 1247 |
+
template <
|
| 1248 |
+
typename U = T,
|
| 1249 |
+
std::enable_if_t<std::is_same<U, double>::value, int> = 0>
|
| 1250 |
+
Vectorized<T> swapped() const {
|
| 1251 |
+
vtype v0 = vec_permi(_vec0, _vec0, 2);
|
| 1252 |
+
vtype v1 = vec_permi(_vec1, _vec1, 2);
|
| 1253 |
+
return {v0, v1};
|
| 1254 |
+
}
|
| 1255 |
+
|
| 1256 |
+
template <
|
| 1257 |
+
typename U = T,
|
| 1258 |
+
std::enable_if_t<std::is_floating_point<U>::value, int> = 0>
|
| 1259 |
+
static Vectorized<T> mergee(Vectorized<T>& first, Vectorized<T>& second) {
|
| 1260 |
+
return {
|
| 1261 |
+
vec_mergee(first._vec0, second._vec0),
|
| 1262 |
+
vec_mergee(first._vec1, second._vec1)};
|
| 1263 |
+
}
|
| 1264 |
+
|
| 1265 |
+
template <
|
| 1266 |
+
typename U = T,
|
| 1267 |
+
std::enable_if_t<std::is_floating_point<U>::value, int> = 0>
|
| 1268 |
+
static Vectorized<T> mergeo(Vectorized<T>& first, Vectorized<T>& second) {
|
| 1269 |
+
return {
|
| 1270 |
+
vec_mergeo(first._vec0, second._vec0),
|
| 1271 |
+
vec_mergeo(first._vec1, second._vec1)};
|
| 1272 |
+
}
|
| 1273 |
+
|
| 1274 |
+
static Vectorized<T> horizontal_add_perm(
|
| 1275 |
+
Vectorized<T>& first,
|
| 1276 |
+
Vectorized<T>& second) {
|
| 1277 |
+
// we will simulate it differently with 6 instructions total
|
| 1278 |
+
// lets permute second so that we can add it getting horizontal sums
|
| 1279 |
+
auto first_perm = first.swapped(); // 2perm
|
| 1280 |
+
auto second_perm = second.swapped(); // 2perm
|
| 1281 |
+
// summ
|
| 1282 |
+
auto first_ret = first + first_perm; // 2add
|
| 1283 |
+
auto second_ret = second + second_perm; // 2 add
|
| 1284 |
+
// now lets choose evens
|
| 1285 |
+
return mergee(first_ret, second_ret); // 2 mergee's
|
| 1286 |
+
}
|
| 1287 |
+
|
| 1288 |
+
static Vectorized<T> horizontal_sub_perm(
|
| 1289 |
+
Vectorized<T>& first,
|
| 1290 |
+
Vectorized<T>& second) {
|
| 1291 |
+
// we will simulate it differently with 6 instructions total
|
| 1292 |
+
// lets permute second so that we can add it getting horizontal sums
|
| 1293 |
+
auto first_perm = first.swapped(); // 2perm
|
| 1294 |
+
auto second_perm = second.swapped(); // 2perm
|
| 1295 |
+
// summ
|
| 1296 |
+
auto first_ret = first - first_perm; // 2sub
|
| 1297 |
+
auto second_ret = second - second_perm; // 2 sub
|
| 1298 |
+
// now lets choose evens
|
| 1299 |
+
return mergee(first_ret, second_ret); // 2 mergee's
|
| 1300 |
+
}
|
| 1301 |
+
|
| 1302 |
+
template <
|
| 1303 |
+
typename U = T,
|
| 1304 |
+
std::enable_if_t<std::is_floating_point<U>::value, int> = 0>
|
| 1305 |
+
Vectorized<T> mergee() const {
|
| 1306 |
+
return {vec_mergee(_vec0, _vec0), vec_mergee(_vec1, _vec1)};
|
| 1307 |
+
}
|
| 1308 |
+
|
| 1309 |
+
template <
|
| 1310 |
+
typename U = T,
|
| 1311 |
+
std::enable_if_t<std::is_floating_point<U>::value, int> = 0>
|
| 1312 |
+
Vectorized<T> mergeo() const {
|
| 1313 |
+
return {vec_mergeo(_vec0, _vec0), vec_mergeo(_vec1, _vec1)};
|
| 1314 |
+
}
|
| 1315 |
+
|
| 1316 |
+
template <
|
| 1317 |
+
typename U = T,
|
| 1318 |
+
std::enable_if_t<std::is_same<U, uint8_t>::value, int> = 0>
|
| 1319 |
+
Vectorized<int32_t> to_vec_float_helper() const {
|
| 1320 |
+
int32_t values[8] = {
|
| 1321 |
+
_vec0[0],
|
| 1322 |
+
_vec0[1],
|
| 1323 |
+
_vec0[2],
|
| 1324 |
+
_vec0[3],
|
| 1325 |
+
_vec0[4],
|
| 1326 |
+
_vec0[5],
|
| 1327 |
+
_vec0[6],
|
| 1328 |
+
_vec0[7],
|
| 1329 |
+
};
|
| 1330 |
+
|
| 1331 |
+
return Vectorized<int32_t>{
|
| 1332 |
+
values[0], values[1], values[2], values[3],
|
| 1333 |
+
values[4], values[5], values[6], values[7]
|
| 1334 |
+
};
|
| 1335 |
+
}
|
| 1336 |
+
|
| 1337 |
+
template <
|
| 1338 |
+
typename U = T,
|
| 1339 |
+
std::enable_if_t<std::is_same<U, int32_t>::value, int> = 0>
|
| 1340 |
+
Vectorized<uint8_t> to_vec_uint8_helper() const {
|
| 1341 |
+
// helper function for float to uint8_t conversion
|
| 1342 |
+
uint8_t values[8] = {
|
| 1343 |
+
static_cast<uint8_t>(_vec0[0]),
|
| 1344 |
+
static_cast<uint8_t>(_vec0[1]),
|
| 1345 |
+
static_cast<uint8_t>(_vec0[2]),
|
| 1346 |
+
static_cast<uint8_t>(_vec0[3]),
|
| 1347 |
+
static_cast<uint8_t>(_vec1[0]),
|
| 1348 |
+
static_cast<uint8_t>(_vec1[1]),
|
| 1349 |
+
static_cast<uint8_t>(_vec1[2]),
|
| 1350 |
+
static_cast<uint8_t>(_vec1[3]),
|
| 1351 |
+
};
|
| 1352 |
+
|
| 1353 |
+
return Vectorized<uint8_t>{
|
| 1354 |
+
values[0], values[1], values[2], values[3],
|
| 1355 |
+
values[4], values[5], values[6], values[7],
|
| 1356 |
+
0, 0, 0, 0,
|
| 1357 |
+
0, 0, 0, 0,
|
| 1358 |
+
0, 0, 0, 0,
|
| 1359 |
+
0, 0, 0, 0,
|
| 1360 |
+
0, 0, 0, 0,
|
| 1361 |
+
0, 0, 0, 0,
|
| 1362 |
+
};
|
| 1363 |
+
}
|
| 1364 |
+
};
|
| 1365 |
+
|
| 1366 |
+
template <>
|
| 1367 |
+
inline Vectorized<int64_t> operator~(const Vectorized<int64_t>& a) {
|
| 1368 |
+
return a._not();
|
| 1369 |
+
}
|
| 1370 |
+
|
| 1371 |
+
template <>
|
| 1372 |
+
inline Vectorized<int32_t> operator~(const Vectorized<int32_t>& a) {
|
| 1373 |
+
return a._not();
|
| 1374 |
+
}
|
| 1375 |
+
|
| 1376 |
+
template <>
|
| 1377 |
+
inline Vectorized<int16_t> operator~(const Vectorized<int16_t>& a) {
|
| 1378 |
+
return a._not();
|
| 1379 |
+
}
|
| 1380 |
+
|
| 1381 |
+
template <>
|
| 1382 |
+
inline Vectorized<int8_t> operator~(const Vectorized<int8_t>& a) {
|
| 1383 |
+
return a._not();
|
| 1384 |
+
}
|
| 1385 |
+
|
| 1386 |
+
template <>
|
| 1387 |
+
inline Vectorized<uint8_t> operator~(const Vectorized<uint8_t>& a) {
|
| 1388 |
+
return a._not();
|
| 1389 |
+
}
|
| 1390 |
+
|
| 1391 |
+
#define DEFINE_MAXMIN_FUNCS(operand_type) \
|
| 1392 |
+
template <> \
|
| 1393 |
+
Vectorized<operand_type> inline maximum( \
|
| 1394 |
+
const Vectorized<operand_type>& a, const Vectorized<operand_type>& b) { \
|
| 1395 |
+
return a.maximum(b); \
|
| 1396 |
+
} \
|
| 1397 |
+
template <> \
|
| 1398 |
+
Vectorized<operand_type> inline minimum( \
|
| 1399 |
+
const Vectorized<operand_type>& a, const Vectorized<operand_type>& b) { \
|
| 1400 |
+
return a.minimum(b); \
|
| 1401 |
+
}
|
| 1402 |
+
|
| 1403 |
+
#define DEFINE_CLAMP_MAXMIN_FUNCS(typex) \
|
| 1404 |
+
DEFINE_MAXMIN_FUNCS(typex) \
|
| 1405 |
+
template <> \
|
| 1406 |
+
Vectorized<typex> C10_ALWAYS_INLINE clamp_min( \
|
| 1407 |
+
const Vectorized<typex>& a, const Vectorized<typex>& min) { \
|
| 1408 |
+
return a.clamp_min(min); \
|
| 1409 |
+
} \
|
| 1410 |
+
template <> \
|
| 1411 |
+
Vectorized<typex> C10_ALWAYS_INLINE clamp_max( \
|
| 1412 |
+
const Vectorized<typex>& a, const Vectorized<typex>& max) { \
|
| 1413 |
+
return a.clamp_max(max); \
|
| 1414 |
+
} \
|
| 1415 |
+
template <> \
|
| 1416 |
+
Vectorized<typex> C10_ALWAYS_INLINE clamp( \
|
| 1417 |
+
const Vectorized<typex>& a, \
|
| 1418 |
+
const Vectorized<typex>& min, \
|
| 1419 |
+
const Vectorized<typex>& max) { \
|
| 1420 |
+
return clamp_max(clamp_min(a, min), max); \
|
| 1421 |
+
}
|
| 1422 |
+
|
| 1423 |
+
DEFINE_CLAMP_MAXMIN_FUNCS(int8_t)
|
| 1424 |
+
DEFINE_CLAMP_MAXMIN_FUNCS(uint8_t)
|
| 1425 |
+
DEFINE_CLAMP_MAXMIN_FUNCS(int16_t)
|
| 1426 |
+
DEFINE_CLAMP_MAXMIN_FUNCS(int32_t)
|
| 1427 |
+
DEFINE_CLAMP_MAXMIN_FUNCS(int64_t)
|
| 1428 |
+
DEFINE_CLAMP_MAXMIN_FUNCS(float)
|
| 1429 |
+
DEFINE_CLAMP_MAXMIN_FUNCS(double)
|
| 1430 |
+
|
| 1431 |
+
namespace { /* unnamed namespace */
|
| 1432 |
+
|
| 1433 |
+
#if !defined(vec_float) || __ARCH__ < 13
|
| 1434 |
+
#warning \
|
| 1435 |
+
"float->int and int->float conversion is simulated. compile for z15 for improved performance"
|
| 1436 |
+
inline ZSimdVect<float> vec_int_flt(const ZSimdVect<int> x) {
|
| 1437 |
+
return ZSimdVect<float>{float(x[0]), float(x[1]), float(x[2]), float(x[3])};
|
| 1438 |
+
}
|
| 1439 |
+
inline ZSimdVect<int> vec_flt_int(const ZSimdVect<float> x) {
|
| 1440 |
+
return ZSimdVect<int>{int(x[0]), int(x[1]), int(x[2]), int(x[3])};
|
| 1441 |
+
}
|
| 1442 |
+
#else
|
| 1443 |
+
#define vec_int_flt vec_float
|
| 1444 |
+
#define vec_flt_int vec_signed
|
| 1445 |
+
#endif
|
| 1446 |
+
|
| 1447 |
+
Vectorized<float> convert_to_float(const Vectorized<int32_t>& x) {
|
| 1448 |
+
return {vec_int_flt(x.vec0()), vec_int_flt(x.vec1())};
|
| 1449 |
+
}
|
| 1450 |
+
|
| 1451 |
+
Vectorized<int32_t> convert_to_int(const Vectorized<float>& x) {
|
| 1452 |
+
return {vec_flt_int(x.vec0()), vec_flt_int(x.vec1())};
|
| 1453 |
+
}
|
| 1454 |
+
|
| 1455 |
+
Vectorized<double> convert_to_float(const Vectorized<int64_t>& x) {
|
| 1456 |
+
return {vec_double(x.vec0()), vec_double(x.vec1())};
|
| 1457 |
+
}
|
| 1458 |
+
|
| 1459 |
+
Vectorized<int64_t> convert_to_int(const Vectorized<double>& x) {
|
| 1460 |
+
return {vec_signed(x.vec0()), vec_signed(x.vec1())};
|
| 1461 |
+
}
|
| 1462 |
+
|
| 1463 |
+
} /* unnamed namespace */
|
| 1464 |
+
|
| 1465 |
+
template <typename T, typename V>
|
| 1466 |
+
Vectorized<V> cast_zvector(const Vectorized<T>& x) {
|
| 1467 |
+
using cast_type = typename Vectorized<V>::vtype;
|
| 1468 |
+
return Vectorized<V>{(cast_type)x.vec0(), (cast_type)x.vec1()};
|
| 1469 |
+
}
|
| 1470 |
+
|
| 1471 |
+
template <>
|
| 1472 |
+
Vectorized<float> C10_ALWAYS_INLINE fmadd(
|
| 1473 |
+
const Vectorized<float>& a,
|
| 1474 |
+
const Vectorized<float>& b,
|
| 1475 |
+
const Vectorized<float>& c) {
|
| 1476 |
+
return Vectorized<float>{
|
| 1477 |
+
__builtin_s390_vfmasb(a.vec0(), b.vec0(), c.vec0()),
|
| 1478 |
+
__builtin_s390_vfmasb(a.vec1(), b.vec1(), c.vec1())};
|
| 1479 |
+
}
|
| 1480 |
+
template <>
|
| 1481 |
+
Vectorized<double> C10_ALWAYS_INLINE fmadd(
|
| 1482 |
+
const Vectorized<double>& a,
|
| 1483 |
+
const Vectorized<double>& b,
|
| 1484 |
+
const Vectorized<double>& c) {
|
| 1485 |
+
return Vectorized<double>{
|
| 1486 |
+
__builtin_s390_vfmadb(a.vec0(), b.vec0(), c.vec0()),
|
| 1487 |
+
__builtin_s390_vfmadb(a.vec1(), b.vec1(), c.vec1())};
|
| 1488 |
+
}
|
| 1489 |
+
template <>
|
| 1490 |
+
Vectorized<int16_t> C10_ALWAYS_INLINE fmadd(
|
| 1491 |
+
const Vectorized<int16_t>& a,
|
| 1492 |
+
const Vectorized<int16_t>& b,
|
| 1493 |
+
const Vectorized<int16_t>& c) {
|
| 1494 |
+
return Vectorized<int16_t>{
|
| 1495 |
+
a.vec0() * b.vec0() + c.vec0(), a.vec1() * b.vec1() + c.vec1()};
|
| 1496 |
+
}
|
| 1497 |
+
template <>
|
| 1498 |
+
Vectorized<int32_t> C10_ALWAYS_INLINE fmadd(
|
| 1499 |
+
const Vectorized<int32_t>& a,
|
| 1500 |
+
const Vectorized<int32_t>& b,
|
| 1501 |
+
const Vectorized<int32_t>& c) {
|
| 1502 |
+
return Vectorized<int32_t>{
|
| 1503 |
+
a.vec0() * b.vec0() + c.vec0(), a.vec1() * b.vec1() + c.vec1()};
|
| 1504 |
+
}
|
| 1505 |
+
template <>
|
| 1506 |
+
Vectorized<int64_t> C10_ALWAYS_INLINE fmadd(
|
| 1507 |
+
const Vectorized<int64_t>& a,
|
| 1508 |
+
const Vectorized<int64_t>& b,
|
| 1509 |
+
const Vectorized<int64_t>& c) {
|
| 1510 |
+
return Vectorized<int64_t>{
|
| 1511 |
+
a.vec0() * b.vec0() + c.vec0(), a.vec1() * b.vec1() + c.vec1()};
|
| 1512 |
+
}
|
| 1513 |
+
|
| 1514 |
+
template <>
|
| 1515 |
+
Vectorized<int64_t> C10_ALWAYS_INLINE
|
| 1516 |
+
convert_to_int_of_same_size<double>(const Vectorized<double>& src) {
|
| 1517 |
+
return convert_to_int(src);
|
| 1518 |
+
}
|
| 1519 |
+
|
| 1520 |
+
template <>
|
| 1521 |
+
Vectorized<int32_t> C10_ALWAYS_INLINE
|
| 1522 |
+
convert_to_int_of_same_size<float>(const Vectorized<float>& src) {
|
| 1523 |
+
return convert_to_int(src);
|
| 1524 |
+
}
|
| 1525 |
+
|
| 1526 |
+
template <>
|
| 1527 |
+
inline void convert(const int32_t* src, float* dst, int64_t n) {
|
| 1528 |
+
// int32_t and float have same size
|
| 1529 |
+
int64_t i;
|
| 1530 |
+
for (i = 0; i <= (n - Vectorized<float>::size());
|
| 1531 |
+
i += Vectorized<float>::size()) {
|
| 1532 |
+
const int32_t* src_a = src + i;
|
| 1533 |
+
float* dst_a = dst + i;
|
| 1534 |
+
auto input_vec = Vectorized<int32_t>::loadu(src_a);
|
| 1535 |
+
auto output_vec = convert_to_float(input_vec);
|
| 1536 |
+
output_vec.store(dst_a);
|
| 1537 |
+
}
|
| 1538 |
+
|
| 1539 |
+
for (; i < n; i++) {
|
| 1540 |
+
dst[i] = static_cast<float>(src[i]);
|
| 1541 |
+
}
|
| 1542 |
+
}
|
| 1543 |
+
|
| 1544 |
+
template <>
|
| 1545 |
+
inline void convert(const int64_t* src, double* dst, int64_t n) {
|
| 1546 |
+
int64_t i;
|
| 1547 |
+
for (i = 0; i <= (n - Vectorized<double>::size());
|
| 1548 |
+
i += Vectorized<double>::size()) {
|
| 1549 |
+
const int64_t* src_a = src + i;
|
| 1550 |
+
double* dst_a = dst + i;
|
| 1551 |
+
auto input_vec = Vectorized<int64_t>::loadu(src_a);
|
| 1552 |
+
auto output_vec = convert_to_float(input_vec);
|
| 1553 |
+
output_vec.store(dst_a);
|
| 1554 |
+
}
|
| 1555 |
+
for (; i < n; i++) {
|
| 1556 |
+
dst[i] = static_cast<double>(src[i]);
|
| 1557 |
+
}
|
| 1558 |
+
}
|
| 1559 |
+
|
| 1560 |
+
#define DEFINE_REINTERPRET_CAST_FUNCS(Fst, Cst) \
|
| 1561 |
+
template <> \
|
| 1562 |
+
C10_ALWAYS_INLINE Vectorized<Cst> cast<Cst, Fst>( \
|
| 1563 |
+
const Vectorized<Fst>& src) { \
|
| 1564 |
+
return cast_zvector<Fst, Cst>(src); \
|
| 1565 |
+
}
|
| 1566 |
+
|
| 1567 |
+
#define DEFINE_REINTERPRET_CAST_TO_ALL_FUNCS(Fst) \
|
| 1568 |
+
DEFINE_REINTERPRET_CAST_FUNCS(Fst, double) \
|
| 1569 |
+
DEFINE_REINTERPRET_CAST_FUNCS(Fst, float) \
|
| 1570 |
+
DEFINE_REINTERPRET_CAST_FUNCS(Fst, int64_t) \
|
| 1571 |
+
DEFINE_REINTERPRET_CAST_FUNCS(Fst, int32_t) \
|
| 1572 |
+
DEFINE_REINTERPRET_CAST_FUNCS(Fst, int16_t)
|
| 1573 |
+
|
| 1574 |
+
DEFINE_REINTERPRET_CAST_TO_ALL_FUNCS(float)
|
| 1575 |
+
DEFINE_REINTERPRET_CAST_TO_ALL_FUNCS(double)
|
| 1576 |
+
DEFINE_REINTERPRET_CAST_TO_ALL_FUNCS(int64_t)
|
| 1577 |
+
DEFINE_REINTERPRET_CAST_TO_ALL_FUNCS(int32_t)
|
| 1578 |
+
DEFINE_REINTERPRET_CAST_TO_ALL_FUNCS(int16_t)
|
| 1579 |
+
|
| 1580 |
+
#undef DEFINE_REINTERPRET_CAST_FUNCS
|
| 1581 |
+
|
| 1582 |
+
template <typename T>
|
| 1583 |
+
struct unpack_type {
|
| 1584 |
+
using type = T;
|
| 1585 |
+
};
|
| 1586 |
+
template <>
|
| 1587 |
+
struct unpack_type<int8_t> {
|
| 1588 |
+
using type = int16_t;
|
| 1589 |
+
};
|
| 1590 |
+
template <>
|
| 1591 |
+
struct unpack_type<uint8_t> {
|
| 1592 |
+
using type = int16_t;
|
| 1593 |
+
};
|
| 1594 |
+
template <>
|
| 1595 |
+
struct unpack_type<int16_t> {
|
| 1596 |
+
using type = int32_t;
|
| 1597 |
+
};
|
| 1598 |
+
|
| 1599 |
+
template <typename T>
|
| 1600 |
+
struct pack_type {
|
| 1601 |
+
using type = T;
|
| 1602 |
+
};
|
| 1603 |
+
template <>
|
| 1604 |
+
struct pack_type<int16_t> {
|
| 1605 |
+
using type = int8_t;
|
| 1606 |
+
};
|
| 1607 |
+
template <>
|
| 1608 |
+
struct pack_type<int32_t> {
|
| 1609 |
+
using type = int16_t;
|
| 1610 |
+
};
|
| 1611 |
+
|
| 1612 |
+
namespace { /* unnamed namespace */
|
| 1613 |
+
|
| 1614 |
+
template <typename T, typename V = typename unpack_type<T>::type>
|
| 1615 |
+
std::pair<Vectorized<V>, Vectorized<V>> unpack(const Vectorized<T>& x) {
|
| 1616 |
+
auto vec0 = vec_unpackh(x.vec0());
|
| 1617 |
+
auto vec1 = vec_unpackl(x.vec0());
|
| 1618 |
+
auto vec2 = vec_unpackh(x.vec1());
|
| 1619 |
+
auto vec3 = vec_unpackl(x.vec1());
|
| 1620 |
+
return {Vectorized<V>{vec0, vec1}, Vectorized<V>{vec2, vec3}};
|
| 1621 |
+
}
|
| 1622 |
+
|
| 1623 |
+
template <>
|
| 1624 |
+
std::pair<Vectorized<int16_t>, Vectorized<int16_t>> unpack<uint8_t, int16_t>(
|
| 1625 |
+
const Vectorized<uint8_t>& x) {
|
| 1626 |
+
using typeX = typename Vectorized<uint16_t>::vtype;
|
| 1627 |
+
typeX vec0 = vec_unpackh(x.vec0());
|
| 1628 |
+
typeX vec1 = vec_unpackl(x.vec0());
|
| 1629 |
+
typeX vec2 = vec_unpackh(x.vec1());
|
| 1630 |
+
typeX vec3 = vec_unpackl(x.vec1());
|
| 1631 |
+
// auto mask = Vectorized<uint16_t>(0xFF);
|
| 1632 |
+
// vec0 = vec0 & mask;
|
| 1633 |
+
// vec1 = vec1 & mask;
|
| 1634 |
+
// vec2 = vec2 & mask;
|
| 1635 |
+
// vec3 = vec3 & mask;
|
| 1636 |
+
return {
|
| 1637 |
+
cast_zvector<uint16_t, int16_t>(Vectorized<uint16_t>{vec0, vec1}),
|
| 1638 |
+
cast_zvector<uint16_t, int16_t>(Vectorized<uint16_t>{vec2, vec3})};
|
| 1639 |
+
}
|
| 1640 |
+
|
| 1641 |
+
template <typename T, typename V = typename pack_type<T>::type>
|
| 1642 |
+
Vectorized<V> pack(const Vectorized<T>& first, const Vectorized<T>& second) {
|
| 1643 |
+
auto vec0 = vec_packs(first.vec0(), first.vec1());
|
| 1644 |
+
auto vec1 = vec_packs(second.vec0(), second.vec1());
|
| 1645 |
+
return Vectorized<V>{vec0, vec1};
|
| 1646 |
+
}
|
| 1647 |
+
|
| 1648 |
+
template <>
|
| 1649 |
+
Vectorized<uint8_t> pack(
|
| 1650 |
+
const Vectorized<int16_t>& first,
|
| 1651 |
+
const Vectorized<int16_t>& second) {
|
| 1652 |
+
auto vec0 = vec_packsu(first.vec0(), first.vec1());
|
| 1653 |
+
auto vec1 = vec_packsu(second.vec0(), second.vec1());
|
| 1654 |
+
return Vectorized<uint8_t>{vec0, vec1};
|
| 1655 |
+
}
|
| 1656 |
+
|
| 1657 |
+
} /* unnamed namespace */
|
| 1658 |
+
|
| 1659 |
+
//////////////////////////////////QUANT///////////////////////////////////////////
|
| 1660 |
+
template <typename T>
|
| 1661 |
+
struct Vectorized<T, std::enable_if_t<is_zarch_implemented_quant<T>()>> {
|
| 1662 |
+
public:
|
| 1663 |
+
using value_type = typename T::underlying;
|
| 1664 |
+
using vtype = ZSimdVect<value_type>;
|
| 1665 |
+
using vmaskType = ZSimdVectBinary<value_type>;
|
| 1666 |
+
using vinner_type = Vectorized<value_type>;
|
| 1667 |
+
using size_type = int;
|
| 1668 |
+
|
| 1669 |
+
static constexpr size_type size() {
|
| 1670 |
+
return VECTOR_WIDTH / sizeof(value_type);
|
| 1671 |
+
}
|
| 1672 |
+
|
| 1673 |
+
static constexpr size_t float_num_vecs() {
|
| 1674 |
+
return size() / Vectorized<float>::size();
|
| 1675 |
+
}
|
| 1676 |
+
static constexpr int int_num_vecs() {
|
| 1677 |
+
return float_num_vecs();
|
| 1678 |
+
}
|
| 1679 |
+
using float_vec_return_type = std::array<Vectorized<float>, float_num_vecs()>;
|
| 1680 |
+
using int_vec_return_type =
|
| 1681 |
+
std::array<Vectorized<c10::qint32>, int_num_vecs()>;
|
| 1682 |
+
|
| 1683 |
+
private:
|
| 1684 |
+
vinner_type _vec;
|
| 1685 |
+
|
| 1686 |
+
public:
|
| 1687 |
+
Vectorized() {}
|
| 1688 |
+
|
| 1689 |
+
explicit C10_ALWAYS_INLINE Vectorized(vinner_type v) : _vec{v} {}
|
| 1690 |
+
Vectorized(const T& val) : _vec(val.val_) {}
|
| 1691 |
+
|
| 1692 |
+
C10_ALWAYS_INLINE const vinner_type& vec() const {
|
| 1693 |
+
return _vec;
|
| 1694 |
+
}
|
| 1695 |
+
|
| 1696 |
+
static Vectorized<T> C10_ALWAYS_INLINE
|
| 1697 |
+
loadu(const void* ptr, int count = size()) {
|
| 1698 |
+
return Vectorized<T>{vinner_type::loadu(ptr, count)};
|
| 1699 |
+
}
|
| 1700 |
+
|
| 1701 |
+
void C10_ALWAYS_INLINE store(void* ptr, int count = size()) const {
|
| 1702 |
+
_vec.store(ptr, count);
|
| 1703 |
+
}
|
| 1704 |
+
|
| 1705 |
+
Vectorized<T> relu(Vectorized<T> zero_point) const {
|
| 1706 |
+
return Vectorized<T>{_vec.maximum(zero_point._vec)};
|
| 1707 |
+
}
|
| 1708 |
+
|
| 1709 |
+
Vectorized<T> relu6(Vectorized<T> zero_point, Vectorized<T> q_six) const {
|
| 1710 |
+
auto ret_max = _vec.maximum(zero_point._vec);
|
| 1711 |
+
auto ret_min = ret_max.minimum(q_six._vec);
|
| 1712 |
+
return Vectorized<T>{ret_min};
|
| 1713 |
+
}
|
| 1714 |
+
|
| 1715 |
+
template <
|
| 1716 |
+
typename U = T,
|
| 1717 |
+
std::enable_if_t<Vectorized<U>::float_num_vecs() == 1, int> = 0>
|
| 1718 |
+
int_vec_return_type widening_subtract(Vectorized<T> b) const {
|
| 1719 |
+
return {*this - b};
|
| 1720 |
+
}
|
| 1721 |
+
|
| 1722 |
+
template <
|
| 1723 |
+
typename U = T,
|
| 1724 |
+
std::enable_if_t<Vectorized<U>::float_num_vecs() == 1, int> = 0>
|
| 1725 |
+
float_vec_return_type dequantize(
|
| 1726 |
+
Vectorized<float> scale,
|
| 1727 |
+
Vectorized<float> zero_point,
|
| 1728 |
+
Vectorized<float> scale_zp_premul) const {
|
| 1729 |
+
auto float_val = convert_to_float(_vec);
|
| 1730 |
+
return {fmadd(scale, float_val, scale_zp_premul)};
|
| 1731 |
+
}
|
| 1732 |
+
|
| 1733 |
+
template <
|
| 1734 |
+
typename U = T,
|
| 1735 |
+
std::enable_if_t<Vectorized<U>::float_num_vecs() == 1, int> = 0>
|
| 1736 |
+
float_vec_return_type dequantize(
|
| 1737 |
+
Vectorized<float> scale,
|
| 1738 |
+
Vectorized<float> zero_point) const {
|
| 1739 |
+
auto float_val = convert_to_float(_vec);
|
| 1740 |
+
return {(float_val - zero_point) * scale};
|
| 1741 |
+
}
|
| 1742 |
+
|
| 1743 |
+
template <
|
| 1744 |
+
typename U = T,
|
| 1745 |
+
std::enable_if_t<Vectorized<U>::float_num_vecs() == 1, int> = 0>
|
| 1746 |
+
static Vectorized<T> quantize(
|
| 1747 |
+
const float_vec_return_type& rhs,
|
| 1748 |
+
float scale,
|
| 1749 |
+
int32_t zero_point,
|
| 1750 |
+
float inverse_scale) {
|
| 1751 |
+
Vectorized<float> vecf = rhs[0];
|
| 1752 |
+
vecf = vecf * Vectorized<float>(inverse_scale);
|
| 1753 |
+
vecf = vecf.rint() + Vectorized<float>((float)(zero_point));
|
| 1754 |
+
auto veci = convert_to_int(vecf);
|
| 1755 |
+
|
| 1756 |
+
return Vectorized<T>{veci};
|
| 1757 |
+
}
|
| 1758 |
+
|
| 1759 |
+
template <
|
| 1760 |
+
typename U = T,
|
| 1761 |
+
std::enable_if_t<Vectorized<U>::int_num_vecs() == 1, int> = 0>
|
| 1762 |
+
static Vectorized<T> requantize_from_int(
|
| 1763 |
+
const int_vec_return_type& inp,
|
| 1764 |
+
float multiplier,
|
| 1765 |
+
int32_t zero_point) {
|
| 1766 |
+
Vectorized<T> vi = inp[0];
|
| 1767 |
+
auto vecf = convert_to_float(vi.vec());
|
| 1768 |
+
vecf = vecf * Vectorized<float>(multiplier);
|
| 1769 |
+
vecf = vecf.rint();
|
| 1770 |
+
auto veci = convert_to_int(vecf) + Vectorized<int>(zero_point);
|
| 1771 |
+
|
| 1772 |
+
return Vectorized<T>{veci};
|
| 1773 |
+
}
|
| 1774 |
+
|
| 1775 |
+
template <
|
| 1776 |
+
typename U = T,
|
| 1777 |
+
std::enable_if_t<Vectorized<U>::int_num_vecs() == 4, int> = 0>
|
| 1778 |
+
int_vec_return_type widening_subtract(Vectorized<U> b) const {
|
| 1779 |
+
auto ret16 = unpack(_vec);
|
| 1780 |
+
auto ret16B = unpack(b.vec());
|
| 1781 |
+
auto ret32_0 = unpack(ret16.first);
|
| 1782 |
+
auto ret32_1 = unpack(ret16.second);
|
| 1783 |
+
auto ret32B_0 = unpack(ret16B.first);
|
| 1784 |
+
auto ret32B_1 = unpack(ret16B.second);
|
| 1785 |
+
|
| 1786 |
+
return {
|
| 1787 |
+
Vectorized<c10::qint32>(ret32_0.first - ret32B_0.first),
|
| 1788 |
+
Vectorized<c10::qint32>(ret32_0.second - ret32B_0.second),
|
| 1789 |
+
Vectorized<c10::qint32>(ret32_1.first - ret32B_1.first),
|
| 1790 |
+
Vectorized<c10::qint32>(ret32_1.second - ret32B_1.second)};
|
| 1791 |
+
}
|
| 1792 |
+
|
| 1793 |
+
template <
|
| 1794 |
+
typename U = T,
|
| 1795 |
+
std::enable_if_t<Vectorized<U>::float_num_vecs() == 4, int> = 0>
|
| 1796 |
+
float_vec_return_type C10_ALWAYS_INLINE dequantize(
|
| 1797 |
+
Vectorized<float> scale,
|
| 1798 |
+
Vectorized<float> zero_point,
|
| 1799 |
+
Vectorized<float> scale_zp_premul) const {
|
| 1800 |
+
// unpacking unsigned as signed
|
| 1801 |
+
auto ret16 = unpack(_vec);
|
| 1802 |
+
auto ret32_0 = unpack(ret16.first);
|
| 1803 |
+
auto ret32_1 = unpack(ret16.second);
|
| 1804 |
+
|
| 1805 |
+
auto vecf_0 = convert_to_float(ret32_0.first);
|
| 1806 |
+
auto vecf_1 = convert_to_float(ret32_0.second);
|
| 1807 |
+
|
| 1808 |
+
auto vecf_2 = convert_to_float(ret32_1.first);
|
| 1809 |
+
auto vecf_3 = convert_to_float(ret32_1.second);
|
| 1810 |
+
return {
|
| 1811 |
+
fmadd(scale, vecf_0, scale_zp_premul),
|
| 1812 |
+
fmadd(scale, vecf_1, scale_zp_premul),
|
| 1813 |
+
fmadd(scale, vecf_2, scale_zp_premul),
|
| 1814 |
+
fmadd(scale, vecf_3, scale_zp_premul)};
|
| 1815 |
+
}
|
| 1816 |
+
|
| 1817 |
+
template <
|
| 1818 |
+
typename U = T,
|
| 1819 |
+
std::enable_if_t<Vectorized<U>::float_num_vecs() == 4, int> = 0>
|
| 1820 |
+
float_vec_return_type dequantize(
|
| 1821 |
+
Vectorized<float> scale,
|
| 1822 |
+
Vectorized<float> zero_point) const {
|
| 1823 |
+
// unpacking unsigned as signed
|
| 1824 |
+
auto ret16 = unpack(_vec);
|
| 1825 |
+
auto ret32_0 = unpack(ret16.first);
|
| 1826 |
+
auto ret32_1 = unpack(ret16.second);
|
| 1827 |
+
|
| 1828 |
+
auto vecf_0 = convert_to_float(ret32_0.first);
|
| 1829 |
+
auto vecf_1 = convert_to_float(ret32_0.second);
|
| 1830 |
+
|
| 1831 |
+
auto vecf_2 = convert_to_float(ret32_1.first);
|
| 1832 |
+
auto vecf_3 = convert_to_float(ret32_1.second);
|
| 1833 |
+
|
| 1834 |
+
return {
|
| 1835 |
+
(vecf_0 - zero_point) * scale,
|
| 1836 |
+
(vecf_1 - zero_point) * scale,
|
| 1837 |
+
(vecf_2 - zero_point) * scale,
|
| 1838 |
+
(vecf_3 - zero_point) * scale };
|
| 1839 |
+
}
|
| 1840 |
+
|
| 1841 |
+
template <
|
| 1842 |
+
typename U = T,
|
| 1843 |
+
std::enable_if_t<Vectorized<U>::float_num_vecs() == 4, int> = 0>
|
| 1844 |
+
static Vectorized<T> quantize(
|
| 1845 |
+
const float_vec_return_type& rhs,
|
| 1846 |
+
float scale,
|
| 1847 |
+
int32_t zero_point,
|
| 1848 |
+
float inverse_scale) {
|
| 1849 |
+
auto vec_inverse = Vectorized<float>(inverse_scale);
|
| 1850 |
+
auto vec_zero_point = Vectorized<float>((float)zero_point);
|
| 1851 |
+
|
| 1852 |
+
auto vecf0 = rhs[0];
|
| 1853 |
+
auto vecf2 = rhs[1];
|
| 1854 |
+
auto vecf4 = rhs[2];
|
| 1855 |
+
auto vecf6 = rhs[3];
|
| 1856 |
+
|
| 1857 |
+
vecf0 = vecf0 * vec_inverse;
|
| 1858 |
+
vecf2 = vecf2 * vec_inverse;
|
| 1859 |
+
vecf4 = vecf4 * vec_inverse;
|
| 1860 |
+
vecf6 = vecf6 * vec_inverse;
|
| 1861 |
+
|
| 1862 |
+
vecf0 = vecf0.rint() + vec_zero_point;
|
| 1863 |
+
vecf2 = vecf2.rint() + vec_zero_point;
|
| 1864 |
+
vecf4 = vecf4.rint() + vec_zero_point;
|
| 1865 |
+
vecf6 = vecf6.rint() + vec_zero_point;
|
| 1866 |
+
|
| 1867 |
+
auto veci0 = convert_to_int(vecf0);
|
| 1868 |
+
auto veci2 = convert_to_int(vecf2);
|
| 1869 |
+
auto veci4 = convert_to_int(vecf4);
|
| 1870 |
+
auto veci6 = convert_to_int(vecf6);
|
| 1871 |
+
|
| 1872 |
+
auto vecshi0 = pack(veci0, veci2);
|
| 1873 |
+
auto vecshi2 = pack(veci4, veci6);
|
| 1874 |
+
auto ret = pack<int16_t, typename U::underlying>(vecshi0, vecshi2);
|
| 1875 |
+
|
| 1876 |
+
return Vectorized<T>{ret};
|
| 1877 |
+
}
|
| 1878 |
+
|
| 1879 |
+
template <
|
| 1880 |
+
typename U = T,
|
| 1881 |
+
std::enable_if_t<Vectorized<U>::int_num_vecs() == 4, int> = 0>
|
| 1882 |
+
static Vectorized<U> requantize_from_int(
|
| 1883 |
+
const int_vec_return_type& inp,
|
| 1884 |
+
float multiplier,
|
| 1885 |
+
int32_t zero_point) {
|
| 1886 |
+
Vectorized<float> vec_multiplier = Vectorized<float>(multiplier);
|
| 1887 |
+
Vectorized<int32_t> vec_zero_point = Vectorized<int32_t>(zero_point);
|
| 1888 |
+
|
| 1889 |
+
Vectorized<c10::qint32> vi0 = inp[0];
|
| 1890 |
+
Vectorized<c10::qint32> vi1 = inp[1];
|
| 1891 |
+
Vectorized<c10::qint32> vi2 = inp[2];
|
| 1892 |
+
Vectorized<c10::qint32> vi3 = inp[3];
|
| 1893 |
+
|
| 1894 |
+
auto vecf0 = convert_to_float(vi0.vec());
|
| 1895 |
+
auto vecf2 = convert_to_float(vi1.vec());
|
| 1896 |
+
|
| 1897 |
+
auto vecf4 = convert_to_float(vi2.vec());
|
| 1898 |
+
auto vecf6 = convert_to_float(vi3.vec());
|
| 1899 |
+
|
| 1900 |
+
vecf0 = vecf0 * vec_multiplier;
|
| 1901 |
+
vecf2 = vecf2 * vec_multiplier;
|
| 1902 |
+
|
| 1903 |
+
vecf4 = vecf4 * vec_multiplier;
|
| 1904 |
+
vecf6 = vecf6 * vec_multiplier;
|
| 1905 |
+
|
| 1906 |
+
vecf0 = vecf0.rint();
|
| 1907 |
+
vecf2 = vecf2.rint();
|
| 1908 |
+
vecf4 = vecf4.rint();
|
| 1909 |
+
vecf6 = vecf6.rint();
|
| 1910 |
+
|
| 1911 |
+
auto veci0 = convert_to_int(vecf0);
|
| 1912 |
+
auto veci2 = convert_to_int(vecf2);
|
| 1913 |
+
auto veci4 = convert_to_int(vecf4);
|
| 1914 |
+
auto veci6 = convert_to_int(vecf6);
|
| 1915 |
+
|
| 1916 |
+
veci0 = veci0 + vec_zero_point;
|
| 1917 |
+
veci2 = veci2 + vec_zero_point;
|
| 1918 |
+
|
| 1919 |
+
veci4 = veci4 + vec_zero_point;
|
| 1920 |
+
veci6 = veci6 + vec_zero_point;
|
| 1921 |
+
|
| 1922 |
+
auto vecshi0 = pack<int32_t, int16_t>(veci0, veci2);
|
| 1923 |
+
auto vecshi2 = pack<int32_t, int16_t>(veci4, veci6);
|
| 1924 |
+
|
| 1925 |
+
auto ret = pack<int16_t, typename U::underlying>(vecshi0, vecshi2);
|
| 1926 |
+
|
| 1927 |
+
return Vectorized<U>{ret};
|
| 1928 |
+
}
|
| 1929 |
+
|
| 1930 |
+
Vectorized<T> C10_ALWAYS_INLINE operator+(const Vectorized<T>& other) const {
|
| 1931 |
+
return Vectorized<T>{_vec + other._vec};
|
| 1932 |
+
}
|
| 1933 |
+
|
| 1934 |
+
Vectorized<T> C10_ALWAYS_INLINE operator-(const Vectorized<T>& other) const {
|
| 1935 |
+
return Vectorized<T>{_vec - other._vec};
|
| 1936 |
+
}
|
| 1937 |
+
|
| 1938 |
+
Vectorized<T> C10_ALWAYS_INLINE operator*(const Vectorized<T>& other) const {
|
| 1939 |
+
return Vectorized<T>{_vec * other._vec};
|
| 1940 |
+
}
|
| 1941 |
+
|
| 1942 |
+
Vectorized<T> C10_ALWAYS_INLINE operator/(const Vectorized<T>& other) const {
|
| 1943 |
+
return Vectorized<T>{_vec / other._vec};
|
| 1944 |
+
}
|
| 1945 |
+
|
| 1946 |
+
Vectorized<T> C10_ALWAYS_INLINE operator&(const Vectorized<T>& other) const {
|
| 1947 |
+
return Vectorized<T>{_vec & other._vec};
|
| 1948 |
+
}
|
| 1949 |
+
|
| 1950 |
+
Vectorized<T> C10_ALWAYS_INLINE operator|(const Vectorized<T>& other) const {
|
| 1951 |
+
return Vectorized<T>{_vec | other._vec};
|
| 1952 |
+
}
|
| 1953 |
+
|
| 1954 |
+
Vectorized<T> C10_ALWAYS_INLINE operator^(const Vectorized<T>& other) const {
|
| 1955 |
+
return Vectorized<T>{_vec ^ other._vec};
|
| 1956 |
+
}
|
| 1957 |
+
Vectorized<T> C10_ALWAYS_INLINE operator==(const Vectorized<T>& other) const {
|
| 1958 |
+
return Vectorized<T>{_vec == other._vec};
|
| 1959 |
+
}
|
| 1960 |
+
|
| 1961 |
+
Vectorized<T> C10_ALWAYS_INLINE operator!=(const Vectorized<T>& other) const {
|
| 1962 |
+
return Vectorized<T>{_vec != other._vec};
|
| 1963 |
+
}
|
| 1964 |
+
Vectorized<T> C10_ALWAYS_INLINE operator>(const Vectorized<T>& other) const {
|
| 1965 |
+
return Vectorized<T>{_vec > other._vec};
|
| 1966 |
+
}
|
| 1967 |
+
Vectorized<T> C10_ALWAYS_INLINE operator>=(const Vectorized<T>& other) const {
|
| 1968 |
+
return Vectorized<T>{_vec >= other._vec};
|
| 1969 |
+
}
|
| 1970 |
+
|
| 1971 |
+
Vectorized<T> C10_ALWAYS_INLINE operator<(const Vectorized<T>& other) const {
|
| 1972 |
+
return Vectorized<T>{_vec < other._vec};
|
| 1973 |
+
}
|
| 1974 |
+
|
| 1975 |
+
Vectorized<T> C10_ALWAYS_INLINE operator<=(const Vectorized<T>& other) const {
|
| 1976 |
+
return Vectorized<T>{_vec <= other._vec};
|
| 1977 |
+
}
|
| 1978 |
+
|
| 1979 |
+
Vectorized<T> C10_ALWAYS_INLINE eq(const Vectorized<T>& other) const {
|
| 1980 |
+
return Vectorized<T>{_vec.eq(other._vec)};
|
| 1981 |
+
}
|
| 1982 |
+
Vectorized<T> C10_ALWAYS_INLINE ne(const Vectorized<T>& other) const {
|
| 1983 |
+
return Vectorized<T>{_vec.ne(other._vec)};
|
| 1984 |
+
}
|
| 1985 |
+
Vectorized<T> C10_ALWAYS_INLINE gt(const Vectorized<T>& other) const {
|
| 1986 |
+
return Vectorized<T>{_vec.gt(other._vec)};
|
| 1987 |
+
}
|
| 1988 |
+
Vectorized<T> C10_ALWAYS_INLINE ge(const Vectorized<T>& other) const {
|
| 1989 |
+
return Vectorized<T>{_vec.ge(other._vec)};
|
| 1990 |
+
}
|
| 1991 |
+
Vectorized<T> C10_ALWAYS_INLINE lt(const Vectorized<T>& other) const {
|
| 1992 |
+
return Vectorized<T>{_vec.lt(other._vec)};
|
| 1993 |
+
}
|
| 1994 |
+
Vectorized<T> C10_ALWAYS_INLINE le(const Vectorized<T>& other) const {
|
| 1995 |
+
return Vectorized<T>{_vec.le(other._vec)};
|
| 1996 |
+
}
|
| 1997 |
+
|
| 1998 |
+
Vectorized<T> clamp_min(const Vectorized<T>& min) const {
|
| 1999 |
+
return Vectorized<T>{_vec.clamp_min(min._vec)};
|
| 2000 |
+
}
|
| 2001 |
+
|
| 2002 |
+
Vectorized<T> clamp_max(const Vectorized<T>& max) const {
|
| 2003 |
+
return Vectorized<T>{_vec.clamp_max(max._vec)};
|
| 2004 |
+
}
|
| 2005 |
+
|
| 2006 |
+
Vectorized<T> minimum(const Vectorized<T>& other) const {
|
| 2007 |
+
return Vectorized<T>{_vec.minimum(other._vec)};
|
| 2008 |
+
}
|
| 2009 |
+
|
| 2010 |
+
Vectorized<T> maximum(const Vectorized<T>& other) const {
|
| 2011 |
+
return Vectorized<T>{_vec.maximum(other._vec)};
|
| 2012 |
+
}
|
| 2013 |
+
};
|
| 2014 |
+
|
| 2015 |
+
DEFINE_CLAMP_MAXMIN_FUNCS(c10::quint8)
|
| 2016 |
+
DEFINE_CLAMP_MAXMIN_FUNCS(c10::qint8)
|
| 2017 |
+
DEFINE_CLAMP_MAXMIN_FUNCS(c10::qint32)
|
| 2018 |
+
|
| 2019 |
+
template <typename U = float>
|
| 2020 |
+
constexpr auto real_mask() {
|
| 2021 |
+
return (ZSimdVect<U>)ZSimdVectBinary<float>{0xFFFFFFFF, 0, 0xFFFFFFFF, 0};
|
| 2022 |
+
}
|
| 2023 |
+
|
| 2024 |
+
template <>
|
| 2025 |
+
constexpr auto real_mask<double>() {
|
| 2026 |
+
return (ZSimdVect<double>)ZSimdVectBinary<double>{0xFFFFFFFFFFFFFFFF, 0};
|
| 2027 |
+
}
|
| 2028 |
+
|
| 2029 |
+
template <typename U = float>
|
| 2030 |
+
constexpr auto image_mask() {
|
| 2031 |
+
return (ZSimdVect<U>)ZSimdVectBinary<U>{0, 0xFFFFFFFF, 0, 0xFFFFFFFF};
|
| 2032 |
+
}
|
| 2033 |
+
|
| 2034 |
+
template <>
|
| 2035 |
+
constexpr auto image_mask<double>() {
|
| 2036 |
+
return (ZSimdVect<double>)ZSimdVectBinary<double>{0, 0xFFFFFFFFFFFFFFFF};
|
| 2037 |
+
}
|
| 2038 |
+
|
| 2039 |
+
template <typename U = float>
|
| 2040 |
+
constexpr auto rsign_mask() {
|
| 2041 |
+
return ZSimdVect<U>{-0.f, 0.f, -0.f, 0.f};
|
| 2042 |
+
}
|
| 2043 |
+
|
| 2044 |
+
template <>
|
| 2045 |
+
constexpr auto rsign_mask<double>() {
|
| 2046 |
+
return ZSimdVect<double>{-0.0, 0.f};
|
| 2047 |
+
}
|
| 2048 |
+
|
| 2049 |
+
template <typename U = float>
|
| 2050 |
+
constexpr auto isign_mask() {
|
| 2051 |
+
return ZSimdVect<U>{0.0, -0.f, 0.0, -0.f};
|
| 2052 |
+
}
|
| 2053 |
+
|
| 2054 |
+
template <>
|
| 2055 |
+
constexpr auto isign_mask<double>() {
|
| 2056 |
+
return ZSimdVect<double>{0.0, -0.0};
|
| 2057 |
+
}
|
| 2058 |
+
|
| 2059 |
+
template <typename U = float>
|
| 2060 |
+
constexpr auto image_one() {
|
| 2061 |
+
return ZSimdVect<U>{0, 1.f, 0, 1.f};
|
| 2062 |
+
}
|
| 2063 |
+
|
| 2064 |
+
template <>
|
| 2065 |
+
constexpr auto image_one<double>() {
|
| 2066 |
+
return ZSimdVect<double>{0.0, 1.0};
|
| 2067 |
+
}
|
| 2068 |
+
|
| 2069 |
+
template <typename U = float>
|
| 2070 |
+
constexpr auto pi_half() {
|
| 2071 |
+
return ZSimdVect<U>{(float)(M_PI / 2.0), 0.f, (float)(M_PI / 2.0), 0.f};
|
| 2072 |
+
}
|
| 2073 |
+
|
| 2074 |
+
template <>
|
| 2075 |
+
constexpr auto pi_half<double>() {
|
| 2076 |
+
return ZSimdVect<double>{M_PI / 2.0, 0.0};
|
| 2077 |
+
}
|
| 2078 |
+
|
| 2079 |
+
template <typename U = float>
|
| 2080 |
+
constexpr auto image_half() {
|
| 2081 |
+
return ZSimdVect<U>{0, 0.5f, 0, 0.5f};
|
| 2082 |
+
}
|
| 2083 |
+
|
| 2084 |
+
template <>
|
| 2085 |
+
constexpr auto image_half<double>() {
|
| 2086 |
+
return ZSimdVect<double>{0.0, 0.5};
|
| 2087 |
+
}
|
| 2088 |
+
|
| 2089 |
+
template <typename U>
|
| 2090 |
+
constexpr U log2e_inv() {
|
| 2091 |
+
return static_cast<U>(1.4426950408889634);
|
| 2092 |
+
}
|
| 2093 |
+
|
| 2094 |
+
template <typename U>
|
| 2095 |
+
constexpr U log10e_inv() {
|
| 2096 |
+
return static_cast<U>(0.43429448190325176);
|
| 2097 |
+
}
|
| 2098 |
+
|
| 2099 |
+
template <typename T>
|
| 2100 |
+
struct Vectorized<T, std::enable_if_t<is_zarch_implemented_complex<T>()>> {
|
| 2101 |
+
public:
|
| 2102 |
+
using underline_type = decltype(std::declval<T>().imag());
|
| 2103 |
+
using value_type = T;
|
| 2104 |
+
using vtype = ZSimdVect<underline_type>;
|
| 2105 |
+
using vmaskType = ZSimdVectBinary<underline_type>;
|
| 2106 |
+
using vinner_type = Vectorized<underline_type>;
|
| 2107 |
+
using size_type = int;
|
| 2108 |
+
using vinner_data = typename Vectorized<underline_type>::vinner_data;
|
| 2109 |
+
|
| 2110 |
+
static constexpr size_type size() {
|
| 2111 |
+
return VECTOR_WIDTH / sizeof(value_type);
|
| 2112 |
+
}
|
| 2113 |
+
|
| 2114 |
+
private:
|
| 2115 |
+
vinner_type _vec;
|
| 2116 |
+
|
| 2117 |
+
public:
|
| 2118 |
+
Vectorized() {}
|
| 2119 |
+
|
| 2120 |
+
C10_ALWAYS_INLINE Vectorized(const vinner_data &v) : _vec{v.first, v.second} {}
|
| 2121 |
+
|
| 2122 |
+
template <typename U = T, std::enable_if_t<(sizeof(U) == 16), int> = 0>
|
| 2123 |
+
C10_ALWAYS_INLINE Vectorized(T s1, T s2)
|
| 2124 |
+
: _vec{s1.real(), s1.imag(), s2.real(), s2.imag()} {}
|
| 2125 |
+
|
| 2126 |
+
template <typename U = T, std::enable_if_t<(sizeof(U) == 8), int> = 0>
|
| 2127 |
+
C10_ALWAYS_INLINE Vectorized(T s1, T s2, T s3, T s4)
|
| 2128 |
+
: _vec{
|
| 2129 |
+
s1.real(),
|
| 2130 |
+
s1.imag(),
|
| 2131 |
+
s2.real(),
|
| 2132 |
+
s2.imag(),
|
| 2133 |
+
s3.real(),
|
| 2134 |
+
s3.imag(),
|
| 2135 |
+
s4.real(),
|
| 2136 |
+
s4.imag()} {}
|
| 2137 |
+
|
| 2138 |
+
template <typename U = T, std::enable_if_t<(sizeof(U) == 16), int> = 0>
|
| 2139 |
+
C10_ALWAYS_INLINE Vectorized(T s) : Vectorized<T>(s, s) {}
|
| 2140 |
+
|
| 2141 |
+
template <typename U = T, std::enable_if_t<(sizeof(U) == 8), int> = 0>
|
| 2142 |
+
C10_ALWAYS_INLINE Vectorized(T s) : Vectorized<T>(s, s, s, s) {}
|
| 2143 |
+
|
| 2144 |
+
C10_ALWAYS_INLINE operator vinner_type() const {
|
| 2145 |
+
return _vec;
|
| 2146 |
+
}
|
| 2147 |
+
|
| 2148 |
+
C10_ALWAYS_INLINE const vinner_type& vec() const {
|
| 2149 |
+
return _vec;
|
| 2150 |
+
}
|
| 2151 |
+
|
| 2152 |
+
C10_ALWAYS_INLINE operator vinner_data() const {
|
| 2153 |
+
return _vec.data();
|
| 2154 |
+
}
|
| 2155 |
+
|
| 2156 |
+
C10_ALWAYS_INLINE vinner_data data() const {
|
| 2157 |
+
return _vec.data();
|
| 2158 |
+
}
|
| 2159 |
+
|
| 2160 |
+
static Vectorized<T> C10_ALWAYS_INLINE
|
| 2161 |
+
loadu(const void* ptr, int count = size()) {
|
| 2162 |
+
return Vectorized<T>{vinner_type::loadu(ptr, 2 * count)};
|
| 2163 |
+
}
|
| 2164 |
+
|
| 2165 |
+
void C10_ALWAYS_INLINE store(void* ptr, int count = size()) const {
|
| 2166 |
+
return _vec.store(ptr, 2 * count);
|
| 2167 |
+
}
|
| 2168 |
+
|
| 2169 |
+
static Vectorized<T> blendv(
|
| 2170 |
+
const Vectorized<T>& a,
|
| 2171 |
+
const Vectorized<T>& b,
|
| 2172 |
+
const Vectorized<T>& mask) {
|
| 2173 |
+
// convert std::complex<V> index mask to V index mask: xy -> xxyy
|
| 2174 |
+
vinner_type vmask = mask.vec();
|
| 2175 |
+
auto mask_complex = vinner_type(
|
| 2176 |
+
vec_mergeh(vmask.vec0(), vmask.vec0()),
|
| 2177 |
+
vec_mergeh(vmask.vec1(), vmask.vec1()));
|
| 2178 |
+
return Vectorized<T>{vinner_type::blendv(a.vec(), b.vec(), mask_complex)};
|
| 2179 |
+
}
|
| 2180 |
+
|
| 2181 |
+
template <int64_t mask>
|
| 2182 |
+
static auto C10_ALWAYS_INLINE
|
| 2183 |
+
blend(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 2184 |
+
constexpr int mask_complex = maskForComplex<sizeof(T)>(mask);
|
| 2185 |
+
return Vectorized<T>{
|
| 2186 |
+
vinner_type::template blend<mask_complex>(a.vec(), b.vec())};
|
| 2187 |
+
}
|
| 2188 |
+
|
| 2189 |
+
template <typename step_t, typename U = T>
|
| 2190 |
+
static std::enable_if_t<sizeof(U) == 16, Vectorized<T>> arange(
|
| 2191 |
+
T base = 0,
|
| 2192 |
+
step_t step = static_cast<step_t>(1)) {
|
| 2193 |
+
return Vectorized<T>(base, base + step);
|
| 2194 |
+
}
|
| 2195 |
+
|
| 2196 |
+
template <typename step_t, typename U = T>
|
| 2197 |
+
static std::enable_if_t<sizeof(U) == 8, Vectorized<T>> arange(
|
| 2198 |
+
T base = 0,
|
| 2199 |
+
step_t step = static_cast<step_t>(1)) {
|
| 2200 |
+
return Vectorized<T>(
|
| 2201 |
+
base,
|
| 2202 |
+
base + step,
|
| 2203 |
+
base + value_type(2) * step,
|
| 2204 |
+
base + value_type(3) * step);
|
| 2205 |
+
}
|
| 2206 |
+
|
| 2207 |
+
template <int16_t Z, int16_t C>
|
| 2208 |
+
static inline std::enable_if_t<(Z >= C), Vectorized<T>> set_inner(
|
| 2209 |
+
const Vectorized<T>& a,
|
| 2210 |
+
const Vectorized<T>& b,
|
| 2211 |
+
size_t count) {
|
| 2212 |
+
return b;
|
| 2213 |
+
}
|
| 2214 |
+
|
| 2215 |
+
template <int16_t Z, int16_t C>
|
| 2216 |
+
static inline std::enable_if_t<(Z < C), Vectorized<T>> set_inner(
|
| 2217 |
+
const Vectorized<T>& a,
|
| 2218 |
+
const Vectorized<T>& b,
|
| 2219 |
+
size_t count) {
|
| 2220 |
+
if (count == Z)
|
| 2221 |
+
return blend<allbitset(Z)>(a, b);
|
| 2222 |
+
else
|
| 2223 |
+
return set_inner<Z + 1, C>(a, b, count);
|
| 2224 |
+
}
|
| 2225 |
+
|
| 2226 |
+
static Vectorized<T> set(
|
| 2227 |
+
const Vectorized<T>& a,
|
| 2228 |
+
const Vectorized<T>& b,
|
| 2229 |
+
size_t count = size()) {
|
| 2230 |
+
if (count == 0)
|
| 2231 |
+
return a;
|
| 2232 |
+
return set_inner<1, size()>(a, b, count);
|
| 2233 |
+
}
|
| 2234 |
+
|
| 2235 |
+
const T& operator[](int idx) const = delete;
|
| 2236 |
+
T& operator[](int idx) = delete;
|
| 2237 |
+
|
| 2238 |
+
template <
|
| 2239 |
+
typename U = T,
|
| 2240 |
+
std::enable_if_t<std::is_same<U, c10::complex<float>>::value, int> = 0>
|
| 2241 |
+
Vectorized<T> mapOrdinary(T (*const f)(const T&)) const {
|
| 2242 |
+
auto v0 = _vec.vec0();
|
| 2243 |
+
auto v1 = _vec.vec1();
|
| 2244 |
+
return Vectorized<T>{
|
| 2245 |
+
f(T(v0[0], v0[1])),
|
| 2246 |
+
f(T(v0[2], v0[3])),
|
| 2247 |
+
f(T(v1[0], v1[1])),
|
| 2248 |
+
f(T(v1[2], v1[3]))};
|
| 2249 |
+
}
|
| 2250 |
+
|
| 2251 |
+
template <
|
| 2252 |
+
typename U = T,
|
| 2253 |
+
std::enable_if_t<std::is_same<U, c10::complex<double>>::value, int> = 0>
|
| 2254 |
+
Vectorized<U> mapOrdinary(T (*const f)(const T&)) const {
|
| 2255 |
+
auto v0 = _vec.vec0();
|
| 2256 |
+
auto v1 = _vec.vec1();
|
| 2257 |
+
return Vectorized<T>{f(T(v0[0], v0[1])), f(T(v1[0], v1[1]))};
|
| 2258 |
+
}
|
| 2259 |
+
|
| 2260 |
+
template <
|
| 2261 |
+
typename U = T,
|
| 2262 |
+
std::enable_if_t<std::is_same<U, c10::complex<float>>::value, int> = 0>
|
| 2263 |
+
Vectorized<T> mapOrdinary(T (*const f)(T)) const {
|
| 2264 |
+
auto v0 = _vec.vec0();
|
| 2265 |
+
auto v1 = _vec.vec1();
|
| 2266 |
+
return Vectorized<T>{
|
| 2267 |
+
f(T(v0[0], v0[1])),
|
| 2268 |
+
f(T(v0[2], v0[3])),
|
| 2269 |
+
f(T(v1[0], v1[1])),
|
| 2270 |
+
f(T(v1[2], v1[3]))};
|
| 2271 |
+
}
|
| 2272 |
+
|
| 2273 |
+
template <
|
| 2274 |
+
typename U = T,
|
| 2275 |
+
std::enable_if_t<std::is_same<U, c10::complex<double>>::value, int> = 0>
|
| 2276 |
+
Vectorized<T> mapOrdinary(T (*const f)(T)) const {
|
| 2277 |
+
auto v0 = _vec.vec0();
|
| 2278 |
+
auto v1 = _vec.vec1();
|
| 2279 |
+
return Vectorized<T>{f(T(v0[0], v0[1])), f(T(v1[0], v1[1]))};
|
| 2280 |
+
}
|
| 2281 |
+
|
| 2282 |
+
template <
|
| 2283 |
+
typename U = T,
|
| 2284 |
+
std::enable_if_t<std::is_same<U, c10::complex<float>>::value, int> = 0>
|
| 2285 |
+
inline Vectorized<T> mapOrdinary(
|
| 2286 |
+
T (*const f)(const T&, const T&),
|
| 2287 |
+
const Vectorized<T>& b) const {
|
| 2288 |
+
auto v0 = _vec.vec0();
|
| 2289 |
+
auto v1 = _vec.vec1();
|
| 2290 |
+
auto bvec = b.vec();
|
| 2291 |
+
auto b0 = bvec.vec0();
|
| 2292 |
+
auto b1 = bvec.vec1();
|
| 2293 |
+
T a00 = f(T(v0[0], v0[1]), T(b0[0], b0[1]));
|
| 2294 |
+
T a01 = f(T(v0[2], v0[3]), T(b0[2], b0[3]));
|
| 2295 |
+
T a02 = f(T(v1[0], v1[1]), T(b1[0], b1[1]));
|
| 2296 |
+
T a03 = f(T(v1[2], v1[3]), T(b1[2], b1[3]));
|
| 2297 |
+
return Vectorized<T>{a00, a01, a02, a03};
|
| 2298 |
+
}
|
| 2299 |
+
|
| 2300 |
+
template <
|
| 2301 |
+
typename U = T,
|
| 2302 |
+
std::enable_if_t<std::is_same<U, c10::complex<double>>::value, int> = 0>
|
| 2303 |
+
inline Vectorized<T> mapOrdinary(
|
| 2304 |
+
T (*const f)(const T&, const T&),
|
| 2305 |
+
const Vectorized<T>& b) const {
|
| 2306 |
+
auto v0 = _vec.vec0();
|
| 2307 |
+
auto v1 = _vec.vec1();
|
| 2308 |
+
auto bvec = b.vec();
|
| 2309 |
+
auto b0 = bvec.vec0();
|
| 2310 |
+
auto b1 = bvec.vec1();
|
| 2311 |
+
U a00 = f(U(v0[0], v0[1]), U(b0[0], b0[1]));
|
| 2312 |
+
U a01 = f(U(v1[0], v1[1]), U(b1[0], b1[1]));
|
| 2313 |
+
return Vectorized<T>{a00, a01};
|
| 2314 |
+
}
|
| 2315 |
+
|
| 2316 |
+
Vectorized<T> C10_ALWAYS_INLINE operator+(const Vectorized<T>& other) const {
|
| 2317 |
+
return Vectorized<T>{_vec + other._vec};
|
| 2318 |
+
}
|
| 2319 |
+
|
| 2320 |
+
Vectorized<T> C10_ALWAYS_INLINE operator-(const Vectorized<T>& other) const {
|
| 2321 |
+
return Vectorized<T>{_vec - other._vec};
|
| 2322 |
+
}
|
| 2323 |
+
|
| 2324 |
+
Vectorized<T> inline operator*(const Vectorized<T>& b) const {
|
| 2325 |
+
//(a + bi) * (c + di) = (ac - bd) + (ad + bc)i
|
| 2326 |
+
vinner_type bv = b.vec();
|
| 2327 |
+
#if !defined(ZVECTOR_SIMULATE_X86_MULT)
|
| 2328 |
+
// this is more z arch friendly than simulating horizontal from x86
|
| 2329 |
+
vinner_type vi = bv.mergeo();
|
| 2330 |
+
vinner_type vr = bv.mergee();
|
| 2331 |
+
vi = vi ^ rsign_mask<underline_type>();
|
| 2332 |
+
vinner_type ret = _vec * vr;
|
| 2333 |
+
vinner_type vx_swapped = _vec.swapped();
|
| 2334 |
+
ret = fmadd(vx_swapped, vi, ret);
|
| 2335 |
+
#else
|
| 2336 |
+
vinner_type ac_bd = _vec * b;
|
| 2337 |
+
vinner_type d_c = bv.swapped();
|
| 2338 |
+
d_c = d_c ^ isign_mask<underline_type>();
|
| 2339 |
+
vinner_type ad_bc = _vec * d_c;
|
| 2340 |
+
vinner_type ret = vinner_type::horizontal_sub_perm(ac_bd, ad_bc);
|
| 2341 |
+
#endif
|
| 2342 |
+
return Vectorized<T>{ret};
|
| 2343 |
+
}
|
| 2344 |
+
|
| 2345 |
+
template <
|
| 2346 |
+
typename U = T,
|
| 2347 |
+
std::enable_if_t<std::is_same<U, c10::complex<float>>::value, int> = 0>
|
| 2348 |
+
static typename Vectorized<T>::vinner_type real_neg(const typename Vectorized<T>::vinner_type &a)
|
| 2349 |
+
{
|
| 2350 |
+
const auto swap_mask = ZSimdVectBinary<uint8_t>{
|
| 2351 |
+
0, 1, 2, 3, 20, 21, 22, 23, 8, 9, 10, 11, 28, 29, 30, 31};
|
| 2352 |
+
|
| 2353 |
+
auto a_neg = a.neg();
|
| 2354 |
+
vtype v0 = vec_perm(a_neg.vec0(), a.vec0(), swap_mask);
|
| 2355 |
+
vtype v1 = vec_perm(a_neg.vec1(), a.vec1(), swap_mask);
|
| 2356 |
+
return {v0, v1};
|
| 2357 |
+
}
|
| 2358 |
+
|
| 2359 |
+
template <
|
| 2360 |
+
typename U = T,
|
| 2361 |
+
std::enable_if_t<std::is_same<U, c10::complex<double>>::value, int> = 0>
|
| 2362 |
+
static typename Vectorized<T>::vinner_type real_neg(const typename Vectorized<T>::vinner_type &a)
|
| 2363 |
+
{
|
| 2364 |
+
auto a_neg = a.neg();
|
| 2365 |
+
auto v0 = vec_permi(a_neg.vec0(), a.vec0(), 1);
|
| 2366 |
+
auto v1 = vec_permi(a_neg.vec1(), a.vec1(), 1);
|
| 2367 |
+
return { v0, v1 };
|
| 2368 |
+
}
|
| 2369 |
+
|
| 2370 |
+
Vectorized<T> inline operator/(const Vectorized<T>& b) const {
|
| 2371 |
+
// Unfortunately, this breaks some tests
|
| 2372 |
+
// Implement it like it's done for avx2
|
| 2373 |
+
auto fabs_cd = b.vec().abs(); // |c| |d|
|
| 2374 |
+
auto fabs_dc = fabs_cd.swapped(); // |d| |c|
|
| 2375 |
+
auto scale = vinner_type {1.0} / maximum(fabs_cd, fabs_dc); // 1/sc 1/sc
|
| 2376 |
+
auto a2 = vec() * scale; // a/sc b/sc
|
| 2377 |
+
auto b2 = b.vec() * scale; // c/sc d/sc
|
| 2378 |
+
auto acbd2 = a2 * b2; // ac/sc^2 bd/sc^2
|
| 2379 |
+
|
| 2380 |
+
auto dc2 = b2.swapped(); // d/sc c/sc
|
| 2381 |
+
dc2 = Vectorized<T>::real_neg(dc2); // -d/|c,d| c/sc
|
| 2382 |
+
auto adbc2 = a2 * dc2; // -ad/sc^2 bc/sc^2
|
| 2383 |
+
auto sum1 = acbd2 + acbd2.swapped(); // (ac+bd)/sc^2 (ac+bd)/sc^2
|
| 2384 |
+
auto sum2 = adbc2 + adbc2.swapped(); // (bc-ad)/sc^2 (bc-ad)/sc^2
|
| 2385 |
+
auto res2 = vinner_type::mergee(sum1, sum2); // (ac+bd)/sc^2 (bc-ad)/sc^2
|
| 2386 |
+
|
| 2387 |
+
// get the denominator
|
| 2388 |
+
auto denom2 = Vectorized<T>{b2}.abs_2_(); // (c^2+d^2)/sc^2 (c^2+d^2)/sc^2
|
| 2389 |
+
res2 = res2 / denom2;
|
| 2390 |
+
return Vectorized<T>{ res2 };
|
| 2391 |
+
}
|
| 2392 |
+
|
| 2393 |
+
Vectorized<T> angle2_() const {
|
| 2394 |
+
auto b_a = _vec.swapped(); // b a
|
| 2395 |
+
return Vectorized<T>{_vec.atan2(b_a).swapped()};
|
| 2396 |
+
}
|
| 2397 |
+
|
| 2398 |
+
Vectorized<T> angle() const {
|
| 2399 |
+
return angle2_().real();
|
| 2400 |
+
}
|
| 2401 |
+
|
| 2402 |
+
Vectorized<T> atan() const {
|
| 2403 |
+
// atan(x) = i/2 * ln((i + z)/(i - z))
|
| 2404 |
+
auto ione = Vectorized<T>{vinner_type(image_one<underline_type>())};
|
| 2405 |
+
auto sum = ione + *this;
|
| 2406 |
+
auto sub = ione - *this;
|
| 2407 |
+
auto ln = (sum / sub).log(); // ln((i + z)/(i - z))
|
| 2408 |
+
return ln *
|
| 2409 |
+
Vectorized<T>{vinner_type(image_half<underline_type>())}; // i/2*ln()
|
| 2410 |
+
}
|
| 2411 |
+
|
| 2412 |
+
Vectorized<T> atanh() const {
|
| 2413 |
+
return mapOrdinary(std::atanh);
|
| 2414 |
+
}
|
| 2415 |
+
|
| 2416 |
+
Vectorized<T> asin() const {
|
| 2417 |
+
// asin(x)
|
| 2418 |
+
// = -i*ln(iz + sqrt(1 -z^2))
|
| 2419 |
+
// = -i*ln((ai - b) + sqrt(1 - (a + bi)*(a + bi)))
|
| 2420 |
+
// = -i*ln((-b + ai) + sqrt(1 - (a**2 - b**2) - 2*abi))
|
| 2421 |
+
#if 1
|
| 2422 |
+
vinner_type cnj = conj().vec();
|
| 2423 |
+
vinner_type b_a = cnj.swapped();
|
| 2424 |
+
vinner_type ab = cnj * b_a;
|
| 2425 |
+
vinner_type im = ab + ab;
|
| 2426 |
+
vinner_type val_2 = _vec * _vec;
|
| 2427 |
+
vinner_type val_2_swapped = val_2.swapped();
|
| 2428 |
+
vinner_type re = vinner_type::horizontal_sub_perm(val_2, val_2_swapped);
|
| 2429 |
+
re = vinner_type(static_cast<underline_type>(1)) - re;
|
| 2430 |
+
constexpr int blend_mask =
|
| 2431 |
+
blend_choice<T>(); // 0x0A for complex<double> , 0xAA for complex<float>
|
| 2432 |
+
vinner_type blendx = vinner_type::template blend<blend_mask>(re, im);
|
| 2433 |
+
auto root = Vectorized<T>(blendx).sqrt();
|
| 2434 |
+
auto ln = Vectorized<T>(Vectorized<T>(b_a) + root).log();
|
| 2435 |
+
return Vectorized<T>(ln.vec().swapped()).conj();
|
| 2436 |
+
#else
|
| 2437 |
+
return mapOrdinary(std::asin);
|
| 2438 |
+
#endif
|
| 2439 |
+
}
|
| 2440 |
+
|
| 2441 |
+
Vectorized<T> acos() const {
|
| 2442 |
+
// acos(x) = pi/2 - asin(x)
|
| 2443 |
+
return Vectorized<T>(vinner_type(pi_half<underline_type>())) - asin();
|
| 2444 |
+
}
|
| 2445 |
+
|
| 2446 |
+
Vectorized<T> sin() const {
|
| 2447 |
+
return mapOrdinary(std::sin);
|
| 2448 |
+
}
|
| 2449 |
+
Vectorized<T> sinh() const {
|
| 2450 |
+
return mapOrdinary(std::sinh);
|
| 2451 |
+
}
|
| 2452 |
+
Vectorized<T> cos() const {
|
| 2453 |
+
return mapOrdinary(std::cos);
|
| 2454 |
+
}
|
| 2455 |
+
Vectorized<T> cosh() const {
|
| 2456 |
+
return mapOrdinary(std::cosh);
|
| 2457 |
+
}
|
| 2458 |
+
Vectorized<T> ceil() const {
|
| 2459 |
+
return Vectorized<T>{_vec.ceil()};
|
| 2460 |
+
}
|
| 2461 |
+
Vectorized<T> floor() const {
|
| 2462 |
+
return Vectorized<T>{_vec.floor()};
|
| 2463 |
+
}
|
| 2464 |
+
Vectorized<T> neg() const {
|
| 2465 |
+
return Vectorized<T>(_vec.neg());
|
| 2466 |
+
}
|
| 2467 |
+
Vectorized<T> round() const {
|
| 2468 |
+
return Vectorized<T>{_vec.round()};
|
| 2469 |
+
}
|
| 2470 |
+
Vectorized<T> tan() const {
|
| 2471 |
+
return mapOrdinary(std::tan);
|
| 2472 |
+
}
|
| 2473 |
+
Vectorized<T> tanh() const {
|
| 2474 |
+
return mapOrdinary(std::tanh);
|
| 2475 |
+
}
|
| 2476 |
+
Vectorized<T> trunc() const {
|
| 2477 |
+
return Vectorized<T>{_vec.trunc()};
|
| 2478 |
+
}
|
| 2479 |
+
|
| 2480 |
+
Vectorized<T> C10_ALWAYS_INLINE operator&(const Vectorized<T>& other) const {
|
| 2481 |
+
return Vectorized<T>{_vec & other._vec};
|
| 2482 |
+
}
|
| 2483 |
+
|
| 2484 |
+
Vectorized<T> C10_ALWAYS_INLINE operator|(const Vectorized<T>& other) const {
|
| 2485 |
+
return Vectorized<T>{_vec | other._vec};
|
| 2486 |
+
}
|
| 2487 |
+
|
| 2488 |
+
Vectorized<T> C10_ALWAYS_INLINE operator^(const Vectorized<T>& other) const {
|
| 2489 |
+
return Vectorized<T>{_vec ^ other._vec};
|
| 2490 |
+
}
|
| 2491 |
+
Vectorized<T> C10_ALWAYS_INLINE operator==(const Vectorized<T>& other) const {
|
| 2492 |
+
return Vectorized<T>{_vec == other._vec};
|
| 2493 |
+
}
|
| 2494 |
+
|
| 2495 |
+
Vectorized<T> C10_ALWAYS_INLINE operator!=(const Vectorized<T>& other) const {
|
| 2496 |
+
return Vectorized<T>{_vec != other._vec};
|
| 2497 |
+
}
|
| 2498 |
+
|
| 2499 |
+
Vectorized<T> C10_ALWAYS_INLINE eq(const Vectorized<T>& other) const {
|
| 2500 |
+
auto eq = _vec.eq(other._vec); // compares real and imag individually
|
| 2501 |
+
// If both real numbers and imag numbers are equal, then the complex numbers are equal
|
| 2502 |
+
auto real = eq & vinner_type(real_mask<underline_type>());
|
| 2503 |
+
auto imag = (eq & vinner_type(image_mask<underline_type>())).swapped();
|
| 2504 |
+
return Vectorized<T>{real & imag};
|
| 2505 |
+
}
|
| 2506 |
+
Vectorized<T> C10_ALWAYS_INLINE ne(const Vectorized<T>& other) const {
|
| 2507 |
+
auto ne = _vec.ne(other._vec); // compares real and imag individually
|
| 2508 |
+
// If either real numbers or imag numbers are not equal, then the complex numbers are not equal
|
| 2509 |
+
auto real = ne & vinner_type(real_mask<underline_type>());
|
| 2510 |
+
auto imag = (ne & vinner_type(image_mask<underline_type>())).swapped();
|
| 2511 |
+
return Vectorized<T>{real | imag};
|
| 2512 |
+
}
|
| 2513 |
+
|
| 2514 |
+
Vectorized<T> real() const {
|
| 2515 |
+
return Vectorized<T>(_vec & vinner_type(real_mask<underline_type>()));
|
| 2516 |
+
}
|
| 2517 |
+
Vectorized<T> imag_() const {
|
| 2518 |
+
return Vectorized<T>(_vec & vinner_type(image_mask<underline_type>()));
|
| 2519 |
+
}
|
| 2520 |
+
Vectorized<T> imag() const {
|
| 2521 |
+
return Vectorized<T>{
|
| 2522 |
+
(_vec & vinner_type(image_mask<underline_type>())).swapped()};
|
| 2523 |
+
}
|
| 2524 |
+
|
| 2525 |
+
Vectorized<T> conj() const {
|
| 2526 |
+
return Vectorized<T>(_vec ^ vinner_type(isign_mask<underline_type>()));
|
| 2527 |
+
}
|
| 2528 |
+
|
| 2529 |
+
vinner_data abs_2_() const {
|
| 2530 |
+
auto a = _vec * _vec;
|
| 2531 |
+
a = a + a.swapped();
|
| 2532 |
+
return a.mergee().data();
|
| 2533 |
+
}
|
| 2534 |
+
|
| 2535 |
+
static T abs_helper(const T &value)
|
| 2536 |
+
{
|
| 2537 |
+
return T(std::abs(value));
|
| 2538 |
+
}
|
| 2539 |
+
|
| 2540 |
+
Vectorized<T> abs() const {
|
| 2541 |
+
return mapOrdinary(abs_helper);
|
| 2542 |
+
}
|
| 2543 |
+
|
| 2544 |
+
Vectorized<T> exp() const {
|
| 2545 |
+
return mapOrdinary(std::exp);
|
| 2546 |
+
}
|
| 2547 |
+
|
| 2548 |
+
Vectorized<T> exp2() const {
|
| 2549 |
+
return mapOrdinary(exp2_impl);
|
| 2550 |
+
}
|
| 2551 |
+
|
| 2552 |
+
Vectorized<T> expm1() const {
|
| 2553 |
+
return mapOrdinary(std::expm1);
|
| 2554 |
+
}
|
| 2555 |
+
|
| 2556 |
+
Vectorized<T> log() const {
|
| 2557 |
+
return mapOrdinary(std::log);
|
| 2558 |
+
}
|
| 2559 |
+
|
| 2560 |
+
Vectorized<T> log2() const {
|
| 2561 |
+
// log2eB_inv
|
| 2562 |
+
auto ret = log();
|
| 2563 |
+
return Vectorized<T>{ret._vec * vinner_type(log2e_inv<underline_type>())};
|
| 2564 |
+
}
|
| 2565 |
+
|
| 2566 |
+
Vectorized<T> log10() const {
|
| 2567 |
+
auto ret = log();
|
| 2568 |
+
return Vectorized<T>{ret._vec * vinner_type(log10e_inv<underline_type>())};
|
| 2569 |
+
}
|
| 2570 |
+
|
| 2571 |
+
Vectorized<T> log1p() const {
|
| 2572 |
+
return mapOrdinary(std::log1p);
|
| 2573 |
+
}
|
| 2574 |
+
|
| 2575 |
+
Vectorized<T> sgn() const {
|
| 2576 |
+
return mapOrdinary(at::native::sgn_impl);
|
| 2577 |
+
}
|
| 2578 |
+
|
| 2579 |
+
Vectorized<T> pow(const Vectorized<T>& exp) const {
|
| 2580 |
+
return mapOrdinary(std::pow, exp);
|
| 2581 |
+
}
|
| 2582 |
+
|
| 2583 |
+
Vectorized<T> sqrt() const {
|
| 2584 |
+
return mapOrdinary(std::sqrt);
|
| 2585 |
+
}
|
| 2586 |
+
|
| 2587 |
+
Vectorized<T> reciprocal() const {
|
| 2588 |
+
// re + im*i = (a + bi) / (c + di)
|
| 2589 |
+
// re = (ac + bd)/abs_2() = c/abs_2()
|
| 2590 |
+
// im = (bc - ad)/abs_2() = d/abs_2()
|
| 2591 |
+
vinner_type c_d = _vec ^ vinner_type(isign_mask<underline_type>());
|
| 2592 |
+
vinner_type abs = abs_2_();
|
| 2593 |
+
return Vectorized<T>{c_d / abs};
|
| 2594 |
+
}
|
| 2595 |
+
|
| 2596 |
+
Vectorized<T> rsqrt() const {
|
| 2597 |
+
return sqrt().reciprocal();
|
| 2598 |
+
}
|
| 2599 |
+
|
| 2600 |
+
Vectorized<T> operator<(const Vectorized<T>& other) const {
|
| 2601 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 2602 |
+
}
|
| 2603 |
+
|
| 2604 |
+
Vectorized<T> operator<=(const Vectorized<T>& other) const {
|
| 2605 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 2606 |
+
}
|
| 2607 |
+
|
| 2608 |
+
Vectorized<T> operator>(const Vectorized<T>& other) const {
|
| 2609 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 2610 |
+
}
|
| 2611 |
+
|
| 2612 |
+
Vectorized<T> operator>=(const Vectorized<T>& other) const {
|
| 2613 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 2614 |
+
}
|
| 2615 |
+
|
| 2616 |
+
Vectorized<T> lt(const Vectorized<T>& other) const {
|
| 2617 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 2618 |
+
}
|
| 2619 |
+
|
| 2620 |
+
Vectorized<T> le(const Vectorized<T>& other) const {
|
| 2621 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 2622 |
+
}
|
| 2623 |
+
|
| 2624 |
+
Vectorized<T> gt(const Vectorized<T>& other) const {
|
| 2625 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 2626 |
+
}
|
| 2627 |
+
|
| 2628 |
+
Vectorized<T> ge(const Vectorized<T>& other) const {
|
| 2629 |
+
TORCH_CHECK(false, "not supported for complex numbers");
|
| 2630 |
+
}
|
| 2631 |
+
};
|
| 2632 |
+
|
| 2633 |
+
template <typename T, std::enable_if_t<(sizeof(T) == 8), int> = 0>
|
| 2634 |
+
std::pair<Vectorized<T>, Vectorized<T>> inline inner_interleave2(
|
| 2635 |
+
const Vectorized<T>& a,
|
| 2636 |
+
const Vectorized<T>& b) {
|
| 2637 |
+
// inputs:
|
| 2638 |
+
// a = {a0, a1, a2, a3}
|
| 2639 |
+
// b = {b0, b1, b2, b3}
|
| 2640 |
+
using vtype = typename Vectorized<T>::vtype;
|
| 2641 |
+
vtype ab00 = vec_permi(a.vec0(), b.vec0(), 0);
|
| 2642 |
+
vtype ab11 = vec_permi(a.vec0(), b.vec0(), 3);
|
| 2643 |
+
vtype ab2_00 = vec_permi(a.vec1(), b.vec1(), 0);
|
| 2644 |
+
vtype ab2_11 = vec_permi(a.vec1(), b.vec1(), 3);
|
| 2645 |
+
// return {a0, b0, a1, b1}
|
| 2646 |
+
// {a2, b2, a3, b3}
|
| 2647 |
+
return std::make_pair(
|
| 2648 |
+
Vectorized<T>{ab00, ab11}, Vectorized<T>{ab2_00, ab2_11});
|
| 2649 |
+
}
|
| 2650 |
+
|
| 2651 |
+
template <typename T, std::enable_if_t<(sizeof(T) == 8), int> = 0>
|
| 2652 |
+
std::pair<Vectorized<T>, Vectorized<T>> inline inner_deinterleave2(
|
| 2653 |
+
const Vectorized<T>& a,
|
| 2654 |
+
const Vectorized<T>& b) {
|
| 2655 |
+
// inputs:
|
| 2656 |
+
// a = {a0, b0, a1, b1}
|
| 2657 |
+
// b = {a2, b2, a3, b3}
|
| 2658 |
+
using vtype = typename Vectorized<T>::vtype;
|
| 2659 |
+
vtype aa01 = vec_permi(a.vec0(), a.vec1(), 0);
|
| 2660 |
+
vtype aa23 = vec_permi(b.vec0(), b.vec1(), 0);
|
| 2661 |
+
|
| 2662 |
+
vtype bb_01 = vec_permi(a.vec0(), a.vec1(), 3);
|
| 2663 |
+
vtype bb_23 = vec_permi(b.vec0(), b.vec1(), 3);
|
| 2664 |
+
|
| 2665 |
+
// swap lanes:
|
| 2666 |
+
// return {a0, a1, a2, a3}
|
| 2667 |
+
// {b0, b1, b2, b3}
|
| 2668 |
+
return std::make_pair(Vectorized<T>{aa01, aa23}, Vectorized<T>{bb_01, bb_23});
|
| 2669 |
+
}
|
| 2670 |
+
|
| 2671 |
+
template <typename T, std::enable_if_t<(sizeof(T) == 4), int> = 0>
|
| 2672 |
+
std::pair<Vectorized<T>, Vectorized<T>> inline inner_interleave2(
|
| 2673 |
+
const Vectorized<T>& a,
|
| 2674 |
+
const Vectorized<T>& b) {
|
| 2675 |
+
// inputs:
|
| 2676 |
+
// a = {a0, a1, a2, a3,, a4, a5, a6, a7}
|
| 2677 |
+
// b = {b0, b1, b2, b3,, b4, b5, b6, b7}
|
| 2678 |
+
using vtype = typename Vectorized<T>::vtype;
|
| 2679 |
+
vtype ab0011 = vec_mergeh(a.vec0(), b.vec0());
|
| 2680 |
+
vtype ab2233 = vec_mergel(a.vec0(), b.vec0());
|
| 2681 |
+
|
| 2682 |
+
vtype ab2_0011 = vec_mergeh(a.vec1(), b.vec1());
|
| 2683 |
+
vtype ab2_2233 = vec_mergel(a.vec1(), b.vec1());
|
| 2684 |
+
// group cols crossing lanes:
|
| 2685 |
+
// return {a0, b0, a1, b1,, a2, b2, a3, b3}
|
| 2686 |
+
// {a4, b4, a5, b5,, a6, b6, a7, b7}
|
| 2687 |
+
|
| 2688 |
+
return std::make_pair(
|
| 2689 |
+
Vectorized<T>{ab0011, ab2233}, Vectorized<T>{ab2_0011, ab2_2233});
|
| 2690 |
+
}
|
| 2691 |
+
|
| 2692 |
+
template <typename T, std::enable_if_t<(sizeof(T) == 4), int> = 0>
|
| 2693 |
+
std::pair<Vectorized<T>, Vectorized<T>> inline inner_deinterleave2(
|
| 2694 |
+
const Vectorized<T>& a,
|
| 2695 |
+
const Vectorized<T>& b) {
|
| 2696 |
+
// inputs:
|
| 2697 |
+
// a = {a0, b0, a1, b1,, a2, b2, a3, b3}
|
| 2698 |
+
// b = {a4, b4, a5, b5,, a6, b6, a7, b7}
|
| 2699 |
+
using vtype = typename Vectorized<T>::vtype;
|
| 2700 |
+
// {a0,a2,b0,b2} {a1,a3,b1,b3}
|
| 2701 |
+
vtype a0a2b0b2 = vec_mergeh(a.vec0(), a.vec1());
|
| 2702 |
+
vtype a1a3b1b3 = vec_mergel(a.vec0(), a.vec1());
|
| 2703 |
+
|
| 2704 |
+
vtype aa0123 = vec_mergeh(a0a2b0b2, a1a3b1b3);
|
| 2705 |
+
vtype bb0123 = vec_mergel(a0a2b0b2, a1a3b1b3);
|
| 2706 |
+
|
| 2707 |
+
vtype a0a2b0b2_2 = vec_mergeh(b.vec0(), b.vec1());
|
| 2708 |
+
vtype a1a3b1b3_2 = vec_mergel(b.vec0(), b.vec1());
|
| 2709 |
+
|
| 2710 |
+
vtype aa0123_2 = vec_mergeh(a0a2b0b2_2, a1a3b1b3_2);
|
| 2711 |
+
vtype bb0123_2 = vec_mergel(a0a2b0b2_2, a1a3b1b3_2);
|
| 2712 |
+
|
| 2713 |
+
// it could be done with vec_perm ,too
|
| 2714 |
+
// swap lanes:
|
| 2715 |
+
// return {a0, a1, a2, a3,, a4, a5, a6, a7}
|
| 2716 |
+
// {b0, b1, b2, b3,, b4, b5, b6, b7}
|
| 2717 |
+
|
| 2718 |
+
return std::make_pair(
|
| 2719 |
+
Vectorized<T>{aa0123, aa0123_2}, Vectorized<T>{bb0123, bb0123_2});
|
| 2720 |
+
}
|
| 2721 |
+
|
| 2722 |
+
template <>
|
| 2723 |
+
std::pair<Vectorized<float>, Vectorized<float>> inline interleave2<float>(
|
| 2724 |
+
const Vectorized<float>& a,
|
| 2725 |
+
const Vectorized<float>& b) {
|
| 2726 |
+
return inner_interleave2<float>(a, b);
|
| 2727 |
+
}
|
| 2728 |
+
|
| 2729 |
+
template <>
|
| 2730 |
+
std::pair<Vectorized<int32_t>, Vectorized<int32_t>> inline interleave2<int32_t>(
|
| 2731 |
+
const Vectorized<int32_t>& a,
|
| 2732 |
+
const Vectorized<int32_t>& b) {
|
| 2733 |
+
return inner_interleave2<int32_t>(a, b);
|
| 2734 |
+
}
|
| 2735 |
+
|
| 2736 |
+
template <>
|
| 2737 |
+
std::pair<Vectorized<double>, Vectorized<double>> inline interleave2<double>(
|
| 2738 |
+
const Vectorized<double>& a,
|
| 2739 |
+
const Vectorized<double>& b) {
|
| 2740 |
+
return inner_interleave2<double>(a, b);
|
| 2741 |
+
}
|
| 2742 |
+
|
| 2743 |
+
template <>
|
| 2744 |
+
std::pair<Vectorized<int64_t>, Vectorized<int64_t>> inline interleave2<int64_t>(
|
| 2745 |
+
const Vectorized<int64_t>& a,
|
| 2746 |
+
const Vectorized<int64_t>& b) {
|
| 2747 |
+
return inner_interleave2<int64_t>(a, b);
|
| 2748 |
+
}
|
| 2749 |
+
|
| 2750 |
+
template <>
|
| 2751 |
+
std::pair<Vectorized<float>, Vectorized<float>> inline deinterleave2<float>(
|
| 2752 |
+
const Vectorized<float>& a,
|
| 2753 |
+
const Vectorized<float>& b) {
|
| 2754 |
+
return inner_deinterleave2<float>(a, b);
|
| 2755 |
+
}
|
| 2756 |
+
|
| 2757 |
+
template <>
|
| 2758 |
+
std::pair<Vectorized<int32_t>, Vectorized<int32_t>> inline deinterleave2<
|
| 2759 |
+
int32_t>(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 2760 |
+
return inner_deinterleave2<int32_t>(a, b);
|
| 2761 |
+
}
|
| 2762 |
+
|
| 2763 |
+
template <>
|
| 2764 |
+
std::pair<Vectorized<double>, Vectorized<double>> inline deinterleave2<double>(
|
| 2765 |
+
const Vectorized<double>& a,
|
| 2766 |
+
const Vectorized<double>& b) {
|
| 2767 |
+
return inner_deinterleave2<double>(a, b);
|
| 2768 |
+
}
|
| 2769 |
+
|
| 2770 |
+
template <>
|
| 2771 |
+
std::pair<Vectorized<int64_t>, Vectorized<int64_t>> inline deinterleave2<
|
| 2772 |
+
int64_t>(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 2773 |
+
return inner_deinterleave2<int64_t>(a, b);
|
| 2774 |
+
}
|
| 2775 |
+
|
| 2776 |
+
inline Vectorized<float> convert_uint8_to_float(const Vectorized<uint8_t> &src) {
|
| 2777 |
+
// Note: this function only convert inputs number of elements equal to at::vec::Vectorized<float>.size()
|
| 2778 |
+
// Only handle first 64 bits
|
| 2779 |
+
auto vec_int = src.to_vec_float_helper();
|
| 2780 |
+
|
| 2781 |
+
return convert_to_float(vec_int);
|
| 2782 |
+
}
|
| 2783 |
+
|
| 2784 |
+
inline Vectorized<uint8_t> convert_float_to_uint8(const Vectorized<float> &src) {
|
| 2785 |
+
constexpr auto min_val = std::numeric_limits<uint8_t>::min();
|
| 2786 |
+
constexpr auto max_val = std::numeric_limits<uint8_t>::max();
|
| 2787 |
+
|
| 2788 |
+
auto vec_int = clamp(convert_to_int(src), Vectorized<int32_t>(min_val), Vectorized<int32_t>(max_val));
|
| 2789 |
+
|
| 2790 |
+
return vec_int.to_vec_uint8_helper();
|
| 2791 |
+
}
|
| 2792 |
+
|
| 2793 |
+
#undef DEFINE_CLAMP_MAXMIN_FUNCS
|
| 2794 |
+
#undef DEFINE_MAXMIN_FUNCS
|
| 2795 |
+
} // namespace
|
| 2796 |
+
} // namespace vec
|
| 2797 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec512/vec512.h
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// DO NOT DEFINE STATIC DATA IN THIS HEADER!
|
| 4 |
+
// See Note [Do not compile initializers with AVX]
|
| 5 |
+
|
| 6 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 7 |
+
|
| 8 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 9 |
+
#include <ATen/cpu/vec/vec512/vec512_float.h>
|
| 10 |
+
#include <ATen/cpu/vec/vec512/vec512_bfloat16.h>
|
| 11 |
+
#include <ATen/cpu/vec/vec512/vec512_double.h>
|
| 12 |
+
#include <ATen/cpu/vec/vec512/vec512_int.h>
|
| 13 |
+
#include <ATen/cpu/vec/vec512/vec512_qint.h>
|
| 14 |
+
#include <ATen/cpu/vec/vec512/vec512_complex_float.h>
|
| 15 |
+
#include <ATen/cpu/vec/vec512/vec512_complex_double.h>
|
| 16 |
+
|
| 17 |
+
#include <algorithm>
|
| 18 |
+
#include <cstddef>
|
| 19 |
+
#include <cstdint>
|
| 20 |
+
#include <cstring>
|
| 21 |
+
#include <ostream>
|
| 22 |
+
|
| 23 |
+
namespace at {
|
| 24 |
+
namespace vec {
|
| 25 |
+
|
| 26 |
+
// See Note [CPU_CAPABILITY namespace]
|
| 27 |
+
inline namespace CPU_CAPABILITY {
|
| 28 |
+
|
| 29 |
+
inline std::ostream& operator<<(std::ostream& stream, const c10::qint32& val) {
|
| 30 |
+
stream << val.val_;
|
| 31 |
+
return stream;
|
| 32 |
+
}
|
| 33 |
+
inline std::ostream& operator<<(std::ostream& stream, const c10::qint8& val) {
|
| 34 |
+
stream << static_cast<int>(val.val_);
|
| 35 |
+
return stream;
|
| 36 |
+
}
|
| 37 |
+
inline std::ostream& operator<<(std::ostream& stream, const c10::quint8& val) {
|
| 38 |
+
stream << static_cast<unsigned int>(val.val_);
|
| 39 |
+
return stream;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
template <typename T>
|
| 43 |
+
std::ostream& operator<<(std::ostream& stream, const Vectorized<T>& vec) {
|
| 44 |
+
T buf[Vectorized<T>::size()];
|
| 45 |
+
vec.store(buf);
|
| 46 |
+
stream << "vec[";
|
| 47 |
+
for (int i = 0; i != Vectorized<T>::size(); i++) {
|
| 48 |
+
if (i != 0) {
|
| 49 |
+
stream << ", ";
|
| 50 |
+
}
|
| 51 |
+
stream << buf[i];
|
| 52 |
+
}
|
| 53 |
+
stream << "]";
|
| 54 |
+
return stream;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
#if defined(CPU_CAPABILITY_AVX512) && !defined(_MSC_VER)
|
| 59 |
+
|
| 60 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CAST (AVX512) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 61 |
+
|
| 62 |
+
template<>
|
| 63 |
+
inline Vectorized<float> cast<float, double>(const Vectorized<double>& src) {
|
| 64 |
+
return _mm512_castpd_ps(src);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
template<>
|
| 68 |
+
inline Vectorized<double> cast<double, float>(const Vectorized<float>& src) {
|
| 69 |
+
return _mm512_castps_pd(src);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
template<>
|
| 73 |
+
inline Vectorized<float> cast<float, int32_t>(const Vectorized<int32_t>& src) {
|
| 74 |
+
return _mm512_castsi512_ps(src);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
template<>
|
| 78 |
+
inline Vectorized<double> cast<double, int64_t>(const Vectorized<int64_t>& src) {
|
| 79 |
+
return _mm512_castsi512_pd(src);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GATHER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 83 |
+
|
| 84 |
+
template<int64_t scale = 1>
|
| 85 |
+
std::enable_if_t<scale == 1 || scale == 2 || scale == 4 || scale == 8, Vectorized<double>>
|
| 86 |
+
inline gather(const double* base_addr, const Vectorized<int64_t>& vindex) {
|
| 87 |
+
return _mm512_i64gather_pd(vindex, base_addr, scale);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
template<int64_t scale = 1>
|
| 91 |
+
std::enable_if_t<scale == 1 || scale == 2 || scale == 4 || scale == 8, Vectorized<float>>
|
| 92 |
+
inline gather(const float* base_addr, const Vectorized<int32_t>& vindex) {
|
| 93 |
+
return _mm512_i32gather_ps(vindex, base_addr, scale);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MASK GATHER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 97 |
+
|
| 98 |
+
template<int64_t scale = 1>
|
| 99 |
+
std::enable_if_t<scale == 1 || scale == 2 || scale == 4 || scale == 8, Vectorized<double>>
|
| 100 |
+
inline mask_gather(const Vectorized<double>& src, const double* base_addr,
|
| 101 |
+
const Vectorized<int64_t>& vindex, Vectorized<double>& mask) {
|
| 102 |
+
auto all_ones = _mm512_castsi512_pd(_mm512_set1_epi64(0xFFFFFFFFFFFFFFFF));
|
| 103 |
+
auto mask_ = _mm512_cmp_pd_mask(all_ones, mask.values, _CMP_EQ_OQ);
|
| 104 |
+
return _mm512_mask_i64gather_pd(src, mask_, vindex, base_addr, scale);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
template<int64_t scale = 1>
|
| 108 |
+
std::enable_if_t<scale == 1 || scale == 2 || scale == 4 || scale == 8, Vectorized<float>>
|
| 109 |
+
inline mask_gather(const Vectorized<float>& src, const float* base_addr,
|
| 110 |
+
const Vectorized<int32_t>& vindex, Vectorized<float>& mask) {
|
| 111 |
+
auto all_ones = _mm512_castsi512_ps(_mm512_set1_epi32(0xFFFFFFFF));
|
| 112 |
+
auto mask_ = _mm512_cmp_ps_mask(all_ones, mask.values, _CMP_EQ_OQ);
|
| 113 |
+
return _mm512_mask_i32gather_ps(src, mask_, vindex, base_addr, scale);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONVERT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 117 |
+
|
| 118 |
+
template<>
|
| 119 |
+
Vectorized<int64_t>
|
| 120 |
+
inline convert_to_int_of_same_size<double>(const Vectorized<double> &src) {
|
| 121 |
+
return _mm512_cvtpd_epi64(src);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
template<>
|
| 125 |
+
Vectorized<int32_t>
|
| 126 |
+
inline convert_to_int_of_same_size<float>(const Vectorized<float> &src) {
|
| 127 |
+
return _mm512_cvttps_epi32(src);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTERLEAVE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 131 |
+
|
| 132 |
+
template <>
|
| 133 |
+
std::pair<Vectorized<double>, Vectorized<double>>
|
| 134 |
+
inline interleave2<double>(const Vectorized<double>& a, const Vectorized<double>& b) {
|
| 135 |
+
// inputs:
|
| 136 |
+
// a = {a0, a1, a3, a3, a4, a5, a6, a7}
|
| 137 |
+
// b = {b0, b1, b2, b3, b4, b5, b6, b7}
|
| 138 |
+
// group cols crossing lanes:
|
| 139 |
+
// return {a0, b0, a1, b1, a2, b2, a3, b3}
|
| 140 |
+
// {a4, b4, a5, b5, a6, b6, a7, b7}
|
| 141 |
+
__m512i idx1 = _mm512_set_epi64(11, 3, 10, 2, 9, 1, 8, 0);
|
| 142 |
+
__m512i idx2 = _mm512_set_epi64(15, 7, 14, 6, 13, 5, 12, 4);
|
| 143 |
+
return std::make_pair(_mm512_mask_permutex2var_pd(a, 0xff, idx1, b),
|
| 144 |
+
_mm512_mask_permutex2var_pd(a, 0xff, idx2, b));
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
template <>
|
| 148 |
+
std::pair<Vectorized<float>, Vectorized<float>>
|
| 149 |
+
inline interleave2<float>(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 150 |
+
// inputs:
|
| 151 |
+
// a = {a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15}
|
| 152 |
+
// b = {b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15}
|
| 153 |
+
//
|
| 154 |
+
// return:
|
| 155 |
+
// {a0, b0, a1, b1, a2, b2, a3, b3, a4, b4, a5, b5, a6, b6, a7, b7}
|
| 156 |
+
// {a8, b8, a9, b9, a10, b10, a11, b11, a12, b12, a13, b13, a14, b14, a15, b15}
|
| 157 |
+
__m512i idx1 = _mm512_set_epi32(23, 7, 22, 6, 21, 5, 20, 4,
|
| 158 |
+
19, 3, 18, 2, 17, 1, 16, 0);
|
| 159 |
+
__m512i idx2 = _mm512_set_epi32(31, 15, 30, 14, 29, 13, 28, 12,
|
| 160 |
+
27, 11, 26, 10, 25, 9, 24, 8);
|
| 161 |
+
return std::make_pair(_mm512_mask_permutex2var_ps(a, 0xffff, idx1, b),
|
| 162 |
+
_mm512_mask_permutex2var_ps(a, 0xffff, idx2, b));
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DEINTERLEAVE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 166 |
+
|
| 167 |
+
template <>
|
| 168 |
+
std::pair<Vectorized<double>, Vectorized<double>>
|
| 169 |
+
inline deinterleave2<double>(const Vectorized<double>& a, const Vectorized<double>& b) {
|
| 170 |
+
// inputs:
|
| 171 |
+
// a = {a0, b0, a1, b1, a2, b2, a3, b3}
|
| 172 |
+
// b = {a4, b4, a5, b5, a6, b6, a7, b7}
|
| 173 |
+
// output:
|
| 174 |
+
// return {a0, a1, a2, a3, a4, a5, a6, a7}
|
| 175 |
+
// {b0, b1, b2, b3, b4, b5, b6, b7}
|
| 176 |
+
// The members of indices have been written in binary format for better understandability
|
| 177 |
+
__m512i idx1 = _mm512_set_epi64(14, 12, 10, 8, 6, 4, 2, 0);
|
| 178 |
+
__m512i idx2 = _mm512_set_epi64(15, 13, 11, 9, 7, 5, 3, 1);
|
| 179 |
+
|
| 180 |
+
return std::make_pair(_mm512_mask_permutex2var_pd(a, 0xff, idx1, b),
|
| 181 |
+
_mm512_mask_permutex2var_pd(a, 0xff, idx2, b));
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
template <>
|
| 185 |
+
std::pair<Vectorized<float>, Vectorized<float>>
|
| 186 |
+
inline deinterleave2<float>(const Vectorized<float>& a, const Vectorized<float>& b) {
|
| 187 |
+
// inputs:
|
| 188 |
+
// a = {a0, b0, a1, b1, a2, b2, a3, b3, a4, b4, a5, b5, a6, b6, a7, b7}
|
| 189 |
+
// b = {a8, b8, a9, b9, a10, b10, a11, b11, a12, b12, a13, b13, a14, b14, a15, b15}
|
| 190 |
+
// output:
|
| 191 |
+
// return {a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15}
|
| 192 |
+
// {b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15}
|
| 193 |
+
__m512i idx1 = _mm512_set_epi32(30, 28, 26, 24, 22, 20, 18, 16,
|
| 194 |
+
14, 12, 10, 8, 6, 4, 2, 0);
|
| 195 |
+
__m512i idx2 = _mm512_set_epi32(31, 29, 27, 25, 23, 21, 19, 17,
|
| 196 |
+
15, 13, 11, 9, 7, 5, 3, 1);
|
| 197 |
+
|
| 198 |
+
return std::make_pair(_mm512_mask_permutex2var_ps(a, 0xffff, idx1, b),
|
| 199 |
+
_mm512_mask_permutex2var_ps(a, 0xffff, idx2, b));
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FLIP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 203 |
+
|
| 204 |
+
template<>
|
| 205 |
+
inline Vectorized<float> flip(const Vectorized<float> & v) {
|
| 206 |
+
const __m512i mask = _mm512_set_epi32(0, 1, 2, 3, 4, 5, 6, 7,
|
| 207 |
+
8, 9, 10, 11, 12, 13, 14, 15);
|
| 208 |
+
return _mm512_permutexvar_ps(mask, v);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
template<>
|
| 212 |
+
inline Vectorized<double> flip(const Vectorized<double> & v) {
|
| 213 |
+
const __m512i mask = _mm512_set_epi64(0, 1, 2, 3, 4, 5, 6, 7);
|
| 214 |
+
return _mm512_permutexvar_pd(mask, v);
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
template<>
|
| 218 |
+
inline Vectorized<int64_t> flip(const Vectorized<int64_t> & v) {
|
| 219 |
+
const __m512i mask = _mm512_set_epi64(0, 1, 2, 3, 4, 5, 6, 7);
|
| 220 |
+
return _mm512_permutexvar_epi64(mask, v);
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
template<>
|
| 224 |
+
inline Vectorized<int32_t> flip(const Vectorized<int32_t> & v) {
|
| 225 |
+
const __m512i mask = _mm512_set_epi32(0, 1, 2, 3, 4, 5, 6, 7,
|
| 226 |
+
8, 9, 10, 11, 12, 13, 14, 15);
|
| 227 |
+
return _mm512_permutexvar_epi32(mask, v);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
template<>
|
| 231 |
+
inline Vectorized<int16_t> flip(const Vectorized<int16_t> & v) {
|
| 232 |
+
const __m512i mask = _mm512_set_epi16(
|
| 233 |
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
| 234 |
+
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
|
| 235 |
+
);
|
| 236 |
+
return _mm512_permutexvar_epi16(mask, v);
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
inline __m512i flip8(const __m512i & v) {
|
| 240 |
+
const __m512i mask1 = _mm512_set_epi8(
|
| 241 |
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
| 242 |
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
| 243 |
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
| 244 |
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
|
| 245 |
+
);
|
| 246 |
+
const __m512i mask2 = _mm512_set_epi64(1, 0, 3, 2, 5, 4, 7, 6);
|
| 247 |
+
auto reversed_vec = _mm512_shuffle_epi8(v, mask1);
|
| 248 |
+
return _mm512_permutexvar_epi64(mask2, reversed_vec);
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
template<>
|
| 252 |
+
inline Vectorized<int8_t> flip(const Vectorized<int8_t> & v) {
|
| 253 |
+
return flip8(v);
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
template<>
|
| 257 |
+
inline Vectorized<uint8_t> flip(const Vectorized<uint8_t> & v) {
|
| 258 |
+
return flip8(v);
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
#endif // defined(CPU_CAPABILITY_AVX512) && !defined(_MSC_VER)
|
| 262 |
+
|
| 263 |
+
}}}
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/cpu/vec/vec512/vec512_int.h
ADDED
|
@@ -0,0 +1,1448 @@
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// DO NOT DEFINE STATIC DATA IN THIS HEADER!
|
| 4 |
+
// See Note [Do not compile initializers with AVX]
|
| 5 |
+
|
| 6 |
+
#include <ATen/cpu/vec/intrinsics.h>
|
| 7 |
+
#include <ATen/cpu/vec/vec_base.h>
|
| 8 |
+
#include <c10/macros/Macros.h>
|
| 9 |
+
#include <c10/util/irange.h>
|
| 10 |
+
|
| 11 |
+
namespace at {
|
| 12 |
+
namespace vec {
|
| 13 |
+
inline namespace CPU_CAPABILITY {
|
| 14 |
+
|
| 15 |
+
#ifdef CPU_CAPABILITY_AVX512
|
| 16 |
+
|
| 17 |
+
struct Vectorizedi {
|
| 18 |
+
protected:
|
| 19 |
+
__m512i values;
|
| 20 |
+
static constexpr __m512i zero_vector {0, 0, 0, 0, 0, 0, 0, 0};
|
| 21 |
+
static inline __m512i invert(const __m512i& v) {
|
| 22 |
+
const auto ones = _mm512_set1_epi64(-1);
|
| 23 |
+
return _mm512_xor_si512(ones, v);
|
| 24 |
+
}
|
| 25 |
+
public:
|
| 26 |
+
Vectorizedi() {}
|
| 27 |
+
Vectorizedi(__m512i v) : values(v) {}
|
| 28 |
+
operator __m512i() const {
|
| 29 |
+
return values;
|
| 30 |
+
}
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
#else
|
| 34 |
+
|
| 35 |
+
struct Vectorizedi {}; // dummy definition to make Vectorizedi always defined
|
| 36 |
+
|
| 37 |
+
#endif // CPU_CAPABILITY_AVX512
|
| 38 |
+
|
| 39 |
+
#ifdef CPU_CAPABILITY_AVX512
|
| 40 |
+
|
| 41 |
+
template <>
|
| 42 |
+
class Vectorized<int64_t> : public Vectorizedi {
|
| 43 |
+
private:
|
| 44 |
+
static const Vectorized<int64_t> ones;
|
| 45 |
+
public:
|
| 46 |
+
using value_type = int64_t;
|
| 47 |
+
using size_type = int;
|
| 48 |
+
static constexpr size_type size() {
|
| 49 |
+
return 8;
|
| 50 |
+
}
|
| 51 |
+
using Vectorizedi::Vectorizedi;
|
| 52 |
+
Vectorized() {}
|
| 53 |
+
Vectorized(int64_t v) { values = _mm512_set1_epi64(v); }
|
| 54 |
+
Vectorized(int64_t val1, int64_t val2, int64_t val3, int64_t val4,
|
| 55 |
+
int64_t val5, int64_t val6, int64_t val7, int64_t val8) {
|
| 56 |
+
values = _mm512_setr_epi64(val1, val2, val3, val4,
|
| 57 |
+
val5, val6, val7, val8);
|
| 58 |
+
}
|
| 59 |
+
template <int64_t mask>
|
| 60 |
+
static Vectorized<int64_t> blend(Vectorized<int64_t> a, Vectorized<int64_t> b) {
|
| 61 |
+
return _mm512_mask_blend_epi64(mask, a.values, b.values);
|
| 62 |
+
}
|
| 63 |
+
static Vectorized<int64_t> blendv(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b,
|
| 64 |
+
const Vectorized<int64_t>& mask) {
|
| 65 |
+
auto msb_one = _mm512_set1_epi64(0xFFFFFFFFFFFFFFFF);
|
| 66 |
+
auto mask_ = _mm512_cmp_epi64_mask(mask, msb_one, _MM_CMPINT_EQ);
|
| 67 |
+
return _mm512_mask_blend_epi64(mask_, a.values, b.values);
|
| 68 |
+
}
|
| 69 |
+
template <typename step_t>
|
| 70 |
+
static Vectorized<int64_t> arange(int64_t base = 0, step_t step = static_cast<step_t>(1)) {
|
| 71 |
+
return Vectorized<int64_t>(base, base + step, base + 2 * step, base + 3 * step,
|
| 72 |
+
base + 4 * step, base + 5 * step, base + 6 * step, base + 7 * step);
|
| 73 |
+
}
|
| 74 |
+
static Vectorized<int64_t>
|
| 75 |
+
set(Vectorized<int64_t> a, Vectorized<int64_t> b, int64_t count = size()) {
|
| 76 |
+
switch (count) {
|
| 77 |
+
case 0:
|
| 78 |
+
return a;
|
| 79 |
+
case 1:
|
| 80 |
+
return blend<1>(a, b);
|
| 81 |
+
case 2:
|
| 82 |
+
return blend<3>(a, b);
|
| 83 |
+
case 3:
|
| 84 |
+
return blend<7>(a, b);
|
| 85 |
+
case 4:
|
| 86 |
+
return blend<15>(a, b);
|
| 87 |
+
case 5:
|
| 88 |
+
return blend<31>(a, b);
|
| 89 |
+
case 6:
|
| 90 |
+
return blend<63>(a, b);
|
| 91 |
+
case 7:
|
| 92 |
+
return blend<127>(a, b);
|
| 93 |
+
}
|
| 94 |
+
return b;
|
| 95 |
+
}
|
| 96 |
+
static Vectorized<int64_t> loadu(const void* ptr) {
|
| 97 |
+
return _mm512_loadu_si512(reinterpret_cast<const __m512i*>(ptr));
|
| 98 |
+
}
|
| 99 |
+
static Vectorized<int64_t> loadu(const void* ptr, int64_t count) {
|
| 100 |
+
__at_align__ int64_t tmp_values[size()];
|
| 101 |
+
// Ensure uninitialized memory does not change the output value See https://github.com/pytorch/pytorch/issues/32502
|
| 102 |
+
// for more details. We do not initialize arrays to zero using "={0}" because gcc would compile it to two
|
| 103 |
+
// instructions while a loop would be compiled to one instruction.
|
| 104 |
+
for (const auto i : c10::irange(size())) {
|
| 105 |
+
tmp_values[i] = 0;
|
| 106 |
+
}
|
| 107 |
+
std::memcpy(tmp_values, ptr, count * sizeof(int64_t));
|
| 108 |
+
return loadu(tmp_values);
|
| 109 |
+
}
|
| 110 |
+
void store(void* ptr, int count = size()) const {
|
| 111 |
+
if (count == size()) {
|
| 112 |
+
// ptr need not to be aligned here. See
|
| 113 |
+
// https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/intrinsics/intrinsics-for-intel-advanced-vector-extensions/intrinsics-for-load-and-store-operations-1/mm512-storeu-si512.html
|
| 114 |
+
_mm512_storeu_si512(reinterpret_cast<__m512i*>(ptr), values);
|
| 115 |
+
} else if (count > 0) {
|
| 116 |
+
__at_align__ int64_t tmp_values[size()];
|
| 117 |
+
_mm512_storeu_si512(reinterpret_cast<__m512i*>(tmp_values), values);
|
| 118 |
+
std::memcpy(ptr, tmp_values, count * sizeof(int64_t));
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
const int64_t& operator[](int idx) const = delete;
|
| 122 |
+
int64_t& operator[](int idx) = delete;
|
| 123 |
+
Vectorized<int64_t> abs() const {
|
| 124 |
+
auto is_larger_mask = _mm512_cmpgt_epi64_mask(zero_vector, values);
|
| 125 |
+
auto is_larger = _mm512_mask_set1_epi64(zero_vector, is_larger_mask, 0xFFFFFFFFFFFFFFFF);
|
| 126 |
+
auto inverse = _mm512_xor_si512(values, is_larger);
|
| 127 |
+
return _mm512_sub_epi64(inverse, is_larger);
|
| 128 |
+
}
|
| 129 |
+
Vectorized<int64_t> real() const {
|
| 130 |
+
return *this;
|
| 131 |
+
}
|
| 132 |
+
Vectorized<int64_t> imag() const {
|
| 133 |
+
return _mm512_set1_epi64(0);
|
| 134 |
+
}
|
| 135 |
+
Vectorized<int64_t> conj() const {
|
| 136 |
+
return *this;
|
| 137 |
+
}
|
| 138 |
+
Vectorized<int64_t> neg() const;
|
| 139 |
+
Vectorized<int64_t> operator==(const Vectorized<int64_t>& other) const {
|
| 140 |
+
auto mask = _mm512_cmpeq_epi64_mask(values, other.values);
|
| 141 |
+
return _mm512_mask_set1_epi64(zero_vector, mask, 0xFFFFFFFFFFFFFFFF);
|
| 142 |
+
}
|
| 143 |
+
Vectorized<int64_t> operator!=(const Vectorized<int64_t>& other) const {
|
| 144 |
+
auto mask = _mm512_cmpneq_epi64_mask(values, other.values);
|
| 145 |
+
return _mm512_mask_set1_epi64(zero_vector, mask, 0xFFFFFFFFFFFFFFFF);
|
| 146 |
+
}
|
| 147 |
+
Vectorized<int64_t> operator<(const Vectorized<int64_t>& other) const {
|
| 148 |
+
auto mask = _mm512_cmplt_epi64_mask(values, other.values);
|
| 149 |
+
return _mm512_mask_set1_epi64(zero_vector, mask, 0xFFFFFFFFFFFFFFFF);
|
| 150 |
+
}
|
| 151 |
+
Vectorized<int64_t> operator<=(const Vectorized<int64_t>& other) const {
|
| 152 |
+
auto mask = _mm512_cmple_epi64_mask(values, other.values);
|
| 153 |
+
return _mm512_mask_set1_epi64(zero_vector, mask, 0xFFFFFFFFFFFFFFFF);
|
| 154 |
+
}
|
| 155 |
+
Vectorized<int64_t> operator>(const Vectorized<int64_t>& other) const {
|
| 156 |
+
auto mask = _mm512_cmpgt_epi64_mask(values, other.values);
|
| 157 |
+
return _mm512_mask_set1_epi64(zero_vector, mask, 0xFFFFFFFFFFFFFFFF);
|
| 158 |
+
}
|
| 159 |
+
Vectorized<int64_t> operator>=(const Vectorized<int64_t>& other) const {
|
| 160 |
+
auto mask = _mm512_cmpge_epi64_mask(values, other.values);
|
| 161 |
+
return _mm512_mask_set1_epi64(zero_vector, mask, 0xFFFFFFFFFFFFFFFF);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
Vectorized<int64_t> eq(const Vectorized<int64_t>& other) const;
|
| 165 |
+
Vectorized<int64_t> ne(const Vectorized<int64_t>& other) const;
|
| 166 |
+
Vectorized<int64_t> gt(const Vectorized<int64_t>& other) const;
|
| 167 |
+
Vectorized<int64_t> ge(const Vectorized<int64_t>& other) const;
|
| 168 |
+
Vectorized<int64_t> lt(const Vectorized<int64_t>& other) const;
|
| 169 |
+
Vectorized<int64_t> le(const Vectorized<int64_t>& other) const;
|
| 170 |
+
};
|
| 171 |
+
|
| 172 |
+
template <>
|
| 173 |
+
class Vectorized<int32_t> : public Vectorizedi {
|
| 174 |
+
private:
|
| 175 |
+
static constexpr __m512i zero_vector {0, 0, 0, 0, 0, 0, 0, 0};
|
| 176 |
+
static const Vectorized<int32_t> ones;
|
| 177 |
+
public:
|
| 178 |
+
using value_type = int32_t;
|
| 179 |
+
static constexpr int size() {
|
| 180 |
+
return 16;
|
| 181 |
+
}
|
| 182 |
+
using Vectorizedi::Vectorizedi;
|
| 183 |
+
Vectorized() {}
|
| 184 |
+
Vectorized(int32_t v) { values = _mm512_set1_epi32(v); }
|
| 185 |
+
Vectorized(int32_t val1, int32_t val2, int32_t val3, int32_t val4,
|
| 186 |
+
int32_t val5, int32_t val6, int32_t val7, int32_t val8,
|
| 187 |
+
int32_t val9, int32_t val10, int32_t val11, int32_t val12,
|
| 188 |
+
int32_t val13, int32_t val14, int32_t val15, int32_t val16) {
|
| 189 |
+
values = _mm512_setr_epi32(val1, val2, val3, val4, val5, val6, val7, val8,
|
| 190 |
+
val9, val10, val11, val12, val13, val14, val15, val16);
|
| 191 |
+
}
|
| 192 |
+
template <int64_t mask>
|
| 193 |
+
static Vectorized<int32_t> blend(Vectorized<int32_t> a, Vectorized<int32_t> b) {
|
| 194 |
+
return _mm512_mask_blend_epi32(mask, a.values, b.values);
|
| 195 |
+
}
|
| 196 |
+
static Vectorized<int32_t> blendv(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b,
|
| 197 |
+
const Vectorized<int32_t>& mask) {
|
| 198 |
+
auto msb_one = _mm512_set1_epi32(0xFFFFFFFF);
|
| 199 |
+
auto mask_ = _mm512_cmp_epi32_mask(mask, msb_one, _MM_CMPINT_EQ);
|
| 200 |
+
return _mm512_mask_blend_epi32(mask_, a.values, b.values);
|
| 201 |
+
}
|
| 202 |
+
template <typename step_t>
|
| 203 |
+
static Vectorized<int32_t> arange(int32_t base = 0, step_t step = static_cast<step_t>(1)) {
|
| 204 |
+
return Vectorized<int32_t>(
|
| 205 |
+
base, base + step, base + 2 * step, base + 3 * step,
|
| 206 |
+
base + 4 * step, base + 5 * step, base + 6 * step, base + 7 * step,
|
| 207 |
+
base + 8 * step, base + 9 * step, base + 10 * step, base + 11 * step,
|
| 208 |
+
base + 12 * step, base + 13 * step, base + 14 * step, base + 15 * step);
|
| 209 |
+
}
|
| 210 |
+
static Vectorized<int32_t>
|
| 211 |
+
set(Vectorized<int32_t> a, Vectorized<int32_t> b, int32_t count = size()) {
|
| 212 |
+
switch (count) {
|
| 213 |
+
case 0:
|
| 214 |
+
return a;
|
| 215 |
+
case 1:
|
| 216 |
+
return blend<1>(a, b);
|
| 217 |
+
case 2:
|
| 218 |
+
return blend<3>(a, b);
|
| 219 |
+
case 3:
|
| 220 |
+
return blend<7>(a, b);
|
| 221 |
+
case 4:
|
| 222 |
+
return blend<15>(a, b);
|
| 223 |
+
case 5:
|
| 224 |
+
return blend<31>(a, b);
|
| 225 |
+
case 6:
|
| 226 |
+
return blend<63>(a, b);
|
| 227 |
+
case 7:
|
| 228 |
+
return blend<127>(a, b);
|
| 229 |
+
case 8:
|
| 230 |
+
return blend<255>(a, b);
|
| 231 |
+
case 9:
|
| 232 |
+
return blend<511>(a, b);
|
| 233 |
+
case 10:
|
| 234 |
+
return blend<1023>(a, b);
|
| 235 |
+
case 11:
|
| 236 |
+
return blend<2047>(a, b);
|
| 237 |
+
case 12:
|
| 238 |
+
return blend<4095>(a, b);
|
| 239 |
+
case 13:
|
| 240 |
+
return blend<8191>(a, b);
|
| 241 |
+
case 14:
|
| 242 |
+
return blend<16383>(a, b);
|
| 243 |
+
case 15:
|
| 244 |
+
return blend<32767>(a, b);
|
| 245 |
+
}
|
| 246 |
+
return b;
|
| 247 |
+
}
|
| 248 |
+
static Vectorized<int32_t> loadu(const void* ptr) {
|
| 249 |
+
return _mm512_loadu_si512(reinterpret_cast<const __m512i*>(ptr));
|
| 250 |
+
}
|
| 251 |
+
static Vectorized<int32_t> loadu(const void* ptr, int32_t count) {
|
| 252 |
+
__at_align__ int32_t tmp_values[size()];
|
| 253 |
+
// Ensure uninitialized memory does not change the output value See https://github.com/pytorch/pytorch/issues/32502
|
| 254 |
+
// for more details. We do not initialize arrays to zero using "={0}" because gcc would compile it to two
|
| 255 |
+
// instructions while a loop would be compiled to one instruction.
|
| 256 |
+
for (const auto i : c10::irange(size())) {
|
| 257 |
+
tmp_values[i] = 0;
|
| 258 |
+
}
|
| 259 |
+
std::memcpy(tmp_values, ptr, count * sizeof(int32_t));
|
| 260 |
+
return loadu(tmp_values);
|
| 261 |
+
}
|
| 262 |
+
void store(void* ptr, int count = size()) const {
|
| 263 |
+
if (count == size()) {
|
| 264 |
+
// ptr need not to be aligned here. See
|
| 265 |
+
// https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/intrinsics/intrinsics-for-intel-advanced-vector-extensions/intrinsics-for-load-and-store-operations-1/mm512-storeu-si512.html
|
| 266 |
+
_mm512_storeu_si512(reinterpret_cast<__m512i*>(ptr), values);
|
| 267 |
+
} else if (count > 0) {
|
| 268 |
+
__at_align__ int32_t tmp_values[size()];
|
| 269 |
+
_mm512_storeu_si512(reinterpret_cast<__m512i*>(tmp_values), values);
|
| 270 |
+
std::memcpy(ptr, tmp_values, count * sizeof(int32_t));
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
const int32_t& operator[](int idx) const = delete;
|
| 274 |
+
int32_t& operator[](int idx) = delete;
|
| 275 |
+
Vectorized<int32_t> abs() const {
|
| 276 |
+
return _mm512_abs_epi32(values);
|
| 277 |
+
}
|
| 278 |
+
Vectorized<int32_t> real() const {
|
| 279 |
+
return *this;
|
| 280 |
+
}
|
| 281 |
+
Vectorized<int32_t> imag() const {
|
| 282 |
+
return _mm512_set1_epi32(0);
|
| 283 |
+
}
|
| 284 |
+
Vectorized<int32_t> conj() const {
|
| 285 |
+
return *this;
|
| 286 |
+
}
|
| 287 |
+
Vectorized<int32_t> neg() const;
|
| 288 |
+
Vectorized<int32_t> operator==(const Vectorized<int32_t>& other) const {
|
| 289 |
+
auto mask = _mm512_cmpeq_epi32_mask(values, other.values);
|
| 290 |
+
return _mm512_mask_set1_epi32(zero_vector, mask, 0xFFFFFFFF);
|
| 291 |
+
}
|
| 292 |
+
Vectorized<int32_t> operator!=(const Vectorized<int32_t>& other) const {
|
| 293 |
+
auto mask = _mm512_cmpneq_epi32_mask(values, other.values);
|
| 294 |
+
return _mm512_mask_set1_epi32(zero_vector, mask, 0xFFFFFFFF);
|
| 295 |
+
}
|
| 296 |
+
Vectorized<int32_t> operator<(const Vectorized<int32_t>& other) const {
|
| 297 |
+
auto mask = _mm512_cmplt_epi32_mask(values, other.values);
|
| 298 |
+
return _mm512_mask_set1_epi32(zero_vector, mask, 0xFFFFFFFF);
|
| 299 |
+
}
|
| 300 |
+
Vectorized<int32_t> operator<=(const Vectorized<int32_t>& other) const {
|
| 301 |
+
auto mask = _mm512_cmple_epi32_mask(values, other.values);
|
| 302 |
+
return _mm512_mask_set1_epi32(zero_vector, mask, 0xFFFFFFFF);
|
| 303 |
+
}
|
| 304 |
+
Vectorized<int32_t> operator>(const Vectorized<int32_t>& other) const {
|
| 305 |
+
auto mask = _mm512_cmpgt_epi32_mask(values, other.values);
|
| 306 |
+
return _mm512_mask_set1_epi32(zero_vector, mask, 0xFFFFFFFF);
|
| 307 |
+
}
|
| 308 |
+
Vectorized<int32_t> operator>=(const Vectorized<int32_t>& other) const {
|
| 309 |
+
auto mask = _mm512_cmpge_epi32_mask(values, other.values);
|
| 310 |
+
return _mm512_mask_set1_epi32(zero_vector, mask, 0xFFFFFFFF);
|
| 311 |
+
}
|
| 312 |
+
Vectorized<int32_t> eq(const Vectorized<int32_t>& other) const;
|
| 313 |
+
Vectorized<int32_t> ne(const Vectorized<int32_t>& other) const;
|
| 314 |
+
Vectorized<int32_t> gt(const Vectorized<int32_t>& other) const;
|
| 315 |
+
Vectorized<int32_t> ge(const Vectorized<int32_t>& other) const;
|
| 316 |
+
Vectorized<int32_t> lt(const Vectorized<int32_t>& other) const;
|
| 317 |
+
Vectorized<int32_t> le(const Vectorized<int32_t>& other) const;
|
| 318 |
+
};
|
| 319 |
+
|
| 320 |
+
template <>
|
| 321 |
+
inline void convert(const int32_t *src, float *dst, int64_t n) {
|
| 322 |
+
int64_t i;
|
| 323 |
+
// int32_t and float have same size
|
| 324 |
+
#ifndef _MSC_VER
|
| 325 |
+
# pragma unroll
|
| 326 |
+
#endif
|
| 327 |
+
for (i = 0; i <= (n - Vectorized<int32_t>::size()); i += Vectorized<int32_t>::size()) {
|
| 328 |
+
auto input_vec = _mm512_loadu_si512(reinterpret_cast<const __m512i*>(src + i));
|
| 329 |
+
auto output_vec = _mm512_cvtepi32_ps(input_vec);
|
| 330 |
+
_mm512_storeu_ps(reinterpret_cast<float*>(dst + i), output_vec);
|
| 331 |
+
}
|
| 332 |
+
#ifndef _MSC_VER
|
| 333 |
+
# pragma unroll
|
| 334 |
+
#endif
|
| 335 |
+
for (; i < n; i++) {
|
| 336 |
+
dst[i] = static_cast<float>(src[i]);
|
| 337 |
+
}
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
template <>
|
| 341 |
+
inline void convert(const int32_t *src, double *dst, int64_t n) {
|
| 342 |
+
int64_t i;
|
| 343 |
+
// int32_t has half the size of double
|
| 344 |
+
#ifndef _MSC_VER
|
| 345 |
+
# pragma unroll
|
| 346 |
+
#endif
|
| 347 |
+
for (i = 0; i <= (n - Vectorized<double>::size()); i += Vectorized<double>::size()) {
|
| 348 |
+
auto input_256_vec = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(src + i));
|
| 349 |
+
auto output_vec = _mm512_cvtepi32_pd(input_256_vec);
|
| 350 |
+
_mm512_storeu_pd(reinterpret_cast<double*>(dst + i), output_vec);
|
| 351 |
+
}
|
| 352 |
+
#ifndef _MSC_VER
|
| 353 |
+
# pragma unroll
|
| 354 |
+
#endif
|
| 355 |
+
for (; i < n; i++) {
|
| 356 |
+
dst[i] = static_cast<double>(src[i]);
|
| 357 |
+
}
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
template <>
|
| 361 |
+
class Vectorized<int16_t> : public Vectorizedi {
|
| 362 |
+
private:
|
| 363 |
+
static const Vectorized<int16_t> ones;
|
| 364 |
+
static constexpr __m512i zero_vector {0, 0, 0, 0, 0, 0, 0, 0};
|
| 365 |
+
public:
|
| 366 |
+
using value_type = int16_t;
|
| 367 |
+
static constexpr int size() {
|
| 368 |
+
return 32;
|
| 369 |
+
}
|
| 370 |
+
using Vectorizedi::Vectorizedi;
|
| 371 |
+
Vectorized() {}
|
| 372 |
+
Vectorized(int16_t v) { values = _mm512_set1_epi16(v); }
|
| 373 |
+
Vectorized(int16_t val1, int16_t val2, int16_t val3, int16_t val4,
|
| 374 |
+
int16_t val5, int16_t val6, int16_t val7, int16_t val8,
|
| 375 |
+
int16_t val9, int16_t val10, int16_t val11, int16_t val12,
|
| 376 |
+
int16_t val13, int16_t val14, int16_t val15, int16_t val16,
|
| 377 |
+
int16_t val17, int16_t val18, int16_t val19, int16_t val20,
|
| 378 |
+
int16_t val21, int16_t val22, int16_t val23, int16_t val24,
|
| 379 |
+
int16_t val25, int16_t val26, int16_t val27, int16_t val28,
|
| 380 |
+
int16_t val29, int16_t val30, int16_t val31, int16_t val32) {
|
| 381 |
+
values = _mm512_set_epi16(val32, val31, val30, val29, val28, val27, val26, val25,
|
| 382 |
+
val24, val23, val22, val21, val20, val19, val18, val17,
|
| 383 |
+
val16, val15, val14, val13, val12, val11, val10, val9,
|
| 384 |
+
val8, val7, val6, val5, val4, val3, val2, val1);
|
| 385 |
+
}
|
| 386 |
+
template <int64_t mask>
|
| 387 |
+
static Vectorized<int16_t> blend(Vectorized<int16_t> a, Vectorized<int16_t> b) {
|
| 388 |
+
return _mm512_mask_blend_epi16(mask, a.values, b.values);
|
| 389 |
+
}
|
| 390 |
+
static Vectorized<int16_t> blendv(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b,
|
| 391 |
+
const Vectorized<int16_t>& mask) {
|
| 392 |
+
auto msb_one = _mm512_set1_epi16(0xFFFF);
|
| 393 |
+
auto mask_ = _mm512_cmp_epi16_mask(mask, msb_one, _MM_CMPINT_EQ);
|
| 394 |
+
return _mm512_mask_blend_epi16(mask_, a.values, b.values);
|
| 395 |
+
}
|
| 396 |
+
template <typename step_t>
|
| 397 |
+
static Vectorized<int16_t> arange(int16_t base = 0, step_t step = static_cast<step_t>(1)) {
|
| 398 |
+
return Vectorized<int16_t>(
|
| 399 |
+
base, base + step, base + 2 * step, base + 3 * step,
|
| 400 |
+
base + 4 * step, base + 5 * step, base + 6 * step, base + 7 * step,
|
| 401 |
+
base + 8 * step, base + 9 * step, base + 10 * step, base + 11 * step,
|
| 402 |
+
base + 12 * step, base + 13 * step, base + 14 * step, base + 15 * step,
|
| 403 |
+
base + 16 * step, base + 17 * step, base + 18 * step, base + 19 * step,
|
| 404 |
+
base + 20 * step, base + 21 * step, base + 22 * step, base + 23 * step,
|
| 405 |
+
base + 24 * step, base + 25 * step, base + 26 * step, base + 27 * step,
|
| 406 |
+
base + 28 * step, base + 29 * step, base + 30 * step, base + 31 * step
|
| 407 |
+
);
|
| 408 |
+
}
|
| 409 |
+
static Vectorized<int16_t>
|
| 410 |
+
set(Vectorized<int16_t> a, Vectorized<int16_t> b, int16_t count = size()) {
|
| 411 |
+
switch (count) {
|
| 412 |
+
case 0:
|
| 413 |
+
return a;
|
| 414 |
+
case 1:
|
| 415 |
+
return blend<0x1>(a, b);
|
| 416 |
+
case 2:
|
| 417 |
+
return blend<0x3>(a, b);
|
| 418 |
+
case 3:
|
| 419 |
+
return blend<0x7>(a, b);
|
| 420 |
+
case 4:
|
| 421 |
+
return blend<0xF>(a, b);
|
| 422 |
+
case 5:
|
| 423 |
+
return blend<0x1F>(a, b);
|
| 424 |
+
case 6:
|
| 425 |
+
return blend<0x3F>(a, b);
|
| 426 |
+
case 7:
|
| 427 |
+
return blend<0x7F>(a, b);
|
| 428 |
+
case 8:
|
| 429 |
+
return blend<0xFF>(a, b);
|
| 430 |
+
case 9:
|
| 431 |
+
return blend<0x1FF>(a, b);
|
| 432 |
+
case 10:
|
| 433 |
+
return blend<0x3FF>(a, b);
|
| 434 |
+
case 11:
|
| 435 |
+
return blend<0x7FF>(a, b);
|
| 436 |
+
case 12:
|
| 437 |
+
return blend<0xFFF>(a, b);
|
| 438 |
+
case 13:
|
| 439 |
+
return blend<0x1FFF>(a, b);
|
| 440 |
+
case 14:
|
| 441 |
+
return blend<0x3FFF>(a, b);
|
| 442 |
+
case 15:
|
| 443 |
+
return blend<0x7FFF>(a, b);
|
| 444 |
+
case 16:
|
| 445 |
+
return blend<0xFFFF>(a, b);
|
| 446 |
+
case 17:
|
| 447 |
+
return blend<0x1FFFF>(a, b);
|
| 448 |
+
case 18:
|
| 449 |
+
return blend<0x3FFFF>(a, b);
|
| 450 |
+
case 19:
|
| 451 |
+
return blend<0x7FFFF>(a, b);
|
| 452 |
+
case 20:
|
| 453 |
+
return blend<0xFFFFF>(a, b);
|
| 454 |
+
case 21:
|
| 455 |
+
return blend<0x1FFFFF>(a, b);
|
| 456 |
+
case 22:
|
| 457 |
+
return blend<0x3FFFFF>(a, b);
|
| 458 |
+
case 23:
|
| 459 |
+
return blend<0x7FFFFF>(a, b);
|
| 460 |
+
case 24:
|
| 461 |
+
return blend<0xFFFFFF>(a, b);
|
| 462 |
+
case 25:
|
| 463 |
+
return blend<0x1FFFFFF>(a, b);
|
| 464 |
+
case 26:
|
| 465 |
+
return blend<0x3FFFFFF>(a, b);
|
| 466 |
+
case 27:
|
| 467 |
+
return blend<0x7FFFFFF>(a, b);
|
| 468 |
+
case 28:
|
| 469 |
+
return blend<0xFFFFFFF>(a, b);
|
| 470 |
+
case 29:
|
| 471 |
+
return blend<0x1FFFFFFF>(a, b);
|
| 472 |
+
case 30:
|
| 473 |
+
return blend<0x3FFFFFFF>(a, b);
|
| 474 |
+
case 31:
|
| 475 |
+
return blend<0x7FFFFFFF>(a, b);
|
| 476 |
+
}
|
| 477 |
+
return b;
|
| 478 |
+
}
|
| 479 |
+
static Vectorized<int16_t> loadu(const void* ptr) {
|
| 480 |
+
return _mm512_loadu_si512(reinterpret_cast<const __m512i*>(ptr));
|
| 481 |
+
}
|
| 482 |
+
static Vectorized<int16_t> loadu(const void* ptr, int16_t count) {
|
| 483 |
+
__at_align__ int16_t tmp_values[size()];
|
| 484 |
+
// Ensure uninitialized memory does not change the output value See https://github.com/pytorch/pytorch/issues/32502
|
| 485 |
+
// for more details. We do not initialize arrays to zero using "={0}" because gcc would compile it to two
|
| 486 |
+
// instructions while a loop would be compiled to one instruction.
|
| 487 |
+
for (const auto i : c10::irange(size())) {
|
| 488 |
+
tmp_values[i] = 0;
|
| 489 |
+
}
|
| 490 |
+
std::memcpy(tmp_values, ptr, count * sizeof(int16_t));
|
| 491 |
+
return loadu(tmp_values);
|
| 492 |
+
}
|
| 493 |
+
void store(void* ptr, int count = size()) const {
|
| 494 |
+
if (count == size()) {
|
| 495 |
+
// ptr need not to be aligned here. See
|
| 496 |
+
// https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/intrinsics/intrinsics-for-intel-advanced-vector-extensions/intrinsics-for-load-and-store-operations-1/mm512-storeu-si512.html
|
| 497 |
+
_mm512_storeu_si512(reinterpret_cast<__m512i*>(ptr), values);
|
| 498 |
+
} else if (count > 0) {
|
| 499 |
+
__at_align__ int16_t tmp_values[size()];
|
| 500 |
+
_mm512_storeu_si512(reinterpret_cast<__m512i*>(tmp_values), values);
|
| 501 |
+
std::memcpy(ptr, tmp_values, count * sizeof(int16_t));
|
| 502 |
+
}
|
| 503 |
+
}
|
| 504 |
+
const int16_t& operator[](int idx) const = delete;
|
| 505 |
+
int16_t& operator[](int idx) = delete;
|
| 506 |
+
Vectorized<int16_t> abs() const {
|
| 507 |
+
return _mm512_abs_epi16(values);
|
| 508 |
+
}
|
| 509 |
+
Vectorized<int16_t> real() const {
|
| 510 |
+
return *this;
|
| 511 |
+
}
|
| 512 |
+
Vectorized<int16_t> imag() const {
|
| 513 |
+
return _mm512_set1_epi16(0);
|
| 514 |
+
}
|
| 515 |
+
Vectorized<int16_t> conj() const {
|
| 516 |
+
return *this;
|
| 517 |
+
}
|
| 518 |
+
Vectorized<int16_t> neg() const;
|
| 519 |
+
Vectorized<int16_t> operator==(const Vectorized<int16_t>& other) const {
|
| 520 |
+
auto mask = _mm512_cmpeq_epi16_mask(values, other.values);
|
| 521 |
+
return _mm512_mask_set1_epi16(zero_vector, mask, 0xFFFF);
|
| 522 |
+
}
|
| 523 |
+
Vectorized<int16_t> operator!=(const Vectorized<int16_t>& other) const {
|
| 524 |
+
auto mask = _mm512_cmpneq_epi16_mask(values, other.values);
|
| 525 |
+
return _mm512_mask_set1_epi16(zero_vector, mask, 0xFFFF);
|
| 526 |
+
}
|
| 527 |
+
Vectorized<int16_t> operator<(const Vectorized<int16_t>& other) const {
|
| 528 |
+
auto mask = _mm512_cmplt_epi16_mask(values, other.values);
|
| 529 |
+
return _mm512_mask_set1_epi16(zero_vector, mask, 0xFFFF);
|
| 530 |
+
}
|
| 531 |
+
Vectorized<int16_t> operator<=(const Vectorized<int16_t>& other) const {
|
| 532 |
+
auto mask = _mm512_cmple_epi16_mask(values, other.values);
|
| 533 |
+
return _mm512_mask_set1_epi16(zero_vector, mask, 0xFFFF);
|
| 534 |
+
}
|
| 535 |
+
Vectorized<int16_t> operator>(const Vectorized<int16_t>& other) const {
|
| 536 |
+
auto mask = _mm512_cmpgt_epi16_mask(values, other.values);
|
| 537 |
+
return _mm512_mask_set1_epi16(zero_vector, mask, 0xFFFF);
|
| 538 |
+
}
|
| 539 |
+
Vectorized<int16_t> operator>=(const Vectorized<int16_t>& other) const {
|
| 540 |
+
auto mask = _mm512_cmpge_epi16_mask(values, other.values);
|
| 541 |
+
return _mm512_mask_set1_epi16(zero_vector, mask, 0xFFFF);
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
Vectorized<int16_t> eq(const Vectorized<int16_t>& other) const;
|
| 545 |
+
Vectorized<int16_t> ne(const Vectorized<int16_t>& other) const;
|
| 546 |
+
Vectorized<int16_t> gt(const Vectorized<int16_t>& other) const;
|
| 547 |
+
Vectorized<int16_t> ge(const Vectorized<int16_t>& other) const;
|
| 548 |
+
Vectorized<int16_t> lt(const Vectorized<int16_t>& other) const;
|
| 549 |
+
Vectorized<int16_t> le(const Vectorized<int16_t>& other) const;
|
| 550 |
+
};
|
| 551 |
+
|
| 552 |
+
template <typename T>
|
| 553 |
+
class Vectorized8 : public Vectorizedi {
|
| 554 |
+
static_assert(
|
| 555 |
+
std::is_same<T, int8_t>::value || std::is_same<T, uint8_t>::value,
|
| 556 |
+
"Only int8_t/uint8_t are supported");
|
| 557 |
+
protected:
|
| 558 |
+
static constexpr __m512i zero_vector {0, 0, 0, 0, 0, 0, 0, 0};
|
| 559 |
+
static const Vectorized<T> ones;
|
| 560 |
+
public:
|
| 561 |
+
using value_type = T;
|
| 562 |
+
static constexpr int size() {
|
| 563 |
+
return 64;
|
| 564 |
+
}
|
| 565 |
+
using Vectorizedi::Vectorizedi;
|
| 566 |
+
Vectorized8() {}
|
| 567 |
+
Vectorized8(T v) { values = _mm512_set1_epi8(v); }
|
| 568 |
+
Vectorized8(T val1, T val2, T val3, T val4,
|
| 569 |
+
T val5, T val6, T val7, T val8,
|
| 570 |
+
T val9, T val10, T val11, T val12,
|
| 571 |
+
T val13, T val14, T val15, T val16,
|
| 572 |
+
T val17, T val18, T val19, T val20,
|
| 573 |
+
T val21, T val22, T val23, T val24,
|
| 574 |
+
T val25, T val26, T val27, T val28,
|
| 575 |
+
T val29, T val30, T val31, T val32,
|
| 576 |
+
T val33, T val34, T val35, T val36,
|
| 577 |
+
T val37, T val38, T val39, T val40,
|
| 578 |
+
T val41, T val42, T val43, T val44,
|
| 579 |
+
T val45, T val46, T val47, T val48,
|
| 580 |
+
T val49, T val50, T val51, T val52,
|
| 581 |
+
T val53, T val54, T val55, T val56,
|
| 582 |
+
T val57, T val58, T val59, T val60,
|
| 583 |
+
T val61, T val62, T val63, T val64){
|
| 584 |
+
values = _mm512_set_epi8(val64, val63, val62, val61, val60, val59, val58, val57,
|
| 585 |
+
val56, val55, val54, val53,val52, val51, val50, val49,
|
| 586 |
+
val48, val47, val46, val45, val44, val43, val42, val41,
|
| 587 |
+
val40, val39, val38, val37, val36, val35, val34, val33,
|
| 588 |
+
val32, val31, val30, val29, val28, val27, val26, val25,
|
| 589 |
+
val24, val23, val22, val21, val20, val19, val18, val17,
|
| 590 |
+
val16, val15, val14, val13, val12, val11, val10, val9,
|
| 591 |
+
val8, val7, val6, val5, val4, val3, val2, val1);
|
| 592 |
+
}
|
| 593 |
+
template <int64_t mask>
|
| 594 |
+
static Vectorized<T> blend(Vectorized<T> a, Vectorized<T> b) {
|
| 595 |
+
return _mm512_mask_blend_epi8(mask, a.values, b.values);
|
| 596 |
+
}
|
| 597 |
+
template <typename step_t>
|
| 598 |
+
static Vectorized<T> arange(T base = 0, step_t step = static_cast<step_t>(1)) {
|
| 599 |
+
return Vectorized<T>(
|
| 600 |
+
base, base + step, base + 2 * step, base + 3 * step,
|
| 601 |
+
base + 4 * step, base + 5 * step, base + 6 * step, base + 7 * step,
|
| 602 |
+
base + 8 * step, base + 9 * step, base + 10 * step, base + 11 * step,
|
| 603 |
+
base + 12 * step, base + 13 * step, base + 14 * step, base + 15 * step,
|
| 604 |
+
base + 16 * step, base + 17 * step, base + 18 * step, base + 19 * step,
|
| 605 |
+
base + 20 * step, base + 21 * step, base + 22 * step, base + 23 * step,
|
| 606 |
+
base + 24 * step, base + 25 * step, base + 26 * step, base + 27 * step,
|
| 607 |
+
base + 28 * step, base + 29 * step, base + 30 * step, base + 31 * step,
|
| 608 |
+
base + 32 * step, base + 33 * step, base + 34 * step, base + 35 * step,
|
| 609 |
+
base + 36 * step, base + 37 * step, base + 38 * step, base + 39 * step,
|
| 610 |
+
base + 40 * step, base + 41 * step, base + 42 * step, base + 43 * step,
|
| 611 |
+
base + 44 * step, base + 45 * step, base + 46 * step, base + 47 * step,
|
| 612 |
+
base + 48 * step, base + 49 * step, base + 50 * step, base + 51 * step,
|
| 613 |
+
base + 52 * step, base + 53 * step, base + 54 * step, base + 55 * step,
|
| 614 |
+
base + 56 * step, base + 57 * step, base + 58 * step, base + 59 * step,
|
| 615 |
+
base + 60 * step, base + 61 * step, base + 62 * step, base + 63 * step);
|
| 616 |
+
}
|
| 617 |
+
static Vectorized<T>
|
| 618 |
+
set(Vectorized<T> a, Vectorized<T> b, T count = size()) {
|
| 619 |
+
switch (count) {
|
| 620 |
+
case 0:
|
| 621 |
+
return a;
|
| 622 |
+
case 1:
|
| 623 |
+
return blend<0x1>(a, b);
|
| 624 |
+
case 2:
|
| 625 |
+
return blend<0x3>(a, b);
|
| 626 |
+
case 3:
|
| 627 |
+
return blend<0x7>(a, b);
|
| 628 |
+
case 4:
|
| 629 |
+
return blend<0xF>(a, b);
|
| 630 |
+
case 5:
|
| 631 |
+
return blend<0x1F>(a, b);
|
| 632 |
+
case 6:
|
| 633 |
+
return blend<0x3F>(a, b);
|
| 634 |
+
case 7:
|
| 635 |
+
return blend<0x7F>(a, b);
|
| 636 |
+
case 8:
|
| 637 |
+
return blend<0xFF>(a, b);
|
| 638 |
+
case 9:
|
| 639 |
+
return blend<0x1FF>(a, b);
|
| 640 |
+
case 10:
|
| 641 |
+
return blend<0x3FF>(a, b);
|
| 642 |
+
case 11:
|
| 643 |
+
return blend<0x7FF>(a, b);
|
| 644 |
+
case 12:
|
| 645 |
+
return blend<0xFFF>(a, b);
|
| 646 |
+
case 13:
|
| 647 |
+
return blend<0x1FFF>(a, b);
|
| 648 |
+
case 14:
|
| 649 |
+
return blend<0x3FFF>(a, b);
|
| 650 |
+
case 15:
|
| 651 |
+
return blend<0x7FFF>(a, b);
|
| 652 |
+
case 16:
|
| 653 |
+
return blend<0xFFFF>(a, b);
|
| 654 |
+
case 17:
|
| 655 |
+
return blend<0x1FFFF>(a, b);
|
| 656 |
+
case 18:
|
| 657 |
+
return blend<0x3FFFF>(a, b);
|
| 658 |
+
case 19:
|
| 659 |
+
return blend<0x7FFFF>(a, b);
|
| 660 |
+
case 20:
|
| 661 |
+
return blend<0xFFFFF>(a, b);
|
| 662 |
+
case 21:
|
| 663 |
+
return blend<0x1FFFFF>(a, b);
|
| 664 |
+
case 22:
|
| 665 |
+
return blend<0x3FFFFF>(a, b);
|
| 666 |
+
case 23:
|
| 667 |
+
return blend<0x7FFFFF>(a, b);
|
| 668 |
+
case 24:
|
| 669 |
+
return blend<0xFFFFFF>(a, b);
|
| 670 |
+
case 25:
|
| 671 |
+
return blend<0x1FFFFFF>(a, b);
|
| 672 |
+
case 26:
|
| 673 |
+
return blend<0x3FFFFFF>(a, b);
|
| 674 |
+
case 27:
|
| 675 |
+
return blend<0x7FFFFFF>(a, b);
|
| 676 |
+
case 28:
|
| 677 |
+
return blend<0xFFFFFFF>(a, b);
|
| 678 |
+
case 29:
|
| 679 |
+
return blend<0x1FFFFFFF>(a, b);
|
| 680 |
+
case 30:
|
| 681 |
+
return blend<0x3FFFFFFF>(a, b);
|
| 682 |
+
case 31:
|
| 683 |
+
return blend<0x7FFFFFFF>(a, b);
|
| 684 |
+
case 32:
|
| 685 |
+
return blend<0xFFFFFFFF>(a, b);
|
| 686 |
+
case 33:
|
| 687 |
+
return blend<0x1FFFFFFFF>(a, b);
|
| 688 |
+
case 34:
|
| 689 |
+
return blend<0x3FFFFFFFF>(a, b);
|
| 690 |
+
case 35:
|
| 691 |
+
return blend<0x7FFFFFFFF>(a, b);
|
| 692 |
+
case 36:
|
| 693 |
+
return blend<0xFFFFFFFFF>(a, b);
|
| 694 |
+
case 37:
|
| 695 |
+
return blend<0x1FFFFFFFFF>(a, b);
|
| 696 |
+
case 38:
|
| 697 |
+
return blend<0x3FFFFFFFFF>(a, b);
|
| 698 |
+
case 39:
|
| 699 |
+
return blend<0x7FFFFFFFFF>(a, b);
|
| 700 |
+
case 40:
|
| 701 |
+
return blend<0xFFFFFFFFFF>(a, b);
|
| 702 |
+
case 41:
|
| 703 |
+
return blend<0x1FFFFFFFFFF>(a, b);
|
| 704 |
+
case 42:
|
| 705 |
+
return blend<0x3FFFFFFFFFF>(a, b);
|
| 706 |
+
case 43:
|
| 707 |
+
return blend<0x7FFFFFFFFFF>(a, b);
|
| 708 |
+
case 44:
|
| 709 |
+
return blend<0xFFFFFFFFFFF>(a, b);
|
| 710 |
+
case 45:
|
| 711 |
+
return blend<0x1FFFFFFFFFFF>(a, b);
|
| 712 |
+
case 46:
|
| 713 |
+
return blend<0x3FFFFFFFFFFF>(a, b);
|
| 714 |
+
case 47:
|
| 715 |
+
return blend<0x7FFFFFFFFFFF>(a, b);
|
| 716 |
+
case 48:
|
| 717 |
+
return blend<0xFFFFFFFFFFFF>(a, b);
|
| 718 |
+
case 49:
|
| 719 |
+
return blend<0x1FFFFFFFFFFFF>(a, b);
|
| 720 |
+
case 50:
|
| 721 |
+
return blend<0x3FFFFFFFFFFFF>(a, b);
|
| 722 |
+
case 51:
|
| 723 |
+
return blend<0x7FFFFFFFFFFFF>(a, b);
|
| 724 |
+
case 52:
|
| 725 |
+
return blend<0xFFFFFFFFFFFFF>(a, b);
|
| 726 |
+
case 53:
|
| 727 |
+
return blend<0x1FFFFFFFFFFFFF>(a, b);
|
| 728 |
+
case 54:
|
| 729 |
+
return blend<0x3FFFFFFFFFFFFF>(a, b);
|
| 730 |
+
case 55:
|
| 731 |
+
return blend<0x7FFFFFFFFFFFFF>(a, b);
|
| 732 |
+
case 56:
|
| 733 |
+
return blend<0xFFFFFFFFFFFFFF>(a, b);
|
| 734 |
+
case 57:
|
| 735 |
+
return blend<0x1FFFFFFFFFFFFFF>(a, b);
|
| 736 |
+
case 58:
|
| 737 |
+
return blend<0x3FFFFFFFFFFFFFF>(a, b);
|
| 738 |
+
case 59:
|
| 739 |
+
return blend<0x7FFFFFFFFFFFFFF>(a, b);
|
| 740 |
+
case 60:
|
| 741 |
+
return blend<0xFFFFFFFFFFFFFFF>(a, b);
|
| 742 |
+
case 61:
|
| 743 |
+
return blend<0x1FFFFFFFFFFFFFFF>(a, b);
|
| 744 |
+
case 62:
|
| 745 |
+
return blend<0x3FFFFFFFFFFFFFFF>(a, b);
|
| 746 |
+
case 63:
|
| 747 |
+
return blend<0x7FFFFFFFFFFFFFFF>(a, b);
|
| 748 |
+
}
|
| 749 |
+
return b;
|
| 750 |
+
}
|
| 751 |
+
static Vectorized<T> loadu(const void* ptr) {
|
| 752 |
+
return _mm512_loadu_si512(reinterpret_cast<const __m512i*>(ptr));
|
| 753 |
+
}
|
| 754 |
+
static Vectorized<T> loadu_one_fourth(const void* ptr) {
|
| 755 |
+
// Fast path if only load element number of 16.
|
| 756 |
+
// Note: We didn't merge it as fast path of loadu(const void* ptr, T count),
|
| 757 |
+
// Because loadu(const void* ptr, T count) requires zero initialization for upper 384 bits.
|
| 758 |
+
// However, by using _mm512_castsi128_si512, the upper 384 bits of the result are undefined.
|
| 759 |
+
// TODO<leslie> We can use _mm512_zextsi128_si512 in the furture,
|
| 760 |
+
// since gcc 9.3 doesn't support it now.
|
| 761 |
+
__m128i input_128 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(ptr));
|
| 762 |
+
return _mm512_castsi128_si512(input_128);
|
| 763 |
+
}
|
| 764 |
+
static Vectorized<T> loadu(const void* ptr, T count) {
|
| 765 |
+
__at_align__ T tmp_values[size()];
|
| 766 |
+
// Ensure uninitialized memory does not change the output value See https://github.com/pytorch/pytorch/issues/32502
|
| 767 |
+
// for more details. We do not initialize arrays to zero using "={0}" because gcc would compile it to two
|
| 768 |
+
// instructions while a loop would be compiled to one instruction.
|
| 769 |
+
for (const auto i : c10::irange(size())) {
|
| 770 |
+
tmp_values[i] = 0;
|
| 771 |
+
}
|
| 772 |
+
std::memcpy(tmp_values, ptr, count * sizeof(T));
|
| 773 |
+
return loadu(tmp_values);
|
| 774 |
+
}
|
| 775 |
+
void store(void* ptr, int count = size()) const {
|
| 776 |
+
if (count == size()) {
|
| 777 |
+
// ptr need not to be aligned here. See
|
| 778 |
+
// https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/intrinsics/intrinsics-for-intel-advanced-vector-extensions/intrinsics-for-load-and-store-operations-1/mm512-storeu-si512.html
|
| 779 |
+
_mm512_storeu_si512(reinterpret_cast<__m512i*>(ptr), values);
|
| 780 |
+
} else if (count > 0) {
|
| 781 |
+
if (count == 16) {
|
| 782 |
+
// Fast path if only store element number of 16
|
| 783 |
+
_mm_storeu_si128(
|
| 784 |
+
reinterpret_cast<__m128i*>(ptr),
|
| 785 |
+
_mm512_castsi512_si128(values));
|
| 786 |
+
} else {
|
| 787 |
+
__at_align__ T tmp_values[size()];
|
| 788 |
+
_mm512_storeu_si512(reinterpret_cast<__m512i*>(tmp_values), values);
|
| 789 |
+
std::memcpy(ptr, tmp_values, count * sizeof(T));
|
| 790 |
+
}
|
| 791 |
+
}
|
| 792 |
+
}
|
| 793 |
+
const T& operator[](int idx) const = delete;
|
| 794 |
+
T& operator[](int idx) = delete;
|
| 795 |
+
Vectorized<T> real() const {
|
| 796 |
+
return *this;
|
| 797 |
+
}
|
| 798 |
+
Vectorized<T> imag() const {
|
| 799 |
+
return _mm512_set1_epi8(0);
|
| 800 |
+
}
|
| 801 |
+
Vectorized<T> conj() const {
|
| 802 |
+
return *this;
|
| 803 |
+
}
|
| 804 |
+
};
|
| 805 |
+
|
| 806 |
+
template<>
|
| 807 |
+
class Vectorized<int8_t>: public Vectorized8<int8_t> {
|
| 808 |
+
public:
|
| 809 |
+
using Vectorized8::Vectorized8;
|
| 810 |
+
|
| 811 |
+
static Vectorized<int8_t> blendv(const Vectorized<int8_t>& a, const Vectorized<int8_t>& b,
|
| 812 |
+
const Vectorized<int8_t>& mask) {
|
| 813 |
+
auto msb_one = _mm512_set1_epi8(0xFF);
|
| 814 |
+
auto mask_ = _mm512_cmp_epi8_mask(mask, msb_one, _MM_CMPINT_EQ);
|
| 815 |
+
return _mm512_mask_blend_epi8(mask_, a.values, b.values);
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
Vectorized<int8_t> neg() const;
|
| 819 |
+
|
| 820 |
+
Vectorized<int8_t> abs() const {
|
| 821 |
+
return _mm512_abs_epi8(values);
|
| 822 |
+
}
|
| 823 |
+
|
| 824 |
+
Vectorized<int8_t> operator==(const Vectorized<int8_t>& other) const {
|
| 825 |
+
auto mask = _mm512_cmpeq_epi8_mask(values, other.values);
|
| 826 |
+
return _mm512_mask_set1_epi8(zero_vector, mask, 0xFF);
|
| 827 |
+
}
|
| 828 |
+
Vectorized<int8_t> operator!=(const Vectorized<int8_t>& other) const {
|
| 829 |
+
auto mask = _mm512_cmpneq_epi8_mask(values, other.values);
|
| 830 |
+
return _mm512_mask_set1_epi8(zero_vector, mask, 0xFF);
|
| 831 |
+
}
|
| 832 |
+
Vectorized<int8_t> operator<(const Vectorized<int8_t>& other) const {
|
| 833 |
+
auto mask = _mm512_cmplt_epi8_mask(values, other.values);
|
| 834 |
+
return _mm512_mask_set1_epi8(zero_vector, mask, 0xFF);
|
| 835 |
+
}
|
| 836 |
+
Vectorized<int8_t> operator<=(const Vectorized<int8_t>& other) const {
|
| 837 |
+
auto mask = _mm512_cmple_epi8_mask(values, other.values);
|
| 838 |
+
return _mm512_mask_set1_epi8(zero_vector, mask, 0xFF);
|
| 839 |
+
}
|
| 840 |
+
Vectorized<int8_t> operator>(const Vectorized<int8_t>& other) const {
|
| 841 |
+
return other < *this;
|
| 842 |
+
}
|
| 843 |
+
Vectorized<int8_t> operator>=(const Vectorized<int8_t>& other) const {
|
| 844 |
+
return other <= *this;
|
| 845 |
+
}
|
| 846 |
+
|
| 847 |
+
Vectorized<int8_t> eq(const Vectorized<int8_t>& other) const;
|
| 848 |
+
Vectorized<int8_t> ne(const Vectorized<int8_t>& other) const;
|
| 849 |
+
Vectorized<int8_t> gt(const Vectorized<int8_t>& other) const;
|
| 850 |
+
Vectorized<int8_t> ge(const Vectorized<int8_t>& other) const;
|
| 851 |
+
Vectorized<int8_t> lt(const Vectorized<int8_t>& other) const;
|
| 852 |
+
Vectorized<int8_t> le(const Vectorized<int8_t>& other) const;
|
| 853 |
+
};
|
| 854 |
+
|
| 855 |
+
template<>
|
| 856 |
+
class Vectorized<uint8_t>: public Vectorized8<uint8_t> {
|
| 857 |
+
public:
|
| 858 |
+
using Vectorized8::Vectorized8;
|
| 859 |
+
|
| 860 |
+
static Vectorized<uint8_t> blendv(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& b,
|
| 861 |
+
const Vectorized<uint8_t>& mask) {
|
| 862 |
+
auto msb_one = _mm512_set1_epi8(0xFF);
|
| 863 |
+
auto mask_ = _mm512_cmp_epu8_mask(mask, msb_one, _MM_CMPINT_EQ);
|
| 864 |
+
return _mm512_mask_blend_epi8(mask_, a.values, b.values);
|
| 865 |
+
}
|
| 866 |
+
|
| 867 |
+
Vectorized<uint8_t> neg() const;
|
| 868 |
+
|
| 869 |
+
Vectorized<uint8_t> abs() const {
|
| 870 |
+
return *this;
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
Vectorized<uint8_t> operator==(const Vectorized<uint8_t>& other) const {
|
| 874 |
+
auto mask = _mm512_cmpeq_epu8_mask(values, other.values);
|
| 875 |
+
return _mm512_mask_set1_epi8(zero_vector, mask, 0xFF);
|
| 876 |
+
}
|
| 877 |
+
Vectorized<uint8_t> operator!=(const Vectorized<uint8_t>& other) const {
|
| 878 |
+
auto mask = _mm512_cmpneq_epu8_mask(values, other.values);
|
| 879 |
+
return _mm512_mask_set1_epi8(zero_vector, mask, 0xFF);
|
| 880 |
+
}
|
| 881 |
+
Vectorized<uint8_t> operator<(const Vectorized<uint8_t>& other) const {
|
| 882 |
+
auto mask = _mm512_cmplt_epu8_mask(values, other.values);
|
| 883 |
+
return _mm512_mask_set1_epi8(zero_vector, mask, 0xFF);
|
| 884 |
+
}
|
| 885 |
+
Vectorized<uint8_t> operator<=(const Vectorized<uint8_t>& other) const {
|
| 886 |
+
auto mask = _mm512_cmple_epu8_mask(values, other.values);
|
| 887 |
+
return _mm512_mask_set1_epi8(zero_vector, mask, 0xFF);
|
| 888 |
+
}
|
| 889 |
+
Vectorized<uint8_t> operator>(const Vectorized<uint8_t>& other) const {
|
| 890 |
+
return other < *this;
|
| 891 |
+
}
|
| 892 |
+
Vectorized<uint8_t> operator>=(const Vectorized<uint8_t>& other) const {
|
| 893 |
+
return other <= *this;
|
| 894 |
+
}
|
| 895 |
+
|
| 896 |
+
Vectorized<uint8_t> eq(const Vectorized<uint8_t>& other) const;
|
| 897 |
+
Vectorized<uint8_t> ne(const Vectorized<uint8_t>& other) const;
|
| 898 |
+
Vectorized<uint8_t> gt(const Vectorized<uint8_t>& other) const;
|
| 899 |
+
Vectorized<uint8_t> ge(const Vectorized<uint8_t>& other) const;
|
| 900 |
+
Vectorized<uint8_t> lt(const Vectorized<uint8_t>& other) const;
|
| 901 |
+
Vectorized<uint8_t> le(const Vectorized<uint8_t>& other) const;
|
| 902 |
+
};
|
| 903 |
+
|
| 904 |
+
template <>
|
| 905 |
+
Vectorized<int64_t> inline operator+(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 906 |
+
return _mm512_add_epi64(a, b);
|
| 907 |
+
}
|
| 908 |
+
|
| 909 |
+
template <>
|
| 910 |
+
Vectorized<int32_t> inline operator+(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 911 |
+
return _mm512_add_epi32(a, b);
|
| 912 |
+
}
|
| 913 |
+
|
| 914 |
+
template <>
|
| 915 |
+
Vectorized<int16_t> inline operator+(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 916 |
+
return _mm512_add_epi16(a, b);
|
| 917 |
+
}
|
| 918 |
+
|
| 919 |
+
template <>
|
| 920 |
+
Vectorized<int8_t> inline operator+(const Vectorized<int8_t>& a, const Vectorized<int8_t>& b) {
|
| 921 |
+
return _mm512_add_epi8(a, b);
|
| 922 |
+
}
|
| 923 |
+
|
| 924 |
+
template <>
|
| 925 |
+
Vectorized<uint8_t> inline operator+(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& b) {
|
| 926 |
+
return _mm512_add_epi8(a, b);
|
| 927 |
+
}
|
| 928 |
+
|
| 929 |
+
template <>
|
| 930 |
+
Vectorized<int64_t> inline operator-(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 931 |
+
return _mm512_sub_epi64(a, b);
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
template <>
|
| 935 |
+
Vectorized<int32_t> inline operator-(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 936 |
+
return _mm512_sub_epi32(a, b);
|
| 937 |
+
}
|
| 938 |
+
|
| 939 |
+
template <>
|
| 940 |
+
Vectorized<int16_t> inline operator-(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 941 |
+
return _mm512_sub_epi16(a, b);
|
| 942 |
+
}
|
| 943 |
+
|
| 944 |
+
template <>
|
| 945 |
+
Vectorized<int8_t> inline operator-(const Vectorized<int8_t>& a, const Vectorized<int8_t>& b) {
|
| 946 |
+
return _mm512_sub_epi8(a, b);
|
| 947 |
+
}
|
| 948 |
+
|
| 949 |
+
template <>
|
| 950 |
+
Vectorized<uint8_t> inline operator-(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& b) {
|
| 951 |
+
return _mm512_sub_epi8(a, b);
|
| 952 |
+
}
|
| 953 |
+
|
| 954 |
+
// Negation. Defined here so we can utilize operator-
|
| 955 |
+
inline Vectorized<int64_t> Vectorized<int64_t>::neg() const {
|
| 956 |
+
return Vectorized<int64_t>(0) - *this;
|
| 957 |
+
}
|
| 958 |
+
|
| 959 |
+
inline Vectorized<int32_t> Vectorized<int32_t>::neg() const {
|
| 960 |
+
return Vectorized<int32_t>(0) - *this;
|
| 961 |
+
}
|
| 962 |
+
|
| 963 |
+
inline Vectorized<int16_t> Vectorized<int16_t>::neg() const {
|
| 964 |
+
return Vectorized<int16_t>(0) - *this;
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
inline Vectorized<int8_t> Vectorized<int8_t>::neg() const {
|
| 968 |
+
return Vectorized<int8_t>(0) - *this;
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
inline Vectorized<uint8_t> Vectorized<uint8_t>::neg() const {
|
| 972 |
+
return Vectorized<uint8_t>(0) - *this;
|
| 973 |
+
}
|
| 974 |
+
|
| 975 |
+
template <>
|
| 976 |
+
Vectorized<int64_t> inline operator*(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 977 |
+
return _mm512_mullo_epi64(a, b);
|
| 978 |
+
}
|
| 979 |
+
|
| 980 |
+
template <>
|
| 981 |
+
Vectorized<int32_t> inline operator*(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 982 |
+
return _mm512_mullo_epi32(a, b);
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
template <>
|
| 986 |
+
Vectorized<int16_t> inline operator*(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 987 |
+
return _mm512_mullo_epi16(a, b);
|
| 988 |
+
}
|
| 989 |
+
|
| 990 |
+
template <typename T, typename Op>
|
| 991 |
+
Vectorized<T> inline int_elementwise_binary_512(const Vectorized<T>& a, const Vectorized<T>& b, Op op) {
|
| 992 |
+
T values_a[Vectorized<T>::size()];
|
| 993 |
+
T values_b[Vectorized<T>::size()];
|
| 994 |
+
a.store(values_a);
|
| 995 |
+
b.store(values_b);
|
| 996 |
+
for (int i = 0; i != Vectorized<T>::size(); i++) {
|
| 997 |
+
values_a[i] = op(values_a[i], values_b[i]);
|
| 998 |
+
}
|
| 999 |
+
return Vectorized<T>::loadu(values_a);
|
| 1000 |
+
}
|
| 1001 |
+
|
| 1002 |
+
template <>
|
| 1003 |
+
Vectorized<int8_t> inline operator*(const Vectorized<int8_t>& a, const Vectorized<int8_t>& b) {
|
| 1004 |
+
// We don't have an instruction for multiplying int8_t
|
| 1005 |
+
return int_elementwise_binary_512(a, b, std::multiplies<int8_t>());
|
| 1006 |
+
}
|
| 1007 |
+
|
| 1008 |
+
template <>
|
| 1009 |
+
Vectorized<uint8_t> inline operator*(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& b) {
|
| 1010 |
+
// We don't have an instruction for multiplying uint8_t
|
| 1011 |
+
return int_elementwise_binary_512(a, b, std::multiplies<uint8_t>());
|
| 1012 |
+
}
|
| 1013 |
+
|
| 1014 |
+
template <>
|
| 1015 |
+
Vectorized<int64_t> inline minimum(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 1016 |
+
return _mm512_min_epi64(a, b);
|
| 1017 |
+
}
|
| 1018 |
+
|
| 1019 |
+
template <>
|
| 1020 |
+
Vectorized<int32_t> inline minimum(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 1021 |
+
return _mm512_min_epi32(a, b);
|
| 1022 |
+
}
|
| 1023 |
+
|
| 1024 |
+
template <>
|
| 1025 |
+
Vectorized<int16_t> inline minimum(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 1026 |
+
return _mm512_min_epi16(a, b);
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
template <>
|
| 1030 |
+
Vectorized<int8_t> inline minimum(const Vectorized<int8_t>& a, const Vectorized<int8_t>& b) {
|
| 1031 |
+
return _mm512_min_epi8(a, b);
|
| 1032 |
+
}
|
| 1033 |
+
|
| 1034 |
+
template <>
|
| 1035 |
+
Vectorized<uint8_t> inline minimum(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& b) {
|
| 1036 |
+
return _mm512_min_epu8(a, b);
|
| 1037 |
+
}
|
| 1038 |
+
|
| 1039 |
+
template <>
|
| 1040 |
+
Vectorized<int64_t> inline maximum(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 1041 |
+
return _mm512_max_epi64(a, b);
|
| 1042 |
+
}
|
| 1043 |
+
|
| 1044 |
+
template <>
|
| 1045 |
+
Vectorized<int32_t> inline maximum(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 1046 |
+
return _mm512_max_epi32(a, b);
|
| 1047 |
+
}
|
| 1048 |
+
|
| 1049 |
+
template <>
|
| 1050 |
+
Vectorized<int16_t> inline maximum(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 1051 |
+
return _mm512_max_epi16(a, b);
|
| 1052 |
+
}
|
| 1053 |
+
|
| 1054 |
+
template <>
|
| 1055 |
+
Vectorized<int8_t> inline maximum(const Vectorized<int8_t>& a, const Vectorized<int8_t>& b) {
|
| 1056 |
+
return _mm512_max_epi8(a, b);
|
| 1057 |
+
}
|
| 1058 |
+
|
| 1059 |
+
template <>
|
| 1060 |
+
Vectorized<uint8_t> inline maximum(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& b) {
|
| 1061 |
+
return _mm512_max_epi8(a, b);
|
| 1062 |
+
}
|
| 1063 |
+
|
| 1064 |
+
template <>
|
| 1065 |
+
Vectorized<int64_t> inline clamp(const Vectorized<int64_t>& a, const Vectorized<int64_t>& min_val, const Vectorized<int64_t>& max_val) {
|
| 1066 |
+
return _mm512_min_epi64(max_val, _mm512_max_epi64(a, min_val));
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
+
template <>
|
| 1070 |
+
Vectorized<int32_t> inline clamp(const Vectorized<int32_t>& a, const Vectorized<int32_t>& min_val, const Vectorized<int32_t>& max_val) {
|
| 1071 |
+
return _mm512_min_epi32(max_val, _mm512_max_epi32(a, min_val));
|
| 1072 |
+
}
|
| 1073 |
+
|
| 1074 |
+
template <>
|
| 1075 |
+
Vectorized<int16_t> inline clamp(const Vectorized<int16_t>& a, const Vectorized<int16_t>& min_val, const Vectorized<int16_t>& max_val) {
|
| 1076 |
+
return _mm512_min_epi16(max_val, _mm512_max_epi16(a, min_val));
|
| 1077 |
+
}
|
| 1078 |
+
|
| 1079 |
+
template <>
|
| 1080 |
+
Vectorized<int8_t> inline clamp(const Vectorized<int8_t>& a, const Vectorized<int8_t>& min_val, const Vectorized<int8_t>& max_val) {
|
| 1081 |
+
return _mm512_min_epi8(max_val, _mm512_max_epi8(a, min_val));
|
| 1082 |
+
}
|
| 1083 |
+
|
| 1084 |
+
template <>
|
| 1085 |
+
Vectorized<uint8_t> inline clamp(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& min_val, const Vectorized<uint8_t>& max_val) {
|
| 1086 |
+
return _mm512_min_epu8(max_val, _mm512_max_epu8(a, min_val));
|
| 1087 |
+
}
|
| 1088 |
+
|
| 1089 |
+
template <>
|
| 1090 |
+
Vectorized<int64_t> inline clamp_max(const Vectorized<int64_t>& a, const Vectorized<int64_t>& max_val) {
|
| 1091 |
+
return _mm512_min_epi64(max_val, a);
|
| 1092 |
+
}
|
| 1093 |
+
|
| 1094 |
+
template <>
|
| 1095 |
+
Vectorized<int32_t> inline clamp_max(const Vectorized<int32_t>& a, const Vectorized<int32_t>& max_val) {
|
| 1096 |
+
return _mm512_min_epi32(max_val, a);
|
| 1097 |
+
}
|
| 1098 |
+
|
| 1099 |
+
template <>
|
| 1100 |
+
Vectorized<int16_t> inline clamp_max(const Vectorized<int16_t>& a, const Vectorized<int16_t>& max_val) {
|
| 1101 |
+
return _mm512_min_epi16(max_val, a);
|
| 1102 |
+
}
|
| 1103 |
+
|
| 1104 |
+
template <>
|
| 1105 |
+
Vectorized<int8_t> inline clamp_max(const Vectorized<int8_t>& a, const Vectorized<int8_t>& max_val) {
|
| 1106 |
+
return _mm512_min_epi8(max_val, a);
|
| 1107 |
+
}
|
| 1108 |
+
|
| 1109 |
+
template <>
|
| 1110 |
+
Vectorized<uint8_t> inline clamp_max(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& max_val) {
|
| 1111 |
+
return _mm512_min_epu8(max_val, a);
|
| 1112 |
+
}
|
| 1113 |
+
|
| 1114 |
+
template <>
|
| 1115 |
+
Vectorized<int64_t> inline clamp_min(const Vectorized<int64_t>& a, const Vectorized<int64_t>& min_val) {
|
| 1116 |
+
return _mm512_max_epi64(min_val, a);
|
| 1117 |
+
}
|
| 1118 |
+
|
| 1119 |
+
template <>
|
| 1120 |
+
Vectorized<int32_t> inline clamp_min(const Vectorized<int32_t>& a, const Vectorized<int32_t>& min_val) {
|
| 1121 |
+
return _mm512_max_epi32(min_val, a);
|
| 1122 |
+
}
|
| 1123 |
+
|
| 1124 |
+
template <>
|
| 1125 |
+
Vectorized<int16_t> inline clamp_min(const Vectorized<int16_t>& a, const Vectorized<int16_t>& min_val) {
|
| 1126 |
+
return _mm512_max_epi16(min_val, a);
|
| 1127 |
+
}
|
| 1128 |
+
|
| 1129 |
+
template <>
|
| 1130 |
+
Vectorized<int8_t> inline clamp_min(const Vectorized<int8_t>& a, const Vectorized<int8_t>& min_val) {
|
| 1131 |
+
return _mm512_max_epi8(min_val, a);
|
| 1132 |
+
}
|
| 1133 |
+
|
| 1134 |
+
template <>
|
| 1135 |
+
Vectorized<uint8_t> inline clamp_min(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& min_val) {
|
| 1136 |
+
return _mm512_max_epu8(min_val, a);
|
| 1137 |
+
}
|
| 1138 |
+
|
| 1139 |
+
template<typename T>
|
| 1140 |
+
Vectorized<int32_t> inline convert_to_int32(const T* ptr) {
|
| 1141 |
+
return Vectorized<int32_t>::loadu(ptr);
|
| 1142 |
+
}
|
| 1143 |
+
|
| 1144 |
+
template<>
|
| 1145 |
+
Vectorized<int32_t> inline convert_to_int32<int8_t>(const int8_t* ptr) {
|
| 1146 |
+
return _mm512_cvtepi8_epi32(_mm_loadu_si128(reinterpret_cast<const __m128i*>(ptr)));
|
| 1147 |
+
}
|
| 1148 |
+
|
| 1149 |
+
template<>
|
| 1150 |
+
Vectorized<int32_t> inline convert_to_int32<uint8_t>(const uint8_t* ptr) {
|
| 1151 |
+
return _mm512_cvtepu8_epi32(_mm_loadu_si128(reinterpret_cast<const __m128i*>(ptr)));
|
| 1152 |
+
}
|
| 1153 |
+
|
| 1154 |
+
template <>
|
| 1155 |
+
Vectorized<int64_t> inline operator/(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 1156 |
+
return int_elementwise_binary_512(a, b, std::divides<int64_t>());
|
| 1157 |
+
}
|
| 1158 |
+
template <>
|
| 1159 |
+
Vectorized<int32_t> inline operator/(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 1160 |
+
return int_elementwise_binary_512(a, b, std::divides<int32_t>());
|
| 1161 |
+
}
|
| 1162 |
+
template <>
|
| 1163 |
+
Vectorized<int16_t> inline operator/(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 1164 |
+
return int_elementwise_binary_512(a, b, std::divides<int16_t>());
|
| 1165 |
+
}
|
| 1166 |
+
template <>
|
| 1167 |
+
Vectorized<int8_t> inline operator/(const Vectorized<int8_t>& a, const Vectorized<int8_t>& b) {
|
| 1168 |
+
return int_elementwise_binary_512(a, b, std::divides<int8_t>());
|
| 1169 |
+
}
|
| 1170 |
+
template <>
|
| 1171 |
+
Vectorized<uint8_t> inline operator/(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& b) {
|
| 1172 |
+
return int_elementwise_binary_512(a, b, std::divides<uint8_t>());
|
| 1173 |
+
}
|
| 1174 |
+
|
| 1175 |
+
template<class T, typename std::enable_if_t<std::is_base_of<Vectorizedi, Vectorized<T>>::value, int> = 0>
|
| 1176 |
+
inline Vectorized<T> operator&(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 1177 |
+
return _mm512_and_si512(a, b);
|
| 1178 |
+
}
|
| 1179 |
+
template<class T, typename std::enable_if_t<std::is_base_of<Vectorizedi, Vectorized<T>>::value, int> = 0>
|
| 1180 |
+
inline Vectorized<T> operator|(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 1181 |
+
return _mm512_or_si512(a, b);
|
| 1182 |
+
}
|
| 1183 |
+
template<class T, typename std::enable_if_t<std::is_base_of<Vectorizedi, Vectorized<T>>::value, int> = 0>
|
| 1184 |
+
inline Vectorized<T> operator^(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 1185 |
+
return _mm512_xor_si512(a, b);
|
| 1186 |
+
}
|
| 1187 |
+
template<class T, typename std::enable_if_t<std::is_base_of<Vectorizedi, Vectorized<T>>::value, int> = 0>
|
| 1188 |
+
inline Vectorized<T> operator~(const Vectorized<T>& a) {
|
| 1189 |
+
return _mm512_xor_si512(a, _mm512_set1_epi32(-1));
|
| 1190 |
+
}
|
| 1191 |
+
|
| 1192 |
+
inline Vectorized<int64_t> Vectorized<int64_t>::eq(const Vectorized<int64_t>& other) const {
|
| 1193 |
+
return (*this == other) & Vectorized<int64_t>(1);
|
| 1194 |
+
}
|
| 1195 |
+
|
| 1196 |
+
inline Vectorized<int64_t> Vectorized<int64_t>::ne(const Vectorized<int64_t>& other) const {
|
| 1197 |
+
return (*this != other) & Vectorized<int64_t>(1);
|
| 1198 |
+
}
|
| 1199 |
+
|
| 1200 |
+
inline Vectorized<int64_t> Vectorized<int64_t>::gt(const Vectorized<int64_t>& other) const {
|
| 1201 |
+
return (*this > other) & Vectorized<int64_t>(1);
|
| 1202 |
+
}
|
| 1203 |
+
|
| 1204 |
+
inline Vectorized<int64_t> Vectorized<int64_t>::ge(const Vectorized<int64_t>& other) const {
|
| 1205 |
+
return (*this >= other) & Vectorized<int64_t>(1);
|
| 1206 |
+
}
|
| 1207 |
+
|
| 1208 |
+
inline Vectorized<int64_t> Vectorized<int64_t>::lt(const Vectorized<int64_t>& other) const {
|
| 1209 |
+
return (*this < other) & Vectorized<int64_t>(1);
|
| 1210 |
+
}
|
| 1211 |
+
|
| 1212 |
+
inline Vectorized<int64_t> Vectorized<int64_t>::le(const Vectorized<int64_t>& other) const {
|
| 1213 |
+
return (*this <= other) & Vectorized<int64_t>(1);
|
| 1214 |
+
}
|
| 1215 |
+
|
| 1216 |
+
inline Vectorized<int32_t> Vectorized<int32_t>::eq(const Vectorized<int32_t>& other) const {
|
| 1217 |
+
return (*this == other) & Vectorized<int32_t>(1);
|
| 1218 |
+
}
|
| 1219 |
+
|
| 1220 |
+
inline Vectorized<int32_t> Vectorized<int32_t>::ne(const Vectorized<int32_t>& other) const {
|
| 1221 |
+
return (*this != other) & Vectorized<int32_t>(1);
|
| 1222 |
+
}
|
| 1223 |
+
|
| 1224 |
+
inline Vectorized<int32_t> Vectorized<int32_t>::gt(const Vectorized<int32_t>& other) const {
|
| 1225 |
+
return (*this > other) & Vectorized<int32_t>(1);
|
| 1226 |
+
}
|
| 1227 |
+
|
| 1228 |
+
inline Vectorized<int32_t> Vectorized<int32_t>::ge(const Vectorized<int32_t>& other) const {
|
| 1229 |
+
return (*this >= other) & Vectorized<int32_t>(1);
|
| 1230 |
+
}
|
| 1231 |
+
|
| 1232 |
+
inline Vectorized<int32_t> Vectorized<int32_t>::lt(const Vectorized<int32_t>& other) const {
|
| 1233 |
+
return (*this < other) & Vectorized<int32_t>(1);
|
| 1234 |
+
}
|
| 1235 |
+
|
| 1236 |
+
inline Vectorized<int32_t> Vectorized<int32_t>::le(const Vectorized<int32_t>& other) const {
|
| 1237 |
+
return (*this <= other) & Vectorized<int32_t>(1);
|
| 1238 |
+
}
|
| 1239 |
+
|
| 1240 |
+
inline Vectorized<int16_t> Vectorized<int16_t>::eq(const Vectorized<int16_t>& other) const {
|
| 1241 |
+
return (*this == other) & Vectorized<int16_t>(1);
|
| 1242 |
+
}
|
| 1243 |
+
|
| 1244 |
+
inline Vectorized<int16_t> Vectorized<int16_t>::ne(const Vectorized<int16_t>& other) const {
|
| 1245 |
+
return (*this != other) & Vectorized<int16_t>(1);
|
| 1246 |
+
}
|
| 1247 |
+
|
| 1248 |
+
inline Vectorized<int16_t> Vectorized<int16_t>::gt(const Vectorized<int16_t>& other) const {
|
| 1249 |
+
return (*this > other) & Vectorized<int16_t>(1);
|
| 1250 |
+
}
|
| 1251 |
+
|
| 1252 |
+
inline Vectorized<int16_t> Vectorized<int16_t>::ge(const Vectorized<int16_t>& other) const {
|
| 1253 |
+
return (*this >= other) & Vectorized<int16_t>(1);
|
| 1254 |
+
}
|
| 1255 |
+
|
| 1256 |
+
inline Vectorized<int16_t> Vectorized<int16_t>::lt(const Vectorized<int16_t>& other) const {
|
| 1257 |
+
return (*this < other) & Vectorized<int16_t>(1);
|
| 1258 |
+
}
|
| 1259 |
+
|
| 1260 |
+
inline Vectorized<int16_t> Vectorized<int16_t>::le(const Vectorized<int16_t>& other) const {
|
| 1261 |
+
return (*this <= other) & Vectorized<int16_t>(1);
|
| 1262 |
+
}
|
| 1263 |
+
|
| 1264 |
+
inline Vectorized<int8_t> Vectorized<int8_t>::eq(const Vectorized<int8_t>& other) const {
|
| 1265 |
+
return (*this == other) & Vectorized<int8_t>(1);
|
| 1266 |
+
}
|
| 1267 |
+
|
| 1268 |
+
inline Vectorized<int8_t> Vectorized<int8_t>::ne(const Vectorized<int8_t>& other) const {
|
| 1269 |
+
return (*this != other) & Vectorized<int8_t>(1);
|
| 1270 |
+
}
|
| 1271 |
+
|
| 1272 |
+
inline Vectorized<int8_t> Vectorized<int8_t>::gt(const Vectorized<int8_t>& other) const {
|
| 1273 |
+
return (*this > other) & Vectorized<int8_t>(1);
|
| 1274 |
+
}
|
| 1275 |
+
|
| 1276 |
+
inline Vectorized<int8_t> Vectorized<int8_t>::ge(const Vectorized<int8_t>& other) const {
|
| 1277 |
+
return (*this >= other) & Vectorized<int8_t>(1);
|
| 1278 |
+
}
|
| 1279 |
+
|
| 1280 |
+
inline Vectorized<int8_t> Vectorized<int8_t>::lt(const Vectorized<int8_t>& other) const {
|
| 1281 |
+
return (*this < other) & Vectorized<int8_t>(1);
|
| 1282 |
+
}
|
| 1283 |
+
|
| 1284 |
+
inline Vectorized<int8_t> Vectorized<int8_t>::le(const Vectorized<int8_t>& other) const {
|
| 1285 |
+
return (*this <= other) & Vectorized<int8_t>(1);
|
| 1286 |
+
}
|
| 1287 |
+
|
| 1288 |
+
inline Vectorized<uint8_t> Vectorized<uint8_t>::eq(const Vectorized<uint8_t>& other) const {
|
| 1289 |
+
return (*this == other) & Vectorized<uint8_t>(1);
|
| 1290 |
+
}
|
| 1291 |
+
|
| 1292 |
+
inline Vectorized<uint8_t> Vectorized<uint8_t>::ne(const Vectorized<uint8_t>& other) const {
|
| 1293 |
+
return (*this != other) & Vectorized<uint8_t>(1);
|
| 1294 |
+
}
|
| 1295 |
+
|
| 1296 |
+
inline Vectorized<uint8_t> Vectorized<uint8_t>::gt(const Vectorized<uint8_t>& other) const {
|
| 1297 |
+
return (*this > other) & Vectorized<uint8_t>(1);
|
| 1298 |
+
}
|
| 1299 |
+
|
| 1300 |
+
inline Vectorized<uint8_t> Vectorized<uint8_t>::ge(const Vectorized<uint8_t>& other) const {
|
| 1301 |
+
return (*this >= other) & Vectorized<uint8_t>(1);
|
| 1302 |
+
}
|
| 1303 |
+
|
| 1304 |
+
inline Vectorized<uint8_t> Vectorized<uint8_t>::lt(const Vectorized<uint8_t>& other) const {
|
| 1305 |
+
return (*this < other) & Vectorized<uint8_t>(1);
|
| 1306 |
+
}
|
| 1307 |
+
|
| 1308 |
+
inline Vectorized<uint8_t> Vectorized<uint8_t>::le(const Vectorized<uint8_t>& other) const {
|
| 1309 |
+
return (*this <= other) & Vectorized<uint8_t>(1);
|
| 1310 |
+
}
|
| 1311 |
+
|
| 1312 |
+
template <bool left_shift, typename T, typename std::enable_if_t<std::is_same<T, int8_t>::value || std::is_same<T, uint8_t>::value, int> = 0>
|
| 1313 |
+
Vectorized<T> inline shift_512_8(const Vectorized<T>& a, const Vectorized<T>& b) {
|
| 1314 |
+
// No vector instruction for shifting int8_t/uint8_t, so emulating
|
| 1315 |
+
// it instead.
|
| 1316 |
+
|
| 1317 |
+
// Control masks for shuffle operation, treating 512 bits as an
|
| 1318 |
+
// array of 8-bit elements, and considering pairs of neighboring
|
| 1319 |
+
// elements. Specifially, a mask named "ctl_M_N" (M,N in [0,1], and
|
| 1320 |
+
// M!=N) is set so that shuffle will move element with index M from
|
| 1321 |
+
// input pair into element with index N in output pair, and element
|
| 1322 |
+
// with index M in output pair will be set to all 0s.
|
| 1323 |
+
__m512i ctl_0_1 = _mm512_set_epi8(62, 0x80, 60, 0x80, 58, 0x80, 56, 0x80,
|
| 1324 |
+
54, 0x80, 52, 0x80, 50, 0x80, 48, 0x80,
|
| 1325 |
+
46, 0x80, 44, 0x80, 42, 0x80, 40, 0x80,
|
| 1326 |
+
38, 0x80, 36, 0x80, 34, 0x80, 32, 0x80,
|
| 1327 |
+
30, 0x80, 28, 0x80, 26, 0x80, 24, 0x80,
|
| 1328 |
+
22, 0x80, 20, 0x80, 18, 0x80, 16, 0x80,
|
| 1329 |
+
14, 0x80, 12, 0x80, 10, 0x80, 8, 0x80,
|
| 1330 |
+
6, 0x80, 4, 0x80, 2, 0x80, 0, 0x80);
|
| 1331 |
+
__m512i ctl_1_0 = _mm512_set_epi8(0x80, 63, 0x80, 61, 0x80, 59, 0x80, 57,
|
| 1332 |
+
0x80, 55, 0x80, 53, 0x80, 51, 0x80, 49,
|
| 1333 |
+
0x80, 47, 0x80, 45, 0x80, 43, 0x80, 41,
|
| 1334 |
+
0x80, 39, 0x80, 37, 0x80, 35, 0x80, 33,
|
| 1335 |
+
0x80, 31, 0x80, 29, 0x80, 27, 0x80, 25,
|
| 1336 |
+
0x80, 23, 0x80, 21, 0x80, 19, 0x80, 17,
|
| 1337 |
+
0x80, 15, 0x80, 13, 0x80, 11, 0x80, 9,
|
| 1338 |
+
0x80, 7, 0x80, 5, 0x80, 3, 0x80, 1);
|
| 1339 |
+
|
| 1340 |
+
// Masks for bitwise and operation, treating 512 bits as an array of
|
| 1341 |
+
// 8-bit elements, and considering them in pairs of neighboring
|
| 1342 |
+
// elements. A mask named "keep_M" (M in [0,1]) is set so that
|
| 1343 |
+
// bitwise and will copy element with index M from input pair into
|
| 1344 |
+
// element with the same index in output pair, while the other
|
| 1345 |
+
// element in output pair will be set to all 0s.
|
| 1346 |
+
__m512i keep_0 = _mm512_set1_epi16(0xFF);
|
| 1347 |
+
__m512i keep_1 = _mm512_set1_epi16(0xFF00);
|
| 1348 |
+
|
| 1349 |
+
// Take each 8-bit element with idx%2==0 from input array to be
|
| 1350 |
+
// shifted and extend it to 16 bits so that 0s are added to the
|
| 1351 |
+
// right. Then, perform shifting on this 16-bit number. Upper 8
|
| 1352 |
+
// bits will be proper result of shifting original 8-bit number, so
|
| 1353 |
+
// write them to result array, into the same position from which
|
| 1354 |
+
// corresponding input element is taken. Also, make sure that
|
| 1355 |
+
// result array elements with idx%2!=0 are set to all 0s.
|
| 1356 |
+
//
|
| 1357 |
+
// Note that number of bits to shift for is extended to 16 bits by
|
| 1358 |
+
// adding 0s to the left. That means this number is not properly
|
| 1359 |
+
// sign-extended for negative values. However, number of bits to
|
| 1360 |
+
// shift is treated as an unsigned integer by respective shift
|
| 1361 |
+
// intrinsics anyway so if negative then either with or without
|
| 1362 |
+
// proper sign extension, it will be interpreted as a number greater
|
| 1363 |
+
// than 32, and the shifting result will be the same.
|
| 1364 |
+
__m512i a0 = _mm512_shuffle_epi8(a, ctl_0_1);
|
| 1365 |
+
__m512i b0 = _mm512_and_si512(b, keep_0);
|
| 1366 |
+
__m512i c0;
|
| 1367 |
+
if (left_shift)
|
| 1368 |
+
c0 = _mm512_sllv_epi16(a0, b0);
|
| 1369 |
+
else
|
| 1370 |
+
if constexpr (std::is_same_v<T, int8_t>)
|
| 1371 |
+
c0 = _mm512_srav_epi16(a0, b0);
|
| 1372 |
+
else
|
| 1373 |
+
c0 = _mm512_srlv_epi16(a0, b0);
|
| 1374 |
+
c0 = _mm512_shuffle_epi8(c0, ctl_1_0);
|
| 1375 |
+
|
| 1376 |
+
// Peform shifting the same way for input array elements with
|
| 1377 |
+
// idx%2==1.
|
| 1378 |
+
__m512i a1 = _mm512_and_si512(a, keep_1);
|
| 1379 |
+
__m512i b1 = _mm512_shuffle_epi8(b, ctl_1_0);
|
| 1380 |
+
__m512i c1;
|
| 1381 |
+
if (left_shift)
|
| 1382 |
+
c1 = _mm512_sllv_epi16(a1, b1);
|
| 1383 |
+
else
|
| 1384 |
+
if constexpr (std::is_same_v<T, int8_t>)
|
| 1385 |
+
c1 = _mm512_srav_epi16(a1, b1);
|
| 1386 |
+
else
|
| 1387 |
+
c1 = _mm512_srlv_epi16(a1, b1);
|
| 1388 |
+
c1 = _mm512_and_si512(c1, keep_1);
|
| 1389 |
+
|
| 1390 |
+
// Merge partial results into the final result.
|
| 1391 |
+
__m512i c = _mm512_or_si512(c0, c1);
|
| 1392 |
+
|
| 1393 |
+
return c;
|
| 1394 |
+
}
|
| 1395 |
+
|
| 1396 |
+
template <>
|
| 1397 |
+
Vectorized<int64_t> inline operator<<(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 1398 |
+
return _mm512_sllv_epi64(a, b);
|
| 1399 |
+
}
|
| 1400 |
+
|
| 1401 |
+
template <>
|
| 1402 |
+
Vectorized<int32_t> inline operator<<(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 1403 |
+
return _mm512_sllv_epi32(a, b);
|
| 1404 |
+
}
|
| 1405 |
+
|
| 1406 |
+
template <>
|
| 1407 |
+
Vectorized<int16_t> inline operator<<(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 1408 |
+
return _mm512_sllv_epi16(a, b);
|
| 1409 |
+
}
|
| 1410 |
+
|
| 1411 |
+
template <>
|
| 1412 |
+
Vectorized<int8_t> inline operator<<(const Vectorized<int8_t>& a, const Vectorized<int8_t>& b) {
|
| 1413 |
+
return shift_512_8<true>(a, b);
|
| 1414 |
+
}
|
| 1415 |
+
|
| 1416 |
+
template <>
|
| 1417 |
+
Vectorized<uint8_t> inline operator<<(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& b) {
|
| 1418 |
+
return shift_512_8<true>(a, b);
|
| 1419 |
+
}
|
| 1420 |
+
|
| 1421 |
+
template <>
|
| 1422 |
+
Vectorized<int64_t> inline operator>>(const Vectorized<int64_t>& a, const Vectorized<int64_t>& b) {
|
| 1423 |
+
return _mm512_srav_epi64(a, b);
|
| 1424 |
+
}
|
| 1425 |
+
|
| 1426 |
+
template <>
|
| 1427 |
+
Vectorized<int32_t> inline operator>>(const Vectorized<int32_t>& a, const Vectorized<int32_t>& b) {
|
| 1428 |
+
return _mm512_srav_epi32(a, b);
|
| 1429 |
+
}
|
| 1430 |
+
|
| 1431 |
+
template <>
|
| 1432 |
+
Vectorized<int16_t> inline operator>>(const Vectorized<int16_t>& a, const Vectorized<int16_t>& b) {
|
| 1433 |
+
return _mm512_srav_epi16(a, b);
|
| 1434 |
+
}
|
| 1435 |
+
|
| 1436 |
+
template <>
|
| 1437 |
+
Vectorized<int8_t> inline operator>>(const Vectorized<int8_t>& a, const Vectorized<int8_t>& b) {
|
| 1438 |
+
return shift_512_8<false>(a, b);
|
| 1439 |
+
}
|
| 1440 |
+
|
| 1441 |
+
template <>
|
| 1442 |
+
Vectorized<uint8_t> inline operator>>(const Vectorized<uint8_t>& a, const Vectorized<uint8_t>& b) {
|
| 1443 |
+
return shift_512_8<false>(a, b);
|
| 1444 |
+
}
|
| 1445 |
+
|
| 1446 |
+
#endif
|
| 1447 |
+
|
| 1448 |
+
}}}
|
vllm/lib/python3.10/site-packages/wandb/integration/keras/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tools for integrating `wandb` with [`Keras`](https://keras.io/)."""
|
| 2 |
+
|
| 3 |
+
__all__ = (
|
| 4 |
+
"WandbCallback",
|
| 5 |
+
"WandbMetricsLogger",
|
| 6 |
+
"WandbModelCheckpoint",
|
| 7 |
+
"WandbEvalCallback",
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
from .callbacks import WandbEvalCallback, WandbMetricsLogger, WandbModelCheckpoint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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import string
|
| 3 |
+
from typing import Any, Dict, List, Literal, Optional, Union
|
| 4 |
+
|
| 5 |
+
import tensorflow as tf # type: ignore
|
| 6 |
+
from tensorflow.keras import callbacks # type: ignore
|
| 7 |
+
|
| 8 |
+
import wandb
|
| 9 |
+
from wandb.sdk.lib import telemetry
|
| 10 |
+
from wandb.sdk.lib.paths import StrPath
|
| 11 |
+
|
| 12 |
+
from ..keras import patch_tf_keras
|
| 13 |
+
|
| 14 |
+
Mode = Literal["auto", "min", "max"]
|
| 15 |
+
SaveStrategy = Literal["epoch"]
|
| 16 |
+
|
| 17 |
+
patch_tf_keras()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class WandbModelCheckpoint(callbacks.ModelCheckpoint):
|
| 21 |
+
"""A checkpoint that periodically saves a Keras model or model weights.
|
| 22 |
+
|
| 23 |
+
Saved weights are uploaded to W&B as a `wandb.Artifact`.
|
| 24 |
+
|
| 25 |
+
Since this callback is subclassed from `tf.keras.callbacks.ModelCheckpoint`, the
|
| 26 |
+
checkpointing logic is taken care of by the parent callback. You can learn more
|
| 27 |
+
here: https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/ModelCheckpoint
|
| 28 |
+
|
| 29 |
+
This callback is to be used in conjunction with training using `model.fit()` to save
|
| 30 |
+
a model or weights (in a checkpoint file) at some interval. The model checkpoints
|
| 31 |
+
will be logged as W&B Artifacts. You can learn more here:
|
| 32 |
+
https://docs.wandb.ai/guides/artifacts
|
| 33 |
+
|
| 34 |
+
This callback provides the following features:
|
| 35 |
+
- Save the model that has achieved "best performance" based on "monitor".
|
| 36 |
+
- Save the model at the end of every epoch regardless of the performance.
|
| 37 |
+
- Save the model at the end of epoch or after a fixed number of training batches.
|
| 38 |
+
- Save only model weights, or save the whole model.
|
| 39 |
+
- Save the model either in SavedModel format or in `.h5` format.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
filepath: (Union[str, os.PathLike]) path to save the model file. `filepath`
|
| 43 |
+
can contain named formatting options, which will be filled by the value
|
| 44 |
+
of `epoch` and keys in `logs` (passed in `on_epoch_end`). For example:
|
| 45 |
+
if `filepath` is `model-{epoch:02d}-{val_loss:.2f}`, then the
|
| 46 |
+
model checkpoints will be saved with the epoch number and the
|
| 47 |
+
validation loss in the filename.
|
| 48 |
+
monitor: (str) The metric name to monitor. Default to "val_loss".
|
| 49 |
+
verbose: (int) Verbosity mode, 0 or 1. Mode 0 is silent, and mode 1
|
| 50 |
+
displays messages when the callback takes an action.
|
| 51 |
+
save_best_only: (bool) if `save_best_only=True`, it only saves when the model
|
| 52 |
+
is considered the "best" and the latest best model according to the
|
| 53 |
+
quantity monitored will not be overwritten. If `filepath` doesn't contain
|
| 54 |
+
formatting options like `{epoch}` then `filepath` will be overwritten by
|
| 55 |
+
each new better model locally. The model logged as an artifact will still be
|
| 56 |
+
associated with the correct `monitor`. Artifacts will be uploaded
|
| 57 |
+
continuously and versioned separately as a new best model is found.
|
| 58 |
+
save_weights_only: (bool) if True, then only the model's weights will be saved.
|
| 59 |
+
mode: (Mode) one of {'auto', 'min', 'max'}. For `val_acc`, this should be `max`,
|
| 60 |
+
for `val_loss` this should be `min`, etc.
|
| 61 |
+
save_freq: (Union[SaveStrategy, int]) `epoch` or integer. When using `'epoch'`,
|
| 62 |
+
the callback saves the model after each epoch. When using an integer, the
|
| 63 |
+
callback saves the model at end of this many batches.
|
| 64 |
+
Note that when monitoring validation metrics such as `val_acc` or `val_loss`,
|
| 65 |
+
save_freq must be set to "epoch" as those metrics are only available at the
|
| 66 |
+
end of an epoch.
|
| 67 |
+
initial_value_threshold: (Optional[float]) Floating point initial "best" value of the metric
|
| 68 |
+
to be monitored.
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
def __init__(
|
| 72 |
+
self,
|
| 73 |
+
filepath: StrPath,
|
| 74 |
+
monitor: str = "val_loss",
|
| 75 |
+
verbose: int = 0,
|
| 76 |
+
save_best_only: bool = False,
|
| 77 |
+
save_weights_only: bool = False,
|
| 78 |
+
mode: Mode = "auto",
|
| 79 |
+
save_freq: Union[SaveStrategy, int] = "epoch",
|
| 80 |
+
initial_value_threshold: Optional[float] = None,
|
| 81 |
+
**kwargs: Any,
|
| 82 |
+
) -> None:
|
| 83 |
+
super().__init__(
|
| 84 |
+
filepath=filepath,
|
| 85 |
+
monitor=monitor,
|
| 86 |
+
verbose=verbose,
|
| 87 |
+
save_best_only=save_best_only,
|
| 88 |
+
save_weights_only=save_weights_only,
|
| 89 |
+
mode=mode,
|
| 90 |
+
save_freq=save_freq,
|
| 91 |
+
initial_value_threshold=initial_value_threshold,
|
| 92 |
+
**kwargs,
|
| 93 |
+
)
|
| 94 |
+
if wandb.run is None:
|
| 95 |
+
raise wandb.Error(
|
| 96 |
+
"You must call `wandb.init()` before `WandbModelCheckpoint()`"
|
| 97 |
+
)
|
| 98 |
+
with telemetry.context(run=wandb.run) as tel:
|
| 99 |
+
tel.feature.keras_model_checkpoint = True
|
| 100 |
+
|
| 101 |
+
self.save_weights_only = save_weights_only
|
| 102 |
+
|
| 103 |
+
# User-friendly warning when trying to save the best model.
|
| 104 |
+
if self.save_best_only:
|
| 105 |
+
self._check_filepath()
|
| 106 |
+
|
| 107 |
+
self._is_old_tf_keras_version: Optional[bool] = None
|
| 108 |
+
|
| 109 |
+
def on_train_batch_end(
|
| 110 |
+
self, batch: int, logs: Optional[Dict[str, float]] = None
|
| 111 |
+
) -> None:
|
| 112 |
+
if self._should_save_on_batch(batch):
|
| 113 |
+
if self.is_old_tf_keras_version:
|
| 114 |
+
# Save the model and get filepath
|
| 115 |
+
self._save_model(epoch=self._current_epoch, logs=logs)
|
| 116 |
+
filepath = self._get_file_path(epoch=self._current_epoch, logs=logs)
|
| 117 |
+
else:
|
| 118 |
+
# Save the model and get filepath
|
| 119 |
+
self._save_model(epoch=self._current_epoch, batch=batch, logs=logs)
|
| 120 |
+
filepath = self._get_file_path(
|
| 121 |
+
epoch=self._current_epoch, batch=batch, logs=logs
|
| 122 |
+
)
|
| 123 |
+
# Log the model as artifact
|
| 124 |
+
aliases = ["latest", f"epoch_{self._current_epoch}_batch_{batch}"]
|
| 125 |
+
self._log_ckpt_as_artifact(filepath, aliases=aliases)
|
| 126 |
+
|
| 127 |
+
def on_epoch_end(self, epoch: int, logs: Optional[Dict[str, float]] = None) -> None:
|
| 128 |
+
super().on_epoch_end(epoch, logs)
|
| 129 |
+
# Check if model checkpoint is created at the end of epoch.
|
| 130 |
+
if self.save_freq == "epoch":
|
| 131 |
+
# Get filepath where the model checkpoint is saved.
|
| 132 |
+
if self.is_old_tf_keras_version:
|
| 133 |
+
filepath = self._get_file_path(epoch=epoch, logs=logs)
|
| 134 |
+
else:
|
| 135 |
+
filepath = self._get_file_path(epoch=epoch, batch=None, logs=logs)
|
| 136 |
+
# Log the model as artifact
|
| 137 |
+
aliases = ["latest", f"epoch_{epoch}"]
|
| 138 |
+
self._log_ckpt_as_artifact(filepath, aliases=aliases)
|
| 139 |
+
|
| 140 |
+
def _log_ckpt_as_artifact(
|
| 141 |
+
self, filepath: str, aliases: Optional[List[str]] = None
|
| 142 |
+
) -> None:
|
| 143 |
+
"""Log model checkpoint as W&B Artifact."""
|
| 144 |
+
try:
|
| 145 |
+
assert wandb.run is not None
|
| 146 |
+
model_checkpoint_artifact = wandb.Artifact(
|
| 147 |
+
f"run_{wandb.run.id}_model", type="model"
|
| 148 |
+
)
|
| 149 |
+
if os.path.isfile(filepath):
|
| 150 |
+
model_checkpoint_artifact.add_file(filepath)
|
| 151 |
+
elif os.path.isdir(filepath):
|
| 152 |
+
model_checkpoint_artifact.add_dir(filepath)
|
| 153 |
+
else:
|
| 154 |
+
raise FileNotFoundError(f"No such file or directory {filepath}")
|
| 155 |
+
wandb.log_artifact(model_checkpoint_artifact, aliases=aliases or [])
|
| 156 |
+
except ValueError:
|
| 157 |
+
# This error occurs when `save_best_only=True` and the model
|
| 158 |
+
# checkpoint is not saved for that epoch/batch. Since TF/Keras
|
| 159 |
+
# is giving friendly log, we can avoid clustering the stdout.
|
| 160 |
+
pass
|
| 161 |
+
|
| 162 |
+
def _check_filepath(self) -> None:
|
| 163 |
+
placeholders = []
|
| 164 |
+
for tup in string.Formatter().parse(self.filepath):
|
| 165 |
+
if tup[1] is not None:
|
| 166 |
+
placeholders.append(tup[1])
|
| 167 |
+
if len(placeholders) == 0:
|
| 168 |
+
wandb.termwarn(
|
| 169 |
+
"When using `save_best_only`, ensure that the `filepath` argument "
|
| 170 |
+
"contains formatting placeholders like `{epoch:02d}` or `{batch:02d}`. "
|
| 171 |
+
"This ensures correct interpretation of the logged artifacts.",
|
| 172 |
+
repeat=False,
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
@property
|
| 176 |
+
def is_old_tf_keras_version(self) -> Optional[bool]:
|
| 177 |
+
if self._is_old_tf_keras_version is None:
|
| 178 |
+
from wandb.util import parse_version
|
| 179 |
+
|
| 180 |
+
try:
|
| 181 |
+
if parse_version(tf.keras.__version__) < parse_version("2.6.0"):
|
| 182 |
+
self._is_old_tf_keras_version = True
|
| 183 |
+
else:
|
| 184 |
+
self._is_old_tf_keras_version = False
|
| 185 |
+
except AttributeError:
|
| 186 |
+
self._is_old_tf_keras_version = False
|
| 187 |
+
|
| 188 |
+
return self._is_old_tf_keras_version
|
vllm/lib/python3.10/site-packages/wandb/integration/sacred/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (5.78 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/integration/sagemaker/config.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import re
|
| 6 |
+
import warnings
|
| 7 |
+
from typing import Any
|
| 8 |
+
|
| 9 |
+
from . import files as sm_files
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def is_using_sagemaker() -> bool:
|
| 13 |
+
"""Returns whether we're in a SageMaker environment."""
|
| 14 |
+
return (
|
| 15 |
+
os.path.exists(sm_files.SM_PARAM_CONFIG) #
|
| 16 |
+
or "SM_TRAINING_ENV" in os.environ
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def parse_sm_config() -> dict[str, Any]:
|
| 21 |
+
"""Parses SageMaker configuration.
|
| 22 |
+
|
| 23 |
+
Returns:
|
| 24 |
+
A dictionary of SageMaker config keys/values
|
| 25 |
+
or an empty dict if not found.
|
| 26 |
+
SM_TRAINING_ENV is a json string of the
|
| 27 |
+
training environment variables set by SageMaker
|
| 28 |
+
and is only available when running in SageMaker,
|
| 29 |
+
but not in local mode.
|
| 30 |
+
SM_TRAINING_ENV is set by the SageMaker container and
|
| 31 |
+
contains arguments such as hyperparameters
|
| 32 |
+
and arguments passed to the training job.
|
| 33 |
+
"""
|
| 34 |
+
conf = {}
|
| 35 |
+
|
| 36 |
+
if os.path.exists(sm_files.SM_PARAM_CONFIG):
|
| 37 |
+
conf["sagemaker_training_job_name"] = os.getenv("TRAINING_JOB_NAME")
|
| 38 |
+
|
| 39 |
+
# Hyperparameter searches quote configs...
|
| 40 |
+
with open(sm_files.SM_PARAM_CONFIG) as fid:
|
| 41 |
+
for key, val in json.load(fid).items():
|
| 42 |
+
cast = val.strip('"')
|
| 43 |
+
if re.match(r"^-?[\d]+$", cast):
|
| 44 |
+
cast = int(cast)
|
| 45 |
+
elif re.match(r"^-?[.\d]+$", cast):
|
| 46 |
+
cast = float(cast)
|
| 47 |
+
conf[key] = cast
|
| 48 |
+
|
| 49 |
+
if env := os.environ.get("SM_TRAINING_ENV"):
|
| 50 |
+
try:
|
| 51 |
+
conf.update(json.loads(env))
|
| 52 |
+
except json.JSONDecodeError:
|
| 53 |
+
warnings.warn(
|
| 54 |
+
"Failed to parse SM_TRAINING_ENV not valid JSON string",
|
| 55 |
+
stacklevel=2,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
return conf
|
vllm/lib/python3.10/site-packages/wandb/integration/sb3/__init__.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .sb3 import WandbCallback
|
| 2 |
+
|
| 3 |
+
__all__ = ["WandbCallback"]
|
vllm/lib/python3.10/site-packages/wandb/integration/sb3/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (234 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/integration/sb3/__pycache__/sb3.cpython-310.pyc
ADDED
|
Binary file (4.79 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/integration/sb3/sb3.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""W&B callback for sb3.
|
| 2 |
+
|
| 3 |
+
Really simple callback to get logging for each tree
|
| 4 |
+
|
| 5 |
+
Example usage:
|
| 6 |
+
|
| 7 |
+
```python
|
| 8 |
+
import gym
|
| 9 |
+
from stable_baselines3 import PPO
|
| 10 |
+
from stable_baselines3.common.monitor import Monitor
|
| 11 |
+
from stable_baselines3.common.vec_env import DummyVecEnv, VecVideoRecorder
|
| 12 |
+
import wandb
|
| 13 |
+
from wandb.integration.sb3 import WandbCallback
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
config = {
|
| 17 |
+
"policy_type": "MlpPolicy",
|
| 18 |
+
"total_timesteps": 25000,
|
| 19 |
+
"env_name": "CartPole-v1",
|
| 20 |
+
}
|
| 21 |
+
run = wandb.init(
|
| 22 |
+
project="sb3",
|
| 23 |
+
config=config,
|
| 24 |
+
sync_tensorboard=True, # auto-upload sb3's tensorboard metrics
|
| 25 |
+
monitor_gym=True, # auto-upload the videos of agents playing the game
|
| 26 |
+
save_code=True, # optional
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def make_env():
|
| 31 |
+
env = gym.make(config["env_name"])
|
| 32 |
+
env = Monitor(env) # record stats such as returns
|
| 33 |
+
return env
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
env = DummyVecEnv([make_env])
|
| 37 |
+
env = VecVideoRecorder(
|
| 38 |
+
env, "videos", record_video_trigger=lambda x: x % 2000 == 0, video_length=200
|
| 39 |
+
)
|
| 40 |
+
model = PPO(config["policy_type"], env, verbose=1, tensorboard_log=f"runs")
|
| 41 |
+
model.learn(
|
| 42 |
+
total_timesteps=config["total_timesteps"],
|
| 43 |
+
callback=WandbCallback(
|
| 44 |
+
model_save_path=f"models/{run.id}",
|
| 45 |
+
gradient_save_freq=100,
|
| 46 |
+
log="all",
|
| 47 |
+
),
|
| 48 |
+
)
|
| 49 |
+
```
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
import logging
|
| 53 |
+
import os
|
| 54 |
+
from typing import Literal, Optional
|
| 55 |
+
|
| 56 |
+
from stable_baselines3.common.callbacks import BaseCallback # type: ignore
|
| 57 |
+
|
| 58 |
+
import wandb
|
| 59 |
+
from wandb.sdk.lib import telemetry as wb_telemetry
|
| 60 |
+
|
| 61 |
+
logger = logging.getLogger(__name__)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class WandbCallback(BaseCallback):
|
| 65 |
+
"""Callback for logging experiments to Weights and Biases.
|
| 66 |
+
|
| 67 |
+
Log SB3 experiments to Weights and Biases
|
| 68 |
+
- Added model tracking and uploading
|
| 69 |
+
- Added complete hyperparameters recording
|
| 70 |
+
- Added gradient logging
|
| 71 |
+
- Note that `wandb.init(...)` must be called before the WandbCallback can be used.
|
| 72 |
+
|
| 73 |
+
Args:
|
| 74 |
+
verbose: The verbosity of sb3 output
|
| 75 |
+
model_save_path: Path to the folder where the model will be saved, The default value is `None` so the model is not logged
|
| 76 |
+
model_save_freq: Frequency to save the model
|
| 77 |
+
gradient_save_freq: Frequency to log gradient. The default value is 0 so the gradients are not logged
|
| 78 |
+
log: What to log. One of "gradients", "parameters", or "all".
|
| 79 |
+
"""
|
| 80 |
+
|
| 81 |
+
def __init__(
|
| 82 |
+
self,
|
| 83 |
+
verbose: int = 0,
|
| 84 |
+
model_save_path: Optional[str] = None,
|
| 85 |
+
model_save_freq: int = 0,
|
| 86 |
+
gradient_save_freq: int = 0,
|
| 87 |
+
log: Optional[Literal["gradients", "parameters", "all"]] = "all",
|
| 88 |
+
) -> None:
|
| 89 |
+
super().__init__(verbose)
|
| 90 |
+
if wandb.run is None:
|
| 91 |
+
raise wandb.Error("You must call wandb.init() before WandbCallback()")
|
| 92 |
+
with wb_telemetry.context() as tel:
|
| 93 |
+
tel.feature.sb3 = True
|
| 94 |
+
self.model_save_freq = model_save_freq
|
| 95 |
+
self.model_save_path = model_save_path
|
| 96 |
+
self.gradient_save_freq = gradient_save_freq
|
| 97 |
+
if log not in ["gradients", "parameters", "all", None]:
|
| 98 |
+
wandb.termwarn(
|
| 99 |
+
"`log` must be one of `None`, 'gradients', 'parameters', or 'all', "
|
| 100 |
+
"falling back to 'all'"
|
| 101 |
+
)
|
| 102 |
+
log = "all"
|
| 103 |
+
self.log = log
|
| 104 |
+
# Create folder if needed
|
| 105 |
+
if self.model_save_path is not None:
|
| 106 |
+
os.makedirs(self.model_save_path, exist_ok=True)
|
| 107 |
+
self.path = os.path.join(self.model_save_path, "model.zip")
|
| 108 |
+
else:
|
| 109 |
+
assert (
|
| 110 |
+
self.model_save_freq == 0
|
| 111 |
+
), "to use the `model_save_freq` you have to set the `model_save_path` parameter"
|
| 112 |
+
|
| 113 |
+
def _init_callback(self) -> None:
|
| 114 |
+
d = {}
|
| 115 |
+
if "algo" not in d:
|
| 116 |
+
d["algo"] = type(self.model).__name__
|
| 117 |
+
for key in self.model.__dict__:
|
| 118 |
+
if key in wandb.config:
|
| 119 |
+
continue
|
| 120 |
+
if type(self.model.__dict__[key]) in [float, int, str]:
|
| 121 |
+
d[key] = self.model.__dict__[key]
|
| 122 |
+
else:
|
| 123 |
+
d[key] = str(self.model.__dict__[key])
|
| 124 |
+
if self.gradient_save_freq > 0:
|
| 125 |
+
wandb.watch(
|
| 126 |
+
self.model.policy,
|
| 127 |
+
log_freq=self.gradient_save_freq,
|
| 128 |
+
log=self.log,
|
| 129 |
+
)
|
| 130 |
+
wandb.config.setdefaults(d)
|
| 131 |
+
|
| 132 |
+
def _on_step(self) -> bool:
|
| 133 |
+
if self.model_save_freq > 0:
|
| 134 |
+
if self.model_save_path is not None:
|
| 135 |
+
if self.n_calls % self.model_save_freq == 0:
|
| 136 |
+
self.save_model()
|
| 137 |
+
return True
|
| 138 |
+
|
| 139 |
+
def _on_training_end(self) -> None:
|
| 140 |
+
if self.model_save_path is not None:
|
| 141 |
+
self.save_model()
|
| 142 |
+
|
| 143 |
+
def save_model(self) -> None:
|
| 144 |
+
self.model.save(self.path)
|
| 145 |
+
wandb.save(self.path, base_path=self.model_save_path)
|
| 146 |
+
if self.verbose > 1:
|
| 147 |
+
logger.info(f"Saving model checkpoint to {self.path}")
|
vllm/lib/python3.10/site-packages/wandb/integration/yolov8/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (174 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/integration/yolov8/yolov8.py
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Callable, Dict, List, Optional
|
| 2 |
+
|
| 3 |
+
from ultralytics.yolo.engine.model import YOLO
|
| 4 |
+
from ultralytics.yolo.engine.trainer import BaseTrainer
|
| 5 |
+
|
| 6 |
+
try:
|
| 7 |
+
from ultralytics.yolo.utils import RANK
|
| 8 |
+
from ultralytics.yolo.utils.torch_utils import get_flops, get_num_params
|
| 9 |
+
except ModuleNotFoundError:
|
| 10 |
+
from ultralytics.utils import RANK
|
| 11 |
+
from ultralytics.utils.torch_utils import get_flops, get_num_params
|
| 12 |
+
from ultralytics.yolo.v8.classify.train import ClassificationTrainer
|
| 13 |
+
|
| 14 |
+
import wandb
|
| 15 |
+
from wandb.sdk.lib import telemetry
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class WandbCallback:
|
| 19 |
+
"""An internal YOLO model wrapper that tracks metrics, and logs models to Weights & Biases.
|
| 20 |
+
|
| 21 |
+
Usage:
|
| 22 |
+
```python
|
| 23 |
+
from wandb.integration.yolov8.yolov8 import WandbCallback
|
| 24 |
+
|
| 25 |
+
model = YOLO("yolov8n.pt")
|
| 26 |
+
wandb_logger = WandbCallback(
|
| 27 |
+
model,
|
| 28 |
+
)
|
| 29 |
+
for event, callback_fn in wandb_logger.callbacks.items():
|
| 30 |
+
model.add_callback(event, callback_fn)
|
| 31 |
+
```
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
def __init__(
|
| 35 |
+
self,
|
| 36 |
+
yolo: YOLO,
|
| 37 |
+
run_name: Optional[str] = None,
|
| 38 |
+
project: Optional[str] = None,
|
| 39 |
+
tags: Optional[List[str]] = None,
|
| 40 |
+
resume: Optional[str] = None,
|
| 41 |
+
**kwargs: Optional[Any],
|
| 42 |
+
) -> None:
|
| 43 |
+
"""A utility class to manage wandb run and various callbacks for the ultralytics YOLOv8 framework.
|
| 44 |
+
|
| 45 |
+
Args:
|
| 46 |
+
yolo: A YOLOv8 model that's inherited from `:class:ultralytics.yolo.engine.model.YOLO`
|
| 47 |
+
run_name, str: The name of the Weights & Biases run, defaults to an auto generated run_name if `trainer.args.name` is not defined.
|
| 48 |
+
project, str: The name of the Weights & Biases project, defaults to `"YOLOv8"` if `trainer.args.project` is not defined.
|
| 49 |
+
tags, List[str]: A list of tags to be added to the Weights & Biases run, defaults to `["YOLOv8"]`.
|
| 50 |
+
resume, str: Whether to resume a previous run on Weights & Biases, defaults to `None`.
|
| 51 |
+
**kwargs: Additional arguments to be passed to `wandb.init()`.
|
| 52 |
+
"""
|
| 53 |
+
self.yolo = yolo
|
| 54 |
+
self.run_name = run_name
|
| 55 |
+
self.project = project
|
| 56 |
+
self.tags = tags
|
| 57 |
+
self.resume = resume
|
| 58 |
+
self.kwargs = kwargs
|
| 59 |
+
|
| 60 |
+
def on_pretrain_routine_start(self, trainer: BaseTrainer) -> None:
|
| 61 |
+
"""Starts a new wandb run to track the training process and log to Weights & Biases.
|
| 62 |
+
|
| 63 |
+
Args:
|
| 64 |
+
trainer: A task trainer that's inherited from `:class:ultralytics.yolo.engine.trainer.BaseTrainer`
|
| 65 |
+
that contains the model training and optimization routine.
|
| 66 |
+
"""
|
| 67 |
+
if wandb.run is None:
|
| 68 |
+
self.run = wandb.init(
|
| 69 |
+
name=self.run_name if self.run_name else trainer.args.name,
|
| 70 |
+
project=self.project
|
| 71 |
+
if self.project
|
| 72 |
+
else trainer.args.project or "YOLOv8",
|
| 73 |
+
tags=self.tags if self.tags else ["YOLOv8"],
|
| 74 |
+
config=vars(trainer.args),
|
| 75 |
+
resume=self.resume if self.resume else None,
|
| 76 |
+
**self.kwargs,
|
| 77 |
+
)
|
| 78 |
+
else:
|
| 79 |
+
self.run = wandb.run
|
| 80 |
+
assert self.run is not None
|
| 81 |
+
self.run.define_metric("epoch", hidden=True)
|
| 82 |
+
self.run.define_metric(
|
| 83 |
+
"train/*", step_metric="epoch", step_sync=True, summary="min"
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
self.run.define_metric(
|
| 87 |
+
"val/*", step_metric="epoch", step_sync=True, summary="min"
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
self.run.define_metric(
|
| 91 |
+
"metrics/*", step_metric="epoch", step_sync=True, summary="max"
|
| 92 |
+
)
|
| 93 |
+
self.run.define_metric(
|
| 94 |
+
"lr/*", step_metric="epoch", step_sync=True, summary="last"
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
with telemetry.context(run=wandb.run) as tel:
|
| 98 |
+
tel.feature.ultralytics_yolov8 = True
|
| 99 |
+
|
| 100 |
+
def on_pretrain_routine_end(self, trainer: BaseTrainer) -> None:
|
| 101 |
+
assert self.run is not None
|
| 102 |
+
self.run.summary.update(
|
| 103 |
+
{
|
| 104 |
+
"model/parameters": get_num_params(trainer.model),
|
| 105 |
+
"model/GFLOPs": round(get_flops(trainer.model), 3),
|
| 106 |
+
}
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
def on_train_epoch_start(self, trainer: BaseTrainer) -> None:
|
| 110 |
+
"""On train epoch start we only log epoch number to the Weights & Biases run."""
|
| 111 |
+
# We log the epoch number here to commit the previous step,
|
| 112 |
+
assert self.run is not None
|
| 113 |
+
self.run.log({"epoch": trainer.epoch + 1})
|
| 114 |
+
|
| 115 |
+
def on_train_epoch_end(self, trainer: BaseTrainer) -> None:
|
| 116 |
+
"""On train epoch end we log all the metrics to the Weights & Biases run."""
|
| 117 |
+
assert self.run is not None
|
| 118 |
+
self.run.log(
|
| 119 |
+
{
|
| 120 |
+
**trainer.metrics,
|
| 121 |
+
**trainer.label_loss_items(trainer.tloss, prefix="train"),
|
| 122 |
+
**trainer.lr,
|
| 123 |
+
},
|
| 124 |
+
)
|
| 125 |
+
# Currently only the detection and segmentation trainers save images to the save_dir
|
| 126 |
+
if not isinstance(trainer, ClassificationTrainer):
|
| 127 |
+
self.run.log(
|
| 128 |
+
{
|
| 129 |
+
"train_batch_images": [
|
| 130 |
+
wandb.Image(str(image_path), caption=image_path.stem)
|
| 131 |
+
for image_path in trainer.save_dir.glob("train_batch*.jpg")
|
| 132 |
+
]
|
| 133 |
+
}
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
def on_fit_epoch_end(self, trainer: BaseTrainer) -> None:
|
| 137 |
+
"""On fit epoch end we log all the best metrics and model detail to Weights & Biases run summary."""
|
| 138 |
+
assert self.run is not None
|
| 139 |
+
if trainer.epoch == 0:
|
| 140 |
+
speeds = [
|
| 141 |
+
trainer.validator.speed.get(
|
| 142 |
+
key,
|
| 143 |
+
)
|
| 144 |
+
for key in (1, "inference")
|
| 145 |
+
]
|
| 146 |
+
speed = speeds[0] if speeds[0] else speeds[1]
|
| 147 |
+
if speed:
|
| 148 |
+
self.run.summary.update(
|
| 149 |
+
{
|
| 150 |
+
"model/speed(ms/img)": round(speed, 3),
|
| 151 |
+
}
|
| 152 |
+
)
|
| 153 |
+
if trainer.best_fitness == trainer.fitness:
|
| 154 |
+
self.run.summary.update(
|
| 155 |
+
{
|
| 156 |
+
"best/epoch": trainer.epoch + 1,
|
| 157 |
+
**{f"best/{key}": val for key, val in trainer.metrics.items()},
|
| 158 |
+
}
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
def on_train_end(self, trainer: BaseTrainer) -> None:
|
| 162 |
+
"""On train end we log all the media, including plots, images and best model artifact to Weights & Biases."""
|
| 163 |
+
# Currently only the detection and segmentation trainers save images to the save_dir
|
| 164 |
+
assert self.run is not None
|
| 165 |
+
if not isinstance(trainer, ClassificationTrainer):
|
| 166 |
+
assert self.run is not None
|
| 167 |
+
self.run.log(
|
| 168 |
+
{
|
| 169 |
+
"plots": [
|
| 170 |
+
wandb.Image(str(image_path), caption=image_path.stem)
|
| 171 |
+
for image_path in trainer.save_dir.glob("*.png")
|
| 172 |
+
],
|
| 173 |
+
"val_images": [
|
| 174 |
+
wandb.Image(str(image_path), caption=image_path.stem)
|
| 175 |
+
for image_path in trainer.validator.save_dir.glob("val*.jpg")
|
| 176 |
+
],
|
| 177 |
+
},
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
if trainer.best.exists():
|
| 181 |
+
assert self.run is not None
|
| 182 |
+
self.run.log_artifact(
|
| 183 |
+
str(trainer.best),
|
| 184 |
+
type="model",
|
| 185 |
+
name=f"{self.run.name}_{trainer.args.task}.pt",
|
| 186 |
+
aliases=["best", f"epoch_{trainer.epoch + 1}"],
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
def on_model_save(self, trainer: BaseTrainer) -> None:
|
| 190 |
+
"""On model save we log the model as an artifact to Weights & Biases."""
|
| 191 |
+
assert self.run is not None
|
| 192 |
+
self.run.log_artifact(
|
| 193 |
+
str(trainer.last),
|
| 194 |
+
type="model",
|
| 195 |
+
name=f"{self.run.name}_{trainer.args.task}.pt",
|
| 196 |
+
aliases=["last", f"epoch_{trainer.epoch + 1}"],
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
def teardown(self, _trainer: BaseTrainer) -> None:
|
| 200 |
+
"""On teardown, we finish the Weights & Biases run and set it to None."""
|
| 201 |
+
assert self.run is not None
|
| 202 |
+
self.run.finish()
|
| 203 |
+
self.run = None
|
| 204 |
+
|
| 205 |
+
@property
|
| 206 |
+
def callbacks(
|
| 207 |
+
self,
|
| 208 |
+
) -> Dict[str, Callable]:
|
| 209 |
+
"""Property contains all the relevant callbacks to add to the YOLO model for the Weights & Biases logging."""
|
| 210 |
+
return {
|
| 211 |
+
"on_pretrain_routine_start": self.on_pretrain_routine_start,
|
| 212 |
+
"on_pretrain_routine_end": self.on_pretrain_routine_end,
|
| 213 |
+
"on_train_epoch_start": self.on_train_epoch_start,
|
| 214 |
+
"on_train_epoch_end": self.on_train_epoch_end,
|
| 215 |
+
"on_fit_epoch_end": self.on_fit_epoch_end,
|
| 216 |
+
"on_train_end": self.on_train_end,
|
| 217 |
+
"on_model_save": self.on_model_save,
|
| 218 |
+
"teardown": self.teardown,
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def add_callbacks(
|
| 223 |
+
yolo: YOLO,
|
| 224 |
+
run_name: Optional[str] = None,
|
| 225 |
+
project: Optional[str] = None,
|
| 226 |
+
tags: Optional[List[str]] = None,
|
| 227 |
+
resume: Optional[str] = None,
|
| 228 |
+
**kwargs: Optional[Any],
|
| 229 |
+
) -> YOLO:
|
| 230 |
+
"""A YOLO model wrapper that tracks metrics, and logs models to Weights & Biases.
|
| 231 |
+
|
| 232 |
+
Args:
|
| 233 |
+
yolo: A YOLOv8 model that's inherited from `:class:ultralytics.yolo.engine.model.YOLO`
|
| 234 |
+
run_name, str: The name of the Weights & Biases run, defaults to an auto generated name if `trainer.args.name` is not defined.
|
| 235 |
+
project, str: The name of the Weights & Biases project, defaults to `"YOLOv8"` if `trainer.args.project` is not defined.
|
| 236 |
+
tags, List[str]: A list of tags to be added to the Weights & Biases run, defaults to `["YOLOv8"]`.
|
| 237 |
+
resume, str: Whether to resume a previous run on Weights & Biases, defaults to `None`.
|
| 238 |
+
**kwargs: Additional arguments to be passed to `wandb.init()`.
|
| 239 |
+
|
| 240 |
+
Usage:
|
| 241 |
+
```python
|
| 242 |
+
from wandb.integration.yolov8 import add_callbacks as add_wandb_callbacks
|
| 243 |
+
|
| 244 |
+
model = YOLO("yolov8n.pt")
|
| 245 |
+
add_wandb_callbacks(
|
| 246 |
+
model,
|
| 247 |
+
)
|
| 248 |
+
model.train(
|
| 249 |
+
data="coco128.yaml",
|
| 250 |
+
epochs=3,
|
| 251 |
+
imgsz=640,
|
| 252 |
+
)
|
| 253 |
+
```
|
| 254 |
+
"""
|
| 255 |
+
wandb.termwarn(
|
| 256 |
+
"""The wandb callback is currently in beta and is subject to change based on updates to `ultralytics yolov8`.
|
| 257 |
+
The callback is tested and supported for ultralytics v8.0.43 and above.
|
| 258 |
+
Please report any issues to https://github.com/wandb/wandb/issues with the tag `yolov8`.
|
| 259 |
+
""",
|
| 260 |
+
repeat=False,
|
| 261 |
+
)
|
| 262 |
+
wandb.termwarn(
|
| 263 |
+
"""This wandb callback is no longer functional and would be deprecated in the near future.
|
| 264 |
+
We recommend you to use the updated callback using `from wandb.integration.ultralytics import add_wandb_callback`.
|
| 265 |
+
The updated callback is tested and supported for ultralytics 8.0.167 and above.
|
| 266 |
+
You can refer to https://docs.wandb.ai/guides/integrations/ultralytics for the updated documentation.
|
| 267 |
+
Please report any issues to https://github.com/wandb/wandb/issues with the tag `yolov8`.
|
| 268 |
+
""",
|
| 269 |
+
repeat=False,
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
if RANK in [-1, 0]:
|
| 273 |
+
wandb_logger = WandbCallback(
|
| 274 |
+
yolo, run_name=run_name, project=project, tags=tags, resume=resume, **kwargs
|
| 275 |
+
)
|
| 276 |
+
for event, callback_fn in wandb_logger.callbacks.items():
|
| 277 |
+
yolo.add_callback(event, callback_fn)
|
| 278 |
+
return yolo
|
| 279 |
+
else:
|
| 280 |
+
wandb.termerror(
|
| 281 |
+
"The RANK of the process to add the callbacks was neither 0 or -1."
|
| 282 |
+
"No Weights & Biases callbacks were added to this instance of the YOLO model."
|
| 283 |
+
)
|
| 284 |
+
return yolo
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/__init__.py
ADDED
|
File without changes
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/ast.py
ADDED
|
@@ -0,0 +1,1349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This is autogenerated code. DO NOT change this manually.
|
| 2 |
+
# Run scripts/generate_ast.py to generate this file.
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class Node(object):
|
| 6 |
+
__slots__ = ()
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Definition(Node):
|
| 10 |
+
__slots__ = ()
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class Document(Node):
|
| 14 |
+
__slots__ = ('loc', 'definitions',)
|
| 15 |
+
_fields = ('definitions',)
|
| 16 |
+
|
| 17 |
+
def __init__(self, definitions, loc=None):
|
| 18 |
+
self.loc = loc
|
| 19 |
+
self.definitions = definitions
|
| 20 |
+
|
| 21 |
+
def __eq__(self, other):
|
| 22 |
+
return (
|
| 23 |
+
self is other or (
|
| 24 |
+
isinstance(other, Document) and
|
| 25 |
+
# self.loc == other.loc and
|
| 26 |
+
self.definitions == other.definitions
|
| 27 |
+
)
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
def __repr__(self):
|
| 31 |
+
return ('Document('
|
| 32 |
+
'definitions={self.definitions!r}'
|
| 33 |
+
')').format(self=self)
|
| 34 |
+
|
| 35 |
+
def __copy__(self):
|
| 36 |
+
return type(self)(
|
| 37 |
+
self.definitions,
|
| 38 |
+
self.loc
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
def __hash__(self):
|
| 42 |
+
return id(self)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class OperationDefinition(Definition):
|
| 46 |
+
__slots__ = ('loc', 'operation', 'name', 'variable_definitions', 'directives', 'selection_set',)
|
| 47 |
+
_fields = ('operation', 'name', 'variable_definitions', 'directives', 'selection_set',)
|
| 48 |
+
|
| 49 |
+
def __init__(self, operation, selection_set, name=None, variable_definitions=None, directives=None, loc=None):
|
| 50 |
+
self.loc = loc
|
| 51 |
+
self.operation = operation
|
| 52 |
+
self.name = name
|
| 53 |
+
self.variable_definitions = variable_definitions
|
| 54 |
+
self.directives = directives
|
| 55 |
+
self.selection_set = selection_set
|
| 56 |
+
|
| 57 |
+
def __eq__(self, other):
|
| 58 |
+
return (
|
| 59 |
+
self is other or (
|
| 60 |
+
isinstance(other, OperationDefinition) and
|
| 61 |
+
# self.loc == other.loc and
|
| 62 |
+
self.operation == other.operation and
|
| 63 |
+
self.name == other.name and
|
| 64 |
+
self.variable_definitions == other.variable_definitions and
|
| 65 |
+
self.directives == other.directives and
|
| 66 |
+
self.selection_set == other.selection_set
|
| 67 |
+
)
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
def __repr__(self):
|
| 71 |
+
return ('OperationDefinition('
|
| 72 |
+
'operation={self.operation!r}'
|
| 73 |
+
', name={self.name!r}'
|
| 74 |
+
', variable_definitions={self.variable_definitions!r}'
|
| 75 |
+
', directives={self.directives!r}'
|
| 76 |
+
', selection_set={self.selection_set!r}'
|
| 77 |
+
')').format(self=self)
|
| 78 |
+
|
| 79 |
+
def __copy__(self):
|
| 80 |
+
return type(self)(
|
| 81 |
+
self.operation,
|
| 82 |
+
self.selection_set,
|
| 83 |
+
self.name,
|
| 84 |
+
self.variable_definitions,
|
| 85 |
+
self.directives,
|
| 86 |
+
self.loc
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
def __hash__(self):
|
| 90 |
+
return id(self)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class VariableDefinition(Node):
|
| 94 |
+
__slots__ = ('loc', 'variable', 'type', 'default_value',)
|
| 95 |
+
_fields = ('variable', 'type', 'default_value',)
|
| 96 |
+
|
| 97 |
+
def __init__(self, variable, type, default_value=None, loc=None):
|
| 98 |
+
self.loc = loc
|
| 99 |
+
self.variable = variable
|
| 100 |
+
self.type = type
|
| 101 |
+
self.default_value = default_value
|
| 102 |
+
|
| 103 |
+
def __eq__(self, other):
|
| 104 |
+
return (
|
| 105 |
+
self is other or (
|
| 106 |
+
isinstance(other, VariableDefinition) and
|
| 107 |
+
# self.loc == other.loc and
|
| 108 |
+
self.variable == other.variable and
|
| 109 |
+
self.type == other.type and
|
| 110 |
+
self.default_value == other.default_value
|
| 111 |
+
)
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
def __repr__(self):
|
| 115 |
+
return ('VariableDefinition('
|
| 116 |
+
'variable={self.variable!r}'
|
| 117 |
+
', type={self.type!r}'
|
| 118 |
+
', default_value={self.default_value!r}'
|
| 119 |
+
')').format(self=self)
|
| 120 |
+
|
| 121 |
+
def __copy__(self):
|
| 122 |
+
return type(self)(
|
| 123 |
+
self.variable,
|
| 124 |
+
self.type,
|
| 125 |
+
self.default_value,
|
| 126 |
+
self.loc
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
def __hash__(self):
|
| 130 |
+
return id(self)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
class SelectionSet(Node):
|
| 134 |
+
__slots__ = ('loc', 'selections',)
|
| 135 |
+
_fields = ('selections',)
|
| 136 |
+
|
| 137 |
+
def __init__(self, selections, loc=None):
|
| 138 |
+
self.loc = loc
|
| 139 |
+
self.selections = selections
|
| 140 |
+
|
| 141 |
+
def __eq__(self, other):
|
| 142 |
+
return (
|
| 143 |
+
self is other or (
|
| 144 |
+
isinstance(other, SelectionSet) and
|
| 145 |
+
# self.loc == other.loc and
|
| 146 |
+
self.selections == other.selections
|
| 147 |
+
)
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
def __repr__(self):
|
| 151 |
+
return ('SelectionSet('
|
| 152 |
+
'selections={self.selections!r}'
|
| 153 |
+
')').format(self=self)
|
| 154 |
+
|
| 155 |
+
def __copy__(self):
|
| 156 |
+
return type(self)(
|
| 157 |
+
self.selections,
|
| 158 |
+
self.loc
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
def __hash__(self):
|
| 162 |
+
return id(self)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
class Selection(Node):
|
| 166 |
+
__slots__ = ()
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
class Field(Selection):
|
| 170 |
+
__slots__ = ('loc', 'alias', 'name', 'arguments', 'directives', 'selection_set',)
|
| 171 |
+
_fields = ('alias', 'name', 'arguments', 'directives', 'selection_set',)
|
| 172 |
+
|
| 173 |
+
def __init__(self, name, alias=None, arguments=None, directives=None, selection_set=None, loc=None):
|
| 174 |
+
self.loc = loc
|
| 175 |
+
self.alias = alias
|
| 176 |
+
self.name = name
|
| 177 |
+
self.arguments = arguments
|
| 178 |
+
self.directives = directives
|
| 179 |
+
self.selection_set = selection_set
|
| 180 |
+
|
| 181 |
+
def __eq__(self, other):
|
| 182 |
+
return (
|
| 183 |
+
self is other or (
|
| 184 |
+
isinstance(other, Field) and
|
| 185 |
+
# self.loc == other.loc and
|
| 186 |
+
self.alias == other.alias and
|
| 187 |
+
self.name == other.name and
|
| 188 |
+
self.arguments == other.arguments and
|
| 189 |
+
self.directives == other.directives and
|
| 190 |
+
self.selection_set == other.selection_set
|
| 191 |
+
)
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
def __repr__(self):
|
| 195 |
+
return ('Field('
|
| 196 |
+
'alias={self.alias!r}'
|
| 197 |
+
', name={self.name!r}'
|
| 198 |
+
', arguments={self.arguments!r}'
|
| 199 |
+
', directives={self.directives!r}'
|
| 200 |
+
', selection_set={self.selection_set!r}'
|
| 201 |
+
')').format(self=self)
|
| 202 |
+
|
| 203 |
+
def __copy__(self):
|
| 204 |
+
return type(self)(
|
| 205 |
+
self.name,
|
| 206 |
+
self.alias,
|
| 207 |
+
self.arguments,
|
| 208 |
+
self.directives,
|
| 209 |
+
self.selection_set,
|
| 210 |
+
self.loc
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
+
def __hash__(self):
|
| 214 |
+
return id(self)
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
class Argument(Node):
|
| 218 |
+
__slots__ = ('loc', 'name', 'value',)
|
| 219 |
+
_fields = ('name', 'value',)
|
| 220 |
+
|
| 221 |
+
def __init__(self, name, value, loc=None):
|
| 222 |
+
self.loc = loc
|
| 223 |
+
self.name = name
|
| 224 |
+
self.value = value
|
| 225 |
+
|
| 226 |
+
def __eq__(self, other):
|
| 227 |
+
return (
|
| 228 |
+
self is other or (
|
| 229 |
+
isinstance(other, Argument) and
|
| 230 |
+
# self.loc == other.loc and
|
| 231 |
+
self.name == other.name and
|
| 232 |
+
self.value == other.value
|
| 233 |
+
)
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
def __repr__(self):
|
| 237 |
+
return ('Argument('
|
| 238 |
+
'name={self.name!r}'
|
| 239 |
+
', value={self.value!r}'
|
| 240 |
+
')').format(self=self)
|
| 241 |
+
|
| 242 |
+
def __copy__(self):
|
| 243 |
+
return type(self)(
|
| 244 |
+
self.name,
|
| 245 |
+
self.value,
|
| 246 |
+
self.loc
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
def __hash__(self):
|
| 250 |
+
return id(self)
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
class FragmentSpread(Selection):
|
| 254 |
+
__slots__ = ('loc', 'name', 'directives',)
|
| 255 |
+
_fields = ('name', 'directives',)
|
| 256 |
+
|
| 257 |
+
def __init__(self, name, directives=None, loc=None):
|
| 258 |
+
self.loc = loc
|
| 259 |
+
self.name = name
|
| 260 |
+
self.directives = directives
|
| 261 |
+
|
| 262 |
+
def __eq__(self, other):
|
| 263 |
+
return (
|
| 264 |
+
self is other or (
|
| 265 |
+
isinstance(other, FragmentSpread) and
|
| 266 |
+
# self.loc == other.loc and
|
| 267 |
+
self.name == other.name and
|
| 268 |
+
self.directives == other.directives
|
| 269 |
+
)
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
def __repr__(self):
|
| 273 |
+
return ('FragmentSpread('
|
| 274 |
+
'name={self.name!r}'
|
| 275 |
+
', directives={self.directives!r}'
|
| 276 |
+
')').format(self=self)
|
| 277 |
+
|
| 278 |
+
def __copy__(self):
|
| 279 |
+
return type(self)(
|
| 280 |
+
self.name,
|
| 281 |
+
self.directives,
|
| 282 |
+
self.loc
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
def __hash__(self):
|
| 286 |
+
return id(self)
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
class InlineFragment(Selection):
|
| 290 |
+
__slots__ = ('loc', 'type_condition', 'directives', 'selection_set',)
|
| 291 |
+
_fields = ('type_condition', 'directives', 'selection_set',)
|
| 292 |
+
|
| 293 |
+
def __init__(self, type_condition, selection_set, directives=None, loc=None):
|
| 294 |
+
self.loc = loc
|
| 295 |
+
self.type_condition = type_condition
|
| 296 |
+
self.directives = directives
|
| 297 |
+
self.selection_set = selection_set
|
| 298 |
+
|
| 299 |
+
def __eq__(self, other):
|
| 300 |
+
return (
|
| 301 |
+
self is other or (
|
| 302 |
+
isinstance(other, InlineFragment) and
|
| 303 |
+
# self.loc == other.loc and
|
| 304 |
+
self.type_condition == other.type_condition and
|
| 305 |
+
self.directives == other.directives and
|
| 306 |
+
self.selection_set == other.selection_set
|
| 307 |
+
)
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
def __repr__(self):
|
| 311 |
+
return ('InlineFragment('
|
| 312 |
+
'type_condition={self.type_condition!r}'
|
| 313 |
+
', directives={self.directives!r}'
|
| 314 |
+
', selection_set={self.selection_set!r}'
|
| 315 |
+
')').format(self=self)
|
| 316 |
+
|
| 317 |
+
def __copy__(self):
|
| 318 |
+
return type(self)(
|
| 319 |
+
self.type_condition,
|
| 320 |
+
self.selection_set,
|
| 321 |
+
self.directives,
|
| 322 |
+
self.loc
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
def __hash__(self):
|
| 326 |
+
return id(self)
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
class FragmentDefinition(Definition):
|
| 330 |
+
__slots__ = ('loc', 'name', 'type_condition', 'directives', 'selection_set',)
|
| 331 |
+
_fields = ('name', 'type_condition', 'directives', 'selection_set',)
|
| 332 |
+
|
| 333 |
+
def __init__(self, name, type_condition, selection_set, directives=None, loc=None):
|
| 334 |
+
self.loc = loc
|
| 335 |
+
self.name = name
|
| 336 |
+
self.type_condition = type_condition
|
| 337 |
+
self.directives = directives
|
| 338 |
+
self.selection_set = selection_set
|
| 339 |
+
|
| 340 |
+
def __eq__(self, other):
|
| 341 |
+
return (
|
| 342 |
+
self is other or (
|
| 343 |
+
isinstance(other, FragmentDefinition) and
|
| 344 |
+
# self.loc == other.loc and
|
| 345 |
+
self.name == other.name and
|
| 346 |
+
self.type_condition == other.type_condition and
|
| 347 |
+
self.directives == other.directives and
|
| 348 |
+
self.selection_set == other.selection_set
|
| 349 |
+
)
|
| 350 |
+
)
|
| 351 |
+
|
| 352 |
+
def __repr__(self):
|
| 353 |
+
return ('FragmentDefinition('
|
| 354 |
+
'name={self.name!r}'
|
| 355 |
+
', type_condition={self.type_condition!r}'
|
| 356 |
+
', directives={self.directives!r}'
|
| 357 |
+
', selection_set={self.selection_set!r}'
|
| 358 |
+
')').format(self=self)
|
| 359 |
+
|
| 360 |
+
def __copy__(self):
|
| 361 |
+
return type(self)(
|
| 362 |
+
self.name,
|
| 363 |
+
self.type_condition,
|
| 364 |
+
self.selection_set,
|
| 365 |
+
self.directives,
|
| 366 |
+
self.loc
|
| 367 |
+
)
|
| 368 |
+
|
| 369 |
+
def __hash__(self):
|
| 370 |
+
return id(self)
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
class Value(Node):
|
| 374 |
+
__slots__ = ()
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
class Variable(Value):
|
| 378 |
+
__slots__ = ('loc', 'name',)
|
| 379 |
+
_fields = ('name',)
|
| 380 |
+
|
| 381 |
+
def __init__(self, name, loc=None):
|
| 382 |
+
self.loc = loc
|
| 383 |
+
self.name = name
|
| 384 |
+
|
| 385 |
+
def __eq__(self, other):
|
| 386 |
+
return (
|
| 387 |
+
self is other or (
|
| 388 |
+
isinstance(other, Variable) and
|
| 389 |
+
# self.loc == other.loc and
|
| 390 |
+
self.name == other.name
|
| 391 |
+
)
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
+
def __repr__(self):
|
| 395 |
+
return ('Variable('
|
| 396 |
+
'name={self.name!r}'
|
| 397 |
+
')').format(self=self)
|
| 398 |
+
|
| 399 |
+
def __copy__(self):
|
| 400 |
+
return type(self)(
|
| 401 |
+
self.name,
|
| 402 |
+
self.loc
|
| 403 |
+
)
|
| 404 |
+
|
| 405 |
+
def __hash__(self):
|
| 406 |
+
return id(self)
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
class IntValue(Value):
|
| 410 |
+
__slots__ = ('loc', 'value',)
|
| 411 |
+
_fields = ('value',)
|
| 412 |
+
|
| 413 |
+
def __init__(self, value, loc=None):
|
| 414 |
+
self.loc = loc
|
| 415 |
+
self.value = value
|
| 416 |
+
|
| 417 |
+
def __eq__(self, other):
|
| 418 |
+
return (
|
| 419 |
+
self is other or (
|
| 420 |
+
isinstance(other, IntValue) and
|
| 421 |
+
# self.loc == other.loc and
|
| 422 |
+
self.value == other.value
|
| 423 |
+
)
|
| 424 |
+
)
|
| 425 |
+
|
| 426 |
+
def __repr__(self):
|
| 427 |
+
return ('IntValue('
|
| 428 |
+
'value={self.value!r}'
|
| 429 |
+
')').format(self=self)
|
| 430 |
+
|
| 431 |
+
def __copy__(self):
|
| 432 |
+
return type(self)(
|
| 433 |
+
self.value,
|
| 434 |
+
self.loc
|
| 435 |
+
)
|
| 436 |
+
|
| 437 |
+
def __hash__(self):
|
| 438 |
+
return id(self)
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
class FloatValue(Value):
|
| 442 |
+
__slots__ = ('loc', 'value',)
|
| 443 |
+
_fields = ('value',)
|
| 444 |
+
|
| 445 |
+
def __init__(self, value, loc=None):
|
| 446 |
+
self.loc = loc
|
| 447 |
+
self.value = value
|
| 448 |
+
|
| 449 |
+
def __eq__(self, other):
|
| 450 |
+
return (
|
| 451 |
+
self is other or (
|
| 452 |
+
isinstance(other, FloatValue) and
|
| 453 |
+
# self.loc == other.loc and
|
| 454 |
+
self.value == other.value
|
| 455 |
+
)
|
| 456 |
+
)
|
| 457 |
+
|
| 458 |
+
def __repr__(self):
|
| 459 |
+
return ('FloatValue('
|
| 460 |
+
'value={self.value!r}'
|
| 461 |
+
')').format(self=self)
|
| 462 |
+
|
| 463 |
+
def __copy__(self):
|
| 464 |
+
return type(self)(
|
| 465 |
+
self.value,
|
| 466 |
+
self.loc
|
| 467 |
+
)
|
| 468 |
+
|
| 469 |
+
def __hash__(self):
|
| 470 |
+
return id(self)
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
class StringValue(Value):
|
| 474 |
+
__slots__ = ('loc', 'value',)
|
| 475 |
+
_fields = ('value',)
|
| 476 |
+
|
| 477 |
+
def __init__(self, value, loc=None):
|
| 478 |
+
self.loc = loc
|
| 479 |
+
self.value = value
|
| 480 |
+
|
| 481 |
+
def __eq__(self, other):
|
| 482 |
+
return (
|
| 483 |
+
self is other or (
|
| 484 |
+
isinstance(other, StringValue) and
|
| 485 |
+
# self.loc == other.loc and
|
| 486 |
+
self.value == other.value
|
| 487 |
+
)
|
| 488 |
+
)
|
| 489 |
+
|
| 490 |
+
def __repr__(self):
|
| 491 |
+
return ('StringValue('
|
| 492 |
+
'value={self.value!r}'
|
| 493 |
+
')').format(self=self)
|
| 494 |
+
|
| 495 |
+
def __copy__(self):
|
| 496 |
+
return type(self)(
|
| 497 |
+
self.value,
|
| 498 |
+
self.loc
|
| 499 |
+
)
|
| 500 |
+
|
| 501 |
+
def __hash__(self):
|
| 502 |
+
return id(self)
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
class BooleanValue(Value):
|
| 506 |
+
__slots__ = ('loc', 'value',)
|
| 507 |
+
_fields = ('value',)
|
| 508 |
+
|
| 509 |
+
def __init__(self, value, loc=None):
|
| 510 |
+
self.loc = loc
|
| 511 |
+
self.value = value
|
| 512 |
+
|
| 513 |
+
def __eq__(self, other):
|
| 514 |
+
return (
|
| 515 |
+
self is other or (
|
| 516 |
+
isinstance(other, BooleanValue) and
|
| 517 |
+
# self.loc == other.loc and
|
| 518 |
+
self.value == other.value
|
| 519 |
+
)
|
| 520 |
+
)
|
| 521 |
+
|
| 522 |
+
def __repr__(self):
|
| 523 |
+
return ('BooleanValue('
|
| 524 |
+
'value={self.value!r}'
|
| 525 |
+
')').format(self=self)
|
| 526 |
+
|
| 527 |
+
def __copy__(self):
|
| 528 |
+
return type(self)(
|
| 529 |
+
self.value,
|
| 530 |
+
self.loc
|
| 531 |
+
)
|
| 532 |
+
|
| 533 |
+
def __hash__(self):
|
| 534 |
+
return id(self)
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
class EnumValue(Value):
|
| 538 |
+
__slots__ = ('loc', 'value',)
|
| 539 |
+
_fields = ('value',)
|
| 540 |
+
|
| 541 |
+
def __init__(self, value, loc=None):
|
| 542 |
+
self.loc = loc
|
| 543 |
+
self.value = value
|
| 544 |
+
|
| 545 |
+
def __eq__(self, other):
|
| 546 |
+
return (
|
| 547 |
+
self is other or (
|
| 548 |
+
isinstance(other, EnumValue) and
|
| 549 |
+
# self.loc == other.loc and
|
| 550 |
+
self.value == other.value
|
| 551 |
+
)
|
| 552 |
+
)
|
| 553 |
+
|
| 554 |
+
def __repr__(self):
|
| 555 |
+
return ('EnumValue('
|
| 556 |
+
'value={self.value!r}'
|
| 557 |
+
')').format(self=self)
|
| 558 |
+
|
| 559 |
+
def __copy__(self):
|
| 560 |
+
return type(self)(
|
| 561 |
+
self.value,
|
| 562 |
+
self.loc
|
| 563 |
+
)
|
| 564 |
+
|
| 565 |
+
def __hash__(self):
|
| 566 |
+
return id(self)
|
| 567 |
+
|
| 568 |
+
|
| 569 |
+
class ListValue(Value):
|
| 570 |
+
__slots__ = ('loc', 'values',)
|
| 571 |
+
_fields = ('values',)
|
| 572 |
+
|
| 573 |
+
def __init__(self, values, loc=None):
|
| 574 |
+
self.loc = loc
|
| 575 |
+
self.values = values
|
| 576 |
+
|
| 577 |
+
def __eq__(self, other):
|
| 578 |
+
return (
|
| 579 |
+
self is other or (
|
| 580 |
+
isinstance(other, ListValue) and
|
| 581 |
+
# self.loc == other.loc and
|
| 582 |
+
self.values == other.values
|
| 583 |
+
)
|
| 584 |
+
)
|
| 585 |
+
|
| 586 |
+
def __repr__(self):
|
| 587 |
+
return ('ListValue('
|
| 588 |
+
'values={self.values!r}'
|
| 589 |
+
')').format(self=self)
|
| 590 |
+
|
| 591 |
+
def __copy__(self):
|
| 592 |
+
return type(self)(
|
| 593 |
+
self.values,
|
| 594 |
+
self.loc
|
| 595 |
+
)
|
| 596 |
+
|
| 597 |
+
def __hash__(self):
|
| 598 |
+
return id(self)
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
class ObjectValue(Value):
|
| 602 |
+
__slots__ = ('loc', 'fields',)
|
| 603 |
+
_fields = ('fields',)
|
| 604 |
+
|
| 605 |
+
def __init__(self, fields, loc=None):
|
| 606 |
+
self.loc = loc
|
| 607 |
+
self.fields = fields
|
| 608 |
+
|
| 609 |
+
def __eq__(self, other):
|
| 610 |
+
return (
|
| 611 |
+
self is other or (
|
| 612 |
+
isinstance(other, ObjectValue) and
|
| 613 |
+
# self.loc == other.loc and
|
| 614 |
+
self.fields == other.fields
|
| 615 |
+
)
|
| 616 |
+
)
|
| 617 |
+
|
| 618 |
+
def __repr__(self):
|
| 619 |
+
return ('ObjectValue('
|
| 620 |
+
'fields={self.fields!r}'
|
| 621 |
+
')').format(self=self)
|
| 622 |
+
|
| 623 |
+
def __copy__(self):
|
| 624 |
+
return type(self)(
|
| 625 |
+
self.fields,
|
| 626 |
+
self.loc
|
| 627 |
+
)
|
| 628 |
+
|
| 629 |
+
def __hash__(self):
|
| 630 |
+
return id(self)
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
class ObjectField(Node):
|
| 634 |
+
__slots__ = ('loc', 'name', 'value',)
|
| 635 |
+
_fields = ('name', 'value',)
|
| 636 |
+
|
| 637 |
+
def __init__(self, name, value, loc=None):
|
| 638 |
+
self.loc = loc
|
| 639 |
+
self.name = name
|
| 640 |
+
self.value = value
|
| 641 |
+
|
| 642 |
+
def __eq__(self, other):
|
| 643 |
+
return (
|
| 644 |
+
self is other or (
|
| 645 |
+
isinstance(other, ObjectField) and
|
| 646 |
+
# self.loc == other.loc and
|
| 647 |
+
self.name == other.name and
|
| 648 |
+
self.value == other.value
|
| 649 |
+
)
|
| 650 |
+
)
|
| 651 |
+
|
| 652 |
+
def __repr__(self):
|
| 653 |
+
return ('ObjectField('
|
| 654 |
+
'name={self.name!r}'
|
| 655 |
+
', value={self.value!r}'
|
| 656 |
+
')').format(self=self)
|
| 657 |
+
|
| 658 |
+
def __copy__(self):
|
| 659 |
+
return type(self)(
|
| 660 |
+
self.name,
|
| 661 |
+
self.value,
|
| 662 |
+
self.loc
|
| 663 |
+
)
|
| 664 |
+
|
| 665 |
+
def __hash__(self):
|
| 666 |
+
return id(self)
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
class Directive(Node):
|
| 670 |
+
__slots__ = ('loc', 'name', 'arguments',)
|
| 671 |
+
_fields = ('name', 'arguments',)
|
| 672 |
+
|
| 673 |
+
def __init__(self, name, arguments=None, loc=None):
|
| 674 |
+
self.loc = loc
|
| 675 |
+
self.name = name
|
| 676 |
+
self.arguments = arguments
|
| 677 |
+
|
| 678 |
+
def __eq__(self, other):
|
| 679 |
+
return (
|
| 680 |
+
self is other or (
|
| 681 |
+
isinstance(other, Directive) and
|
| 682 |
+
# self.loc == other.loc and
|
| 683 |
+
self.name == other.name and
|
| 684 |
+
self.arguments == other.arguments
|
| 685 |
+
)
|
| 686 |
+
)
|
| 687 |
+
|
| 688 |
+
def __repr__(self):
|
| 689 |
+
return ('Directive('
|
| 690 |
+
'name={self.name!r}'
|
| 691 |
+
', arguments={self.arguments!r}'
|
| 692 |
+
')').format(self=self)
|
| 693 |
+
|
| 694 |
+
def __copy__(self):
|
| 695 |
+
return type(self)(
|
| 696 |
+
self.name,
|
| 697 |
+
self.arguments,
|
| 698 |
+
self.loc
|
| 699 |
+
)
|
| 700 |
+
|
| 701 |
+
def __hash__(self):
|
| 702 |
+
return id(self)
|
| 703 |
+
|
| 704 |
+
|
| 705 |
+
class Type(Node):
|
| 706 |
+
__slots__ = ()
|
| 707 |
+
|
| 708 |
+
|
| 709 |
+
class NamedType(Type):
|
| 710 |
+
__slots__ = ('loc', 'name',)
|
| 711 |
+
_fields = ('name',)
|
| 712 |
+
|
| 713 |
+
def __init__(self, name, loc=None):
|
| 714 |
+
self.loc = loc
|
| 715 |
+
self.name = name
|
| 716 |
+
|
| 717 |
+
def __eq__(self, other):
|
| 718 |
+
return (
|
| 719 |
+
self is other or (
|
| 720 |
+
isinstance(other, NamedType) and
|
| 721 |
+
# self.loc == other.loc and
|
| 722 |
+
self.name == other.name
|
| 723 |
+
)
|
| 724 |
+
)
|
| 725 |
+
|
| 726 |
+
def __repr__(self):
|
| 727 |
+
return ('NamedType('
|
| 728 |
+
'name={self.name!r}'
|
| 729 |
+
')').format(self=self)
|
| 730 |
+
|
| 731 |
+
def __copy__(self):
|
| 732 |
+
return type(self)(
|
| 733 |
+
self.name,
|
| 734 |
+
self.loc
|
| 735 |
+
)
|
| 736 |
+
|
| 737 |
+
def __hash__(self):
|
| 738 |
+
return id(self)
|
| 739 |
+
|
| 740 |
+
|
| 741 |
+
class ListType(Type):
|
| 742 |
+
__slots__ = ('loc', 'type',)
|
| 743 |
+
_fields = ('type',)
|
| 744 |
+
|
| 745 |
+
def __init__(self, type, loc=None):
|
| 746 |
+
self.loc = loc
|
| 747 |
+
self.type = type
|
| 748 |
+
|
| 749 |
+
def __eq__(self, other):
|
| 750 |
+
return (
|
| 751 |
+
self is other or (
|
| 752 |
+
isinstance(other, ListType) and
|
| 753 |
+
# self.loc == other.loc and
|
| 754 |
+
self.type == other.type
|
| 755 |
+
)
|
| 756 |
+
)
|
| 757 |
+
|
| 758 |
+
def __repr__(self):
|
| 759 |
+
return ('ListType('
|
| 760 |
+
'type={self.type!r}'
|
| 761 |
+
')').format(self=self)
|
| 762 |
+
|
| 763 |
+
def __copy__(self):
|
| 764 |
+
return type(self)(
|
| 765 |
+
self.type,
|
| 766 |
+
self.loc
|
| 767 |
+
)
|
| 768 |
+
|
| 769 |
+
def __hash__(self):
|
| 770 |
+
return id(self)
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
class NonNullType(Type):
|
| 774 |
+
__slots__ = ('loc', 'type',)
|
| 775 |
+
_fields = ('type',)
|
| 776 |
+
|
| 777 |
+
def __init__(self, type, loc=None):
|
| 778 |
+
self.loc = loc
|
| 779 |
+
self.type = type
|
| 780 |
+
|
| 781 |
+
def __eq__(self, other):
|
| 782 |
+
return (
|
| 783 |
+
self is other or (
|
| 784 |
+
isinstance(other, NonNullType) and
|
| 785 |
+
# self.loc == other.loc and
|
| 786 |
+
self.type == other.type
|
| 787 |
+
)
|
| 788 |
+
)
|
| 789 |
+
|
| 790 |
+
def __repr__(self):
|
| 791 |
+
return ('NonNullType('
|
| 792 |
+
'type={self.type!r}'
|
| 793 |
+
')').format(self=self)
|
| 794 |
+
|
| 795 |
+
def __copy__(self):
|
| 796 |
+
return type(self)(
|
| 797 |
+
self.type,
|
| 798 |
+
self.loc
|
| 799 |
+
)
|
| 800 |
+
|
| 801 |
+
def __hash__(self):
|
| 802 |
+
return id(self)
|
| 803 |
+
|
| 804 |
+
|
| 805 |
+
class Name(Node):
|
| 806 |
+
__slots__ = ('loc', 'value',)
|
| 807 |
+
_fields = ('value',)
|
| 808 |
+
|
| 809 |
+
def __init__(self, value, loc=None):
|
| 810 |
+
self.loc = loc
|
| 811 |
+
self.value = value
|
| 812 |
+
|
| 813 |
+
def __eq__(self, other):
|
| 814 |
+
return (
|
| 815 |
+
self is other or (
|
| 816 |
+
isinstance(other, Name) and
|
| 817 |
+
# self.loc == other.loc and
|
| 818 |
+
self.value == other.value
|
| 819 |
+
)
|
| 820 |
+
)
|
| 821 |
+
|
| 822 |
+
def __repr__(self):
|
| 823 |
+
return ('Name('
|
| 824 |
+
'value={self.value!r}'
|
| 825 |
+
')').format(self=self)
|
| 826 |
+
|
| 827 |
+
def __copy__(self):
|
| 828 |
+
return type(self)(
|
| 829 |
+
self.value,
|
| 830 |
+
self.loc
|
| 831 |
+
)
|
| 832 |
+
|
| 833 |
+
def __hash__(self):
|
| 834 |
+
return id(self)
|
| 835 |
+
|
| 836 |
+
|
| 837 |
+
# Type System Definition
|
| 838 |
+
|
| 839 |
+
class TypeDefinition(Node):
|
| 840 |
+
pass
|
| 841 |
+
|
| 842 |
+
|
| 843 |
+
class TypeSystemDefinition(TypeDefinition):
|
| 844 |
+
pass
|
| 845 |
+
|
| 846 |
+
|
| 847 |
+
class SchemaDefinition(TypeSystemDefinition):
|
| 848 |
+
__slots__ = ('loc', 'directives', 'operation_types',)
|
| 849 |
+
_fields = ('operation_types',)
|
| 850 |
+
|
| 851 |
+
def __init__(self, operation_types, loc=None, directives=None):
|
| 852 |
+
self.operation_types = operation_types
|
| 853 |
+
self.loc = loc
|
| 854 |
+
self.directives = directives
|
| 855 |
+
|
| 856 |
+
def __eq__(self, other):
|
| 857 |
+
return (
|
| 858 |
+
self is other or (
|
| 859 |
+
isinstance(other, SchemaDefinition) and
|
| 860 |
+
self.operation_types == other.operation_types and
|
| 861 |
+
self.directives == other.directives
|
| 862 |
+
)
|
| 863 |
+
)
|
| 864 |
+
|
| 865 |
+
def __repr__(self):
|
| 866 |
+
return ('SchemaDefinition('
|
| 867 |
+
'operation_types={self.operation_types!r}'
|
| 868 |
+
', directives={self.directives!r}'
|
| 869 |
+
')').format(self=self)
|
| 870 |
+
|
| 871 |
+
def __copy__(self):
|
| 872 |
+
return type(self)(
|
| 873 |
+
self.operation_types,
|
| 874 |
+
self.loc,
|
| 875 |
+
self.directives,
|
| 876 |
+
)
|
| 877 |
+
|
| 878 |
+
def __hash__(self):
|
| 879 |
+
return id(self)
|
| 880 |
+
|
| 881 |
+
|
| 882 |
+
class OperationTypeDefinition(Node):
|
| 883 |
+
__slots__ = ('loc', 'operation', 'type',)
|
| 884 |
+
_fields = ('operation', 'type',)
|
| 885 |
+
|
| 886 |
+
def __init__(self, operation, type, loc=None):
|
| 887 |
+
self.operation = operation
|
| 888 |
+
self.type = type
|
| 889 |
+
self.loc = loc
|
| 890 |
+
|
| 891 |
+
def __eq__(self, other):
|
| 892 |
+
return (
|
| 893 |
+
self is other or (
|
| 894 |
+
isinstance(other, OperationTypeDefinition) and
|
| 895 |
+
self.operation == other.operation and
|
| 896 |
+
self.type == other.type
|
| 897 |
+
)
|
| 898 |
+
)
|
| 899 |
+
|
| 900 |
+
def __repr__(self):
|
| 901 |
+
return ('OperationTypeDefinition('
|
| 902 |
+
'operation={self.operation!r}'
|
| 903 |
+
', type={self.type!r}'
|
| 904 |
+
')').format(self=self)
|
| 905 |
+
|
| 906 |
+
def __copy__(self):
|
| 907 |
+
return type(self)(
|
| 908 |
+
self.operation,
|
| 909 |
+
self.type,
|
| 910 |
+
self.loc
|
| 911 |
+
)
|
| 912 |
+
|
| 913 |
+
def __hash__(self):
|
| 914 |
+
return id(self)
|
| 915 |
+
|
| 916 |
+
|
| 917 |
+
class ObjectTypeDefinition(TypeDefinition):
|
| 918 |
+
__slots__ = ('loc', 'name', 'interfaces', 'directives', 'fields',)
|
| 919 |
+
_fields = ('name', 'interfaces', 'fields',)
|
| 920 |
+
|
| 921 |
+
def __init__(self, name, fields, interfaces=None, loc=None, directives=None):
|
| 922 |
+
self.loc = loc
|
| 923 |
+
self.name = name
|
| 924 |
+
self.interfaces = interfaces
|
| 925 |
+
self.fields = fields
|
| 926 |
+
self.directives = directives
|
| 927 |
+
|
| 928 |
+
def __eq__(self, other):
|
| 929 |
+
return (
|
| 930 |
+
self is other or (
|
| 931 |
+
isinstance(other, ObjectTypeDefinition) and
|
| 932 |
+
# self.loc == other.loc and
|
| 933 |
+
self.name == other.name and
|
| 934 |
+
self.interfaces == other.interfaces and
|
| 935 |
+
self.fields == other.fields and
|
| 936 |
+
self.directives == other.directives
|
| 937 |
+
)
|
| 938 |
+
)
|
| 939 |
+
|
| 940 |
+
def __repr__(self):
|
| 941 |
+
return ('ObjectTypeDefinition('
|
| 942 |
+
'name={self.name!r}'
|
| 943 |
+
', interfaces={self.interfaces!r}'
|
| 944 |
+
', fields={self.fields!r}'
|
| 945 |
+
', directives={self.directives!r}'
|
| 946 |
+
')').format(self=self)
|
| 947 |
+
|
| 948 |
+
def __copy__(self):
|
| 949 |
+
return type(self)(
|
| 950 |
+
self.name,
|
| 951 |
+
self.fields,
|
| 952 |
+
self.interfaces,
|
| 953 |
+
self.loc,
|
| 954 |
+
self.directives,
|
| 955 |
+
)
|
| 956 |
+
|
| 957 |
+
def __hash__(self):
|
| 958 |
+
return id(self)
|
| 959 |
+
|
| 960 |
+
|
| 961 |
+
class FieldDefinition(Node):
|
| 962 |
+
__slots__ = ('loc', 'name', 'arguments', 'type', 'directives',)
|
| 963 |
+
_fields = ('name', 'arguments', 'type',)
|
| 964 |
+
|
| 965 |
+
def __init__(self, name, arguments, type, loc=None, directives=None):
|
| 966 |
+
self.loc = loc
|
| 967 |
+
self.name = name
|
| 968 |
+
self.arguments = arguments
|
| 969 |
+
self.type = type
|
| 970 |
+
self.directives = directives
|
| 971 |
+
|
| 972 |
+
def __eq__(self, other):
|
| 973 |
+
return (
|
| 974 |
+
self is other or (
|
| 975 |
+
isinstance(other, FieldDefinition) and
|
| 976 |
+
# self.loc == other.loc and
|
| 977 |
+
self.name == other.name and
|
| 978 |
+
self.arguments == other.arguments and
|
| 979 |
+
self.type == other.type and
|
| 980 |
+
self.directives == other.directives
|
| 981 |
+
)
|
| 982 |
+
)
|
| 983 |
+
|
| 984 |
+
def __repr__(self):
|
| 985 |
+
return ('FieldDefinition('
|
| 986 |
+
'name={self.name!r}'
|
| 987 |
+
', arguments={self.arguments!r}'
|
| 988 |
+
', type={self.type!r}'
|
| 989 |
+
')').format(self=self)
|
| 990 |
+
|
| 991 |
+
def __copy__(self):
|
| 992 |
+
return type(self)(
|
| 993 |
+
self.name,
|
| 994 |
+
self.arguments,
|
| 995 |
+
self.type,
|
| 996 |
+
self.loc,
|
| 997 |
+
self.directives,
|
| 998 |
+
)
|
| 999 |
+
|
| 1000 |
+
def __hash__(self):
|
| 1001 |
+
return id(self)
|
| 1002 |
+
|
| 1003 |
+
|
| 1004 |
+
class InputValueDefinition(Node):
|
| 1005 |
+
__slots__ = ('loc', 'name', 'type', 'default_value', 'directives')
|
| 1006 |
+
_fields = ('name', 'type', 'default_value',)
|
| 1007 |
+
|
| 1008 |
+
def __init__(self, name, type, default_value=None, loc=None,
|
| 1009 |
+
directives=None):
|
| 1010 |
+
self.loc = loc
|
| 1011 |
+
self.name = name
|
| 1012 |
+
self.type = type
|
| 1013 |
+
self.default_value = default_value
|
| 1014 |
+
self.directives = directives
|
| 1015 |
+
|
| 1016 |
+
def __eq__(self, other):
|
| 1017 |
+
return (
|
| 1018 |
+
self is other or (
|
| 1019 |
+
isinstance(other, InputValueDefinition) and
|
| 1020 |
+
# self.loc == other.loc and
|
| 1021 |
+
self.name == other.name and
|
| 1022 |
+
self.type == other.type and
|
| 1023 |
+
self.default_value == other.default_value and
|
| 1024 |
+
self.directives == other.directives
|
| 1025 |
+
)
|
| 1026 |
+
)
|
| 1027 |
+
|
| 1028 |
+
def __repr__(self):
|
| 1029 |
+
return ('InputValueDefinition('
|
| 1030 |
+
'name={self.name!r}'
|
| 1031 |
+
', type={self.type!r}'
|
| 1032 |
+
', default_value={self.default_value!r}'
|
| 1033 |
+
', directives={self.directives!r}'
|
| 1034 |
+
')').format(self=self)
|
| 1035 |
+
|
| 1036 |
+
def __copy__(self):
|
| 1037 |
+
return type(self)(
|
| 1038 |
+
self.name,
|
| 1039 |
+
self.type,
|
| 1040 |
+
self.default_value,
|
| 1041 |
+
self.loc,
|
| 1042 |
+
self.directives,
|
| 1043 |
+
)
|
| 1044 |
+
|
| 1045 |
+
def __hash__(self):
|
| 1046 |
+
return id(self)
|
| 1047 |
+
|
| 1048 |
+
|
| 1049 |
+
class InterfaceTypeDefinition(TypeDefinition):
|
| 1050 |
+
__slots__ = ('loc', 'name', 'fields', 'directives',)
|
| 1051 |
+
_fields = ('name', 'fields',)
|
| 1052 |
+
|
| 1053 |
+
def __init__(self, name, fields, loc=None, directives=None):
|
| 1054 |
+
self.loc = loc
|
| 1055 |
+
self.name = name
|
| 1056 |
+
self.fields = fields
|
| 1057 |
+
self.directives = directives
|
| 1058 |
+
|
| 1059 |
+
def __eq__(self, other):
|
| 1060 |
+
return (
|
| 1061 |
+
self is other or (
|
| 1062 |
+
isinstance(other, InterfaceTypeDefinition) and
|
| 1063 |
+
# self.loc == other.loc and
|
| 1064 |
+
self.name == other.name and
|
| 1065 |
+
self.fields == other.fields and
|
| 1066 |
+
self.directives == other.directives
|
| 1067 |
+
)
|
| 1068 |
+
)
|
| 1069 |
+
|
| 1070 |
+
def __repr__(self):
|
| 1071 |
+
return ('InterfaceTypeDefinition('
|
| 1072 |
+
'name={self.name!r}'
|
| 1073 |
+
', fields={self.fields!r}'
|
| 1074 |
+
', directives={self.directives!r}'
|
| 1075 |
+
')').format(self=self)
|
| 1076 |
+
|
| 1077 |
+
def __copy__(self):
|
| 1078 |
+
return type(self)(
|
| 1079 |
+
self.name,
|
| 1080 |
+
self.fields,
|
| 1081 |
+
self.loc,
|
| 1082 |
+
self.directives,
|
| 1083 |
+
)
|
| 1084 |
+
|
| 1085 |
+
def __hash__(self):
|
| 1086 |
+
return id(self)
|
| 1087 |
+
|
| 1088 |
+
|
| 1089 |
+
class UnionTypeDefinition(TypeDefinition):
|
| 1090 |
+
__slots__ = ('loc', 'name', 'types', 'directives',)
|
| 1091 |
+
_fields = ('name', 'types',)
|
| 1092 |
+
|
| 1093 |
+
def __init__(self, name, types, loc=None, directives=None):
|
| 1094 |
+
self.loc = loc
|
| 1095 |
+
self.name = name
|
| 1096 |
+
self.types = types
|
| 1097 |
+
self.directives = directives
|
| 1098 |
+
|
| 1099 |
+
def __eq__(self, other):
|
| 1100 |
+
return (
|
| 1101 |
+
self is other or (
|
| 1102 |
+
isinstance(other, UnionTypeDefinition) and
|
| 1103 |
+
# self.loc == other.loc and
|
| 1104 |
+
self.name == other.name and
|
| 1105 |
+
self.types == other.types and
|
| 1106 |
+
self.directives == other.directives
|
| 1107 |
+
)
|
| 1108 |
+
)
|
| 1109 |
+
|
| 1110 |
+
def __repr__(self):
|
| 1111 |
+
return ('UnionTypeDefinition('
|
| 1112 |
+
'name={self.name!r}'
|
| 1113 |
+
', types={self.types!r}'
|
| 1114 |
+
', directives={self.directives!r}'
|
| 1115 |
+
')').format(self=self)
|
| 1116 |
+
|
| 1117 |
+
def __copy__(self):
|
| 1118 |
+
return type(self)(
|
| 1119 |
+
self.name,
|
| 1120 |
+
self.types,
|
| 1121 |
+
self.loc,
|
| 1122 |
+
self.directives,
|
| 1123 |
+
)
|
| 1124 |
+
|
| 1125 |
+
def __hash__(self):
|
| 1126 |
+
return id(self)
|
| 1127 |
+
|
| 1128 |
+
|
| 1129 |
+
class ScalarTypeDefinition(TypeDefinition):
|
| 1130 |
+
__slots__ = ('loc', 'name', 'directives',)
|
| 1131 |
+
_fields = ('name',)
|
| 1132 |
+
|
| 1133 |
+
def __init__(self, name, loc=None, directives=None):
|
| 1134 |
+
self.loc = loc
|
| 1135 |
+
self.name = name
|
| 1136 |
+
self.directives = directives
|
| 1137 |
+
|
| 1138 |
+
def __eq__(self, other):
|
| 1139 |
+
return (
|
| 1140 |
+
self is other or (
|
| 1141 |
+
isinstance(other, ScalarTypeDefinition) and
|
| 1142 |
+
# self.loc == other.loc and
|
| 1143 |
+
self.name == other.name and
|
| 1144 |
+
self.directives == other.directives
|
| 1145 |
+
)
|
| 1146 |
+
)
|
| 1147 |
+
|
| 1148 |
+
def __repr__(self):
|
| 1149 |
+
return ('ScalarTypeDefinition('
|
| 1150 |
+
'name={self.name!r}'
|
| 1151 |
+
'directives={self.directives!r}'
|
| 1152 |
+
')').format(self=self)
|
| 1153 |
+
|
| 1154 |
+
def __copy__(self):
|
| 1155 |
+
return type(self)(
|
| 1156 |
+
self.name,
|
| 1157 |
+
self.loc,
|
| 1158 |
+
self.directives
|
| 1159 |
+
)
|
| 1160 |
+
|
| 1161 |
+
def __hash__(self):
|
| 1162 |
+
return id(self)
|
| 1163 |
+
|
| 1164 |
+
|
| 1165 |
+
class EnumTypeDefinition(TypeDefinition):
|
| 1166 |
+
__slots__ = ('loc', 'name', 'values', 'directives',)
|
| 1167 |
+
_fields = ('name', 'values',)
|
| 1168 |
+
|
| 1169 |
+
def __init__(self, name, values, loc=None, directives=None):
|
| 1170 |
+
self.loc = loc
|
| 1171 |
+
self.name = name
|
| 1172 |
+
self.values = values
|
| 1173 |
+
self.directives = directives
|
| 1174 |
+
|
| 1175 |
+
def __eq__(self, other):
|
| 1176 |
+
return (
|
| 1177 |
+
self is other or (
|
| 1178 |
+
isinstance(other, EnumTypeDefinition) and
|
| 1179 |
+
# self.loc == other.loc and
|
| 1180 |
+
self.name == other.name and
|
| 1181 |
+
self.values == other.values and
|
| 1182 |
+
self.directives == other.directives
|
| 1183 |
+
)
|
| 1184 |
+
)
|
| 1185 |
+
|
| 1186 |
+
def __repr__(self):
|
| 1187 |
+
return ('EnumTypeDefinition('
|
| 1188 |
+
'name={self.name!r}'
|
| 1189 |
+
', values={self.values!r}'
|
| 1190 |
+
', directives={self.directives!r}'
|
| 1191 |
+
')').format(self=self)
|
| 1192 |
+
|
| 1193 |
+
def __copy__(self):
|
| 1194 |
+
return type(self)(
|
| 1195 |
+
self.name,
|
| 1196 |
+
self.values,
|
| 1197 |
+
self.loc,
|
| 1198 |
+
self.directives,
|
| 1199 |
+
)
|
| 1200 |
+
|
| 1201 |
+
def __hash__(self):
|
| 1202 |
+
return id(self)
|
| 1203 |
+
|
| 1204 |
+
|
| 1205 |
+
class EnumValueDefinition(Node):
|
| 1206 |
+
__slots__ = ('loc', 'name', 'directives',)
|
| 1207 |
+
_fields = ('name',)
|
| 1208 |
+
|
| 1209 |
+
def __init__(self, name, loc=None, directives=None):
|
| 1210 |
+
self.loc = loc
|
| 1211 |
+
self.name = name
|
| 1212 |
+
self.directives = directives
|
| 1213 |
+
|
| 1214 |
+
def __eq__(self, other):
|
| 1215 |
+
return (
|
| 1216 |
+
self is other or (
|
| 1217 |
+
isinstance(other, EnumValueDefinition) and
|
| 1218 |
+
# self.loc == other.loc and
|
| 1219 |
+
self.name == other.name and
|
| 1220 |
+
self.directives == other.directives
|
| 1221 |
+
)
|
| 1222 |
+
)
|
| 1223 |
+
|
| 1224 |
+
def __repr__(self):
|
| 1225 |
+
return ('EnumValueDefinition('
|
| 1226 |
+
'name={self.name!r}'
|
| 1227 |
+
', directives={self.directives!r}'
|
| 1228 |
+
')').format(self=self)
|
| 1229 |
+
|
| 1230 |
+
def __copy__(self):
|
| 1231 |
+
return type(self)(
|
| 1232 |
+
self.name,
|
| 1233 |
+
self.loc,
|
| 1234 |
+
self.directives,
|
| 1235 |
+
)
|
| 1236 |
+
|
| 1237 |
+
def __hash__(self):
|
| 1238 |
+
return id(self)
|
| 1239 |
+
|
| 1240 |
+
|
| 1241 |
+
class InputObjectTypeDefinition(TypeDefinition):
|
| 1242 |
+
__slots__ = ('loc', 'name', 'fields', 'directives',)
|
| 1243 |
+
_fields = ('name', 'fields',)
|
| 1244 |
+
|
| 1245 |
+
def __init__(self, name, fields, loc=None, directives=None):
|
| 1246 |
+
self.loc = loc
|
| 1247 |
+
self.name = name
|
| 1248 |
+
self.fields = fields
|
| 1249 |
+
self.directives = directives
|
| 1250 |
+
|
| 1251 |
+
def __eq__(self, other):
|
| 1252 |
+
return (
|
| 1253 |
+
self is other or (
|
| 1254 |
+
isinstance(other, InputObjectTypeDefinition) and
|
| 1255 |
+
# self.loc == other.loc and
|
| 1256 |
+
self.name == other.name and
|
| 1257 |
+
self.fields == other.fields and
|
| 1258 |
+
self.directives == other.directives
|
| 1259 |
+
)
|
| 1260 |
+
)
|
| 1261 |
+
|
| 1262 |
+
def __repr__(self):
|
| 1263 |
+
return ('InputObjectTypeDefinition('
|
| 1264 |
+
'name={self.name!r}'
|
| 1265 |
+
', fields={self.fields!r}'
|
| 1266 |
+
', directives={self.directives!r}'
|
| 1267 |
+
')').format(self=self)
|
| 1268 |
+
|
| 1269 |
+
def __copy__(self):
|
| 1270 |
+
return type(self)(
|
| 1271 |
+
self.name,
|
| 1272 |
+
self.fields,
|
| 1273 |
+
self.loc,
|
| 1274 |
+
self.directives,
|
| 1275 |
+
)
|
| 1276 |
+
|
| 1277 |
+
def __hash__(self):
|
| 1278 |
+
return id(self)
|
| 1279 |
+
|
| 1280 |
+
|
| 1281 |
+
class TypeExtensionDefinition(TypeSystemDefinition):
|
| 1282 |
+
__slots__ = ('loc', 'definition',)
|
| 1283 |
+
_fields = ('definition',)
|
| 1284 |
+
|
| 1285 |
+
def __init__(self, definition, loc=None):
|
| 1286 |
+
self.loc = loc
|
| 1287 |
+
self.definition = definition
|
| 1288 |
+
|
| 1289 |
+
def __eq__(self, other):
|
| 1290 |
+
return (
|
| 1291 |
+
self is other or (
|
| 1292 |
+
isinstance(other, TypeExtensionDefinition) and
|
| 1293 |
+
# self.loc == other.loc and
|
| 1294 |
+
self.definition == other.definition
|
| 1295 |
+
)
|
| 1296 |
+
)
|
| 1297 |
+
|
| 1298 |
+
def __repr__(self):
|
| 1299 |
+
return ('TypeExtensionDefinition('
|
| 1300 |
+
'definition={self.definition!r}'
|
| 1301 |
+
')').format(self=self)
|
| 1302 |
+
|
| 1303 |
+
def __copy__(self):
|
| 1304 |
+
return type(self)(
|
| 1305 |
+
self.definition,
|
| 1306 |
+
self.loc
|
| 1307 |
+
)
|
| 1308 |
+
|
| 1309 |
+
def __hash__(self):
|
| 1310 |
+
return id(self)
|
| 1311 |
+
|
| 1312 |
+
|
| 1313 |
+
class DirectiveDefinition(TypeSystemDefinition):
|
| 1314 |
+
__slots__ = ('loc', 'name', 'arguments', 'locations')
|
| 1315 |
+
_fields = ('name', 'locations')
|
| 1316 |
+
|
| 1317 |
+
def __init__(self, name, locations, arguments=None, loc=None):
|
| 1318 |
+
self.name = name
|
| 1319 |
+
self.locations = locations
|
| 1320 |
+
self.loc = loc
|
| 1321 |
+
self.arguments = arguments
|
| 1322 |
+
|
| 1323 |
+
def __eq__(self, other):
|
| 1324 |
+
return (
|
| 1325 |
+
self is other or (
|
| 1326 |
+
isinstance(other, DirectiveDefinition) and
|
| 1327 |
+
self.name == other.name and
|
| 1328 |
+
self.locations == other.locations and
|
| 1329 |
+
# self.loc == other.loc and
|
| 1330 |
+
self.arguments == other.arguments
|
| 1331 |
+
)
|
| 1332 |
+
)
|
| 1333 |
+
|
| 1334 |
+
def __repr__(self):
|
| 1335 |
+
return ('DirectiveDefinition('
|
| 1336 |
+
'name={self.name!r}, '
|
| 1337 |
+
'locations={self.locations!r}'
|
| 1338 |
+
')').format(self=self)
|
| 1339 |
+
|
| 1340 |
+
def __copy__(self):
|
| 1341 |
+
return type(self)(
|
| 1342 |
+
self.name,
|
| 1343 |
+
self.locations,
|
| 1344 |
+
self.arguments,
|
| 1345 |
+
self.loc,
|
| 1346 |
+
)
|
| 1347 |
+
|
| 1348 |
+
def __hash__(self):
|
| 1349 |
+
return id(self)
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/lexer.py
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
from ..error import GraphQLSyntaxError
|
| 4 |
+
|
| 5 |
+
__all__ = ['Token', 'Lexer', 'TokenKind',
|
| 6 |
+
'get_token_desc', 'get_token_kind_desc']
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Token(object):
|
| 10 |
+
__slots__ = 'kind', 'start', 'end', 'value'
|
| 11 |
+
|
| 12 |
+
def __init__(self, kind, start, end, value=None):
|
| 13 |
+
self.kind = kind
|
| 14 |
+
self.start = start
|
| 15 |
+
self.end = end
|
| 16 |
+
self.value = value
|
| 17 |
+
|
| 18 |
+
def __repr__(self):
|
| 19 |
+
return u'<Token kind={} at {}..{} value={}>'.format(
|
| 20 |
+
get_token_kind_desc(self.kind),
|
| 21 |
+
self.start,
|
| 22 |
+
self.end,
|
| 23 |
+
repr(self.value)
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
def __eq__(self, other):
|
| 27 |
+
return (self.kind == other.kind and
|
| 28 |
+
self.start == other.start and
|
| 29 |
+
self.end == other.end and
|
| 30 |
+
self.value == other.value)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class Lexer(object):
|
| 34 |
+
__slots__ = 'source', 'prev_position'
|
| 35 |
+
|
| 36 |
+
def __init__(self, source):
|
| 37 |
+
self.source = source
|
| 38 |
+
self.prev_position = 0
|
| 39 |
+
|
| 40 |
+
def next_token(self, reset_position=None):
|
| 41 |
+
if reset_position is None:
|
| 42 |
+
reset_position = self.prev_position
|
| 43 |
+
token = read_token(self.source, reset_position)
|
| 44 |
+
self.prev_position = token.end
|
| 45 |
+
return token
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class TokenKind(object):
|
| 49 |
+
EOF = 1
|
| 50 |
+
BANG = 2
|
| 51 |
+
DOLLAR = 3
|
| 52 |
+
PAREN_L = 4
|
| 53 |
+
PAREN_R = 5
|
| 54 |
+
SPREAD = 6
|
| 55 |
+
COLON = 7
|
| 56 |
+
EQUALS = 8
|
| 57 |
+
AT = 9
|
| 58 |
+
BRACKET_L = 10
|
| 59 |
+
BRACKET_R = 11
|
| 60 |
+
BRACE_L = 12
|
| 61 |
+
PIPE = 13
|
| 62 |
+
BRACE_R = 14
|
| 63 |
+
NAME = 15
|
| 64 |
+
VARIABLE = 16
|
| 65 |
+
INT = 17
|
| 66 |
+
FLOAT = 18
|
| 67 |
+
STRING = 19
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def get_token_desc(token):
|
| 71 |
+
if token.value:
|
| 72 |
+
return u'{} "{}"'.format(
|
| 73 |
+
get_token_kind_desc(token.kind),
|
| 74 |
+
token.value
|
| 75 |
+
)
|
| 76 |
+
else:
|
| 77 |
+
return get_token_kind_desc(token.kind)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def get_token_kind_desc(kind):
|
| 81 |
+
return TOKEN_DESCRIPTION[kind]
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
TOKEN_DESCRIPTION = {
|
| 85 |
+
TokenKind.EOF: 'EOF',
|
| 86 |
+
TokenKind.BANG: '!',
|
| 87 |
+
TokenKind.DOLLAR: '$',
|
| 88 |
+
TokenKind.PAREN_L: '(',
|
| 89 |
+
TokenKind.PAREN_R: ')',
|
| 90 |
+
TokenKind.SPREAD: '...',
|
| 91 |
+
TokenKind.COLON: ':',
|
| 92 |
+
TokenKind.EQUALS: '=',
|
| 93 |
+
TokenKind.AT: '@',
|
| 94 |
+
TokenKind.BRACKET_L: '[',
|
| 95 |
+
TokenKind.BRACKET_R: ']',
|
| 96 |
+
TokenKind.BRACE_L: '{',
|
| 97 |
+
TokenKind.PIPE: '|',
|
| 98 |
+
TokenKind.BRACE_R: '}',
|
| 99 |
+
TokenKind.NAME: 'Name',
|
| 100 |
+
TokenKind.VARIABLE: 'Variable',
|
| 101 |
+
TokenKind.INT: 'Int',
|
| 102 |
+
TokenKind.FLOAT: 'Float',
|
| 103 |
+
TokenKind.STRING: 'String',
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def char_code_at(s, pos):
|
| 108 |
+
if 0 <= pos < len(s):
|
| 109 |
+
return ord(s[pos])
|
| 110 |
+
|
| 111 |
+
return None
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
PUNCT_CODE_TO_KIND = {
|
| 115 |
+
ord('!'): TokenKind.BANG,
|
| 116 |
+
ord('$'): TokenKind.DOLLAR,
|
| 117 |
+
ord('('): TokenKind.PAREN_L,
|
| 118 |
+
ord(')'): TokenKind.PAREN_R,
|
| 119 |
+
ord(':'): TokenKind.COLON,
|
| 120 |
+
ord('='): TokenKind.EQUALS,
|
| 121 |
+
ord('@'): TokenKind.AT,
|
| 122 |
+
ord('['): TokenKind.BRACKET_L,
|
| 123 |
+
ord(']'): TokenKind.BRACKET_R,
|
| 124 |
+
ord('{'): TokenKind.BRACE_L,
|
| 125 |
+
ord('|'): TokenKind.PIPE,
|
| 126 |
+
ord('}'): TokenKind.BRACE_R,
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def print_char_code(code):
|
| 131 |
+
if code is None:
|
| 132 |
+
return '<EOF>'
|
| 133 |
+
|
| 134 |
+
if code < 0x007F:
|
| 135 |
+
return json.dumps(chr(code))
|
| 136 |
+
|
| 137 |
+
return '"\\u%04X"' % code
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def read_token(source, from_position):
|
| 141 |
+
"""Gets the next token from the source starting at the given position.
|
| 142 |
+
|
| 143 |
+
This skips over whitespace and comments until it finds the next lexable
|
| 144 |
+
token, then lexes punctuators immediately or calls the appropriate
|
| 145 |
+
helper fucntion for more complicated tokens."""
|
| 146 |
+
body = source.body
|
| 147 |
+
body_length = len(body)
|
| 148 |
+
|
| 149 |
+
position = position_after_whitespace(body, from_position)
|
| 150 |
+
|
| 151 |
+
if position >= body_length:
|
| 152 |
+
return Token(TokenKind.EOF, position, position)
|
| 153 |
+
|
| 154 |
+
code = char_code_at(body, position)
|
| 155 |
+
|
| 156 |
+
if code < 0x0020 and code not in (0x0009, 0x000A, 0x000D):
|
| 157 |
+
raise GraphQLSyntaxError(
|
| 158 |
+
source, position,
|
| 159 |
+
u'Invalid character {}.'.format(print_char_code(code))
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
kind = PUNCT_CODE_TO_KIND.get(code)
|
| 163 |
+
if kind is not None:
|
| 164 |
+
return Token(kind, position, position + 1)
|
| 165 |
+
|
| 166 |
+
if code == 46: # .
|
| 167 |
+
if char_code_at(body, position + 1) == char_code_at(body, position + 2) == 46:
|
| 168 |
+
return Token(TokenKind.SPREAD, position, position + 3)
|
| 169 |
+
|
| 170 |
+
elif 65 <= code <= 90 or code == 95 or 97 <= code <= 122:
|
| 171 |
+
# A-Z, _, a-z
|
| 172 |
+
return read_name(source, position)
|
| 173 |
+
|
| 174 |
+
elif code == 45 or 48 <= code <= 57: # -, 0-9
|
| 175 |
+
return read_number(source, position, code)
|
| 176 |
+
|
| 177 |
+
elif code == 34: # "
|
| 178 |
+
return read_string(source, position)
|
| 179 |
+
|
| 180 |
+
raise GraphQLSyntaxError(
|
| 181 |
+
source, position,
|
| 182 |
+
u'Unexpected character {}.'.format(print_char_code(code)))
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
ignored_whitespace_characters = frozenset([
|
| 186 |
+
# BOM
|
| 187 |
+
0xFEFF,
|
| 188 |
+
# White Space
|
| 189 |
+
0x0009, # tab
|
| 190 |
+
0x0020, # space
|
| 191 |
+
# Line Terminator
|
| 192 |
+
0x000A, # new line
|
| 193 |
+
0x000D, # carriage return
|
| 194 |
+
# Comma
|
| 195 |
+
0x002C
|
| 196 |
+
])
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def position_after_whitespace(body, start_position):
|
| 200 |
+
"""Reads from body starting at start_position until it finds a
|
| 201 |
+
non-whitespace or commented character, then returns the position of
|
| 202 |
+
that character for lexing."""
|
| 203 |
+
body_length = len(body)
|
| 204 |
+
position = start_position
|
| 205 |
+
while position < body_length:
|
| 206 |
+
code = char_code_at(body, position)
|
| 207 |
+
if code in ignored_whitespace_characters:
|
| 208 |
+
position += 1
|
| 209 |
+
|
| 210 |
+
elif code == 35: # #, skip comments
|
| 211 |
+
position += 1
|
| 212 |
+
while position < body_length:
|
| 213 |
+
code = char_code_at(body, position)
|
| 214 |
+
if not (code is not None and (code > 0x001F or code == 0x0009) and code not in (0x000A, 0x000D)):
|
| 215 |
+
break
|
| 216 |
+
|
| 217 |
+
position += 1
|
| 218 |
+
else:
|
| 219 |
+
break
|
| 220 |
+
return position
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def read_number(source, start, first_code):
|
| 224 |
+
"""Reads a number token from the source file, either a float
|
| 225 |
+
or an int depending on whether a decimal point appears.
|
| 226 |
+
"""
|
| 227 |
+
code = first_code
|
| 228 |
+
body = source.body
|
| 229 |
+
position = start
|
| 230 |
+
is_float = False
|
| 231 |
+
|
| 232 |
+
if code == 45: # -
|
| 233 |
+
position += 1
|
| 234 |
+
code = char_code_at(body, position)
|
| 235 |
+
|
| 236 |
+
if code == 48: # 0
|
| 237 |
+
position += 1
|
| 238 |
+
code = char_code_at(body, position)
|
| 239 |
+
|
| 240 |
+
if code is not None and 48 <= code <= 57:
|
| 241 |
+
raise GraphQLSyntaxError(
|
| 242 |
+
source,
|
| 243 |
+
position,
|
| 244 |
+
u'Invalid number, unexpected digit after 0: {}.'.format(print_char_code(code))
|
| 245 |
+
)
|
| 246 |
+
else:
|
| 247 |
+
position = read_digits(source, position, code)
|
| 248 |
+
code = char_code_at(body, position)
|
| 249 |
+
|
| 250 |
+
if code == 46: # .
|
| 251 |
+
is_float = True
|
| 252 |
+
|
| 253 |
+
position += 1
|
| 254 |
+
code = char_code_at(body, position)
|
| 255 |
+
position = read_digits(source, position, code)
|
| 256 |
+
code = char_code_at(body, position)
|
| 257 |
+
|
| 258 |
+
if code in (69, 101): # E e
|
| 259 |
+
is_float = True
|
| 260 |
+
position += 1
|
| 261 |
+
code = char_code_at(body, position)
|
| 262 |
+
if code in (43, 45): # + -
|
| 263 |
+
position += 1
|
| 264 |
+
code = char_code_at(body, position)
|
| 265 |
+
|
| 266 |
+
position = read_digits(source, position, code)
|
| 267 |
+
|
| 268 |
+
return Token(
|
| 269 |
+
TokenKind.FLOAT if is_float else TokenKind.INT,
|
| 270 |
+
start,
|
| 271 |
+
position,
|
| 272 |
+
body[start:position]
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
def read_digits(source, start, first_code):
|
| 277 |
+
body = source.body
|
| 278 |
+
position = start
|
| 279 |
+
code = first_code
|
| 280 |
+
|
| 281 |
+
if code is not None and 48 <= code <= 57: # 0 - 9
|
| 282 |
+
while True:
|
| 283 |
+
position += 1
|
| 284 |
+
code = char_code_at(body, position)
|
| 285 |
+
|
| 286 |
+
if not (code is not None and 48 <= code <= 57):
|
| 287 |
+
break
|
| 288 |
+
|
| 289 |
+
return position
|
| 290 |
+
|
| 291 |
+
raise GraphQLSyntaxError(
|
| 292 |
+
source,
|
| 293 |
+
position,
|
| 294 |
+
u'Invalid number, expected digit but got: {}.'.format(print_char_code(code))
|
| 295 |
+
)
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
ESCAPED_CHAR_CODES = {
|
| 299 |
+
34: '"',
|
| 300 |
+
47: '/',
|
| 301 |
+
92: '\\',
|
| 302 |
+
98: '\b',
|
| 303 |
+
102: '\f',
|
| 304 |
+
110: '\n',
|
| 305 |
+
114: '\r',
|
| 306 |
+
116: '\t',
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
def read_string(source, start):
|
| 311 |
+
"""Reads a string token from the source file.
|
| 312 |
+
|
| 313 |
+
"([^"\\\u000A\u000D\u2028\u2029]|(\\(u[0-9a-fA-F]{4}|["\\/bfnrt])))*"
|
| 314 |
+
"""
|
| 315 |
+
body = source.body
|
| 316 |
+
body_length = len(body)
|
| 317 |
+
|
| 318 |
+
position = start + 1
|
| 319 |
+
chunk_start = position
|
| 320 |
+
code = 0
|
| 321 |
+
value = []
|
| 322 |
+
append = value.append
|
| 323 |
+
|
| 324 |
+
while position < body_length:
|
| 325 |
+
code = char_code_at(body, position)
|
| 326 |
+
if not (
|
| 327 |
+
code is not None and
|
| 328 |
+
code not in (
|
| 329 |
+
# LineTerminator
|
| 330 |
+
0x000A, 0x000D,
|
| 331 |
+
# Quote
|
| 332 |
+
34
|
| 333 |
+
)
|
| 334 |
+
):
|
| 335 |
+
break
|
| 336 |
+
|
| 337 |
+
if code < 0x0020 and code != 0x0009:
|
| 338 |
+
raise GraphQLSyntaxError(
|
| 339 |
+
source,
|
| 340 |
+
position,
|
| 341 |
+
u'Invalid character within String: {}.'.format(print_char_code(code))
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
position += 1
|
| 345 |
+
if code == 92: # \
|
| 346 |
+
append(body[chunk_start:position - 1])
|
| 347 |
+
|
| 348 |
+
code = char_code_at(body, position)
|
| 349 |
+
escaped = ESCAPED_CHAR_CODES.get(code)
|
| 350 |
+
if escaped is not None:
|
| 351 |
+
append(escaped)
|
| 352 |
+
|
| 353 |
+
elif code == 117: # u
|
| 354 |
+
char_code = uni_char_code(
|
| 355 |
+
char_code_at(body, position + 1) or 0,
|
| 356 |
+
char_code_at(body, position + 2) or 0,
|
| 357 |
+
char_code_at(body, position + 3) or 0,
|
| 358 |
+
char_code_at(body, position + 4) or 0,
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
if char_code < 0:
|
| 362 |
+
raise GraphQLSyntaxError(
|
| 363 |
+
source, position,
|
| 364 |
+
u'Invalid character escape sequence: \\u{}.'.format(body[position + 1: position + 5])
|
| 365 |
+
)
|
| 366 |
+
|
| 367 |
+
append(chr(char_code))
|
| 368 |
+
position += 4
|
| 369 |
+
else:
|
| 370 |
+
raise GraphQLSyntaxError(
|
| 371 |
+
source, position,
|
| 372 |
+
u'Invalid character escape sequence: \\{}.'.format(chr(code))
|
| 373 |
+
)
|
| 374 |
+
|
| 375 |
+
position += 1
|
| 376 |
+
chunk_start = position
|
| 377 |
+
|
| 378 |
+
if code != 34: # Quote (")
|
| 379 |
+
raise GraphQLSyntaxError(source, position, 'Unterminated string')
|
| 380 |
+
|
| 381 |
+
append(body[chunk_start:position])
|
| 382 |
+
return Token(TokenKind.STRING, start, position + 1, u''.join(value))
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
def uni_char_code(a, b, c, d):
|
| 386 |
+
"""Converts four hexidecimal chars to the integer that the
|
| 387 |
+
string represents. For example, uniCharCode('0','0','0','f')
|
| 388 |
+
will return 15, and uniCharCode('0','0','f','f') returns 255.
|
| 389 |
+
|
| 390 |
+
Returns a negative number on error, if a char was invalid.
|
| 391 |
+
|
| 392 |
+
This is implemented by noting that char2hex() returns -1 on error,
|
| 393 |
+
which means the result of ORing the char2hex() will also be negative.
|
| 394 |
+
"""
|
| 395 |
+
return (char2hex(a) << 12 | char2hex(b) << 8 |
|
| 396 |
+
char2hex(c) << 4 | char2hex(d))
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
def char2hex(a):
|
| 400 |
+
"""Converts a hex character to its integer value.
|
| 401 |
+
'0' becomes 0, '9' becomes 9
|
| 402 |
+
'A' becomes 10, 'F' becomes 15
|
| 403 |
+
'a' becomes 10, 'f' becomes 15
|
| 404 |
+
|
| 405 |
+
Returns -1 on error."""
|
| 406 |
+
if 48 <= a <= 57: # 0-9
|
| 407 |
+
return a - 48
|
| 408 |
+
elif 65 <= a <= 70: # A-F
|
| 409 |
+
return a - 55
|
| 410 |
+
elif 97 <= a <= 102: # a-f
|
| 411 |
+
return a - 87
|
| 412 |
+
return -1
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
def read_name(source, position):
|
| 416 |
+
"""Reads an alphanumeric + underscore name from the source.
|
| 417 |
+
|
| 418 |
+
[_A-Za-z][_0-9A-Za-z]*"""
|
| 419 |
+
body = source.body
|
| 420 |
+
body_length = len(body)
|
| 421 |
+
end = position + 1
|
| 422 |
+
|
| 423 |
+
while end != body_length:
|
| 424 |
+
code = char_code_at(body, end)
|
| 425 |
+
if not (code is not None and (
|
| 426 |
+
code == 95 or # _
|
| 427 |
+
48 <= code <= 57 or # 0-9
|
| 428 |
+
65 <= code <= 90 or # A-Z
|
| 429 |
+
97 <= code <= 122 # a-z
|
| 430 |
+
)):
|
| 431 |
+
break
|
| 432 |
+
|
| 433 |
+
end += 1
|
| 434 |
+
|
| 435 |
+
return Token(TokenKind.NAME, position, end, body[position:end])
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/location.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = ['get_location', 'SourceLocation']
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class SourceLocation(object):
|
| 5 |
+
__slots__ = 'line', 'column'
|
| 6 |
+
|
| 7 |
+
def __init__(self, line, column):
|
| 8 |
+
self.line = line
|
| 9 |
+
self.column = column
|
| 10 |
+
|
| 11 |
+
def __repr__(self):
|
| 12 |
+
return '<SourceLocation line={} column={}>'.format(self.line, self.column)
|
| 13 |
+
|
| 14 |
+
def __eq__(self, other):
|
| 15 |
+
return (
|
| 16 |
+
isinstance(other, SourceLocation) and
|
| 17 |
+
self.line == other.line and
|
| 18 |
+
self.column == other.column
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def get_location(source, position):
|
| 23 |
+
lines = source.body[:position].splitlines()
|
| 24 |
+
if lines:
|
| 25 |
+
line = len(lines)
|
| 26 |
+
column = len(lines[-1]) + 1
|
| 27 |
+
else:
|
| 28 |
+
line = 1
|
| 29 |
+
column = 1
|
| 30 |
+
return SourceLocation(line, column)
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/source.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = ['Source']
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class Source(object):
|
| 5 |
+
__slots__ = 'body', 'name'
|
| 6 |
+
|
| 7 |
+
def __init__(self, body, name='GraphQL'):
|
| 8 |
+
self.body = body
|
| 9 |
+
self.name = name
|
| 10 |
+
|
| 11 |
+
def __eq__(self, other):
|
| 12 |
+
return (
|
| 13 |
+
self is other or (
|
| 14 |
+
isinstance(other, Source) and
|
| 15 |
+
self.body == other.body and
|
| 16 |
+
self.name == other.name
|
| 17 |
+
)
|
| 18 |
+
)
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor_meta.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import ast
|
| 2 |
+
|
| 3 |
+
QUERY_DOCUMENT_KEYS = {
|
| 4 |
+
ast.Name: (),
|
| 5 |
+
|
| 6 |
+
ast.Document: ('definitions',),
|
| 7 |
+
ast.OperationDefinition: ('name', 'variable_definitions', 'directives', 'selection_set'),
|
| 8 |
+
ast.VariableDefinition: ('variable', 'type', 'default_value'),
|
| 9 |
+
ast.Variable: ('name',),
|
| 10 |
+
ast.SelectionSet: ('selections',),
|
| 11 |
+
ast.Field: ('alias', 'name', 'arguments', 'directives', 'selection_set'),
|
| 12 |
+
ast.Argument: ('name', 'value'),
|
| 13 |
+
|
| 14 |
+
ast.FragmentSpread: ('name', 'directives'),
|
| 15 |
+
ast.InlineFragment: ('type_condition', 'directives', 'selection_set'),
|
| 16 |
+
ast.FragmentDefinition: ('name', 'type_condition', 'directives', 'selection_set'),
|
| 17 |
+
|
| 18 |
+
ast.IntValue: (),
|
| 19 |
+
ast.FloatValue: (),
|
| 20 |
+
ast.StringValue: (),
|
| 21 |
+
ast.BooleanValue: (),
|
| 22 |
+
ast.EnumValue: (),
|
| 23 |
+
ast.ListValue: ('values',),
|
| 24 |
+
ast.ObjectValue: ('fields',),
|
| 25 |
+
ast.ObjectField: ('name', 'value'),
|
| 26 |
+
|
| 27 |
+
ast.Directive: ('name', 'arguments'),
|
| 28 |
+
|
| 29 |
+
ast.NamedType: ('name',),
|
| 30 |
+
ast.ListType: ('type',),
|
| 31 |
+
ast.NonNullType: ('type',),
|
| 32 |
+
|
| 33 |
+
ast.SchemaDefinition: ('directives', 'operation_types',),
|
| 34 |
+
ast.OperationTypeDefinition: ('type',),
|
| 35 |
+
|
| 36 |
+
ast.ScalarTypeDefinition: ('name', 'directives',),
|
| 37 |
+
ast.ObjectTypeDefinition: ('name', 'interfaces', 'directives', 'fields'),
|
| 38 |
+
ast.FieldDefinition: ('name', 'arguments', 'directives', 'type'),
|
| 39 |
+
ast.InputValueDefinition: ('name', 'type', 'directives', 'default_value'),
|
| 40 |
+
ast.InterfaceTypeDefinition: ('name', 'directives', 'fields'),
|
| 41 |
+
ast.UnionTypeDefinition: ('name', 'directives', 'types'),
|
| 42 |
+
ast.EnumTypeDefinition: ('name', 'directives', 'values'),
|
| 43 |
+
ast.EnumValueDefinition: ('name', 'directives',),
|
| 44 |
+
ast.InputObjectTypeDefinition: ('name', 'directives', 'fields'),
|
| 45 |
+
|
| 46 |
+
ast.TypeExtensionDefinition: ('definition',),
|
| 47 |
+
|
| 48 |
+
ast.DirectiveDefinition: ('name', 'arguments', 'locations'),
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
AST_KIND_TO_TYPE = {c.__name__: c for c in QUERY_DOCUMENT_KEYS.keys()}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class VisitorMeta(type):
|
| 55 |
+
|
| 56 |
+
def __new__(cls, name, bases, attrs):
|
| 57 |
+
enter_handlers = {}
|
| 58 |
+
leave_handlers = {}
|
| 59 |
+
|
| 60 |
+
for base in bases:
|
| 61 |
+
if hasattr(base, '_enter_handlers'):
|
| 62 |
+
enter_handlers.update(base._enter_handlers)
|
| 63 |
+
|
| 64 |
+
if hasattr(base, '_leave_handlers'):
|
| 65 |
+
leave_handlers.update(base._leave_handlers)
|
| 66 |
+
|
| 67 |
+
for attr, val in attrs.items():
|
| 68 |
+
if attr.startswith('enter_'):
|
| 69 |
+
ast_kind = attr[6:]
|
| 70 |
+
ast_type = AST_KIND_TO_TYPE.get(ast_kind)
|
| 71 |
+
enter_handlers[ast_type] = val
|
| 72 |
+
|
| 73 |
+
elif attr.startswith('leave_'):
|
| 74 |
+
ast_kind = attr[6:]
|
| 75 |
+
ast_type = AST_KIND_TO_TYPE.get(ast_kind)
|
| 76 |
+
leave_handlers[ast_type] = val
|
| 77 |
+
|
| 78 |
+
attrs['_enter_handlers'] = enter_handlers
|
| 79 |
+
attrs['_leave_handlers'] = leave_handlers
|
| 80 |
+
attrs['_get_enter_handler'] = enter_handlers.get
|
| 81 |
+
attrs['_get_leave_handler'] = leave_handlers.get
|
| 82 |
+
return super(VisitorMeta, cls).__new__(cls, name, bases, attrs)
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__init__.py
ADDED
|
File without changes
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (199 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/assert_valid_name.cpython-310.pyc
ADDED
|
Binary file (566 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/ast_from_value.cpython-310.pyc
ADDED
|
Binary file (1.69 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/ast_to_code.cpython-310.pyc
ADDED
|
Binary file (1.24 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/ast_to_dict.cpython-310.pyc
ADDED
|
Binary file (812 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/base.cpython-310.pyc
ADDED
|
Binary file (1.08 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/build_ast_schema.cpython-310.pyc
ADDED
|
Binary file (10.4 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/build_client_schema.cpython-310.pyc
ADDED
|
Binary file (9.84 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/concat_ast.cpython-310.pyc
ADDED
|
Binary file (612 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/extend_schema.cpython-310.pyc
ADDED
|
Binary file (11.7 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/get_field_def.cpython-310.pyc
ADDED
|
Binary file (1.03 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/get_operation_ast.cpython-310.pyc
ADDED
|
Binary file (568 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/introspection_query.cpython-310.pyc
ADDED
|
Binary file (1.68 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/is_valid_literal_value.cpython-310.pyc
ADDED
|
Binary file (2.14 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/is_valid_value.cpython-310.pyc
ADDED
|
Binary file (1.79 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/quoted_or_list.cpython-310.pyc
ADDED
|
Binary file (1.04 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__pycache__/schema_printer.cpython-310.pyc
ADDED
|
Binary file (6.13 kB). View file
|
|
|