Skip to content

Commit bd6df0f

Browse files
authored
Reapply "[LLVM] Make the GPU loader utilities an LLVM tool (llvm#132096)" (llvm#132277)
Summary: There were a few issues with the first one, leading to some errors and warnings. Most importantly, this was building on MSVC which isn't supported.
1 parent 4a2ab3a commit bd6df0f

File tree

15 files changed

+228
-236
lines changed

15 files changed

+228
-236
lines changed

libc/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ set(LIBC_NAMESPACE ${default_namespace}
5959
CACHE STRING "The namespace to use to enclose internal implementations. Must start with '__llvm_libc'."
6060
)
6161

62-
# We will build the GPU utilities if we are not doing a runtimes build.
63-
option(LIBC_BUILD_GPU_LOADER "Always build the GPU loader utilities" OFF)
64-
if(LIBC_BUILD_GPU_LOADER OR ((NOT LLVM_RUNTIMES_BUILD) AND LLVM_LIBC_GPU_BUILD))
65-
add_subdirectory(utils/gpu)
66-
return()
67-
endif()
68-
6962
option(LIBC_CMAKE_VERBOSE_LOGGING
7063
"Log details warnings and notifications during CMake configuration." OFF)
7164

libc/src/__support/RPC/rpc_server.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
#define __has_builtin(x) 0
2121
#endif
2222

23+
// Workaround for missing __builtin_is_constant_evaluated in < GCC 10.
24+
#ifndef __builtin_is_constant_evaluated
25+
#define __builtin_is_constant_evaluated(x) 0
26+
#endif
27+
2328
// Configs for using the LLVM libc writer interface.
2429
#define LIBC_COPT_USE_C_ASSERT
2530
#define LIBC_COPT_MEMCPY_USE_EMBEDDED_TINY
@@ -28,7 +33,7 @@
2833
#define LIBC_COPT_PRINTF_DISABLE_INDEX_MODE
2934
#define LIBC_COPT_PRINTF_DISABLE_STRERROR
3035

31-
// The 'long double' type is 8 byte
36+
// The 'long double' type is 8 bytes.
3237
#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
3338

3439
#include "shared/rpc.h"

libc/utils/gpu/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

libc/utils/gpu/loader/CMakeLists.txt

Lines changed: 0 additions & 54 deletions
This file was deleted.

libc/utils/gpu/loader/amdgpu/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

libc/utils/gpu/loader/nvptx/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

llvm/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,6 @@ if("${LIBC_TARGET_TRIPLE}" STREQUAL "amdgcn-amd-amdhsa" OR
210210
"${LIBC_TARGET_TRIPLE}" STREQUAL "nvptx64-nvidia-cuda")
211211
set(LLVM_LIBC_GPU_BUILD ON)
212212
endif()
213-
if (NOT "libc" IN_LIST LLVM_ENABLE_PROJECTS AND LLVM_LIBC_GPU_BUILD)
214-
message(STATUS "Enabling libc project to build libc testing tools")
215-
list(APPEND LLVM_ENABLE_PROJECTS "libc")
216-
endif()
217213

218214
# LLVM_ENABLE_PROJECTS_USED is `ON` if the user has ever used the
219215
# `LLVM_ENABLE_PROJECTS` CMake cache variable. This exists for

llvm/runtimes/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -534,20 +534,6 @@ if(build_runtimes)
534534
endif()
535535
if(LLVM_LIBC_GPU_BUILD)
536536
list(APPEND extra_cmake_args "-DLLVM_LIBC_GPU_BUILD=ON")
537-
if("libc" IN_LIST RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES)
538-
if(TARGET amdhsa-loader)
539-
list(APPEND extra_cmake_args
540-
"-DRUNTIMES_amdgcn-amd-amdhsa_LIBC_GPU_LOADER_EXECUTABLE=$<TARGET_FILE:amdhsa-loader>")
541-
list(APPEND extra_deps amdhsa-loader)
542-
endif()
543-
endif()
544-
if("libc" IN_LIST RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES)
545-
if(TARGET nvptx-loader)
546-
list(APPEND extra_cmake_args
547-
"-DRUNTIMES_nvptx64-nvidia-cuda_LIBC_GPU_LOADER_EXECUTABLE=$<TARGET_FILE:nvptx-loader>")
548-
list(APPEND extra_deps nvptx-loader)
549-
endif()
550-
endif()
551537
if(TARGET clang-offload-packager)
552538
list(APPEND extra_deps clang-offload-packager)
553539
endif()

llvm/tools/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
# traversing each directory.
1010
create_llvm_tool_options()
1111

12+
if(NOT LLVM_COMPILER_IS_GCC_COMPATIBLE)
13+
set(LLVM_TOOL_LLVM_GPU_LOADER_BUILD OFF)
14+
endif()
15+
1216
if(NOT LLVM_BUILD_LLVM_DYLIB AND NOT LLVM_BUILD_LLVM_C_DYLIB)
1317
set(LLVM_TOOL_LLVM_SHLIB_BUILD Off)
1418
endif()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
set(LLVM_LINK_COMPONENTS
2+
BinaryFormat
3+
Object
4+
Option
5+
Support
6+
FrontendOffloading
7+
TargetParser
8+
)
9+
10+
add_llvm_tool(llvm-gpu-loader
11+
llvm-gpu-loader.cpp
12+
13+
# TODO: We intentionally split this currently due to statically linking the
14+
# GPU runtimes. Dynamically load the dependencies, possibly using the
15+
# LLVM offloading API when it is complete.
16+
PARTIAL_SOURCES_INTENDED
17+
18+
DEPENDS
19+
intrinsics_gen
20+
)
21+
22+
# Locate the RPC server handling interface.
23+
include(FindLibcCommonUtils)
24+
target_link_libraries(llvm-gpu-loader PUBLIC llvm-libc-common-utilities)
25+
26+
# Check for HSA support for targeting AMD GPUs.
27+
find_package(hsa-runtime64 QUIET 1.2.0 HINTS ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm)
28+
if(hsa-runtime64_FOUND)
29+
target_sources(llvm-gpu-loader PRIVATE amdhsa.cpp)
30+
target_compile_definitions(llvm-gpu-loader PRIVATE AMDHSA_SUPPORT)
31+
target_link_libraries(llvm-gpu-loader PRIVATE hsa-runtime64::hsa-runtime64)
32+
33+
# Compatibility with the old amdhsa-loader name.
34+
add_llvm_tool_symlink(amdhsa-loader llvm-gpu-loader)
35+
endif()
36+
37+
# Check for CUDA support for targeting NVIDIA GPUs.
38+
find_package(CUDAToolkit 11.2 QUIET)
39+
if(CUDAToolkit_FOUND)
40+
target_sources(llvm-gpu-loader PRIVATE nvptx.cpp)
41+
target_compile_definitions(llvm-gpu-loader PRIVATE NVPTX_SUPPORT)
42+
target_link_libraries(llvm-gpu-loader PRIVATE CUDA::cuda_driver)
43+
44+
# Compatibility with the old nvptx-loader name.
45+
add_llvm_tool_symlink(nvptx-loader llvm-gpu-loader)
46+
endif()

0 commit comments

Comments
 (0)