Skip to content

Commit

Permalink
[libc][gpu][NFC] Move CMake logic to prepare GPU build to a separate …
Browse files Browse the repository at this point in the history
…file.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D140309
  • Loading branch information
Siva Chandra Reddy committed Dec 19, 2022
1 parent 6a907a4 commit 8d68195
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
18 changes: 2 additions & 16 deletions libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,15 @@ option(LLVM_LIBC_FULL_BUILD "Build and test LLVM libc as if it is the full libc"
option(LLVM_LIBC_IMPLEMENTATION_DEFINED_TEST_BEHAVIOR "Build LLVM libc tests assuming our implementation-defined behavior" ON)
option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" OFF)

# Set up the target architectures to build for the GPU
set(ALL_GPU_ARCHITECTURES "sm_35;sm_37;sm_50;sm_52;sm_53;sm_60;sm_61;sm_62;sm_70;sm_72;sm_75;sm_80;sm_86;gfx700;gfx701;gfx801;gfx803;gfx900;gfx902;gfx906;gfx908;gfx90a;gfx90c;gfx940;gfx1010;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103")
set(LLVM_LIBC_GPU_ARCHITECTURES ${ALL_GPU_ARCHITECTURES} CACHE STRING "List of GPU architectures to support in LLVM libc")
if (LLVM_LIBC_GPU_ARCHITECTURES STREQUAL "all")
set(LIBC_GPU_ARCHITECTURES ${ALL_GPU_ARCHITECTURES})
else()
set(LIBC_GPU_ARCHITECTURES ${LLVM_LIBC_GPU_ARCHITECTURES})
endif()

set(LLVM_LIBC_TARGET_OS ${CMAKE_SYSTEM_NAME} CACHE STRING "Target operating system for LLVM libc")
string(TOLOWER ${LLVM_LIBC_TARGET_OS} LIBC_TARGET_OS)

# Defines LIBC_TARGET_ARCHITECTURE and associated macros.
include(LLVMLibCArchitectures)
include(LLVMLibCCheckMPFR)

# Ensure the compiler is a valid clang when building the GPU target.
if(LIBC_TARGET_ARCHITECTURE_IS_GPU AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" AND
${CMAKE_CXX_COMPILER_VERSION} VERSION_EQUAL "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}"))
message(FATAL_ERROR "Cannot build GPU library, CMake compiler '${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}' is not `Clang ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}`")
endif()
if(LIBC_TARGET_ARCHITECTURE_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
message(FATAL_ERROR "Cannot build GPU library, LLVM_LIBC_FULL_BUILD must be enabled")
if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
include(prepare_libc_gpu_build)
endif()

if(LLVM_LIBC_CLANG_TIDY)
Expand Down
26 changes: 26 additions & 0 deletions libc/cmake/modules/prepare_libc_gpu_build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Set up the target architectures to build the GPU libc for.
set(all_gpu_architectures "sm_35;sm_37;sm_50;sm_52;sm_53;sm_60;sm_61;sm_62;"
"sm_70;sm_72;sm_75;sm_80;sm_86;gfx700;gfx701;gfx801;"
"gfx803;gfx900;gfx902;gfx906;gfx908;gfx90a;gfx90c;"
"gfx940;gfx1010;gfx1030;gfx1031;gfx1032;gfx1033;"
"gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;"
"gfx1103")
set(LIBC_GPU_ARCHITECTURES ${all_gpu_architectures} CACHE STRING
"List of GPU architectures to build the libc for.")
if(LIBC_GPU_ARCHITECTURES STREQUAL "all")
set(LIBC_GPU_ARCHITECTURES ${all_gpu_architectures} FORCE)
endif()

# Ensure the compiler is a valid clang when building the GPU target.
set(req_ver "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
if(LIBC_TARGET_ARCHITECTURE_IS_GPU AND
NOT (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" AND
${CMAKE_CXX_COMPILER_VERSION} VERSION_EQUAL "${req_ver}"))
message(FATAL_ERROR "Cannot build libc for GPU. CMake compiler "
"'${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}' "
" is not `Clang ${req_ver}.")
endif()
if(LLVM_LIBC_FULL_BUILD)
message(FATAL_ERROR "LLVM_LIBC_FULL_BUILD must be enabled to build libc for "
"GPU.")
endif()

0 comments on commit 8d68195

Please sign in to comment.