performance: Move preemption allocation init to the first submission

Related-To: NEO-12323
Signed-off-by: Krzysztof Sprzaczkowski <krzysztof.sprzaczkowski@intel.com>
This commit is contained in:
Krzysztof Sprzaczkowski
2025-01-15 13:44:10 +00:00
committed by Compute-Runtime-Automation
parent 92ea7ee7a3
commit a17745532c
23 changed files with 117 additions and 48 deletions

View File

@@ -221,7 +221,7 @@ CommandList *CommandList::createImmediate(uint32_t productFamily, Device *device
bool enabledCmdListSharing = !NEO::EngineHelper::isCopyOnlyEngineType(engineGroupType) && commandList->isFlushTaskSubmissionEnabled; bool enabledCmdListSharing = !NEO::EngineHelper::isCopyOnlyEngineType(engineGroupType) && commandList->isFlushTaskSubmissionEnabled;
commandList->immediateCmdListHeapSharing = L0GfxCoreHelper::enableImmediateCmdListHeapSharing(rootDeviceEnvironment, enabledCmdListSharing); commandList->immediateCmdListHeapSharing = L0GfxCoreHelper::enableImmediateCmdListHeapSharing(rootDeviceEnvironment, enabledCmdListSharing);
} }
csr->initializeResources(false); csr->initializeResources(false, device->getDevicePreemptionMode());
csr->initDirectSubmission(); csr->initDirectSubmission();
auto commandQueue = CommandQueue::create(productFamily, device, csr, &cmdQdesc, NEO::EngineHelper::isCopyOnlyEngineType(engineGroupType), internalUsage, true, returnValue); auto commandQueue = CommandQueue::create(productFamily, device, csr, &cmdQdesc, NEO::EngineHelper::isCopyOnlyEngineType(engineGroupType), internalUsage, true, returnValue);

View File

@@ -250,7 +250,7 @@ CommandQueue *CommandQueue::create(uint32_t productFamily, Device *device, NEO::
osContext.reInitializeContext(); osContext.reInitializeContext();
} }
csr->initializeResources(false); csr->initializeResources(false, device->getDevicePreemptionMode());
csr->initDirectSubmission(); csr->initDirectSubmission();
if (commandQueue->cmdListHeapAddressModel == NEO::HeapAddressModel::globalStateless) { if (commandQueue->cmdListHeapAddressModel == NEO::HeapAddressModel::globalStateless) {
csr->createGlobalStatelessHeap(); csr->createGlobalStatelessHeap();

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2024 Intel Corporation * Copyright (C) 2021-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -75,6 +75,9 @@ void AUBFixtureL0::setUp(const NEO::HardwareInfo *hardwareInfo, bool debuggingEn
neoDevice = NEO::MockDevice::createWithExecutionEnvironment<NEO::MockDevice>(&hwInfo, executionEnvironment, 0u); neoDevice = NEO::MockDevice::createWithExecutionEnvironment<NEO::MockDevice>(&hwInfo, executionEnvironment, 0u);
this->csr = neoDevice->getDefaultEngine().commandStreamReceiver; this->csr = neoDevice->getDefaultEngine().commandStreamReceiver;
if (!this->csr->getPreemptionAllocation()) {
ASSERT_TRUE(this->csr->createPreemptionAllocation());
}
NEO::DeviceVector devices; NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice)); devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));

View File

@@ -53,6 +53,14 @@ void DeviceFixture::setupWithExecutionEnvironment(NEO::ExecutionEnvironment &exe
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
context = static_cast<ContextImp *>(Context::fromHandle(hContext)); context = static_cast<ContextImp *>(Context::fromHandle(hContext));
executionEnvironment.incRefInternal(); executionEnvironment.incRefInternal();
if (neoDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread) {
for (auto &engine : neoDevice->getAllEngines()) {
NEO::CommandStreamReceiver *csr = engine.commandStreamReceiver;
if (!csr->getPreemptionAllocation()) {
csr->createPreemptionAllocation();
}
}
}
} }
void DeviceFixture::tearDown() { void DeviceFixture::tearDown() {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022-2024 Intel Corporation * Copyright (C) 2022-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -36,6 +36,15 @@ void HostPointerManagerFixure::setUp() {
hostDriverHandle = std::make_unique<L0::ult::DriverHandle>(); hostDriverHandle = std::make_unique<L0::ult::DriverHandle>();
hostDriverHandle->initialize(std::move(devices)); hostDriverHandle->initialize(std::move(devices));
device = hostDriverHandle->devices[0]; device = hostDriverHandle->devices[0];
if (neoDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread) {
for (auto &engine : neoDevice->getAllEngines()) {
NEO::CommandStreamReceiver *csr = engine.commandStreamReceiver;
if (!csr->getPreemptionAllocation()) {
csr->createPreemptionAllocation();
}
}
}
openHostPointerManager = static_cast<L0::ult::HostPointerManager *>(hostDriverHandle->hostPointerManager.get()); openHostPointerManager = static_cast<L0::ult::HostPointerManager *>(hostDriverHandle->hostPointerManager.get());
heapPointer = hostDriverHandle->getMemoryManager()->allocateSystemMemory(heapSize, MemoryConstants::pageSize); heapPointer = hostDriverHandle->getMemoryManager()->allocateSystemMemory(heapSize, MemoryConstants::pageSize);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022-2024 Intel Corporation * Copyright (C) 2022-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -2913,10 +2913,9 @@ HWTEST2_F(CommandListStateBaseAddressGlobalStatelessTest,
auto otherCsr = std::unique_ptr<UltCommandStreamReceiver<FamilyType>>(static_cast<UltCommandStreamReceiver<FamilyType> *>(createCommandStream(*device->getNEODevice()->getExecutionEnvironment(), 0, 1))); auto otherCsr = std::unique_ptr<UltCommandStreamReceiver<FamilyType>>(static_cast<UltCommandStreamReceiver<FamilyType> *>(createCommandStream(*device->getNEODevice()->getExecutionEnvironment(), 0, 1)));
otherCsr->setupContext(*neoDevice->getDefaultEngine().osContext); otherCsr->setupContext(*neoDevice->getDefaultEngine().osContext);
otherCsr->initializeResources(false); otherCsr->initializeResources(false, neoDevice->getPreemptionMode());
otherCsr->initializeTagAllocation(); otherCsr->initializeTagAllocation();
otherCsr->createGlobalFenceAllocation(); otherCsr->createGlobalFenceAllocation();
otherCsr->createPreemptionAllocation();
otherCsr->createGlobalStatelessHeap(); otherCsr->createGlobalStatelessHeap();
ze_command_queue_desc_t desc = {}; ze_command_queue_desc_t desc = {};

View File

@@ -753,6 +753,14 @@ struct DeviceTest : public ::testing::Test {
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>(); driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices)); driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0]; device = driverHandle->devices[0];
if (neoDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread) {
for (auto &engine : neoDevice->getAllEngines()) {
NEO::CommandStreamReceiver *csr = engine.commandStreamReceiver;
if (!csr->getPreemptionAllocation()) {
csr->createPreemptionAllocation();
}
}
}
} }
void TearDown() override { void TearDown() override {
@@ -1799,6 +1807,14 @@ struct GlobalTimestampTest : public ::testing::Test {
void SetUp() override { void SetUp() override {
debugManager.flags.CreateMultipleRootDevices.set(numRootDevices); debugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), rootDeviceIndex); neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get(), rootDeviceIndex);
if (neoDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread) {
for (auto &engine : neoDevice->getAllEngines()) {
NEO::CommandStreamReceiver *csr = engine.commandStreamReceiver;
if (!csr->getPreemptionAllocation()) {
csr->createPreemptionAllocation();
}
}
}
} }
DebugManagerStateRestore restorer; DebugManagerStateRestore restorer;
@@ -2467,6 +2483,12 @@ struct MultipleDevicesFixture : public ::testing::Test {
auto neoDevice = device->getNEODevice(); auto neoDevice = device->getNEODevice();
context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex()); context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex());
context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
if (neoDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread) {
auto &csr = neoDevice->getInternalEngine().commandStreamReceiver;
if (!csr->getPreemptionAllocation()) {
csr->createPreemptionAllocation();
}
}
} }
} }

View File

@@ -3465,7 +3465,7 @@ HWTEST_F(EventTests, GivenEventWhenHostSynchronizeCalledThenExpectDownloadEventA
}; };
auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(event->csrs[0]); auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(event->csrs[0]);
ultCsr->initializeResources(false); ultCsr->initializeResources(false, device->getDevicePreemptionMode());
VariableBackup<std::function<void(GraphicsAllocation & gfxAllocation)>> backupCsrDownloadImpl(&ultCsr->downloadAllocationImpl); VariableBackup<std::function<void(GraphicsAllocation & gfxAllocation)>> backupCsrDownloadImpl(&ultCsr->downloadAllocationImpl);
ultCsr->downloadAllocationImpl = [&downloadAllocationTrack](GraphicsAllocation &gfxAllocation) { ultCsr->downloadAllocationImpl = [&downloadAllocationTrack](GraphicsAllocation &gfxAllocation) {
downloadAllocationTrack[&gfxAllocation]++; downloadAllocationTrack[&gfxAllocation]++;
@@ -3548,7 +3548,7 @@ HWTEST_F(EventContextGroupTests, givenSecondaryCsrWhenDownloadingAllocationThenU
OsContext osContext(0, static_cast<uint32_t>(neoDevice->getAllEngines().size()), EngineDescriptorHelper::getDefaultDescriptor()); OsContext osContext(0, static_cast<uint32_t>(neoDevice->getAllEngines().size()), EngineDescriptorHelper::getDefaultDescriptor());
ultCsr->setupContext(osContext); ultCsr->setupContext(osContext);
ultCsr->initializeResources(false); ultCsr->initializeResources(false, device->getDevicePreemptionMode());
uint32_t downloadCounter = 0; uint32_t downloadCounter = 0;
ultCsr->downloadAllocationImpl = [&downloadCounter](GraphicsAllocation &gfxAllocation) { ultCsr->downloadAllocationImpl = [&downloadCounter](GraphicsAllocation &gfxAllocation) {
@@ -3588,7 +3588,7 @@ HWTEST_F(EventTests, GivenEventUsedOnNonDefaultCsrWhenHostSynchronizeCalledThenA
EXPECT_LT(1u, neoDevice->getAllEngines().size()); EXPECT_LT(1u, neoDevice->getAllEngines().size());
auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(neoDevice->getAllEngines()[1].commandStreamReceiver); auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(neoDevice->getAllEngines()[1].commandStreamReceiver);
ultCsr->initializeResources(false); ultCsr->initializeResources(false, device->getDevicePreemptionMode());
EXPECT_NE(event->csrs[0], ultCsr); EXPECT_NE(event->csrs[0], ultCsr);
VariableBackup<std::function<void(GraphicsAllocation & gfxAllocation)>> backupCsrDownloadImpl(&ultCsr->downloadAllocationImpl); VariableBackup<std::function<void(GraphicsAllocation & gfxAllocation)>> backupCsrDownloadImpl(&ultCsr->downloadAllocationImpl);
@@ -3636,7 +3636,7 @@ HWTEST_F(EventTests, givenInOrderEventWhenHostSynchronizeIsCalledThenAllocationI
*eventAddress = Event::STATE_SIGNALED; *eventAddress = Event::STATE_SIGNALED;
auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(event->csrs[0]); auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(event->csrs[0]);
ultCsr->initializeResources(false); ultCsr->initializeResources(false, device->getDevicePreemptionMode());
VariableBackup<std::function<void(GraphicsAllocation & gfxAllocation)>> backupCsrDownloadImpl(&ultCsr->downloadAllocationImpl); VariableBackup<std::function<void(GraphicsAllocation & gfxAllocation)>> backupCsrDownloadImpl(&ultCsr->downloadAllocationImpl);
ultCsr->downloadAllocationImpl = [&downloadAllocationTrack](GraphicsAllocation &gfxAllocation) { ultCsr->downloadAllocationImpl = [&downloadAllocationTrack](GraphicsAllocation &gfxAllocation) {
@@ -3738,7 +3738,7 @@ HWTEST_F(EventTests, givenInOrderEventWithHostAllocWhenHostSynchronizeIsCalledTh
*eventAddress = Event::STATE_SIGNALED; *eventAddress = Event::STATE_SIGNALED;
auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(event->csrs[0]); auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(event->csrs[0]);
ultCsr->initializeResources(false); ultCsr->initializeResources(false, device->getDevicePreemptionMode());
VariableBackup<std::function<void(GraphicsAllocation & gfxAllocation)>> backupCsrDownloadImpl(&ultCsr->downloadAllocationImpl); VariableBackup<std::function<void(GraphicsAllocation & gfxAllocation)>> backupCsrDownloadImpl(&ultCsr->downloadAllocationImpl);
ultCsr->downloadAllocationImpl = [&downloadAllocationTrack](GraphicsAllocation &gfxAllocation) { ultCsr->downloadAllocationImpl = [&downloadAllocationTrack](GraphicsAllocation &gfxAllocation) {
downloadAllocationTrack[&gfxAllocation]++; downloadAllocationTrack[&gfxAllocation]++;
@@ -4511,9 +4511,9 @@ HWTEST2_F(EventMultiTileDynamicPacketUseTest, givenEventUsedCreatedOnSubDeviceBu
auto ultCsr1 = static_cast<UltCommandStreamReceiver<FamilyType> *>(subDevice1->getNEODevice()->getDefaultEngine().commandStreamReceiver); auto ultCsr1 = static_cast<UltCommandStreamReceiver<FamilyType> *>(subDevice1->getNEODevice()->getDefaultEngine().commandStreamReceiver);
auto ultCsr2 = static_cast<UltCommandStreamReceiver<FamilyType> *>(subDevice1->getNEODevice()->getInternalEngine().commandStreamReceiver); auto ultCsr2 = static_cast<UltCommandStreamReceiver<FamilyType> *>(subDevice1->getNEODevice()->getInternalEngine().commandStreamReceiver);
rootCsr->initializeResources(false); rootCsr->initializeResources(false, device->getDevicePreemptionMode());
ultCsr0->initializeResources(false); ultCsr0->initializeResources(false, device->getDevicePreemptionMode());
ultCsr1->initializeResources(false); ultCsr1->initializeResources(false, device->getDevicePreemptionMode());
rootCsr->commandStreamReceiverType = CommandStreamReceiverType::tbx; rootCsr->commandStreamReceiverType = CommandStreamReceiverType::tbx;
ultCsr0->commandStreamReceiverType = CommandStreamReceiverType::tbx; ultCsr0->commandStreamReceiverType = CommandStreamReceiverType::tbx;
@@ -4599,8 +4599,8 @@ HWTEST2_F(EventMultiTileDynamicPacketUseTest, givenEventCounterBasedUsedCreatedO
auto ultCsr0 = static_cast<UltCommandStreamReceiver<FamilyType> *>(subDevice0->getNEODevice()->getDefaultEngine().commandStreamReceiver); auto ultCsr0 = static_cast<UltCommandStreamReceiver<FamilyType> *>(subDevice0->getNEODevice()->getDefaultEngine().commandStreamReceiver);
auto ultCsr1 = static_cast<UltCommandStreamReceiver<FamilyType> *>(subDevice1->getNEODevice()->getDefaultEngine().commandStreamReceiver); auto ultCsr1 = static_cast<UltCommandStreamReceiver<FamilyType> *>(subDevice1->getNEODevice()->getDefaultEngine().commandStreamReceiver);
ultCsr0->initializeResources(false); ultCsr0->initializeResources(false, device->getDevicePreemptionMode());
ultCsr1->initializeResources(false); ultCsr1->initializeResources(false, device->getDevicePreemptionMode());
ultCsr0->commandStreamReceiverType = CommandStreamReceiverType::tbx; ultCsr0->commandStreamReceiverType = CommandStreamReceiverType::tbx;
ultCsr1->commandStreamReceiverType = CommandStreamReceiverType::tbx; ultCsr1->commandStreamReceiverType = CommandStreamReceiverType::tbx;

View File

@@ -238,7 +238,7 @@ void CommandQueue::initializeGpgpuInternals() const {
} }
} }
gpgpuEngine->commandStreamReceiver->initializeResources(false); gpgpuEngine->commandStreamReceiver->initializeResources(false, device->getPreemptionMode());
gpgpuEngine->commandStreamReceiver->requestPreallocation(); gpgpuEngine->commandStreamReceiver->requestPreallocation();
gpgpuEngine->commandStreamReceiver->initDirectSubmission(); gpgpuEngine->commandStreamReceiver->initDirectSubmission();
@@ -421,7 +421,7 @@ void CommandQueue::constructBcsEnginesForSplit() {
if (bcsEngines[i]) { if (bcsEngines[i]) {
bcsQueueEngineType = engineType; bcsQueueEngineType = engineType;
bcsEngines[i]->commandStreamReceiver->initializeResources(false); bcsEngines[i]->commandStreamReceiver->initializeResources(false, device->getPreemptionMode());
bcsEngines[i]->commandStreamReceiver->initDirectSubmission(); bcsEngines[i]->commandStreamReceiver->initDirectSubmission();
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020-2024 Intel Corporation * Copyright (C) 2020-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -33,6 +33,10 @@ void ClDeviceFixture::setUpImpl(const NEO::HardwareInfo *hardwareInfo) {
pTagMemory = commandStreamReceiver.getTagAddress(); pTagMemory = commandStreamReceiver.getTagAddress();
ASSERT_NE(nullptr, const_cast<TagAddressType *>(pTagMemory)); ASSERT_NE(nullptr, const_cast<TagAddressType *>(pTagMemory));
this->osContext = pDevice->getDefaultEngine().osContext; this->osContext = pDevice->getDefaultEngine().osContext;
if (pDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread &&
!commandStreamReceiver.getPreemptionAllocation()) {
commandStreamReceiver.createPreemptionAllocation();
}
} }
void ClDeviceFixture::tearDown() { void ClDeviceFixture::tearDown() {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018-2024 Intel Corporation * Copyright (C) 2018-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -331,13 +331,17 @@ uint8_t CommandStreamReceiver::getUmdPowerHintValue() const {
return this->osContext ? this->osContext->getUmdPowerHintValue() : 0u; return this->osContext ? this->osContext->getUmdPowerHintValue() : 0u;
} }
bool CommandStreamReceiver::initializeResources(bool allocateInterrupt) { bool CommandStreamReceiver::initializeResources(bool allocateInterrupt, const PreemptionMode preemptionMode) {
if (!resourcesInitialized) { if (!resourcesInitialized) {
auto lock = obtainUniqueOwnership(); auto lock = obtainUniqueOwnership();
if (!resourcesInitialized) { if (!resourcesInitialized) {
if (!osContext->ensureContextInitialized(allocateInterrupt)) { if (!osContext->ensureContextInitialized(allocateInterrupt)) {
return false; return false;
} }
if (preemptionMode == NEO::PreemptionMode::MidThread &&
!this->getPreemptionAllocation()) {
this->createPreemptionAllocation();
}
this->fillReusableAllocationsList(); this->fillReusableAllocationsList();
this->resourcesInitialized = true; this->resourcesInitialized = true;
} }

View File

@@ -284,7 +284,7 @@ class CommandStreamReceiver {
virtual void setupContext(OsContext &osContext) { this->osContext = &osContext; } virtual void setupContext(OsContext &osContext) { this->osContext = &osContext; }
OsContext &getOsContext() const { return *osContext; } OsContext &getOsContext() const { return *osContext; }
uint8_t getUmdPowerHintValue() const; uint8_t getUmdPowerHintValue() const;
bool initializeResources(bool allocateInterrupt); bool initializeResources(bool allocateInterrupt, const PreemptionMode preemptionMode);
TagAllocatorBase *getEventTsAllocator(); TagAllocatorBase *getEventTsAllocator();
TagAllocatorBase *getEventPerfCountAllocator(const uint32_t tagSize); TagAllocatorBase *getEventPerfCountAllocator(const uint32_t tagSize);
virtual TagAllocatorBase *getTimestampPacketAllocator() = 0; virtual TagAllocatorBase *getTimestampPacketAllocator() = 0;

View File

@@ -997,7 +997,7 @@ TaskCountType CommandStreamReceiverHw<GfxFamily>::flushBcsTask(const BlitPropert
auto newTaskCount = taskCount + 1; auto newTaskCount = taskCount + 1;
latestSentTaskCount = newTaskCount; latestSentTaskCount = newTaskCount;
this->initializeResources(false); this->initializeResources(false, device.getPreemptionMode());
this->initDirectSubmission(); this->initDirectSubmission();
if (PauseOnGpuProperties::pauseModeAllowed(debugManager.flags.PauseOnBlitCopy.get(), taskCount, PauseOnGpuProperties::PauseMode::BeforeWorkload)) { if (PauseOnGpuProperties::pauseModeAllowed(debugManager.flags.PauseOnBlitCopy.get(), taskCount, PauseOnGpuProperties::PauseMode::BeforeWorkload)) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2024 Intel Corporation * Copyright (C) 2024-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -14,6 +14,7 @@ SubmissionStatus CommandStreamReceiverHw<GfxFamily>::initializeDeviceWithFirstSu
if (this->latestFlushedTaskCount > 0) { if (this->latestFlushedTaskCount > 0) {
return SubmissionStatus::success; return SubmissionStatus::success;
} }
auto status = flushTagUpdate(); auto status = flushTagUpdate();
if (isTbxMode() && (status == SubmissionStatus::success)) { if (isTbxMode() && (status == SubmissionStatus::success)) {

View File

@@ -477,7 +477,7 @@ bool Device::createEngine(EngineTypeUsage engineTypeUsage) {
commandStreamReceiver->setupContext(*osContext); commandStreamReceiver->setupContext(*osContext);
if (osContext->isImmediateContextInitializationEnabled(isDefaultEngine)) { if (osContext->isImmediateContextInitializationEnabled(isDefaultEngine)) {
if (!commandStreamReceiver->initializeResources(false)) { if (!commandStreamReceiver->initializeResources(false, this->getPreemptionMode())) {
return false; return false;
} }
} }
@@ -490,10 +490,6 @@ bool Device::createEngine(EngineTypeUsage engineTypeUsage) {
return false; return false;
} }
if (preemptionMode == PreemptionMode::MidThread && !commandStreamReceiver->createPreemptionAllocation()) {
return false;
}
EngineControl engine{commandStreamReceiver.get(), osContext}; EngineControl engine{commandStreamReceiver.get(), osContext};
allEngines.push_back(engine); allEngines.push_back(engine);
if (engineUsage == EngineUsage::regular) { if (engineUsage == EngineUsage::regular) {
@@ -534,7 +530,7 @@ bool Device::initializeEngines() {
bool initializeDevice = (engine.osContext->isPartOfContextGroup() || isHeaplessStateInit) && !firstSubmissionDone; bool initializeDevice = (engine.osContext->isPartOfContextGroup() || isHeaplessStateInit) && !firstSubmissionDone;
if (initializeDevice) { if (initializeDevice) {
engine.commandStreamReceiver->initializeResources(false); engine.commandStreamReceiver->initializeResources(false, this->getPreemptionMode());
if (debugManager.flags.DeferStateInitSubmissionToFirstRegularUsage.get() != 1) { if (debugManager.flags.DeferStateInitSubmissionToFirstRegularUsage.get() != 1) {
engine.commandStreamReceiver->initializeDeviceWithFirstSubmission(*this); engine.commandStreamReceiver->initializeDeviceWithFirstSubmission(*this);
@@ -604,7 +600,7 @@ EngineControl *Device::getSecondaryEngineCsr(EngineTypeUsage engineTypeUsage, bo
EngineDescriptor engineDescriptor(engineTypeUsage, getDeviceBitfield(), preemptionMode, false); EngineDescriptor engineDescriptor(engineTypeUsage, getDeviceBitfield(), preemptionMode, false);
if (!commandStreamReceiver->initializeResources(allocateInterrupt)) { if (!commandStreamReceiver->initializeResources(allocateInterrupt, this->getPreemptionMode())) {
return nullptr; return nullptr;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2019-2024 Intel Corporation * Copyright (C) 2019-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -91,14 +91,11 @@ void RootDevice::initializeRootCommandStreamReceiver() {
osContext->setIsPrimaryEngine(isPrimaryEngine); osContext->setIsPrimaryEngine(isPrimaryEngine);
rootCommandStreamReceiver->setupContext(*osContext); rootCommandStreamReceiver->setupContext(*osContext);
rootCommandStreamReceiver->initializeResources(false); rootCommandStreamReceiver->initializeResources(false, preemptionMode);
rootCsrCreated = true; rootCsrCreated = true;
rootCommandStreamReceiver->initializeTagAllocation(); rootCommandStreamReceiver->initializeTagAllocation();
rootCommandStreamReceiver->createGlobalFenceAllocation(); rootCommandStreamReceiver->createGlobalFenceAllocation();
rootCommandStreamReceiver->createWorkPartitionAllocation(*this); rootCommandStreamReceiver->createWorkPartitionAllocation(*this);
if (preemptionMode == PreemptionMode::MidThread) {
rootCommandStreamReceiver->createPreemptionAllocation();
}
commandStreamReceivers.push_back(std::move(rootCommandStreamReceiver)); commandStreamReceivers.push_back(std::move(rootCommandStreamReceiver));
EngineControl engine{commandStreamReceivers.back().get(), osContext}; EngineControl engine{commandStreamReceivers.back().get(), osContext};

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2023-2024 Intel Corporation * Copyright (C) 2023-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -55,7 +55,7 @@ BlitOperationResult BlitHelper::blitMemoryToAllocationBanks(const Device &device
return BlitOperationResult::unsupported; return BlitOperationResult::unsupported;
} }
bcsEngine->commandStreamReceiver->initializeResources(false); bcsEngine->commandStreamReceiver->initializeResources(false, device.getPreemptionMode());
bcsEngine->commandStreamReceiver->initDirectSubmission(); bcsEngine->commandStreamReceiver->initDirectSubmission();
BlitPropertiesContainer blitPropertiesContainer; BlitPropertiesContainer blitPropertiesContainer;
blitPropertiesContainer.push_back( blitPropertiesContainer.push_back(

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020-2024 Intel Corporation * Copyright (C) 2020-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -30,7 +30,7 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResident(Device *devi
auto &engines = device->getAllEngines(); auto &engines = device->getAllEngines();
MemoryOperationsStatus result = MemoryOperationsStatus::success; MemoryOperationsStatus result = MemoryOperationsStatus::success;
for (const auto &engine : engines) { for (const auto &engine : engines) {
engine.commandStreamReceiver->initializeResources(false); engine.commandStreamReceiver->initializeResources(false, device->getPreemptionMode());
result = this->makeResidentWithinOsContext(engine.osContext, gfxAllocations, false); result = this->makeResidentWithinOsContext(engine.osContext, gfxAllocations, false);
if (result != MemoryOperationsStatus::success) { if (result != MemoryOperationsStatus::success) {
break; break;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022-2024 Intel Corporation * Copyright (C) 2022-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -37,6 +37,13 @@ void CommandStreamReceiverFixture::setUp() {
requiredStreamProperties.initSupport(pDevice->getRootDeviceEnvironment()); requiredStreamProperties.initSupport(pDevice->getRootDeviceEnvironment());
immediateFlushTaskFlags.requiredState = &requiredStreamProperties; immediateFlushTaskFlags.requiredState = &requiredStreamProperties;
immediateFlushTaskFlags.sshCpuBase = sshBuffer; immediateFlushTaskFlags.sshCpuBase = sshBuffer;
if (pDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread) {
auto &commandStreamReceiver = pDevice->getGpgpuCommandStreamReceiver();
if (!commandStreamReceiver.getPreemptionAllocation()) {
ASSERT_TRUE(commandStreamReceiver.createPreemptionAllocation());
}
}
} }
void CommandStreamReceiverFixture::tearDown() { void CommandStreamReceiverFixture::tearDown() {

View File

@@ -47,7 +47,16 @@ UltDeviceFactory::UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevice
pCreatedDevice->incRefInternal(); pCreatedDevice->incRefInternal();
if (pCreatedDevice->getNumSubDevices() > 1) { if (pCreatedDevice->getNumSubDevices() > 1) {
for (uint32_t i = 0; i < pCreatedDevice->getNumSubDevices(); i++) { for (uint32_t i = 0; i < pCreatedDevice->getNumSubDevices(); i++) {
this->subDevices.push_back(static_cast<SubDevice *>(pCreatedDevice->getSubDevice(i))); auto *pDevice = static_cast<SubDevice *>(pCreatedDevice->getSubDevice(i));
this->subDevices.push_back(pDevice);
}
}
if (pCreatedDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread) {
for (auto &engine : pCreatedDevice->getAllEngines()) {
NEO::CommandStreamReceiver *csr = engine.commandStreamReceiver;
if (!csr->getPreemptionAllocation()) {
csr->createPreemptionAllocation();
}
} }
} }
this->rootDevices.push_back(static_cast<MockDevice *>(pCreatedDevice.release())); this->rootDevices.push_back(static_cast<MockDevice *>(pCreatedDevice.release()));

View File

@@ -137,9 +137,9 @@ HWTEST_F(CommandStreamReceiverTest, WhenInitializeResourcesThenCallFillReusableA
ultCsr.fillReusableAllocationsListCalled = 0u; ultCsr.fillReusableAllocationsListCalled = 0u;
ultCsr.resourcesInitialized = false; ultCsr.resourcesInitialized = false;
commandStreamReceiver->initializeResources(false); commandStreamReceiver->initializeResources(false, pDevice->getPreemptionMode());
EXPECT_EQ(1u, pDevice->getUltCommandStreamReceiver<FamilyType>().fillReusableAllocationsListCalled); EXPECT_EQ(1u, pDevice->getUltCommandStreamReceiver<FamilyType>().fillReusableAllocationsListCalled);
commandStreamReceiver->initializeResources(false); commandStreamReceiver->initializeResources(false, pDevice->getPreemptionMode());
EXPECT_EQ(1u, pDevice->getUltCommandStreamReceiver<FamilyType>().fillReusableAllocationsListCalled); EXPECT_EQ(1u, pDevice->getUltCommandStreamReceiver<FamilyType>().fillReusableAllocationsListCalled);
} }
@@ -161,7 +161,7 @@ HWTEST_F(CommandStreamReceiverTest, whenContextCreateReturnsFalseThenExpectCSRIn
auto &ultCsr = pDevice->getUltCommandStreamReceiver<FamilyType>(); auto &ultCsr = pDevice->getUltCommandStreamReceiver<FamilyType>();
ultCsr.resourcesInitialized = false; ultCsr.resourcesInitialized = false;
ultCsr.setupContext(osContext); ultCsr.setupContext(osContext);
bool ret = ultCsr.initializeResources(false); bool ret = ultCsr.initializeResources(false, pDevice->getPreemptionMode());
EXPECT_FALSE(ret); EXPECT_FALSE(ret);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018-2024 Intel Corporation * Copyright (C) 2018-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -442,6 +442,10 @@ HWTEST_F(MidThreadPreemptionTests, GivenNoWaWhenCreatingCsrSurfaceThenSurfaceIsC
ASSERT_NE(nullptr, mockDevice.get()); ASSERT_NE(nullptr, mockDevice.get());
auto &csr = mockDevice->getUltCommandStreamReceiver<FamilyType>(); auto &csr = mockDevice->getUltCommandStreamReceiver<FamilyType>();
if (mockDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread &&
!csr.getPreemptionAllocation()) {
ASSERT_TRUE(csr.createPreemptionAllocation());
}
MemoryAllocation *csrSurface = static_cast<MemoryAllocation *>(csr.getPreemptionAllocation()); MemoryAllocation *csrSurface = static_cast<MemoryAllocation *>(csr.getPreemptionAllocation());
ASSERT_NE(nullptr, csrSurface); ASSERT_NE(nullptr, csrSurface);
EXPECT_FALSE(csrSurface->uncacheable); EXPECT_FALSE(csrSurface->uncacheable);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2024 Intel Corporation * Copyright (C) 2024-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -41,6 +41,12 @@ struct Xe2MidThreadPreemptionTests : public Xe2PreemptionTests {
preemptionMode = PreemptionMode::MidThread; preemptionMode = PreemptionMode::MidThread;
Xe2PreemptionTests::SetUp(); Xe2PreemptionTests::SetUp();
auto &csr = device->getGpgpuCommandStreamReceiver();
if (device->getPreemptionMode() == NEO::PreemptionMode::MidThread &&
!csr.getPreemptionAllocation()) {
csr.createPreemptionAllocation();
}
} }
void TearDown() override { void TearDown() override {
Xe2PreemptionTests::TearDown(); Xe2PreemptionTests::TearDown();