20 #ifdef XPTI_ENABLE_INSTRUMENTATION
22 #include "xpti/xpti_trace_framework.h"
27 #define __SYCL_REPORT_UR_ERR_TO_STREAM(expr) \
30 if (code != UR_RESULT_SUCCESS) { \
31 std::cerr << __SYCL_UR_ERROR_REPORT << sycl::detail::codeToString(code) \
36 #define __SYCL_CHECK_OCL_CODE_NO_EXC(X) __SYCL_REPORT_UR_ERR_TO_STREAM(X)
39 inline namespace _V1 {
51 : MAdapter(adapter), MBackend(UseBackend),
52 TracingMutex(
std::make_shared<
std::mutex>()),
53 MPluginMutex(
std::make_shared<
std::mutex>()) {}
64 template <sycl::errc errc = sycl::errc::runtime>
66 const char *message =
nullptr;
67 if (ur_result == UR_RESULT_ERROR_ADAPTER_SPECIFIC) {
68 int32_t adapter_error = 0;
69 ur_result =
call_nocheck(urAdapterGetLastError, MAdapter, &message, &adapter_error);
77 if (ur_result == UR_RESULT_SUCCESS) {
81 if (ur_result != UR_RESULT_SUCCESS) {
86 (message ?
"\n" + std::string(message) +
"\n"
93 std::call_once(PlatformsPopulated, [&]() {
94 uint32_t platformCount = 0;
95 call(urPlatformGet, &MAdapter, 1, 0,
nullptr, &platformCount);
96 UrPlatforms.resize(platformCount);
97 call(urPlatformGet, &MAdapter, 1, platformCount, UrPlatforms.data(),
100 LastDeviceIds.resize(platformCount);
117 template <
class UrFunc,
typename... ArgsT>
119 ur_result_t R = UR_RESULT_SUCCESS;
129 template <
class UrFunc,
typename... ArgsT>
130 void call(UrFunc F, ArgsT... Args)
const {
137 void call(UrFunc F, ArgsT... Args)
const {
139 checkUrResult<errc>(Err);
148 call(urAdapterRelease, MAdapter);
156 auto It = std::find(UrPlatforms.begin(), UrPlatforms.end(), Platform);
157 if (It != UrPlatforms.end())
158 return It - UrPlatforms.begin();
160 UrPlatforms.push_back(Platform);
161 LastDeviceIds.push_back(0);
162 return UrPlatforms.size() - 1;
174 return LastDeviceIds[PlatformId - 1];
181 LastDeviceIds[PlatformId] = Id;
189 if (PlatformId > 0 &&
190 LastDeviceIds[PlatformId] < LastDeviceIds[PlatformId - 1])
191 LastDeviceIds[PlatformId] = LastDeviceIds[PlatformId - 1];
195 auto It = std::find(UrPlatforms.begin(), UrPlatforms.end(), Platform);
196 return It != UrPlatforms.end();
203 ur_adapter_handle_t MAdapter;
205 std::shared_ptr<std::mutex> TracingMutex;
209 std::shared_ptr<std::mutex> MPluginMutex;
211 std::once_flag PlatformsPopulated;
212 std::vector<ur_platform_handle_t> UrPlatforms;
215 std::vector<int> LastDeviceIds;
218 using PluginPtr = std::shared_ptr<plugin>;
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
bool hasBackend(backend Backend) const
Tells if this plugin can serve specified backend.
plugin & operator=(const plugin &)=delete
ur_result_t call_nocheck(UrFunc F, ArgsT... Args) const
Calls the UR Api, traces the call, and returns the result.
int getStartingDeviceId(ur_platform_handle_t Platform)
plugin(ur_adapter_handle_t adapter, backend UseBackend)
std::vector< ur_platform_handle_t > & getUrPlatforms()
plugin(plugin &&other) noexcept=delete
int getPlatformId(ur_platform_handle_t Platform)
void setLastDeviceId(ur_platform_handle_t Platform, int Id)
bool containsUrPlatform(ur_platform_handle_t Platform)
plugin(const plugin &)=delete
plugin & operator=(plugin &&other) noexcept=delete
void checkUrResult(ur_result_t ur_result) const
std::shared_ptr< std::mutex > getPluginMutex()
void call(UrFunc F, ArgsT... Args) const
void adjustLastDeviceId(ur_platform_handle_t Platform)
void call(UrFunc F, ArgsT... Args) const
Calls the API, traces the call, checks the result.
ur_adapter_handle_t getUrAdapter()
#define __SYCL_UR_ERROR_REPORT
__SYCL_EXTERN_STREAM_ATTRS ostream clog
Linked to standard error (buffered)
std::string codeToString(int32_t code)
std::shared_ptr< plugin > PluginPtr
exception set_ur_error(exception &&e, int32_t ur_err)
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
_Abi const simd< _Tp, _Abi > & noexcept
C++ utilities for Unified Runtime integration.