Skip to content

Commit

Permalink
Fix pow operator complex32 UT failure on Windows MTL/LNL (#847)
Browse files Browse the repository at this point in the history
(Windows only) Fix for
test_binary_ufuncs_xpu.py::TestBinaryUfuncsXPU::test_pow_xpu_float16

The previous way of casting into opmath_t leads to accuracy failure for
complex half dtype on windows. This change uses memory::LoadWithCast
instead which fixes the problem.

(cherry picked from commit 5955b5c)

---------

Co-authored-by: Feng Yuan <feng1.yuan@intel.com>
  • Loading branch information
Kanya-Mo and fengyuan14 authored Aug 31, 2024
1 parent 909f118 commit 5967041
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ATen/native/xpu/sycl/PowKernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,24 @@ static inline c10::complex<T> pow_(c10::complex<T> base, c10::complex<T> exp) {

} // namespace impl

#ifdef _MSC_VER
// Divergence for MSVC due to accuracy issue. https://github.com/intel/torch-xpu-ops/issues/842.
template <typename scalar_t>
struct PowTensorTensorCastFunctor {
using opmath_t = at::opmath_type<scalar_t>;
opmath_t operator()(opmath_t base, opmath_t exp) const {
return impl::pow_(base, exp);
}
};
#else
template <typename scalar_t>
struct PowTensorTensorCastFunctor {
scalar_t operator()(scalar_t base, scalar_t exp) const {
using opmath_t = at::opmath_type<scalar_t>;
return impl::pow_(opmath_t{base}, opmath_t{exp});
}
};
#endif

template <typename scalar_t>
struct PowTensorTensorFunctor {
Expand Down

0 comments on commit 5967041

Please sign in to comment.