llvm / llvm/llvm-project

[SYCL] Implement backend feature test macros as prescribed by spec

Open
#220,997 1 comment 0 reactions 1 assignee Claimed by @KseniyaTikhomirova View on GitHub
SYCL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://github.com/llvm/llvm-project/blob/dca328efcdeebf40ef936152a6d7bc25d0ed6f70/libsycl/include/sycl/__impl/backend.hpp#L27-L32

Per https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:backend-macros the backend list is implementation defined and each backend identifier must have associated macro definition to feature test availability of the backend. I believe we are currently missing these defines.

Quote from the spec: "Backend macros
As the identifiers defined in enum class backend are implementation-defined, and the associated backends are not guaranteed to be available, a SYCL implementation must also define a preprocessor macro for each of these identifiers. If the [SYCL backend](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#backend) is defined by the Khronos SYCL group, the name of the macro has the form `SYCL_BACKEND_`, where `backend_name` is the associated identifier from backend in all upper-case. See [Chapter 6](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#chapter.extensions) for the name of the macro if the vendor defines the [SYCL backend](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#backend) outside of the Khronos SYCL group.

If a backend listed in the enum class backend is not available, the associated macro must be left undefined."

Also, are backends which we currently support Khronos defined or not? To be honest I can't find in the spec if Khronos group has defined any backend as of today.

This feature macro is needed, for example, in Pytorch to enable build with the LLVM sycl. Pytorch explicitly checks for the level zero backend:
* https://github.com/pytorch/pytorch/blob/16ee283cbb46b4cda3d9b3de133f90eca12d3fbd/c10/xpu/XPUFunctions.cpp#L53

```c++
if (platform.get_backend() != sycl::backend::ext_oneapi_level_zero) {
return false;
}
```

CC: @KseniyaTikhomirova, @tahonermann

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.