Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e07a118

Browse files
authored
[libc] Tweak the runtimes cross-build for GPU (#178548)
Summary: We should likely use `-DLLVM_DEFAULT_TARGET_TRIPLE` as the general source of truth, make the handling work with that since we use it for the output directories. Fix the creation of startup files in this mode and make sure it can detect the GPU properly. Fixes: #179375
1 parent 5587993 commit e07a118

3 files changed

Lines changed: 9 additions & 36 deletions

File tree

libc/cmake/modules/prepare_libc_gpu_build.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ if(NOT LLVM_LIBC_FULL_BUILD)
1717
endif()
1818

1919
# Set the required flags globally so standard CMake utilities can compile.
20-
if(LIBC_TARGET_TRIPLE)
21-
set(CMAKE_REQUIRED_FLAGS "--target=${LIBC_TARGET_TRIPLE}")
20+
if(NOT CMAKE_CXX_COMPILER_TARGET)
21+
set(CMAKE_REQUIRED_FLAGS "${LIBC_COMPILE_OPTIONS_DEFAULT}")
2222
endif()
2323

2424
# Optionally set up a job pool to limit the number of GPU tests run in parallel.

libc/docs/gpu/building.rst

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -100,47 +100,19 @@ targeting a GPU architecture.
100100
$> TARGET_C_COMPILER=</path/to/clang>
101101
$> TARGET_CXX_COMPILER=</path/to/clang++>
102102
$> cmake ../runtimes \ # Point to the runtimes build
103-
-G Ninja \
104-
-DLLVM_ENABLE_RUNTIMES=libc \
105-
-DCMAKE_C_COMPILER=$TARGET_C_COMPILER \
106-
-DCMAKE_CXX_COMPILER=$TARGET_CXX_COMPILER \
107-
-DLLVM_LIBC_FULL_BUILD=ON \
108-
-DLLVM_RUNTIMES_TARGET=$TARGET_TRIPLE \
103+
-G Ninja \
104+
-DLLVM_ENABLE_RUNTIMES=libc \
105+
-DCMAKE_C_COMPILER=$TARGET_C_COMPILER \
106+
-DCMAKE_CXX_COMPILER=$TARGET_CXX_COMPILER \
107+
-DLLVM_LIBC_FULL_BUILD=ON \
108+
-DLLVM_DEFAULT_TARGET_TRIPLE=$TARGET_TRIPLE \
109109
-DCMAKE_BUILD_TYPE=Release
110110
$> ninja install
111111
112112
The above steps will result in a build targeting one of the supported GPU
113113
architectures. Building for multiple targets requires separate CMake
114114
invocations.
115115

116-
Standalone cross build
117-
----------------------
118-
119-
The GPU build can also be targeted directly as long as the compiler used is a
120-
supported ``clang`` compiler. This method is generally not recommended as it can
121-
only target a single GPU architecture.
122-
123-
.. code-block:: sh
124-
125-
$> cd llvm-project # The llvm-project checkout
126-
$> mkdir build # A different build directory for the build tools
127-
$> cd build
128-
$> CLANG_C_COMPILER=</path/to/clang> # Must be a trunk build
129-
$> CLANG_CXX_COMPILER=</path/to/clang++> # Must be a trunk build
130-
$> TARGET_TRIPLE=<amdgcn-amd-amdhsa or nvptx64-nvidia-cuda>
131-
$> cmake ../llvm \ # Point to the llvm directory
132-
-G Ninja \
133-
-DLLVM_ENABLE_PROJECTS=libc \
134-
-DCMAKE_C_COMPILER=$CLANG_C_COMPILER \
135-
-DCMAKE_CXX_COMPILER=$CLANG_CXX_COMPILER \
136-
-DLLVM_LIBC_FULL_BUILD=ON \
137-
-DLIBC_TARGET_TRIPLE=$TARGET_TRIPLE \
138-
-DCMAKE_BUILD_TYPE=Release
139-
$> ninja install
140-
141-
This will build and install the GPU C library along with all the other LLVM
142-
libraries.
143-
144116
Build overview
145117
==============
146118

libc/startup/gpu/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function(add_startup_object name)
3434
RUNTIME_OUTPUT_DIRECTORY ${LIBC_LIBRARY_DIR}
3535
RUNTIME_OUTPUT_NAME ${name}.o)
3636
target_link_options(${fq_target_name}.exe PRIVATE
37+
${LIBC_COMPILE_OPTIONS_DEFAULT}
3738
"-r" "-nostdlib" "-flto" "-Wl,--lto-emit-llvm")
3839
endif()
3940
endfunction()

0 commit comments

Comments
 (0)