Skip to content

Commit

Permalink
Simplify getAllocationProperties
Browse files Browse the repository at this point in the history
Change-Id: I006337ec700e50259c46be1fd73fde34562c8b83
Related-To: NEO-2535
Signed-off-by: Filip Hazubski <[email protected]>
  • Loading branch information
fhazubski-Intel authored and Compute-Runtime-Automation committed Apr 26, 2019
1 parent 068a8d7 commit ddcd3fb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
8 changes: 3 additions & 5 deletions runtime/mem_obj/mem_obj_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 13 additions & 7 deletions runtime/mem_obj/mem_obj_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(MemoryProperties memoryProperties, bool allocateMemory,
size_t size, GraphicsAllocation::AllocationType type) {
AllocationProperties allocationProperties(allocateMemory, size, type);
fillPoliciesInProperties(allocationProperties, memoryProperties);
return allocationProperties;
}

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));
fillPoliciesInProperties(allocationProperties, memoryProperties);
return allocationProperties;
}

static void fillCachePolicyInProperties(AllocationProperties &allocationProperties, bool uncached, bool readOnly) {
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;
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/memory_manager/svm_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions unit_tests/mem_obj/mem_obj_helper_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
}

0 comments on commit ddcd3fb

Please sign in to comment.