This commit refactors the `add_offload_test_device_code` CMake function to compile device code using the C++ compiler (`CMAKE_CXX_COMPILER`) instead of the C compiler. This change enables the use of C++ features, such as templates, within device-side test kernels. This will allow for more advanced and reusable kernel wrappers, reducing boilerplate code in the conformance test suite. As part of this change: - All `.c` files for device code in `unittests/` have been renamed to `.cpp`. - Kernel definitions are now wrapped in `extern "C"` to ensure C linkage and prevent name mangling. This change affects the `OffloadAPI` and `Conformance` test suites. cc @callumfare @RossBrunton @jhuber6
41 lines
1.2 KiB
C++
41 lines
1.2 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 of the device kernels that wrap the
|
|
/// math functions from the llvm-libm provider.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include <gpuintrin.h>
|
|
#include <math.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
typedef _Float16 float16;
|
|
|
|
extern "C" {
|
|
|
|
__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();
|
|
|
|
if (Index < NumElements)
|
|
Out[Index] = hypotf16(X[Index], Y[Index]);
|
|
}
|
|
|
|
__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();
|
|
|
|
if (Index < NumElements)
|
|
Out[Index] = logf(X[Index]);
|
|
}
|
|
} // extern "C"
|