Skip to content

Commit 6781c4a

Browse files
hjheefengyuan14
andauthored
Add aten::ceil (#463)
- ceil.out - ceil - ceil_ --------- Co-authored-by: Feng Yuan <[email protected]>
1 parent 3fc911b commit 6781c4a

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

src/ATen/native/xpu/UnaryOps.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,4 +515,40 @@ Tensor& XPUNativeFunctions::erfc_out(const Tensor& self, Tensor& out) {
515515
return out;
516516
}
517517

518+
TensorIterator ceil_meta(const Tensor& self, Tensor& out) {
519+
TORCH_CHECK(!self.is_complex(), "ceil is not supported for complex inputs");
520+
TensorIterator iter;
521+
iter.build_borrowing_unary_op(out, self);
522+
return iter;
523+
}
524+
525+
Tensor XPUNativeFunctions::ceil(const Tensor& self) {
526+
if (c10::isIntegralType(self.scalar_type(), /*includeBool=*/false)) {
527+
return self.clone();
528+
}
529+
Tensor out;
530+
auto iter = ceil_meta(self, out);
531+
native::xpu::ceil_kernel(iter);
532+
return iter.output();
533+
}
534+
535+
Tensor& XPUNativeFunctions::ceil_(Tensor& self) {
536+
if (c10::isIntegralType(self.scalar_type(), /*includeBool=*/false)) {
537+
return self;
538+
}
539+
auto iter = ceil_meta(self, self);
540+
native::xpu::ceil_kernel(iter);
541+
return self;
542+
}
543+
544+
Tensor& XPUNativeFunctions::ceil_out(const Tensor& self, Tensor& out) {
545+
if (c10::isIntegralType(self.scalar_type(), /*includeBool=*/false)) {
546+
out.copy_(self);
547+
return out;
548+
}
549+
auto iter = ceil_meta(self, out);
550+
native::xpu::ceil_kernel(iter);
551+
return out;
552+
}
553+
518554
} // namespace at

src/ATen/native/xpu/XPUFallback.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ TORCH_LIBRARY_IMPL(aten, XPU, m) {
180180
"bitwise_right_shift.Tensor_out",
181181
"cauchy_",
182182
"_cdist_backward",
183-
"ceil.out",
184183
"channel_shuffle",
185184
"cholesky",
186185
"cholesky_inverse",

src/ATen/native/xpu/sycl/UnaryFractionKernels.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,25 @@ void reciprocal_kernel(TensorIteratorBase& iter) {
5555
[&]() { gpu_kernel(iter, ReciprocalFunctor<scalar_t>()); });
5656
}
5757

58+
template <typename scalar_t>
59+
struct CeilFunctor {
60+
scalar_t operator()(const scalar_t a) const {
61+
return std::ceil(a);
62+
}
63+
};
64+
65+
template <typename T>
66+
struct CeilFunctor<c10::complex<T>> {
67+
c10::complex<T> operator()(const c10::complex<T> a) const {
68+
return c10::complex<T>(std::ceil(a.real()), std::ceil(a.imag()));
69+
}
70+
};
71+
72+
void ceil_kernel(TensorIteratorBase& iter) {
73+
AT_DISPATCH_FLOATING_TYPES_AND2(
74+
ScalarType::Half, ScalarType::BFloat16, iter.dtype(), "ceil_xpu", [&]() {
75+
gpu_kernel(iter, CeilFunctor<scalar_t>());
76+
});
77+
}
78+
5879
} // namespace at::native::xpu

src/ATen/native/xpu/sycl/UnaryFractionKernels.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ namespace at::native::xpu {
66

77
void reciprocal_kernel(TensorIteratorBase& iter);
88

9+
void ceil_kernel(TensorIteratorBase& iter);
10+
911
} // namespace at::native::xpu

yaml/xpu_functions.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,6 @@ supported:
500500
- randperm.generator_out
501501
- _amp_foreach_non_finite_check_and_unscale_
502502
- _amp_update_scale_
503+
- ceil
504+
- ceil_
505+
- ceil.out

0 commit comments

Comments
 (0)