SWDEV-430437,SWDEV-434702 - Split the streamset per device

Change-Id: If1bcca45825c9899462bb95ed6f637f5af806cc8
This commit is contained in:
Ioannis Assiouras
2024-02-06 00:34:35 +00:00
والد 1239309c90
کامیت be2bdabb76
6فایلهای تغییر یافته به همراه175 افزوده شده و 144 حذف شده
+141 -2
مشاهده پرونده
@@ -43,7 +43,7 @@ hip::Stream* Device::NullStream(bool wait) {
}
if (wait == true) {
// Wait for all active streams before executing commands on the default
iHipWaitActiveStreams(null_stream_);
WaitActiveStreams(null_stream_);
}
return null_stream_;
}
@@ -149,11 +149,150 @@ void Device::Reset() {
mem_pools_.clear();
}
flags_ = hipDeviceScheduleSpin;
hip::Stream::destroyAllStreams(deviceId_);
destroyAllStreams();
amd::MemObjMap::Purge(devices()[0]);
Create();
}
// ================================================================================================
void Device::WaitActiveStreams(hip::Stream* blocking_stream, bool wait_null_stream) {
amd::Command::EventWaitList eventWaitList(0);
bool submitMarker = 0;
auto waitForStream = [&submitMarker,
&eventWaitList](hip::Stream* stream) {
if (amd::Command *command = stream->getLastQueuedCommand(true)) {
amd::Event &event = command->event();
// Check HW status of the ROCcrl event.
// Note: not all ROCclr modes support HW status
bool ready = stream->device().IsHwEventReady(event);
if (!ready) {
ready = (command->status() == CL_COMPLETE);
}
submitMarker |= stream->vdev()->isFenceDirty();
// Check the current active status
if (!ready) {
command->notifyCmdQueue();
eventWaitList.push_back(command);
} else {
command->release();
}
}
};
if (wait_null_stream) {
if (null_stream_) {
waitForStream(null_stream_);
}
} else {
amd::ScopedLock lock(streamSetLock);
for (const auto& active_stream : streamSet) {
// If it's the current device
if (// Make sure it's a default stream
((active_stream->Flags() & hipStreamNonBlocking) == 0) &&
// and it's not the current stream
(active_stream != blocking_stream)) {
// Get the last valid command
waitForStream(active_stream);
}
}
}
// Check if we have to wait anything
if (eventWaitList.size() > 0 || submitMarker) {
amd::Command* command = new amd::Marker(*blocking_stream, kMarkerDisableFlush, eventWaitList);
if (command != nullptr) {
command->enqueue();
command->release();
}
}
// Release all active commands. It's safe after the marker was enqueued
for (const auto& it : eventWaitList) {
it->release();
}
}
// ================================================================================================
void Device::AddStream(Stream* stream) {
amd::ScopedLock lock(streamSetLock);
streamSet.insert(stream);
}
// ================================================================================================
void Device::RemoveStream(Stream* stream){
amd::ScopedLock lock(streamSetLock);
streamSet.erase(stream);
}
// ================================================================================================
bool Device::StreamExists(Stream* stream){
amd::ScopedLock lock(streamSetLock);
if (streamSet.find(stream) != streamSet.end()) {
return true;
}
return false;
}
// ================================================================================================
void Device::destroyAllStreams() {
std::vector<Stream*> toBeDeleted;
{
amd::ScopedLock lock(streamSetLock);
for (auto& it : streamSet) {
if (it->Null() == false ) {
toBeDeleted.push_back(it);
}
}
}
for (auto& it : toBeDeleted) {
hip::Stream::Destroy(it);
}
}
// ================================================================================================
void Device::SyncAllStreams( bool cpu_wait) {
// Make a local copy to avoid stalls for GPU finish with multiple threads
std::vector<hip::Stream*> streams;
streams.reserve(streamSet.size());
{
amd::ScopedLock lock(streamSetLock);
for (auto it : streamSet) {
streams.push_back(it);
it->retain();
}
}
for (auto it : streams) {
it->finish(cpu_wait);
it->release();
}
// Release freed memory for all memory pools on the device
ReleaseFreedMemory();
}
// ================================================================================================
bool Device::StreamCaptureBlocking() {
amd::ScopedLock lock(streamSetLock);
for (auto& it : streamSet) {
if (it->GetCaptureStatus() == hipStreamCaptureStatusActive && it->Flags() != hipStreamNonBlocking) {
return true;
}
}
return false;
}
// ================================================================================================
bool Device::existsActiveStreamForDevice() {
amd::ScopedLock lock(streamSetLock);
for (const auto& active_stream : streamSet) {
if (active_stream->GetQueueStatus()) {
return true;
}
}
return false;
}
// ================================================================================================
Device::~Device() {
if (default_mem_pool_ != nullptr) {