9 #ifdef ENABLE_STACK_TRACE
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/Support/Signals.h"
33 inline namespace _V1 {
37 SpinLock GlobalHandler::MSyclGlobalHandlerProtector{};
61 LockGuard Guard(GlobalHandler::MSyclGlobalHandlerProtector);
63 GlobalHandler *RTGlobalObjHandler = GlobalHandler::getInstancePtr();
64 if (RTGlobalObjHandler) {
67 }
catch (std::exception &e) {
73 static std::atomic_uint MCounter;
76 std::atomic_uint ObjectUsageCounter::MCounter{0};
78 GlobalHandler::GlobalHandler() =
default;
79 GlobalHandler::~GlobalHandler() =
default;
82 #ifdef XPTI_ENABLE_INSTRUMENTATION
86 xpti::payload_t SYCLPayload(
"SYCL Runtime Exceptions");
87 uint64_t SYCLInstanceNo;
88 GSYCLCallEvent = xptiMakeEvent(
"SYCL Try-catch Exceptions", &SYCLPayload,
89 xpti::trace_algorithm_event, xpti_at::active,
97 #ifdef XPTI_ENABLE_INSTRUMENTATION
98 static std::once_flag InitXPTIFlag;
99 if (xptiTraceEnabled()) {
100 std::call_once(InitXPTIFlag, [&]() {
InitXPTI(); });
105 auto CodeLocation = Tls.
query();
108 xpti::framework::tracepoint_t TP(
109 CodeLocation.fileName(), CodeLocation.functionName(),
110 CodeLocation.lineNumber(), CodeLocation.columnNumber(),
nullptr);
120 .trace_type(xpti::trace_point_type_t::diagnostics)
121 .notify(
static_cast<const void *
>(Message));
129 return RTGlobalObjHandler;
133 GlobalHandler *RTGlobalObjHandler = GlobalHandler::getInstancePtr();
134 assert(RTGlobalObjHandler &&
"Handler must not be deallocated earlier");
135 return *RTGlobalObjHandler;
138 template <
typename T,
typename... Types>
139 T &GlobalHandler::getOrCreate(InstWithLock<T> &IWL, Types... Args) {
143 IWL.Inst = std::make_unique<T>(Args...);
157 #ifdef ENABLE_STACK_TRACE
158 static std::once_flag PrintStackFlag;
159 std::call_once(PrintStackFlag, []() {
160 llvm::sys::PrintStackTraceOnErrorSignal(llvm::StringRef());
166 getOrCreate(MScheduler);
175 return *MScheduler.Inst;
185 return getOrCreate(MProgramManager);
188 std::unordered_map<PlatformImplPtr, ContextImplPtr> &
190 return getOrCreate(MPlatformToDefaultContextCache);
194 return getOrCreate(MPlatformToDefaultContextCacheMutex);
200 return getOrCreate(MPlatformCache);
204 return getOrCreate(MPlatformMapMutex);
208 return getOrCreate(MFilterMutex);
213 return getOrCreate(MPlugins);
218 return getOrCreate(MOneapiDeviceSelectorTargets, InitValue);
222 return getOrCreate(MXPTIRegistry);
227 ThreadPool &TP = getOrCreate(MHostTaskThreadPool, Size);
237 MPlatformToDefaultContextCache.Inst.reset(
nullptr);
249 }
catch (std::exception &e) {
293 if (MHostTaskThreadPool.Inst)
294 MHostTaskThreadPool.Inst->drain();
310 const LockGuard Lock{GlobalHandler::MSyclGlobalHandlerProtector};
322 if (Handler->MHostTaskThreadPool.Inst)
323 Handler->MHostTaskThreadPool.Inst->finishAndWait();
331 const LockGuard Lock{GlobalHandler::MSyclGlobalHandlerProtector};
337 Handler->MPlatformCache.Inst.reset(
nullptr);
338 Handler->MScheduler.Inst.reset(
nullptr);
339 Handler->MProgramManager.Inst.reset(
nullptr);
343 if (Handler->MPlugins.Inst)
344 Handler->MPlugins.Inst.reset(
nullptr);
346 Handler->MXPTIRegistry.Inst.reset(
nullptr);
355 extern "C" __SYCL_EXPORT BOOL WINAPI DllMain(HINSTANCE hinstDLL,
360 if (std::getenv(
"SYCL_PI_TRACE")) {
361 std::cerr <<
"SYCL_PI_TRACE has been removed use SYCL_UR_TRACE instead\n";
368 case DLL_PROCESS_DETACH:
370 std::cout <<
"---> DLL_PROCESS_DETACH syclx.dll\n" << std::endl;
372 #ifdef XPTI_ENABLE_INSTRUMENTATION
373 if (xptiTraceEnabled())
380 case DLL_PROCESS_ATTACH:
382 std::cout <<
"---> DLL_PROCESS_ATTACH syclx.dll\n" << std::endl;
384 case DLL_THREAD_ATTACH:
386 case DLL_THREAD_DETACH:
Wrapper class for global data structures with non-trivial destructors.
static void registerEarlyShutdownHandler()
ods_target_list & getOneapiDeviceSelectorTargets(const std::string &InitValue)
bool isSchedulerAlive() const
void releaseDefaultContexts()
std::vector< PlatformImplPtr > & getPlatformCache()
XPTIRegistry & getXPTIRegistry()
ProgramManager & getProgramManager()
std::unordered_map< PlatformImplPtr, ContextImplPtr > & getPlatformToDefaultContextCache()
std::vector< PluginPtr > & getPlugins()
void prepareSchedulerToRelease(bool Blocking)
void TraceEventXPTI(const char *Message)
std::mutex & getPlatformMapMutex()
void attachScheduler(Scheduler *Scheduler)
void registerSchedulerUsage(bool ModifyCounter=true)
std::mutex & getPlatformToDefaultContextCacheMutex()
void endDeferredRelease()
std::mutex & getFilterMutex()
ThreadPool & getHostTaskThreadPool()
Scheduler & getScheduler()
static GlobalHandler & instance()
ObjectUsageCounter(bool ModifyCounter)
static const char * get()
DPC++ graph scheduler class.
SpinLock is a synchronization primitive, that uses atomic variable and causes thread trying acquire l...
Groups and provides access to all the locks used the SYCL runtime.
void initializeStream(const std::string &StreamName, uint32_t MajVer, uint32_t MinVer, const std::string &VerStr)
Notifies XPTI subscribers about new stream.
Data type that manages the code_location information in TLS.
const detail::code_location & query()
Query the information in the TLS slot.
Command group handler class.
#define __SYCL_REPORT_EXCEPTION_TO_STREAM(str, e)
__SYCL_EXTERN_STREAM_ATTRS ostream cout
Linked to standard output.
__SYCL_EXTERN_STREAM_ATTRS ostream cerr
Linked to standard error (unbuffered)
constexpr const char * SYCL_STREAM_NAME
__attribute__((destructor(110))) static void syclUnload()
std::lock_guard< SpinLock > LockGuard
static void enableOnCrashStackPrinting()
C++ utilities for Unified Runtime integration.