DPC++ Runtime
Runtime libraries for oneAPI DPC++
global_handler.hpp
Go to the documentation of this file.
1 //==--------- global_handler.hpp --- Global objects handler ----------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
12 #include <CL/sycl/detail/util.hpp>
13 
14 #include <memory>
15 #include <unordered_map>
16 
18 namespace sycl {
19 namespace detail {
20 class platform_impl;
21 class context_impl;
22 class Scheduler;
23 class ProgramManager;
24 class Sync;
25 class plugin;
26 class device_filter_list;
27 class XPTIRegistry;
28 class ThreadPool;
29 
30 using PlatformImplPtr = std::shared_ptr<platform_impl>;
31 using ContextImplPtr = std::shared_ptr<context_impl>;
32 
46 public:
51  static GlobalHandler &instance();
52 
53  GlobalHandler(const GlobalHandler &) = delete;
54  GlobalHandler(GlobalHandler &&) = delete;
55 
56  Scheduler &getScheduler();
57  ProgramManager &getProgramManager();
58  Sync &getSync();
59  std::vector<PlatformImplPtr> &getPlatformCache();
60 
61  std::unordered_map<PlatformImplPtr, ContextImplPtr> &
62  getPlatformToDefaultContextCache();
63 
64  std::mutex &getPlatformToDefaultContextCacheMutex();
65  std::mutex &getPlatformMapMutex();
66  std::mutex &getFilterMutex();
67  std::vector<plugin> &getPlugins();
68  device_filter_list &getDeviceFilterList(const std::string &InitValue);
69  XPTIRegistry &getXPTIRegistry();
70  std::mutex &getHandlerExtendedMembersMutex();
71  ThreadPool &getHostTaskThreadPool();
72 
73  static void registerDefaultContextReleaseHandler();
74 
75 private:
76  friend void releaseDefaultContexts();
77  friend void shutdown();
78 
79  // Constructor and destructor are declared out-of-line to allow incomplete
80  // types as template arguments to unique_ptr.
81  GlobalHandler();
82  ~GlobalHandler();
83 
84  template <typename T> struct InstWithLock {
85  std::unique_ptr<T> Inst;
86  SpinLock Lock;
87  };
88 
89  template <typename T, typename... Types>
90  T &getOrCreate(InstWithLock<T> &IWL, Types... Args);
91 
92  InstWithLock<Scheduler> MScheduler;
93  InstWithLock<ProgramManager> MProgramManager;
94  InstWithLock<Sync> MSync;
95  InstWithLock<std::vector<PlatformImplPtr>> MPlatformCache;
96  InstWithLock<std::unordered_map<PlatformImplPtr, ContextImplPtr>>
97  MPlatformToDefaultContextCache;
98  InstWithLock<std::mutex> MPlatformToDefaultContextCacheMutex;
99  InstWithLock<std::mutex> MPlatformMapMutex;
100  InstWithLock<std::mutex> MFilterMutex;
101  InstWithLock<std::vector<plugin>> MPlugins;
102  InstWithLock<device_filter_list> MDeviceFilterList;
103  InstWithLock<XPTIRegistry> MXPTIRegistry;
104  // The mutex for synchronizing accesses to handlers extended members
105  InstWithLock<std::mutex> MHandlerExtendedMembersMutex;
106  // Thread pool for host task and event callbacks execution
107  InstWithLock<ThreadPool> MHostTaskThreadPool;
108 };
109 } // namespace detail
110 } // namespace sycl
111 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::Scheduler
DPC++ graph scheduler class.
Definition: scheduler.hpp:358
cl::sycl::detail::ContextImplPtr
std::shared_ptr< detail::context_impl > ContextImplPtr
Definition: memory_manager.hpp:31
cl::sycl::detail::Sync
Groups and provides access to all the locks used the SYCL runtime.
Definition: util.hpp:24
cl::sycl::detail::SpinLock
SpinLock is a synchronization primitive, that uses atomic variable and causes thread trying acquire l...
Definition: spinlock.hpp:27
sycl
Definition: invoke_simd.hpp:68
util.hpp
cl::sycl::detail::shutdown
void shutdown()
Definition: global_handler.cpp:123
cl::sycl::detail::GlobalHandler
Wrapper class for global data structures with non-trivial destructors.
Definition: global_handler.hpp:45
cl::sycl::detail::releaseDefaultContexts
void releaseDefaultContexts()
Definition: global_handler.cpp:101
cl::sycl::detail::device_filter_list
Definition: device_filter.hpp:37
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::XPTIRegistry
Definition: xpti_registry.hpp:47
spinlock.hpp
cl::sycl::detail::ThreadPool
Definition: thread_pool.hpp:25
cl::sycl::detail::ProgramManager
Definition: program_manager.hpp:73
cl::sycl::detail::PlatformImplPtr
std::shared_ptr< detail::platform_impl > PlatformImplPtr
Definition: context_impl.hpp:30
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12