[llvm] [SYCL] Add platform enumeration and info query using liboffload (PR #166927)
Dmitry Rogozhkin via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 12 08:35:05 PST 2025
================
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBSYCL_OFFLOAD_UTILS
+#define _LIBSYCL_OFFLOAD_UTILS
+
+#include <sycl/__impl/backend.hpp>
+#include <sycl/__impl/detail/config.hpp>
+#include <sycl/__impl/exception.hpp>
+
+#include <OffloadAPI.h>
+
+_LIBSYCL_BEGIN_NAMESPACE_SYCL
+
+namespace detail {
+
+const char *stringifyErrorCode(ol_errc_t error);
+
+inline std::string formatCodeString(ol_result_t Result) {
+ return std::to_string(Result->Code) + " (" +
+ std::string(stringifyErrorCode(Result->Code)) + ")" + Result->Details;
+}
+
+template <sycl::errc errc = sycl::errc::runtime>
+void checkAndThrow(ol_result_t Result) {
+ if (Result != OL_SUCCESS) {
+ throw sycl::exception(sycl::make_error_code(errc),
+ detail::formatCodeString(Result));
+ }
+}
+
+/// Calls the API, doesn't check result. To be called when specific handling is
+/// needed and explicitly done by developer after.
+template <typename FunctionType, typename... ArgsT>
+ol_result_t call_nocheck(FunctionType &Function, ArgsT &&...Args) {
+ return Function(std::forward<ArgsT>(Args)...);
+}
+
+/// Calls the API & checks the result
+///
+/// \throw sycl::runtime_exception if the call was not successful.
+template <typename FunctionType, typename... ArgsT>
+void call_and_throw(FunctionType &Function, ArgsT &&...Args) {
+ auto Err = call_nocheck(Function, std::forward<ArgsT>(Args)...);
+ checkAndThrow(Err);
+}
+
+backend convertBackend(ol_platform_backend_t Backend);
+
+/// Helper to map SYCL information descriptors to OL_<HANDLE>_INFO_<SMTH>. To be
+/// used like:
+///
+/// using Map = info_ol_mapping<ol_foo_info_t>;
----------------
dvrogozh wrote:
`///` is for tools to create documentation. I honestly did not look into compliance of the comments to the intended format in this respect, but 1) are you going to generate any documentation from this header? 2) this specific comment likely does not follow required format as it gives code block example without any markup to mark it as such.
https://github.com/llvm/llvm-project/pull/166927
More information about the llvm-commits
mailing list