#pragma once #include #include #include C10_CLANG_DIAGNOSTIC_PUSH() #if C10_CLANG_HAS_WARNING("-Wimplicit-float-conversion") C10_CLANG_DIAGNOSTIC_IGNORE("-Wimplicit-float-conversion") #endif namespace c10 { // TODO: Replace me with inline constexpr variable when C++17 becomes available namespace detail { template C10_HOST_DEVICE inline constexpr T e() { return static_cast(2.718281828459045235360287471352662); } template C10_HOST_DEVICE inline constexpr T euler() { return static_cast(0.577215664901532860606512090082402); } template C10_HOST_DEVICE inline constexpr T frac_1_pi() { return static_cast(0.318309886183790671537767526745028); } template C10_HOST_DEVICE inline constexpr T frac_1_sqrt_pi() { return static_cast(0.564189583547756286948079451560772); } template C10_HOST_DEVICE inline constexpr T frac_sqrt_2() { return static_cast(0.707106781186547524400844362104849); } template C10_HOST_DEVICE inline constexpr T frac_sqrt_3() { return static_cast(0.577350269189625764509148780501957); } template C10_HOST_DEVICE inline constexpr T golden_ratio() { return static_cast(1.618033988749894848204586834365638); } template C10_HOST_DEVICE inline constexpr T ln_10() { return static_cast(2.302585092994045684017991454684364); } template C10_HOST_DEVICE inline constexpr T ln_2() { return static_cast(0.693147180559945309417232121458176); } template C10_HOST_DEVICE inline constexpr T log_10_e() { return static_cast(0.434294481903251827651128918916605); } template C10_HOST_DEVICE inline constexpr T log_2_e() { return static_cast(1.442695040888963407359924681001892); } template C10_HOST_DEVICE inline constexpr T pi() { return static_cast(3.141592653589793238462643383279502); } template C10_HOST_DEVICE inline constexpr T sqrt_2() { return static_cast(1.414213562373095048801688724209698); } template C10_HOST_DEVICE inline constexpr T sqrt_3() { return static_cast(1.732050807568877293527446341505872); } template <> C10_HOST_DEVICE inline constexpr BFloat16 pi() { // According to // https://en.wikipedia.org/wiki/Bfloat16_floating-point_format#Special_values // pi is encoded as 4049 return BFloat16(0x4049, BFloat16::from_bits()); } template <> C10_HOST_DEVICE inline constexpr Half pi() { return Half(0x4248, Half::from_bits()); } } // namespace detail template constexpr T e = c10::detail::e(); template constexpr T euler = c10::detail::euler(); template constexpr T frac_1_pi = c10::detail::frac_1_pi(); template constexpr T frac_1_sqrt_pi = c10::detail::frac_1_sqrt_pi(); template constexpr T frac_sqrt_2 = c10::detail::frac_sqrt_2(); template constexpr T frac_sqrt_3 = c10::detail::frac_sqrt_3(); template constexpr T golden_ratio = c10::detail::golden_ratio(); template constexpr T ln_10 = c10::detail::ln_10(); template constexpr T ln_2 = c10::detail::ln_2(); template constexpr T log_10_e = c10::detail::log_10_e(); template constexpr T log_2_e = c10::detail::log_2_e(); template constexpr T pi = c10::detail::pi(); template constexpr T sqrt_2 = c10::detail::sqrt_2(); template constexpr T sqrt_3 = c10::detail::sqrt_3(); } // namespace c10 C10_CLANG_DIAGNOSTIC_POP()