| commit | d82c4483a308d30018b2de9889d579f9cbbefc46 | [log] [tgz] |
|---|---|---|
| author | Joseph Huber <huberjn@outlook.com> | Wed Jan 07 08:21:45 2026 -0600 |
| committer | Copybara-Service <copybara-worker@google.com> | Wed Jan 07 06:26:42 2026 -0800 |
| tree | 8088bbfd62227f6c38199f5fb2c7a38e0b31c71b | |
| parent | 5d07dff75d06af7f4381357697c815710415f81d [diff] |
[libclc] Initial support for cross-compiling OpenCL libraries (#174022) 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. GitOrigin-RevId: 9315747fb31b5dcf7e5879a0138d39098c30cea3
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.
(in the following instructions you can use make or ninja)
For an in-tree build, Clang must also be built at the same time:
$ cmake <path-to>/llvm-project/llvm/CMakeLists.txt -DLLVM_ENABLE_PROJECTS="clang" \
-DLLVM_ENABLE_RUNTIMES="libclc" -DCMAKE_BUILD_TYPE=Release -G Ninja
$ ninja
Then install:
$ ninja install
Note you can use the DESTDIR Makefile variable to do staged installs.
$ DESTDIR=/path/for/staged/install ninja install
To build out of tree, or in other words, against an existing LLVM build or install:
$ cmake <path-to>/llvm-project/libclc/CMakeLists.txt -DCMAKE_BUILD_TYPE=Release \ -G Ninja -DLLVM_DIR=$(<path-to>/llvm-config --cmakedir) $ ninja
Then install as before.
In both cases this will include all supported targets. You can choose which targets are enabled by passing -DLIBCLC_TARGETS_TO_BUILD to CMake. The default is all.
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.