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
114 lines
4.4 KiB
C++
114 lines
4.4 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <Reference.hpp>
|
|
#include <Tensile/ContractionProblem.hpp>
|
|
#include <Tensile/DataTypes.hpp>
|
|
|
|
#include <cmath>
|
|
#include <vector>
|
|
|
|
using namespace TensileLite;
|
|
using namespace TensileLite::Client;
|
|
|
|
namespace
|
|
{
|
|
ContractionProblemGemm makePackedProblem(rocisa::DataType typeA,
|
|
rocisa::DataType typeB,
|
|
rocisa::DataType typeC,
|
|
size_t M,
|
|
size_t N,
|
|
size_t K)
|
|
{
|
|
auto problem = ContractionProblemGemm::GEMM_Strides(false,
|
|
false,
|
|
typeA,
|
|
typeB,
|
|
typeC,
|
|
typeC,
|
|
M,
|
|
N,
|
|
K,
|
|
1,
|
|
M,
|
|
M * K,
|
|
K,
|
|
K * N,
|
|
M,
|
|
M * N,
|
|
M,
|
|
M * N,
|
|
0.0);
|
|
problem.setComputeInputTypeA(typeA);
|
|
problem.setComputeInputTypeB(typeB);
|
|
problem.setAlphaType(typeC);
|
|
problem.setBetaType(typeC);
|
|
return problem;
|
|
}
|
|
} // namespace
|
|
|
|
TEST(ReferenceFastPath, PreservesDoublePrecisionForF64)
|
|
{
|
|
const size_t M = 1;
|
|
const size_t N = 1;
|
|
const size_t K = 2;
|
|
|
|
auto problem = makePackedProblem(rocisa::DataType::Double,
|
|
rocisa::DataType::Double,
|
|
rocisa::DataType::Double,
|
|
M,
|
|
N,
|
|
K);
|
|
ASSERT_TRUE(isFastPathEligible(problem));
|
|
|
|
const double a0 = 1.0 + std::ldexp(1.0, -40);
|
|
const double a1 = 1.0 + std::ldexp(1.0, -41);
|
|
const double b0 = 1.0 + std::ldexp(1.0, -42);
|
|
const double b1 = 1.0 + std::ldexp(1.0, -43);
|
|
|
|
std::vector<double> a = {a0, a1};
|
|
std::vector<double> b = {b0, b1};
|
|
std::vector<double> c = {0.0};
|
|
std::vector<double> d = {0.0};
|
|
|
|
ContractionInputs inputs(a.data(), b.data(), c.data(), d.data(), 1.0, 0.0);
|
|
SolveGemmCPU(problem, inputs, /*elementsToValidate=*/-1, /*tryFastPath=*/true);
|
|
|
|
const double expected = a0 * b0 + a1 * b1;
|
|
ASSERT_NE(static_cast<double>(static_cast<float>(expected)), expected);
|
|
EXPECT_EQ(d[0], expected);
|
|
}
|
|
|
|
TEST(ReferenceFastPath, AppliesXFloat32OperandMathOpToBothOperands)
|
|
{
|
|
const size_t M = 1;
|
|
const size_t N = 1;
|
|
const size_t K = 2;
|
|
|
|
auto problem = makePackedProblem(rocisa::DataType::Float,
|
|
rocisa::DataType::Float,
|
|
rocisa::DataType::Float,
|
|
M,
|
|
N,
|
|
K);
|
|
problem.setF32XdlMathOp(rocisa::DataType::XFloat32);
|
|
ASSERT_TRUE(isFastPathEligible(problem));
|
|
|
|
std::vector<float> a = {1.234567f, -2.345678f};
|
|
std::vector<float> b = {3.456789f, 4.567891f};
|
|
std::vector<float> c = {0.0f};
|
|
std::vector<float> d = {0.0f};
|
|
|
|
ContractionInputs inputs(a.data(), b.data(), c.data(), d.data(), 1.0f, 0.0f);
|
|
SolveGemmCPU(problem, inputs, /*elementsToValidate=*/-1, /*tryFastPath=*/true);
|
|
|
|
auto xf32 = [](float v) { return static_cast<float>(XFloat32(v)); };
|
|
const float expected = xf32(a[0]) * xf32(b[0]) + xf32(a[1]) * xf32(b[1]);
|
|
const float fullF32 = a[0] * b[0] + a[1] * b[1];
|
|
|
|
ASSERT_NE(expected, fullF32);
|
|
EXPECT_EQ(d[0], expected);
|
|
}
|