Skip to content

[libc] Fix the GPU build when building inside the NATIVE project #118573

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

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Dec 4, 2024

Summary:
We use the NATIVE directory for cross-compiling tools that need to be
run on the host. This was not forwarding the CMake arguments we used to
check if this was a GPU compile that created its own tools. Forward that
and simplify.

Fixes #118558

Summary:
We use the NATIVE directory for cross-compiling tools that need to be
run on the host. This was not forwarding the CMake arguments we used to
check if this was a GPU compile that created its own tools. Forward that
and simplify.

Fixes llvm#118558
@llvmbot llvmbot added cmake Build system in general and CMake in particular libc labels Dec 4, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 4, 2024

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

Changes

Summary:
We use the NATIVE directory for cross-compiling tools that need to be
run on the host. This was not forwarding the CMake arguments we used to
check if this was a GPU compile that created its own tools. Forward that
and simplify.

Fixes #118558


Full diff: https://github.com/llvm/llvm-project/pull/118573.diff

2 Files Affected:

  • (modified) libc/CMakeLists.txt (+3-16)
  • (modified) llvm/cmake/modules/CrossCompile.cmake (+3)
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index fd82359022cffd..11a355b1203602 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -52,22 +52,9 @@ set(LIBC_NAMESPACE ${default_namespace}
 
 # We will build the GPU utilities if we are not doing a runtimes build.
 option(LIBC_BUILD_GPU_LOADER "Always build the GPU loader utilities" OFF)
-if(LIBC_BUILD_GPU_LOADER OR NOT LLVM_RUNTIMES_BUILD)
-  foreach(_name ${LLVM_RUNTIME_TARGETS})
-    if("libc" IN_LIST RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
-      if("${_name}" STREQUAL "amdgcn-amd-amdhsa" OR "${_name}" STREQUAL "nvptx64-nvidia-cuda")
-        set(LIBC_NEED_LOADER_UTILS TRUE)
-      endif()
-    endif()
-  endforeach()
-  if("${LIBC_TARGET_TRIPLE}" STREQUAL "amdgcn-amd-amdhsa" OR
-     "${LIBC_TARGET_TRIPLE}" STREQUAL "nvptx64-nvidia-cuda")
-    set(LIBC_NEED_LOADER_UTILS TRUE)
-  endif()
-  if(LIBC_NEED_LOADER_UTILS)
-    add_subdirectory(utils/gpu)
-    return()
-  endif()
+if(LIBC_BUILD_GPU_LOADER OR ((NOT LLVM_RUNTIMES_BUILD) AND LLVM_LIBC_GPU_BUILD))
+  add_subdirectory(utils/gpu)
+  return()
 endif()
 
 add_subdirectory(newhdrgen)
diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake
index e36a71f522d82c..c22d185349dcc5 100644
--- a/llvm/cmake/modules/CrossCompile.cmake
+++ b/llvm/cmake/modules/CrossCompile.cmake
@@ -78,6 +78,9 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
       list(APPEND libc_flags -DLLVM_FORCE_BUILD_RUNTIME=ON)
     endif()
   endif()
+  if(LLVM_LIBC_GPU_BUILD)
+    list(APPEND libc_flags -DLLVM_LIBC_GPU_BUILD=ON)
+  endif()
 
   add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}/CMakeCache.txt
     COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for figuring this out!

Looks like there's some more references to LIBC_HDRGEN_EXE in llvm/cmake/modules/CrossCompile.cmake that can get cleaned up, too.

@jhuber6 jhuber6 merged commit 3dc9755 into llvm:main Dec 4, 2024
11 checks passed
@jhuber6
Copy link
Contributor Author

jhuber6 commented Dec 4, 2024

Not that this makes GPU build + project libc build not work, but I'm not too concerened because we're deprecating that anyways.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 5, 2024

LLVM Buildbot has detected a new failure on builder lld-x86_64-win running on as-worker-93 while building libc,llvm at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/146/builds/1763

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM-Unit :: Support/./SupportTests.exe/37/87' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe-LLVM-Unit-14912-37-87.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=87 GTEST_SHARD_INDEX=37 C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe
--

Script:
--
C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe --gtest_filter=ProgramEnvTest.CreateProcessLongPath
--
C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(160): error: Expected equality of these values:
  0
  RC
    Which is: -2

C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(163): error: fs::remove(Twine(LongPath)): did not return errc::success.
error number: 13
error message: permission denied



C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:160
Expected equality of these values:
  0
  RC
    Which is: -2

C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:163
fs::remove(Twine(LongPath)): did not return errc::success.
error number: 13
error message: permission denied




********************


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular libc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libc: fails to build with add_custom_target cannot create target "libc" because another target with the same name already exists
4 participants