Skip to content

Commit 63ffaba

Browse files
Merge pull request #1802 from IntelPython/clean-up-reduction-headers
Explicitly include headers used in the c++ file pertaining to reduction
2 parents f19d57b + 146f66e commit 63ffaba

File tree

10 files changed

+46
-12
lines changed

10 files changed

+46
-12
lines changed

dpctl/tensor/libtensor/include/kernels/reductions.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@
3939
#include "utils/type_dispatch_building.hpp"
4040
#include "utils/type_utils.hpp"
4141

42-
namespace td_ns = dpctl::tensor::type_dispatch;
43-
namespace su_ns = dpctl::tensor::sycl_utils;
44-
4542
namespace dpctl
4643
{
4744
namespace tensor
4845
{
4946
namespace kernels
5047
{
5148

49+
namespace td_ns = dpctl::tensor::type_dispatch;
50+
namespace su_ns = dpctl::tensor::sycl_utils;
51+
5252
namespace reduction_detail
5353
{
5454

dpctl/tensor/libtensor/include/utils/math_utils.hpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,32 @@ template <typename T> T logaddexp(T x, T y)
122122
return x + log2;
123123
}
124124
else {
125-
// FIXME: switch to `sycl::log1p` when
126-
// compiler segfault in CUDA build is fixed
127125
const T tmp = x - y;
128-
if (tmp > 0) {
129-
return x + std::log1p(sycl::exp(-tmp));
130-
}
131-
else if (tmp <= 0) {
132-
return y + std::log1p(sycl::exp(tmp));
126+
constexpr T zero(0);
127+
128+
if constexpr (std::is_same_v<T, sycl::half>) {
129+
return (tmp > zero)
130+
? (x + sycl::log1p(sycl::exp(-tmp)))
131+
: ((tmp <= zero) ? y + sycl::log1p(sycl::exp(tmp))
132+
: std::numeric_limits<T>::quiet_NaN());
133133
}
134134
else {
135-
return std::numeric_limits<T>::quiet_NaN();
135+
if constexpr (std::is_same_v<T, double>) {
136+
// FIXME: switch to `sycl::log1p` when
137+
// compiler segfault in CUDA build is fixed
138+
return (tmp > zero)
139+
? (x + std::log1p(sycl::exp(-tmp)))
140+
: ((tmp <= zero)
141+
? y + std::log1p(sycl::exp(tmp))
142+
: std::numeric_limits<T>::quiet_NaN());
143+
}
144+
else {
145+
return (tmp > zero)
146+
? (x + sycl::log1p(sycl::exp(-tmp)))
147+
: ((tmp <= zero)
148+
? y + sycl::log1p(sycl::exp(tmp))
149+
: std::numeric_limits<T>::quiet_NaN());
150+
}
136151
}
137152
}
138153
}

dpctl/tensor/libtensor/source/linalg_functions/dot_dispatch.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "kernels/linalg_functions/dot_product.hpp"
3232
#include "kernels/linalg_functions/gemm.hpp"
33+
#include "utils/type_dispatch_building.hpp"
3334

3435
namespace dpctl
3536
{
@@ -38,6 +39,8 @@ namespace tensor
3839
namespace py_internal
3940
{
4041

42+
namespace td_ns = dpctl::tensor::type_dispatch;
43+
4144
template <typename T1, typename T2> struct DotAtomicOutputType
4245
{
4346
using value_type = typename std::disjunction< // disjunction is C++17

dpctl/tensor/libtensor/source/reductions/argmax.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "kernels/reductions.hpp"
3434
#include "reduction_over_axis.hpp"
35+
#include "utils/sycl_utils.hpp"
3536
#include "utils/type_dispatch_building.hpp"
3637

3738
namespace py = pybind11;
@@ -44,6 +45,7 @@ namespace py_internal
4445
{
4546

4647
namespace td_ns = dpctl::tensor::type_dispatch;
48+
namespace su_ns = dpctl::tensor::sycl_utils;
4749

4850
namespace impl
4951
{

dpctl/tensor/libtensor/source/reductions/argmin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#include "kernels/reductions.hpp"
3434
#include "reduction_over_axis.hpp"
35+
36+
#include "utils/sycl_utils.hpp"
3537
#include "utils/type_dispatch_building.hpp"
3638

3739
namespace py = pybind11;
@@ -44,6 +46,7 @@ namespace py_internal
4446
{
4547

4648
namespace td_ns = dpctl::tensor::type_dispatch;
49+
namespace su_ns = dpctl::tensor::sycl_utils;
4750

4851
namespace impl
4952
{

dpctl/tensor/libtensor/source/reductions/logsumexp.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "kernels/reductions.hpp"
3434
#include "reduction_over_axis.hpp"
35+
#include "utils/sycl_utils.hpp"
3536
#include "utils/type_dispatch_building.hpp"
3637

3738
namespace py = pybind11;
@@ -44,6 +45,7 @@ namespace py_internal
4445
{
4546

4647
namespace td_ns = dpctl::tensor::type_dispatch;
48+
namespace su_ns = dpctl::tensor::sycl_utils;
4749

4850
namespace impl
4951
{
@@ -68,6 +70,7 @@ struct TypePairSupportDataForLogSumExpReductionTemps
6870
static constexpr bool is_defined = std::disjunction< // disjunction is C++17
6971
// feature, supported
7072
// by DPC++ input bool
73+
#if 1
7174
td_ns::TypePairDefinedEntry<argTy, bool, outTy, sycl::half>,
7275
td_ns::TypePairDefinedEntry<argTy, bool, outTy, float>,
7376
td_ns::TypePairDefinedEntry<argTy, bool, outTy, double>,
@@ -105,7 +108,6 @@ struct TypePairSupportDataForLogSumExpReductionTemps
105108
// input uint64_t
106109
td_ns::TypePairDefinedEntry<argTy, std::uint64_t, outTy, float>,
107110
td_ns::TypePairDefinedEntry<argTy, std::uint64_t, outTy, double>,
108-
109111
// input half
110112
td_ns::TypePairDefinedEntry<argTy, sycl::half, outTy, sycl::half>,
111113
td_ns::TypePairDefinedEntry<argTy, sycl::half, outTy, float>,
@@ -117,6 +119,7 @@ struct TypePairSupportDataForLogSumExpReductionTemps
117119

118120
// input double
119121
td_ns::TypePairDefinedEntry<argTy, double, outTy, double>,
122+
#endif
120123

121124
// fall-through
122125
td_ns::NotDefinedEntry>::is_defined;

dpctl/tensor/libtensor/source/reductions/max.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <vector>
3232

3333
#include "kernels/reductions.hpp"
34+
#include "utils/sycl_utils.hpp"
3435
#include "utils/type_dispatch_building.hpp"
3536

3637
#include "reduction_atomic_support.hpp"
@@ -46,6 +47,7 @@ namespace py_internal
4647
{
4748

4849
namespace td_ns = dpctl::tensor::type_dispatch;
50+
namespace su_ns = dpctl::tensor::sycl_utils;
4951

5052
namespace impl
5153
{

dpctl/tensor/libtensor/source/reductions/min.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <vector>
3232

3333
#include "kernels/reductions.hpp"
34+
#include "utils/sycl_utils.hpp"
3435
#include "utils/type_dispatch_building.hpp"
3536

3637
#include "reduction_atomic_support.hpp"
@@ -46,6 +47,7 @@ namespace py_internal
4647
{
4748

4849
namespace td_ns = dpctl::tensor::type_dispatch;
50+
namespace su_ns = dpctl::tensor::sycl_utils;
4951

5052
namespace impl
5153
{

dpctl/tensor/libtensor/source/reductions/reduce_hypot.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "kernels/reductions.hpp"
3434
#include "reduction_over_axis.hpp"
35+
#include "utils/sycl_utils.hpp"
3536
#include "utils/type_dispatch_building.hpp"
3637

3738
namespace py = pybind11;
@@ -44,6 +45,7 @@ namespace py_internal
4445
{
4546

4647
namespace td_ns = dpctl::tensor::type_dispatch;
48+
namespace su_ns = dpctl::tensor::sycl_utils;
4749

4850
namespace impl
4951
{

dpctl/tensor/libtensor/source/reductions/reduction_over_axis.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ namespace tensor
5252
namespace py_internal
5353
{
5454

55+
namespace td_ns = dpctl::tensor::type_dispatch;
56+
5557
/* ====================== dtype supported ======================== */
5658

5759
/*! @brief Template implementing Python API for querying type support by

0 commit comments

Comments
 (0)