[libclc] Give a helpful error when an unknown target is requested (#111528)

I just tried using LLVM backend names here e.g. NVPTX but libclc want's
targets more like triples. This change adds a mesasge to tell you that.

Before you got:
```
 libclc target 'AMDGCN' is enabled
 CMake Error at CMakeLists.txt:253 (list):
   list index: 1 out of range (-1, 0)

 CMake Error at CMakeLists.txt:254 (list):
   list index: 2 out of range (-1, 0)

 Configuring incomplete, errors occurred!
```
Now you get:

```
 CMake Error at CMakeLists.txt:145 (message):
   Unknown target in LIBCLC_TARGETS_TO_BUILD: "AMDGCN"

   Valid targets are:
   amdgcn--;amdgcn--amdhsa;clspv--;clspv64--;r600--;nvptx--;nvptx64--;nvptx--nvidiacl;nvptx64--nvidiacl;amdgcn-mesa-mesa3d
```
Some of the targets are dynamic based on what is installed, so spirv
isn't here for me because I don't have llvm-spirv installed yet.

So this is not perfect but it's an improvement on the current behaviour.

GitOrigin-RevId: a4de127086ba4e39effb28642973edbb758e9656
1 file changed
tree: e17173ea1aa06ffd60a0f4d0dda941b7fbcf147f
  1. amdgcn/
  2. amdgcn-amdhsa/
  3. amdgpu/
  4. clspv/
  5. cmake/
  6. generic/
  7. ptx/
  8. ptx-nvidiacl/
  9. r600/
  10. spirv/
  11. spirv64/
  12. test/
  13. utils/
  14. www/
  15. .gitignore
  16. check_external_calls.sh
  17. CMakeLists.txt
  18. compile-test.sh
  19. CREDITS.TXT
  20. libclc.pc.in
  21. LICENSE.TXT
  22. README.md
README.md

libclc

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:

  • 6.1: Supported Data Types
  • 6.2.3: Explicit Conversions
  • 6.2.4.2: Reinterpreting Types Using as_type() and as_typen()
  • 6.9: Preprocessor Directives and Macros
  • 6.11: Built-in Functions
  • 9.3: Double Precision Floating-Point
  • 9.4: 64-bit Atomics
  • 9.5: Writing to 3D image memory objects
  • 9.6: Half Precision Floating-Point

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.

Compiling and installing

(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="libclc;clang" \
    -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.

Website

https://libclc.llvm.org/