[llvm] [SYCL] Add platform enumeration and info query using liboffload (PR #166927)

Andrei Elovikov via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 7 10:10:57 PST 2025


================
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the declaration of SYCL 2020 platform info types.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBSYCL___IMPL_INFO_PLATFORM_HPP
+#define _LIBSYCL___IMPL_INFO_PLATFORM_HPP
+
+#include <sycl/__impl/detail/config.hpp>
+
+#include <string>
+
+_LIBSYCL_BEGIN_NAMESPACE_SYCL
+
+// A.1. Platform information descriptors
+namespace info {
+namespace platform {
+#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, OffloadCode)         \
+  struct Desc {                                                                \
+    using return_type = ReturnT;                                               \
+  };
+
+// 4.6.2.4. Information descriptors
+#include <sycl/__impl/info/platform.def>
+
+#undef __SYCL_PARAM_TRAITS_SPEC
+} // namespace platform
+} // namespace info
+
+namespace detail {
+template <typename T> struct is_platform_info_desc : std::false_type {};
+
+#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, OffloadCode)         \
+  template <>                                                                  \
+  struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type {    \
+    using return_type = info::DescType::Desc::return_type;                     \
+  };
----------------
aelovikov-intel wrote:

I grepped our downstream implementation, it seems we use the `::value` part in just a few places inside `libsycl.so` for `static_assert`s. I think we can change to

```c++
template <typename Desc> struct enable_platform_info_return {};

#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, OffloadCode)         \
  template <>                                                                  \
  struct enable_##DescType##_info_return<info::DescType::Desc> {               \
    using return_type = info::DescType::Desc::return_type;                     \
  };
```

followed by 

```c++
template <typename Desc> using enable_platform_info_return_t =
    typename enable_platform_info<Desc>::return_type;
```

and then introduce some helper inside the library to use for the `static_assert`s. Something like https://godbolt.org/z/vocr575q4:

```c++
template <typename Desc, template <typename> typename Enabler, typename = void>
struct is_enabled : std::false_type {};

template <typename Desc, template <typename> typename Enabler>
struct is_enabled<Desc, Enabler, std::void_t<Enabler<Desc>>> : std::true_type {};
```

Also, we include `platform.def` specifically, do we really need macro-magic around `##DescType##`? Can't we use "platfrom" directly?

https://github.com/llvm/llvm-project/pull/166927


More information about the llvm-commits mailing list