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

26 lines
919 B
CMake

add_offload_test_device_code(foo.cpp foo)
add_offload_test_device_code(bar.cpp bar)
# Compile with optimizations to eliminate AMDGPU implicit arguments.
add_offload_test_device_code(noargs.cpp noargs -O3)
add_offload_test_device_code(localmem.cpp localmem)
add_offload_test_device_code(localmem_reduction.cpp localmem_reduction)
add_offload_test_device_code(localmem_static.cpp localmem_static)
add_offload_test_device_code(global.cpp global)
add_offload_test_device_code(global_ctor.cpp global_ctor)
add_offload_test_device_code(global_dtor.cpp global_dtor)
add_offload_test_device_code(sequence.cpp sequence)
add_custom_target(offload_device_binaries DEPENDS
foo.bin
bar.bin
noargs.bin
localmem.bin
localmem_reduction.bin
localmem_static.bin
global.bin
global_ctor.bin
global_dtor.bin
sequence.bin
)
set(OFFLOAD_TEST_DEVICE_CODE_PATH ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)