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 atan::asinh, atan::atan, atan::atan2, atan::atanh, atan::asin, atan::cosh #457

Merged
merged 24 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions src/ATen/native/xpu/BinaryOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,29 @@ Tensor XPUNativeFunctions::sigmoid_backward(
return iter.output();
}

Tensor XPUNativeFunctions::atan2(const Tensor& self, const Tensor& other) {
Tensor out;
TensorIterator iter;
iter.build_borrowing_binary_float_op(out, self, other);
native::xpu::atan2_kernel(iter);
return iter.output();
}

Tensor& XPUNativeFunctions::atan2_(Tensor& self, const Tensor& other) {
TensorIterator iter;
iter.build_borrowing_binary_float_op(self, self, other);
native::xpu::atan2_kernel(iter);
return self;
}

Tensor& XPUNativeFunctions::atan2_out(
const Tensor& self,
const Tensor& other,
Tensor& out) {
TensorIterator iter;
iter.build_borrowing_binary_float_op(out, self, other);
native::xpu::atan2_kernel(iter);
return out;
}

} // namespace at
115 changes: 115 additions & 0 deletions src/ATen/native/xpu/UnaryOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
#include <ATen/native/xpu/sycl/UnaryFractionKernels.h>
#include <ATen/native/xpu/sycl/UnaryGeometricAcosKernel.h>
#include <ATen/native/xpu/sycl/UnaryGeometricAcoshKernel.h>
#include <ATen/native/xpu/sycl/UnaryGeometricAsinKernel.h>
#include <ATen/native/xpu/sycl/UnaryGeometricAsinhKernel.h>
#include <ATen/native/xpu/sycl/UnaryGeometricAtanKernel.h>
#include <ATen/native/xpu/sycl/UnaryGeometricAtanhKernel.h>
#include <ATen/native/xpu/sycl/UnaryGeometricCosKernel.h>
#include <ATen/native/xpu/sycl/UnaryGeometricCoshKernel.h>
#include <ATen/native/xpu/sycl/UnaryGeometricSinKernel.h>
#include <ATen/native/xpu/sycl/UnaryGeometricTanhKernel.h>
#include <ATen/native/xpu/sycl/UnaryKernels.h>
Expand Down Expand Up @@ -516,6 +521,116 @@ Tensor& XPUNativeFunctions::erfc_out(const Tensor& self, Tensor& out) {
return out;
}

Tensor XPUNativeFunctions::asinh(const Tensor& self) {
Tensor out;
TensorIterator iter;
iter.build_borrowing_unary_float_op(out, self);
native::xpu::asinh_kernel(iter);
return iter.output();
}

Tensor& XPUNativeFunctions::asinh_(Tensor& self) {
TensorIterator iter;
iter.build_borrowing_unary_float_op(self, self);
native::xpu::asinh_kernel(iter);
return self;
}

Tensor& XPUNativeFunctions::asinh_out(const Tensor& self, Tensor& out) {
TensorIterator iter;
iter.build_borrowing_unary_float_op(out, self);
native::xpu::asinh_kernel(iter);
return out;
}

Tensor XPUNativeFunctions::asin(const Tensor& self) {
Tensor out;
TensorIterator iter;
iter.build_borrowing_unary_float_op(out, self);
native::xpu::asin_kernel(iter);
return iter.output();
}

Tensor& XPUNativeFunctions::asin_(Tensor& self) {
TensorIterator iter;
iter.build_borrowing_unary_float_op(self, self);
native::xpu::asin_kernel(iter);
return self;
}

Tensor& XPUNativeFunctions::asin_out(const Tensor& self, Tensor& out) {
TensorIterator iter;
iter.build_borrowing_unary_float_op(out, self);
native::xpu::asin_kernel(iter);
return out;
}

Tensor XPUNativeFunctions::atan(const Tensor& self) {
Tensor out;
TensorIterator iter;
iter.build_borrowing_unary_float_op(out, self);
native::xpu::atan_kernel(iter);
return iter.output();
}

Tensor& XPUNativeFunctions::atan_(Tensor& self) {
TensorIterator iter;
iter.build_borrowing_unary_float_op(self, self);
native::xpu::atan_kernel(iter);
return self;
}

Tensor& XPUNativeFunctions::atan_out(const Tensor& self, Tensor& out) {
TensorIterator iter;
iter.build_borrowing_unary_float_op(out, self);
native::xpu::atan_kernel(iter);
return out;
}

Tensor XPUNativeFunctions::atanh(const Tensor& self) {
Tensor out;
TensorIterator iter;
iter.build_borrowing_unary_float_op(out, self);
native::xpu::atanh_kernel(iter);
return iter.output();
}

Tensor& XPUNativeFunctions::atanh_(Tensor& self) {
TensorIterator iter;
iter.build_borrowing_unary_float_op(self, self);
native::xpu::atanh_kernel(iter);
return self;
}

Tensor& XPUNativeFunctions::atanh_out(const Tensor& self, Tensor& out) {
TensorIterator iter;
iter.build_borrowing_unary_float_op(out, self);
native::xpu::atanh_kernel(iter);
return out;
}

Tensor XPUNativeFunctions::cosh(const Tensor& self) {
Tensor out;
TensorIterator iter;
iter.build_borrowing_unary_float_op(out, self);
native::xpu::cosh_kernel(iter);
return iter.output();
}

Tensor& XPUNativeFunctions::cosh_(Tensor& self) {
TensorIterator iter;
iter.build_borrowing_unary_float_op(self, self);
native::xpu::cosh_kernel(iter);
return self;
}

Tensor& XPUNativeFunctions::cosh_out(const Tensor& self, Tensor& out) {
TensorIterator iter;
iter.build_borrowing_unary_float_op(out, self);
native::xpu::cosh_kernel(iter);
return out;
}

Tensor& XPUNativeFunctions::conj_physical_out(const Tensor& self, Tensor& out) {
auto iter = TensorIterator::unary_op(out, self);
native::xpu::conj_physical_kernel(iter);
Expand Down
6 changes: 0 additions & 6 deletions src/ATen/native/xpu/XPUFallback.template
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ TORCH_LIBRARY_IMPL(aten, XPU, m) {
"aminmax.out",
"angle",
"argmin.out",
"asinh.out",
"asin.out",
"atan2.out",
"atanh.out",
"atan.out",
"avg_pool3d_backward.grad_input",
"avg_pool3d.out",
"binary_cross_entropy",
Expand All @@ -180,7 +175,6 @@ TORCH_LIBRARY_IMPL(aten, XPU, m) {
"cholesky_inverse",
"_cholesky_solve_helper",
"copysign.out",
"cosh.out",
"count_nonzero.dim_IntList",
"_ctc_loss",
"_ctc_loss_backward",
Expand Down
17 changes: 16 additions & 1 deletion src/ATen/native/xpu/sycl/BinaryGeometricKernels.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
#include <ATen/ATen.h>
#include <ATen/Dispatch.h>
#include <ATen/native/TensorIterator.h>

#include <ATen/native/xpu/sycl/Loops.h>

namespace at {
namespace native {
namespace xpu {

template <typename scalar_t>
struct Atan2Functor {
scalar_t operator()(scalar_t a, scalar_t b) const {
return std::atan2(a, b);
}
};

void atan2_kernel(TensorIteratorBase& iter) {
AT_DISPATCH_FLOATING_TYPES_AND2(
at::ScalarType::BFloat16,
at::ScalarType::Half,
iter.common_dtype(),
"atan2_xpu",
[&]() { gpu_kernel(iter, Atan2Functor<scalar_t>()); });
}

template <typename scalar_t>
struct HypotFunctor {
scalar_t operator()(scalar_t a, scalar_t b) const {
Expand Down
2 changes: 2 additions & 0 deletions src/ATen/native/xpu/sycl/BinaryGeometricKernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace at::native::xpu {

void atan2_kernel(TensorIteratorBase& iter);

void hypot_kernel(TensorIteratorBase& iter);

} // namespace at::native::xpu
40 changes: 40 additions & 0 deletions src/ATen/native/xpu/sycl/UnaryGeometricAsinKernel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <ATen/Dispatch.h>
#include <ATen/OpMathType.h>

#include <ATen/native/xpu/sycl/Loops.h>

namespace at::native::xpu {

template <typename scalar_t>
struct AsinComplexFunctor {
using opmath_t = at::opmath_type<scalar_t>;
scalar_t operator()(const scalar_t a) const {
return std::asin(static_cast<opmath_t>(a));
}
};

template <typename scalar_t>
struct AsinFunctor {
scalar_t operator()(const scalar_t a) const {
return std::asin(a);
}
};

void asin_kernel(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
AT_DISPATCH_COMPLEX_TYPES_AND(
kComplexHalf, common_dtype, "asin_xpu", [&]() {
gpu_kernel(iter, AsinComplexFunctor<scalar_t>());
});
} else {
AT_DISPATCH_FLOATING_TYPES_AND2(
ScalarType::Half,
ScalarType::BFloat16,
common_dtype,
"asin_xpu",
[&]() { gpu_kernel(iter, AsinFunctor<scalar_t>()); });
}
}

} // namespace at::native::xpu
9 changes: 9 additions & 0 deletions src/ATen/native/xpu/sycl/UnaryGeometricAsinKernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <ATen/native/TensorIterator.h>

namespace at::native::xpu {

void asin_kernel(TensorIteratorBase& iter);

} // namespace at::native::xpu
40 changes: 40 additions & 0 deletions src/ATen/native/xpu/sycl/UnaryGeometricAsinhKernel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <ATen/Dispatch.h>
#include <ATen/OpMathType.h>

#include <ATen/native/xpu/sycl/Loops.h>

namespace at::native::xpu {

template <typename scalar_t>
struct AsinhComplexFunctor {
using opmath_t = at::opmath_type<scalar_t>;
scalar_t operator()(const scalar_t a) const {
return std::asinh(static_cast<opmath_t>(a));
}
};

template <typename scalar_t>
struct AsinhFunctor {
scalar_t operator()(const scalar_t a) const {
return std::asinh(a);
}
};

void asinh_kernel(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
AT_DISPATCH_COMPLEX_TYPES_AND(
kComplexHalf, common_dtype, "asinh_xpu", [&]() {
gpu_kernel(iter, AsinhComplexFunctor<scalar_t>());
});
} else {
AT_DISPATCH_FLOATING_TYPES_AND2(
ScalarType::Half,
ScalarType::BFloat16,
common_dtype,
"asinh_xpu",
[&]() { gpu_kernel(iter, AsinhFunctor<scalar_t>()); });
}
}

} // namespace at::native::xpu
9 changes: 9 additions & 0 deletions src/ATen/native/xpu/sycl/UnaryGeometricAsinhKernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <ATen/native/TensorIterator.h>

namespace at::native::xpu {

void asinh_kernel(TensorIteratorBase& iter);

} // namespace at::native::xpu
40 changes: 40 additions & 0 deletions src/ATen/native/xpu/sycl/UnaryGeometricAtanKernel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <ATen/Dispatch.h>
#include <ATen/OpMathType.h>

#include <ATen/native/xpu/sycl/Loops.h>

namespace at::native::xpu {

template <typename scalar_t>
struct AtanComplexFunctor {
using opmath_t = at::opmath_type<scalar_t>;
scalar_t operator()(const scalar_t a) const {
return std::atan(static_cast<opmath_t>(a));
}
};

template <typename scalar_t>
struct AtanFunctor {
scalar_t operator()(const scalar_t a) const {
return std::atan(a);
}
};

void atan_kernel(TensorIteratorBase& iter) {
auto common_dtype = iter.common_dtype();
if (at::isComplexType(common_dtype)) {
AT_DISPATCH_COMPLEX_TYPES_AND(
kComplexHalf, common_dtype, "atan_xpu", [&]() {
gpu_kernel(iter, AtanComplexFunctor<scalar_t>());
});
} else {
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES_AND2(
ScalarType::Half,
ScalarType::BFloat16,
common_dtype,
"atan_xpu",
[&]() { gpu_kernel(iter, AtanFunctor<scalar_t>()); });
}
}

} // namespace at::native::xpu
9 changes: 9 additions & 0 deletions src/ATen/native/xpu/sycl/UnaryGeometricAtanKernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <ATen/native/TensorIterator.h>

namespace at::native::xpu {

void atan_kernel(TensorIteratorBase& iter);

} // namespace at::native::xpu
Loading