Skip to content

Commit ddcd3fb

Browse files
Simplify getAllocationProperties
Change-Id: I006337ec700e50259c46be1fd73fde34562c8b83 Related-To: NEO-2535 Signed-off-by: Filip Hazubski <[email protected]>
1 parent 068a8d7 commit ddcd3fb

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

runtime/mem_obj/mem_obj_helper.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ bool MemObjHelper::parseMemoryProperties(const cl_mem_properties_intel *properti
3131
return true;
3232
}
3333

34-
AllocationProperties MemObjHelper::getAllocationProperties(MemoryProperties memoryProperties, bool allocateMemory,
35-
size_t size, GraphicsAllocation::AllocationType type) {
36-
AllocationProperties allocationProperties(allocateMemory, size, type);
34+
void MemObjHelper::fillPoliciesInProperties(AllocationProperties &allocationProperties, MemoryProperties &memoryProperties) {
3735
fillCachePolicyInProperties(allocationProperties,
3836
isValueSet(memoryProperties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE),
39-
isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY));
40-
return allocationProperties;
37+
isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY),
38+
false);
4139
}
4240

4341
bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressed, const MemoryProperties &properties, ContextType contextType, bool preferCompression) {

runtime/mem_obj/mem_obj_helper.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,25 @@ class MemObjHelper {
8888
return validateExtraMemoryProperties(properties);
8989
}
9090

91-
static AllocationProperties getAllocationProperties(MemoryProperties properties, bool allocateMemory,
92-
size_t size, GraphicsAllocation::AllocationType type);
91+
static AllocationProperties getAllocationProperties(MemoryProperties memoryProperties, bool allocateMemory,
92+
size_t size, GraphicsAllocation::AllocationType type) {
93+
AllocationProperties allocationProperties(allocateMemory, size, type);
94+
fillPoliciesInProperties(allocationProperties, memoryProperties);
95+
return allocationProperties;
96+
}
97+
9398
static AllocationProperties getAllocationProperties(ImageInfo &imgInfo, bool allocateMemory, MemoryProperties memoryProperties) {
9499
AllocationProperties allocationProperties{allocateMemory, imgInfo, GraphicsAllocation::AllocationType::IMAGE};
95-
fillCachePolicyInProperties(allocationProperties,
96-
isValueSet(memoryProperties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE),
97-
isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY));
100+
fillPoliciesInProperties(allocationProperties, memoryProperties);
98101
return allocationProperties;
99102
}
100103

101-
static void fillCachePolicyInProperties(AllocationProperties &allocationProperties, bool uncached, bool readOnly) {
104+
static void fillPoliciesInProperties(AllocationProperties &allocationProperties, MemoryProperties &memoryProperties);
105+
106+
static void fillCachePolicyInProperties(AllocationProperties &allocationProperties, bool uncached, bool readOnly,
107+
bool deviceOnlyVisibilty) {
102108
allocationProperties.flags.uncacheable = uncached;
103-
auto cacheFlushRequired = !uncached && !readOnly;
109+
auto cacheFlushRequired = !uncached && !readOnly && !deviceOnlyVisibilty;
104110
allocationProperties.flags.flushL3RequiredForRead = cacheFlushRequired;
105111
allocationProperties.flags.flushL3RequiredForWrite = cacheFlushRequired;
106112
}

runtime/memory_manager/svm_memory_manager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void SVMAllocsManager::freeSVMAlloc(void *ptr) {
102102

103103
void *SVMAllocsManager::createZeroCopySvmAllocation(size_t size, const SvmAllocationProperties &svmProperties) {
104104
AllocationProperties properties{true, size, GraphicsAllocation::AllocationType::SVM_ZERO_COPY};
105-
MemObjHelper::fillCachePolicyInProperties(properties, false, svmProperties.readOnly);
105+
MemObjHelper::fillCachePolicyInProperties(properties, false, svmProperties.readOnly, false);
106106
GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
107107
if (!allocation) {
108108
return nullptr;
@@ -122,7 +122,7 @@ void *SVMAllocsManager::createSvmAllocationWithDeviceStorage(size_t size, const
122122
size_t alignedSize = alignUp<size_t>(size, 2 * MemoryConstants::megaByte);
123123
AllocationProperties cpuProperties{true, alignedSize, GraphicsAllocation::AllocationType::SVM_CPU};
124124
cpuProperties.alignment = 2 * MemoryConstants::megaByte;
125-
MemObjHelper::fillCachePolicyInProperties(cpuProperties, false, svmProperties.readOnly);
125+
MemObjHelper::fillCachePolicyInProperties(cpuProperties, false, svmProperties.readOnly, false);
126126
GraphicsAllocation *allocationCpu = memoryManager->allocateGraphicsMemoryWithProperties(cpuProperties);
127127
if (!allocationCpu) {
128128
return nullptr;
@@ -133,7 +133,7 @@ void *SVMAllocsManager::createSvmAllocationWithDeviceStorage(size_t size, const
133133

134134
AllocationProperties gpuProperties{false, alignedSize, GraphicsAllocation::AllocationType::SVM_GPU};
135135
gpuProperties.alignment = 2 * MemoryConstants::megaByte;
136-
MemObjHelper::fillCachePolicyInProperties(gpuProperties, false, svmProperties.readOnly);
136+
MemObjHelper::fillCachePolicyInProperties(gpuProperties, false, svmProperties.readOnly, false);
137137
GraphicsAllocation *allocationGpu = memoryManager->allocateGraphicsMemoryWithProperties(gpuProperties, svmPtr);
138138
if (!allocationGpu) {
139139
memoryManager->freeGraphicsMemory(allocationCpu);

unit_tests/mem_obj/mem_obj_helper_tests.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,27 @@ TEST(MemObjHelper, givenParentMemObjAndHostPtrFlagsWhenValidatingMemoryPropertie
135135
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, imageWithAccessFlagsUnrestricted.get()));
136136
}
137137
}
138+
139+
TEST(MemObjHelper, givenDifferentParametersWhenCallingFillCachePolicyInPropertiesThenFlushL3FlagsAreCorrectlySet) {
140+
AllocationProperties allocationProperties{0, GraphicsAllocation::AllocationType::BUFFER};
141+
142+
for (auto uncached : ::testing::Bool()) {
143+
for (auto readOnly : ::testing::Bool()) {
144+
for (auto deviceOnlyVisibilty : ::testing::Bool()) {
145+
if (uncached || readOnly || deviceOnlyVisibilty) {
146+
allocationProperties.flags.flushL3RequiredForRead = true;
147+
allocationProperties.flags.flushL3RequiredForWrite = true;
148+
MemObjHelper::fillCachePolicyInProperties(allocationProperties, uncached, readOnly, deviceOnlyVisibilty);
149+
EXPECT_FALSE(allocationProperties.flags.flushL3RequiredForRead);
150+
EXPECT_FALSE(allocationProperties.flags.flushL3RequiredForWrite);
151+
} else {
152+
allocationProperties.flags.flushL3RequiredForRead = false;
153+
allocationProperties.flags.flushL3RequiredForWrite = false;
154+
MemObjHelper::fillCachePolicyInProperties(allocationProperties, uncached, readOnly, deviceOnlyVisibilty);
155+
EXPECT_TRUE(allocationProperties.flags.flushL3RequiredForRead);
156+
EXPECT_TRUE(allocationProperties.flags.flushL3RequiredForWrite);
157+
}
158+
}
159+
}
160+
}
161+
}

0 commit comments

Comments
 (0)