Skip to content

Commit af478c8

Browse files
authored
[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)`).
1 parent 918ef31 commit af478c8

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

llvm/runtimes/CMakeLists.txt

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,6 @@ foreach(entry ${runtimes})
204204
if(canon_name STREQUAL "LIBC")
205205
list(APPEND prefixes "LLVM_LIBC")
206206
list(APPEND prefixes "LIBC_")
207-
# The `libc` project may require '-DCUDAToolkit_ROOT' in GPU mode.
208-
if(LLVM_LIBC_GPU_BUILD)
209-
list(APPEND prefixes "CUDA")
210-
endif()
211207
endif()
212208

213209
_get_runtime_name(${name} name)
@@ -261,6 +257,7 @@ function(runtime_default_target)
261257
${ARG_CMAKE_ARGS}
262258
PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
263259
LLVM_USE_LINKER
260+
CUDA # For runtimes that may look for the CUDA SDK (libc, offload)
264261
${ARG_PREFIXES}
265262
EXTRA_TARGETS ${extra_targets}
266263
${test_targets}
@@ -445,6 +442,18 @@ if(build_runtimes)
445442
# The runtimes target is a configuration of all the runtime libraries
446443
# together in a single CMake invocation.
447444
set(extra_deps "")
445+
set(extra_cmake_args "")
446+
447+
# Forward user-provived system configuration to runtimes for requirement introspection.
448+
# CMAKE_PREFIX_PATH is the search path for CMake packages.
449+
if(CMAKE_PREFIX_PATH)
450+
list(APPEND extra_cmake_args "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}")
451+
endif()
452+
# CMAKE_PROGRAM_PATH is the search path for executables such as python.
453+
if(CMAKE_PROGRAM_PATH)
454+
list(APPEND extra_cmake_args "-DCMAKE_PROGRAM_PATH=${CMAKE_PROGRAM_PATH}")
455+
endif()
456+
448457
if("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)
449458
if (${LLVM_TOOL_FLANG_BUILD})
450459
message(STATUS "Configuring build of omp_lib.mod and omp_lib_kinds.mod via flang-new")
@@ -478,49 +487,46 @@ if(build_runtimes)
478487
if(NOT hdrgen_exe)
479488
message(FATAL_ERROR "libc-hdrgen executable missing")
480489
endif()
481-
list(APPEND libc_cmake_args "-DLIBC_HDRGEN_EXE=${hdrgen_exe}")
490+
list(APPEND extra_cmake_args "-DLIBC_HDRGEN_EXE=${hdrgen_exe}")
482491
list(APPEND extra_deps ${hdrgen_deps})
483492
endif()
484493
if(LLVM_LIBC_GPU_BUILD)
485-
list(APPEND libc_cmake_args "-DLLVM_LIBC_GPU_BUILD=ON")
494+
list(APPEND extra_cmake_args "-DLLVM_LIBC_GPU_BUILD=ON")
486495
if("libc" IN_LIST RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES)
487496
if(TARGET amdhsa-loader)
488-
list(APPEND libc_cmake_args
497+
list(APPEND extra_cmake_args
489498
"-DRUNTIMES_amdgcn-amd-amdhsa_LIBC_GPU_LOADER_EXECUTABLE=$<TARGET_FILE:amdhsa-loader>")
490499
list(APPEND extra_deps amdhsa-loader amdgpu-arch)
491500
endif()
492-
list(APPEND libc_cmake_args "-DRUNTIMES_amdgcn-amd-amdhsa_LLVM_LIBC_FULL_BUILD=ON")
501+
list(APPEND extra_cmake_args "-DRUNTIMES_amdgcn-amd-amdhsa_LLVM_LIBC_FULL_BUILD=ON")
493502
endif()
494503
if("libc" IN_LIST RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES)
495504
if(TARGET nvptx-loader)
496-
list(APPEND libc_cmake_args
505+
list(APPEND extra_cmake_args
497506
"-DRUNTIMES_nvptx64-nvidia-cuda_LIBC_GPU_LOADER_EXECUTABLE=$<TARGET_FILE:nvptx-loader>")
498507
list(APPEND extra_deps nvptx-loader nvptx-arch)
499508
endif()
500-
list(APPEND libc_cmake_args "-DRUNTIMES_nvptx64-nvidia-cuda_LLVM_LIBC_FULL_BUILD=ON")
501-
endif()
502-
# The `libc` project may require '-DCUDAToolkit_ROOT' in GPU mode.
503-
if(CUDAToolkit_ROOT)
504-
list(APPEND libc_cmake_args "-DCUDAToolkit_ROOT=${CUDAToolkit_ROOT}")
509+
list(APPEND extra_cmake_args "-DRUNTIMES_nvptx64-nvidia-cuda_LLVM_LIBC_FULL_BUILD=ON")
505510
endif()
506511
if(TARGET clang-offload-packager)
507512
list(APPEND extra_deps clang-offload-packager)
508513
endif()
509514
endif()
510515
if(LLVM_LIBC_FULL_BUILD)
511-
list(APPEND libc_cmake_args "-DLLVM_LIBC_FULL_BUILD=ON")
516+
list(APPEND extra_cmake_args "-DLLVM_LIBC_FULL_BUILD=ON")
512517
endif()
518+
513519
if(NOT LLVM_RUNTIME_TARGETS)
514520
runtime_default_target(
515521
DEPENDS ${builtins_dep} ${extra_deps}
516-
CMAKE_ARGS ${libc_cmake_args}
522+
CMAKE_ARGS ${extra_cmake_args}
517523
PREFIXES ${prefixes})
518524
set(test_targets check-runtimes)
519525
else()
520526
if("default" IN_LIST LLVM_RUNTIME_TARGETS)
521527
runtime_default_target(
522528
DEPENDS ${builtins_dep} ${extra_deps}
523-
CMAKE_ARGS ${libc_cmake_args}
529+
CMAKE_ARGS ${extra_cmake_args}
524530
PREFIXES ${prefixes})
525531
list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
526532
else()
@@ -567,7 +573,7 @@ if(build_runtimes)
567573

568574
runtime_register_target(${name}
569575
DEPENDS ${builtins_dep_name} ${extra_deps}
570-
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
576+
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${extra_cmake_args}
571577
EXTRA_ARGS TARGET_TRIPLE ${name})
572578
endforeach()
573579

0 commit comments

Comments
 (0)