SWDEV-224639 - Device memory is still occupied

- Add cache free on OCL context destroy
- Remove std::mem_fun() usage, since it was removed in c++17

Change-Id: If6acd08f13a2298912ecd78fc025dcf0b32aee54
Dieser Commit ist enthalten in:
German Andryeyev
2020-03-27 17:42:49 -04:00
Ursprung 7ef8dfdfe7
Commit 9f795d750d
4 geänderte Dateien mit 28 neuen und 14 gelöschten Zeilen
+3
Datei anzeigen
@@ -1423,6 +1423,9 @@ class Device : public RuntimeObject {
return false;
}
// Notifies device about context destroy
virtual void ContextDestroy() {}
//! Returns active wait state for this device
bool ActiveWait() const { return activeWait_; }
+5
Datei anzeigen
@@ -365,6 +365,11 @@ class Device : public NullDevice {
virtual bool unbindExternalDevice(uint flags, void* const pDevice[], void* pContext,
bool validateOnly);
//! Free resource cache on device if OCL context was destroyed.
//! @note: Backend device doesn't track resources per context and releases all resources, regardless
//! the number of still active contexts
virtual void ContextDestroy() { resourceCache().free(); }
//! Validates kernel before execution
virtual bool validateKernel(const amd::Kernel& kernel, //!< AMD kernel object
const device::VirtualDevice* vdev, bool coop_group = false);
+10 -8
Datei anzeigen
@@ -2187,7 +2187,7 @@ bool ResourceCache::free(size_t minCacheEntries) {
if (minCacheEntries < resCache_.size()) {
result = true;
// Clear the cache
while (static_cast<int>(cacheSize_) > 0) {
while (static_cast<int64_t>(cacheSize_) > 0) {
removeLast();
}
CondLog((cacheSize_ != 0), "Incorrect size for cache release!");
@@ -2201,14 +2201,16 @@ void ResourceCache::removeLast() {
{
// Protect access to the global data
amd::ScopedLock l(&lockCacheOps_);
entry = resCache_.back();
resCache_.pop_back();
cacheSize_ -= entry.second->iMem()->Desc().size;
if (entry.first->type_ == Resource::Local) {
lclCacheSize_ -= entry.second->iMem()->Desc().size;
if (resCache_.size() > 0) {
entry = resCache_.back();
resCache_.pop_back();
cacheSize_ -= entry.second->iMem()->Desc().size;
if (entry.first->type_ == Resource::Local) {
lclCacheSize_ -= entry.second->iMem()->Desc().size;
}
// Delete Descriptor
delete entry.first;
}
// Delete Descriptor
delete entry.first;
}
// Destroy PAL resource
+10 -6
Datei anzeigen
@@ -75,12 +75,18 @@ Context::Context(const std::vector<Device*>& devices, const Info& info)
Context::~Context() {
static const bool VALIDATE_ONLY = false;
// Dissociate OCL context with any external device
if (info_.flags_ & (GLDeviceKhr | D3D10DeviceKhr | D3D11DeviceKhr)) {
// Loop through all devices
for (const auto& it : devices_) {
// Loop through all devices
for (const auto& it : devices_) {
// Dissociate OCL context with any external device
if (info_.flags_ & (GLDeviceKhr | D3D10DeviceKhr | D3D11DeviceKhr)) {
it->unbindExternalDevice(info_.flags_, info_.hDev_, info_.hCtx_, VALIDATE_ONLY);
}
// Notify device about context destroy
it->ContextDestroy();
// Release device
it->release();
}
if (properties_ != NULL) {
@@ -91,8 +97,6 @@ Context::~Context() {
glenv_ = NULL;
}
std::for_each(devices_.begin(), devices_.end(), std::mem_fun(&Device::release));
#ifdef WITH_LIQUID_FLASH
lfTerminate();
#endif