Fix elapsed time calculation for null stream

SWDEV-237377 - This fixes time calculation where the event may
be recorded on Null stream and work submitted on other streams

Change-Id: Ie36310dea5cee2fed4a514ed01f04db4b47e571c
Этот коммит содержится в:
Saleel Kudchadker
2020-05-27 00:36:27 -07:00
родитель f6addba699
Коммит fb2d7bcd2b
3 изменённых файлов: 27 добавлений и 9 удалений
+17 -5
Просмотреть файл
@@ -90,11 +90,22 @@ hipError_t Event::elapsedTime(Event& eStop, float& ms) {
return hipErrorNotReady;
}
// For certain HIP Api's that take start and stop event
// the command is the same
if (event_ == eStop.event_) {
// For certain HIP API's that take start and stop event
// and no hipEventRecord needs to be called
if (event_ == eStop.event_ && !recorded_ && !eStop.recorded_) {
ms = static_cast<float>(static_cast<int64_t>(eStop.event_->profilingInfo().end_ -
event_->profilingInfo().start_))/1000000.f;
} else if (event_ == eStop.event_) {
// Events are the same, which indicates the stream is empty and likely
// eventRecord is called on another stream. For such cases insert and measure a
// marker.
amd::Command* command = new amd::Marker(*event_->command().queue(), false);
command->enqueue();
command->awaitCompletion();
ms = static_cast<float>(static_cast<int64_t>(command->event().profilingInfo().end_ -
event_->profilingInfo().end_))/1000000.f;
command->release();
} else {
ms = static_cast<float>(static_cast<int64_t>(eStop.event_->profilingInfo().end_ -
event_->profilingInfo().end_))/1000000.f;
@@ -126,7 +137,7 @@ hipError_t Event::streamWait(amd::HostQueue* hostQueue, uint flags) {
return hipSuccess;
}
void Event::addMarker(amd::HostQueue* queue, amd::Command* command) {
void Event::addMarker(amd::HostQueue* queue, amd::Command* command, bool record) {
amd::ScopedLock lock(lock_);
if (event_ == &command->event()) return;
@@ -136,6 +147,7 @@ void Event::addMarker(amd::HostQueue* queue, amd::Command* command) {
}
event_ = &command->event();
recorded_ = record;
}
}
@@ -233,7 +245,7 @@ hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream) {
}
hip::Event* e = reinterpret_cast<hip::Event*>(event);
e->addMarker(queue, command);
e->addMarker(queue, command, true);
HIP_RETURN(hipSuccess);
}
+8 -2
Просмотреть файл
@@ -37,7 +37,8 @@ public:
class Event {
public:
Event(unsigned int flags) : flags(flags), lock_("hipEvent_t"), event_(nullptr) {
Event(unsigned int flags) : flags(flags), lock_("hipEvent_t"),
event_(nullptr), recorded_(false) {
// No need to init event_ here as addMarker does that
}
@@ -53,13 +54,18 @@ public:
hipError_t elapsedTime(Event& stop, float& ms);
hipError_t streamWait(amd::HostQueue* queue, uint flags);
void addMarker(amd::HostQueue* queue, amd::Command* command);
void addMarker(amd::HostQueue* queue, amd::Command* command, bool record);
private:
amd::Monitor lock_;
amd::HostQueue* stream_;
amd::Event* event_;
//! Flag to indicate hipEventRecord has been called. This is needed except for
//! hip*ModuleLaunchKernel API which takes start and stop events so no
//! hipEventRecord is called. Cleanup needed once those APIs are deprecated.
bool recorded_;
bool ready();
};
+2 -2
Просмотреть файл
@@ -458,11 +458,11 @@ hipError_t ihipModuleLaunchKernel(hipFunction_t f,
command->enqueue();
if(startEvent != nullptr) {
eStart->addMarker(queue, command);
eStart->addMarker(queue, command, false);
command->retain();
}
if(stopEvent != nullptr) {
eStop->addMarker(queue, command);
eStop->addMarker(queue, command, false);
command->retain();
}
command->release();