Skip to content

Commit 5a3df8f

Browse files
committed
[SYCL] Load PI plugins only once. Make pi::initialize return const reference to the global vector of plugins, not a temporary copy of it.
Change-Id: Ic1373059c9697b0b4d318548b79be7bcb9d4f2a9 Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 3009338 commit 5a3df8f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

sycl/include/CL/sycl/detail/pi.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ template <class To, class From> To cast(From value);
135135
extern std::shared_ptr<plugin> GlobalPlugin;
136136

137137
// Performs PI one-time initialization.
138-
vector_class<plugin> initialize();
138+
const vector_class<plugin> &initialize();
139139

140140
// Utility Functions to get Function Name for a PI Api.
141141
template <PiApiKind PiApiOffset> struct PiFuncInfo {};

sycl/source/detail/pi.cpp

100755100644
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,13 @@ bool trace(TraceLevel Level) {
255255
}
256256

257257
// Initializes all available Plugins.
258-
vector_class<plugin> initialize() {
258+
// The returned reference lifetime is through the end of the process.
259+
//
260+
// TODO: make sure that the global Plugins is destroyed last, at least
261+
// after other tear-down relying on plugins (like destructors of global
262+
// buffers) is completed.
263+
//
264+
const vector_class<plugin> &initialize() {
259265
static bool PluginsInitDone = false;
260266
static vector_class<plugin> Plugins;
261267
if (PluginsInitDone) {

sycl/source/detail/platform_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static bool IsBannedPlatform(platform Platform) {
4949

5050
vector_class<platform> platform_impl::get_platforms() {
5151
vector_class<platform> Platforms;
52-
vector_class<plugin> Plugins = RT::initialize();
52+
const vector_class<plugin> &Plugins = RT::initialize();
5353

5454
info::device_type ForcedType = detail::get_forced_type();
5555
for (unsigned int i = 0; i < Plugins.size(); i++) {

0 commit comments

Comments
 (0)