diff --git a/rocclr/hip_event.cpp b/rocclr/hip_event.cpp index 2e4870834f..584a133613 100644 --- a/rocclr/hip_event.cpp +++ b/rocclr/hip_event.cpp @@ -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(static_cast(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(static_cast(command->event().profilingInfo().end_ - + event_->profilingInfo().end_))/1000000.f; + command->release(); + } else { ms = static_cast(static_cast(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(event); - e->addMarker(queue, command); + e->addMarker(queue, command, true); HIP_RETURN(hipSuccess); } diff --git a/rocclr/hip_event.hpp b/rocclr/hip_event.hpp index 2360c972bb..78e081d4dc 100644 --- a/rocclr/hip_event.hpp +++ b/rocclr/hip_event.hpp @@ -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(); }; diff --git a/rocclr/hip_module.cpp b/rocclr/hip_module.cpp index 3a51001063..8ae9ad799c 100755 --- a/rocclr/hip_module.cpp +++ b/rocclr/hip_module.cpp @@ -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();