Skip to content

Commit db80c7d

Browse files
authored
Merge Removeing attributes from math functions
This merge removes `GKO_ATTRIBUTES` from constexpr functions in math.hpp. Since we build cuda with `--expt-relaxed-constexpr` the `constexpr` is already enough to allow those functions on the device. Related PR: #1695
2 parents 532566d + 98f29f6 commit db80c7d

1 file changed

Lines changed: 22 additions & 153 deletions

File tree

include/ginkgo/core/base/math.hpp

Lines changed: 22 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ using is_complex_s = detail::is_complex_impl<T>;
283283
* @return `true` if T is a complex type, `false` otherwise
284284
*/
285285
template <typename T>
286-
GKO_INLINE GKO_ATTRIBUTES constexpr bool is_complex()
286+
GKO_INLINE constexpr bool is_complex()
287287
{
288288
return detail::is_complex_impl<T>::value;
289289
}
@@ -307,7 +307,7 @@ using is_complex_or_scalar_s = detail::is_complex_or_scalar_impl<T>;
307307
* @return `true` if T is a complex/scalar type, `false` otherwise
308308
*/
309309
template <typename T>
310-
GKO_INLINE GKO_ATTRIBUTES constexpr bool is_complex_or_scalar()
310+
GKO_INLINE constexpr bool is_complex_or_scalar()
311311
{
312312
return detail::is_complex_or_scalar_impl<T>::value;
313313
}
@@ -511,7 +511,7 @@ using highest_precision =
511511
* @return the rounded down value
512512
*/
513513
template <typename T>
514-
GKO_INLINE GKO_ATTRIBUTES constexpr reduce_precision<T> round_down(T val)
514+
GKO_INLINE constexpr reduce_precision<T> round_down(T val)
515515
{
516516
return static_cast<reduce_precision<T>>(val);
517517
}
@@ -527,7 +527,7 @@ GKO_INLINE GKO_ATTRIBUTES constexpr reduce_precision<T> round_down(T val)
527527
* @return the rounded up value
528528
*/
529529
template <typename T>
530-
GKO_INLINE GKO_ATTRIBUTES constexpr increase_precision<T> round_up(T val)
530+
GKO_INLINE constexpr increase_precision<T> round_up(T val)
531531
{
532532
return static_cast<increase_precision<T>>(val);
533533
}
@@ -609,141 +609,19 @@ struct default_converter {
609609
*
610610
* @return returns the ceiled quotient.
611611
*/
612-
GKO_INLINE GKO_ATTRIBUTES constexpr int64 ceildiv(int64 num, int64 den)
612+
GKO_INLINE constexpr int64 ceildiv(int64 num, int64 den)
613613
{
614614
return (num + den - 1) / den;
615615
}
616616

617617

618-
#if defined(__HIPCC__) && GINKGO_HIP_PLATFORM_HCC
619-
620-
621-
/**
622-
* Returns the additive identity for T.
623-
*
624-
* @return additive identity for T
625-
*/
626-
template <typename T>
627-
GKO_INLINE __host__ constexpr T zero()
628-
{
629-
return T{};
630-
}
631-
632-
633-
/**
634-
* Returns the additive identity for T.
635-
*
636-
* @return additive identity for T
637-
*
638-
* @note This version takes an unused reference argument to avoid
639-
* complicated calls like `zero<decltype(x)>()`. Instead, it allows
640-
* `zero(x)`.
641-
*/
642-
template <typename T>
643-
GKO_INLINE __host__ constexpr T zero(const T&)
644-
{
645-
return zero<T>();
646-
}
647-
648-
649-
/**
650-
* Returns the multiplicative identity for T.
651-
*
652-
* @return the multiplicative identity for T
653-
*/
654-
template <typename T>
655-
GKO_INLINE __host__ constexpr T one()
656-
{
657-
return T(1);
658-
}
659-
660-
661-
/**
662-
* Returns the multiplicative identity for T.
663-
*
664-
* @return the multiplicative identity for T
665-
*
666-
* @note This version takes an unused reference argument to avoid
667-
* complicated calls like `one<decltype(x)>()`. Instead, it allows
668-
* `one(x)`.
669-
*/
670-
template <typename T>
671-
GKO_INLINE __host__ constexpr T one(const T&)
672-
{
673-
return one<T>();
674-
}
675-
676-
677-
/**
678-
* Returns the additive identity for T.
679-
*
680-
* @return additive identity for T
681-
*/
682-
template <typename T>
683-
GKO_INLINE __device__ constexpr std::enable_if_t<
684-
!std::is_same<T, std::complex<remove_complex<T>>>::value, T>
685-
zero()
686-
{
687-
return T{};
688-
}
689-
690-
691618
/**
692619
* Returns the additive identity for T.
693620
*
694621
* @return additive identity for T
695-
*
696-
* @note This version takes an unused reference argument to avoid
697-
* complicated calls like `zero<decltype(x)>()`. Instead, it allows
698-
* `zero(x)`.
699622
*/
700623
template <typename T>
701-
GKO_INLINE __device__ constexpr T zero(const T&)
702-
{
703-
return zero<T>();
704-
}
705-
706-
707-
/**
708-
* Returns the multiplicative identity for T.
709-
*
710-
* @return the multiplicative identity for T
711-
*/
712-
template <typename T>
713-
GKO_INLINE __device__ constexpr std::enable_if_t<
714-
!std::is_same<T, std::complex<remove_complex<T>>>::value, T>
715-
one()
716-
{
717-
return T(1);
718-
}
719-
720-
721-
/**
722-
* Returns the multiplicative identity for T.
723-
*
724-
* @return the multiplicative identity for T
725-
*
726-
* @note This version takes an unused reference argument to avoid
727-
* complicated calls like `one<decltype(x)>()`. Instead, it allows
728-
* `one(x)`.
729-
*/
730-
template <typename T>
731-
GKO_INLINE __device__ constexpr T one(const T&)
732-
{
733-
return one<T>();
734-
}
735-
736-
737-
#else
738-
739-
740-
/**
741-
* Returns the additive identity for T.
742-
*
743-
* @return additive identity for T
744-
*/
745-
template <typename T>
746-
GKO_INLINE GKO_ATTRIBUTES constexpr T zero()
624+
GKO_INLINE constexpr T zero()
747625
{
748626
return T{};
749627
}
@@ -759,7 +637,7 @@ GKO_INLINE GKO_ATTRIBUTES constexpr T zero()
759637
* `zero(x)`.
760638
*/
761639
template <typename T>
762-
GKO_INLINE GKO_ATTRIBUTES constexpr T zero(const T&)
640+
GKO_INLINE constexpr T zero(const T&)
763641
{
764642
return zero<T>();
765643
}
@@ -771,7 +649,7 @@ GKO_INLINE GKO_ATTRIBUTES constexpr T zero(const T&)
771649
* @return the multiplicative identity for T
772650
*/
773651
template <typename T>
774-
GKO_INLINE GKO_ATTRIBUTES constexpr T one()
652+
GKO_INLINE constexpr T one()
775653
{
776654
return T(1);
777655
}
@@ -787,18 +665,12 @@ GKO_INLINE GKO_ATTRIBUTES constexpr T one()
787665
* `one(x)`.
788666
*/
789667
template <typename T>
790-
GKO_INLINE GKO_ATTRIBUTES constexpr T one(const T&)
668+
GKO_INLINE constexpr T one(const T&)
791669
{
792670
return one<T>();
793671
}
794672

795673

796-
#endif // defined(__HIPCC__) && GINKGO_HIP_PLATFORM_HCC
797-
798-
799-
#undef GKO_BIND_ZERO_ONE
800-
801-
802674
/**
803675
* Returns true if and only if the given value is zero.
804676
*
@@ -808,7 +680,7 @@ GKO_INLINE GKO_ATTRIBUTES constexpr T one(const T&)
808680
* @return true iff the given value is zero, i.e. `value == zero<T>()`
809681
*/
810682
template <typename T>
811-
GKO_INLINE GKO_ATTRIBUTES constexpr bool is_zero(T value)
683+
GKO_INLINE constexpr bool is_zero(T value)
812684
{
813685
return value == zero<T>();
814686
}
@@ -823,7 +695,7 @@ GKO_INLINE GKO_ATTRIBUTES constexpr bool is_zero(T value)
823695
* @return true iff the given value is not zero, i.e. `value != zero<T>()`
824696
*/
825697
template <typename T>
826-
GKO_INLINE GKO_ATTRIBUTES constexpr bool is_nonzero(T value)
698+
GKO_INLINE constexpr bool is_nonzero(T value)
827699
{
828700
return value != zero<T>();
829701
}
@@ -841,7 +713,7 @@ GKO_INLINE GKO_ATTRIBUTES constexpr bool is_nonzero(T value)
841713
*
842714
*/
843715
template <typename T>
844-
GKO_INLINE GKO_ATTRIBUTES constexpr T max(const T& x, const T& y)
716+
GKO_INLINE constexpr T max(const T& x, const T& y)
845717
{
846718
return x >= y ? x : y;
847719
}
@@ -859,7 +731,7 @@ GKO_INLINE GKO_ATTRIBUTES constexpr T max(const T& x, const T& y)
859731
*
860732
*/
861733
template <typename T>
862-
GKO_INLINE GKO_ATTRIBUTES constexpr T min(const T& x, const T& y)
734+
GKO_INLINE constexpr T min(const T& x, const T& y)
863735
{
864736
return x <= y ? x : y;
865737
}
@@ -1053,7 +925,7 @@ GKO_ATTRIBUTES GKO_INLINE constexpr auto conj(const T& x)
1053925
* @return The squared norm of the object.
1054926
*/
1055927
template <typename T>
1056-
GKO_INLINE GKO_ATTRIBUTES constexpr auto squared_norm(const T& x)
928+
GKO_INLINE constexpr auto squared_norm(const T& x)
1057929
-> decltype(real(conj(x) * x))
1058930
{
1059931
return real(conj(x) * x);
@@ -1070,16 +942,15 @@ GKO_INLINE GKO_ATTRIBUTES constexpr auto squared_norm(const T& x)
1070942
* @return x >= zero<T>() ? x : -x;
1071943
*/
1072944
template <typename T>
1073-
GKO_INLINE GKO_ATTRIBUTES constexpr std::enable_if_t<!is_complex_s<T>::value, T>
1074-
abs(const T& x)
945+
GKO_INLINE constexpr std::enable_if_t<!is_complex_s<T>::value, T> abs(
946+
const T& x)
1075947
{
1076948
return x >= zero<T>() ? x : -x;
1077949
}
1078950

1079951

1080952
template <typename T>
1081-
GKO_INLINE GKO_ATTRIBUTES constexpr std::enable_if_t<is_complex_s<T>::value,
1082-
remove_complex<T>>
953+
GKO_INLINE constexpr std::enable_if_t<is_complex_s<T>::value, remove_complex<T>>
1083954
abs(const T& x)
1084955
{
1085956
return sqrt(squared_norm(x));
@@ -1092,7 +963,7 @@ abs(const T& x)
1092963
* @tparam T the value type to return
1093964
*/
1094965
template <typename T>
1095-
GKO_INLINE GKO_ATTRIBUTES constexpr T pi()
966+
GKO_INLINE constexpr T pi()
1096967
{
1097968
return static_cast<T>(3.1415926535897932384626433);
1098969
}
@@ -1107,8 +978,8 @@ GKO_INLINE GKO_ATTRIBUTES constexpr T pi()
1107978
* @tparam T the corresponding real value type.
1108979
*/
1109980
template <typename T>
1110-
GKO_INLINE GKO_ATTRIBUTES constexpr std::complex<remove_complex<T>> unit_root(
1111-
int64 n, int64 k = 1)
981+
GKO_INLINE constexpr std::complex<remove_complex<T>> unit_root(int64 n,
982+
int64 k = 1)
1112983
{
1113984
return std::polar(one<remove_complex<T>>(),
1114985
remove_complex<T>{2} * pi<remove_complex<T>>() * k / n);
@@ -1259,8 +1130,7 @@ GKO_INLINE GKO_ATTRIBUTES std::enable_if_t<is_complex_s<T>::value, bool> is_nan(
12591130
* @return NaN.
12601131
*/
12611132
template <typename T>
1262-
GKO_INLINE GKO_ATTRIBUTES constexpr std::enable_if_t<!is_complex_s<T>::value, T>
1263-
nan()
1133+
GKO_INLINE constexpr std::enable_if_t<!is_complex_s<T>::value, T> nan()
12641134
{
12651135
return std::numeric_limits<T>::quiet_NaN();
12661136
}
@@ -1274,8 +1144,7 @@ nan()
12741144
* @return complex{NaN, NaN}.
12751145
*/
12761146
template <typename T>
1277-
GKO_INLINE GKO_ATTRIBUTES constexpr std::enable_if_t<is_complex_s<T>::value, T>
1278-
nan()
1147+
GKO_INLINE constexpr std::enable_if_t<is_complex_s<T>::value, T> nan()
12791148
{
12801149
return T{nan<remove_complex<T>>(), nan<remove_complex<T>>()};
12811150
}

0 commit comments

Comments
 (0)