Skip to content

Commit a664a0e

Browse files
committed
Reuse pi::getPlugin
1 parent 9301a53 commit a664a0e

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

sycl/source/backend/level_zero.cpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,10 @@ namespace sycl {
1717
namespace level0 {
1818
using namespace detail;
1919

20-
// Get the L0 plugin.
21-
static const plugin &getPlugin() {
22-
static const plugin *L0Plugin = nullptr;
23-
if (L0Plugin)
24-
return *L0Plugin;
25-
26-
const vector_class<plugin> &Plugins = pi::initialize();
27-
for (const auto &Plugin : Plugins)
28-
if (Plugin.getBackend() == backend::level0) {
29-
L0Plugin = &Plugin;
30-
break;
31-
}
32-
if (!L0Plugin) {
33-
throw runtime_error("sycl::level0 - no Level-Zero plugin",
34-
PI_INVALID_OPERATION);
35-
}
36-
return *L0Plugin;
37-
}
38-
3920
//----------------------------------------------------------------------------
4021
// Implementation of level0::make<platform>
4122
__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle) {
42-
const auto &Plugin = getPlugin();
23+
const auto &Plugin = pi::getPlugin<backend::level0>();
4324
// Create PI platform first.
4425
pi::PiPlatform PiPlatform;
4526
Plugin.call<PiApiKind::piextPlatformCreateWithNativeHandle>(NativeHandle,
@@ -54,7 +35,7 @@ __SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle) {
5435
// Implementation of level0::make<device>
5536
__SYCL_EXPORT device make_device(const platform &Platform,
5637
pi_native_handle NativeHandle) {
57-
const auto &Plugin = getPlugin();
38+
const auto &Plugin = pi::getPlugin<backend::level0>();
5839
const auto &PlatformImpl = getSyclObjImpl(Platform);
5940
// Create PI device first.
6041
pi::PiDevice PiDevice;
@@ -80,7 +61,7 @@ __SYCL_EXPORT program make_program(const context &Context,
8061
// Implementation of level0::make<queue>
8162
__SYCL_EXPORT queue make_queue(const context &Context,
8263
pi_native_handle NativeHandle) {
83-
const auto &Plugin = getPlugin();
64+
const auto &Plugin = pi::getPlugin<backend::level0>();
8465
const auto &ContextImpl = getSyclObjImpl(Context);
8566
// Create PI queue first.
8667
pi::PiQueue PiQueue;

sycl/source/detail/pi.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ template <backend BE> const plugin &getPlugin() {
390390
}
391391

392392
template const plugin &getPlugin<backend::opencl>();
393+
template const plugin &getPlugin<backend::level0>();
393394

394395
// Report error and no return (keeps compiler from printing warnings).
395396
// TODO: Probably change that to throw a catchable exception,

0 commit comments

Comments
 (0)