[llvm] [offload][runtimes] Forward user-provided system configuration. (PR #96303)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 21 06:18:08 PDT 2024


https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/96303

In order for LLVM_ENABLE_RUNTIMES projects to find their requirements, they need access to user-provided configuration options such as `CMAKE_PREFIX_PATH`. Forward a selection of configuration options sich that runtimes uses the same system introspection as LLVM and LLVM_ENABLE_PROJECTS do.

The concrete symptom this is solving is that the path to CUDA is provided using `cmake -DCUDA_TOOLKIT_ROOT_DIR=/opt/cuda` or `CUDA_PATH`, but is ignored by offload. Handling for this case already existed for libc, but only when it was enabled and only `CUDAToolkit_ROOT` (The former is for `find_package(CUDA)`, the latter for `find_package(CUDAToolkit)`).

`CUDA_TOOLKIT_ROOT_DIR` is actually deprecated but still used and required by `offload/list/lit.site.cfg.in`.

>From 8c907752808e8344c7cee310bcd28a4255cf6095 Mon Sep 17 00:00:00 2001
From: Michael Kruse <meinersbur at github.com>
Date: Fri, 21 Jun 2024 04:38:05 -0700
Subject: [PATCH] Forward user-provided system configuration

---
 llvm/runtimes/CMakeLists.txt | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index e60c9dd6041b4..4948964962d35 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -204,10 +204,6 @@ foreach(entry ${runtimes})
   if(canon_name STREQUAL "LIBC")
     list(APPEND prefixes "LLVM_LIBC")
     list(APPEND prefixes "LIBC_")
-    # The `libc` project may require '-DCUDAToolkit_ROOT' in GPU mode.
-    if(LLVM_LIBC_GPU_BUILD)
-      list(APPEND prefixes "CUDA")
-    endif()
   endif()
 
   _get_runtime_name(${name} name)
@@ -261,6 +257,7 @@ function(runtime_default_target)
                                       ${ARG_CMAKE_ARGS}
                            PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
                                                 LLVM_USE_LINKER
+                                                CUDA # For runtimes that may look for the CUDA SDK (libc, offload)
                                                 ${ARG_PREFIXES}
                            EXTRA_TARGETS ${extra_targets}
                                          ${test_targets}
@@ -445,6 +442,18 @@ if(build_runtimes)
   # The runtimes target is a configuration of all the runtime libraries
   # together in a single CMake invocation.
   set(extra_deps "")
+  set(extra_cmake_args "")
+
+  # Forward user-provived system configuration to runtimes for requirement introspection.
+  # CMAKE_PREFIX_PATH is the search path for CMake packages.
+  if(CMAKE_PREFIX_PATH)
+    list(APPEND extra_cmake_args "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}")
+  endif()
+  # CMAKE_PROGRAM_PATH is the search path for executables such as python.
+  if(CMAKE_PROGRAM_PATH)
+    list(APPEND extra_cmake_args "-DCMAKE_PROGRAM_PATH=${CMAKE_PROGRAM_PATH}")
+  endif()
+
   if("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)
     if (${LLVM_TOOL_FLANG_BUILD})
       message(STATUS "Configuring build of omp_lib.mod and omp_lib_kinds.mod via flang-new")
@@ -499,10 +508,6 @@ if(build_runtimes)
       endif()
       list(APPEND libc_cmake_args "-DRUNTIMES_nvptx64-nvidia-cuda_LLVM_LIBC_FULL_BUILD=ON")
     endif()
-    # The `libc` project may require '-DCUDAToolkit_ROOT' in GPU mode.
-    if(CUDAToolkit_ROOT)
-      list(APPEND libc_cmake_args "-DCUDAToolkit_ROOT=${CUDAToolkit_ROOT}")
-    endif()
     if(TARGET clang-offload-packager)
       list(APPEND extra_deps clang-offload-packager)
     endif()
@@ -510,17 +515,18 @@ if(build_runtimes)
   if(LLVM_LIBC_FULL_BUILD)
     list(APPEND libc_cmake_args "-DLLVM_LIBC_FULL_BUILD=ON")
   endif()
+
   if(NOT LLVM_RUNTIME_TARGETS)
     runtime_default_target(
       DEPENDS ${builtins_dep} ${extra_deps}
-      CMAKE_ARGS ${libc_cmake_args}
+      CMAKE_ARGS ${extra_cmake_args} ${libc_cmake_args}
       PREFIXES ${prefixes})
     set(test_targets check-runtimes)
   else()
     if("default" IN_LIST LLVM_RUNTIME_TARGETS)
       runtime_default_target(
         DEPENDS ${builtins_dep} ${extra_deps}
-        CMAKE_ARGS ${libc_cmake_args}
+        CMAKE_ARGS ${extra_cmake_args} ${libc_cmake_args}
         PREFIXES ${prefixes})
       list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
     else()
@@ -567,7 +573,7 @@ if(build_runtimes)
 
       runtime_register_target(${name}
         DEPENDS ${builtins_dep_name} ${extra_deps}
-        CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
+        CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${extra_cmake_args} ${libc_cmake_args}
         EXTRA_ARGS TARGET_TRIPLE ${name})
     endforeach()
 



More information about the llvm-commits mailing list