Skip to content

Commit c81735a

Browse files
authored
Merge pull request #1707 from IntelPython/replace-some-std-namepsace-functions-with-sycl-namespace-functions
Remove USE_SYCL_FOR_COMPLEX_TYPES
2 parents f114571 + 6ea1120 commit c81735a

38 files changed

+124
-491
lines changed

dpctl/tensor/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ foreach(_src_fn ${_no_fast_math_sources})
231231
)
232232
endforeach()
233233

234-
set(_compiler_definitions "USE_SYCL_FOR_COMPLEX_TYPES")
234+
set(_compiler_definitions "")
235235

236236
foreach(_src_fn ${_elementwise_sources})
237237
get_source_file_property(_cmpl_options_defs ${_src_fn} COMPILE_DEFINITIONS)

dpctl/tensor/libtensor/include/kernels/elementwise_functions/abs.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ template <typename argT, typename resT> struct AbsFunctor
7878
else if constexpr (std::is_same_v<argT, sycl::half> ||
7979
std::is_floating_point_v<argT>)
8080
{
81-
return (std::signbit(x) ? -x : x);
81+
return (sycl::signbit(x) ? -x : x);
8282
}
8383
else {
8484
return sycl::abs(x);

dpctl/tensor/libtensor/include/kernels/elementwise_functions/acos.hpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ template <typename argT, typename resT> struct AcosFunctor
8989
}
9090
/* acos(0 + I*NaN) = PI/2 + I*NaN with inexact */
9191
if (x == realT(0)) {
92-
const realT res_re = std::atan(realT(1)) * 2; // PI/2
92+
const realT res_re = sycl::atan(realT(1)) * 2; // PI/2
9393
return resT{res_re, q_nan};
9494
}
9595

@@ -103,7 +103,6 @@ template <typename argT, typename resT> struct AcosFunctor
103103
constexpr realT r_eps =
104104
realT(1) / std::numeric_limits<realT>::epsilon();
105105
if (sycl::fabs(x) > r_eps || sycl::fabs(y) > r_eps) {
106-
#ifdef USE_SYCL_FOR_COMPLEX_TYPES
107106
using sycl_complexT = exprm_ns::complex<realT>;
108107
sycl_complexT log_in =
109108
exprm_ns::log(exprm_ns::complex<realT>(in));
@@ -112,31 +111,17 @@ template <typename argT, typename resT> struct AcosFunctor
112111
const realT wy = log_in.imag();
113112
const realT rx = sycl::fabs(wy);
114113

115-
realT ry = wx + std::log(realT(2));
116-
return resT{rx, (std::signbit(y)) ? ry : -ry};
117-
#else
118-
resT log_in = std::log(in);
119-
const realT wx = std::real(log_in);
120-
const realT wy = std::imag(log_in);
121-
const realT rx = sycl::fabs(wy);
122-
123-
realT ry = wx + std::log(realT(2));
124-
return resT{rx, (std::signbit(y)) ? ry : -ry};
125-
#endif
114+
realT ry = wx + sycl::log(realT(2));
115+
return resT{rx, (sycl::signbit(y)) ? ry : -ry};
126116
}
127117

128118
/* ordinary cases */
129-
#if USE_SYCL_FOR_COMPLEX_TYPES
130-
return exprm_ns::acos(
131-
exprm_ns::complex<realT>(in)); // std::acos(in);
132-
#else
133-
return std::acos(in);
134-
#endif
119+
return exprm_ns::acos(exprm_ns::complex<realT>(in)); // acos(in);
135120
}
136121
else {
137122
static_assert(std::is_floating_point_v<argT> ||
138123
std::is_same_v<argT, sycl::half>);
139-
return std::acos(in);
124+
return sycl::acos(in);
140125
}
141126
}
142127
};
@@ -203,7 +188,7 @@ template <typename fnT, typename T> struct AcosContigFactory
203188

204189
template <typename fnT, typename T> struct AcosTypeMapFactory
205190
{
206-
/*! @brief get typeid for output type of std::acos(T x) */
191+
/*! @brief get typeid for output type of sycl::acos(T x) */
207192
std::enable_if_t<std::is_same<fnT, int>::value, int> get()
208193
{
209194
using rT = typename AcosOutputType<T>::value_type;

dpctl/tensor/libtensor/include/kernels/elementwise_functions/acosh.hpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ template <typename argT, typename resT> struct AcoshFunctor
9696
}
9797
/* acos(0 + I*NaN) = Pi/2 + I*NaN with inexact */
9898
else if (x == realT(0)) {
99-
const realT pi_half = std::atan(1) * 2;
99+
const realT pi_half = sycl::atan(realT(1)) * 2;
100100
acos_in = resT{pi_half, q_nan};
101101
}
102102
else {
@@ -110,28 +110,18 @@ template <typename argT, typename resT> struct AcoshFunctor
110110
* For large x or y including acos(+-Inf + I*+-Inf)
111111
*/
112112
if (sycl::fabs(x) > r_eps || sycl::fabs(y) > r_eps) {
113-
#ifdef USE_SYCL_FOR_COMPLEX_TYPES
114113
using sycl_complexT = typename exprm_ns::complex<realT>;
115114
const sycl_complexT log_in = exprm_ns::log(sycl_complexT(in));
116115
const realT wx = log_in.real();
117116
const realT wy = log_in.imag();
118-
#else
119-
const resT log_in = std::log(in);
120-
const realT wx = std::real(log_in);
121-
const realT wy = std::imag(log_in);
122-
#endif
123117
const realT rx = sycl::fabs(wy);
124-
realT ry = wx + std::log(realT(2));
125-
acos_in = resT{rx, (std::signbit(y)) ? ry : -ry};
118+
realT ry = wx + sycl::log(realT(2));
119+
acos_in = resT{rx, (sycl::signbit(y)) ? ry : -ry};
126120
}
127121
else {
128122
/* ordinary cases */
129-
#if USE_SYCL_FOR_COMPLEX_TYPES
130-
acos_in = exprm_ns::acos(
131-
exprm_ns::complex<realT>(in)); // std::acos(in);
132-
#else
133-
acos_in = std::acos(in);
134-
#endif
123+
acos_in =
124+
exprm_ns::acos(exprm_ns::complex<realT>(in)); // acos(in);
135125
}
136126

137127
/* Now we calculate acosh(z) */
@@ -158,7 +148,7 @@ template <typename argT, typename resT> struct AcoshFunctor
158148
else {
159149
static_assert(std::is_floating_point_v<argT> ||
160150
std::is_same_v<argT, sycl::half>);
161-
return std::acosh(in);
151+
return sycl::acosh(in);
162152
}
163153
}
164154
};
@@ -225,7 +215,7 @@ template <typename fnT, typename T> struct AcoshContigFactory
225215

226216
template <typename fnT, typename T> struct AcoshTypeMapFactory
227217
{
228-
/*! @brief get typeid for output type of std::acosh(T x) */
218+
/*! @brief get typeid for output type of sycl::acosh(T x) */
229219
std::enable_if_t<std::is_same<fnT, int>::value, int> get()
230220
{
231221
using rT = typename AcoshOutputType<T>::value_type;

dpctl/tensor/libtensor/include/kernels/elementwise_functions/add.hpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,36 +63,24 @@ template <typename argT1, typename argT2, typename resT> struct AddFunctor
6363
if constexpr (tu_ns::is_complex<argT1>::value &&
6464
tu_ns::is_complex<argT2>::value)
6565
{
66-
#ifdef USE_SYCL_FOR_COMPLEX_TYPES
6766
using rT1 = typename argT1::value_type;
6867
using rT2 = typename argT2::value_type;
6968

7069
return exprm_ns::complex<rT1>(in1) + exprm_ns::complex<rT2>(in2);
71-
#else
72-
return in1 + in2;
73-
#endif
7470
}
7571
else if constexpr (tu_ns::is_complex<argT1>::value &&
7672
!tu_ns::is_complex<argT2>::value)
7773
{
78-
#ifdef USE_SYCL_FOR_COMPLEX_TYPES
7974
using rT1 = typename argT1::value_type;
8075

8176
return exprm_ns::complex<rT1>(in1) + in2;
82-
#else
83-
return in1 + in2;
84-
#endif
8577
}
8678
else if constexpr (!tu_ns::is_complex<argT1>::value &&
8779
tu_ns::is_complex<argT2>::value)
8880
{
89-
#ifdef USE_SYCL_FOR_COMPLEX_TYPES
9081
using rT2 = typename argT2::value_type;
9182

9283
return in1 + exprm_ns::complex<rT2>(in2);
93-
#else
94-
return in1 + in2;
95-
#endif
9684
}
9785
else {
9886
return in1 + in2;

dpctl/tensor/libtensor/include/kernels/elementwise_functions/angle.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,9 @@ template <typename argT, typename resT> struct AngleFunctor
6666

6767
resT operator()(const argT &in) const
6868
{
69-
#ifdef USE_SYCL_FOR_COMPLEX_TYPES
7069
using rT = typename argT::value_type;
7170

72-
return exprm_ns::arg(exprm_ns::complex<rT>(in)); // std::arg(in);
73-
#else
74-
return std::arg(in);
75-
#endif
71+
return exprm_ns::arg(exprm_ns::complex<rT>(in)); // arg(in);
7672
}
7773
};
7874

dpctl/tensor/libtensor/include/kernels/elementwise_functions/asin.hpp

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -117,50 +117,31 @@ template <typename argT, typename resT> struct AsinFunctor
117117
constexpr realT r_eps =
118118
realT(1) / std::numeric_limits<realT>::epsilon();
119119
if (sycl::fabs(x) > r_eps || sycl::fabs(y) > r_eps) {
120-
#ifdef USE_SYCL_FOR_COMPLEX_TYPES
121120
using sycl_complexT = exprm_ns::complex<realT>;
122121
const sycl_complexT z{x, y};
123122
realT wx, wy;
124-
if (!std::signbit(x)) {
123+
if (!sycl::signbit(x)) {
125124
const auto log_z = exprm_ns::log(z);
126-
wx = log_z.real() + std::log(realT(2));
125+
wx = log_z.real() + sycl::log(realT(2));
127126
wy = log_z.imag();
128127
}
129128
else {
130129
const auto log_mz = exprm_ns::log(-z);
131-
wx = log_mz.real() + std::log(realT(2));
130+
wx = log_mz.real() + sycl::log(realT(2));
132131
wy = log_mz.imag();
133132
}
134-
#else
135-
const resT z{x, y};
136-
realT wx, wy;
137-
if (!std::signbit(x)) {
138-
const auto log_z = std::log(z);
139-
wx = std::real(log_z) + std::log(realT(2));
140-
wy = std::imag(log_z);
141-
}
142-
else {
143-
const auto log_mz = std::log(-z);
144-
wx = std::real(log_mz) + std::log(realT(2));
145-
wy = std::imag(log_mz);
146-
}
147-
#endif
148133
const realT asinh_re = sycl::copysign(wx, x);
149134
const realT asinh_im = sycl::copysign(wy, y);
150135
return resT{asinh_im, asinh_re};
151136
}
152137
/* ordinary cases */
153-
#if USE_SYCL_FOR_COMPLEX_TYPES
154138
return exprm_ns::asin(
155-
exprm_ns::complex<realT>(in)); // std::asin(in);
156-
#else
157-
return std::asin(in);
158-
#endif
139+
exprm_ns::complex<realT>(in)); // sycl::asin(in);
159140
}
160141
else {
161142
static_assert(std::is_floating_point_v<argT> ||
162143
std::is_same_v<argT, sycl::half>);
163-
return std::asin(in);
144+
return sycl::asin(in);
164145
}
165146
}
166147
};
@@ -227,7 +208,7 @@ template <typename fnT, typename T> struct AsinContigFactory
227208

228209
template <typename fnT, typename T> struct AsinTypeMapFactory
229210
{
230-
/*! @brief get typeid for output type of std::asin(T x) */
211+
/*! @brief get typeid for output type of sycl::asin(T x) */
231212
std::enable_if_t<std::is_same<fnT, int>::value, int> get()
232213
{
233214
using rT = typename AsinOutputType<T>::value_type;

dpctl/tensor/libtensor/include/kernels/elementwise_functions/asinh.hpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,35 +106,25 @@ template <typename argT, typename resT> struct AsinhFunctor
106106
realT(1) / std::numeric_limits<realT>::epsilon();
107107

108108
if (sycl::fabs(x) > r_eps || sycl::fabs(y) > r_eps) {
109-
#ifdef USE_SYCL_FOR_COMPLEX_TYPES
110109
using sycl_complexT = exprm_ns::complex<realT>;
111-
sycl_complexT log_in = (std::signbit(x))
110+
sycl_complexT log_in = (sycl::signbit(x))
112111
? exprm_ns::log(sycl_complexT(-in))
113112
: exprm_ns::log(sycl_complexT(in));
114-
realT wx = log_in.real() + std::log(realT(2));
113+
realT wx = log_in.real() + sycl::log(realT(2));
115114
realT wy = log_in.imag();
116-
#else
117-
auto log_in = std::log(std::signbit(x) ? -in : in);
118-
realT wx = std::real(log_in) + std::log(realT(2));
119-
realT wy = std::imag(log_in);
120-
#endif
115+
121116
const realT res_re = sycl::copysign(wx, x);
122117
const realT res_im = sycl::copysign(wy, y);
123118
return resT{res_re, res_im};
124119
}
125120

126121
/* ordinary cases */
127-
#if USE_SYCL_FOR_COMPLEX_TYPES
128-
return exprm_ns::asinh(
129-
exprm_ns::complex<realT>(in)); // std::asinh(in);
130-
#else
131-
return std::asinh(in);
132-
#endif
122+
return exprm_ns::asinh(exprm_ns::complex<realT>(in)); // asinh(in);
133123
}
134124
else {
135125
static_assert(std::is_floating_point_v<argT> ||
136126
std::is_same_v<argT, sycl::half>);
137-
return std::asinh(in);
127+
return sycl::asinh(in);
138128
}
139129
}
140130
};
@@ -201,7 +191,7 @@ template <typename fnT, typename T> struct AsinhContigFactory
201191

202192
template <typename fnT, typename T> struct AsinhTypeMapFactory
203193
{
204-
/*! @brief get typeid for output type of std::asinh(T x) */
194+
/*! @brief get typeid for output type of sycl::asinh(T x) */
205195
std::enable_if_t<std::is_same<fnT, int>::value, int> get()
206196
{
207197
using rT = typename AsinhOutputType<T>::value_type;

dpctl/tensor/libtensor/include/kernels/elementwise_functions/atan.hpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ template <typename argT, typename resT> struct AtanFunctor
8282
if (std::isnan(x)) {
8383
/* atanh(NaN + I*+-Inf) = sign(NaN)*0 + I*+-Pi/2 */
8484
if (std::isinf(y)) {
85-
const realT pi_half = std::atan(realT(1)) * 2;
85+
const realT pi_half = sycl::atan(realT(1)) * 2;
8686

8787
const realT atanh_re = sycl::copysign(realT(0), x);
8888
const realT atanh_im = sycl::copysign(pi_half, y);
@@ -119,24 +119,19 @@ template <typename argT, typename resT> struct AtanFunctor
119119
constexpr realT r_eps =
120120
realT(1) / std::numeric_limits<realT>::epsilon();
121121
if (sycl::fabs(x) > r_eps || sycl::fabs(y) > r_eps) {
122-
const realT pi_half = std::atan(realT(1)) * 2;
122+
const realT pi_half = sycl::atan(realT(1)) * 2;
123123

124124
const realT atanh_re = realT(0);
125125
const realT atanh_im = sycl::copysign(pi_half, y);
126126
return resT{atanh_im, atanh_re};
127127
}
128128
/* ordinary cases */
129-
#ifdef USE_SYCL_FOR_COMPLEX_TYPES
130-
return exprm_ns::atan(
131-
exprm_ns::complex<realT>(in)); // std::atan(in);
132-
#else
133-
return std::atan(in);
134-
#endif
129+
return exprm_ns::atan(exprm_ns::complex<realT>(in)); // atan(in);
135130
}
136131
else {
137132
static_assert(std::is_floating_point_v<argT> ||
138133
std::is_same_v<argT, sycl::half>);
139-
return std::atan(in);
134+
return sycl::atan(in);
140135
}
141136
}
142137
};
@@ -203,7 +198,7 @@ template <typename fnT, typename T> struct AtanContigFactory
203198

204199
template <typename fnT, typename T> struct AtanTypeMapFactory
205200
{
206-
/*! @brief get typeid for output type of std::atan(T x) */
201+
/*! @brief get typeid for output type of sycl::atan(T x) */
207202
std::enable_if_t<std::is_same<fnT, int>::value, int> get()
208203
{
209204
using rT = typename AtanOutputType<T>::value_type;

dpctl/tensor/libtensor/include/kernels/elementwise_functions/atan2.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ template <typename argT1, typename argT2, typename resT> struct Atan2Functor
5656

5757
resT operator()(const argT1 &in1, const argT2 &in2) const
5858
{
59-
if (std::isinf(in2) && !std::signbit(in2)) {
59+
if (std::isinf(in2) && !sycl::signbit(in2)) {
6060
if (std::isfinite(in1)) {
6161
return sycl::copysign(resT(0), in1);
6262
}
6363
}
64-
return std::atan2(in1, in2);
64+
return sycl::atan2(in1, in2);
6565
}
6666
};
6767

@@ -145,7 +145,7 @@ template <typename fnT, typename T1, typename T2> struct Atan2ContigFactory
145145

146146
template <typename fnT, typename T1, typename T2> struct Atan2TypeMapFactory
147147
{
148-
/*! @brief get typeid for output type of std::hypot(T1 x, T2 y) */
148+
/*! @brief get typeid for output type of sycl::atan2(T1 x, T2 y) */
149149
std::enable_if_t<std::is_same<fnT, int>::value, int> get()
150150
{
151151
using rT = typename Atan2OutputType<T1, T2>::value_type;

0 commit comments

Comments
 (0)