mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 14:02:58 +08:00
fix: initialize CommandToPatch member
Also: adjusted tests for optional scratch, reordered members for best alignment and removed unused variable Related-To: NEO-14130 Signed-off-by: Naklicki, Mateusz <mateusz.naklicki@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
cb0db589b9
commit
9603d1f2a7
@@ -477,8 +477,6 @@ struct CommandList : _ze_command_list_handle_t {
|
||||
int64_t currentIndirectObjectBaseAddress = NEO::StreamProperty64::initValue;
|
||||
int64_t currentBindingTablePoolBaseAddress = NEO::StreamProperty64::initValue;
|
||||
|
||||
uint64_t currentScratchPatchAddress = 0;
|
||||
|
||||
ze_context_handle_t hContext = nullptr;
|
||||
CommandQueue *cmdQImmediate = nullptr;
|
||||
CommandQueue *cmdQImmediateCopyOffload = nullptr;
|
||||
|
||||
@@ -128,7 +128,6 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::reset() {
|
||||
commandListPreemptionMode = device->getDevicePreemptionMode();
|
||||
commandListPerThreadScratchSize[0] = 0u;
|
||||
commandListPerThreadScratchSize[1] = 0u;
|
||||
currentScratchPatchAddress = 0u;
|
||||
usedScratchController = nullptr;
|
||||
requiredStreamState.resetState();
|
||||
finalStreamState.resetState();
|
||||
|
||||
@@ -35,15 +35,13 @@ struct CommandToPatch {
|
||||
Invalid
|
||||
};
|
||||
void *pDestination = nullptr;
|
||||
union {
|
||||
void *pCommand;
|
||||
mutable uint64_t scratchAddressAfterPatch;
|
||||
};
|
||||
void *pCommand = nullptr;
|
||||
uint64_t baseAddress = 0;
|
||||
mutable uint64_t scratchAddressAfterPatch = 0;
|
||||
size_t offset = 0;
|
||||
CommandType type = Invalid;
|
||||
size_t inOrderPatchListIndex = 0;
|
||||
size_t patchSize = 0;
|
||||
uint64_t baseAddress = 0;
|
||||
CommandType type = Invalid;
|
||||
};
|
||||
|
||||
using CommandToPatchContainer = std::vector<CommandToPatch>;
|
||||
|
||||
@@ -1559,6 +1559,13 @@ void CommandListScratchPatchFixtureInit::testScratchGrowingPatching() {
|
||||
auto scratchAddress = scratchController->getScratchPatchAddress();
|
||||
auto fullScratchAddress = surfaceHeapGpuBase + scratchAddress;
|
||||
|
||||
auto patchIndex = launchParams.scratchAddressPatchIndex;
|
||||
ASSERT_TRUE(commandList->commandsToPatch.size() > patchIndex);
|
||||
|
||||
auto currentScratchPatchAddress = commandList->commandsToPatch[patchIndex].scratchAddressAfterPatch;
|
||||
auto expectedScratchPatchAddress = getExpectedScratchPatchAddress(scratchAddress);
|
||||
|
||||
EXPECT_EQ(expectedScratchPatchAddress, currentScratchPatchAddress);
|
||||
EXPECT_EQ(scratchController, commandList->getCommandListUsedScratchController());
|
||||
|
||||
uint64_t scratchInlineValue = 0;
|
||||
@@ -1597,6 +1604,13 @@ void CommandListScratchPatchFixtureInit::testScratchGrowingPatching() {
|
||||
scratchAddress = scratchController->getScratchPatchAddress();
|
||||
auto fullScratchSlot1Address = surfaceHeapGpuBase + scratchAddress;
|
||||
|
||||
patchIndex = launchParams.scratchAddressPatchIndex;
|
||||
ASSERT_TRUE(commandList->commandsToPatch.size() > patchIndex);
|
||||
|
||||
currentScratchPatchAddress = commandList->commandsToPatch[patchIndex].scratchAddressAfterPatch;
|
||||
expectedScratchPatchAddress = getExpectedScratchPatchAddress(scratchAddress);
|
||||
|
||||
EXPECT_EQ(expectedScratchPatchAddress, currentScratchPatchAddress);
|
||||
EXPECT_EQ(scratchController, commandList->getCommandListUsedScratchController());
|
||||
|
||||
scratchInlinePtr = ptrOffset(walkerPtrWithSlot1Scratch, (inlineOffset + scratchInlineOffset));
|
||||
@@ -1626,6 +1640,7 @@ void CommandListScratchPatchFixtureInit::testScratchSameNotPatching() {
|
||||
|
||||
const ze_group_count_t groupCount{1, 1, 1};
|
||||
CmdListKernelLaunchParams launchParams = {};
|
||||
EXPECT_TRUE(NEO::isUndefined(launchParams.scratchAddressPatchIndex));
|
||||
|
||||
auto result = ZE_RESULT_SUCCESS;
|
||||
size_t usedBefore = cmdListStream->getUsed();
|
||||
@@ -1648,18 +1663,33 @@ void CommandListScratchPatchFixtureInit::testScratchSameNotPatching() {
|
||||
result = commandList->close();
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
const CommandToPatch *scratchCmd = nullptr;
|
||||
size_t scratchCmdIndex = 0;
|
||||
for (const auto &cmdToPatch : commandList->getCommandsToPatch()) {
|
||||
if (cmdToPatch.type == CommandToPatch::CommandType::ComputeWalkerInlineDataScratch) {
|
||||
scratchCmd = &cmdToPatch;
|
||||
break;
|
||||
}
|
||||
scratchCmdIndex += 1;
|
||||
}
|
||||
ASSERT_NE(scratchCmd, nullptr);
|
||||
EXPECT_EQ(scratchCmd->scratchAddressAfterPatch, 0u);
|
||||
EXPECT_EQ(scratchCmdIndex, launchParams.scratchAddressPatchIndex);
|
||||
|
||||
auto commandListHandle = commandList->toHandle();
|
||||
result = commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false, nullptr, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
auto scratchAddress = scratchController->getScratchPatchAddress();
|
||||
auto fullScratchAddress = surfaceHeapGpuBase + scratchAddress;
|
||||
auto expectedSavedScratchAddress = fixtureGlobalStatelessMode ? fullScratchAddress : scratchAddress;
|
||||
|
||||
uint64_t scratchInlineValue = 0;
|
||||
|
||||
void *scratchInlinePtr = ptrOffset(walkerPtrWithScratch, (inlineOffset + scratchInlineOffset));
|
||||
std::memcpy(&scratchInlineValue, scratchInlinePtr, sizeof(scratchInlineValue));
|
||||
EXPECT_EQ(fullScratchAddress, scratchInlineValue);
|
||||
EXPECT_EQ(expectedSavedScratchAddress, scratchCmd->scratchAddressAfterPatch);
|
||||
|
||||
memset(scratchInlinePtr, 0, scratchInlinePointerSize);
|
||||
|
||||
@@ -1668,6 +1698,7 @@ void CommandListScratchPatchFixtureInit::testScratchSameNotPatching() {
|
||||
|
||||
std::memcpy(&scratchInlineValue, scratchInlinePtr, sizeof(scratchInlineValue));
|
||||
EXPECT_EQ(0u, scratchInlineValue);
|
||||
EXPECT_EQ(expectedSavedScratchAddress, scratchCmd->scratchAddressAfterPatch);
|
||||
}
|
||||
|
||||
template <typename FamilyType>
|
||||
@@ -1765,6 +1796,8 @@ void CommandListScratchPatchFixtureInit::testScratchChangedControllerPatching()
|
||||
auto fullScratchAddress = surfaceHeapGpuBase + scratchAddress;
|
||||
|
||||
auto patchIndex = launchParams.scratchAddressPatchIndex;
|
||||
ASSERT_TRUE(commandList->commandsToPatch.size() > patchIndex);
|
||||
|
||||
auto currentScratchPatchAddress = commandList->commandsToPatch[patchIndex].scratchAddressAfterPatch;
|
||||
auto expectedScratchPatchAddress = getExpectedScratchPatchAddress(scratchAddress);
|
||||
|
||||
@@ -1892,6 +1925,13 @@ void CommandListScratchPatchFixtureInit::testExternalScratchPatching() {
|
||||
auto scratchAddress = scratchController->getScratchPatchAddress();
|
||||
auto fullScratchAddress = surfaceHeapGpuBase + scratchAddress;
|
||||
|
||||
auto patchIndex = launchParams.scratchAddressPatchIndex;
|
||||
ASSERT_TRUE(commandList->commandsToPatch.size() > patchIndex);
|
||||
|
||||
auto currentScratchPatchAddress = commandList->commandsToPatch[patchIndex].scratchAddressAfterPatch;
|
||||
auto expectedScratchPatchAddress = getExpectedScratchPatchAddress(scratchAddress);
|
||||
|
||||
EXPECT_EQ(expectedScratchPatchAddress, currentScratchPatchAddress);
|
||||
EXPECT_EQ(scratchController, commandList->getCommandListUsedScratchController());
|
||||
|
||||
uint64_t scratchInlineValue = 0;
|
||||
|
||||
@@ -1058,20 +1058,23 @@ HWTEST2_F(CommandQueueScratchTests, givenInlineDataScratchWhenPatchCommandsIsCal
|
||||
constexpr uint64_t dummyScratchAddress = 0xdeadu;
|
||||
constexpr uint64_t baseAddress = 0x1234u;
|
||||
constexpr uint64_t scratchAddress = 0x5000u;
|
||||
constexpr uint64_t expectedPatchedScratchAddress = baseAddress + scratchAddress;
|
||||
|
||||
struct TestCase {
|
||||
const char *name;
|
||||
bool undefinedPatchSize;
|
||||
bool undefinedOffset;
|
||||
bool scratchAlreadyPatched;
|
||||
bool scratchControllerChanged;
|
||||
uint64_t expectedValue;
|
||||
};
|
||||
|
||||
const TestCase testCases[] = {
|
||||
{"Valid patchSize and offset - should patch", false, false, false, scratchAddress + baseAddress},
|
||||
{"Undefined patchSize - should not patch", true, false, false, dummyScratchAddress},
|
||||
{"Undefined offset - should not patch", false, true, false, dummyScratchAddress},
|
||||
{"scratchAddressAfterPatch==scratchAddress - should not patch", false, false, true, dummyScratchAddress}};
|
||||
{false, false, false, false, expectedPatchedScratchAddress}, // Valid patchSize and offset - should patch
|
||||
{false, false, false, true, expectedPatchedScratchAddress}, // scratchControllerChanged - should patch
|
||||
{true, false, false, false, dummyScratchAddress}, // Undefined patchSize - should not patch
|
||||
{false, true, false, false, dummyScratchAddress}, // Undefined offset - should not patch
|
||||
{false, false, true, false, dummyScratchAddress}, // scratchAddressAfterPatch==scratchAddress - should not patch
|
||||
};
|
||||
|
||||
for (const auto &testCase : testCases) {
|
||||
uint64_t scratchBuffer = dummyScratchAddress;
|
||||
@@ -1086,12 +1089,46 @@ HWTEST2_F(CommandQueueScratchTests, givenInlineDataScratchWhenPatchCommandsIsCal
|
||||
cmd.scratchAddressAfterPatch = testCase.scratchAlreadyPatched ? scratchAddress : 0;
|
||||
|
||||
commandList->commandsToPatch.push_back(cmd);
|
||||
commandQueue->patchCommands(*commandList, scratchAddress, false);
|
||||
commandQueue->patchCommands(*commandList, scratchAddress, testCase.scratchControllerChanged);
|
||||
|
||||
EXPECT_EQ(testCase.expectedValue, scratchBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST2_F(CommandQueueScratchTests, givenImplicitArgsScratchWhenPatchCommandsIsCalledThenCommandsAreCorrectlyPatched, IsAtLeastXeCore) {
|
||||
ze_command_queue_desc_t desc = {};
|
||||
NEO::CommandStreamReceiver *csr = nullptr;
|
||||
device->getCsrForOrdinalAndIndex(&csr, 0u, 0u, ZE_COMMAND_QUEUE_PRIORITY_NORMAL, 0, false);
|
||||
auto commandQueue = std::make_unique<MockCommandQueueHw<FamilyType::gfxCoreFamily>>(device, csr, &desc);
|
||||
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<FamilyType::gfxCoreFamily>>>();
|
||||
|
||||
constexpr uint64_t dummyScratchAddress = 0xdeadu;
|
||||
constexpr uint64_t baseAddress = 0x1234u;
|
||||
constexpr uint64_t scratchAddress = 0x5000u;
|
||||
constexpr uint64_t expectedPatchedScratchAddress = baseAddress + scratchAddress;
|
||||
|
||||
for (const bool scratchControllerChanged : {false, true}) {
|
||||
for (const bool scratchAlreadyPatched : {false, true}) {
|
||||
const uint64_t expectedValue = (scratchControllerChanged || !scratchAlreadyPatched) ? expectedPatchedScratchAddress : dummyScratchAddress;
|
||||
uint64_t scratchBuffer = dummyScratchAddress;
|
||||
commandList->commandsToPatch.clear();
|
||||
|
||||
CommandToPatch cmd;
|
||||
cmd.type = CommandToPatch::ComputeWalkerImplicitArgsScratch;
|
||||
cmd.pDestination = &scratchBuffer;
|
||||
cmd.baseAddress = baseAddress;
|
||||
cmd.offset = 0;
|
||||
cmd.patchSize = sizeof(uint64_t);
|
||||
cmd.scratchAddressAfterPatch = scratchAlreadyPatched ? scratchAddress : 0;
|
||||
|
||||
commandList->commandsToPatch.push_back(cmd);
|
||||
commandQueue->patchCommands(*commandList, scratchAddress, scratchControllerChanged);
|
||||
|
||||
EXPECT_EQ(expectedValue, scratchBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using CommandQueueCreate = Test<DeviceFixture>;
|
||||
|
||||
HWTEST_F(CommandQueueCreate, givenCommandsToPatchWithNoopSpacePatchWhenPatchCommandsIsCalledThenSpaceIsNooped) {
|
||||
|
||||
Reference in New Issue
Block a user