Skip to content

Commit

Permalink
Fix cvtfp32_bf16 (#41280)
Browse files Browse the repository at this point in the history
Summary:
For `Vec256<bfloat16>::blendv()` operator to work correctly, float32 -nan (0xfffffffff) must be converted to bfloat16 -nan (0xffff).
But cvtfp32_bf16 converts -nan to nan (0x7fc0)
TODO: Fix float32 +-nan conversion: i.e. float32 nan (0x7fffffff) must be converted to bfloat16 (0x7fff) nan

Closes #41238

Pull Request resolved: #41280

Reviewed By: mruberry

Differential Revision: D23311585

Pulled By: malfet

fbshipit-source-id: 79499ce19f1ec3f6c954a874f1cd47f4ece6bdb5
  • Loading branch information
malfet authored and facebook-github-bot committed Dec 14, 2020
1 parent bd322c8 commit 8397a62
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aten/src/ATen/cpu/vec256/vec256_bfloat16.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static inline void cvtbf16_fp32(const __m256i& a, __m256& o1, __m256& o2) {
static inline __m256i cvtfp32_bf16(const __m256& a, const __m256& b) {
__m256i lo = _mm256_castps_si256(a);
__m256i hi = _mm256_castps_si256(b);
__m256i nan = _mm256_set1_epi32(0x7fc0);
__m256i nan = _mm256_set1_epi32(0xffff);
__m256i mask_lo = _mm256_castps_si256(_mm256_cmp_ps(a, a, _CMP_ORD_Q));
__m256i mask_hi = _mm256_castps_si256(_mm256_cmp_ps(b, b, _CMP_ORD_Q));
__m256i ones = _mm256_set1_epi32(0x1);
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cpu/UnaryOpsKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static void sign_kernel(TensorIterator& iter){
[=](scalar_t a) -> scalar_t { return (0 < a) - (a < 0); },
[=](Vec256<scalar_t> self_vec){

// Comparision operators returns bitmask.
// Comparison operators returns bitmask.
auto left = Vec256<scalar_t>::blendv(zero_vec, one_vec, zero_vec < self_vec);
auto right = Vec256<scalar_t>::blendv(zero_vec, one_vec, self_vec < zero_vec);

Expand Down

0 comments on commit 8397a62

Please sign in to comment.