Skip to content

Commit

Permalink
Merge branch 'main' into majing/histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
majing921201 authored Jul 12, 2024
2 parents 85f42f4 + 78575b6 commit 5fdaa12
Show file tree
Hide file tree
Showing 23 changed files with 538 additions and 32 deletions.
48 changes: 48 additions & 0 deletions src/ATen/native/xpu/BinaryOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <ATen/native/xpu/sycl/BinaryKernels.h>
#include <ATen/native/xpu/sycl/BinaryMiscBackwardOpsKernels.h>
#include <ATen/native/xpu/sycl/BinaryRemainderKernel.h>
#include <ATen/native/xpu/sycl/CopysignKernel.h>
#include <ATen/native/xpu/sycl/GcdLcmKernels.h>
#include <ATen/native/xpu/sycl/MaxMinElementwiseKernels.h>

Expand Down Expand Up @@ -477,4 +478,51 @@ 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;
}

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

Tensor& XPUNativeFunctions::copysign_(Tensor& self, const Tensor& other) {
return XPUNativeFunctions::copysign_out(self, other, self);
}

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

} // namespace at
1 change: 1 addition & 0 deletions src/ATen/native/xpu/Indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ Tensor XPUNativeFunctions::index_select(
auto out = at::empty({0}, self.options());
return index_select_out(self, dim, index, out);
}

} // namespace at
4 changes: 4 additions & 0 deletions src/ATen/native/xpu/TensorAdvancedIndexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1396,4 +1396,8 @@ Tensor& XPUNativeFunctions::gather_out(
return out;
}

Tensor XPUNativeFunctions::count_nonzero(const Tensor& self, IntArrayRef dims) {
return (self != 0).sum(dims);
}

} // 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
8 changes: 0 additions & 8 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 @@ -179,9 +174,6 @@ TORCH_LIBRARY_IMPL(aten, XPU, m) {
"cholesky",
"cholesky_inverse",
"_cholesky_solve_helper",
"copysign.out",
"cosh.out",
"count_nonzero.dim_IntList",
"_ctc_loss",
"_ctc_loss_backward",
"_cummax_helper",
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
24 changes: 24 additions & 0 deletions src/ATen/native/xpu/sycl/CopysignKernel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <ATen/Dispatch.h>
#include <ATen/native/TensorIterator.h>

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

namespace at::native::xpu {

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

void copysign_kernel(TensorIteratorBase& iter) {
AT_DISPATCH_FLOATING_TYPES_AND2(
at::ScalarType::Half,
at::ScalarType::BFloat16,
iter.common_dtype(),
"copysign_xpu",
[&]() { gpu_kernel_with_scalars(iter, CopysignFunctor<scalar_t>()); });
}

} // namespace at::native::xpu
9 changes: 9 additions & 0 deletions src/ATen/native/xpu/sycl/CopysignKernel.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 copysign_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
Loading

0 comments on commit 5fdaa12

Please sign in to comment.