[llvm] [SYCL] Add platform enumeration and info query using liboffload (PR #166927)
Kseniya Tikhomirova via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 15 08:14:32 PST 2026
================
@@ -0,0 +1,115 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 {
+
+/// Converts liboffload error code to C-string.
+///
+/// \param Error liboffload error code.
+///
+/// \returns C-string representing the name of Error as specified in enum.
+const char *stringifyErrorCode(ol_errc_t Error);
+
+/// Contructs C++-string with information about liboffload error.
+///
+/// \param Error liboffload result of calling API.
+///
+/// \returns C++-string containing all available data of failure.
+inline std::string formatCodeString(ol_result_t Result) {
+ return std::to_string(Result->Code) + " (" +
+ std::string(stringifyErrorCode(Result->Code)) + ") " + Result->Details;
+}
+
+/// Checks liboffload API call result.
+///
+/// Used after calling the API without check.
+/// To be called when specific handling is needed and explicitly done by
+/// developer before throwing exception.
+///
+/// \param Error liboffload result of calling API.
+///
+/// \throw sycl::runtime_exception if the call was not successful.
+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.
+///
+/// \param Function liboffload API function to be called.
+/// \param Args arguments to be passed to the liboffload API function.
+///
+/// \returns liboffload error code returned by API call.
+template <typename FunctionType, typename... ArgsT>
+ol_result_t call_nocheck(FunctionType &Function, ArgsT &&...Args) {
+ return Function(std::forward<ArgsT>(Args)...);
+}
+
+/// Calls the API and checks result.
+///
+/// \param Function liboffload API function to be called.
+/// \param Args arguments to be passed to the liboffload API function.
+///
+/// \throw sycl::runtime_exception if the call was not successful.
+template <typename FunctionType, typename... ArgsT>
+void call_and_throw(FunctionType &Function, ArgsT &&...Args) {
----------------
KseniyaTikhomirova wrote:
I've done all renaming, closing as resolved
https://github.com/llvm/llvm-project/pull/166927
More information about the llvm-commits
mailing list