Skip to content

Commit 8560b2b

Browse files
Create dedicated allocation for global fence purposes
Related-To: NEO-3216 Change-Id: I0483a99ea1095c7a10b1318f51569e479386cac4 Signed-off-by: Milczarek, Slawomir <[email protected]>
1 parent 004ea39 commit 8560b2b

16 files changed

+99
-1
lines changed

core/memory_manager/graphics_allocation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
7979
SVM_GPU,
8080
SVM_ZERO_COPY,
8181
TAG_BUFFER,
82+
GLOBAL_FENCE,
8283
TIMESTAMP_PACKET_TAG_BUFFER,
8384
WRITE_COMBINED
8485
};

runtime/command_stream/command_stream_receiver.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ void CommandStreamReceiver::cleanupResources() {
178178
tagAddress = nullptr;
179179
}
180180

181+
if (globalFenceAllocation) {
182+
getMemoryManager()->freeGraphicsMemory(globalFenceAllocation);
183+
globalFenceAllocation = nullptr;
184+
}
185+
181186
if (preemptionAllocation) {
182187
getMemoryManager()->freeGraphicsMemory(preemptionAllocation);
183188
preemptionAllocation = nullptr;
@@ -379,6 +384,15 @@ bool CommandStreamReceiver::initializeTagAllocation() {
379384
return true;
380385
}
381386

387+
bool CommandStreamReceiver::createGlobalFenceAllocation() {
388+
if (!localMemoryEnabled) {
389+
return true;
390+
}
391+
DEBUG_BREAK_IF(this->globalFenceAllocation != nullptr);
392+
this->globalFenceAllocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::GLOBAL_FENCE});
393+
return this->globalFenceAllocation != nullptr;
394+
}
395+
382396
bool CommandStreamReceiver::createPreemptionAllocation() {
383397
auto hwInfo = executionEnvironment.getHardwareInfo();
384398
AllocationProperties properties{rootDeviceIndex, true, hwInfo->capabilityTable.requiredPreemptionSurfaceSize, GraphicsAllocation::AllocationType::PREEMPTION, false};

runtime/command_stream/command_stream_receiver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class CommandStreamReceiver {
149149
void setExperimentalCmdBuffer(std::unique_ptr<ExperimentalCommandBuffer> &&cmdBuffer);
150150

151151
bool initializeTagAllocation();
152+
MOCKABLE_VIRTUAL bool createGlobalFenceAllocation();
152153
MOCKABLE_VIRTUAL bool createPreemptionAllocation();
153154
MOCKABLE_VIRTUAL bool createPerDssBackedBuffer(Device &device);
154155
MOCKABLE_VIRTUAL std::unique_lock<MutexType> obtainUniqueOwnership();
@@ -216,6 +217,7 @@ class CommandStreamReceiver {
216217
volatile uint32_t *tagAddress = nullptr;
217218

218219
GraphicsAllocation *tagAllocation = nullptr;
220+
GraphicsAllocation *globalFenceAllocation = nullptr;
219221
GraphicsAllocation *preemptionAllocation = nullptr;
220222
GraphicsAllocation *debugSurface = nullptr;
221223
GraphicsAllocation *perDssBackedBuffer = nullptr;

runtime/command_stream/command_stream_receiver_hw_base.inl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,13 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
385385

386386
this->makeResident(*tagAllocation);
387387

388-
if (preemptionAllocation)
388+
if (globalFenceAllocation) {
389+
makeResident(*globalFenceAllocation);
390+
}
391+
392+
if (preemptionAllocation) {
389393
makeResident(*preemptionAllocation);
394+
}
390395

391396
if (dispatchFlags.preemptionMode == PreemptionMode::MidThread || device.isSourceLevelDebuggerActive()) {
392397
makeResident(*SipKernel::getSipKernelAllocation(device));

runtime/device/device.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ bool Device::createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engine
140140
if (!commandStreamReceiver->initializeTagAllocation()) {
141141
return false;
142142
}
143+
144+
if (!commandStreamReceiver->createGlobalFenceAllocation()) {
145+
return false;
146+
}
147+
143148
if (engineType == defaultEngineType && !lowPriority && !internalUsage) {
144149
defaultEngineIndex = deviceCsrIndex;
145150
}

runtime/device/root_device.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void RootDevice::initializeRootCommandStreamReceiver() {
105105

106106
rootCommandStreamReceiver->setupContext(*osContext);
107107
rootCommandStreamReceiver->initializeTagAllocation();
108+
rootCommandStreamReceiver->createGlobalFenceAllocation();
108109
commandStreamReceivers.push_back(std::move(rootCommandStreamReceiver));
109110
engines.emplace_back(commandStreamReceivers.back().get(), osContext);
110111
}

runtime/memory_manager/memory_manager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
280280
case GraphicsAllocation::AllocationType::SVM_CPU:
281281
case GraphicsAllocation::AllocationType::SVM_ZERO_COPY:
282282
case GraphicsAllocation::AllocationType::TAG_BUFFER:
283+
case GraphicsAllocation::AllocationType::GLOBAL_FENCE:
283284
case GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY:
284285
allocationData.flags.useSystemMemory = true;
285286
default:

runtime/utilities/logger.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ const char *FileLogger<DebugLevel>::getAllocationTypeString(GraphicsAllocation c
315315
return "SVM_ZERO_COPY";
316316
case GraphicsAllocation::AllocationType::TAG_BUFFER:
317317
return "TAG_BUFFER";
318+
case GraphicsAllocation::AllocationType::GLOBAL_FENCE:
319+
return "GLOBAL_FENCE";
318320
case GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER:
319321
return "TIMESTAMP_PACKET_TAG_BUFFER";
320322
case GraphicsAllocation::AllocationType::UNKNOWN:

unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,25 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, handleTagAndScratchAllocationsResi
444444
EXPECT_TRUE(commandStreamReceiver->isMadeNonResident(scratchAllocation));
445445
}
446446

447+
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCommandStreamReceiverWhenLocalMemoryIsEnabledAndFlushTaskIsCalledThenGlobalFenceAlocationIsMadeResident) {
448+
DebugManagerStateRestore dbgRestorer;
449+
DebugManager.flags.EnableLocalMemory.set(true);
450+
451+
auto commandStreamReceiver = new MockCsrHw<FamilyType>(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex());
452+
pDevice->resetCommandStreamReceiver(commandStreamReceiver);
453+
454+
auto globalFenceAllocation = commandStreamReceiver->globalFenceAllocation;
455+
ASSERT_NE(globalFenceAllocation, nullptr);
456+
457+
EXPECT_FALSE(commandStreamReceiver->isMadeResident(globalFenceAllocation));
458+
EXPECT_FALSE(commandStreamReceiver->isMadeNonResident(globalFenceAllocation));
459+
460+
flushTask(*commandStreamReceiver);
461+
462+
EXPECT_TRUE(commandStreamReceiver->isMadeResident(globalFenceAllocation));
463+
EXPECT_TRUE(commandStreamReceiver->isMadeNonResident(globalFenceAllocation));
464+
}
465+
447466
struct MockScratchController : public ScratchSpaceController {
448467
using ScratchSpaceController::privateScratchAllocation;
449468
using ScratchSpaceController::scratchAllocation;

unit_tests/command_stream/command_stream_receiver_tests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,19 @@ TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenInitializeTa
363363
EXPECT_EQ(*csr->getTagAddress(), initialHardwareTag);
364364
}
365365

366+
HWTEST_F(CommandStreamReceiverTest, givenCommandStreamReceiverWhenLocalMemoryIsEnabledAndCreateGlobalFenceAllocationIsCalledThenGlobalFenceAllocationIsAllocated) {
367+
DebugManagerStateRestore dbgRestore;
368+
DebugManager.flags.EnableLocalMemory.set(true);
369+
370+
MockCsrHw<FamilyType> csr(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex());
371+
EXPECT_EQ(nullptr, csr.globalFenceAllocation);
372+
373+
EXPECT_TRUE(csr.createGlobalFenceAllocation());
374+
375+
ASSERT_NE(nullptr, csr.globalFenceAllocation);
376+
EXPECT_EQ(GraphicsAllocation::AllocationType::GLOBAL_FENCE, csr.globalFenceAllocation->getAllocationType());
377+
}
378+
366379
TEST(CommandStreamReceiverSimpleTest, givenNullHardwareDebugModeWhenInitializeTagAllocationIsCalledThenTagAllocationIsBeingAllocatedAndinitialValueIsMinusOne) {
367380
DebugManagerStateRestore dbgRestore;
368381
DebugManager.flags.EnableNullHardware.set(true);

0 commit comments

Comments
 (0)