SWDEV-387810 - Fixes to verify if the current stream matches the capture stream

- invalid to synchronize or query the execution status of a capturing stream but non-capturing streams can.

- If any local thread has an ongoing or concurrent capture sequence initiated with hipStreamCaptureModeGlobal, it is prohibited from unsafe calls

Change-Id: Ifa641e807216d3b7c3e8c2fb1be2f7a50bd641df
This commit is contained in:
Sourabh Betigeri
2023-03-10 23:19:57 +00:00
committed by Maneesh Gupta
parent 300ba5b1f1
commit 7809d2846b
4 changed files with 19 additions and 8 deletions
+15 -5
View File
@@ -156,8 +156,18 @@ void Stream::destroyAllStreams(int deviceId) {
}
}
bool Stream::StreamCaptureOngoing(void) {
return (g_allCapturingStreams.empty() == true) ? false : true;
bool Stream::StreamCaptureOngoing(hipStream_t hStream) {
hip::Stream* s = reinterpret_cast<hip::Stream*>(hStream);
// If any local thread has an ongoing or concurrent capture sequence initiated
// with hipStreamCaptureModeGlobal, it is prohibited from unsafe calls
if (s != nullptr && s->GetCaptureMode() == hipStreamCaptureModeGlobal) {
amd::ScopedLock lock(g_captureStreamsLock);
return (g_captureStreams.empty() == true) ? false : true;
}
else {
amd::ScopedLock lock(g_streamSetLock);
return (g_allCapturingStreams.find(s) == g_allCapturingStreams.end() ? false : true);
}
}
bool Stream::existsActiveStreamForDevice(hip::Device* device) {
@@ -416,7 +426,7 @@ hipError_t hipStreamSynchronize_common(hipStream_t stream) {
}
if (stream != nullptr) {
// If still capturing return error
if (hip::Stream::StreamCaptureOngoing() == true) {
if (hip::Stream::StreamCaptureOngoing(stream) == true) {
HIP_RETURN(hipErrorStreamCaptureUnsupported);
}
}
@@ -526,7 +536,7 @@ hipError_t hipStreamQuery_common(hipStream_t stream) {
}
if (stream != nullptr) {
// If still capturing return error
if (hip::Stream::StreamCaptureOngoing() == true) {
if (hip::Stream::StreamCaptureOngoing(stream) == true) {
HIP_RETURN(hipErrorStreamCaptureUnsupported);
}
}
@@ -657,7 +667,7 @@ hipError_t hipLaunchHostFunc_spt(hipStream_t stream, hipHostFn_t fn, void* userD
// ================================================================================================
hipError_t hipLaunchHostFunc(hipStream_t stream, hipHostFn_t fn, void* userData) {
HIP_INIT_API(hipLaunchHostFunc, stream, fn, userData);
if (stream == nullptr && (hip::Stream::StreamCaptureOngoing() == true)) {
if (stream == nullptr && (hip::Stream::StreamCaptureOngoing(stream) == true)) {
HIP_RETURN(hipErrorStreamCaptureImplicit);
}
HIP_RETURN(hipLaunchHostFunc_common(stream, fn, userData));