remove ihipEvent_t::refreshEventStatus(), new hipEventElapsedTime
This fixes possible races in hipEventElapsedTime.
[ROCm/hip commit: 7986090d9c]
This commit is contained in:
@@ -44,28 +44,22 @@ void ihipEvent_t::attachToCompletionFuture(const hc::completion_future* cf, hipS
|
||||
}
|
||||
|
||||
|
||||
std::pair<hipEventStatus_t, uint64_t> ihipEvent_t::refreshEventStatus() {
|
||||
auto ecd = locked_copyCrit();
|
||||
if (ecd._state == hipEventStatusRecording) {
|
||||
bool isReady1 = ecd._stream->locked_eventIsReady(this);
|
||||
if (isReady1) {
|
||||
LockedAccessor_EventCrit_t eCrit(_criticalData);
|
||||
|
||||
if ((eCrit->_eventData._type == hipEventTypeIndependent) ||
|
||||
(eCrit->_eventData._type == hipEventTypeStopCommand)) {
|
||||
eCrit->_eventData._timestamp = eCrit->_eventData.marker().get_end_tick();
|
||||
} else if (eCrit->_eventData._type == hipEventTypeStartCommand) {
|
||||
eCrit->_eventData._timestamp = eCrit->_eventData.marker().get_begin_tick();
|
||||
} else {
|
||||
eCrit->_eventData._timestamp = 0;
|
||||
assert(0); // TODO - move to debug assert
|
||||
}
|
||||
|
||||
eCrit->_eventData._state = hipEventStatusComplete;
|
||||
|
||||
return std::pair<hipEventStatus_t, uint64_t>(eCrit->_eventData._state,
|
||||
eCrit->_eventData._timestamp);
|
||||
static std::pair<hipEventStatus_t, uint64_t> refreshEventStatus(ihipEventData_t &ecd) {
|
||||
if (ecd._state == hipEventStatusRecording && ecd.marker().is_ready()) {
|
||||
if ((ecd._type == hipEventTypeIndependent) ||
|
||||
(ecd._type == hipEventTypeStopCommand)) {
|
||||
ecd._timestamp = ecd.marker().get_end_tick();
|
||||
} else if (ecd._type == hipEventTypeStartCommand) {
|
||||
ecd._timestamp = ecd.marker().get_begin_tick();
|
||||
} else {
|
||||
ecd._timestamp = 0;
|
||||
assert(0); // TODO - move to debug assert
|
||||
}
|
||||
|
||||
ecd._state = hipEventStatusComplete;
|
||||
|
||||
return std::pair<hipEventStatus_t, uint64_t>(ecd._state,
|
||||
ecd._timestamp);
|
||||
}
|
||||
|
||||
// Not complete path here:
|
||||
@@ -180,60 +174,49 @@ hipError_t hipEventSynchronize(hipEvent_t event) {
|
||||
hipError_t hipEventElapsedTime(float* ms, hipEvent_t start, hipEvent_t stop) {
|
||||
HIP_INIT_API(hipEventElapsedTime, ms, start, stop);
|
||||
|
||||
hipError_t status = hipSuccess;
|
||||
if (ms == nullptr) return ihipLogStatus(hipErrorInvalidValue);
|
||||
if ((start == nullptr) || (stop == nullptr)) return ihipLogStatus(hipErrorInvalidResourceHandle);
|
||||
|
||||
if (ms == nullptr) {
|
||||
status = hipErrorInvalidValue;
|
||||
*ms = 0.0f;
|
||||
auto startEcd = start->locked_copyCrit();
|
||||
auto stopEcd = stop->locked_copyCrit();
|
||||
|
||||
if ((start->_flags & hipEventDisableTiming) ||
|
||||
(startEcd._state == hipEventStatusUnitialized) ||
|
||||
(startEcd._state == hipEventStatusCreated) ||
|
||||
(stop->_flags & hipEventDisableTiming) ||
|
||||
(stopEcd._state == hipEventStatusUnitialized) ||
|
||||
(stopEcd._state == hipEventStatusCreated)) {
|
||||
// Both events must be at least recorded else return hipErrorInvalidResourceHandle
|
||||
return ihipLogStatus(hipErrorInvalidResourceHandle);
|
||||
}
|
||||
else if ((start == nullptr) || (stop == nullptr)) {
|
||||
status = hipErrorInvalidResourceHandle;
|
||||
} else {
|
||||
*ms = 0.0f;
|
||||
auto startEcd = start->locked_copyCrit();
|
||||
auto stopEcd = stop->locked_copyCrit();
|
||||
|
||||
if ((start->_flags & hipEventDisableTiming) ||
|
||||
(startEcd._state == hipEventStatusUnitialized) ||
|
||||
(startEcd._state == hipEventStatusCreated) || (stop->_flags & hipEventDisableTiming) ||
|
||||
(stopEcd._state == hipEventStatusUnitialized) ||
|
||||
(stopEcd._state == hipEventStatusCreated)) {
|
||||
// Both events must be at least recorded else return hipErrorInvalidResourceHandle
|
||||
// Refresh status, if still recording...
|
||||
|
||||
status = hipErrorInvalidResourceHandle;
|
||||
auto startStatus = refreshEventStatus(startEcd); // pair < state, timestamp >
|
||||
auto stopStatus = refreshEventStatus(stopEcd); // pair < state, timestamp >
|
||||
|
||||
if ((startStatus.first == hipEventStatusComplete) &&
|
||||
(stopStatus.first == hipEventStatusComplete)) {
|
||||
// Common case, we have good information for both events. 'second' is the timestamp:
|
||||
int64_t tickDiff = (stopStatus.second - startStatus.second);
|
||||
uint64_t freqHz;
|
||||
hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY, &freqHz);
|
||||
if (freqHz) {
|
||||
*ms = ((double)(tickDiff) / (double)(freqHz)) * 1000.0f;
|
||||
return ihipLogStatus(hipSuccess);
|
||||
} else {
|
||||
// Refresh status, if still recording...
|
||||
|
||||
auto startStatus = start->refreshEventStatus(); // pair < state, timestamp >
|
||||
auto stopStatus = stop->refreshEventStatus(); // pair < state, timestamp >
|
||||
|
||||
if ((startStatus.first == hipEventStatusComplete) &&
|
||||
(stopStatus.first == hipEventStatusComplete)) {
|
||||
// Common case, we have good information for both events. 'second" is the
|
||||
// timestamp:
|
||||
int64_t tickDiff = (stopStatus.second - startStatus.second);
|
||||
|
||||
uint64_t freqHz;
|
||||
hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP_FREQUENCY, &freqHz);
|
||||
if (freqHz) {
|
||||
*ms = ((double)(tickDiff) / (double)(freqHz)) * 1000.0f;
|
||||
status = hipSuccess;
|
||||
} else {
|
||||
*ms = 0.0f;
|
||||
status = hipErrorInvalidValue;
|
||||
}
|
||||
|
||||
|
||||
} else if ((startStatus.first == hipEventStatusRecording) ||
|
||||
(stopStatus.first == hipEventStatusRecording)) {
|
||||
status = hipErrorNotReady;
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
*ms = 0.0f;
|
||||
return ihipLogStatus(hipErrorInvalidValue);
|
||||
}
|
||||
} else if ((startStatus.first == hipEventStatusRecording) ||
|
||||
(stopStatus.first == hipEventStatusRecording)) {
|
||||
return ihipLogStatus(hipErrorNotReady);
|
||||
} else {
|
||||
assert(0); // TODO should we return hipErrorUnknown ?
|
||||
}
|
||||
|
||||
return ihipLogStatus(status);
|
||||
return ihipLogStatus(hipSuccess);
|
||||
}
|
||||
|
||||
hipError_t hipEventQuery(hipEvent_t event) {
|
||||
|
||||
@@ -724,8 +724,6 @@ class ihipEvent_t {
|
||||
explicit ihipEvent_t(unsigned flags);
|
||||
void attachToCompletionFuture(const hc::completion_future* cf, hipStream_t stream,
|
||||
ihipEventType_t eventType);
|
||||
std::pair<hipEventStatus_t, uint64_t> refreshEventStatus(); // returns pair <state, timestamp>
|
||||
|
||||
|
||||
// Return a copy of the critical state. The critical data is locked during the copy.
|
||||
ihipEventData_t locked_copyCrit() {
|
||||
|
||||
Fai riferimento in un nuovo problema
Block a user