@@ -42,8 +42,8 @@ MemObj::MemObj(Context *context,
4242 : context(context), memObjectType(memObjectType), memoryProperties(memoryProperties), flags(flags), flagsIntel(flagsIntel), size(size),
4343 memoryStorage (memoryStorage), hostPtr(hostPtr),
4444 isZeroCopy(zeroCopy), isHostPtrSVM(isHostPtrSVM), isObjectRedescribed(isObjectRedescribed),
45- multiGraphicsAllocation(std::move(multiGraphicsAllocation)) {
46-
45+ multiGraphicsAllocation(std::move(multiGraphicsAllocation)),
46+ mapAllocations( static_cast < uint32_t >( this ->multiGraphicsAllocation.getGraphicsAllocations().size() - 1)) {
4747 if (context) {
4848 context->incRefInternal ();
4949 memoryManager = context->getMemoryManager ();
@@ -58,6 +58,7 @@ MemObj::~MemObj() {
5858 }
5959
6060 bool needWait = false ;
61+
6162 if (allocatedMapPtr != nullptr ) {
6263 needWait = true ;
6364 }
@@ -72,35 +73,37 @@ MemObj::~MemObj() {
7273 if (peekSharingHandler ()) {
7374 peekSharingHandler ()->releaseReusedGraphicsAllocation ();
7475 }
75- auto graphicsAllocation = multiGraphicsAllocation.getDefaultGraphicsAllocation ();
76- if (graphicsAllocation && !associatedMemObject && !isHostPtrSVM && graphicsAllocation->peekReuseCount () == 0 ) {
77- memoryManager->removeAllocationFromHostPtrManager (graphicsAllocation);
78- bool doAsyncDestructions = DebugManager.flags .EnableAsyncDestroyAllocations .get ();
79- if (!doAsyncDestructions) {
80- needWait = true ;
76+
77+ for (auto graphicsAllocation : multiGraphicsAllocation.getGraphicsAllocations ()) {
78+ auto rootDeviceIndex = graphicsAllocation ? graphicsAllocation->getRootDeviceIndex () : 0 ;
79+ if (graphicsAllocation && !associatedMemObject && !isHostPtrSVM && graphicsAllocation->peekReuseCount () == 0 ) {
80+ memoryManager->removeAllocationFromHostPtrManager (graphicsAllocation);
81+ bool doAsyncDestructions = DebugManager.flags .EnableAsyncDestroyAllocations .get ();
82+ if (!doAsyncDestructions) {
83+ needWait = true ;
84+ }
85+ if (needWait && graphicsAllocation->isUsed ()) {
86+ memoryManager->waitForEnginesCompletion (*graphicsAllocation);
87+ }
88+ destroyGraphicsAllocation (graphicsAllocation, doAsyncDestructions);
89+ graphicsAllocation = nullptr ;
90+ }
91+ if (!associatedMemObject) {
92+ releaseMapAllocation (rootDeviceIndex);
93+ }
94+ if (mcsAllocation) {
95+ destroyGraphicsAllocation (mcsAllocation, false );
8196 }
82- if (needWait && graphicsAllocation->isUsed ()) {
83- memoryManager->waitForEnginesCompletion (*graphicsAllocation);
97+ if (graphicsAllocation && associatedMemObject) {
98+ if (associatedMemObject->getGraphicsAllocation (graphicsAllocation->getRootDeviceIndex ()) != graphicsAllocation) {
99+ destroyGraphicsAllocation (graphicsAllocation, false );
100+ }
101+ associatedMemObject->decRefInternal ();
84102 }
85- destroyGraphicsAllocation (graphicsAllocation, doAsyncDestructions);
86- graphicsAllocation = nullptr ;
87103 }
88-
89104 if (!associatedMemObject) {
90- releaseMapAllocation ();
91105 releaseAllocatedMapPtr ();
92106 }
93- if (mcsAllocation) {
94- destroyGraphicsAllocation (mcsAllocation, false );
95- }
96-
97- if (associatedMemObject) {
98- UNRECOVERABLE_IF (!graphicsAllocation);
99- if (associatedMemObject->getGraphicsAllocation (graphicsAllocation->getRootDeviceIndex ()) != graphicsAllocation) {
100- destroyGraphicsAllocation (graphicsAllocation, false );
101- }
102- associatedMemObject->decRefInternal ();
103- }
104107 }
105108 if (!destructorCallbacks.empty ()) {
106109 for (auto iter = destructorCallbacks.rbegin (); iter != destructorCallbacks.rend (); iter++) {
@@ -315,9 +318,9 @@ void MemObj::releaseAllocatedMapPtr() {
315318 allocatedMapPtr = nullptr ;
316319}
317320
318- void MemObj::releaseMapAllocation () {
319- if (mapAllocation && !isHostPtrSVM) {
320- destroyGraphicsAllocation (mapAllocation , false );
321+ void MemObj::releaseMapAllocation (uint32_t rootDeviceIndex ) {
322+ if (mapAllocations. getGraphicsAllocation (rootDeviceIndex) && !isHostPtrSVM) {
323+ destroyGraphicsAllocation (mapAllocations. getGraphicsAllocation (rootDeviceIndex) , false );
321324 }
322325}
323326
@@ -347,8 +350,8 @@ void *MemObj::getBasePtrForMap(uint32_t rootDeviceIndex) {
347350 return getHostPtr ();
348351 } else {
349352 TakeOwnershipWrapper<MemObj> memObjOwnership (*this );
350- if (getMapAllocation ()) {
351- return getMapAllocation ()->getUnderlyingBuffer ();
353+ if (getMapAllocation (rootDeviceIndex )) {
354+ return getMapAllocation (rootDeviceIndex )->getUnderlyingBuffer ();
352355 } else {
353356 auto memory = memoryManager->allocateSystemMemory (getSize (), MemoryConstants::pageSize);
354357 setAllocatedMapPtr (memory);
0 commit comments