fix race condition in hipEventRecord
This commit is contained in:
+21
-44
@@ -109,51 +109,28 @@ hipError_t hipEventCreate(hipEvent_t* event) {
|
||||
|
||||
hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream) {
|
||||
HIP_INIT_SPECIAL_API(hipEventRecord, TRACE_SYNC, event, stream);
|
||||
|
||||
hipError_t status;
|
||||
if (event){
|
||||
auto ecd = event->locked_copyCrit();
|
||||
if( ecd._state != hipEventStatusUnitialized) {
|
||||
stream = ihipSyncAndResolveStream(stream);
|
||||
|
||||
if (HIP_SYNC_NULL_STREAM && stream->isDefaultStream()) {
|
||||
// TODO-HIP_SYNC_NULL_STREAM : can remove this code when HIP_SYNC_NULL_STREAM = 0
|
||||
//
|
||||
// If default stream , then wait on all queues.
|
||||
ihipCtx_t* ctx = ihipGetTlsDefaultCtx();
|
||||
ctx->locked_syncDefaultStream(true, true);
|
||||
|
||||
{
|
||||
LockedAccessor_EventCrit_t eCrit(event->criticalData());
|
||||
eCrit->_eventData.marker(hc::completion_future()); // reset event
|
||||
eCrit->_eventData._stream = stream;
|
||||
eCrit->_eventData._timestamp = hc::get_system_ticks();
|
||||
eCrit->_eventData._state = hipEventStatusComplete;
|
||||
}
|
||||
status = hipSuccess;
|
||||
} else {
|
||||
// Record the event in the stream:
|
||||
// Keep a copy outside the critical section so we lock stream first, then event - to
|
||||
// avoid deadlock
|
||||
hc::completion_future cf = stream->locked_recordEvent(event);
|
||||
|
||||
{
|
||||
LockedAccessor_EventCrit_t eCrit(event->criticalData());
|
||||
eCrit->_eventData.marker(cf);
|
||||
eCrit->_eventData._stream = stream;
|
||||
eCrit->_eventData._timestamp = 0;
|
||||
eCrit->_eventData._state = hipEventStatusRecording;
|
||||
}
|
||||
|
||||
status = hipSuccess;
|
||||
}
|
||||
} else {
|
||||
status = hipErrorInvalidResourceHandle;
|
||||
}
|
||||
} else {
|
||||
status = hipErrorInvalidResourceHandle;
|
||||
if (!event) return ihipLogStatus(hipErrorInvalidResourceHandle);
|
||||
stream = ihipSyncAndResolveStream(stream);
|
||||
LockedAccessor_EventCrit_t eCrit(event->criticalData());
|
||||
if (eCrit->_eventData._state == hipEventStatusUnitialized) return ihipLogStatus(hipErrorInvalidResourceHandle);
|
||||
if (HIP_SYNC_NULL_STREAM && stream->isDefaultStream()) {
|
||||
// TODO-HIP_SYNC_NULL_STREAM : can remove this code when HIP_SYNC_NULL_STREAM = 0
|
||||
// If default stream , then wait on all queues.
|
||||
ihipCtx_t* ctx = ihipGetTlsDefaultCtx();
|
||||
ctx->locked_syncDefaultStream(true, true);
|
||||
eCrit->_eventData.marker(hc::completion_future()); // reset event
|
||||
eCrit->_eventData._stream = stream;
|
||||
eCrit->_eventData._timestamp = hc::get_system_ticks();
|
||||
eCrit->_eventData._state = hipEventStatusComplete;
|
||||
}
|
||||
return ihipLogStatus(status);
|
||||
else {
|
||||
// Record the event in the stream:
|
||||
eCrit->_eventData.marker(stream->locked_recordEvent(event));
|
||||
eCrit->_eventData._stream = stream;
|
||||
eCrit->_eventData._timestamp = 0;
|
||||
eCrit->_eventData._state = hipEventStatusRecording;
|
||||
}
|
||||
return ihipLogStatus(hipSuccess);
|
||||
}
|
||||
|
||||
|
||||
|
||||
مرجع در شماره جدید
Block a user