mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Add checks for default cache policy
Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
a23f211113
commit
ef3678e005
@ -73,6 +73,7 @@ class DrmMockTime : public DrmMockSuccess {
|
||||
class DrmMockCustom : public Drm {
|
||||
public:
|
||||
using Drm::bindAvailable;
|
||||
using Drm::cacheInfo;
|
||||
using Drm::memoryInfo;
|
||||
|
||||
struct IoctlResExt {
|
||||
|
@ -4194,6 +4194,17 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenIsaIsRegisteredThenC
|
||||
EXPECT_EQ(2u, drm.unregisterCalledCount);
|
||||
}
|
||||
|
||||
TEST(DrmAllocationTest, givenDrmAllocationWhenSetCacheRegionIsCalledForDefaultRegionThenReturnTrue) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
|
||||
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
|
||||
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory);
|
||||
|
||||
EXPECT_TRUE(allocation.setCacheRegion(&drm, CacheRegion::Default));
|
||||
}
|
||||
|
||||
TEST(DrmAllocationTest, givenDrmAllocationWhenCacheInfoIsNotAvailableThenCacheRegionIsNotSet) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
@ -4202,10 +4213,10 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenCacheInfoIsNotAvailableThenCacheRe
|
||||
|
||||
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory);
|
||||
|
||||
EXPECT_FALSE(allocation.setCacheRegion(&drm, CacheRegion::None));
|
||||
EXPECT_FALSE(allocation.setCacheRegion(&drm, CacheRegion::Region1));
|
||||
}
|
||||
|
||||
TEST(DrmAllocationTest, givenDrmAllocationWhenCacheInfoIsAvailableThenCacheRegionIsNotSetForTheDefault) {
|
||||
TEST(DrmAllocationTest, givenDrmAllocationWhenDefaultCacheInfoIsAvailableThenCacheRegionIsNotSet) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
|
||||
@ -4214,7 +4225,7 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenCacheInfoIsAvailableThenCacheRegio
|
||||
|
||||
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::BUFFER, MemoryPool::LocalMemory);
|
||||
|
||||
EXPECT_FALSE(allocation.setCacheRegion(&drm, CacheRegion::Default));
|
||||
EXPECT_FALSE(allocation.setCacheRegion(&drm, CacheRegion::Region1));
|
||||
}
|
||||
|
||||
TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsNotSetThenReturnFalse) {
|
||||
@ -4260,4 +4271,63 @@ TEST(DrmAllocationTest, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThenSe
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmAllocationWithHostPtrWhenItIsCreatedWithCacheRegionThenSetRegionInBufferObject) {
|
||||
mock->ioctl_expected.total = -1;
|
||||
auto drm = static_cast<DrmMockCustom *>(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getDrm());
|
||||
drm->cacheInfo.reset(new MockCacheInfo());
|
||||
|
||||
auto ptr = reinterpret_cast<void *>(0x1000);
|
||||
auto size = MemoryConstants::pageSize;
|
||||
|
||||
OsHandleStorage storage;
|
||||
storage.fragmentStorageData[0].cpuPtr = ptr;
|
||||
storage.fragmentStorageData[0].fragmentSize = 1;
|
||||
storage.fragmentCount = 1;
|
||||
|
||||
memoryManager->populateOsHandles(storage, rootDeviceIndex);
|
||||
|
||||
auto allocation = std::make_unique<DrmAllocation>(rootDeviceIndex, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY,
|
||||
nullptr, ptr, castToUint64(ptr), size, MemoryPool::System4KBPages);
|
||||
allocation->fragmentsStorage = storage;
|
||||
|
||||
allocation->setCacheAdvice(drm, 1024, CacheRegion::Region1);
|
||||
|
||||
for (uint32_t i = 0; i < storage.fragmentCount; i++) {
|
||||
auto bo = allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
|
||||
EXPECT_EQ(CacheRegion::Region1, bo->peekCacheRegion());
|
||||
}
|
||||
|
||||
storage.fragmentStorageData[0].freeTheFragment = true;
|
||||
memoryManager->cleanOsHandles(storage, rootDeviceIndex);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmAllocationWithHostPtrWhenItIsCreatedWithIncorrectCacheRegionThenReturnNull) {
|
||||
mock->ioctl_expected.total = -1;
|
||||
auto drm = static_cast<DrmMockCustom *>(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getDrm());
|
||||
drm->setupCacheInfo(*defaultHwInfo.get());
|
||||
|
||||
auto ptr = reinterpret_cast<void *>(0x1000);
|
||||
auto size = MemoryConstants::pageSize;
|
||||
|
||||
allocationData.size = size;
|
||||
allocationData.hostPtr = ptr;
|
||||
allocationData.cacheRegion = 0xFFFF;
|
||||
|
||||
auto allocation = std::unique_ptr<GraphicsAllocation>(memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData));
|
||||
EXPECT_EQ(allocation, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmAllocationWithWithAlignmentFromUserptrWhenItIsCreatedWithIncorrectCacheRegionThenReturnNull) {
|
||||
mock->ioctl_expected.total = -1;
|
||||
auto drm = static_cast<DrmMockCustom *>(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getDrm());
|
||||
drm->setupCacheInfo(*defaultHwInfo.get());
|
||||
|
||||
auto size = MemoryConstants::pageSize;
|
||||
allocationData.size = size;
|
||||
allocationData.cacheRegion = 0xFFFF;
|
||||
|
||||
auto allocation = static_cast<DrmAllocation *>(memoryManager->createAllocWithAlignmentFromUserptr(allocationData, size, 0, 0, 0x1000));
|
||||
EXPECT_EQ(allocation, nullptr);
|
||||
}
|
||||
} // namespace NEO
|
||||
|
@ -17,7 +17,7 @@ struct MockCacheInfo : public CacheInfo {
|
||||
~MockCacheInfo() override = default;
|
||||
|
||||
bool getCacheRegion(size_t regionSize, CacheRegion regionIndex) override {
|
||||
return (regionIndex > CacheRegion::None) ? true : false;
|
||||
return (regionIndex < CacheRegion::Count) ? true : false;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -112,6 +112,10 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryWithHostPtr(const Alloc
|
||||
auto osStorage = hostPtrManager->prepareOsStorageForAllocation(*this, allocationData.size, allocationData.hostPtr, allocationData.rootDeviceIndex);
|
||||
if (osStorage.fragmentCount > 0) {
|
||||
graphicsAllocation = createGraphicsAllocation(osStorage, allocationData);
|
||||
if (graphicsAllocation == nullptr) {
|
||||
hostPtrManager->releaseHandleStorage(allocationData.rootDeviceIndex, osStorage);
|
||||
cleanOsHandles(osStorage, allocationData.rootDeviceIndex);
|
||||
}
|
||||
}
|
||||
return graphicsAllocation;
|
||||
}
|
||||
|
@ -13,10 +13,11 @@
|
||||
namespace NEO {
|
||||
|
||||
enum class CacheRegion : uint16_t {
|
||||
None = 0,
|
||||
Default = 0,
|
||||
Region1,
|
||||
Region2,
|
||||
Default = None
|
||||
Count,
|
||||
None = 0xFFFF
|
||||
};
|
||||
|
||||
struct CacheInfo {
|
||||
|
@ -34,6 +34,14 @@ bool DrmAllocation::setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regi
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fragmentsStorage.fragmentCount > 0) {
|
||||
for (uint32_t i = 0; i < fragmentsStorage.fragmentCount; i++) {
|
||||
auto bo = fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
|
||||
bo->setCacheRegion(regionIndex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto bo : bufferObjects) {
|
||||
if (bo != nullptr) {
|
||||
bo->setCacheRegion(regionIndex);
|
||||
|
@ -19,6 +19,10 @@ void DrmAllocation::bindBOs(OsContext *osContext, uint32_t vmHandleId, std::vect
|
||||
}
|
||||
|
||||
bool DrmAllocation::setCacheRegion(Drm *drm, CacheRegion regionIndex) {
|
||||
if (regionIndex == CacheRegion::Default) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto cacheInfo = static_cast<CacheInfoImpl *>(drm->getCacheInfo());
|
||||
if (cacheInfo == nullptr) {
|
||||
return false;
|
||||
|
@ -223,10 +223,12 @@ void DrmMemoryManager::emitPinningRequest(BufferObject *bo, const AllocationData
|
||||
|
||||
DrmAllocation *DrmMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) {
|
||||
auto hostPtr = const_cast<void *>(allocationData.hostPtr);
|
||||
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, nullptr, hostPtr, castToUint64(hostPtr), allocationData.size, MemoryPool::System4KBPages);
|
||||
auto allocation = std::make_unique<DrmAllocation>(allocationData.rootDeviceIndex, allocationData.type, nullptr, hostPtr, castToUint64(hostPtr), allocationData.size, MemoryPool::System4KBPages);
|
||||
allocation->fragmentsStorage = handleStorage;
|
||||
allocation->setCacheRegion(&this->getDrm(allocationData.rootDeviceIndex), static_cast<CacheRegion>(allocationData.cacheRegion));
|
||||
return allocation;
|
||||
if (!allocation->setCacheRegion(&this->getDrm(allocationData.rootDeviceIndex), static_cast<CacheRegion>(allocationData.cacheRegion))) {
|
||||
return nullptr;
|
||||
}
|
||||
return allocation.release();
|
||||
}
|
||||
|
||||
DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) {
|
||||
@ -265,22 +267,26 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignmentFromUserptr(const Alloc
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto bo = allocUserptr(reinterpret_cast<uintptr_t>(res), size, 0, allocationData.rootDeviceIndex);
|
||||
|
||||
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(allocUserptr(reinterpret_cast<uintptr_t>(res), size, 0, allocationData.rootDeviceIndex));
|
||||
if (!bo) {
|
||||
alignedFreeWrapper(res);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
obtainGpuAddress(allocationData, bo, gpuAddress);
|
||||
emitPinningRequest(bo, allocationData);
|
||||
obtainGpuAddress(allocationData, bo.get(), gpuAddress);
|
||||
emitPinningRequest(bo.get(), allocationData);
|
||||
|
||||
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo, res, bo->gpuAddress, size, MemoryPool::System4KBPages);
|
||||
auto allocation = std::make_unique<DrmAllocation>(allocationData.rootDeviceIndex, allocationData.type, bo.get(), res, bo->gpuAddress, size, MemoryPool::System4KBPages);
|
||||
allocation->setDriverAllocatedCpuPtr(res);
|
||||
allocation->setReservedAddressRange(reinterpret_cast<void *>(gpuAddress), alignedSVMSize);
|
||||
allocation->setCacheRegion(&this->getDrm(allocationData.rootDeviceIndex), static_cast<CacheRegion>(allocationData.cacheRegion));
|
||||
if (!allocation->setCacheRegion(&this->getDrm(allocationData.rootDeviceIndex), static_cast<CacheRegion>(allocationData.cacheRegion))) {
|
||||
alignedFreeWrapper(res);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return allocation;
|
||||
bo.release();
|
||||
|
||||
return allocation.release();
|
||||
}
|
||||
|
||||
void DrmMemoryManager::obtainGpuAddress(const AllocationData &allocationData, BufferObject *bo, uint64_t gpuAddress) {
|
||||
|
@ -70,6 +70,7 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
|
||||
using DrmMemoryManager::allocateShareableMemory;
|
||||
using DrmMemoryManager::allocUserptr;
|
||||
using DrmMemoryManager::createAllocWithAlignment;
|
||||
using DrmMemoryManager::createAllocWithAlignmentFromUserptr;
|
||||
using DrmMemoryManager::createGraphicsAllocation;
|
||||
using DrmMemoryManager::createSharedBufferObject;
|
||||
using DrmMemoryManager::eraseSharedBufferObject;
|
||||
|
Reference in New Issue
Block a user