-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Configure CMAKE_REQUIRED_FLAGS so the GPU can use flag checks #95424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-libc Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/95424.diff 2 Files Affected:
diff --git a/libc/cmake/modules/prepare_libc_gpu_build.cmake b/libc/cmake/modules/prepare_libc_gpu_build.cmake
index dc8beb14fd7f4..f1275e34a42e8 100644
--- a/libc/cmake/modules/prepare_libc_gpu_build.cmake
+++ b/libc/cmake/modules/prepare_libc_gpu_build.cmake
@@ -16,6 +16,17 @@ if(NOT LLVM_LIBC_FULL_BUILD)
"GPU.")
endif()
+# Set the required flags globally so standard CMake utilities can compile.
+if(LIBC_TARGET_TRIPLE)
+ set(CMAKE_REQUIRED_FLAGS "--target=${explicit_target_triple}")
+endif()
+if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
+elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
+ set(CMAKE_REQUIRED_FLAGS
+ "${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
+endif()
+
# Identify the program used to package multiple images into a single binary.
get_filename_component(compiler_path ${CMAKE_CXX_COMPILER} DIRECTORY)
if(TARGET clang-offload-packager)
@@ -56,39 +67,9 @@ endif()
set(LIBC_GPU_TEST_ARCHITECTURE "" CACHE STRING "Architecture for the GPU tests")
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
- # Identify any locally installed AMD GPUs on the system using 'amdgpu-arch'.
- if(TARGET amdgpu-arch)
- get_target_property(LIBC_AMDGPU_ARCH amdgpu-arch LOCATION)
- else()
- find_program(LIBC_AMDGPU_ARCH
- NAMES amdgpu-arch NO_DEFAULT_PATH
- PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
- endif()
- if(LIBC_AMDGPU_ARCH)
- execute_process(COMMAND ${LIBC_AMDGPU_ARCH}
- OUTPUT_VARIABLE arch_tool_output
- ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
- if(arch_tool_output MATCHES "^gfx[0-9]+")
- set(PLATFORM_HAS_GPU TRUE)
- endif()
- endif()
+ check_cxx_compiler_flag(-mcpu=native PLATFORM_HAS_GPU)
elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
- # Identify any locally installed NVIDIA GPUs on the system using 'nvptx-arch'.
- if(TARGET nvptx-arch)
- get_target_property(LIBC_NVPTX_ARCH nvptx-arch LOCATION)
- else()
- find_program(LIBC_NVPTX_ARCH
- NAMES nvptx-arch NO_DEFAULT_PATH
- PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
- endif()
- if(LIBC_NVPTX_ARCH)
- execute_process(COMMAND ${LIBC_NVPTX_ARCH}
- OUTPUT_VARIABLE arch_tool_output
- ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
- if(arch_tool_output MATCHES "^sm_[0-9]+")
- set(PLATFORM_HAS_GPU TRUE)
- endif()
- endif()
+ check_cxx_compiler_flag(-march=native PLATFORM_HAS_GPU)
endif()
set(gpu_test_architecture "")
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index e60c9dd6041b4..b6ed497fa122a 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -487,7 +487,7 @@ if(build_runtimes)
if(TARGET amdhsa-loader)
list(APPEND libc_cmake_args
"-DRUNTIMES_amdgcn-amd-amdhsa_LIBC_GPU_LOADER_EXECUTABLE=$<TARGET_FILE:amdhsa-loader>")
- list(APPEND extra_deps amdhsa-loader amdgpu-arch)
+ list(APPEND extra_deps amdhsa-loader)
endif()
list(APPEND libc_cmake_args "-DRUNTIMES_amdgcn-amd-amdhsa_LLVM_LIBC_FULL_BUILD=ON")
endif()
@@ -495,7 +495,7 @@ if(build_runtimes)
if(TARGET nvptx-loader)
list(APPEND libc_cmake_args
"-DRUNTIMES_nvptx64-nvidia-cuda_LIBC_GPU_LOADER_EXECUTABLE=$<TARGET_FILE:nvptx-loader>")
- list(APPEND extra_deps nvptx-loader nvptx-arch)
+ list(APPEND extra_deps nvptx-loader)
endif()
list(APPEND libc_cmake_args "-DRUNTIMES_nvptx64-nvidia-cuda_LLVM_LIBC_FULL_BUILD=ON")
endif()
|
Summary: This patch adds `CMAKE_REQUIRED_FLAGS` for the GPU build so checks like `check_cxx_compiler_flags` work as expected. This is required because we need to hack around the potential lack of `nvlink` and `ptxas` for NVPTX targets and the fact that the AMDGPU target needs `-nogpulib` to avoid errors on lack of ROCm. This makes a few of the checks pass and also allows us to just check `-mcpu=native` for architecture detection instead of finding the tools manually.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/163/builds/585 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/586 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/496 Here is the relevant piece of the build log for the reference:
|
…lvm#95424) Summary: This patch adds `CMAKE_REQUIRED_FLAGS` for the GPU build so checks like `check_cxx_compiler_flags` work as expected. This is required because we need to hack around the potential lack of `nvlink` and `ptxas` for NVPTX targets and the fact that the AMDGPU target needs `-nogpulib` to avoid errors on lack of ROCm. This makes a few of the checks pass and also allows us to just check `-mcpu=native` for architecture detection instead of finding the tools manually.
Summary:
This patch adds
CMAKE_REQUIRED_FLAGS
for the GPU build so checks likecheck_cxx_compiler_flags
work as expected. This is required because weneed to hack around the potential lack of
nvlink
andptxas
for NVPTXtargets and the fact that the AMDGPU target needs
-nogpulib
to avoiderrors on lack of ROCm. This makes a few of the checks pass and also
allows us to just check
-mcpu=native
for architecture detectioninstead of finding the tools manually.