https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/174022
>From 65da21f8ccbee951675fb0880bbc3bbcaa3d4f97 Mon Sep 17 00:00:00 2001 From: Joseph Huber <[email protected]> Date: Tue, 6 Jan 2026 09:41:00 -0600 Subject: [PATCH] [libclc] Initial support for cross-compiling OpenCL libraries Summary: The other GPU enabled libraries, (openmp, flang-rt, compiler-rt, libc, libcxx, libcxx-abi) all support builds through a runtime cross-build. In these builds we use a separate CMake build that cross-compiles to a single target. This patch provides basic support for this with the libclc libraries. Changes include adding support for the more standard GPU compute triples (amdgcn-amd-amdhsa, nvptx64-nvidia-cuda) and building only one target in this mode. Some things left to do: This patch does not change the compiler invocations, this method would allow us to use standard CMake routines but this keeps it minimal. The prebuild support is questionable and doesn't fit into this scheme because it's a host executable, I'm ignoring it for now. The installed location should just use the triple with no libclc/ subdirectory handling I believe. --- libclc/CMakeLists.txt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 52babf98075fc..fbdba78cc29d6 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -38,7 +38,12 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS set( LIBCLC_MIN_LLVM 3.9.0 ) -set( LIBCLC_TARGETS_TO_BUILD "all" +# A runtimes cross-build should only use the requested target. +set( LIBCLC_DEFAULT_TARGET "all" ) +if( LLVM_RUNTIMES_BUILD AND LLVM_DEFAULT_TARGET_TRIPLE MATCHES "^nvptx|^amdgcn" ) + set( LIBCLC_DEFAULT_TARGET ${LLVM_DEFAULT_TARGET_TRIPLE} ) +endif() +set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_DEFAULT_TARGET} CACHE STRING "Semicolon-separated list of libclc targets to build, or 'all'." ) option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF ) @@ -82,7 +87,10 @@ else() # In-tree configuration set( LIBCLC_STANDALONE_BUILD FALSE ) - set( LLVM_PACKAGE_VERSION ${LLVM_VERSION} ) + if( NOT LLVM_PACKAGE_VERSION ) + set( LLVM_PACKAGE_VERSION ${LLVM_VERSION} ) + endif() + set( PACKAGE_VERSION ${LLVM_PACKAGE_VERSION} ) # Note that we check this later (for both build types) but we can provide a # more useful error message when built in-tree. We assume that LLVM tools are @@ -154,6 +162,7 @@ set( LIBCLC_TARGETS_ALL r600-- nvptx64-- nvptx64--nvidiacl + nvptx64-nvidia-cuda ) # The mesa3d environment is only available since LLVM 4.0 @@ -205,6 +214,7 @@ set( clspv--_devices none ) set( clspv64--_devices none ) set( nvptx64--_devices none ) set( nvptx64--nvidiacl_devices none ) +set( nvptx64-nvidia-cuda_devices none ) set( spirv-mesa3d-_devices none ) set( spirv64-mesa3d-_devices none ) @@ -307,6 +317,9 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) else() set( DARCH ${ARCH} ) endif() + if ( "${OS}" STREQUAL cuda ) + set( DOS nvidiacl ) + endif() # Append a variety of target- and triple-based directories to search, # increasing in specificity. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
