From 785adf07b229ab839e21ed9b43095d0f30302b13 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Thu, 10 Oct 2024 11:57:00 +0200 Subject: [PATCH 1/2] W/a issue with lcm kernel on Windows --- .../ufunc/elementwise_functions/gcd.cpp | 10 ---------- .../ufunc/elementwise_functions/lcm.cpp | 10 ---------- .../kernels/elementwise_functions/gcd.hpp | 3 +++ .../kernels/elementwise_functions/lcm.hpp | 17 ++++++++++++++++- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/dpnp/backend/extensions/ufunc/elementwise_functions/gcd.cpp b/dpnp/backend/extensions/ufunc/elementwise_functions/gcd.cpp index ed804939455e..ebe82807f913 100644 --- a/dpnp/backend/extensions/ufunc/elementwise_functions/gcd.cpp +++ b/dpnp/backend/extensions/ufunc/elementwise_functions/gcd.cpp @@ -95,16 +95,6 @@ struct OutputType T2, std::int64_t, std::int64_t>, - td_ns::BinaryTypeMapResultEntry, - td_ns::BinaryTypeMapResultEntry, td_ns::DefaultResultEntry>::result_type; }; diff --git a/dpnp/backend/extensions/ufunc/elementwise_functions/lcm.cpp b/dpnp/backend/extensions/ufunc/elementwise_functions/lcm.cpp index d02e98236240..e1fcab3eccfb 100644 --- a/dpnp/backend/extensions/ufunc/elementwise_functions/lcm.cpp +++ b/dpnp/backend/extensions/ufunc/elementwise_functions/lcm.cpp @@ -95,16 +95,6 @@ struct OutputType T2, std::int64_t, std::int64_t>, - td_ns::BinaryTypeMapResultEntry, - td_ns::BinaryTypeMapResultEntry, td_ns::DefaultResultEntry>::result_type; }; diff --git a/dpnp/backend/kernels/elementwise_functions/gcd.hpp b/dpnp/backend/kernels/elementwise_functions/gcd.hpp index e643e9559003..426dd6a3cd23 100644 --- a/dpnp/backend/kernels/elementwise_functions/gcd.hpp +++ b/dpnp/backend/kernels/elementwise_functions/gcd.hpp @@ -38,6 +38,9 @@ struct GcdFunctor resT operator()(const argT1 &in1, const argT2 &in2) const { + static_assert(std::is_same_v, + "Input types are expected to be the same"); + return oneapi::dpl::gcd(in1, in2); } }; diff --git a/dpnp/backend/kernels/elementwise_functions/lcm.hpp b/dpnp/backend/kernels/elementwise_functions/lcm.hpp index f1a346addd46..b3696f07fec9 100644 --- a/dpnp/backend/kernels/elementwise_functions/lcm.hpp +++ b/dpnp/backend/kernels/elementwise_functions/lcm.hpp @@ -38,7 +38,22 @@ struct LcmFunctor resT operator()(const argT1 &in1, const argT2 &in2) const { - return oneapi::dpl::lcm(in1, in2); + static_assert(std::is_same_v, + "Input types are expected to be the same"); + + if (in1 == 0 || in2 == 0) + return 0; + + resT res = in1 / oneapi::dpl::gcd(in1, in2) * in2; + if constexpr (std::is_signed_v) { + if (res < 0) { + return -res; + } + } + return res; + + // TODO: address the issue to OneDPL team + // return oneapi::dpl::lcm(in1, in2); } }; } // namespace dpnp::kernels::lcm From ad5a69921fd522c980967ba49ad5b3a368652695 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Sat, 12 Oct 2024 11:30:50 +0200 Subject: [PATCH 2/2] Update TODO comment to point on Jira ticket with issue --- dpnp/backend/kernels/elementwise_functions/lcm.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpnp/backend/kernels/elementwise_functions/lcm.hpp b/dpnp/backend/kernels/elementwise_functions/lcm.hpp index b3696f07fec9..13c3804e593c 100644 --- a/dpnp/backend/kernels/elementwise_functions/lcm.hpp +++ b/dpnp/backend/kernels/elementwise_functions/lcm.hpp @@ -52,7 +52,7 @@ struct LcmFunctor } return res; - // TODO: address the issue to OneDPL team + // TODO: undo the w/a once ONEDPL-1320 is resolved // return oneapi::dpl::lcm(in1, in2); } };