Lock streams when waiting on event completion or querying event safety.

[ROCm/hip commit: 6ff74d0e97]
Este commit está contenido en:
Ben Sander committed 2017-08-28 18:40:16 -05:00
1 padre 0f0414a5ba
commit bd434502db
4 files changed
+52 -14

No files matched your search

+16 -7
Ver fichero
@@ -55,13 +55,13 @@ void ihipEvent_t::attachToCompletionFuture(const hc::completion_future *cf,
void ihipEvent_t::refereshEventStatus() void ihipEvent_t::refereshEventStatus()
{ {
bool isReady0 = _marker.is_ready(); bool isReady0 = locked_isReady();
bool isReady1; bool isReady1;
int val = 0; int val = 0;
if (_state == hipEventStatusRecording) { if (_state == hipEventStatusRecording) {
// TODO - use completion-future functions to obtain ticks and timestamps: // TODO - use completion-future functions to obtain ticks and timestamps:
hsa_signal_t *sig = static_cast<hsa_signal_t*> (_marker.get_native_handle()); hsa_signal_t *sig = static_cast<hsa_signal_t*> (_marker.get_native_handle());
isReady1 = _marker.is_ready(); isReady1 = locked_isReady();
if (sig) { if (sig) {
val = hsa_signal_load_acquire(*sig); val = hsa_signal_load_acquire(*sig);
if (val == 0) { if (val == 0) {
@@ -86,6 +86,17 @@ void ihipEvent_t::refereshEventStatus()
} }
bool ihipEvent_t::locked_isReady()
{
return _stream->locked_eventIsReady(this);
}
void ihipEvent_t::locked_waitComplete(hc::hcWaitMode waitMode)
{
return _stream->locked_eventWaitComplete(this, waitMode);
}
hipError_t ihipEventCreate(hipEvent_t* event, unsigned flags) hipError_t ihipEventCreate(hipEvent_t* event, unsigned flags)
{ {
hipError_t e = hipSuccess; hipError_t e = hipSuccess;
@@ -127,7 +138,7 @@ 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(TRACE_QUERY, event, stream); HIP_INIT_SPECIAL_API(TRACE_SYNC, event, stream);
if (event && event->_state != hipEventStatusUnitialized) { if (event && event->_state != hipEventStatusUnitialized) {
stream = ihipSyncAndResolveStream(stream); stream = ihipSyncAndResolveStream(stream);
@@ -192,9 +203,7 @@ hipError_t hipEventSynchronize(hipEvent_t event)
ctx->locked_syncDefaultStream(true, true); ctx->locked_syncDefaultStream(true, true);
return ihipLogStatus(hipSuccess); return ihipLogStatus(hipSuccess);
} else { } else {
event->_marker.wait((event->_flags & hipEventBlockingSync) ? hc::hcWaitModeBlocked : hc::hcWaitModeActive); event->locked_waitComplete((event->_flags & hipEventBlockingSync) ? hc::hcWaitModeBlocked : hc::hcWaitModeActive);
assert (event->_marker.is_ready());
return ihipLogStatus(hipSuccess); return ihipLogStatus(hipSuccess);
} }
@@ -259,7 +268,7 @@ hipError_t hipEventQuery(hipEvent_t event)
{ {
HIP_INIT_SPECIAL_API(TRACE_QUERY, event); HIP_INIT_SPECIAL_API(TRACE_QUERY, event);
if ((event->_state == hipEventStatusRecording) && (!event->_marker.is_ready())) { if ((event->_state == hipEventStatusRecording) && !event->locked_isReady()) {
return ihipLogStatus(hipErrorNotReady); return ihipLogStatus(hipErrorNotReady);
} else { } else {
return ihipLogStatus(hipSuccess); return ihipLogStatus(hipSuccess);
+23 -3
Ver fichero
@@ -328,14 +328,34 @@ void ihipStream_t::locked_wait()
// Causes current stream to wait for specified event to complete: // Causes current stream to wait for specified event to complete:
// Note this does not provide any kind of host serialization. // Note this does not provide any kind of host serialization.
void ihipStream_t::locked_waitEvent(hipEvent_t event) void ihipStream_t::locked_streamWaitEvent(hipEvent_t event)
{ {
LockedAccessor_StreamCrit_t crit(_criticalData); LockedAccessor_StreamCrit_t crit(_criticalData);
crit->_av.create_blocking_marker(event->_marker, hc::accelerator_scope); crit->_av.create_blocking_marker(event->marker(), hc::accelerator_scope);
} }
// Causes current stream to wait for specified event to complete:
// Note this does not provide any kind of host serialization.
bool ihipStream_t::locked_eventIsReady(hipEvent_t event)
{
// Event query that returns "Complete" may cause HCC to manipulate
// internal queue state so lock the stream's queue here.
LockedAccessor_StreamCrit_t crit(_criticalData);
return (event->marker().is_ready());
}
void ihipStream_t::locked_eventWaitComplete(hipEvent_t event, hc::hcWaitMode waitMode)
{
LockedAccessor_StreamCrit_t crit(_criticalData);
event->marker().wait(waitMode);
}
// Create a marker in this stream. // Create a marker in this stream.
// Save state in the event so it can track the status of the event. // Save state in the event so it can track the status of the event.
void ihipStream_t::locked_recordEvent(hipEvent_t event) void ihipStream_t::locked_recordEvent(hipEvent_t event)
@@ -354,7 +374,7 @@ void ihipStream_t::locked_recordEvent(hipEvent_t event)
scopeFlag = HIP_EVENT_SYS_RELEASE ? hc::system_scope : hc::accelerator_scope; scopeFlag = HIP_EVENT_SYS_RELEASE ? hc::system_scope : hc::accelerator_scope;
} }
event->_marker = crit->_av.create_marker(scopeFlag); event->marker(crit->_av.create_marker(scopeFlag));
}; };
//============================================================================= //=============================================================================
+12 -3
Ver fichero
@@ -517,9 +517,12 @@ public:
hc::accelerator_view* locked_getAv() { LockedAccessor_StreamCrit_t crit(_criticalData); return &(crit->_av); }; hc::accelerator_view* locked_getAv() { LockedAccessor_StreamCrit_t crit(_criticalData); return &(crit->_av); };
void locked_waitEvent(hipEvent_t event); void locked_streamWaitEvent(hipEvent_t event);
void locked_recordEvent(hipEvent_t event); void locked_recordEvent(hipEvent_t event);
bool locked_eventIsReady(hipEvent_t event);
void locked_eventWaitComplete(hipEvent_t event, hc::hcWaitMode waitMode);
ihipStreamCritical_t &criticalData() { return _criticalData; }; ihipStreamCritical_t &criticalData() { return _criticalData; };
//--- //---
@@ -608,18 +611,24 @@ public:
ihipEvent_t(unsigned flags); ihipEvent_t(unsigned flags);
void attachToCompletionFuture(const hc::completion_future *cf, hipStream_t stream, ihipEventType_t eventType); void attachToCompletionFuture(const hc::completion_future *cf, hipStream_t stream, ihipEventType_t eventType);
void refereshEventStatus(); void refereshEventStatus();
hc::completion_future & marker() { return _marker; }
void marker(hc::completion_future cf) { _marker = cf; };
bool locked_isReady();
void locked_waitComplete(hc::hcWaitMode waitMode);
uint64_t timestamp() const { return _timestamp; } ; uint64_t timestamp() const { return _timestamp; } ;
ihipEventType_t type() const { return _type; }; ihipEventType_t type() const { return _type; };
public: public:
hipEventStatus_t _state; hipEventStatus_t _state;
hipStream_t _stream; // Stream where the event is recorded, or NULL if all streams. hipStream_t _stream; // Stream where the event is recorded. Null stream is resolved to actual stream when recorded
unsigned _flags; unsigned _flags;
hc::completion_future _marker;
private: private:
hc::completion_future _marker;
ihipEventType_t _type; ihipEventType_t _type;
uint64_t _timestamp; // store timestamp, may be set on host or by marker. uint64_t _timestamp; // store timestamp, may be set on host or by marker.
friend hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream); friend hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream);
+1 -1
Ver fichero
@@ -96,7 +96,7 @@ hipError_t hipStreamWaitEvent(hipStream_t stream, hipEvent_t event, unsigned int
if (stream != hipStreamNull) { if (stream != hipStreamNull) {
// This will user create_blocking_marker to wait on the specified queue. // This will user create_blocking_marker to wait on the specified queue.
stream->locked_waitEvent(event); stream->locked_streamWaitEvent(event);
} else { } else {
// TODO-hcc Convert to use create_blocking_marker(...) functionality. // TODO-hcc Convert to use create_blocking_marker(...) functionality.