[llvm] af478c8 - [offload][runtimes] Forward user-provided system configuration (#96303)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 21 10:49:43 PDT 2024
Author: Michael Kruse
Date: 2024-06-21T19:49:40+02:00
New Revision: af478c82a5f6e42ff5d1e67dcefbf9dd0fee501c
URL: https://github.com/llvm/llvm-project/commit/af478c82a5f6e42ff5d1e67dcefbf9dd0fee501c
DIFF: https://github.com/llvm/llvm-project/commit/af478c82a5f6e42ff5d1e67dcefbf9dd0fee501c.diff
LOG: [offload][runtimes] Forward user-provided system configuration (#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 such
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_PATH` is used by
`find_package(CUDAToolkit)` and `enable_language(CUDA)`).
Added:
Modified:
llvm/runtimes/CMakeLists.txt
Removed:
################################################################################
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index e60c9dd6041b4..029b6a73674a1 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")
@@ -478,49 +487,46 @@ if(build_runtimes)
if(NOT hdrgen_exe)
message(FATAL_ERROR "libc-hdrgen executable missing")
endif()
- list(APPEND libc_cmake_args "-DLIBC_HDRGEN_EXE=${hdrgen_exe}")
+ list(APPEND extra_cmake_args "-DLIBC_HDRGEN_EXE=${hdrgen_exe}")
list(APPEND extra_deps ${hdrgen_deps})
endif()
if(LLVM_LIBC_GPU_BUILD)
- list(APPEND libc_cmake_args "-DLLVM_LIBC_GPU_BUILD=ON")
+ list(APPEND extra_cmake_args "-DLLVM_LIBC_GPU_BUILD=ON")
if("libc" IN_LIST RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES)
if(TARGET amdhsa-loader)
- list(APPEND libc_cmake_args
+ list(APPEND extra_cmake_args
"-DRUNTIMES_amdgcn-amd-amdhsa_LIBC_GPU_LOADER_EXECUTABLE=$<TARGET_FILE:amdhsa-loader>")
list(APPEND extra_deps amdhsa-loader amdgpu-arch)
endif()
- list(APPEND libc_cmake_args "-DRUNTIMES_amdgcn-amd-amdhsa_LLVM_LIBC_FULL_BUILD=ON")
+ list(APPEND extra_cmake_args "-DRUNTIMES_amdgcn-amd-amdhsa_LLVM_LIBC_FULL_BUILD=ON")
endif()
if("libc" IN_LIST RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES)
if(TARGET nvptx-loader)
- list(APPEND libc_cmake_args
+ list(APPEND extra_cmake_args
"-DRUNTIMES_nvptx64-nvidia-cuda_LIBC_GPU_LOADER_EXECUTABLE=$<TARGET_FILE:nvptx-loader>")
list(APPEND extra_deps nvptx-loader nvptx-arch)
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}")
+ list(APPEND extra_cmake_args "-DRUNTIMES_nvptx64-nvidia-cuda_LLVM_LIBC_FULL_BUILD=ON")
endif()
if(TARGET clang-offload-packager)
list(APPEND extra_deps clang-offload-packager)
endif()
endif()
if(LLVM_LIBC_FULL_BUILD)
- list(APPEND libc_cmake_args "-DLLVM_LIBC_FULL_BUILD=ON")
+ list(APPEND extra_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}
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}
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}
EXTRA_ARGS TARGET_TRIPLE ${name})
endforeach()
More information about the llvm-commits
mailing list