
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
29 lines
605 B
C++
29 lines
605 B
C++
#include <gpuintrin.h>
|
|
#include <stdint.h>
|
|
|
|
extern "C" {
|
|
|
|
uint32_t global[64];
|
|
|
|
[[gnu::constructor(202)]] void ctorc() {
|
|
for (unsigned I = 0; I < 64; I++)
|
|
global[I] += 20;
|
|
}
|
|
|
|
[[gnu::constructor(200)]] void ctora() {
|
|
for (unsigned I = 0; I < 64; I++)
|
|
global[I] = 40;
|
|
}
|
|
|
|
[[gnu::constructor(201)]] void ctorb() {
|
|
for (unsigned I = 0; I < 64; I++)
|
|
global[I] *= 2;
|
|
}
|
|
|
|
__gpu_kernel void global_ctor(uint32_t *out) {
|
|
global[__gpu_thread_id(0)] += __gpu_thread_id(0);
|
|
out[__gpu_thread_id(0) + (__gpu_num_threads(0) * __gpu_block_id(0))] =
|
|
global[__gpu_thread_id(0)];
|
|
}
|
|
} // extern "C"
|