[libc-commits] [libc] 9f5c6dc - [libc] Search for the CUDA patch explicitly when testing

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Wed Apr 5 13:14:57 PDT 2023


Author: Joseph Huber
Date: 2023-04-05T15:14:47-05:00
New Revision: 9f5c6dcf595229fccf08a5c8acfbb1ac01cd85f9

URL: https://github.com/llvm/llvm-project/commit/9f5c6dcf595229fccf08a5c8acfbb1ac01cd85f9
DIFF: https://github.com/llvm/llvm-project/commit/9f5c6dcf595229fccf08a5c8acfbb1ac01cd85f9.diff

LOG: [libc] Search for the CUDA patch explicitly when testing

The packaged version of the `libc` library does not depend on the CUDA
installation because it only uses `clang` and emits LLVM-IR. However,
for testing we directly need the CUDA toolkit to emit and execute the
files. This patch explicitly passes `--cuda-path` to the relevant
compilations for NVPTX testing.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D147653

Added: 
    

Modified: 
    libc/cmake/modules/LLVMLibCObjectRules.cmake
    libc/cmake/modules/LLVMLibCTestRules.cmake
    libc/cmake/modules/prepare_libc_gpu_build.cmake
    libc/startup/gpu/nvptx/CMakeLists.txt
    libc/test/IntegrationTest/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 289612bc32a30..5ddc67a1db4ca 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -195,7 +195,9 @@ function(_build_gpu_objects fq_target_name internal_target_name)
     if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
       target_compile_options(${internal_target_name} PRIVATE -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto)
     elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
-      target_compile_options(${internal_target_name} PRIVATE -march=${LIBC_GPU_TARGET_ARCHITECTURE})
+      target_compile_options(${internal_target_name} PRIVATE
+                             -march=${LIBC_GPU_TARGET_ARCHITECTURE}
+                             --cuda-path=${LIBC_CUDA_ROOT})
     endif()
     target_include_directories(${internal_target_name} PRIVATE ${include_dirs})
     if(full_deps_list)

diff  --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 0e1b9f1f6efda..a1ec483600302 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -507,6 +507,7 @@ function(add_integration_test test_name)
                            --target=${LIBC_GPU_TARGET_TRIPLE})
   elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
     target_compile_options(${fq_build_target_name} PRIVATE
+                           --cuda-path=${LIBC_CUDA_ROOT}
                            -march=${LIBC_GPU_TARGET_ARCHITECTURE}
                            --target=${LIBC_GPU_TARGET_TRIPLE})
   endif()

diff  --git a/libc/cmake/modules/prepare_libc_gpu_build.cmake b/libc/cmake/modules/prepare_libc_gpu_build.cmake
index d28cc3f576371..9e0ce79ce5652 100644
--- a/libc/cmake/modules/prepare_libc_gpu_build.cmake
+++ b/libc/cmake/modules/prepare_libc_gpu_build.cmake
@@ -98,3 +98,11 @@ elseif("${gpu_test_architecture}" IN_LIST all_nvptx_architectures)
 else()
   message(FATAL_ERROR "Unknown GPU architecture '${gpu_test_architecture}'")
 endif()
+
+if(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
+  find_package(CUDAToolkit QUIET)
+  if(CUDAToolkit_FOUND)
+    get_filename_component(LIBC_CUDA_ROOT "${CUDAToolkit_BIN_DIR}" DIRECTORY ABSOLUTE)
+    message(WARNING ${LIBC_CUDA_ROOT})
+  endif()
+endif()

diff  --git a/libc/startup/gpu/nvptx/CMakeLists.txt b/libc/startup/gpu/nvptx/CMakeLists.txt
index 0fe0b2d7f7e6c..f8839e9674159 100644
--- a/libc/startup/gpu/nvptx/CMakeLists.txt
+++ b/libc/startup/gpu/nvptx/CMakeLists.txt
@@ -10,6 +10,7 @@ add_startup_object(
     -nogpulib # Do not include any GPU vendor libraries.
     -march=${LIBC_GPU_TARGET_ARCHITECTURE}
     --target=${LIBC_GPU_TARGET_TRIPLE}
+    --cuda-path=${LIBC_CUDA_ROOT}
   NO_GPU_BUNDLE # Compile this file directly without special GPU handling.
 )
 get_fq_target_name(crt1 fq_name)
@@ -19,4 +20,5 @@ target_link_libraries(${fq_name}
   PUBLIC
   "-march=${LIBC_GPU_TARGET_ARCHITECTURE}"
   "--target=${LIBC_GPU_TARGET_TRIPLE}"
+  "--cuda-path=${LIBC_CUDA_ROOT}"
 )

diff  --git a/libc/test/IntegrationTest/CMakeLists.txt b/libc/test/IntegrationTest/CMakeLists.txt
index 62bd114645b57..0c4c38db12f32 100644
--- a/libc/test/IntegrationTest/CMakeLists.txt
+++ b/libc/test/IntegrationTest/CMakeLists.txt
@@ -8,6 +8,7 @@ elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
   set(TEST_COMPILE_FLAGS
     -march=${LIBC_GPU_TARGET_ARCHITECTURE}
     --target=${LIBC_GPU_TARGET_TRIPLE}
+    --cuda-path=${LIBC_CUDA_ROOT}
   )
 endif()
 


        


More information about the libc-commits mailing list