SWDEV-363369 - Elapsed time needs only stop event timings if both start and stop events are recorded
Change-Id: I91c9ce79aacf1014ae77600d1250cfccd9dd6039
Этот коммит содержится в:
@@ -128,14 +128,14 @@ hipError_t Event::elapsedTime(Event& eStop, float& ms) {
|
||||
return hipErrorNotReady;
|
||||
}
|
||||
|
||||
if (event_ == eStop.event_ && recorded_ && eStop.isRecorded()) {
|
||||
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(), kMarkerDisableFlush);
|
||||
command->enqueue();
|
||||
command->awaitCompletion();
|
||||
ms = static_cast<float>(static_cast<int64_t>(command->event().profilingInfo().end_) - time()) /
|
||||
ms = static_cast<float>(static_cast<int64_t>(command->event().profilingInfo().end_) - time(false)) /
|
||||
1000000.f;
|
||||
command->release();
|
||||
} else {
|
||||
@@ -143,32 +143,37 @@ hipError_t Event::elapsedTime(Event& eStop, float& ms) {
|
||||
// Hence for now make sure CPU status is updated by calling awaitCompletion();
|
||||
awaitEventCompletion();
|
||||
eStop.awaitEventCompletion();
|
||||
ms = static_cast<float>(eStop.time() - time()) / 1000000.f;
|
||||
if (unrecorded_ && eStop.isUnRecorded()) {
|
||||
// Both the events are not recorded, just need the end and start of stop event
|
||||
ms = static_cast<float>(eStop.time(false) - eStop.time(true)) / 1000000.f;
|
||||
} else {
|
||||
ms = static_cast<float>(eStop.time(false) - time(false)) / 1000000.f;
|
||||
}
|
||||
}
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
int64_t Event::time() const {
|
||||
int64_t Event::time(bool getStartTs) const {
|
||||
assert(event_ != nullptr);
|
||||
if (recorded_) {
|
||||
return static_cast<int64_t>(event_->profilingInfo().end_);
|
||||
} else {
|
||||
if (getStartTs) {
|
||||
return static_cast<int64_t>(event_->profilingInfo().start_);
|
||||
} else {
|
||||
return static_cast<int64_t>(event_->profilingInfo().end_);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t EventDD::time() const {
|
||||
int64_t EventDD::time(bool getStartTs) const {
|
||||
uint64_t start = 0, end = 0;
|
||||
assert(event_ != nullptr);
|
||||
g_devices[deviceId()]->devices()[0]->getHwEventTime(*event_, &start, &end);
|
||||
// FIXME: This is only needed if the command had to wait CL_COMPLETE status
|
||||
if (start == 0 || end == 0) {
|
||||
return Event::time();
|
||||
return Event::time(getStartTs);
|
||||
}
|
||||
if (recorded_) {
|
||||
return static_cast<int64_t>(end);
|
||||
} else {
|
||||
if (getStartTs) {
|
||||
return static_cast<int64_t>(start);
|
||||
} else {
|
||||
return static_cast<int64_t>(end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +243,7 @@ hipError_t Event::enqueueRecordCommand(hipStream_t stream, amd::Command* command
|
||||
event_->release();
|
||||
}
|
||||
event_ = &command->event();
|
||||
recorded_ = record;
|
||||
unrecorded_ = !record;
|
||||
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ class Event {
|
||||
|
||||
public:
|
||||
Event(unsigned int flags) : flags(flags), lock_("hipEvent_t", true),
|
||||
event_(nullptr), recorded_(false), stream_(nullptr) {
|
||||
event_(nullptr), unrecorded_(false), stream_(nullptr) {
|
||||
// No need to init event_ here as addMarker does that
|
||||
onCapture_ = false;
|
||||
device_id_ = hip::getCurrentDevice()->deviceId(); // Created in current device ctx
|
||||
@@ -131,11 +131,11 @@ class Event {
|
||||
event_->release();
|
||||
}
|
||||
event_ = &command.event();
|
||||
recorded_ = record;
|
||||
unrecorded_ = !record;
|
||||
command.retain();
|
||||
}
|
||||
|
||||
bool isRecorded() const { return recorded_; }
|
||||
bool isUnRecorded() const { return unrecorded_; }
|
||||
amd::Monitor& lock() { return lock_; }
|
||||
const int deviceId() const { return device_id_; }
|
||||
void setDeviceId(int id) { device_id_ = id; }
|
||||
@@ -171,17 +171,17 @@ class Event {
|
||||
}
|
||||
virtual bool awaitEventCompletion();
|
||||
virtual bool ready();
|
||||
virtual int64_t time() const;
|
||||
virtual int64_t time(bool getStartTs) const;
|
||||
|
||||
protected:
|
||||
amd::Monitor lock_;
|
||||
amd::HostQueue* stream_;
|
||||
amd::Event* event_;
|
||||
int device_id_;
|
||||
//! Flag to indicate hipEventRecord has been called. This is needed except for
|
||||
//! Flag to indicate hipEventRecord has not been called. This is needed 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 unrecorded_;
|
||||
};
|
||||
|
||||
class EventDD : public Event {
|
||||
@@ -191,7 +191,7 @@ class EventDD : public Event {
|
||||
|
||||
virtual bool awaitEventCompletion();
|
||||
virtual bool ready();
|
||||
virtual int64_t time() const;
|
||||
virtual int64_t time(bool getStartTs) const;
|
||||
};
|
||||
|
||||
class IPCEvent : public Event {
|
||||
|
||||
@@ -141,8 +141,8 @@ hipError_t IPCEvent::streamWait(hipStream_t stream, uint flags) {
|
||||
}
|
||||
|
||||
hipError_t IPCEvent::recordCommand(amd::Command*& command, amd::HostQueue* queue, uint32_t flags) {
|
||||
bool recorded = isRecorded();
|
||||
if (!recorded) {
|
||||
bool unrecorded = isUnRecorded();
|
||||
if (unrecorded) {
|
||||
command = new amd::Marker(*queue, kMarkerDisableFlush);
|
||||
} else {
|
||||
return Event::recordCommand(command, queue);
|
||||
@@ -152,8 +152,8 @@ hipError_t IPCEvent::recordCommand(amd::Command*& command, amd::HostQueue* queue
|
||||
|
||||
hipError_t IPCEvent::enqueueRecordCommand(hipStream_t stream, amd::Command* command, bool record) {
|
||||
amd::HostQueue* queue = hip::getQueue(stream);
|
||||
bool recorded = isRecorded();
|
||||
if (!recorded) {
|
||||
bool unrecorded = isUnRecorded();
|
||||
if (unrecorded) {
|
||||
amd::Event& tEvent = command->event();
|
||||
createIpcEventShmemIfNeeded();
|
||||
int write_index = ipc_evt_.ipc_shmem_->write_index++;
|
||||
|
||||
@@ -367,7 +367,7 @@ hipError_t ihipModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX,
|
||||
|
||||
if (startEvent != nullptr) {
|
||||
hip::Event* eStart = reinterpret_cast<hip::Event*>(startEvent);
|
||||
status = eStart->addMarker(hStream, nullptr, true);
|
||||
status = eStart->addMarker(hStream, nullptr, false);
|
||||
if (status != hipSuccess) {
|
||||
return status;
|
||||
}
|
||||
@@ -377,7 +377,7 @@ hipError_t ihipModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX,
|
||||
|
||||
if (stopEvent != nullptr) {
|
||||
hip::Event* eStop = reinterpret_cast<hip::Event*>(stopEvent);
|
||||
eStop->BindCommand(*command, true);
|
||||
eStop->BindCommand(*command, false);
|
||||
}
|
||||
command->release();
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user