From b26970ec4b79590f41f5e1dd7cb56d5f8d4d9301 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Fri, 24 Mar 2023 21:00:25 -0500 Subject: [PATCH] [libc] Enable integration tests targeting NVIDIA GPUs This patch adds the necessary build infrastructure to build and run the integration tests on NVIDIA GPUs. The NVIDIA `nvlink` linker utility is what is ultimately used to combine these files into a single executable image. Unfortunately, their tool does not support static libraries. So we need to link with every object directly instead. This could be solved by impelementing a "wrapper" utility around `nvlink` like we used to use for OpenMP. But for now this should be sufficient. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D146861 --- libc/cmake/modules/LLVMLibCTestRules.cmake | 11 ++++++++--- libc/utils/gpu/loader/CMakeLists.txt | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake index f28b345..4e1a63d 100644 --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -484,6 +484,8 @@ function(add_integration_test test_name) add_executable( ${fq_build_target_name} EXCLUDE_FROM_ALL + # The NVIDIA 'nvlink' linker does not currently support static libraries. + $<$:${link_object_files}> ${INTEGRATION_TEST_SRCS} ${INTEGRATION_TEST_HDRS} ) @@ -510,9 +512,12 @@ function(add_integration_test test_name) endif() target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static) - target_link_libraries(${fq_build_target_name} ${fq_target_name}.__libc__ - libc.startup.${LIBC_TARGET_OS}.crt1 - libc.test.IntegrationTest.test) + target_link_libraries( + ${fq_build_target_name} + # The NVIDIA 'nvlink' linker does not currently support static libraries. + $<$>:${fq_target_name}.__libc__> + libc.startup.${LIBC_TARGET_OS}.crt1 + libc.test.IntegrationTest.test) add_dependencies(${fq_build_target_name} libc.test.IntegrationTest.test ${INTEGRATION_TEST_DEPENDS}) diff --git a/libc/utils/gpu/loader/CMakeLists.txt b/libc/utils/gpu/loader/CMakeLists.txt index 5e9f0a1..f037d3f 100644 --- a/libc/utils/gpu/loader/CMakeLists.txt +++ b/libc/utils/gpu/loader/CMakeLists.txt @@ -24,4 +24,12 @@ if(TARGET amdhsa_loader AND LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) PROPERTIES EXECUTABLE "$" ) +elseif(TARGET nvptx_loader AND LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) + add_custom_target(libc.utils.gpu.loader) + add_dependencies(libc.utils.gpu.loader nvptx_loader) + set_target_properties( + libc.utils.gpu.loader + PROPERTIES + EXECUTABLE "$" + ) endif() -- 2.7.4