SWDEV-311271 - Add dependency tracking for streams
Mempool has capability to track dependency between streams for
faster memory reuse. Enable that capability.
Change-Id: I28266a7e38d0fc4c5d027b9542d3719653840821
[ROCm/clr commit: 17d0c166d2]
Этот коммит содержится в:
@@ -127,6 +127,15 @@ void Device::RemoveStreamFromPools(Stream* stream) {
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Device::AddSafeStream(Stream* event_stream, Stream* wait_stream) {
|
||||
amd::ScopedLock lock(lock_);
|
||||
// Update all pools with the safe streams
|
||||
for (auto it : mem_pools_) {
|
||||
it->AddSafeStream(event_stream, wait_stream);
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Device::Reset() {
|
||||
{
|
||||
|
||||
@@ -535,6 +535,9 @@ public:
|
||||
/// Removes a destroyed stream from the safe list of memory pools
|
||||
void RemoveStreamFromPools(Stream* stream);
|
||||
|
||||
/// Add safe streams into the memppools for reuse
|
||||
void AddSafeStream(Stream* event_stream, Stream* wait_stream);
|
||||
|
||||
/// Returns true if memory pool is valid on this device
|
||||
bool IsMemoryPoolValid(MemoryPool* pool);
|
||||
};
|
||||
|
||||
@@ -46,9 +46,15 @@ struct MemoryTimestamp {
|
||||
MemoryTimestamp(): event_(nullptr) {}
|
||||
|
||||
/// Adds a safe stream to the list of stream for possible reuse
|
||||
void AddSafeStream(hip::Stream* stream) {
|
||||
if (safe_streams_.find(stream) != safe_streams_.end()) {
|
||||
safe_streams_.insert(stream);
|
||||
void AddSafeStream(Stream* event_stream, Stream* wait_stream = nullptr) {
|
||||
if (wait_stream == nullptr) {
|
||||
if (safe_streams_.find(event_stream) == safe_streams_.end()) {
|
||||
safe_streams_.insert(event_stream);
|
||||
}
|
||||
} else {
|
||||
if (safe_streams_.find(event_stream) != safe_streams_.end()) {
|
||||
safe_streams_.insert(wait_stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Changes last known valid event asociated with memory
|
||||
@@ -144,6 +150,14 @@ public:
|
||||
/// Erases single allocation form the heap's map
|
||||
SortedMap::iterator EraseAllocaton(SortedMap::iterator& it);
|
||||
|
||||
/// Add a safe stream for quick looks-ups in all allocations
|
||||
void AddSafeStream(Stream* event_stream, Stream* wait_stream) {
|
||||
for (auto& it : allocations_) {
|
||||
it.second.AddSafeStream(event_stream, wait_stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Checks if memory belongs to this heap
|
||||
bool IsActiveMemory(amd::Memory* memory) const {
|
||||
return (allocations_.find({memory->getSize(), memory}) != allocations_.end());
|
||||
@@ -233,6 +247,14 @@ class MemoryPool : public amd::ReferenceCountedObject {
|
||||
void AddBusyMemory(amd::Memory* memory) {
|
||||
busy_heap_.AddMemory(memory, nullptr);
|
||||
}
|
||||
|
||||
/// Add a safe stream for quick looks-ups if event dependencies option is enabled
|
||||
void AddSafeStream(Stream* event_stream, Stream* wait_stream) {
|
||||
if (EventDependencies()) {
|
||||
free_heap_.AddSafeStream(event_stream, wait_stream);
|
||||
}
|
||||
}
|
||||
|
||||
/// Trims the pool until it has only min_bytes_to_hold
|
||||
void TrimTo(size_t min_bytes_to_hold);
|
||||
|
||||
|
||||
@@ -553,10 +553,14 @@ hipError_t hipStreamWaitEvent_common(hipStream_t stream, hipEvent_t event, unsig
|
||||
if (flags != 0) {
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
if ((eventStream != nullptr) &&
|
||||
(eventStream->GetCaptureStatus() == hipStreamCaptureStatusActive)) {
|
||||
// If stream is capturing but event is not recorded on event's stream.
|
||||
return hipErrorStreamCaptureIsolation;
|
||||
if (eventStream != nullptr) {
|
||||
if (eventStream->GetCaptureStatus() == hipStreamCaptureStatusActive) {
|
||||
// If stream is capturing but event is not recorded on event's stream.
|
||||
return hipErrorStreamCaptureIsolation;
|
||||
}
|
||||
if (eventStream->DeviceId() == waitStream->DeviceId()) {
|
||||
eventStream->GetDevice()->AddSafeStream(eventStream, waitStream);
|
||||
}
|
||||
}
|
||||
status = e->streamWait(stream, flags);
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user