Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/math/casting_double_funcs.cc
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

588 lines
20 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include "casting_common.hh"
#include "casting_double_negative_kernels_rtc.hh"
/**
* @addtogroup CastingDoubleType CastingDoubleType
* @{
* @ingroup MathTest
*/
#define CAST_DOUBLE2INT_TEST_DEF(kern_name, T, ref_func) \
CAST_KERNEL_DEF(kern_name, T, double) \
CAST_F2I_REF_DEF(kern_name, T, double, ref_func) \
\
HIP_TEST_CASE(Unit_Device_##kern_name##_Positive) { \
T (*ref)(double) = kern_name##_ref; \
CastDoublePrecisionTest(kern_name##_kernel, ref, EqValidatorBuilderFactory<T>()); \
}
#define CAST_DOUBLE2INT_RZ_TEST_DEF(kern_name, T) \
CAST_KERNEL_DEF(kern_name, T, double) \
CAST_F2I_RZ_REF_DEF(kern_name, T, double) \
\
HIP_TEST_CASE(Unit_Device_##kern_name##_Positive) { \
T (*ref)(double) = kern_name##_ref; \
CastDoublePrecisionTest(kern_name##_kernel, ref, EqValidatorBuilderFactory<T>()); \
}
/**
* Test Description
* ------------------------
* - Tests that checks `__double2int_rd` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function
* `std::floor`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2INT_TEST_DEF(__double2int_rd, int, std::floor)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2int_rn` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function
* `std::rint`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2INT_TEST_DEF(__double2int_rn, int, std::rint)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2int_ru` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function
* `std::ceil`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2INT_TEST_DEF(__double2int_ru, int, std::ceil)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2int_rz` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function which
* performs cast to int.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2INT_RZ_TEST_DEF(__double2int_rz, int)
/**
* Test Description
* ------------------------
* - RTCs kernels that pass argument of invalid type for __double2int_[rd,rn,ru,rz].
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_Device___double2int_Negative_RTC) { NegativeTestRTCWrapper<12>(kDouble2Int); }
/**
* Test Description
* ------------------------
* - Tests that checks `__double2uint_rd` against a table of difficult values, followed by a
* large number of randomly generated values. The results are compared against reference function
* `std::floor`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2INT_TEST_DEF(__double2uint_rd, unsigned int, std::floor)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2uint_rn` against a table of difficult values, followed by a
* large number of randomly generated values. The results are compared against reference function
* `std::rint`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2INT_TEST_DEF(__double2uint_rn, unsigned int, std::rint)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2uint_ru` against a table of difficult values, followed by a
* large number of randomly generated values. The results are compared against reference function
* `std::ceil`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2INT_TEST_DEF(__double2uint_ru, unsigned int, std::ceil)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2uint_rz` against a table of difficult values, followed by a
* large number of randomly generated values. The results are compared against reference function
* which performs cast to unsigned int.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2INT_RZ_TEST_DEF(__double2uint_rz, unsigned int)
/**
* Test Description
* ------------------------
* - RTCs kernels that pass argument of invalid type for __double2uint_[rd,rn,ru,rz].
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_Device___double2uint_Negative_RTC) { NegativeTestRTCWrapper<12>(kDouble2Uint); }
#define CAST_DOUBLE2LL_TEST_DEF(kern_name, T, ref_func) \
CAST_KERNEL_DEF(kern_name, T, double) \
CAST_F2I_REF_DEF(kern_name, T, double, ref_func) \
\
HIP_TEST_CASE(Unit_Device_##kern_name##_Positive) { \
T (*ref)(double) = kern_name##_ref; \
UnaryDoublePrecisionBruteForceTest(kern_name##_kernel, ref, EqValidatorBuilderFactory<T>(), \
static_cast<double>(std::numeric_limits<T>::min()), \
static_cast<double>(std::numeric_limits<T>::max())); \
}
#define CAST_DOUBLE2LL_RZ_TEST_DEF(kern_name, T) \
CAST_KERNEL_DEF(kern_name, T, double) \
CAST_F2I_RZ_REF_DEF(kern_name, T, double) \
\
HIP_TEST_CASE(Unit_Device_##kern_name##_Positive) { \
T (*ref)(double) = kern_name##_ref; \
UnaryDoublePrecisionBruteForceTest(kern_name##_kernel, ref, EqValidatorBuilderFactory<T>(), \
static_cast<double>(std::numeric_limits<T>::min()), \
static_cast<double>(std::numeric_limits<T>::max())); \
}
/**
* Test Description
* ------------------------
* - Tests that checks `__double2ll_rd` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function
* `std::floor`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2LL_TEST_DEF(__double2ll_rd, long long int, std::floor)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2ll_rn` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function
* `std::rint`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2LL_TEST_DEF(__double2ll_rn, long long int, std::rint)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2ll_ru` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function
* `std::ceil`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2LL_TEST_DEF(__double2ll_ru, long long int, std::ceil)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2ll_rz` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function which
* performs cast to long long int.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2LL_RZ_TEST_DEF(__double2ll_rz, long long int)
/**
* Test Description
* ------------------------
* - RTCs kernels that pass argument of invalid type for __double2ll_[rd,rn,ru,rz].
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_Device___double2ll_Negative_RTC) { NegativeTestRTCWrapper<12>(kDouble2LL); }
/**
* Test Description
* ------------------------
* - Tests that checks `__double2ull_rd` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function
* `std::floor`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2LL_TEST_DEF(__double2ull_rd, unsigned long long int, std::floor)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2ull_rn` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function
* `std::rint`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2LL_TEST_DEF(__double2ull_rn, unsigned long long int, std::rint)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2ull_ru` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function
* `std::ceil`.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2LL_TEST_DEF(__double2ull_ru, unsigned long long int, std::ceil)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2ull_rz` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function which
* performs cast to unsigned long long int.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2LL_RZ_TEST_DEF(__double2ull_rz, unsigned long long int)
/**
* Test Description
* ------------------------
* - RTCs kernels that pass argument of invalid type for __double2ull_[rd,rn,ru,rz].
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_Device___double2ull_Negative_RTC) { NegativeTestRTCWrapper<12>(kDouble2ULL); }
#define CAST_DOUBLE2FLOAT_TEST_DEF(kern_name, round_dir) \
CAST_KERNEL_DEF(kern_name, float, double) \
CAST_RND_REF_DEF(kern_name, float, double, round_dir) \
\
HIP_TEST_CASE(Unit_Device_##kern_name##_Positive) { \
float (*ref)(double) = kern_name##_ref; \
CastDoublePrecisionTest(kern_name##_kernel, ref, EqValidatorBuilderFactory<float>()); \
}
#define CAST_DOUBLE2FLOAT_RN_TEST_DEF(kern_name) \
CAST_KERNEL_DEF(kern_name, float, double) \
CAST_REF_DEF(kern_name, float, double) \
\
HIP_TEST_CASE(Unit_Device_##kern_name##_Positive) { \
float (*ref)(double) = kern_name##_ref; \
CastDoublePrecisionTest(kern_name##_kernel, ref, EqValidatorBuilderFactory<float>()); \
}
/**
* Test Description
* ------------------------
* - Tests that checks `__double2float_rd` against a table of difficult values, followed by a
* large number of randomly generated values. The results are compared against reference function
* which performs cast to float with rounding mode FE_DOWNWARD.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2FLOAT_TEST_DEF(__double2float_rd, FE_DOWNWARD)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2float_rn` against a table of difficult values, followed by a
* large number of randomly generated values. The results are compared against reference function
* which performs cast to float.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2FLOAT_RN_TEST_DEF(__double2float_rn)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2float_ru` against a table of difficult values, followed by a
* large number of randomly generated values. The results are compared against reference function
* which performs cast to float with rounding mode FE_UPWARD.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2FLOAT_TEST_DEF(__double2float_ru, FE_UPWARD)
/**
* Test Description
* ------------------------
* - Tests that checks `__double2float_rz` against a table of difficult values, followed by a
* large number of randomly generated values. The results are compared against reference function
* which performs cast to float with rounding mode FE_TOWARDZERO.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
CAST_DOUBLE2FLOAT_TEST_DEF(__double2float_rz, FE_TOWARDZERO)
/**
* Test Description
* ------------------------
* - RTCs kernels that pass argument of invalid type for __double2float_[rd,rn,ru,rz].
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_Device___double2float_Negative_RTC) { NegativeTestRTCWrapper<12>(kDouble2Float); }
CAST_KERNEL_DEF(__double2hiint, int, double)
int __double2hiint_ref(double arg) {
int tmp[2];
memcpy(tmp, &arg, sizeof(tmp));
return tmp[1];
}
/**
* Test Description
* ------------------------
* - Tests that checks `__double2hiint` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function which
* performs copy of higher part of double value to int variable.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_Device___double2hiint_Positive) {
int (*ref)(double) = __double2hiint_ref;
CastDoublePrecisionTest(__double2hiint_kernel, ref, EqValidatorBuilderFactory<int>());
}
/**
* Test Description
* ------------------------
* - RTCs kernels that pass argument of invalid type for __double2hiint.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_Device___double2hiint_Negative_RTC) { NegativeTestRTCWrapper<3>(kDouble2Hiint); }
CAST_KERNEL_DEF(__double2loint, int, double)
int __double2loint_ref(double arg) {
int tmp[2];
memcpy(tmp, &arg, sizeof(tmp));
return tmp[0];
}
/**
* Test Description
* ------------------------
* - Tests that checks `__double2loint` against a table of difficult values, followed by a large
* number of randomly generated values. The results are compared against reference function which
* performs copy of lower part of double value to int variable.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_Device___double2loint_Positive) {
int (*ref)(double) = __double2loint_ref;
CastDoublePrecisionTest(__double2loint_kernel, ref, EqValidatorBuilderFactory<int>());
}
/**
* Test Description
* ------------------------
* - RTCs kernels that pass argument of invalid type for __double2loint.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_Device___double2loint_Negative_RTC) { NegativeTestRTCWrapper<3>(kDouble2Loint); }
CAST_KERNEL_DEF(__double_as_longlong, long long int, double)
/**
* Test Description
* ------------------------
* - Tests that checks `__double_as_longlong` against a table of difficult values, followed by a
* large number of randomly generated values. The results are compared against reference function
* which performs copy of double value to long long int variable.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_Device___double_as_longlong_Positive) {
long long int (*ref)(double) = type2_as_type1_ref<long long int, double>;
CastDoublePrecisionTest(__double_as_longlong_kernel, ref,
EqValidatorBuilderFactory<long long int>());
}
/**
* Test Description
* ------------------------
* - RTCs kernels that pass argument of invalid type for __double_as_longlong.
*
* Test source
* ------------------------
* - unit/math/casting_double_funcs.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_Device___double_as_longlong_Negative_RTC) {
NegativeTestRTCWrapper<3>(kDoubleAsLonglong);
}
/**
* End doxygen group MathTest.
* @}
*/