[libclc] Enable LLVM_RUNTIME_TARGETS in build system (#189892) libclc target is now passed in from LLVM_RUNTIME_TARGETS. The old configure flow based on `-DLLVM_ENABLE_RUNTIMES=libclc` is deprecated because libclc no longer has a default target. `-DLLVM_ENABLE_RUNTIMES=libclc -DLLVM_RUNTIME_TARGETS="<target-triple>"` still works but it is considered legacy. The new standard build requires: Each target must now be selected explicitly on the CMake command line through the runtimes target-specific cache entry and LLVM_RUNTIME_TARGETS. For example: -DRUNTIMES_amdgcn-amd-amdhsa-llvm_LLVM_ENABLE_RUNTIMES=libclc -DLLVM_RUNTIME_TARGETS="amdgcn-amd-amdhsa-llvm" -DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=libclc -DLLVM_RUNTIME_TARGETS="nvptx64-nvidia-cuda" -DRUNTIMES_clspv--_LLVM_ENABLE_RUNTIMES=libclc -DLLVM_RUNTIME_TARGETS="clspv--" -DRUNTIMES_clspv64--_LLVM_ENABLE_RUNTIMES=libclc -DLLVM_RUNTIME_TARGETS="clspv64--" -DRUNTIMES_spirv-mesa3d-_LLVM_ENABLE_RUNTIMES=libclc -DLLVM_RUNTIME_TARGETS="spirv-mesa3d-" -DRUNTIMES_spirv64-mesa3d-_LLVM_ENABLE_RUNTIMES=libclc -DLLVM_RUNTIME_TARGETS="spirv64-mesa3d-" To build multiple targets, pass them as a semicolon-separated list in `LLVM_RUNTIME_TARGETS` and provide a matching `RUNTIMES_<target-triple>_LLVM_ENABLE_RUNTIMES=libclc` entry for each target. Updated README.md to document the new build flow. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> GitOrigin-RevId: 121f5a96ff38ec0c5d5f7274b1b0ca0df26a1cee
libclc is an open source implementation of the library requirements of the OpenCL C programming language, as specified by the OpenCL 1.1 Specification. The following sections of the specification impose library requirements:
libclc is intended to be used with the Clang compiler's OpenCL frontend.
libclc is designed to be portable and extensible. To this end, it provides generic implementations of most library requirements, allowing the target to override the generic implementation at the granularity of individual functions.
libclc currently supports PTX, AMDGPU, SPIRV and CLSPV targets, but support for more targets is welcome.
libclc is built as part of an LLVM runtimes build.
Select the targets to build with LLVM_RUNTIME_TARGETS, and enable libclc for each selected target with the matching RUNTIMES_<target-triple>_LLVM_ENABLE_RUNTIMES cache entry.
cd llvm-project mkdir build cd build cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release \ -DRUNTIMES_amdgcn-amd-amdhsa-llvm_LLVM_ENABLE_RUNTIMES=libclc \ -DLLVM_RUNTIME_TARGETS="amdgcn-amd-amdhsa-llvm"
cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release \ -DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=libclc \ -DLLVM_RUNTIME_TARGETS="nvptx64-nvidia-cuda"
cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release \ -DRUNTIMES_clspv--_LLVM_ENABLE_RUNTIMES=libclc \ -DRUNTIMES_clspv64--_LLVM_ENABLE_RUNTIMES=libclc \ -DLLVM_RUNTIME_TARGETS="clspv--;clspv64--"
cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release \ -DRUNTIMES_spirv-mesa3d-_LLVM_ENABLE_RUNTIMES=libclc \ -DRUNTIMES_spirv64-mesa3d-_LLVM_ENABLE_RUNTIMES=libclc \ -DLLVM_RUNTIME_TARGETS="spirv-mesa3d-;spirv64-mesa3d-"
To build multiple targets, pass them as a semicolon-separated list in LLVM_RUNTIME_TARGETS and provide a matching RUNTIMES_<target-triple>_LLVM_ENABLE_RUNTIMES=libclc entry for each target.
ninja
ninja install
Note you can use the DESTDIR Makefile variable to do staged installs.
DESTDIR=/path/for/staged/install ninja install
ninja check-libclc-<target-triple>
or
ninja -C runtimes/runtimes-<target-triple>-bins check-libclc
To build out of tree, or in other words, against an existing LLVM build or install:
CC=$(<path-to>/llvm-config --bindir)/clang cmake \ <path-to>/llvm-project/libclc/CMakeLists.txt -DCMAKE_BUILD_TYPE=Release \ -G Ninja -DLLVM_DIR=$(<path-to>/llvm-config --cmakedir) \ -DLLVM_RUNTIMES_TARGET=<target-triple> $ ninja
Then install as before.
In both cases, the LLVM used must include the targets you want libclc support for (AMDGPU and NVPTX are enabled in LLVM by default). Apart from SPIRV where you do not need an LLVM target but you do need the llvm-spirv tool available. Either build this in-tree, or place it in the directory pointed to by LLVM_TOOLS_BINARY_DIR.