Debian Codegraph @

offload/unittests/Conformance/tests/Log1pTest.cpp

raw
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file contains the conformance test of the log1p 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 <limits>
25 #include <math.h>
26
27 namespace {
28
29 // Disambiguate the overloaded 'log1p' function to select the double version
30 constexpr auto log1pd // NOLINT(readability-identifier-naming)
31 = static_cast<double (*)(double)>(log1p);
32 } // namespace
33
34 namespace mathtest {
35
36 template <> struct FunctionConfig<log1pd> {
37 static constexpr llvm::StringRef Name = "log1p";
38 static constexpr llvm::StringRef KernelName = "log1pKernel";
39
40 // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4,
41 // Table 68, Khronos Registry [July 10, 2025].
42 static constexpr uint64_t UlpTolerance = 2;
43 };
44 } // namespace mathtest
45
46 int main(int argc, const char **argv) {
47 llvm::cl::ParseCommandLineOptions(argc, argv,
48 "Conformance test of the log1p function");
49
50 using namespace mathtest;
51
52 uint64_t Seed = 42;
53 uint64_t Size = 1ULL << 32;
54 IndexedRange<double> Range(/*Begin=*/-1.0,
55 /*End=*/std::numeric_limits<double>::infinity(),
56 /*Inclusive=*/true);
57 RandomGenerator<double> Generator(SeedTy{Seed}, Size, Range);
58
59 const auto Configs = cl::getTestConfigs();
60 const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR;
61 const bool IsVerbose = cl::IsVerbose;
62
63 bool Passed =
64 runTests<log1pd>(Generator, Configs, DeviceBinaryDir, IsVerbose);
65
66 return Passed ? EXIT_SUCCESS : EXIT_FAILURE;
67 }