brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 246801e Raw
75 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file contains the conformance test of the powf function.11///12//===----------------------------------------------------------------------===//13 14#include "mathtest/CommandLineExtras.hpp"15#include "mathtest/IndexedRange.hpp"16#include "mathtest/RandomGenerator.hpp"17#include "mathtest/RandomState.hpp"18#include "mathtest/TestConfig.hpp"19#include "mathtest/TestRunner.hpp"20 21#include "llvm/ADT/StringRef.h"22 23#include <cstdlib>24#include <math.h>25 26static inline float powfRoundedExponent(float Base, float Exponent) {27  return powf(Base, roundf(Exponent));28}29 30namespace mathtest {31 32template <> struct FunctionConfig<powf> {33  static constexpr llvm::StringRef Name = "powf (real exponents)";34  static constexpr llvm::StringRef KernelName = "powfKernel";35 36  // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4,37  //         Table 65, Khronos Registry [July 10, 2025].38  static constexpr uint64_t UlpTolerance = 16;39};40 41template <> struct FunctionConfig<powfRoundedExponent> {42  static constexpr llvm::StringRef Name = "powf (integer exponents)";43  static constexpr llvm::StringRef KernelName = "powfRoundedExponentKernel";44 45  // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4,46  //         Table 65, Khronos Registry [July 10, 2025].47  static constexpr uint64_t UlpTolerance = 16;48};49} // namespace mathtest50 51int main(int argc, const char **argv) {52  llvm::cl::ParseCommandLineOptions(argc, argv,53                                    "Conformance test of the powf function");54 55  using namespace mathtest;56 57  uint64_t Size = 1ULL << 32;58  IndexedRange<float> RangeX;59  IndexedRange<float> RangeY;60  RandomGenerator<float, float> Generator0(SeedTy{42}, Size, RangeX, RangeY);61  RandomGenerator<float, float> Generator1(SeedTy{51}, Size, RangeX, RangeY);62 63  const auto Configs = cl::getTestConfigs();64  const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR;65  const bool IsVerbose = cl::IsVerbose;66 67  bool RealExponentsPassed =68      runTests<powf>(Generator0, Configs, DeviceBinaryDir, IsVerbose);69  bool IntegerExponentsPassed = runTests<powfRoundedExponent>(70      Generator1, Configs, DeviceBinaryDir, IsVerbose);71 72  return (RealExponentsPassed && IntegerExponentsPassed) ? EXIT_SUCCESS73                                                         : EXIT_FAILURE;74}75