-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libcxx] Add necessary compile flags for targeting the GPU #99333
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-libcxx Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/99333.diff 1 Files Affected:
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 190a97db9462f..a72e5aca0903f 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -491,6 +491,15 @@ include(HandleLibcxxFlags)
# 'config-ix' use them during feature checks. It also adds them to both
# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'
+# Targeting the GPU requires a clang compiler and several extra flags.
+if (${LLVM_RUNTIMES_TARGET} MATCHES "^amdgcn")
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
+ add_flags("-nogpulib" "-flto" "-fconvergent-functions" "-Xclang" "-mcode-object-version=none")
+elseif (${LLVM_RUNTIMES_TARGET} MATCHES "^nvptx")
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
+ add_flags("-nogpulib" "-flto" "-fconvergent-functions" "--cuda-feature=+ptx63")
+endif()
+
if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
add_flags_if_supported("-mdefault-visibility-export-mapping=explicit")
set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF)
|
Summary: This patch adds a CMake cache config file for the GPU build. This cache will set the default required options when used from the LLVM runtime interface or directly. These options pretty much disable everything the GPU can't handle. With this and the fllowing patches: llvm#99259, llvm#99243, llvm#99287, and llvm#99333, we will be able to build `libc++` targeting the GPU with an invocation like this. ``` $ cmake ../llvm -C${LLVM_ROOT}/libcxx/cmake/caches/GPU.cmake \ -DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DLLVM_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda \ ``` This will then install the libraries and headers into the appropriate locations for use with `clang`.
Ping |
libcxx/CMakeLists.txt
Outdated
@@ -491,6 +491,15 @@ include(HandleLibcxxFlags) | |||
# 'config-ix' use them during feature checks. It also adds them to both | |||
# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' | |||
|
|||
# Targeting the GPU requires a clang compiler and several extra flags. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does Clang require -nogpulib
? Don't we already pass -nodefaultlibs
?
Also, why -flto
?
We should set this in the CMake caches -- we don't want to add any more target-specific flags in our CMake files, this is too messy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-nogpulib
is separate, it controls whether or not the GPU toolchain pulls in external vendor libraries.
-flto
is 100% required because GPUs have almost no backwards compatibility, so unless you want to build libc++
over 30 times you need to use LLVM-IR + LTO to defer creating object code until it's linked into the user's application. Also ELF linking isn't supported at all for AMDGPU.
I can move this bit to the CMake cache, but CMAKE_REQUIRED_FLAGS
might need to stay, otherwise check_cxx_flags
will not work.
Summary: The GPU target will always be a sufficiently new `clang`, so we can assume these flags are present. We need to first set `CMAKE_REQUIRED_FLAGS` to these values so that the `check_cxx_compile_flag` utilities work. Then, we need to add several things to the compiler flags that are necessary for correctness and optimal code output.
Seems I can do this in the cache like you said, will update that shortly. |
Summary: This patch adds a CMake cache config file for the GPU build. This cache will set the default required options when used from the LLVM runtime interface or directly. These options pretty much disable everything the GPU can't handle. With this and the fllowing patches: llvm#99259, llvm#99243, llvm#99287, and llvm#99333, we will be able to build `libc++` targeting the GPU with an invocation like this. ``` $ cmake ../llvm -C${LLVM_ROOT}/libcxx/cmake/caches/GPU.cmake \ -DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DLLVM_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda \ ``` This will then install the libraries and headers into the appropriate locations for use with `clang`.
Summary: This patch adds a CMake cache config file for the GPU build. This cache will set the default required options when used from the LLVM runtime interface or directly. These options pretty much disable everything the GPU can't handle. With this and the fllowing patches: llvm#99259, llvm#99243, llvm#99287, and llvm#99333, we will be able to build `libc++` targeting the GPU with an invocation like this. ``` $ cmake ../llvm -C${LLVM_ROOT}/libcxx/cmake/caches/GPU.cmake \ -DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DLLVM_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda \ ``` This will then install the libraries and headers into the appropriate locations for use with `clang`.
Summary: This patch adds a CMake cache config file for the GPU build. This cache will set the default required options when used from the LLVM runtime interface or directly. These options pretty much disable everything the GPU can't handle. With this and the fllowing patches: llvm#99259, llvm#99243, llvm#99287, and llvm#99333, we will be able to build `libc++` targeting the GPU with an invocation like this. ``` $ cmake ../llvm -C${LLVM_ROOT}/libcxx/cmake/caches/GPU.cmake \ -DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DLLVM_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda \ ``` This will then install the libraries and headers into the appropriate locations for use with `clang`.
Summary: This patch adds a CMake cache config file for the GPU build. This cache will set the default required options when used from the LLVM runtime interface or directly. These options pretty much disable everything the GPU can't handle. With this and the fllowing patches: llvm#99259, llvm#99243, llvm#99287, and llvm#99333, we will be able to build `libc++` targeting the GPU with an invocation like this. ``` $ cmake ../llvm -C${LLVM_ROOT}/libcxx/cmake/caches/GPU.cmake \ -DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DLLVM_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda \ ``` This will then install the libraries and headers into the appropriate locations for use with `clang`. Move to separate files
Summary: This patch adds a CMake cache config file for the GPU build. This cache will set the default required options when used from the LLVM runtime interface or directly. These options pretty much disable everything the GPU can't handle. With this and the fllowing patches: llvm#99259, llvm#99243, llvm#99287, and llvm#99333, we will be able to build `libc++` targeting the GPU with an invocation like this. ``` $ cmake ../llvm -C${LLVM_ROOT}/libcxx/cmake/caches/GPU.cmake \ -DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DLLVM_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda \ ``` This will then install the libraries and headers into the appropriate locations for use with `clang`.
Summary: This patch adds a CMake cache config file for the GPU build. This cache will set the default required options when used from the LLVM runtime interface or directly. These options pretty much disable everything the GPU can't handle. With this and the following patches: #99259, #99243, #99287, and #99333, we will be able to build `libc++` targeting the GPU with an invocation like this. ``` $ cmake ../llvm -DRUNTIMES_nvptx64-nvidia-cuda_CACHE_FILES=${LLVM_SRC}/../libcxx/cmake/caches/NVPTX.cmake \ -DRUNTIMES_amdgcn-amd-amdhsa_CACHE_FILES=${LLVM_SRC}/../libcxx/cmake/caches/AMDGPU.cmake \ -DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DLLVM_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda \ ``` This will then install the libraries and headers into the appropriate locations for use with `clang`.
Summary: This patch adds a CMake cache config file for the GPU build. This cache will set the default required options when used from the LLVM runtime interface or directly. These options pretty much disable everything the GPU can't handle. With this and the following patches: llvm#99259, llvm#99243, llvm#99287, and llvm#99333, we will be able to build `libc++` targeting the GPU with an invocation like this. ``` $ cmake ../llvm -DRUNTIMES_nvptx64-nvidia-cuda_CACHE_FILES=${LLVM_SRC}/../libcxx/cmake/caches/NVPTX.cmake \ -DRUNTIMES_amdgcn-amd-amdhsa_CACHE_FILES=${LLVM_SRC}/../libcxx/cmake/caches/AMDGPU.cmake \ -DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=compiler-rt;libc;libcxx \ -DLLVM_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda \ ``` This will then install the libraries and headers into the appropriate locations for use with `clang`.
Summary:
The GPU target will always be a sufficiently new
clang
, so we canassume these flags are present. We need to first set
CMAKE_REQUIRED_FLAGS
to these values so that thecheck_cxx_compile_flag
utilities work. Then, we need to add severalthings to the compiler flags that are necessary for correctness and
optimal code output.