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

Fixed dace::math::pi and dace::math::nan on GPU #1759

Merged
merged 7 commits into from
Nov 15, 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
2 changes: 1 addition & 1 deletion dace/runtime/include/dace/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ namespace dace
{
namespace math
{
static DACE_CONSTEXPR typeless_pi pi{};
static DACE_CONSTEXPR DACE_HostDev typeless_pi pi{};
static DACE_CONSTEXPR typeless_nan nan{};
//////////////////////////////////////////////////////
template<typename T>
Expand Down
100 changes: 59 additions & 41 deletions dace/runtime/include/dace/nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,101 +13,119 @@ namespace dace
// Defines a typeless Pi
struct typeless_nan
{
DACE_CONSTEXPR DACE_HDFI typeless_nan() noexcept = default;
DACE_CONSTEXPR DACE_HDFI typeless_nan(const typeless_nan&) noexcept = default;
DACE_CONSTEXPR DACE_HDFI typeless_nan(typeless_nan&&) noexcept = default;
DACE_HDFI ~typeless_nan() noexcept = default;

#ifndef DACE_XILINX
DACE_CONSTEXPR DACE_HDFI typeless_nan& operator=(const typeless_nan&) noexcept = default;
DACE_CONSTEXPR DACE_HDFI typeless_nan& operator=(typeless_nan&&) noexcept = default;
#endif

operator int() const = delete;
operator float() const
DACE_CONSTEXPR DACE_HDFI operator float() const
{
return std::numeric_limits<float>::quiet_NaN();
}
operator double() const
DACE_CONSTEXPR DACE_HDFI operator double() const
{
return std::numeric_limits<double>::quiet_NaN();
}
operator long double() const

#if !( defined(__CUDACC__) || defined(__HIPCC__) )
//There is no long double on the GPU
DACE_CONSTEXPR DACE_HDFI operator long double() const
{
return std::numeric_limits<long double>::quiet_NaN();
}
typeless_nan operator+() const
#endif
DACE_CONSTEXPR DACE_HDFI typeless_nan operator+() const
{
return typeless_nan{};
}
typeless_nan operator-() const
DACE_CONSTEXPR DACE_HDFI typeless_nan operator-() const
{
return typeless_nan{};
}
};

template<typename T>
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type
operator*(const T&, const typeless_nan&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI std::enable_if_t<std::is_floating_point<T>::value || std::is_integral<T>::value, typeless_nan>
operator*(const T&, const typeless_nan&) noexcept { return typeless_nan{}; }

template<typename T>
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type
operator*(const typeless_nan&, const T&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI std::enable_if_t<std::is_floating_point<T>::value || std::is_integral<T>::value, typeless_nan>
operator*(const typeless_nan&, const T&) noexcept { return typeless_nan{}; }

inline typeless_nan
operator*(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI typeless_nan
operator*(const typeless_nan&, const typeless_nan&) noexcept { return typeless_nan{}; }


template<typename T>
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type
operator+(const T&, const typeless_nan&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI std::enable_if_t<std::is_floating_point<T>::value || std::is_integral<T>::value, typeless_nan>
operator+(const T&, const typeless_nan&) noexcept { return typeless_nan{}; }

template<typename T>
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type
operator+(const typeless_nan&, const T&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI std::enable_if_t<std::is_floating_point<T>::value || std::is_integral<T>::value, typeless_nan>
operator+(const typeless_nan&, const T&) noexcept { return typeless_nan{}; }

inline typeless_nan
operator+(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI typeless_nan
operator+(const typeless_nan&, const typeless_nan&) noexcept { return typeless_nan{}; }


template<typename T>
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type
operator-(const T&, const typeless_nan&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI std::enable_if_t<std::is_floating_point<T>::value || std::is_integral<T>::value, typeless_nan>
operator-(const T&, const typeless_nan&) noexcept { return typeless_nan{}; }

template<typename T>
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type
operator-(const typeless_nan&, const T&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI std::enable_if_t<std::is_floating_point<T>::value || std::is_integral<T>::value, typeless_nan>
operator-(const typeless_nan&, const T&) noexcept { return typeless_nan{}; }

inline typeless_nan
operator-(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI typeless_nan
operator-(const typeless_nan&, const typeless_nan&) noexcept { return typeless_nan{}; }


template<typename T>
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type
operator/(const T&, const typeless_nan&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI std::enable_if_t<std::is_floating_point<T>::value || std::is_integral<T>::value, typeless_nan>
operator/(const T&, const typeless_nan&) noexcept { return typeless_nan{}; }

template<typename T>
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type
operator/(const typeless_nan&, const T&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI std::enable_if_t<std::is_floating_point<T>::value || std::is_integral<T>::value, typeless_nan>
operator/(const typeless_nan&, const T&) noexcept { return typeless_nan{}; }

inline typeless_nan
operator/(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI typeless_nan
operator/(const typeless_nan&, const typeless_nan&) noexcept { return typeless_nan{}; }


template<typename T>
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type
operator%(const T&, const typeless_nan&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI std::enable_if_t<std::is_floating_point<T>::value || std::is_integral<T>::value, typeless_nan>
operator%(const T&, const typeless_nan&) noexcept { return typeless_nan{}; }

template<typename T>
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type
operator%(const typeless_nan&, const T&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI std::enable_if_t<std::is_floating_point<T>::value || std::is_integral<T>::value, typeless_nan>
operator%(const typeless_nan&, const T&) noexcept { return typeless_nan{}; }

inline typeless_nan
operator%(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; }
DACE_CONSTEXPR DACE_HDFI typeless_nan
operator%(const typeless_nan&, const typeless_nan&) noexcept { return typeless_nan{}; }

}
}
DACE_HDFI typeless_nan ipow(const typeless_nan&, const unsigned int&) {
return typeless_nan{};
}

//These functions allows to perfrom operations with `typeless_nan` instances.
# define FADAPT(F) DACE_CONSTEXPR ::dace::math::typeless_nan F (::dace::math::typeless_nan) { return ::dace::math::typeless_nan{}; }
# define FADAPT2(F) template<typename T1> DACE_CONSTEXPR dace::math::typeless_nan F (T1&&, dace::math::typeless_nan) { return ::dace::math::typeless_nan{}; }; \
template<typename T2> DACE_CONSTEXPR dace::math::typeless_nan F (dace::math::typeless_nan, T2&&) { return ::dace::math::typeless_nan{}; }; \
DACE_CONSTEXPR ::dace::math::typeless_nan F (dace::math::typeless_nan, dace::math::typeless_nan) { return ::dace::math::typeless_nan{}; }
# define FADAPT(F) DACE_CONSTEXPR DACE_HDFI typeless_nan F (const typeless_nan&) noexcept { return typeless_nan{}; }
# define FADAPT2(F) template<typename T1> DACE_CONSTEXPR DACE_HDFI typeless_nan F (T1&&, dace::math::typeless_nan) noexcept { return typeless_nan{}; }; \
template<typename T2> DACE_CONSTEXPR DACE_HDFI typeless_nan F (const typeless_nan&, T2&&) noexcept { return typeless_nan{}; }; \
DACE_CONSTEXPR DACE_HDFI typeless_nan F (const typeless_nan&, const typeless_nan&) noexcept { return typeless_nan{}; }
FADAPT(tanh); FADAPT(cos); FADAPT(sin); FADAPT(sqrt); FADAPT(tan);
FADAPT(acos); FADAPT(asin); FADAPT(atan); FADAPT(log); FADAPT(exp);
FADAPT(floor); FADAPT(ceil); FADAPT(round); FADAPT(abs);
FADAPT2(max); FADAPT2(min);
# undef FADAPT2
# undef FADAPT
}
}


#endif // __DACE_NAN_H
Loading