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
102 lines
2.8 KiB
C++
102 lines
2.8 KiB
C++
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <limits>
|
|
#include <type_traits>
|
|
#include <utility>
|
|
#include <half/half.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
#include "verify.hpp"
|
|
#include "../tensor_holder.hpp"
|
|
|
|
namespace test_helpers {
|
|
template <typename T>
|
|
constexpr bool is_floating_point_tensor =
|
|
(std::is_same_v<typename T::value_type, half_float::half> ||
|
|
std::is_floating_point_v<typename T::value_type>);
|
|
|
|
template <class... Ts>
|
|
constexpr bool any_float_tensors()
|
|
{
|
|
return (is_floating_point_tensor<Ts> || ...);
|
|
}
|
|
|
|
template <class T>
|
|
auto const& GetResultData(std::vector<T> const& result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
template <class T>
|
|
std::vector<T> const& GetResultData(tensor<T> const& result)
|
|
{
|
|
return result.data;
|
|
}
|
|
|
|
template <class T>
|
|
constexpr double GetResultDataErrorMargin(std::vector<T> const& /*result*/, double tolerance)
|
|
{
|
|
return (std::numeric_limits<T>::epsilon() * tolerance);
|
|
}
|
|
|
|
template <class T>
|
|
constexpr double GetResultDataErrorMargin(tensor<T> const& /*result*/, double tolerance)
|
|
{
|
|
return (std::numeric_limits<T>::epsilon() * tolerance);
|
|
}
|
|
|
|
template <class LeftTuple, class RightTuple, std::size_t... I>
|
|
bool CompareFloatTensorTuples(LeftTuple const& left,
|
|
RightTuple const& right,
|
|
double tolerance,
|
|
std::index_sequence<I...>)
|
|
{
|
|
return (
|
|
(miopen::rms_range(GetResultData(std::get<I>(left)), GetResultData(std::get<I>(right))) <=
|
|
(GetResultDataErrorMargin(std::get<I>(left), tolerance))) &&
|
|
...);
|
|
}
|
|
|
|
template <typename... CpuT, typename... GpuT>
|
|
bool Compare(std::tuple<CpuT...> const& cpu_result,
|
|
std::tuple<GpuT...> const& gpu_result,
|
|
double tolerance)
|
|
{
|
|
if constexpr(any_float_tensors<CpuT...>() || any_float_tensors<GpuT...>())
|
|
{
|
|
return CompareFloatTensorTuples(
|
|
cpu_result, gpu_result, tolerance, std::index_sequence_for<CpuT...>{});
|
|
}
|
|
else
|
|
{
|
|
return cpu_result == gpu_result;
|
|
}
|
|
}
|
|
|
|
template <typename T>
|
|
bool Compare(tensor<T> cpu_result, tensor<T> gpu_result, double tolerance)
|
|
{
|
|
double threshold = std::numeric_limits<T>::epsilon() * tolerance;
|
|
return (miopen::rms_range(cpu_result.data, gpu_result.data) <= threshold);
|
|
}
|
|
|
|
/// Generic comparison helper for structs using cpu() and gpu() methods
|
|
template <class VerifyT>
|
|
auto CompareResults(VerifyT&& verifier, double tolerance = 80.f)
|
|
-> std::pair<decltype(verifier.cpu()), decltype(verifier.gpu())>
|
|
{
|
|
const auto gpu_result = verifier.gpu();
|
|
const auto cpu_result = verifier.cpu();
|
|
if(!Compare(cpu_result, gpu_result, tolerance))
|
|
{
|
|
verifier.fail();
|
|
}
|
|
|
|
return std::make_pair(cpu_result, gpu_result);
|
|
}
|
|
} // namespace test_helpers
|