mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
Destroy all GraphicsAllocation in ~MemObj
Related-To: NEO-4672 Change-Id: I4fa09ae7753ed258f489b9e9f328d0a455e7d9b6 Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
d46ac4b420
commit
cb5ab704b6
@@ -99,7 +99,6 @@ cl_mem Buffer::validateInputAndCreateBuffer(cl_context context,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int &retVal) {
|
||||
|
||||
Context *pContext = nullptr;
|
||||
retVal = validateObjects(WithCastToInternal(context, &pContext));
|
||||
if (retVal != CL_SUCCESS) {
|
||||
@@ -335,7 +334,9 @@ Buffer *Buffer::create(Context *context,
|
||||
|
||||
Buffer::provideCompressionHint(allocationType, context, pBuffer);
|
||||
|
||||
pBuffer->mapAllocation = mapAllocation;
|
||||
if (mapAllocation) {
|
||||
pBuffer->mapAllocations.addAllocation(mapAllocation);
|
||||
}
|
||||
pBuffer->setHostPtrMinSize(size);
|
||||
|
||||
if (copyMemoryFromHostPtr) {
|
||||
@@ -627,7 +628,6 @@ Buffer *Buffer::createBufferHwFromDevice(const Device *device,
|
||||
bool zeroCopy,
|
||||
bool isHostPtrSVM,
|
||||
bool isImageRedescribed) {
|
||||
|
||||
const auto &hwInfo = device->getHardwareInfo();
|
||||
|
||||
auto funcCreate = bufferFactory[hwInfo.platform.eRenderCoreFamily].createBufferFunction;
|
||||
|
||||
@@ -418,7 +418,9 @@ Image *Image::create(Context *context,
|
||||
}
|
||||
}
|
||||
|
||||
image->mapAllocation = mapAllocation;
|
||||
if (mapAllocation) {
|
||||
image->mapAllocations.addAllocation(mapAllocation);
|
||||
}
|
||||
|
||||
if (errcodeRet != CL_SUCCESS) {
|
||||
image->release();
|
||||
|
||||
@@ -42,8 +42,8 @@ MemObj::MemObj(Context *context,
|
||||
: context(context), memObjectType(memObjectType), memoryProperties(memoryProperties), flags(flags), flagsIntel(flagsIntel), size(size),
|
||||
memoryStorage(memoryStorage), hostPtr(hostPtr),
|
||||
isZeroCopy(zeroCopy), isHostPtrSVM(isHostPtrSVM), isObjectRedescribed(isObjectRedescribed),
|
||||
multiGraphicsAllocation(std::move(multiGraphicsAllocation)) {
|
||||
|
||||
multiGraphicsAllocation(std::move(multiGraphicsAllocation)),
|
||||
mapAllocations(static_cast<uint32_t>(this->multiGraphicsAllocation.getGraphicsAllocations().size() - 1)) {
|
||||
if (context) {
|
||||
context->incRefInternal();
|
||||
memoryManager = context->getMemoryManager();
|
||||
@@ -58,6 +58,7 @@ MemObj::~MemObj() {
|
||||
}
|
||||
|
||||
bool needWait = false;
|
||||
|
||||
if (allocatedMapPtr != nullptr) {
|
||||
needWait = true;
|
||||
}
|
||||
@@ -72,35 +73,37 @@ MemObj::~MemObj() {
|
||||
if (peekSharingHandler()) {
|
||||
peekSharingHandler()->releaseReusedGraphicsAllocation();
|
||||
}
|
||||
auto graphicsAllocation = multiGraphicsAllocation.getDefaultGraphicsAllocation();
|
||||
if (graphicsAllocation && !associatedMemObject && !isHostPtrSVM && graphicsAllocation->peekReuseCount() == 0) {
|
||||
memoryManager->removeAllocationFromHostPtrManager(graphicsAllocation);
|
||||
bool doAsyncDestructions = DebugManager.flags.EnableAsyncDestroyAllocations.get();
|
||||
if (!doAsyncDestructions) {
|
||||
needWait = true;
|
||||
}
|
||||
if (needWait && graphicsAllocation->isUsed()) {
|
||||
memoryManager->waitForEnginesCompletion(*graphicsAllocation);
|
||||
}
|
||||
destroyGraphicsAllocation(graphicsAllocation, doAsyncDestructions);
|
||||
graphicsAllocation = nullptr;
|
||||
}
|
||||
|
||||
for (auto graphicsAllocation : multiGraphicsAllocation.getGraphicsAllocations()) {
|
||||
auto rootDeviceIndex = graphicsAllocation ? graphicsAllocation->getRootDeviceIndex() : 0;
|
||||
if (graphicsAllocation && !associatedMemObject && !isHostPtrSVM && graphicsAllocation->peekReuseCount() == 0) {
|
||||
memoryManager->removeAllocationFromHostPtrManager(graphicsAllocation);
|
||||
bool doAsyncDestructions = DebugManager.flags.EnableAsyncDestroyAllocations.get();
|
||||
if (!doAsyncDestructions) {
|
||||
needWait = true;
|
||||
}
|
||||
if (needWait && graphicsAllocation->isUsed()) {
|
||||
memoryManager->waitForEnginesCompletion(*graphicsAllocation);
|
||||
}
|
||||
destroyGraphicsAllocation(graphicsAllocation, doAsyncDestructions);
|
||||
graphicsAllocation = nullptr;
|
||||
}
|
||||
if (!associatedMemObject) {
|
||||
releaseMapAllocation(rootDeviceIndex);
|
||||
}
|
||||
if (mcsAllocation) {
|
||||
destroyGraphicsAllocation(mcsAllocation, false);
|
||||
}
|
||||
if (graphicsAllocation && associatedMemObject) {
|
||||
if (associatedMemObject->getGraphicsAllocation(graphicsAllocation->getRootDeviceIndex()) != graphicsAllocation) {
|
||||
destroyGraphicsAllocation(graphicsAllocation, false);
|
||||
}
|
||||
associatedMemObject->decRefInternal();
|
||||
}
|
||||
}
|
||||
if (!associatedMemObject) {
|
||||
releaseMapAllocation();
|
||||
releaseAllocatedMapPtr();
|
||||
}
|
||||
if (mcsAllocation) {
|
||||
destroyGraphicsAllocation(mcsAllocation, false);
|
||||
}
|
||||
|
||||
if (associatedMemObject) {
|
||||
UNRECOVERABLE_IF(!graphicsAllocation);
|
||||
if (associatedMemObject->getGraphicsAllocation(graphicsAllocation->getRootDeviceIndex()) != graphicsAllocation) {
|
||||
destroyGraphicsAllocation(graphicsAllocation, false);
|
||||
}
|
||||
associatedMemObject->decRefInternal();
|
||||
}
|
||||
}
|
||||
if (!destructorCallbacks.empty()) {
|
||||
for (auto iter = destructorCallbacks.rbegin(); iter != destructorCallbacks.rend(); iter++) {
|
||||
@@ -315,9 +318,9 @@ void MemObj::releaseAllocatedMapPtr() {
|
||||
allocatedMapPtr = nullptr;
|
||||
}
|
||||
|
||||
void MemObj::releaseMapAllocation() {
|
||||
if (mapAllocation && !isHostPtrSVM) {
|
||||
destroyGraphicsAllocation(mapAllocation, false);
|
||||
void MemObj::releaseMapAllocation(uint32_t rootDeviceIndex) {
|
||||
if (mapAllocations.getGraphicsAllocation(rootDeviceIndex) && !isHostPtrSVM) {
|
||||
destroyGraphicsAllocation(mapAllocations.getGraphicsAllocation(rootDeviceIndex), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,8 +350,8 @@ void *MemObj::getBasePtrForMap(uint32_t rootDeviceIndex) {
|
||||
return getHostPtr();
|
||||
} else {
|
||||
TakeOwnershipWrapper<MemObj> memObjOwnership(*this);
|
||||
if (getMapAllocation()) {
|
||||
return getMapAllocation()->getUnderlyingBuffer();
|
||||
if (getMapAllocation(rootDeviceIndex)) {
|
||||
return getMapAllocation(rootDeviceIndex)->getUnderlyingBuffer();
|
||||
} else {
|
||||
auto memory = memoryManager->allocateSystemMemory(getSize(), MemoryConstants::pageSize);
|
||||
setAllocatedMapPtr(memory);
|
||||
|
||||
@@ -75,7 +75,7 @@ class MemObj : public BaseObject<_cl_mem> {
|
||||
|
||||
void setHostPtrMinSize(size_t size);
|
||||
void releaseAllocatedMapPtr();
|
||||
void releaseMapAllocation();
|
||||
void releaseMapAllocation(uint32_t rootDeviceIndex);
|
||||
|
||||
bool isMemObjZeroCopy() const;
|
||||
bool isMemObjWithHostPtrSVM() const;
|
||||
@@ -117,13 +117,13 @@ class MemObj : public BaseObject<_cl_mem> {
|
||||
return memoryManager;
|
||||
}
|
||||
void setMapAllocation(GraphicsAllocation *allocation) {
|
||||
mapAllocation = allocation;
|
||||
mapAllocations.addAllocation(allocation);
|
||||
}
|
||||
GraphicsAllocation *getMapAllocation() const {
|
||||
GraphicsAllocation *getMapAllocation(uint32_t rootDeviceIndex) const {
|
||||
if (associatedMemObject) {
|
||||
return associatedMemObject->getMapAllocation();
|
||||
return associatedMemObject->getMapAllocation(rootDeviceIndex);
|
||||
}
|
||||
return mapAllocation;
|
||||
return mapAllocations.getGraphicsAllocation(rootDeviceIndex);
|
||||
}
|
||||
|
||||
const cl_mem_flags &getFlags() const { return flags; }
|
||||
@@ -156,7 +156,7 @@ class MemObj : public BaseObject<_cl_mem> {
|
||||
MemoryManager *memoryManager = nullptr;
|
||||
MultiGraphicsAllocation multiGraphicsAllocation;
|
||||
GraphicsAllocation *mcsAllocation = nullptr;
|
||||
GraphicsAllocation *mapAllocation = nullptr;
|
||||
MultiGraphicsAllocation mapAllocations;
|
||||
std::shared_ptr<SharingHandler> sharingHandler;
|
||||
std::vector<uint64_t> propertiesVector;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user