[llvm] WIP: [Offload] Add testing for Offload program and kernel related entry points (PR #127803)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 19 08:09:05 PST 2025


================
@@ -0,0 +1,36 @@
+macro(add_offload_test_device_code test_filename test_name)
+    message("Building Offload API device code for test '${test_name}'")
+    set(SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${test_filename})
+    set(UTIL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/util.h)
+
+    # Build for NVPTX
+    set(BIN_PATH ${CMAKE_CURRENT_BINARY_DIR}/${test_name}.nvptx64.bin)
+    add_custom_command(OUTPUT ${BIN_PATH}
+        COMMAND
+        ${CMAKE_C_COMPILER} --target=nvptx64-nvidia-cuda -march=native
+        --cuda-path=/usr/local/cuda
+        ${SRC_PATH} -o ${BIN_PATH}
+        DEPENDS ${SRC_PATH} ${UTIL_PATH}
+    )
+    list(APPEND BIN_PATHS ${BIN_PATH})
+
+    # Build for AMDGPU
+    set(BIN_PATH ${CMAKE_CURRENT_BINARY_DIR}/${test_name}.amdgpu.bin)
+    add_custom_command(OUTPUT ${BIN_PATH}
+        COMMAND
+        ${CMAKE_C_COMPILER} --target=amdgcn-amd-amdhsa -nogpulib
+        ${SRC_PATH} -o ${BIN_PATH}
+        DEPENDS ${SRC_PATH} ${UTIL_PATH}
+    )
+    list(APPEND BIN_PATHS ${BIN_PATH})
+
+    # TODO: Build for host CPU
+endmacro()
+
+
----------------
jhuber6 wrote:

Refer to my `libc` code for a lot of similar handling https://github.com/llvm/llvm-project/blob/main/libc/cmake/modules/prepare_libc_gpu_build.cmake#L20. I need to hack in `CMAKE_REQUIRED_FLAGS` to get the standard helpers to work, likely can just push / pop those once we're out of this function, or do the `check_source_compiles` manually. I just found that checking if `-march=` or `-mcpu` succeeded was the easiest way to check.

https://github.com/llvm/llvm-project/pull/127803


More information about the llvm-commits mailing list