Refactor: pass root device environment to gmm client context

Related-To: NEO-6853
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2022-11-25 07:53:05 +00:00
committed by Compute-Runtime-Automation
parent ba9c50694d
commit 27cb39ef25
24 changed files with 150 additions and 156 deletions

View File

@@ -8,7 +8,6 @@
#include "level_zero/core/test/unit_tests/fixtures/module_fixture.h" #include "level_zero/core/test/unit_tests/fixtures/module_fixture.h"
#include "shared/source/command_container/implicit_scaling.h" #include "shared/source/command_container/implicit_scaling.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@@ -18,33 +17,7 @@ namespace ult {
ModuleImmutableDataFixture::MockImmutableMemoryManager::MockImmutableMemoryManager(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {} ModuleImmutableDataFixture::MockImmutableMemoryManager::MockImmutableMemoryManager(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
ModuleImmutableDataFixture::MockImmutableData::MockImmutableData(uint32_t perHwThreadPrivateMemorySize) { ModuleImmutableDataFixture::MockImmutableData::MockImmutableData(uint32_t perHwThreadPrivateMemorySize) : MockImmutableData(perHwThreadPrivateMemorySize, 0, 0) {}
mockKernelDescriptor = new NEO::KernelDescriptor;
mockKernelDescriptor->kernelAttributes.perHwThreadPrivateMemorySize = perHwThreadPrivateMemorySize;
kernelDescriptor = mockKernelDescriptor;
mockKernelInfo = new NEO::KernelInfo;
mockKernelInfo->heapInfo.pKernelHeap = kernelHeap;
mockKernelInfo->heapInfo.KernelHeapSize = MemoryConstants::pageSize;
kernelInfo = mockKernelInfo;
if (getIsaGraphicsAllocation() != nullptr) {
device->getNEODevice()->getMemoryManager()->freeGraphicsMemory(&*isaGraphicsAllocation);
isaGraphicsAllocation.release();
}
auto ptr = reinterpret_cast<void *>(0x1234);
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get());
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
isaGraphicsAllocation.reset(new NEO::MockGraphicsAllocation(0,
NEO::AllocationType::KERNEL_ISA,
ptr,
0x1000,
0u,
MemoryPool::System4KBPages,
MemoryManager::maxOsContextCount,
canonizedGpuAddress));
kernelInfo->kernelAllocation = isaGraphicsAllocation.get();
}
ModuleImmutableDataFixture::MockImmutableData::MockImmutableData(uint32_t perHwThreadPrivateMemorySize, uint32_t perThreadScratchSize, uint32_t perThreaddPrivateScratchSize) { ModuleImmutableDataFixture::MockImmutableData::MockImmutableData(uint32_t perHwThreadPrivateMemorySize, uint32_t perThreadScratchSize, uint32_t perThreaddPrivateScratchSize) {
mockKernelDescriptor = new NEO::KernelDescriptor; mockKernelDescriptor = new NEO::KernelDescriptor;
mockKernelDescriptor->kernelAttributes.perHwThreadPrivateMemorySize = perHwThreadPrivateMemorySize; mockKernelDescriptor->kernelAttributes.perHwThreadPrivateMemorySize = perHwThreadPrivateMemorySize;
@@ -57,13 +30,7 @@ ModuleImmutableDataFixture::MockImmutableData::MockImmutableData(uint32_t perHwT
mockKernelInfo->heapInfo.KernelHeapSize = MemoryConstants::pageSize; mockKernelInfo->heapInfo.KernelHeapSize = MemoryConstants::pageSize;
kernelInfo = mockKernelInfo; kernelInfo = mockKernelInfo;
if (getIsaGraphicsAllocation() != nullptr) {
device->getNEODevice()->getMemoryManager()->freeGraphicsMemory(&*isaGraphicsAllocation);
isaGraphicsAllocation.release();
}
auto ptr = reinterpret_cast<void *>(0x1234); auto ptr = reinterpret_cast<void *>(0x1234);
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get());
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
isaGraphicsAllocation.reset(new NEO::MockGraphicsAllocation(0, isaGraphicsAllocation.reset(new NEO::MockGraphicsAllocation(0,
NEO::AllocationType::KERNEL_ISA, NEO::AllocationType::KERNEL_ISA,
ptr, ptr,
@@ -71,7 +38,7 @@ ModuleImmutableDataFixture::MockImmutableData::MockImmutableData(uint32_t perHwT
0u, 0u,
MemoryPool::System4KBPages, MemoryPool::System4KBPages,
MemoryManager::maxOsContextCount, MemoryManager::maxOsContextCount,
canonizedGpuAddress)); castToUint64(ptr)));
kernelInfo->kernelAllocation = isaGraphicsAllocation.get(); kernelInfo->kernelAllocation = isaGraphicsAllocation.get();
} }
@@ -247,8 +214,6 @@ ModuleWithZebinFixture::MockImmutableData::MockImmutableData(L0::Device *device)
kernelDescriptor = mockKernelDescriptor; kernelDescriptor = mockKernelDescriptor;
this->device = device; this->device = device;
auto ptr = reinterpret_cast<void *>(0x1234); auto ptr = reinterpret_cast<void *>(0x1234);
auto gmmHelper = device->getNEODevice()->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
isaGraphicsAllocation.reset(new NEO::MockGraphicsAllocation(0, isaGraphicsAllocation.reset(new NEO::MockGraphicsAllocation(0,
NEO::AllocationType::KERNEL_ISA, NEO::AllocationType::KERNEL_ISA,
ptr, ptr,
@@ -256,7 +221,7 @@ ModuleWithZebinFixture::MockImmutableData::MockImmutableData(L0::Device *device)
0u, 0u,
MemoryPool::System4KBPages, MemoryPool::System4KBPages,
MemoryManager::maxOsContextCount, MemoryManager::maxOsContextCount,
canonizedGpuAddress)); castToUint64(ptr)));
} }
ModuleWithZebinFixture::MockImmutableData::~MockImmutableData() { ModuleWithZebinFixture::MockImmutableData::~MockImmutableData() {
@@ -269,8 +234,7 @@ ModuleWithZebinFixture::MockModuleWithZebin::MockModuleWithZebin(L0::Device *dev
void ModuleWithZebinFixture::MockModuleWithZebin::addSegments() { void ModuleWithZebinFixture::MockModuleWithZebin::addSegments() {
kernelImmDatas.push_back(std::make_unique<MockImmutableData>(device)); kernelImmDatas.push_back(std::make_unique<MockImmutableData>(device));
auto ptr = reinterpret_cast<void *>(0x1234); auto ptr = reinterpret_cast<void *>(0x1234);
auto gmmHelper = device->getNEODevice()->getGmmHelper(); auto canonizedGpuAddress = castToUint64(ptr);
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
translationUnit->globalVarBuffer = new NEO::MockGraphicsAllocation(0, translationUnit->globalVarBuffer = new NEO::MockGraphicsAllocation(0,
NEO::AllocationType::GLOBAL_SURFACE, NEO::AllocationType::GLOBAL_SURFACE,
ptr, ptr,

View File

@@ -283,7 +283,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe
DirectSubmissionControllerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} DirectSubmissionControllerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
}; };
struct GmmHelperMock : public DestructorCounted<GmmHelper, 6> { struct GmmHelperMock : public DestructorCounted<GmmHelper, 6> {
GmmHelperMock(uint32_t &destructorId, const HardwareInfo *hwInfo) : DestructorCounted(destructorId, nullptr, hwInfo) {} GmmHelperMock(uint32_t &destructorId, const RootDeviceEnvironment &rootDeviceEnvironment) : DestructorCounted(destructorId, rootDeviceEnvironment) {}
}; };
struct OsInterfaceMock : public DestructorCounted<OSInterface, 5> { struct OsInterfaceMock : public DestructorCounted<OSInterface, 5> {
OsInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} OsInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
@@ -304,10 +304,8 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe
SourceLevelDebuggerMock(uint32_t &destructorId) : DestructorCounted(destructorId, nullptr) {} SourceLevelDebuggerMock(uint32_t &destructorId) : DestructorCounted(destructorId, nullptr) {}
}; };
auto gmmHelper = new GmmHelperMock(destructorId, defaultHwInfo.get());
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>(); auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
executionEnvironment->rootDeviceEnvironments[0]->gmmHelper = std::unique_ptr<GmmHelperMock>(gmmHelper); executionEnvironment->rootDeviceEnvironments[0]->gmmHelper = std::make_unique<GmmHelperMock>(destructorId, *executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OsInterfaceMock>(destructorId); executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OsInterfaceMock>(destructorId);
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<MemoryOperationsHandlerMock>(destructorId); executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<MemoryOperationsHandlerMock>(destructorId);
executionEnvironment->memoryManager = std::make_unique<MemoryMangerMock>(destructorId, *executionEnvironment); executionEnvironment->memoryManager = std::make_unique<MemoryMangerMock>(destructorId, *executionEnvironment);

View File

@@ -42,6 +42,7 @@ using namespace ::testing;
namespace NEO { namespace NEO {
extern GMM_INIT_IN_ARGS passedInputArgs; extern GMM_INIT_IN_ARGS passedInputArgs;
extern GT_SYSTEM_INFO passedGtSystemInfo;
extern SKU_FEATURE_TABLE passedFtrTable; extern SKU_FEATURE_TABLE passedFtrTable;
extern WA_TABLE passedWaTable; extern WA_TABLE passedWaTable;
extern bool copyInputArgs; extern bool copyInputArgs;
@@ -51,9 +52,11 @@ struct GmmTests : public MockExecutionEnvironmentGmmFixtureTest {
MockExecutionEnvironmentGmmFixture::setUp(); MockExecutionEnvironmentGmmFixture::setUp();
rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get();
localPlatformDevice = rootDeviceEnvironment->getMutableHardwareInfo(); localPlatformDevice = rootDeviceEnvironment->getMutableHardwareInfo();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
} }
RootDeviceEnvironment *rootDeviceEnvironment = nullptr; RootDeviceEnvironment *rootDeviceEnvironment = nullptr;
HardwareInfo *localPlatformDevice = nullptr; HardwareInfo *localPlatformDevice = nullptr;
GmmHelper *gmmHelper = nullptr;
}; };
TEST(GmmGlTests, givenGmmWhenAskedforCubeFaceIndexThenProperValueIsReturned) { TEST(GmmGlTests, givenGmmWhenAskedforCubeFaceIndexThenProperValueIsReturned) {
@@ -350,11 +353,13 @@ TEST_F(GmmTests, givenNonZeroRowPitchWhenQueryImgFromBufferParamsThenUseUserValu
using GmmCanonizeTests = GmmTests; using GmmCanonizeTests = GmmTests;
TEST_F(GmmCanonizeTests, WhenCanonizingThenCorrectAddressIsReturned) { TEST_F(GmmCanonizeTests, WhenCanonizingThenCorrectAddressIsReturned) {
auto hwInfo = *defaultHwInfo; auto &hwInfo = *rootDeviceEnvironment->getMutableHardwareInfo();
// 48 bit - canonize to 48 bit // 48 bit - canonize to 48 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); // 0x0000FFFFFFFFFFFF; hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); // 0x0000FFFFFFFFFFFF;
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo); rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
uint64_t testAddr1 = 0x7777777777777777; uint64_t testAddr1 = 0x7777777777777777;
uint64_t goodAddr1 = 0x0000777777777777; uint64_t goodAddr1 = 0x0000777777777777;
@@ -366,18 +371,22 @@ TEST_F(GmmCanonizeTests, WhenCanonizingThenCorrectAddressIsReturned) {
// 36 bit - also canonize to 48 bit // 36 bit - also canonize to 48 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); // 0x0000000FFFFFFFFF; hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); // 0x0000000FFFFFFFFF;
gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo); rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
EXPECT_EQ(gmmHelper->canonize(testAddr1), goodAddr1); EXPECT_EQ(gmmHelper->canonize(testAddr1), goodAddr1);
EXPECT_EQ(gmmHelper->canonize(testAddr2), goodAddr2); EXPECT_EQ(gmmHelper->canonize(testAddr2), goodAddr2);
} }
TEST_F(GmmCanonizeTests, WhenDecanonizingThenCorrectAddressIsReturned) { TEST_F(GmmCanonizeTests, WhenDecanonizingThenCorrectAddressIsReturned) {
auto hwInfo = *defaultHwInfo; auto &hwInfo = *rootDeviceEnvironment->getMutableHardwareInfo();
// 48 bit - decanonize to 48 bit // 48 bit - decanonize to 48 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); // 0x0000FFFFFFFFFFFF; hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); // 0x0000FFFFFFFFFFFF;
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo); rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
uint64_t testAddr1 = 0x7777777777777777; uint64_t testAddr1 = 0x7777777777777777;
uint64_t goodAddr1 = 0x0000777777777777; uint64_t goodAddr1 = 0x0000777777777777;
@@ -389,18 +398,22 @@ TEST_F(GmmCanonizeTests, WhenDecanonizingThenCorrectAddressIsReturned) {
// 36 bit - also decanonize to 48 bit // 36 bit - also decanonize to 48 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); // 0x0000000FFFFFFFFF; hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); // 0x0000000FFFFFFFFF;
gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo); rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
EXPECT_EQ(gmmHelper->decanonize(testAddr1), goodAddr1); EXPECT_EQ(gmmHelper->decanonize(testAddr1), goodAddr1);
EXPECT_EQ(gmmHelper->decanonize(testAddr2), goodAddr2); EXPECT_EQ(gmmHelper->decanonize(testAddr2), goodAddr2);
} }
TEST_F(GmmCanonizeTests, WhenCheckingIsValidCanonicalGpuAddressThenOnlyValidAddressesReturnTrue) { TEST_F(GmmCanonizeTests, WhenCheckingIsValidCanonicalGpuAddressThenOnlyValidAddressesReturnTrue) {
auto hwInfo = *defaultHwInfo; auto &hwInfo = *rootDeviceEnvironment->getMutableHardwareInfo();
// 48 bit // 48 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); // 0x0000FFFFFFFFFFFF; hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); // 0x0000FFFFFFFFFFFF;
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo); rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
uint64_t testAddr1 = 0x0000400000000000; uint64_t testAddr1 = 0x0000400000000000;
EXPECT_TRUE(gmmHelper->isValidCanonicalGpuAddress(testAddr1)); EXPECT_TRUE(gmmHelper->isValidCanonicalGpuAddress(testAddr1));
@@ -416,7 +429,9 @@ TEST_F(GmmCanonizeTests, WhenCheckingIsValidCanonicalGpuAddressThenOnlyValidAddr
// 36 bit // 36 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); // 0x0000000FFFFFFFFF; hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); // 0x0000000FFFFFFFFF;
gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo); rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
uint64_t testAddr5 = 0x0000000400000000; uint64_t testAddr5 = 0x0000000400000000;
EXPECT_TRUE(gmmHelper->isValidCanonicalGpuAddress(testAddr5)); EXPECT_TRUE(gmmHelper->isValidCanonicalGpuAddress(testAddr5));
@@ -432,7 +447,9 @@ TEST_F(GmmCanonizeTests, WhenCheckingIsValidCanonicalGpuAddressThenOnlyValidAddr
// 57 bit // 57 bit
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(57); // 0x01FFFFFFFFFFFFFFF; hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(57); // 0x01FFFFFFFFFFFFFFF;
gmmHelper = std::make_unique<GmmHelper>(nullptr, &hwInfo); rootDeviceEnvironment->gmmHelper.reset();
rootDeviceEnvironment->initGmm();
gmmHelper = rootDeviceEnvironment->getGmmHelper();
uint64_t testAddr9 = 0x0080000000000000; uint64_t testAddr9 = 0x0080000000000000;
EXPECT_TRUE(gmmHelper->isValidCanonicalGpuAddress(testAddr9)); EXPECT_TRUE(gmmHelper->isValidCanonicalGpuAddress(testAddr9));
@@ -1027,31 +1044,31 @@ struct GmmHelperTests : MockExecutionEnvironmentGmmFixtureTest {
}; };
TEST_F(GmmHelperTests, givenValidGmmFunctionsWhenCreateGmmHelperWithInitializedOsInterfaceThenProperParametersArePassed) { TEST_F(GmmHelperTests, givenValidGmmFunctionsWhenCreateGmmHelperWithInitializedOsInterfaceThenProperParametersArePassed) {
std::unique_ptr<GmmHelper> gmmHelper;
DeviceFactory::prepareDeviceEnvironments(*executionEnvironment); DeviceFactory::prepareDeviceEnvironments(*executionEnvironment);
VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs); VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs);
VariableBackup<decltype(passedFtrTable)> passedFtrTableBackup(&passedFtrTable); VariableBackup<decltype(passedFtrTable)> passedFtrTableBackup(&passedFtrTable);
VariableBackup<decltype(passedGtSystemInfo)> passedGtSystemInfoBackup(&passedGtSystemInfo);
VariableBackup<decltype(passedWaTable)> passedWaTableBackup(&passedWaTable); VariableBackup<decltype(passedWaTable)> passedWaTableBackup(&passedWaTable);
VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true); VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true);
auto hwInfo = defaultHwInfo.get(); auto hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
SKU_FEATURE_TABLE expectedFtrTable = {}; SKU_FEATURE_TABLE expectedFtrTable = {};
WA_TABLE expectedWaTable = {}; WA_TABLE expectedWaTable = {};
SkuInfoTransfer::transferFtrTableForGmm(&expectedFtrTable, &hwInfo->featureTable); SkuInfoTransfer::transferFtrTableForGmm(&expectedFtrTable, &hwInfo->featureTable);
SkuInfoTransfer::transferWaTableForGmm(&expectedWaTable, &hwInfo->workaroundTable); SkuInfoTransfer::transferWaTableForGmm(&expectedWaTable, &hwInfo->workaroundTable);
gmmHelper.reset(new GmmHelper(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(), hwInfo)); auto gmmHelper = std::make_unique<GmmHelper>(*executionEnvironment->rootDeviceEnvironments[0]);
EXPECT_EQ(0, memcmp(&hwInfo->platform, &passedInputArgs.Platform, sizeof(PLATFORM))); EXPECT_EQ(0, memcmp(&hwInfo->platform, &passedInputArgs.Platform, sizeof(PLATFORM)));
EXPECT_EQ(&hwInfo->gtSystemInfo, passedInputArgs.pGtSysInfo); EXPECT_EQ(0, memcmp(&hwInfo->gtSystemInfo, &passedGtSystemInfo, sizeof(GT_SYSTEM_INFO)));
EXPECT_EQ(0, memcmp(&expectedFtrTable, &passedFtrTable, sizeof(SKU_FEATURE_TABLE))); EXPECT_EQ(0, memcmp(&expectedFtrTable, &passedFtrTable, sizeof(SKU_FEATURE_TABLE)));
EXPECT_EQ(0, memcmp(&expectedWaTable, &passedWaTable, sizeof(WA_TABLE))); EXPECT_EQ(0, memcmp(&expectedWaTable, &passedWaTable, sizeof(WA_TABLE)));
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType); EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType);
} }
TEST(GmmHelperTest, givenValidGmmFunctionsWhenCreateGmmHelperWithoutOsInterfaceThenInitializationDoesntCrashAndProperParametersArePassed) { TEST(GmmHelperTest, givenValidGmmFunctionsWhenCreateGmmHelperWithoutOsInterfaceThenInitializationDoesntCrashAndProperParametersArePassed) {
std::unique_ptr<GmmHelper> gmmHelper;
VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs); VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs);
VariableBackup<decltype(passedFtrTable)> passedFtrTableBackup(&passedFtrTable); VariableBackup<decltype(passedFtrTable)> passedFtrTableBackup(&passedFtrTable);
VariableBackup<decltype(passedGtSystemInfo)> passedGtSystemInfoBackup(&passedGtSystemInfo);
VariableBackup<decltype(passedWaTable)> passedWaTableBackup(&passedWaTable); VariableBackup<decltype(passedWaTable)> passedWaTableBackup(&passedWaTable);
VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true); VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true);
@@ -1061,9 +1078,10 @@ TEST(GmmHelperTest, givenValidGmmFunctionsWhenCreateGmmHelperWithoutOsInterfaceT
SkuInfoTransfer::transferFtrTableForGmm(&expectedFtrTable, &hwInfo->featureTable); SkuInfoTransfer::transferFtrTableForGmm(&expectedFtrTable, &hwInfo->featureTable);
SkuInfoTransfer::transferWaTableForGmm(&expectedWaTable, &hwInfo->workaroundTable); SkuInfoTransfer::transferWaTableForGmm(&expectedWaTable, &hwInfo->workaroundTable);
gmmHelper.reset(new GmmHelper(nullptr, hwInfo)); MockExecutionEnvironment executionEnvironment{hwInfo};
EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[0]->osInterface.get());
EXPECT_EQ(0, memcmp(&hwInfo->platform, &passedInputArgs.Platform, sizeof(PLATFORM))); EXPECT_EQ(0, memcmp(&hwInfo->platform, &passedInputArgs.Platform, sizeof(PLATFORM)));
EXPECT_EQ(&hwInfo->gtSystemInfo, passedInputArgs.pGtSysInfo); EXPECT_EQ(0, memcmp(&hwInfo->gtSystemInfo, &passedGtSystemInfo, sizeof(GT_SYSTEM_INFO)));
EXPECT_EQ(0, memcmp(&expectedFtrTable, &passedFtrTable, sizeof(SKU_FEATURE_TABLE))); EXPECT_EQ(0, memcmp(&expectedFtrTable, &passedFtrTable, sizeof(SKU_FEATURE_TABLE)));
EXPECT_EQ(0, memcmp(&expectedWaTable, &passedWaTable, sizeof(WA_TABLE))); EXPECT_EQ(0, memcmp(&expectedWaTable, &passedWaTable, sizeof(WA_TABLE)));
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType); EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType);
@@ -1073,9 +1091,8 @@ TEST(GmmHelperTest, givenGmmHelperAndL3CacheDisabledForDebugThenCorrectMOCSIsRet
decltype(GmmHelper::createGmmContextWrapperFunc) createGmmContextSave = GmmHelper::createGmmContextWrapperFunc; decltype(GmmHelper::createGmmContextWrapperFunc) createGmmContextSave = GmmHelper::createGmmContextWrapperFunc;
GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create<MockGmmClientContext>; GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create<MockGmmClientContext>;
std::unique_ptr<GmmHelper> gmmHelper; MockExecutionEnvironment executionEnvironment{};
auto hwInfo = defaultHwInfo.get(); auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
gmmHelper.reset(new GmmHelper(nullptr, hwInfo));
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED)); EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED));
EXPECT_EQ(2u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER)); EXPECT_EQ(2u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER));
@@ -1101,9 +1118,8 @@ TEST(GmmHelperTest, givenGmmHelperAndForceAllResourcesUncachedDebugVariableSetTh
decltype(GmmHelper::createGmmContextWrapperFunc) createGmmContextSave = GmmHelper::createGmmContextWrapperFunc; decltype(GmmHelper::createGmmContextWrapperFunc) createGmmContextSave = GmmHelper::createGmmContextWrapperFunc;
GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create<MockGmmClientContext>; GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create<MockGmmClientContext>;
std::unique_ptr<GmmHelper> gmmHelper; MockExecutionEnvironment executionEnvironment{};
auto hwInfo = defaultHwInfo.get(); auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
gmmHelper.reset(new GmmHelper(nullptr, hwInfo));
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED)); EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED));
EXPECT_EQ(2u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER)); EXPECT_EQ(2u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER));

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020-2021 Intel Corporation * Copyright (C) 2020-2022 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -45,13 +45,13 @@ TEST(OsInterfaceTest, whenOsInterfaceSetupsGmmInputArgsThenFileDescriptorIsSetWi
} }
TEST(GmmHelperTest, whenCreateGmmHelperWithoutOsInterfaceThenPassedFileDescriptorIsZeroed) { TEST(GmmHelperTest, whenCreateGmmHelperWithoutOsInterfaceThenPassedFileDescriptorIsZeroed) {
std::unique_ptr<GmmHelper> gmmHelper; MockExecutionEnvironment executionEnvironment{};
VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs); VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs);
VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true); VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true);
uint32_t expectedFileDescriptor = 0u; uint32_t expectedFileDescriptor = 0u;
gmmHelper.reset(new GmmHelper(nullptr, defaultHwInfo.get())); auto gmmHelper = std::make_unique<GmmHelper>(*executionEnvironment.rootDeviceEnvironments[0]);
EXPECT_EQ(expectedFileDescriptor, passedInputArgs.FileDescriptor); EXPECT_EQ(expectedFileDescriptor, passedInputArgs.FileDescriptor);
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType); EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType);
} }

View File

@@ -127,8 +127,9 @@ TEST(GraphicsAllocationTest, WhenAllocationIsCreatedThenItsAddressIsCorrect) {
TEST(GraphicsAllocationTest, GivenNonSharedResourceHandleWhenAllocationIsCreatedThenItsAddressIsCorrect) { TEST(GraphicsAllocationTest, GivenNonSharedResourceHandleWhenAllocationIsCreatedThenItsAddressIsCorrect) {
void *cpuPtr = (void *)0x30000; void *cpuPtr = (void *)0x30000;
size_t size = 0x1000; size_t size = 0x1000;
GmmHelper gmmHelper(nullptr, defaultHwInfo.get()); MockExecutionEnvironment executionEnvironment{};
auto canonizedGpuAddress = gmmHelper.canonize(castToUint64(cpuPtr)); auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(cpuPtr));
osHandle sharedHandle = Sharing::nonSharedResource; osHandle sharedHandle = Sharing::nonSharedResource;
GraphicsAllocation gfxAllocation(0, AllocationType::UNKNOWN, cpuPtr, size, sharedHandle, MemoryPool::MemoryNull, 0u, canonizedGpuAddress); GraphicsAllocation gfxAllocation(0, AllocationType::UNKNOWN, cpuPtr, size, sharedHandle, MemoryPool::MemoryNull, 0u, canonizedGpuAddress);
uint64_t expectedGpuAddr = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(gfxAllocation.getUnderlyingBuffer())); uint64_t expectedGpuAddr = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(gfxAllocation.getUnderlyingBuffer()));
@@ -150,7 +151,8 @@ TEST(GraphicsAllocationTest, WhenGettingAddressesThenAddressesAreCorrect) {
cpuPtr = (void *)65535; cpuPtr = (void *)65535;
gpuAddr = 1ULL; gpuAddr = 1ULL;
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get()); MockExecutionEnvironment executionEnvironment{};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(gpuAddr); auto canonizedGpuAddress = gmmHelper->canonize(gpuAddr);
gfxAllocation.setCpuPtrAndGpuAddress(cpuPtr, canonizedGpuAddress); gfxAllocation.setCpuPtrAndGpuAddress(cpuPtr, canonizedGpuAddress);
@@ -340,7 +342,6 @@ TEST_F(MemoryAllocatorTest, WhenPopulatingOsHandleThenOneFragmentIsReturned) {
TEST_F(MemoryAllocatorTest, givenOsHandleStorageWhenOsHandlesAreCleanedAndAubManagerIsNotAvailableThenFreeMemoryIsNotCalledOnAubManager) { TEST_F(MemoryAllocatorTest, givenOsHandleStorageWhenOsHandlesAreCleanedAndAubManagerIsNotAvailableThenFreeMemoryIsNotCalledOnAubManager) {
MockExecutionEnvironment mockExecutionEnvironment(defaultHwInfo.get()); MockExecutionEnvironment mockExecutionEnvironment(defaultHwInfo.get());
MockMemoryManager mockMemoryManager(mockExecutionEnvironment); MockMemoryManager mockMemoryManager(mockExecutionEnvironment);
GmmHelper gmmHelper(nullptr, defaultHwInfo.get());
auto mockAubCenter = new MockAubCenter(*mockExecutionEnvironment.rootDeviceEnvironments[0], false, "aubfile", CommandStreamReceiverType::CSR_AUB); auto mockAubCenter = new MockAubCenter(*mockExecutionEnvironment.rootDeviceEnvironments[0], false, "aubfile", CommandStreamReceiverType::CSR_AUB);
mockAubCenter->aubManager.reset(nullptr); mockAubCenter->aubManager.reset(nullptr);
mockExecutionEnvironment.rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter); mockExecutionEnvironment.rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter);
@@ -360,7 +361,6 @@ TEST_F(MemoryAllocatorTest, givenOsHandleStorageAndFreeMemoryEnabledWhenOsHandle
const uint32_t rootDeviceIndex = 1u; const uint32_t rootDeviceIndex = 1u;
MockExecutionEnvironment mockExecutionEnvironment(defaultHwInfo.get(), true, 3); MockExecutionEnvironment mockExecutionEnvironment(defaultHwInfo.get(), true, 3);
MockMemoryManager mockMemoryManager(mockExecutionEnvironment); MockMemoryManager mockMemoryManager(mockExecutionEnvironment);
GmmHelper gmmHelper(nullptr, defaultHwInfo.get());
auto mockManager0 = new MockAubManager(); auto mockManager0 = new MockAubManager();
auto mockAubCenter0 = new MockAubCenter(*mockExecutionEnvironment.rootDeviceEnvironments[0], false, "aubfile", CommandStreamReceiverType::CSR_AUB); auto mockAubCenter0 = new MockAubCenter(*mockExecutionEnvironment.rootDeviceEnvironments[0], false, "aubfile", CommandStreamReceiverType::CSR_AUB);
mockAubCenter0->aubManager.reset(mockManager0); mockAubCenter0->aubManager.reset(mockManager0);
@@ -1598,7 +1598,6 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerAndFreeMemoryEnabledWh
DebugManager.flags.EnableFreeMemory.set(true); DebugManager.flags.EnableFreeMemory.set(true);
MockExecutionEnvironment executionEnvironment; MockExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(executionEnvironment); OsAgnosticMemoryManager memoryManager(executionEnvironment);
GmmHelper gmmHelper(nullptr, defaultHwInfo.get());
MockAubManager *mockManager = new MockAubManager(); MockAubManager *mockManager = new MockAubManager();
MockAubCenter *mockAubCenter = new MockAubCenter(*executionEnvironment.rootDeviceEnvironments[0], false, "file_name.aub", CommandStreamReceiverType::CSR_AUB); MockAubCenter *mockAubCenter = new MockAubCenter(*executionEnvironment.rootDeviceEnvironments[0], false, "file_name.aub", CommandStreamReceiverType::CSR_AUB);
mockAubCenter->aubManager = std::unique_ptr<MockAubManager>(mockManager); mockAubCenter->aubManager = std::unique_ptr<MockAubManager>(mockManager);
@@ -1615,7 +1614,6 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerAndFreeMemoryDisabledW
DebugManager.flags.EnableFreeMemory.set(false); DebugManager.flags.EnableFreeMemory.set(false);
MockExecutionEnvironment executionEnvironment; MockExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(executionEnvironment); OsAgnosticMemoryManager memoryManager(executionEnvironment);
GmmHelper gmmHelper(nullptr, defaultHwInfo.get());
MockAubManager *mockManager = new MockAubManager(); MockAubManager *mockManager = new MockAubManager();
MockAubCenter *mockAubCenter = new MockAubCenter(*executionEnvironment.rootDeviceEnvironments[0], false, "file_name.aub", CommandStreamReceiverType::CSR_AUB); MockAubCenter *mockAubCenter = new MockAubCenter(*executionEnvironment.rootDeviceEnvironments[0], false, "file_name.aub", CommandStreamReceiverType::CSR_AUB);
mockAubCenter->aubManager = std::unique_ptr<MockAubManager>(mockManager); mockAubCenter->aubManager = std::unique_ptr<MockAubManager>(mockManager);
@@ -2195,8 +2193,9 @@ TEST(GraphicsAllocation, givenSharedHandleBasedConstructorWhenGraphicsAllocation
void *addressWithTrailingBitSet = reinterpret_cast<void *>(address); void *addressWithTrailingBitSet = reinterpret_cast<void *>(address);
uint64_t expectedGpuAddress = 0xf0000000; uint64_t expectedGpuAddress = 0xf0000000;
osHandle sharedHandle{}; osHandle sharedHandle{};
GmmHelper gmmHelper(nullptr, defaultHwInfo.get()); MockExecutionEnvironment executionEnvironment{};
auto canonizedGpuAddress = gmmHelper.canonize(castToUint64(addressWithTrailingBitSet)); auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(addressWithTrailingBitSet));
GraphicsAllocation graphicsAllocation(0, AllocationType::UNKNOWN, addressWithTrailingBitSet, 1u, sharedHandle, MemoryPool::MemoryNull, 0u, canonizedGpuAddress); GraphicsAllocation graphicsAllocation(0, AllocationType::UNKNOWN, addressWithTrailingBitSet, 1u, sharedHandle, MemoryPool::MemoryNull, 0u, canonizedGpuAddress);
EXPECT_EQ(expectedGpuAddress, graphicsAllocation.getGpuAddress()); EXPECT_EQ(expectedGpuAddress, graphicsAllocation.getGpuAddress());
} }

View File

@@ -110,7 +110,7 @@ bool RootDeviceEnvironment::initAilConfiguration() {
void RootDeviceEnvironment::initGmm() { void RootDeviceEnvironment::initGmm() {
if (!gmmHelper) { if (!gmmHelper) {
gmmHelper.reset(new GmmHelper(osInterface.get(), getHardwareInfo())); gmmHelper.reset(new GmmHelper(*this));
} }
} }

View File

@@ -7,6 +7,8 @@
#include "shared/source/gmm_helper/client_context/gmm_client_context.h" #include "shared/source/gmm_helper/client_context/gmm_client_context.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/client_context/gmm_handle_allocator.h"
#include "shared/source/gmm_helper/gmm_interface.h" #include "shared/source/gmm_helper/gmm_interface.h"
#include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/hw_info.h" #include "shared/source/helpers/hw_info.h"
@@ -14,21 +16,23 @@
#include "shared/source/sku_info/operations/sku_info_transfer.h" #include "shared/source/sku_info/operations/sku_info_transfer.h"
namespace NEO { namespace NEO {
GmmClientContext::GmmClientContext(OSInterface *osInterface, HardwareInfo *hwInfo) : hardwareInfo(hwInfo) { GmmClientContext::GmmClientContext(const RootDeviceEnvironment &rootDeviceEnvironment) : hardwareInfo(rootDeviceEnvironment.getHardwareInfo()) {
_SKU_FEATURE_TABLE gmmFtrTable = {}; _SKU_FEATURE_TABLE gmmFtrTable = {};
_WA_TABLE gmmWaTable = {}; _WA_TABLE gmmWaTable = {};
SkuInfoTransfer::transferFtrTableForGmm(&gmmFtrTable, &hwInfo->featureTable); SkuInfoTransfer::transferFtrTableForGmm(&gmmFtrTable, &hardwareInfo->featureTable);
SkuInfoTransfer::transferWaTableForGmm(&gmmWaTable, &hwInfo->workaroundTable); SkuInfoTransfer::transferWaTableForGmm(&gmmWaTable, &hardwareInfo->workaroundTable);
GMM_INIT_IN_ARGS inArgs{}; GMM_INIT_IN_ARGS inArgs{};
GMM_INIT_OUT_ARGS outArgs{}; GMM_INIT_OUT_ARGS outArgs{};
auto gtSystemInfo = hardwareInfo->gtSystemInfo;
inArgs.ClientType = GMM_CLIENT::GMM_OCL_VISTA; inArgs.ClientType = GMM_CLIENT::GMM_OCL_VISTA;
inArgs.pGtSysInfo = &hwInfo->gtSystemInfo; inArgs.pGtSysInfo = &gtSystemInfo;
inArgs.pSkuTable = &gmmFtrTable; inArgs.pSkuTable = &gmmFtrTable;
inArgs.pWaTable = &gmmWaTable; inArgs.pWaTable = &gmmWaTable;
inArgs.Platform = hwInfo->platform; inArgs.Platform = hardwareInfo->platform;
auto osInterface = rootDeviceEnvironment.osInterface.get();
if (osInterface && osInterface->getDriverModel()) { if (osInterface && osInterface->getDriverModel()) {
osInterface->getDriverModel()->setGmmInputArgs(&inArgs); osInterface->getDriverModel()->setGmmInputArgs(&inArgs);
} }
@@ -86,5 +90,8 @@ uint32_t GmmClientContext::cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResource
return patIndex; return patIndex;
} }
void GmmClientContext::setHandleAllocator(std::unique_ptr<GmmHandleAllocator> allocator) {
this->handleAllocator = std::move(allocator);
}
} // namespace NEO } // namespace NEO

View File

@@ -6,19 +6,19 @@
*/ */
#pragma once #pragma once
#include "shared/source/gmm_helper/client_context/gmm_handle_allocator.h"
#include "shared/source/gmm_helper/gmm_lib.h" #include "shared/source/gmm_helper/gmm_lib.h"
#include <memory> #include <memory>
namespace NEO { namespace NEO {
class GmmClientContext; class GmmClientContext;
class OSInterface; struct RootDeviceEnvironment;
struct HardwareInfo; struct HardwareInfo;
class GmmHandleAllocator;
class GmmClientContext { class GmmClientContext {
public: public:
GmmClientContext(OSInterface *osInterface, HardwareInfo *hwInfo); GmmClientContext(const RootDeviceEnvironment &rootDeviceEnvironment);
MOCKABLE_VIRTUAL ~GmmClientContext(); MOCKABLE_VIRTUAL ~GmmClientContext();
MOCKABLE_VIRTUAL MEMORY_OBJECT_CONTROL_STATE cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage); MOCKABLE_VIRTUAL MEMORY_OBJECT_CONTROL_STATE cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage);
@@ -29,8 +29,8 @@ class GmmClientContext {
MOCKABLE_VIRTUAL void destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo); MOCKABLE_VIRTUAL void destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo);
GMM_CLIENT_CONTEXT *getHandle() const; GMM_CLIENT_CONTEXT *getHandle() const;
template <typename T> template <typename T>
static std::unique_ptr<GmmClientContext> create(OSInterface *osInterface, HardwareInfo *hwInfo) { static std::unique_ptr<GmmClientContext> create(const RootDeviceEnvironment &rootDeviceEnvironment) {
return std::make_unique<T>(osInterface, hwInfo); return std::make_unique<T>(rootDeviceEnvironment);
} }
const HardwareInfo *getHardwareInfo() { const HardwareInfo *getHardwareInfo() {
@@ -40,9 +40,7 @@ class GmmClientContext {
MOCKABLE_VIRTUAL uint8_t getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format); MOCKABLE_VIRTUAL uint8_t getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format);
MOCKABLE_VIRTUAL uint8_t getMediaSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format); MOCKABLE_VIRTUAL uint8_t getMediaSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format);
void setHandleAllocator(std::unique_ptr<GmmHandleAllocator> allocator) { void setHandleAllocator(std::unique_ptr<GmmHandleAllocator> allocator);
this->handleAllocator = std::move(allocator);
}
MOCKABLE_VIRTUAL void setGmmDeviceInfo(GMM_DEVICE_INFO *deviceInfo); MOCKABLE_VIRTUAL void setGmmDeviceInfo(GMM_DEVICE_INFO *deviceInfo);
@@ -51,7 +49,7 @@ class GmmClientContext {
} }
protected: protected:
HardwareInfo *hardwareInfo = nullptr; const HardwareInfo *hardwareInfo = nullptr;
GMM_CLIENT_CONTEXT *clientContext; GMM_CLIENT_CONTEXT *clientContext;
std::unique_ptr<GmmHandleAllocator> handleAllocator; std::unique_ptr<GmmHandleAllocator> handleAllocator;
}; };

View File

@@ -7,7 +7,7 @@
#pragma once #pragma once
#include "shared/source/gmm_helper/gmm.h" #include "shared/source/gmm_helper/gmm_lib.h"
#include <cstddef> #include <cstddef>

View File

@@ -8,6 +8,7 @@
#include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/client_context/gmm_client_context.h" #include "shared/source/gmm_helper/client_context/gmm_client_context.h"
#include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/hw_helper.h" #include "shared/source/helpers/hw_helper.h"
@@ -42,11 +43,11 @@ void GmmHelper::applyMocsEncryptionBit(uint32_t &index) {
} }
} }
GmmHelper::GmmHelper(OSInterface *osInterface, const HardwareInfo *pHwInfo) : hwInfo(pHwInfo) { GmmHelper::GmmHelper(const RootDeviceEnvironment &rootDeviceEnvironment) : hwInfo(rootDeviceEnvironment.getHardwareInfo()) {
auto hwInfoAddressWidth = Math::log2(hwInfo->capabilityTable.gpuAddressSpace + 1); auto hwInfoAddressWidth = Math::log2(hwInfo->capabilityTable.gpuAddressSpace + 1);
addressWidth = std::max(hwInfoAddressWidth, 48u); addressWidth = std::max(hwInfoAddressWidth, 48u);
gmmClientContext = GmmHelper::createGmmContextWrapperFunc(osInterface, const_cast<HardwareInfo *>(pHwInfo)); gmmClientContext = GmmHelper::createGmmContextWrapperFunc(rootDeviceEnvironment);
UNRECOVERABLE_IF(!gmmClientContext); UNRECOVERABLE_IF(!gmmClientContext);
} }

View File

@@ -11,13 +11,13 @@
namespace NEO { namespace NEO {
class GmmClientContext; class GmmClientContext;
class OSInterface;
struct HardwareInfo; struct HardwareInfo;
struct RootDeviceEnvironment;
class GmmHelper { class GmmHelper {
public: public:
GmmHelper() = delete; GmmHelper() = delete;
GmmHelper(OSInterface *osInterface, const HardwareInfo *hwInfo); GmmHelper(const RootDeviceEnvironment &rootDeviceEnvironment);
MOCKABLE_VIRTUAL ~GmmHelper(); MOCKABLE_VIRTUAL ~GmmHelper();
const HardwareInfo *getHardwareInfo(); const HardwareInfo *getHardwareInfo();
@@ -37,7 +37,7 @@ class GmmHelper {
GmmClientContext *getClientContext() const; GmmClientContext *getClientContext() const;
static std::unique_ptr<GmmClientContext> (*createGmmContextWrapperFunc)(OSInterface *, HardwareInfo *); static std::unique_ptr<GmmClientContext> (*createGmmContextWrapperFunc)(const RootDeviceEnvironment &);
protected: protected:
uint32_t addressWidth; uint32_t addressWidth;

View File

@@ -6,6 +6,7 @@
*/ */
#include "shared/source/gmm_helper/client_context/gmm_client_context.h" #include "shared/source/gmm_helper/client_context/gmm_client_context.h"
#include "shared/source/gmm_helper/client_context/gmm_handle_allocator.h"
#include "shared/source/gmm_helper/resource_info.h" #include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/debug_helpers.h"

View File

@@ -5,7 +5,7 @@
* *
*/ */
#include "drm_neo.h" #include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/command_stream/submission_status.h" #include "shared/source/command_stream/submission_status.h"
#include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/debug_settings/debug_settings_manager.h"
@@ -13,6 +13,7 @@
#include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/cache_settings_helper.h" #include "shared/source/gmm_helper/cache_settings_helper.h"
#include "shared/source/gmm_helper/client_context/gmm_client_context.h" #include "shared/source/gmm_helper/client_context/gmm_client_context.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/resource_info.h" #include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/constants.h" #include "shared/source/helpers/constants.h"
#include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/debug_helpers.h"

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018-2021 Intel Corporation * Copyright (C) 2018-2022 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -9,6 +9,7 @@
namespace NEO { namespace NEO {
GMM_INIT_IN_ARGS passedInputArgs = {}; GMM_INIT_IN_ARGS passedInputArgs = {};
GT_SYSTEM_INFO passedGtSystemInfo = {};
SKU_FEATURE_TABLE passedFtrTable = {}; SKU_FEATURE_TABLE passedFtrTable = {};
WA_TABLE passedWaTable = {}; WA_TABLE passedWaTable = {};
bool copyInputArgs = false; bool copyInputArgs = false;
@@ -23,6 +24,7 @@ GMM_STATUS initialize(GMM_INIT_IN_ARGS *pInArgs, GMM_INIT_OUT_ARGS *pOutArgs) {
} }
if (copyInputArgs) { if (copyInputArgs) {
passedInputArgs = *pInArgs; passedInputArgs = *pInArgs;
passedGtSystemInfo = *reinterpret_cast<GT_SYSTEM_INFO *>(pInArgs->pGtSysInfo);
passedFtrTable = *reinterpret_cast<SKU_FEATURE_TABLE *>(pInArgs->pSkuTable); passedFtrTable = *reinterpret_cast<SKU_FEATURE_TABLE *>(pInArgs->pSkuTable);
passedWaTable = *reinterpret_cast<WA_TABLE *>(pInArgs->pWaTable); passedWaTable = *reinterpret_cast<WA_TABLE *>(pInArgs->pWaTable);
} }

View File

@@ -8,8 +8,6 @@
#include "mock_gmm_client_context.h" #include "mock_gmm_client_context.h"
namespace NEO { namespace NEO {
MockGmmClientContext::MockGmmClientContext(OSInterface *osInterface, HardwareInfo *hwInfo) : MockGmmClientContextBase(osInterface, hwInfo) {
}
MEMORY_OBJECT_CONTROL_STATE MockGmmClientContextBase::cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) { MEMORY_OBJECT_CONTROL_STATE MockGmmClientContextBase::cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) {
MEMORY_OBJECT_CONTROL_STATE retVal = {}; MEMORY_OBJECT_CONTROL_STATE retVal = {};

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018-2021 Intel Corporation * Copyright (C) 2018-2022 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -11,6 +11,6 @@
namespace NEO { namespace NEO {
class MockGmmClientContext : public MockGmmClientContextBase { class MockGmmClientContext : public MockGmmClientContextBase {
public: public:
MockGmmClientContext(OSInterface *osInterface, HardwareInfo *hwInfo); using MockGmmClientContextBase::MockGmmClientContextBase;
}; };
} // namespace NEO } // namespace NEO

View File

@@ -46,6 +46,7 @@ class DrmCommandStreamTest : public ::testing::Test {
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock)); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
executionEnvironment.rootDeviceEnvironments[0]->initGmm(); executionEnvironment.rootDeviceEnvironments[0]->initGmm();
gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo)); mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo));
osContext = std::make_unique<OsContextLinux>(*mock, 0, 0u, osContext = std::make_unique<OsContextLinux>(*mock, 0, 0u,
@@ -95,6 +96,7 @@ class DrmCommandStreamTest : public ::testing::Test {
DebugManagerStateRestore dbgState; DebugManagerStateRestore dbgState;
MockExecutionEnvironment executionEnvironment; MockExecutionEnvironment executionEnvironment;
std::unique_ptr<OsContextLinux> osContext; std::unique_ptr<OsContextLinux> osContext;
GmmHelper *gmmHelper = nullptr;
}; };
template <typename DrmType> template <typename DrmType>

View File

@@ -10,6 +10,7 @@
#include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/test/common/fixtures/device_fixture.h" #include "shared/test/common/fixtures/device_fixture.h"
#include "shared/test/common/fixtures/linear_stream_fixture.h" #include "shared/test/common/fixtures/linear_stream_fixture.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_graphics_allocation.h"
using namespace NEO; using namespace NEO;
@@ -42,7 +43,8 @@ TEST(LinearStreamSimpleTest, givenLinearStreamWithoutGraphicsAllocationWhenGetti
TEST(LinearStreamSimpleTest, givenLinearStreamWithGraphicsAllocationWhenGettingGpuBaseThenGpuAddressFromGraphicsAllocationIsReturned) { TEST(LinearStreamSimpleTest, givenLinearStreamWithGraphicsAllocationWhenGettingGpuBaseThenGpuAddressFromGraphicsAllocationIsReturned) {
MockGraphicsAllocation gfxAllocation; MockGraphicsAllocation gfxAllocation;
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get()); auto executionEnvironment = MockExecutionEnvironment{};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(0x5555000); auto canonizedGpuAddress = gmmHelper->canonize(0x5555000);
gfxAllocation.setCpuPtrAndGpuAddress(nullptr, canonizedGpuAddress); gfxAllocation.setCpuPtrAndGpuAddress(nullptr, canonizedGpuAddress);

View File

@@ -10,11 +10,12 @@
#include "shared/source/gmm_helper/resource_info.h" #include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/constants.h" #include "shared/source/helpers/constants.h"
#include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/helpers/default_hw_info.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_gmm_client_context.h" #include "shared/test/common/mocks/mock_gmm_client_context.h"
#include "shared/test/common/mocks/mock_gmm_resource_info.h" #include "shared/test/common/mocks/mock_gmm_resource_info.h"
#include "shared/test/common/test_macros/hw_test.h" #include "shared/test/common/test_macros/hw_test.h"
extern PRODUCT_FAMILY productFamily; using namespace NEO;
struct MockGmmHandleAllocator : NEO::GmmHandleAllocator { struct MockGmmHandleAllocator : NEO::GmmHandleAllocator {
void *createHandle(const GMM_RESOURCE_INFO *gmmResourceInfo) override { void *createHandle(const GMM_RESOURCE_INFO *gmmResourceInfo) override {
@@ -40,9 +41,9 @@ struct MockGmmHandleAllocator : NEO::GmmHandleAllocator {
}; };
TEST(GmmResourceInfo, WhenGmmHandleAllocatorIsPresentThenItsBeingUsedForCreatingGmmResourceInfoHandles) { TEST(GmmResourceInfo, WhenGmmHandleAllocatorIsPresentThenItsBeingUsedForCreatingGmmResourceInfoHandles) {
NEO::HardwareInfo hwInfo; auto hwInfo = *defaultHwInfo;
hwInfo.platform.eProductFamily = productFamily; MockExecutionEnvironment executionEnvironment{&hwInfo};
NEO::MockGmmClientContext gmmClientCtx{nullptr, &hwInfo}; NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]};
gmmClientCtx.setHandleAllocator(std::make_unique<MockGmmHandleAllocator>()); gmmClientCtx.setHandleAllocator(std::make_unique<MockGmmHandleAllocator>());
auto handleAllocator = static_cast<MockGmmHandleAllocator *>(gmmClientCtx.getHandleAllocator()); auto handleAllocator = static_cast<MockGmmHandleAllocator *>(gmmClientCtx.getHandleAllocator());
@@ -73,9 +74,9 @@ TEST(GmmResourceInfo, WhenGmmHandleAllocatorIsPresentThenItsBeingUsedForCreating
} }
TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenDecodingResourceInfoThenExistingHandleIsOpened) { TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenDecodingResourceInfoThenExistingHandleIsOpened) {
NEO::HardwareInfo hwInfo; auto hwInfo = *defaultHwInfo;
hwInfo.platform.eProductFamily = productFamily; MockExecutionEnvironment executionEnvironment{&hwInfo};
NEO::MockGmmClientContext gmmClientCtx{nullptr, &hwInfo}; NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]};
gmmClientCtx.setHandleAllocator(std::make_unique<MockGmmHandleAllocator>()); gmmClientCtx.setHandleAllocator(std::make_unique<MockGmmHandleAllocator>());
auto handleAllocator = static_cast<MockGmmHandleAllocator *>(gmmClientCtx.getHandleAllocator()); auto handleAllocator = static_cast<MockGmmHandleAllocator *>(gmmClientCtx.getHandleAllocator());
@@ -131,9 +132,9 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenD
} }
TEST(GmmResourceInfo, GivenResourceInfoWhenRefreshIsCalledTiwceThenOpenHandleIsCalledTwice) { TEST(GmmResourceInfo, GivenResourceInfoWhenRefreshIsCalledTiwceThenOpenHandleIsCalledTwice) {
NEO::HardwareInfo hwInfo; auto hwInfo = *defaultHwInfo;
hwInfo.platform.eProductFamily = productFamily; MockExecutionEnvironment executionEnvironment{&hwInfo};
NEO::MockGmmClientContext gmmClientCtx{nullptr, &hwInfo}; NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]};
gmmClientCtx.setHandleAllocator(std::make_unique<MockGmmHandleAllocator>()); gmmClientCtx.setHandleAllocator(std::make_unique<MockGmmHandleAllocator>());
auto handleAllocator = static_cast<MockGmmHandleAllocator *>(gmmClientCtx.getHandleAllocator()); auto handleAllocator = static_cast<MockGmmHandleAllocator *>(gmmClientCtx.getHandleAllocator());
@@ -206,23 +207,28 @@ TEST(GmmResourceInfo, GivenEmptyHandleWhenUsingBaseHandleAllocatorThenOpenHandle
} }
TEST(GmmHelperTests, WhenInitializingGmmHelperThenCorrectAddressWidthIsSet) { TEST(GmmHelperTests, WhenInitializingGmmHelperThenCorrectAddressWidthIsSet) {
auto hwInfo = *NEO::defaultHwInfo; auto hwInfo = *defaultHwInfo;
{
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48);
auto gmmHelper = std::make_unique<NEO::GmmHelper>(nullptr, &hwInfo); MockExecutionEnvironment executionEnvironment{&hwInfo};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
auto addressWidth = gmmHelper->getAddressWidth(); auto addressWidth = gmmHelper->getAddressWidth();
EXPECT_EQ(48u, addressWidth); EXPECT_EQ(48u, addressWidth);
}
{
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36);
gmmHelper = std::make_unique<NEO::GmmHelper>(nullptr, &hwInfo); MockExecutionEnvironment executionEnvironment{&hwInfo};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
addressWidth = gmmHelper->getAddressWidth(); auto addressWidth = gmmHelper->getAddressWidth();
EXPECT_EQ(48u, addressWidth); EXPECT_EQ(48u, addressWidth);
}
{
hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(57); hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(57);
gmmHelper = std::make_unique<NEO::GmmHelper>(nullptr, &hwInfo); MockExecutionEnvironment executionEnvironment{&hwInfo};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
addressWidth = gmmHelper->getAddressWidth(); auto addressWidth = gmmHelper->getAddressWidth();
EXPECT_EQ(57u, addressWidth); EXPECT_EQ(57u, addressWidth);
} }
}

View File

@@ -11,6 +11,7 @@
#include "shared/source/indirect_heap/indirect_heap.h" #include "shared/source/indirect_heap/indirect_heap.h"
#include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/helpers/default_hw_info.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@@ -66,7 +67,8 @@ TEST_F(HeapDirtyStateTests, givenNonDirtyObjectWhenAddressChangedThenReturnDirty
auto newBuffer = ptrOffset(buffer, MemoryConstants::pageSize + 1); auto newBuffer = ptrOffset(buffer, MemoryConstants::pageSize + 1);
auto graphicsAllocation = stream->getGraphicsAllocation(); auto graphicsAllocation = stream->getGraphicsAllocation();
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get()); MockExecutionEnvironment executionEnvironment{};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(newBuffer)); auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(newBuffer));
graphicsAllocation->setCpuPtrAndGpuAddress(newBuffer, canonizedGpuAddress); graphicsAllocation->setCpuPtrAndGpuAddress(newBuffer, canonizedGpuAddress);
@@ -106,7 +108,8 @@ TEST_F(HeapDirtyStateTests, givenNonDirtyObjectWhenSizeAndBufferChangedThenRetur
auto newBuffer = ptrOffset(buffer, 1); auto newBuffer = ptrOffset(buffer, 1);
auto newBufferSize = bufferSize + MemoryConstants::pageSize; auto newBufferSize = bufferSize + MemoryConstants::pageSize;
auto graphicsAllocation = stream->getGraphicsAllocation(); auto graphicsAllocation = stream->getGraphicsAllocation();
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get()); MockExecutionEnvironment executionEnvironment{};
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(newBuffer)); auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(newBuffer));
graphicsAllocation->setSize(newBufferSize); graphicsAllocation->setSize(newBufferSize);

View File

@@ -232,8 +232,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamTest, GivenInvalidAddressWhenFlushingThenSucc
char *commandBuffer = new (std::nothrow) char[1024]; char *commandBuffer = new (std::nothrow) char[1024];
ASSERT_NE(nullptr, commandBuffer); // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks) ASSERT_NE(nullptr, commandBuffer); // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
GmmHelper gmmHelper(nullptr, defaultHwInfo.get()); auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(commandBuffer));
auto canonizedGpuAddress = gmmHelper.canonize(castToUint64(commandBuffer));
DrmAllocation commandBufferAllocation(0, AllocationType::COMMAND_BUFFER, nullptr, commandBuffer, 1024, static_cast<osHandle>(1u), MemoryPool::MemoryNull, canonizedGpuAddress); DrmAllocation commandBufferAllocation(0, AllocationType::COMMAND_BUFFER, nullptr, commandBuffer, 1024, static_cast<osHandle>(1u), MemoryPool::MemoryNull, canonizedGpuAddress);
LinearStream cs(&commandBufferAllocation); LinearStream cs(&commandBufferAllocation);

View File

@@ -28,7 +28,7 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::System64KBPages); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::System64KBPages);
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get()); auto gmmHelper = executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(0x12345); auto canonizedGpuAddress = gmmHelper->canonize(0x12345);
allocation.setCpuPtrAndGpuAddress(&allocation, canonizedGpuAddress); allocation.setCpuPtrAndGpuAddress(&allocation, canonizedGpuAddress);
@@ -79,7 +79,7 @@ TEST(FileLogger, givenLogAllocationStdoutWhenLogAllocationThenLogToStdoutInstead
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]); DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::System64KBPages); MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::System64KBPages);
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get()); auto gmmHelper = executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(0x12345); auto canonizedGpuAddress = gmmHelper->canonize(0x12345);
allocation.setCpuPtrAndGpuAddress(&allocation, canonizedGpuAddress); allocation.setCpuPtrAndGpuAddress(&allocation, canonizedGpuAddress);

View File

@@ -201,21 +201,20 @@ NTSTATUS __stdcall getDeviceStateMock(D3DKMT_GETDEVICESTATE *arg) {
struct WddmLinuxTest : public ::testing::Test { struct WddmLinuxTest : public ::testing::Test {
void SetUp() override { void SetUp() override {
mockRootDeviceEnvironment = std::make_unique<NEO::MockRootDeviceEnvironment>(mockExecEnv);
osEnvironment = std::make_unique<NEO::OsEnvironmentWin>(); osEnvironment = std::make_unique<NEO::OsEnvironmentWin>();
osEnvironment->gdi->closeAdapter = closeAdapterMock; osEnvironment->gdi->closeAdapter = closeAdapterMock;
auto hwDeviceIdIn = std::make_unique<WddmLinuxMockHwDeviceIdWddm>(NULL_HANDLE, LUID{}, osEnvironment.get(), std::make_unique<NEO::UmKmDataTranslator>()); auto hwDeviceIdIn = std::make_unique<WddmLinuxMockHwDeviceIdWddm>(NULL_HANDLE, LUID{}, osEnvironment.get(), std::make_unique<NEO::UmKmDataTranslator>());
this->hwDeviceId = hwDeviceIdIn.get(); this->hwDeviceId = hwDeviceIdIn.get();
auto &rootDeviceEnvironment = *mockExecEnv.rootDeviceEnvironments[0];
auto wddm = std::make_unique<MockWddmLinux>(std::move(hwDeviceIdIn), *mockRootDeviceEnvironment.get()); auto wddm = std::make_unique<MockWddmLinux>(std::move(hwDeviceIdIn), rootDeviceEnvironment);
this->wddm = wddm.get(); this->wddm = wddm.get();
mockGmmClientContext = NEO::GmmClientContext::create<NEO::MockGmmClientContext>(nullptr, NEO::defaultHwInfo.get()); auto gmmHelper = rootDeviceEnvironment.getGmmHelper();
wddm->gmmMemory = std::make_unique<MockGmmMemoryWddmLinux>(mockGmmClientContext.get());
wddm->gmmMemory = std::make_unique<MockGmmMemoryWddmLinux>(gmmHelper->getClientContext());
*wddm->gfxPlatform = NEO::defaultHwInfo->platform; *wddm->gfxPlatform = NEO::defaultHwInfo->platform;
mockExecEnv.rootDeviceEnvironments[0]->osInterface.reset(new NEO::OSInterface); rootDeviceEnvironment.osInterface.reset(new NEO::OSInterface);
mockExecEnv.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::move(wddm)); rootDeviceEnvironment.osInterface->setDriverModel(std::move(wddm));
mockExecEnv.rootDeviceEnvironments[0]->gmmHelper.reset(new NEO::GmmHelper(mockExecEnv.rootDeviceEnvironments[0]->osInterface.get(), mockExecEnv.rootDeviceEnvironments[0]->getHardwareInfo()));
} }
size_t getMaxSvmSize() const { size_t getMaxSvmSize() const {
@@ -231,10 +230,8 @@ struct WddmLinuxTest : public ::testing::Test {
std::unique_ptr<NEO::OsEnvironmentWin> osEnvironment; std::unique_ptr<NEO::OsEnvironmentWin> osEnvironment;
NEO::MockExecutionEnvironment mockExecEnv; NEO::MockExecutionEnvironment mockExecEnv;
std::unique_ptr<NEO::MockRootDeviceEnvironment> mockRootDeviceEnvironment;
MockWddmLinux *wddm = nullptr; MockWddmLinux *wddm = nullptr;
WddmLinuxMockHwDeviceIdWddm *hwDeviceId = nullptr; WddmLinuxMockHwDeviceIdWddm *hwDeviceId = nullptr;
std::unique_ptr<NEO::GmmClientContext> mockGmmClientContext;
}; };
using GmmTestsDG2 = WddmLinuxTest; using GmmTestsDG2 = WddmLinuxTest;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020-2021 Intel Corporation * Copyright (C) 2020-2022 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -9,6 +9,7 @@
#include "shared/source/gmm_helper/gmm_lib.h" #include "shared/source/gmm_helper/gmm_lib.h"
#include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/helpers/default_hw_info.h"
#include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@@ -18,13 +19,12 @@ extern GMM_INIT_IN_ARGS passedInputArgs;
extern bool copyInputArgs; extern bool copyInputArgs;
TEST(GmmHelperTest, whenCreateGmmHelperWithoutOsInterfaceThenPassedAdapterBDFIsZeroed) { TEST(GmmHelperTest, whenCreateGmmHelperWithoutOsInterfaceThenPassedAdapterBDFIsZeroed) {
std::unique_ptr<GmmHelper> gmmHelper;
VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs); VariableBackup<decltype(passedInputArgs)> passedInputArgsBackup(&passedInputArgs);
VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true); VariableBackup<decltype(copyInputArgs)> copyInputArgsBackup(&copyInputArgs, true);
ADAPTER_BDF expectedAdapterBDF{}; ADAPTER_BDF expectedAdapterBDF{};
gmmHelper.reset(new GmmHelper(nullptr, defaultHwInfo.get())); MockExecutionEnvironment executionEnvironment{};
EXPECT_EQ(0, memcmp(&expectedAdapterBDF, &passedInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF))); EXPECT_EQ(0, memcmp(&expectedAdapterBDF, &passedInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType); EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType);
} }