Leandro Lacerda 2abd58cb7e
[Offload] Add framework for math conformance tests (#149242)
This PR introduces the initial version of a C++ framework for the
conformance testing of GPU math library functions, building upon the
skeleton provided in #146391.

The main goal of this framework is to systematically measure the
accuracy of math functions in the GPU libc, verifying correctness or at
least conformance to standards like OpenCL via exhaustive or random
accuracy tests.
2025-07-29 11:08:27 -05:00

57 lines
1.8 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file contains the implementation for the functions that define the set
/// of all and default test configurations.
///
//===----------------------------------------------------------------------===//
#include "mathtest/TestConfig.hpp"
#include "mathtest/DeviceContext.hpp"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SmallVectorExtras.h"
using namespace mathtest;
[[nodiscard]] const llvm::SmallVector<TestConfig, 4> &
mathtest::getAllTestConfigs() {
// Thread-safe initialization of a static local variable
static auto AllTestConfigs = []() -> llvm::SmallVector<TestConfig, 4> {
return {
{"llvm-libm", "amdgpu"},
{"llvm-libm", "cuda"},
{"cuda-math", "cuda"},
{"hip-math", "amdgpu"},
};
}();
return AllTestConfigs;
};
[[nodiscard]] const llvm::SmallVector<TestConfig, 4> &
mathtest::getDefaultTestConfigs() {
// Thread-safe initialization of a static local variable
static auto DefaultTestConfigs = []() -> llvm::SmallVector<TestConfig, 4> {
const auto Platforms = getPlatforms();
const auto AllTestConfigs = getAllTestConfigs();
llvm::StringRef Provider = "llvm-libm";
return llvm::filter_to_vector(AllTestConfigs, [&](const auto &Config) {
return Provider.equals_insensitive(Config.Provider) &&
llvm::any_of(Platforms, [&](llvm::StringRef Platform) {
return Platform.equals_insensitive(Config.Platform);
});
});
}();
return DefaultTestConfigs;
};