Skip to content

Commit 97451b1

Browse files
authored
[SYCL] Check if Plugin before all calls to a plugin API (#11128)
- Using Teardown tracking of "pluginReleased", check if the plugin is released before each call to a plugin's functions. Signed-off-by: Spruit, Neil R <[email protected]>
1 parent a527dd1 commit 97451b1

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

sycl/source/detail/device_impl.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,9 @@ device_impl::~device_impl() {
8787
if (!MIsHostDevice) {
8888
// TODO catch an exception and put it to list of asynchronous exceptions
8989
const PluginPtr &Plugin = getPlugin();
90-
if (!Plugin->pluginReleased) {
91-
sycl::detail::pi::PiResult Err =
92-
Plugin->call_nocheck<PiApiKind::piDeviceRelease>(MDevice);
93-
__SYCL_CHECK_OCL_CODE_NO_EXC(Err);
94-
}
90+
sycl::detail::pi::PiResult Err =
91+
Plugin->call_nocheck<PiApiKind::piDeviceRelease>(MDevice);
92+
__SYCL_CHECK_OCL_CODE_NO_EXC(Err);
9593
}
9694
}
9795

sycl/source/detail/plugin.hpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,27 @@ class plugin {
193193
static_cast<uint32_t>(PiApiOffset), PIFnName, ArgsDataPtr, *MPlugin);
194194
}
195195
#endif
196-
sycl::detail::pi::PiResult R;
196+
sycl::detail::pi::PiResult R = PI_SUCCESS;
197197
if (pi::trace(pi::TraceLevel::PI_TRACE_CALLS)) {
198198
std::lock_guard<std::mutex> Guard(*TracingMutex);
199199
const char *FnName = PiCallInfo.getFuncName();
200200
std::cout << "---> " << FnName << "(" << std::endl;
201201
sycl::detail::pi::printArgs(Args...);
202-
R = PiCallInfo.getFuncPtr(*MPlugin)(Args...);
203-
std::cout << ") ---> ";
204-
sycl::detail::pi::printArgs(R);
205-
sycl::detail::pi::printOuts(Args...);
206-
std::cout << std::endl;
202+
if (!pluginReleased) {
203+
R = PiCallInfo.getFuncPtr(*MPlugin)(Args...);
204+
std::cout << ") ---> ";
205+
sycl::detail::pi::printArgs(R);
206+
sycl::detail::pi::printOuts(Args...);
207+
std::cout << std::endl;
208+
} else {
209+
std::cout << ") ---> ";
210+
std::cout << "API Called After Plugin Teardown, Functon Call ignored.";
211+
std::cout << std::endl;
212+
}
207213
} else {
208-
R = PiCallInfo.getFuncPtr(*MPlugin)(Args...);
214+
if (!pluginReleased) {
215+
R = PiCallInfo.getFuncPtr(*MPlugin)(Args...);
216+
}
209217
}
210218
#ifdef XPTI_ENABLE_INSTRUMENTATION
211219
// Close the function begin with a call to function end
@@ -240,7 +248,10 @@ class plugin {
240248

241249
void *getLibraryHandle() const { return MLibraryHandle; }
242250
void *getLibraryHandle() { return MLibraryHandle; }
243-
int unload() { return sycl::detail::pi::unloadPlugin(MLibraryHandle); }
251+
int unload() {
252+
this->pluginReleased = true;
253+
return sycl::detail::pi::unloadPlugin(MLibraryHandle);
254+
}
244255

245256
// return the index of PiPlatforms.
246257
// If not found, add it and return its index.

0 commit comments

Comments
 (0)