Simplify getAllocationProperties
Change-Id: I006337ec700e50259c46be1fd73fde34562c8b83 Related-To: NEO-2535 Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
parent
068a8d7189
commit
ddcd3fbbed
|
@ -31,13 +31,11 @@ bool MemObjHelper::parseMemoryProperties(const cl_mem_properties_intel *properti
|
|||
return true;
|
||||
}
|
||||
|
||||
AllocationProperties MemObjHelper::getAllocationProperties(MemoryProperties memoryProperties, bool allocateMemory,
|
||||
size_t size, GraphicsAllocation::AllocationType type) {
|
||||
AllocationProperties allocationProperties(allocateMemory, size, type);
|
||||
void MemObjHelper::fillPoliciesInProperties(AllocationProperties &allocationProperties, MemoryProperties &memoryProperties) {
|
||||
fillCachePolicyInProperties(allocationProperties,
|
||||
isValueSet(memoryProperties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE),
|
||||
isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY));
|
||||
return allocationProperties;
|
||||
isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY),
|
||||
false);
|
||||
}
|
||||
|
||||
bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressed, const MemoryProperties &properties, ContextType contextType, bool preferCompression) {
|
||||
|
|
|
@ -88,19 +88,25 @@ class MemObjHelper {
|
|||
return validateExtraMemoryProperties(properties);
|
||||
}
|
||||
|
||||
static AllocationProperties getAllocationProperties(MemoryProperties properties, bool allocateMemory,
|
||||
size_t size, GraphicsAllocation::AllocationType type);
|
||||
static AllocationProperties getAllocationProperties(ImageInfo &imgInfo, bool allocateMemory, MemoryProperties memoryProperties) {
|
||||
AllocationProperties allocationProperties{allocateMemory, imgInfo, GraphicsAllocation::AllocationType::IMAGE};
|
||||
fillCachePolicyInProperties(allocationProperties,
|
||||
isValueSet(memoryProperties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE),
|
||||
isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY));
|
||||
static AllocationProperties getAllocationProperties(MemoryProperties memoryProperties, bool allocateMemory,
|
||||
size_t size, GraphicsAllocation::AllocationType type) {
|
||||
AllocationProperties allocationProperties(allocateMemory, size, type);
|
||||
fillPoliciesInProperties(allocationProperties, memoryProperties);
|
||||
return allocationProperties;
|
||||
}
|
||||
|
||||
static void fillCachePolicyInProperties(AllocationProperties &allocationProperties, bool uncached, bool readOnly) {
|
||||
static AllocationProperties getAllocationProperties(ImageInfo &imgInfo, bool allocateMemory, MemoryProperties memoryProperties) {
|
||||
AllocationProperties allocationProperties{allocateMemory, imgInfo, GraphicsAllocation::AllocationType::IMAGE};
|
||||
fillPoliciesInProperties(allocationProperties, memoryProperties);
|
||||
return allocationProperties;
|
||||
}
|
||||
|
||||
static void fillPoliciesInProperties(AllocationProperties &allocationProperties, MemoryProperties &memoryProperties);
|
||||
|
||||
static void fillCachePolicyInProperties(AllocationProperties &allocationProperties, bool uncached, bool readOnly,
|
||||
bool deviceOnlyVisibilty) {
|
||||
allocationProperties.flags.uncacheable = uncached;
|
||||
auto cacheFlushRequired = !uncached && !readOnly;
|
||||
auto cacheFlushRequired = !uncached && !readOnly && !deviceOnlyVisibilty;
|
||||
allocationProperties.flags.flushL3RequiredForRead = cacheFlushRequired;
|
||||
allocationProperties.flags.flushL3RequiredForWrite = cacheFlushRequired;
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ void SVMAllocsManager::freeSVMAlloc(void *ptr) {
|
|||
|
||||
void *SVMAllocsManager::createZeroCopySvmAllocation(size_t size, const SvmAllocationProperties &svmProperties) {
|
||||
AllocationProperties properties{true, size, GraphicsAllocation::AllocationType::SVM_ZERO_COPY};
|
||||
MemObjHelper::fillCachePolicyInProperties(properties, false, svmProperties.readOnly);
|
||||
MemObjHelper::fillCachePolicyInProperties(properties, false, svmProperties.readOnly, false);
|
||||
GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
|
||||
if (!allocation) {
|
||||
return nullptr;
|
||||
|
@ -122,7 +122,7 @@ void *SVMAllocsManager::createSvmAllocationWithDeviceStorage(size_t size, const
|
|||
size_t alignedSize = alignUp<size_t>(size, 2 * MemoryConstants::megaByte);
|
||||
AllocationProperties cpuProperties{true, alignedSize, GraphicsAllocation::AllocationType::SVM_CPU};
|
||||
cpuProperties.alignment = 2 * MemoryConstants::megaByte;
|
||||
MemObjHelper::fillCachePolicyInProperties(cpuProperties, false, svmProperties.readOnly);
|
||||
MemObjHelper::fillCachePolicyInProperties(cpuProperties, false, svmProperties.readOnly, false);
|
||||
GraphicsAllocation *allocationCpu = memoryManager->allocateGraphicsMemoryWithProperties(cpuProperties);
|
||||
if (!allocationCpu) {
|
||||
return nullptr;
|
||||
|
@ -133,7 +133,7 @@ void *SVMAllocsManager::createSvmAllocationWithDeviceStorage(size_t size, const
|
|||
|
||||
AllocationProperties gpuProperties{false, alignedSize, GraphicsAllocation::AllocationType::SVM_GPU};
|
||||
gpuProperties.alignment = 2 * MemoryConstants::megaByte;
|
||||
MemObjHelper::fillCachePolicyInProperties(gpuProperties, false, svmProperties.readOnly);
|
||||
MemObjHelper::fillCachePolicyInProperties(gpuProperties, false, svmProperties.readOnly, false);
|
||||
GraphicsAllocation *allocationGpu = memoryManager->allocateGraphicsMemoryWithProperties(gpuProperties, svmPtr);
|
||||
if (!allocationGpu) {
|
||||
memoryManager->freeGraphicsMemory(allocationCpu);
|
||||
|
|
|
@ -135,3 +135,27 @@ TEST(MemObjHelper, givenParentMemObjAndHostPtrFlagsWhenValidatingMemoryPropertie
|
|||
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, imageWithAccessFlagsUnrestricted.get()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MemObjHelper, givenDifferentParametersWhenCallingFillCachePolicyInPropertiesThenFlushL3FlagsAreCorrectlySet) {
|
||||
AllocationProperties allocationProperties{0, GraphicsAllocation::AllocationType::BUFFER};
|
||||
|
||||
for (auto uncached : ::testing::Bool()) {
|
||||
for (auto readOnly : ::testing::Bool()) {
|
||||
for (auto deviceOnlyVisibilty : ::testing::Bool()) {
|
||||
if (uncached || readOnly || deviceOnlyVisibilty) {
|
||||
allocationProperties.flags.flushL3RequiredForRead = true;
|
||||
allocationProperties.flags.flushL3RequiredForWrite = true;
|
||||
MemObjHelper::fillCachePolicyInProperties(allocationProperties, uncached, readOnly, deviceOnlyVisibilty);
|
||||
EXPECT_FALSE(allocationProperties.flags.flushL3RequiredForRead);
|
||||
EXPECT_FALSE(allocationProperties.flags.flushL3RequiredForWrite);
|
||||
} else {
|
||||
allocationProperties.flags.flushL3RequiredForRead = false;
|
||||
allocationProperties.flags.flushL3RequiredForWrite = false;
|
||||
MemObjHelper::fillCachePolicyInProperties(allocationProperties, uncached, readOnly, deviceOnlyVisibilty);
|
||||
EXPECT_TRUE(allocationProperties.flags.flushL3RequiredForRead);
|
||||
EXPECT_TRUE(allocationProperties.flags.flushL3RequiredForWrite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue