fix race condition in hipEventRecord

このコミットが含まれているのは:
Jeff Daily
2019-11-04 17:45:11 +00:00
コミット 6fcff0118e
+21 -44
ファイルの表示
@@ -109,51 +109,28 @@ hipError_t hipEventCreate(hipEvent_t* event) {
hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream) { hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream) {
HIP_INIT_SPECIAL_API(hipEventRecord, TRACE_SYNC, event, stream); HIP_INIT_SPECIAL_API(hipEventRecord, TRACE_SYNC, event, stream);
if (!event) return ihipLogStatus(hipErrorInvalidResourceHandle);
hipError_t status; stream = ihipSyncAndResolveStream(stream);
if (event){ LockedAccessor_EventCrit_t eCrit(event->criticalData());
auto ecd = event->locked_copyCrit(); if (eCrit->_eventData._state == hipEventStatusUnitialized) return ihipLogStatus(hipErrorInvalidResourceHandle);
if( ecd._state != hipEventStatusUnitialized) { if (HIP_SYNC_NULL_STREAM && stream->isDefaultStream()) {
stream = ihipSyncAndResolveStream(stream); // TODO-HIP_SYNC_NULL_STREAM : can remove this code when HIP_SYNC_NULL_STREAM = 0
// If default stream , then wait on all queues.
if (HIP_SYNC_NULL_STREAM && stream->isDefaultStream()) { ihipCtx_t* ctx = ihipGetTlsDefaultCtx();
// TODO-HIP_SYNC_NULL_STREAM : can remove this code when HIP_SYNC_NULL_STREAM = 0 ctx->locked_syncDefaultStream(true, true);
// eCrit->_eventData.marker(hc::completion_future()); // reset event
// If default stream , then wait on all queues. eCrit->_eventData._stream = stream;
ihipCtx_t* ctx = ihipGetTlsDefaultCtx(); eCrit->_eventData._timestamp = hc::get_system_ticks();
ctx->locked_syncDefaultStream(true, true); eCrit->_eventData._state = hipEventStatusComplete;
{
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;
} }
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);
} }