diff --git a/projects/clr/hipamd/rocclr/hip_event.cpp b/projects/clr/hipamd/rocclr/hip_event.cpp index 6bd2056cbc..e5043bc763 100755 --- a/projects/clr/hipamd/rocclr/hip_event.cpp +++ b/projects/clr/hipamd/rocclr/hip_event.cpp @@ -97,32 +97,30 @@ hipError_t Event::elapsedTime(Event& eStop, float& ms) { return hipErrorNotReady; } - if (event_ != eStop.event_ && recorded_ && eStop.recorded_) { - ms = static_cast(static_cast(eStop.event_->profilingInfo().end_ - - event_->profilingInfo().end_))/1000000.f; - } else if (event_ != eStop.event_ && !recorded_ && !eStop.recorded_) { - //It is invalid to use unrecorded events across multiple commands to get time - //For example start and stop events from different hipExtLaunchKernelGGL calls - return hipErrorInvalidHandle; - } else if (event_ == eStop.event_ && (recorded_ || eStop.recorded_)) { + if (event_ == eStop.event_ && recorded_ && eStop.recorded_) { // 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(), kMarkerDisableFlush); command->enqueue(); command->awaitCompletion(); - ms = static_cast(static_cast(command->event().profilingInfo().end_ - - event_->profilingInfo().end_))/1000000.f; + ms = static_cast(static_cast(command->event().profilingInfo().end_) - time())/1000000.f; command->release(); } else { - // For certain HIP API's that take both start and stop event - // or scenarios where HIP API takes one of the events and the other event is recorded with hipEventRecord - ms = static_cast(static_cast(eStop.event_->profilingInfo().end_ - - event_->profilingInfo().start_))/1000000.f; + ms = static_cast(eStop.time() - time())/1000000.f; } return hipSuccess; } +int64_t Event::time() const { + assert(event_ != nullptr); + if (recorded_) { + return static_cast(event_->profilingInfo().end_); + } else { + return static_cast(event_->profilingInfo().start_); + } +} + hipError_t Event::streamWait(amd::HostQueue* hostQueue, uint flags) { if ((event_ == nullptr) || (event_->command().queue() == hostQueue)) { return hipSuccess; diff --git a/projects/clr/hipamd/rocclr/hip_event.hpp b/projects/clr/hipamd/rocclr/hip_event.hpp index 71a6c44b10..e63ee84be8 100644 --- a/projects/clr/hipamd/rocclr/hip_event.hpp +++ b/projects/clr/hipamd/rocclr/hip_event.hpp @@ -112,6 +112,7 @@ private: bool recorded_; bool ready(); + int64_t time() const; }; }; diff --git a/projects/clr/hipamd/rocclr/hip_module.cpp b/projects/clr/hipamd/rocclr/hip_module.cpp index 6d5f902cb9..b79ad4385f 100755 --- a/projects/clr/hipamd/rocclr/hip_module.cpp +++ b/projects/clr/hipamd/rocclr/hip_module.cpp @@ -390,7 +390,7 @@ hipError_t ihipModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX, command->retain(); } if (stopEvent != nullptr) { - eStop->addMarker(queue, command, false); + eStop->addMarker(queue, command, true); command->retain(); } command->release();