feature: add host function allocation

Related-To: NEO-14577
Signed-off-by: Kamil Kopryk <kamil.kopryk@intel.com>
This commit is contained in:
Kamil Kopryk
2025-09-22 08:20:23 +00:00
committed by Compute-Runtime-Automation
parent 27922536ff
commit 75b4de70cd
20 changed files with 175 additions and 15 deletions

View File

@@ -43,6 +43,8 @@ class MockCommandStreamReceiver : public CommandStreamReceiver {
using CommandStreamReceiver::gpuHangCheckPeriod;
using CommandStreamReceiver::heaplessStateInitEnabled;
using CommandStreamReceiver::heaplessStateInitialized;
using CommandStreamReceiver::hostFunctionDataAllocation;
using CommandStreamReceiver::hostFunctionDataMultiAllocation;
using CommandStreamReceiver::immWritePostSyncWriteOffset;
using CommandStreamReceiver::internalAllocationStorage;
using CommandStreamReceiver::latestFlushedTaskCount;
@@ -277,6 +279,11 @@ class MockCommandStreamReceiver : public CommandStreamReceiver {
BaseClass::setupContext(osContext);
}
void initializeHostFunctionData() override {
initializeHostFunctionDataCalledTimes++;
BaseClass::initializeHostFunctionData();
}
static constexpr size_t tagSize = 256;
static volatile TagAddressType mockTagAddress[tagSize];
std::vector<char> instructionHeapReserveredData;
@@ -289,6 +296,7 @@ class MockCommandStreamReceiver : public CommandStreamReceiver {
uint32_t downloadAllocationsCalledCount = 0;
uint32_t submitDependencyUpdateCalledTimes = 0;
uint32_t stopDirectSubmissionCalledTimes = 0;
uint32_t initializeHostFunctionDataCalledTimes = 0;
int hostPtrSurfaceCreationMutexLockCount = 0;
bool multiOsContextCapable = false;
bool memoryCompressionEnabled = false;

View File

@@ -119,6 +119,7 @@ TEST(AubHelper, givenAllocationTypeWhenAskingIfOneTimeWritableThenReturnCorrectR
case AllocationType::assertBuffer:
case AllocationType::tagBuffer:
case AllocationType::syncDispatchToken:
case AllocationType::hostFunction:
EXPECT_TRUE(isOneTimeWritable);
break;
default:

View File

@@ -6446,3 +6446,75 @@ HWTEST_F(CommandStreamReceiverHwTest, givenVariousCsrModeWhenGettingHardwareMode
ultCsr.commandStreamReceiverType = CommandStreamReceiverType::tbxWithAub;
EXPECT_FALSE(ultCsr.isHardwareMode());
}
TEST(CommandStreamReceiverHostFunctionsTest, givenCommandStreamReceiverWhenEnsureHostFunctionDataInitializationCalledThenHostFunctionAllocationIsBeingAllocatedOnlyOnce) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
DeviceBitfield devices(0b11);
auto csr = std::make_unique<MockCommandStreamReceiver>(executionEnvironment, 0, devices);
executionEnvironment.memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment));
EXPECT_EQ(nullptr, csr->getHostFunctionDataAllocation());
csr->ensureHostFunctionDataInitialization();
auto *hostDataAllocation = csr->getHostFunctionDataAllocation();
EXPECT_NE(nullptr, hostDataAllocation);
EXPECT_EQ(1u, csr->initializeHostFunctionDataCalledTimes);
csr->ensureHostFunctionDataInitialization();
EXPECT_EQ(hostDataAllocation, csr->getHostFunctionDataAllocation());
EXPECT_EQ(1u, csr->initializeHostFunctionDataCalledTimes);
csr->initializeHostFunctionData();
EXPECT_EQ(2u, csr->initializeHostFunctionDataCalledTimes); // direct call -> the counter updated but due to an early return allocation didn't change
EXPECT_EQ(hostDataAllocation, csr->getHostFunctionDataAllocation());
EXPECT_EQ(AllocationType::hostFunction, hostDataAllocation->getAllocationType());
auto expectedHostFunctionAddress = reinterpret_cast<uint64_t>(ptrOffset(hostDataAllocation->getUnderlyingBuffer(), HostFunctionHelper::entryOffset));
EXPECT_EQ(expectedHostFunctionAddress, reinterpret_cast<uint64_t>(csr->getHostFunctionData().entry));
auto expectedUserDataAddress = reinterpret_cast<uint64_t>(ptrOffset(hostDataAllocation->getUnderlyingBuffer(), HostFunctionHelper::userDataOffset));
EXPECT_EQ(expectedUserDataAddress, reinterpret_cast<uint64_t>(csr->getHostFunctionData().userData));
auto expectedInternalTagAddress = reinterpret_cast<uint64_t>(ptrOffset(hostDataAllocation->getUnderlyingBuffer(), HostFunctionHelper::internalTagOffset));
EXPECT_EQ(expectedInternalTagAddress, reinterpret_cast<uint64_t>(csr->getHostFunctionData().internalTag));
}
TEST(CommandStreamReceiverHostFunctionsTest, givenDestructedCommandStreamReceiverWhenEnsureHostFunctionDataInitializationCalledThenHostFunctionAllocationsDeallocated) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
DeviceBitfield devices(0b11);
auto csr = std::make_unique<MockCommandStreamReceiver>(executionEnvironment, 0, devices);
executionEnvironment.memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment));
EXPECT_EQ(nullptr, csr->getHostFunctionDataAllocation());
csr->ensureHostFunctionDataInitialization();
EXPECT_NE(nullptr, csr->hostFunctionDataAllocation);
EXPECT_NE(nullptr, csr->hostFunctionDataMultiAllocation);
csr->cleanupResources();
EXPECT_EQ(nullptr, csr->hostFunctionDataAllocation);
EXPECT_EQ(nullptr, csr->hostFunctionDataMultiAllocation);
}
TEST(CommandStreamReceiverHostFunctionsTest, givenCommandStreamReceiverWithHostFunctionDataWhenMakeResidentHostFunctionAllocationIsCalledThenHostAllocationIsResident) {
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get(), 0u));
auto &csr = *device->commandStreamReceivers[0];
ASSERT_EQ(nullptr, csr.getHostFunctionDataAllocation());
csr.ensureHostFunctionDataInitialization();
auto *hostDataAllocation = csr.getHostFunctionDataAllocation();
ASSERT_NE(nullptr, hostDataAllocation);
auto csrContextId = csr.getOsContext().getContextId();
EXPECT_FALSE(hostDataAllocation->isResident(csrContextId));
csr.makeResidentHostFunctionAllocation();
EXPECT_TRUE(hostDataAllocation->isResident(csrContextId));
csr.makeNonResident(*hostDataAllocation);
EXPECT_FALSE(hostDataAllocation->isResident(csrContextId));
EXPECT_EQ(1u, csr.getEvictionAllocations().size());
}

View File

@@ -1555,6 +1555,7 @@ static constexpr std::array onceWritableAllocTypesForTbx{
AllocationType::tagBuffer,
AllocationType::syncDispatchToken,
AllocationType::bufferHostMemory,
AllocationType::hostFunction,
};
HWTEST_F(TbxCommandStreamTests, givenAubOneTimeWritableAllocWhenTbxFaultManagerIsAvailableAndAllocIsTbxFaultableThenTbxFaultableTypesShouldReturnTrue) {

View File

@@ -722,6 +722,7 @@ TEST(GmmTest, givenAllocationTypeWhenGettingUsageTypeThenReturnCorrectValue) {
case AllocationType::svmZeroCopy:
case AllocationType::tagBuffer:
case AllocationType::printfSurface:
case AllocationType::hostFunction:
expectedUsage = forceUncached ? uncachedGmmUsageType : GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER;
break;
default:
@@ -831,6 +832,7 @@ TEST(GmmTest, givenAllocationTypeAndMitigatedDcFlushWhenGettingUsageTypeThenRetu
case AllocationType::svmZeroCopy:
case AllocationType::tagBuffer:
case AllocationType::printfSurface:
case AllocationType::hostFunction:
expectedUsage = GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER;
break;
default:

View File

@@ -102,7 +102,8 @@ AllocationTypeTagTestCase allocationTypeTagValues[static_cast<int>(AllocationTyp
{AllocationType::swTagBuffer, "SWTAGBF"},
{AllocationType::deferredTasksList, "TSKLIST"},
{AllocationType::assertBuffer, "ASSRTBUF"},
{AllocationType::syncDispatchToken, "SYNCTOK"}};
{AllocationType::syncDispatchToken, "SYNCTOK"},
{AllocationType::hostFunction, "HOSTFUNC"}};
class AllocationTypeTagString : public ::testing::TestWithParam<AllocationTypeTagTestCase> {};
TEST_P(AllocationTypeTagString, givenGraphicsAllocationTypeWhenCopyTagToStorageInfoThenCorrectTagIsReturned) {

View File

@@ -532,6 +532,14 @@ TEST(MemoryManagerTest, givenTagBufferTypeWhenGetAllocationDataIsCalledThenSyste
EXPECT_TRUE(allocData.flags.useSystemMemory);
}
TEST(MemoryManagerTest, givenHostFunctionTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) {
AllocationData allocData;
MockMemoryManager mockMemoryManager;
AllocationProperties properties{mockRootDeviceIndex, 1, AllocationType::hostFunction, mockDeviceBitfield};
mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties));
EXPECT_TRUE(allocData.flags.useSystemMemory);
}
TEST(MemoryManagerTest, givenGlobalFenceTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) {
AllocationData allocData;
MockMemoryManager mockMemoryManager;

View File

@@ -601,7 +601,8 @@ TEST_F(WddmMemoryManagerTests, givenTypeWhenCallIsStatelessAccessRequiredThenPro
AllocationType::swTagBuffer,
AllocationType::deferredTasksList,
AllocationType::assertBuffer,
AllocationType::syncDispatchToken}) {
AllocationType::syncDispatchToken,
AllocationType::hostFunction}) {
EXPECT_FALSE(wddmMemoryManager->isStatelessAccessRequired(type));
}
}

View File

@@ -447,7 +447,7 @@ TEST(AllocationTypeLogging, givenGraphicsAllocationTypeWhenConvertingToStringThe
DebugVariables flags;
FullyEnabledFileLogger fileLogger(testFile, flags);
std::array<std::pair<NEO::AllocationType, const char *>, 40> allocationTypeValues = {
std::array<std::pair<NEO::AllocationType, const char *>, 41> allocationTypeValues = {
{{AllocationType::buffer, "BUFFER"},
{AllocationType::bufferHostMemory, "BUFFER_HOST_MEMORY"},
{AllocationType::commandBuffer, "COMMAND_BUFFER"},
@@ -487,7 +487,8 @@ TEST(AllocationTypeLogging, givenGraphicsAllocationTypeWhenConvertingToStringThe
{AllocationType::debugContextSaveArea, "DEBUG_CONTEXT_SAVE_AREA"},
{AllocationType::debugSbaTrackingBuffer, "DEBUG_SBA_TRACKING_BUFFER"},
{AllocationType::debugModuleArea, "DEBUG_MODULE_AREA"},
{AllocationType::swTagBuffer, "SW_TAG_BUFFER"}}};
{AllocationType::swTagBuffer, "SW_TAG_BUFFER"},
{AllocationType::hostFunction, "HOST_FUNCTION"}}};
for (const auto &[type, str] : allocationTypeValues) {
GraphicsAllocation graphicsAllocation(0, 1u /*num gmms*/, type, nullptr, 0, 0, MemoryPool::memoryNull, MemoryManager::maxOsContextCount, 0llu);

View File

@@ -102,7 +102,8 @@ LNLTEST_F(LnlProductHelper, whenCheckPreferredAllocationMethodThenAllocateByKmdI
auto allocationType = static_cast<AllocationType>(i);
auto preferredAllocationMethod = productHelper->getPreferredAllocationMethod(allocationType);
if (allocationType == AllocationType::tagBuffer ||
allocationType == AllocationType::timestampPacketTagBuffer) {
allocationType == AllocationType::timestampPacketTagBuffer ||
allocationType == AllocationType::hostFunction) {
EXPECT_TRUE(preferredAllocationMethod.has_value());
EXPECT_EQ(GfxMemoryAllocationMethod::allocateByKmd, preferredAllocationMethod.value());
}

View File

@@ -336,7 +336,8 @@ HWTEST2_F(XeLpgProductHelperTests, whenCheckPreferredAllocationMethodThenAllocat
auto allocationType = static_cast<AllocationType>(i);
auto preferredAllocationMethod = productHelper->getPreferredAllocationMethod(allocationType);
if (allocationType == AllocationType::tagBuffer ||
allocationType == AllocationType::timestampPacketTagBuffer) {
allocationType == AllocationType::timestampPacketTagBuffer ||
allocationType == AllocationType::hostFunction) {
EXPECT_FALSE(preferredAllocationMethod.has_value());
} else {
EXPECT_TRUE(preferredAllocationMethod.has_value());