/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ #include "trig_negative_kernels_rtc.hh" #include "unary_common.hh" #include "binary_common.hh" #include "math_reference_impl.hh" MATH_UNARY_WITHIN_ULP_TEST_DEF(sin, std::sin, 2, 2); HIP_TEST_CASE(Unit_Device_sin_sinf_Negative_RTC) { NegativeTestRTCWrapper<4>(kSin); } MATH_UNARY_WITHIN_ULP_TEST_DEF(cos, std::cos, 2, 2) HIP_TEST_CASE(Unit_Device_cos_cosf_Negative_RTC) { NegativeTestRTCWrapper<4>(kCos); } MATH_UNARY_WITHIN_ULP_TEST_DEF(tan, std::tan, 4, 2) HIP_TEST_CASE(Unit_Device_tan_tanf_Negative_RTC) { NegativeTestRTCWrapper<4>(kTan); } MATH_UNARY_WITHIN_ULP_TEST_DEF(asin, std::asin, 3, 2) HIP_TEST_CASE(Unit_Device_asin_asinf_Negative_RTC) { NegativeTestRTCWrapper<4>(kAsin); } MATH_UNARY_WITHIN_ULP_TEST_DEF(acos, std::acos, 2, 2) HIP_TEST_CASE(Unit_Device_acos_acosf_Negative_RTC) { NegativeTestRTCWrapper<4>(kAcos); } MATH_UNARY_WITHIN_ULP_TEST_DEF(atan, std::atan, 2, 2) HIP_TEST_CASE(Unit_Device_atan_atanf_Negative_RTC) { NegativeTestRTCWrapper<4>(kAtan); } MATH_UNARY_WITHIN_ULP_TEST_DEF(sinh, std::sinh, 3, 2) HIP_TEST_CASE(Unit_Device_sinh_sinhf_Negative_RTC) { NegativeTestRTCWrapper<4>(kSinh); } MATH_UNARY_WITHIN_ULP_TEST_DEF(cosh, std::cosh, 2, 1) HIP_TEST_CASE(Unit_Device_cosh_coshf_Negative_RTC) { NegativeTestRTCWrapper<4>(kCosh); } MATH_UNARY_WITHIN_ULP_TEST_DEF(tanh, std::tanh, 2, 1) HIP_TEST_CASE(Unit_Device_tanh_tanhf_Negative_RTC) { NegativeTestRTCWrapper<4>(kTanh); } MATH_UNARY_WITHIN_ULP_TEST_DEF(asinh, std::asinh, 3, 2) HIP_TEST_CASE(Unit_Device_asinh_asinhf_Negative_RTC) { NegativeTestRTCWrapper<4>(kAsinh); } MATH_UNARY_WITHIN_ULP_TEST_DEF(acosh, std::acosh, 4, 2) HIP_TEST_CASE(Unit_Device_acosh_acoshf_Negative_RTC) { NegativeTestRTCWrapper<4>(kAcosh); } MATH_UNARY_WITHIN_ULP_TEST_DEF(atanh, std::atanh, 3, 2) HIP_TEST_CASE(Unit_Device_atanh_atanhf_Negative_RTC) { NegativeTestRTCWrapper<4>(kAtanh); } MATH_UNARY_WITHIN_ULP_TEST_DEF(sinpi, math_reference::sin_pi, 2, 2); HIP_TEST_CASE(Unit_Device_sinpi_sinpif_Negative_RTC) { NegativeTestRTCWrapper<4>(kSinpi); } MATH_UNARY_WITHIN_ULP_TEST_DEF(cospi, math_reference::cos_pi, 2, 2); HIP_TEST_CASE(Unit_Device_cospi_cospif_Negative_RTC) { NegativeTestRTCWrapper<4>(kCospi); } MATH_BINARY_WITHIN_ULP_TEST_DEF(atan2, std::atan2, 3, 2); HIP_TEST_CASE(Unit_Device_atan2_atan2f_Negative_RTC) { NegativeTestRTCWrapper<8>(kAtan2); } template __global__ void sincos_kernel(std::pair* const ys, const size_t num_xs, T* const xs) { const auto tid = cg::this_grid().thread_rank(); const auto stride = cg::this_grid().size(); for (size_t i = tid; i < num_xs; i += stride) { if constexpr (std::is_same_v) { sincosf(xs[i], &ys[i].first, &ys[i].second); } else if constexpr (std::is_same_v) { sincos(xs[i], &ys[i].first, &ys[i].second); } } } template std::pair sincos(T x) { return {std::sin(x), std::cos(x)}; } HIP_TEST_CASE(Unit_Device_sincos_Accuracy_Positive_float) { UnarySinglePrecisionTest( sincos_kernel, sincos, PairValidatorBuilderFactory(ULPValidatorBuilderFactory(2))); } HIP_TEST_CASE(Unit_Device_sincos_Accuracy_Positive_double) { const auto validator_builder = PairValidatorBuilderFactory(ULPValidatorBuilderFactory(2)); UnaryDoublePrecisionTest(sincos_kernel, sincos, validator_builder); } HIP_TEST_CASE(Unit_Device_sincos_sincosf_Negative_RTC) { NegativeTestRTCWrapper<36>(kSincos); } template __global__ void sincospi_kernel(std::pair* const ys, const size_t num_xs, T* const xs) { const auto tid = cg::this_grid().thread_rank(); const auto stride = cg::this_grid().size(); for (size_t i = tid; i < num_xs; i += stride) { if constexpr (std::is_same_v) { sincospif(xs[i], &ys[i].first, &ys[i].second); } else if constexpr (std::is_same_v) { sincospi(xs[i], &ys[i].first, &ys[i].second); } } } template std::pair sincospi(T x) { return {math_reference::sin_pi(x), math_reference::cos_pi(x)}; } HIP_TEST_CASE(Unit_Device_sincospi_Accuracy_Positive_float) { UnarySinglePrecisionTest( sincospi_kernel, sincospi, PairValidatorBuilderFactory(ULPValidatorBuilderFactory(2))); } HIP_TEST_CASE(Unit_Device_sincospi_Accuracy_Positive_double) { const auto validator_builder = PairValidatorBuilderFactory(ULPValidatorBuilderFactory(2)); UnaryDoublePrecisionTest(sincospi_kernel, sincospi, validator_builder); } HIP_TEST_CASE(Unit_Device_sincospi_sincospif_Negative_RTC) { NegativeTestRTCWrapper<36>(kSincospi); }