diff --git a/offload/unittests/CMakeLists.txt b/offload/unittests/CMakeLists.txt index 117c88b742f8b..726d3eef59c8f 100644 --- a/offload/unittests/CMakeLists.txt +++ b/offload/unittests/CMakeLists.txt @@ -15,6 +15,8 @@ if (NOT TARGET llvm_gtest) return () endif () +set(OFFLOAD_UNITTESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + function(add_offload_test_device_code test_filename test_name) set(SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${test_filename}) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) @@ -39,6 +41,7 @@ function(add_offload_test_device_code test_filename test_name) add_custom_command( OUTPUT ${output_file} COMMAND ${CMAKE_CXX_COMPILER} + -I${OFFLOAD_UNITTESTS_DIR} --target=nvptx64-nvidia-cuda -march=${nvptx_arch} -nogpulib --cuda-path=${cuda_path} -flto ${ARGN} ${SRC_PATH} -o ${output_file} @@ -63,6 +66,7 @@ function(add_offload_test_device_code test_filename test_name) add_custom_command( OUTPUT ${output_file} COMMAND ${CMAKE_CXX_COMPILER} + -I${OFFLOAD_UNITTESTS_DIR} --target=amdgcn-amd-amdhsa -mcpu=${amdgpu_arch} -nogpulib -flto ${ARGN} ${SRC_PATH} -o ${output_file} DEPENDS ${SRC_PATH} diff --git a/offload/unittests/Conformance/device_code/CMakeLists.txt b/offload/unittests/Conformance/device_code/CMakeLists.txt index 9cbd11096292c..789dd167bb9ff 100644 --- a/offload/unittests/Conformance/device_code/CMakeLists.txt +++ b/offload/unittests/Conformance/device_code/CMakeLists.txt @@ -1,4 +1,4 @@ -add_offload_test_device_code(LLVMLibm.cpp llvm-libm -stdlib -fno-builtin) +add_offload_test_device_code(LLVMLibm.cpp llvm-libm -O3 -stdlib -fno-builtin) add_custom_target(conformance_device_binaries DEPENDS llvm-libm.bin) set(OFFLOAD_CONFORMANCE_DEVICE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE) diff --git a/offload/unittests/Conformance/device_code/Common.hpp b/offload/unittests/Conformance/device_code/Common.hpp new file mode 100644 index 0000000000000..bcf3ac617b54c --- /dev/null +++ b/offload/unittests/Conformance/device_code/Common.hpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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 common utilities for defining device kernel wrappers to +/// math functions. +/// +//===----------------------------------------------------------------------===// + +#ifndef CONFORMANCE_DEVICE_CODE_COMMON_HPP +#define CONFORMANCE_DEVICE_CODE_COMMON_HPP + +#include +#include +#include + +namespace common { + +typedef _Float16 float16; + +template +void runKernelBody(size_t NumElements, OutType *Out, const InTypes *...Ins) { + uint32_t Index = + __gpu_num_threads_x() * __gpu_block_id_x() + __gpu_thread_id_x(); + + if (Index < NumElements) { + Out[Index] = Func(Ins[Index]...); + } +} +} // namespace common + +#endif // CONFORMANCE_DEVICE_CODE_COMMON_HPP diff --git a/offload/unittests/Conformance/device_code/LLVMLibm.cpp b/offload/unittests/Conformance/device_code/LLVMLibm.cpp index 2c3d9bc5bf5cf..f137ba3d23752 100644 --- a/offload/unittests/Conformance/device_code/LLVMLibm.cpp +++ b/offload/unittests/Conformance/device_code/LLVMLibm.cpp @@ -12,29 +12,173 @@ /// //===----------------------------------------------------------------------===// +#include "Conformance/device_code/Common.hpp" + #include #include #include -#include -typedef _Float16 float16; +using namespace common; + +//===----------------------------------------------------------------------===// +// Helpers +//===----------------------------------------------------------------------===// + +static inline float sincosfSin(float X) { + float SinX, CosX; + sincosf(X, &SinX, &CosX); + return SinX; +} + +static inline float sincosfCos(float X) { + float SinX, CosX; + sincosf(X, &SinX, &CosX); + return CosX; +} + +//===----------------------------------------------------------------------===// +// Kernels +//===----------------------------------------------------------------------===// extern "C" { +__gpu_kernel void acosfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void acoshfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void asinfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void asinhfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void atanfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void atanhfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void cbrtfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void cosfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void coshfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void cospifKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void erffKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void expfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void exp10fKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void exp2fKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void expm1fKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + __gpu_kernel void hypotf16Kernel(const float16 *X, float16 *Y, float16 *Out, - size_t NumElements) { - uint32_t Index = - __gpu_num_threads_x() * __gpu_block_id_x() + __gpu_thread_id_x(); + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X, Y); +} + +__gpu_kernel void logfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void log10fKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} - if (Index < NumElements) - Out[Index] = hypotf16(X[Index], Y[Index]); +__gpu_kernel void log1pfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); } -__gpu_kernel void logfKernel(const float *X, float *Out, size_t NumElements) { - uint32_t Index = - __gpu_num_threads_x() * __gpu_block_id_x() + __gpu_thread_id_x(); +__gpu_kernel void log2fKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void sinfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void sincosfSinKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void sincosfCosKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void sinhfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void sinpifKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void tanfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} + +__gpu_kernel void tanhfKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); +} - if (Index < NumElements) - Out[Index] = logf(X[Index]); +__gpu_kernel void tanpifKernel(const float *X, float *Out, + size_t NumElements) noexcept { + runKernelBody(NumElements, Out, X); } } // extern "C" diff --git a/offload/unittests/Conformance/tests/AcosfTest.cpp b/offload/unittests/Conformance/tests/AcosfTest.cpp new file mode 100644 index 0000000000000..e69ee3b7d1fd7 --- /dev/null +++ b/offload/unittests/Conformance/tests/AcosfTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the acosf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "acosf"; + static constexpr llvm::StringRef KernelName = "acosfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the acosf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/AcoshfTest.cpp b/offload/unittests/Conformance/tests/AcoshfTest.cpp new file mode 100644 index 0000000000000..4d43a661c3535 --- /dev/null +++ b/offload/unittests/Conformance/tests/AcoshfTest.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the acoshf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "acoshf"; + static constexpr llvm::StringRef KernelName = "acoshfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the acoshf function"); + + using namespace mathtest; + + IndexedRange Range(/*Begin=*/1.0f, + /*End=*/std::numeric_limits::infinity(), + /*Inclusive=*/true); + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/AsinfTest.cpp b/offload/unittests/Conformance/tests/AsinfTest.cpp new file mode 100644 index 0000000000000..991f79b111efe --- /dev/null +++ b/offload/unittests/Conformance/tests/AsinfTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the asinf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "asinf"; + static constexpr llvm::StringRef KernelName = "asinfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the asinf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/AsinhfTest.cpp b/offload/unittests/Conformance/tests/AsinhfTest.cpp new file mode 100644 index 0000000000000..9439383772314 --- /dev/null +++ b/offload/unittests/Conformance/tests/AsinhfTest.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the asinhf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "asinhf"; + static constexpr llvm::StringRef KernelName = "asinhfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the asinhf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/AtanfTest.cpp b/offload/unittests/Conformance/tests/AtanfTest.cpp new file mode 100644 index 0000000000000..64068ef6bff0c --- /dev/null +++ b/offload/unittests/Conformance/tests/AtanfTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the atanf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "atanf"; + static constexpr llvm::StringRef KernelName = "atanfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 5; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the atanf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/AtanhfTest.cpp b/offload/unittests/Conformance/tests/AtanhfTest.cpp new file mode 100644 index 0000000000000..66b934c2f925e --- /dev/null +++ b/offload/unittests/Conformance/tests/AtanhfTest.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the atanhf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "atanhf"; + static constexpr llvm::StringRef KernelName = "atanhfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 5; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the atanhf function"); + + using namespace mathtest; + + IndexedRange Range(/*Begin=*/-1.0f, + /*End=*/1.0f, + /*Inclusive=*/true); + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/CMakeLists.txt b/offload/unittests/Conformance/tests/CMakeLists.txt index b1aa22b44bb5c..5c0c3ba55c062 100644 --- a/offload/unittests/Conformance/tests/CMakeLists.txt +++ b/offload/unittests/Conformance/tests/CMakeLists.txt @@ -1,2 +1,27 @@ +add_conformance_test(acosf AcosfTest.cpp) +add_conformance_test(acoshf AcoshfTest.cpp) +add_conformance_test(asinf AsinfTest.cpp) +add_conformance_test(asinhf AsinhfTest.cpp) +add_conformance_test(atanf AtanfTest.cpp) +add_conformance_test(atanhf AtanhfTest.cpp) +add_conformance_test(cbrtf CbrtfTest.cpp) +add_conformance_test(cosf CosfTest.cpp) +add_conformance_test(coshf CoshfTest.cpp) +add_conformance_test(cospif CospifTest.cpp) +add_conformance_test(erff ErffTest.cpp) +add_conformance_test(expf ExpfTest.cpp) +add_conformance_test(exp10f Exp10fTest.cpp) +add_conformance_test(exp2f Exp2fTest.cpp) +add_conformance_test(expm1f Expm1fTest.cpp) add_conformance_test(hypotf16 Hypotf16Test.cpp) add_conformance_test(logf LogfTest.cpp) +add_conformance_test(log10f Log10fTest.cpp) +add_conformance_test(log1pf Log1pfTest.cpp) +add_conformance_test(log2f Log2fTest.cpp) +add_conformance_test(sinf SinfTest.cpp) +add_conformance_test(sincosf SincosfTest.cpp) +add_conformance_test(sinhf SinhfTest.cpp) +add_conformance_test(sinpif SinpifTest.cpp) +add_conformance_test(tanf TanfTest.cpp) +add_conformance_test(tanhf TanhfTest.cpp) +add_conformance_test(tanpif TanpifTest.cpp) diff --git a/offload/unittests/Conformance/tests/CbrtfTest.cpp b/offload/unittests/Conformance/tests/CbrtfTest.cpp new file mode 100644 index 0000000000000..81c1beab13919 --- /dev/null +++ b/offload/unittests/Conformance/tests/CbrtfTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the cbrtf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "cbrtf"; + static constexpr llvm::StringRef KernelName = "cbrtfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 2; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the cbrtf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/CosfTest.cpp b/offload/unittests/Conformance/tests/CosfTest.cpp new file mode 100644 index 0000000000000..3fa76926a568e --- /dev/null +++ b/offload/unittests/Conformance/tests/CosfTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the cosf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "cosf"; + static constexpr llvm::StringRef KernelName = "cosfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the cosf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/CoshfTest.cpp b/offload/unittests/Conformance/tests/CoshfTest.cpp new file mode 100644 index 0000000000000..33ad515dcaddf --- /dev/null +++ b/offload/unittests/Conformance/tests/CoshfTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the coshf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "coshf"; + static constexpr llvm::StringRef KernelName = "coshfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the coshf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/CospifTest.cpp b/offload/unittests/Conformance/tests/CospifTest.cpp new file mode 100644 index 0000000000000..8fe0ae184b050 --- /dev/null +++ b/offload/unittests/Conformance/tests/CospifTest.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the cospif function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +extern "C" float cospif(float); + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "cospif"; + static constexpr llvm::StringRef KernelName = "cospifKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the cospif function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/ErffTest.cpp b/offload/unittests/Conformance/tests/ErffTest.cpp new file mode 100644 index 0000000000000..20629509d7503 --- /dev/null +++ b/offload/unittests/Conformance/tests/ErffTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the erff function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "erff"; + static constexpr llvm::StringRef KernelName = "erffKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 16; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the erff function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/Exp10fTest.cpp b/offload/unittests/Conformance/tests/Exp10fTest.cpp new file mode 100644 index 0000000000000..c4c88769250f3 --- /dev/null +++ b/offload/unittests/Conformance/tests/Exp10fTest.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the exp10f function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "exp10f"; + static constexpr llvm::StringRef KernelName = "exp10fKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 3; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the exp10f function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/Exp2fTest.cpp b/offload/unittests/Conformance/tests/Exp2fTest.cpp new file mode 100644 index 0000000000000..9d65ca059d008 --- /dev/null +++ b/offload/unittests/Conformance/tests/Exp2fTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the exp2f function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "exp2f"; + static constexpr llvm::StringRef KernelName = "exp2fKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 3; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the exp2f function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/ExpfTest.cpp b/offload/unittests/Conformance/tests/ExpfTest.cpp new file mode 100644 index 0000000000000..996ad39f04738 --- /dev/null +++ b/offload/unittests/Conformance/tests/ExpfTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the expf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "expf"; + static constexpr llvm::StringRef KernelName = "expfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 3; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the expf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/Expm1fTest.cpp b/offload/unittests/Conformance/tests/Expm1fTest.cpp new file mode 100644 index 0000000000000..cfdf48aefe5c3 --- /dev/null +++ b/offload/unittests/Conformance/tests/Expm1fTest.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the expm1f function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "expm1f"; + static constexpr llvm::StringRef KernelName = "expm1fKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 3; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the expm1f function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/Hypotf16Test.cpp b/offload/unittests/Conformance/tests/Hypotf16Test.cpp index fbc001a9fb683..39094f4c24749 100644 --- a/offload/unittests/Conformance/tests/Hypotf16Test.cpp +++ b/offload/unittests/Conformance/tests/Hypotf16Test.cpp @@ -25,10 +25,7 @@ using namespace mathtest; -extern "C" { - -float16 hypotf16(float16, float16); -} +extern "C" float16 hypotf16(float16, float16); namespace mathtest { diff --git a/offload/unittests/Conformance/tests/Log10fTest.cpp b/offload/unittests/Conformance/tests/Log10fTest.cpp new file mode 100644 index 0000000000000..fc7cbab568659 --- /dev/null +++ b/offload/unittests/Conformance/tests/Log10fTest.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the log10f function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "log10f"; + static constexpr llvm::StringRef KernelName = "log10fKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 3; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the log10f function"); + + using namespace mathtest; + + IndexedRange Range(/*Begin=*/0.0f, + /*End=*/std::numeric_limits::infinity(), + /*Inclusive=*/true); + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/Log1pfTest.cpp b/offload/unittests/Conformance/tests/Log1pfTest.cpp new file mode 100644 index 0000000000000..4388cf4ea1a95 --- /dev/null +++ b/offload/unittests/Conformance/tests/Log1pfTest.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the log1pf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "log1pf"; + static constexpr llvm::StringRef KernelName = "log1pfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 2; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the log1pf function"); + + using namespace mathtest; + + IndexedRange Range(/*Begin=*/-1.0f, + /*End=*/std::numeric_limits::infinity(), + /*Inclusive=*/true); + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/Log2fTest.cpp b/offload/unittests/Conformance/tests/Log2fTest.cpp new file mode 100644 index 0000000000000..8c6fff177bb8b --- /dev/null +++ b/offload/unittests/Conformance/tests/Log2fTest.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the log2f function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "log2f"; + static constexpr llvm::StringRef KernelName = "log2fKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 3; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the log2f function"); + + using namespace mathtest; + + IndexedRange Range(/*Begin=*/0.0f, + /*End=*/std::numeric_limits::infinity(), + /*Inclusive=*/true); + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/SincosfTest.cpp b/offload/unittests/Conformance/tests/SincosfTest.cpp new file mode 100644 index 0000000000000..2a70b51e4b057 --- /dev/null +++ b/offload/unittests/Conformance/tests/SincosfTest.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the sincosf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +static inline float sincosfSin(float X) { + float SinX, CosX; + sincosf(X, &SinX, &CosX); + return SinX; +} + +static inline float sincosfCos(float X) { + float SinX, CosX; + sincosf(X, &SinX, &CosX); + return CosX; +} + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "sincosf (sin part)"; + static constexpr llvm::StringRef KernelName = "sincosfSinKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "sincosf (cos part)"; + static constexpr llvm::StringRef KernelName = "sincosfCosKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the sincosf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool SinPartPassed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + bool CosPartPassed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return (SinPartPassed && CosPartPassed) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/SinfTest.cpp b/offload/unittests/Conformance/tests/SinfTest.cpp new file mode 100644 index 0000000000000..b5f2b34ff57ac --- /dev/null +++ b/offload/unittests/Conformance/tests/SinfTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the sinf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "sinf"; + static constexpr llvm::StringRef KernelName = "sinfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the sinf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/SinhfTest.cpp b/offload/unittests/Conformance/tests/SinhfTest.cpp new file mode 100644 index 0000000000000..d0510687f51e6 --- /dev/null +++ b/offload/unittests/Conformance/tests/SinhfTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the sinhf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "sinhf"; + static constexpr llvm::StringRef KernelName = "sinhfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the sinhf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/SinpifTest.cpp b/offload/unittests/Conformance/tests/SinpifTest.cpp new file mode 100644 index 0000000000000..745af111f99a2 --- /dev/null +++ b/offload/unittests/Conformance/tests/SinpifTest.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the sinpif function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +extern "C" float sinpif(float); + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "sinpif"; + static constexpr llvm::StringRef KernelName = "sinpifKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 4; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the sinpif function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/TanfTest.cpp b/offload/unittests/Conformance/tests/TanfTest.cpp new file mode 100644 index 0000000000000..0fe7d9651cece --- /dev/null +++ b/offload/unittests/Conformance/tests/TanfTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the tanf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "tanf"; + static constexpr llvm::StringRef KernelName = "tanfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 5; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the tanf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/TanhfTest.cpp b/offload/unittests/Conformance/tests/TanhfTest.cpp new file mode 100644 index 0000000000000..6de4c146544d8 --- /dev/null +++ b/offload/unittests/Conformance/tests/TanhfTest.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the tanhf function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "tanhf"; + static constexpr llvm::StringRef KernelName = "tanhfKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 5; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the tanhf function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/offload/unittests/Conformance/tests/TanpifTest.cpp b/offload/unittests/Conformance/tests/TanpifTest.cpp new file mode 100644 index 0000000000000..dabfdd865cb02 --- /dev/null +++ b/offload/unittests/Conformance/tests/TanpifTest.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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 conformance test of the tanpif function. +/// +//===----------------------------------------------------------------------===// + +#include "mathtest/CommandLineExtras.hpp" +#include "mathtest/ExhaustiveGenerator.hpp" +#include "mathtest/IndexedRange.hpp" +#include "mathtest/TestConfig.hpp" +#include "mathtest/TestRunner.hpp" + +#include "llvm/ADT/StringRef.h" + +#include +#include + +extern "C" float tanpif(float); + +namespace mathtest { + +template <> struct FunctionConfig { + static constexpr llvm::StringRef Name = "tanpif"; + static constexpr llvm::StringRef KernelName = "tanpifKernel"; + + // Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, + // Table 65, Khronos Registry [July 10, 2025]. + static constexpr uint64_t UlpTolerance = 6; +}; +} // namespace mathtest + +int main(int argc, const char **argv) { + llvm::cl::ParseCommandLineOptions(argc, argv, + "Conformance test of the tanpif function"); + + using namespace mathtest; + + IndexedRange Range; + ExhaustiveGenerator Generator(Range); + + const auto Configs = cl::getTestConfigs(); + const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; + const bool IsVerbose = cl::IsVerbose; + + bool Passed = + runTests(Generator, Configs, DeviceBinaryDir, IsVerbose); + + return Passed ? EXIT_SUCCESS : EXIT_FAILURE; +}