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::lop10/log1p/log2 and their variants #519

Merged
merged 8 commits into from
Jul 17, 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
66 changes: 66 additions & 0 deletions src/ATen/native/xpu/UnaryOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,72 @@ Tensor& XPUNativeFunctions::log_out(const Tensor& self, Tensor& out) {
return out;
}

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

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

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

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

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

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

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

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

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

Tensor XPUNativeFunctions::sqrt(const Tensor& self) {
Tensor out;
TensorIterator iter;
Expand Down
3 changes: 0 additions & 3 deletions src/ATen/native/xpu/XPUFallback.template
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ TORCH_LIBRARY_IMPL(aten, XPU, m) {
"linalg_solve_triangular",
"_linalg_svd.U",
"linspace.out",
"log10.out",
"log1p.out",
"log2.out",
"logaddexp2.out",
"logaddexp.out",
"_logcumsumexp",
Expand Down
48 changes: 48 additions & 0 deletions src/ATen/native/xpu/sycl/UnaryLogKernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,52 @@ void log_kernel(TensorIteratorBase& iter) {
}
}

template <typename scalar_t>
struct Log10Functor {
scalar_t operator()(scalar_t x) const {
return std::log10(x);
}
};

void log10_kernel(TensorIteratorBase& iter) {
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES_AND2(
ScalarType::Half,
ScalarType::BFloat16,
iter.common_dtype(),
"log10_xpu",
[&]() { gpu_kernel(iter, Log10Functor<scalar_t>()); });
}

template <typename scalar_t>
struct Log1pFunctor {
scalar_t operator()(scalar_t x) const {
return std::log1p(x);
}
};

void log1p_kernel(TensorIteratorBase& iter) {
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES_AND2(
ScalarType::Half,
ScalarType::BFloat16,
iter.common_dtype(),
"log1p_xpu",
[&]() { gpu_kernel(iter, Log1pFunctor<scalar_t>()); });
}

template <typename scalar_t>
struct Log2Functor {
scalar_t operator()(scalar_t x) const {
return std::log2(x);
}
};

void log2_kernel(TensorIteratorBase& iter) {
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES_AND2(
ScalarType::Half,
ScalarType::BFloat16,
iter.common_dtype(),
"log2_xpu",
[&]() { gpu_kernel(iter, Log2Functor<scalar_t>()); });
}

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

void log_kernel(TensorIteratorBase& iter);

void log10_kernel(TensorIteratorBase& iter);

void log1p_kernel(TensorIteratorBase& iter);

void log2_kernel(TensorIteratorBase& 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 @@ -13,6 +13,10 @@
"test_compare_cpu_cumsum_xpu_bfloat16",
"test_compare_cpu_cumsum_xpu_float16",
"test_compare_cpu_log_xpu_complex64",
"test_compare_cpu_log10_xpu_complex64",
"test_compare_cpu_log1p_xpu_complex64",
"test_compare_cpu_log2_xpu_complex64",
"test_compare_cpu_log2_xpu_complex128",
"test_compare_cpu_mul_xpu_complex64",
"test_compare_cpu_pow_xpu_complex128",
"test_compare_cpu_pow_xpu_complex64",
Expand Down
21 changes: 19 additions & 2 deletions test/xpu/run_test_with_skip.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def launch_test(test_case, skip_list=None, exe_list=None):
res = 0

# test_ops


skip_list = (
# Skip list of base line
"test_dtypes___rmod___xpu",
Expand Down Expand Up @@ -794,6 +792,14 @@ def launch_test(test_case, skip_list=None, exe_list=None):
# in XPU supported operators. Then the case will work.
"test_noncontiguous_samples_nn_functional_avg_pool1d_xpu_int64",
"test_noncontiguous_samples_nn_functional_local_response_norm_xpu_int64",

# Numeric difference
# https://github.com/intel/torch-xpu-ops/issues/544
# Mismatched elements: 7 / 1048576 (0.0%)
# Greatest absolute difference: 0.4922053598013041 at index (765, 860) (up to 1e-07 allowed)
# Greatest relative difference: 0.15330001655652495 at index (765, 860) (up to 1e-07 allowed)
"test_python_ref__refs_log2_xpu_complex128",

# torch.complex32 - "sinh_cpu" not implemented for 'ComplexHalf'
"test_dtypes_cosh_xpu",
)
Expand Down Expand Up @@ -1520,6 +1526,10 @@ def launch_test(test_case, skip_list=None, exe_list=None):
"test_reference_numerics_extremal_asin_xpu_complex64",
"test_reference_numerics_large__refs_acosh_xpu_complex64",
"test_reference_numerics_large_acosh_xpu_complex64",
"test_reference_numerics_extremal__refs_log10_xpu_complex64",
"test_reference_numerics_extremal__refs_log1p_xpu_complex64",
"test_reference_numerics_extremal_log10_xpu_complex64",
"test_reference_numerics_extremal_log1p_xpu_complex64",
"test_reference_numerics_extremal__refs_tan_xpu_complex128",
"test_reference_numerics_extremal__refs_tan_xpu_complex64",
"test_reference_numerics_extremal_tan_xpu_complex128",
Expand Down Expand Up @@ -1547,6 +1557,13 @@ def launch_test(test_case, skip_list=None, exe_list=None):
# Failed: Unexpected success
"test_reference_numerics_large__refs_rsqrt_xpu_complex32",
"test_reference_numerics_large_rsqrt_xpu_complex32",

# Numeric difference
# https://github.com/intel/torch-xpu-ops/issues/544
# Expected 0.00497517 but got 0.00497520063072443.
# Absolute difference: 3.063072442997111e-08 (up to 0.0 allowed)
# Relative difference: 6.156719153309558e-06 (up to 1e-06 allowed)
"test_log1p_complex_xpu_complex64",
)
res += launch_test("test_unary_ufuncs_xpu.py", skip_list)

Expand Down
3 changes: 3 additions & 0 deletions test/xpu/xpu_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
"isnan",
"le",
"log",
"log10",
"log1p",
"log2",
"lt",
"logical_and",
"logical_or",
Expand Down
9 changes: 9 additions & 0 deletions yaml/xpu_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ supported:
- log
- log_
- log.out
- log10
- log10_
- log10.out
- log1p
- log1p_
- log1p.out
- log2
- log2_
- log2.out
- logical_and
- logical_and_
- logical_and.out
Expand Down