diff --git a/sycl/source/CMakeLists.txt b/sycl/source/CMakeLists.txt index 47b21614f92ad..7516865682f26 100644 --- a/sycl/source/CMakeLists.txt +++ b/sycl/source/CMakeLists.txt @@ -266,6 +266,7 @@ set(SYCL_COMMON_SOURCES "builtins/native_math_functions.cpp" "builtins/relational_functions.cpp" "detail/accessor_impl.cpp" + "detail/adapter_impl.cpp" "detail/allowlist.cpp" "detail/bindless_images.cpp" "detail/buffer_impl.cpp" diff --git a/sycl/source/detail/adapter_impl.cpp b/sycl/source/detail/adapter_impl.cpp new file mode 100644 index 0000000000000..6bdf7b87e3533 --- /dev/null +++ b/sycl/source/detail/adapter_impl.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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 definitions for the members of the adapter_impl +/// class. +/// +//===----------------------------------------------------------------------===// + +#include "adapter_impl.hpp" + +namespace sycl { +inline namespace _V1 { +namespace detail { + +void adapter_impl::ur_failed_throw_exception(sycl::errc errc, + ur_result_t ur_result) const { + assert(ur_result != UR_RESULT_SUCCESS); + std::string message = + __SYCL_UR_ERROR_REPORT(MBackend) + codeToString(ur_result); + + if (ur_result == UR_RESULT_ERROR_ADAPTER_SPECIFIC) { + assert(!adapterReleased); + const char *last_error_message = nullptr; + int32_t adapter_error = 0; + ur_result = call_nocheck( + MAdapter, &last_error_message, &adapter_error); + if (last_error_message) + message += "\n" + std::string(last_error_message) + "(adapter error )" + + std::to_string(adapter_error) + "\n"; + } + + throw set_ur_error(sycl::exception(sycl::make_error_code(errc), message), + ur_result); +} + +} // namespace detail +} // namespace _V1 +} // namespace sycl diff --git a/sycl/source/detail/adapter_impl.hpp b/sycl/source/detail/adapter_impl.hpp index 67619dbea1558..0933d7d77982d 100644 --- a/sycl/source/detail/adapter_impl.hpp +++ b/sycl/source/detail/adapter_impl.hpp @@ -71,29 +71,8 @@ class adapter_impl { /// \throw SYCL 2020 exception(errc) if ur_result is not UR_RESULT_SUCCESS template void checkUrResult(ur_result_t ur_result) const { - if (ur_result == UR_RESULT_ERROR_ADAPTER_SPECIFIC) { - assert(!adapterReleased); - const char *message = nullptr; - int32_t adapter_error = 0; - ur_result = call_nocheck( - MAdapter, &message, &adapter_error); - throw sycl::detail::set_ur_error( - sycl::exception( - sycl::make_error_code(errc), - __SYCL_UR_ERROR_REPORT(MBackend) + - sycl::detail::codeToString(ur_result) + - (message ? "\n" + std::string(message) + "(adapter error )" + - std::to_string(adapter_error) + "\n" - : std::string{})), - ur_result); - } - if (ur_result != UR_RESULT_SUCCESS) { - throw sycl::detail::set_ur_error( - sycl::exception(sycl::make_error_code(errc), - __SYCL_UR_ERROR_REPORT(MBackend) + - sycl::detail::codeToString(ur_result)), - ur_result); - } + if (__builtin_expect(ur_result != UR_RESULT_SUCCESS, false)) + ur_failed_throw_exception(errc, ur_result); } std::vector &getUrPlatforms() { @@ -225,6 +204,8 @@ class adapter_impl { bool adapterReleased = false; private: + void ur_failed_throw_exception(sycl::errc errc, ur_result_t ur_result) const; + ur_adapter_handle_t MAdapter; backend MBackend; // Mutex to guard UrPlatforms and LastDeviceIds. diff --git a/sycl/source/detail/event_impl.cpp b/sycl/source/detail/event_impl.cpp index 7256393f30a7e..6b7957bf781bd 100644 --- a/sycl/source/detail/event_impl.cpp +++ b/sycl/source/detail/event_impl.cpp @@ -131,12 +131,6 @@ static uint64_t inline getTimestamp(device_impl *Device) { } } -ur_event_handle_t event_impl::getHandle() const { return MEvent.load(); } - -void event_impl::setHandle(const ur_event_handle_t &UREvent) { - MEvent.store(UREvent); -} - context_impl &event_impl::getContextImpl() { initContextIfNeeded(); assert(MContext && "Trying to get context from a host event!"); diff --git a/sycl/source/detail/event_impl.hpp b/sycl/source/detail/event_impl.hpp index 0f98ac3958aa0..d4e1ed59a9016 100644 --- a/sycl/source/detail/event_impl.hpp +++ b/sycl/source/detail/event_impl.hpp @@ -163,10 +163,10 @@ class event_impl { void setComplete(); /// Returns raw interoperability event handle. - ur_event_handle_t getHandle() const; + ur_event_handle_t getHandle() const { return MEvent.load(); } /// Set event handle for this event object. - void setHandle(const ur_event_handle_t &UREvent); + void setHandle(const ur_event_handle_t &UREvent) { MEvent.store(UREvent); } /// Returns context that is associated with this event. context_impl &getContextImpl(); diff --git a/unified-runtime/source/loader/ur_lib.cpp b/unified-runtime/source/loader/ur_lib.cpp index 1e040433de6a8..d401054e0e331 100644 --- a/unified-runtime/source/loader/ur_lib.cpp +++ b/unified-runtime/source/loader/ur_lib.cpp @@ -28,15 +28,9 @@ #include namespace ur_lib { -/////////////////////////////////////////////////////////////////////////////// -context_t *getContext() { return context_t::get_direct(); } - /////////////////////////////////////////////////////////////////////////////// context_t::context_t() { parseEnvEnabledLayers(); } -/////////////////////////////////////////////////////////////////////////////// -context_t::~context_t() {} - void context_t::parseEnvEnabledLayers() { auto maybeEnableEnvVarVec = getenv_to_vec("UR_ENABLE_LAYERS"); if (!maybeEnableEnvVarVec.has_value()) { diff --git a/unified-runtime/source/loader/ur_lib.hpp b/unified-runtime/source/loader/ur_lib.hpp index 6e6b4bb7fd53e..341dcfb7af475 100644 --- a/unified-runtime/source/loader/ur_lib.hpp +++ b/unified-runtime/source/loader/ur_lib.hpp @@ -61,7 +61,6 @@ class __urdlllocal context_t : public AtomicSingleton { #endif context_t(); - ~context_t(); std::once_flag initOnce; @@ -117,7 +116,7 @@ class __urdlllocal context_t : public AtomicSingleton { void tearDownLayers() const; }; -context_t *getContext(); +inline context_t *getContext() { return context_t::get_direct(); } ur_result_t urLoaderConfigCreate(ur_loader_config_handle_t *phLoaderConfig); ur_result_t urLoaderConfigRetain(ur_loader_config_handle_t hLoaderConfig);