Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aten::polar and its variants #606

Merged
merged 8 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/ATen/native/xpu/TensorFactories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,29 @@ Tensor& XPUNativeFunctions::complex_out(
return result;
}

Tensor& XPUNativeFunctions::polar_out(
const Tensor& abs,
const Tensor& angle,
Tensor& result) {
complex_check_dtype(result, abs, angle);
auto iter = TensorIteratorConfig()
.add_output(result)
.add_const_input(abs)
.add_const_input(angle)
.check_all_same_dtype(false)
.build();
native::xpu::polar_kernel(iter);
return result;
}

Tensor XPUNativeFunctions::polar(const Tensor& abs, const Tensor& angle) {
complex_check_floating(abs, angle);
c10::TensorOptions options = abs.options();
options = options.dtype(toComplexType(abs.scalar_type()));
Tensor result = at::empty(0, options);
return at::polar_out(result, abs, angle);
}
fengyuan14 marked this conversation as resolved.
Show resolved Hide resolved

Tensor& XPUNativeFunctions::randperm_out(
int64_t n,
c10::optional<Generator> generator,
Expand Down
1 change: 0 additions & 1 deletion src/ATen/native/xpu/XPUFallback.template
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ TORCH_LIBRARY_IMPL(aten, XPU, m) {
"ormqr",
"_pdist_backward",
"_pdist_forward",
"polar.out",
"_prelu_kernel",
"_prelu_kernel_backward",
"prod",
Expand Down
14 changes: 14 additions & 0 deletions src/ATen/native/xpu/sycl/ComplexKernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ void complex_kernel(TensorIterator& iter) {
});
}

template <typename scalar_t>
struct PolarFunctor {
c10::complex<scalar_t> operator()(scalar_t a, scalar_t b) const {
return c10::complex<scalar_t>(a * std::cos(b), a * std::sin(b));
}
};

void polar_kernel(TensorIterator& iter) {
AT_DISPATCH_FLOATING_TYPES(iter.input_dtype(0), "polar_xpu", [&]() {
PolarFunctor<scalar_t> f;
gpu_kernel(iter, f);
});
}

} // namespace at::native::xpu
2 changes: 2 additions & 0 deletions src/ATen/native/xpu/sycl/ComplexKernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ namespace at::native::xpu {

void complex_kernel(TensorIterator& iter);

void polar_kernel(TensorIterator& iter);

} // namespace at::native::xpu
4 changes: 4 additions & 0 deletions test/xpu/extended/run_test_with_skip.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@
# Greatest relative difference: 0.00396728515625 at index (610,) (up to 0.001 allowed)
"test_compare_cpu_hypot_xpu_bfloat16",

# RuntimeError: Expected both inputs to be Half, Float or Double tensors but got BFloat16 and BFloat16.
# Polar's backward is calculated using complex(), which does not support bfloat16. CUDA fails with same error.
"test_compare_cpu_polar_xpu_bfloat16",

# Regressions due to PyTorch uplift (Numeric difference in float and bfloat)
# https://github.com/intel/torch-xpu-ops/issues/549
# Example fail log
Expand Down
4 changes: 4 additions & 0 deletions test/xpu/run_test_with_skip.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,10 @@ def launch_test(test_case, skip_list=None, exe_list=None):
# torch.complex32 - "sinh_cpu" not implemented for 'ComplexHalf'
"test_dtypes_cosh_xpu",

# RuntimeError: Expected both inputs to be Half, Float or Double tensors but got BFloat16 and BFloat16.
# Polar's backward is calculated using complex(), which does not support bfloat16. CUDA fails with same error.
"test_dtypes_polar_xpu",

# implemented aten::histogram to align MPS operators coverage, CUDA doesn't support
# but test_dtypes infrastructure leverage CUDA supported datatypes
"test_dtypes_histogram_xpu",
Expand Down
1 change: 1 addition & 0 deletions test/xpu/xpu_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"unique",
"multinomial",
"lerp",
"polar",
"frac",
"aminmax",
"argmin",
Expand Down
2 changes: 2 additions & 0 deletions yaml/xpu_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ supported:
- eye.m_out
- _efficientzerotensor
- complex.out
- polar.out
- polar
fengyuan14 marked this conversation as resolved.
Show resolved Hide resolved
- clone
- fill_.Scalar
- fill_.Tensor
Expand Down
Loading