Leandro Lacerda f1eb869bae
[Offload][UnitTests] Build device code as C++ (#151714)
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
2025-08-04 07:00:51 -05:00

17 lines
390 B
C++

#include <gpuintrin.h>
#include <stdint.h>
extern __gpu_local uint32_t shared_mem[];
extern "C" __gpu_kernel void localmem_reduction(uint32_t *out) {
shared_mem[__gpu_thread_id(0)] = 2;
__gpu_sync_threads();
if (__gpu_thread_id(0) == 0) {
out[__gpu_block_id(0)] = 0;
for (uint32_t i = 0; i < __gpu_num_threads(0); i++)
out[__gpu_block_id(0)] += shared_mem[i];
}
}