Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/math/double_precision_intrinsics.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

228 lines
9.4 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include <hip_test_common.hh>
#include "unary_common.hh"
#include "binary_common.hh"
#include "ternary_common.hh"
/********** Unary Functions **********/
#define MATH_UNARY_DP_KERNEL_DEF(func_name) \
__global__ void func_name##_kernel(double* const ys, const size_t num_xs, double* 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) { \
ys[i] = func_name(xs[i]); \
} \
}
#define MATH_UNARY_DP_TEST_DEF_IMPL(func_name, ref_func, validator_builder) \
HIP_TEST_CASE(Unit_Device_##func_name##_Accuracy_Positive) { \
UnaryDoublePrecisionTest(func_name##_kernel, ref_func, validator_builder); \
}
#define MATH_UNARY_DP_TEST_DEF(func_name, ref_func) \
MATH_UNARY_DP_TEST_DEF_IMPL(func_name, ref_func, func_name##_validator_builder)
#define MATH_UNARY_DP_VALIDATOR_BUILDER_DEF(func_name) \
static std::unique_ptr<MatcherBase<double>> func_name##_validator_builder(double target, double x)
static double __drcp_rn_ref(double x) { return 1.0 / x; }
MATH_UNARY_DP_KERNEL_DEF(__drcp_rn);
/**
* Test Description
* ------------------------
* - Tests the numerical accuracy of `__drcp_rn(x)` against a table of difficult values,
* followed by a large number of randomly generated values. The error bounds are
* IEEE-compliant.
*
* Test source
* ------------------------
* - unit/math/double_precision_intrinsics.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
MATH_UNARY_DP_TEST_DEF_IMPL(__drcp_rn, __drcp_rn_ref, EqValidatorBuilderFactory<double>());
MATH_UNARY_DP_KERNEL_DEF(__dsqrt_rn);
/**
* Test Description
* ------------------------
* - Tests the numerical accuracy of `__dsqrt_rn(x)` against a table of difficult values,
* followed by a large number of randomly generated values. The results are
* compared against reference function `double std::sqrt(double)`. The error bounds are
* IEEE-compliant.
*
* Test source
* ------------------------
* - unit/math/double_precision_intrinsics.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
MATH_UNARY_DP_TEST_DEF_IMPL(__dsqrt_rn, static_cast<double (*)(double)>(std::sqrt),
EqValidatorBuilderFactory<double>());
/********** Binary Functions **********/
#define MATH_BINARY_DP_KERNEL_DEF(func_name) \
__global__ void func_name##_kernel(double* const ys, const size_t num_xs, double* const x1s, \
double* const x2s) { \
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) { \
ys[i] = func_name(x1s[i], x2s[i]); \
} \
}
#define MATH_BINARY_DP_TEST_DEF_IMPL(func_name, ref_func, validator_builder) \
HIP_TEST_CASE(Unit_Device_##func_name##_Accuracy_Positive) { \
BinaryFloatingPointTest(func_name##_kernel, ref_func, validator_builder); \
}
#define MATH_BINARY_DP_TEST_DEF(func_name, ref_func) \
MATH_BINARY_DP_TEST_IMPL(func_name, ref_func, func_name##_validator_builder)
#define MATH_BINARY_DP_VALIDATOR_BUILDER_DEF(func_name) \
static std::unique_ptr<MatcherBase<double>> func_name##_validator_builder(double target, \
double x1, double x2)
static double __dadd_rn_ref(double x1, double x2) { return x1 + x2; }
MATH_BINARY_DP_KERNEL_DEF(__dadd_rn);
/**
* Test Description
* ------------------------
* - Tests the numerical accuracy of `__dadd_rn(x,y)` against a table of difficult values,
* followed by a large number of randomly generated values. The error bounds are IEEE-compliant.
*
* Test source
* ------------------------
* - unit/math/double_precision_intrinsics.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
MATH_BINARY_DP_TEST_DEF_IMPL(__dadd_rn, __dadd_rn_ref, EqValidatorBuilderFactory<double>());
static double __dsub_rn_ref(double x1, double x2) { return x1 - x2; }
MATH_BINARY_DP_KERNEL_DEF(__dsub_rn);
/**
* Test Description
* ------------------------
* - Tests the numerical accuracy of `__dsub_rn(x,y)` against a table of difficult values,
* followed by a large number of randomly generated values. The error bounds are IEEE-compliant.
*
* Test source
* ------------------------
* - unit/math/double_precision_intrinsics.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
MATH_BINARY_DP_TEST_DEF_IMPL(__dsub_rn, __dsub_rn_ref, EqValidatorBuilderFactory<double>());
static double __dmul_rn_ref(double x1, double x2) { return x1 * x2; }
MATH_BINARY_DP_KERNEL_DEF(__dmul_rn);
/**
* Test Description
* ------------------------
* - Tests the numerical accuracy of `__dmul_rn(x,y)` against a table of difficult values,
* followed by a large number of randomly generated values. The error bounds are IEEE-compliant.
*
* Test source
* ------------------------
* - unit/math/double_precision_intrinsics.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
MATH_BINARY_DP_TEST_DEF_IMPL(__dmul_rn, __dmul_rn_ref, EqValidatorBuilderFactory<double>());
static double __ddiv_rn_ref(double x1, double x2) { return x1 / x2; }
MATH_BINARY_DP_KERNEL_DEF(__ddiv_rn);
/**
* Test Description
* ------------------------
* - Tests the numerical accuracy of `__ddiv_rn(x,y)` against a table of difficult values,
* followed by a large number of randomly generated values. The error bounds are IEEE-compliant.
*
* Test source
* ------------------------
* - unit/math/double_precision_intrinsics.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
MATH_BINARY_DP_TEST_DEF_IMPL(__ddiv_rn, __ddiv_rn_ref, EqValidatorBuilderFactory<double>());
/********** Ternary Functions **********/
#define MATH_TERNARY_DP_KERNEL_DEF(func_name) \
__global__ void func_name##_kernel(double* const ys, const size_t num_xs, double* const x1s, \
double* const x2s, double* const x3s) { \
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) { \
ys[i] = func_name(x1s[i], x2s[i], x3s[i]); \
} \
}
#define MATH_TERNARY_DP_TEST_DEF_IMPL(func_name, ref_func, validator_builder) \
HIP_TEST_CASE(Unit_Device_##func_name##_Accuracy_Positive) { \
TernaryFloatingPointTest(func_name##_kernel, ref_func, validator_builder); \
}
#define MATH_TERNARY_DP_TEST_DEF(func_name, ref_func, validator_builder) \
MATH_TERNARY_DP_TEST_DEF_IMPL(func_name, ref_func, func_name##_validator_builder)
#define MATH_TERNARY_DP_VALIDATOR_BUILDER_DEF(func_name) \
static std::unique_ptr<MatcherBase<double>> func_name##_validator_builder( \
double target, double x1, double x2, double x3)
MATH_TERNARY_DP_KERNEL_DEF(__fma_rn);
/**
* Test Description
* ------------------------
* - Tests the numerical accuracy of `__fma(x,y,z)` against a table of difficult values,
* followed by a large number of randomly generated values. The error bounds are IEEE-compliant.
*
* Test source
* ------------------------
* - unit/math/double_precision_intrinsics.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
MATH_TERNARY_DP_TEST_DEF_IMPL(__fma_rn, static_cast<double (*)(double, double, double)>(std::fma),
EqValidatorBuilderFactory<double>());