Skip to content

Commit b2e16b7

Browse files
Update allocationForCacheFlush method
Related-To: NEO-2535 Change-Id: Ia24556814188263e2ebb54b6419feddd5d8ed707 Signed-off-by: Filip Hazubski <[email protected]>
1 parent e22b406 commit b2e16b7

30 files changed

+230
-99
lines changed

runtime/api/api.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,8 +3352,7 @@ void *CL_API_CALL clSVMAlloc(cl_context context,
33523352
return pAlloc;
33533353
}
33543354

3355-
pAlloc = pContext->getSVMAllocsManager()->createSVMAlloc(size, !!(flags & CL_MEM_SVM_FINE_GRAIN_BUFFER),
3356-
SVMAllocsManager::memFlagIsReadOnly(flags));
3355+
pAlloc = pContext->getSVMAllocsManager()->createSVMAlloc(size, flags);
33573356

33583357
if (pContext->isProvidingPerformanceHints()) {
33593358
pContext->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, CL_SVM_ALLOC_MEETS_ALIGNMENT_RESTRICTIONS, pAlloc, size);

runtime/command_stream/command_stream_receiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void CommandStreamReceiver::ensureCommandBufferAllocation(LinearStream &commandS
126126
constexpr static auto allocationType = GraphicsAllocation::AllocationType::COMMAND_BUFFER;
127127
auto allocation = this->getInternalAllocationStorage()->obtainReusableAllocation(allocationSize, allocationType).release();
128128
if (allocation == nullptr) {
129-
const AllocationProperties commandStreamAllocationProperties{true, allocationSize, allocationType, this->isMultiOsContextCapable(), this->deviceIndex};
129+
const AllocationProperties commandStreamAllocationProperties{true, allocationSize, allocationType, this->isMultiOsContextCapable(), this->deviceIndex, 0};
130130
allocation = this->getMemoryManager()->allocateGraphicsMemoryWithProperties(commandStreamAllocationProperties);
131131
}
132132
DEBUG_BREAK_IF(allocation == nullptr);

runtime/kernel/kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@ void Kernel::getAllocationsForCacheFlush(CacheFlushAllocationsVec &out) const {
21812181
}
21822182

21832183
bool Kernel::allocationForCacheFlush(GraphicsAllocation *argAllocation) const {
2184-
return argAllocation->isFlushL3Required() || argAllocation->isMemObjectsAllocationWithWritableFlags();
2184+
return argAllocation->isFlushL3Required();
21852185
}
21862186

21872187
void Kernel::addAllocationToCacheFlushVector(uint32_t argIndex, GraphicsAllocation *argAllocation) {

runtime/mem_obj/buffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Buffer *Buffer::create(Context *context,
206206
}
207207

208208
if (!memory) {
209-
AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(properties.flags_intel, allocateMemory, size, allocationType);
209+
AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(properties, allocateMemory, size, allocationType);
210210
StorageInfo storageInfo = MemObjHelper::getStorageInfo(properties);
211211
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, storageInfo, hostPtr);
212212
}
@@ -220,7 +220,7 @@ Buffer *Buffer::create(Context *context,
220220
allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
221221
zeroCopyAllowed = false;
222222
copyMemoryFromHostPtr = true;
223-
AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(properties.flags_intel, true, size, allocationType);
223+
AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(properties, true, size, allocationType);
224224
StorageInfo storageInfo = MemObjHelper::getStorageInfo(properties);
225225
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, storageInfo, nullptr);
226226
}

runtime/mem_obj/mem_obj_helper.cpp

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

34-
AllocationProperties MemObjHelper::getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory,
34+
AllocationProperties MemObjHelper::getAllocationProperties(MemoryProperties properties, bool allocateMemory,
3535
size_t size, GraphicsAllocation::AllocationType type) {
36-
AllocationProperties allocationProperties(allocateMemory, size, type);
37-
allocationProperties.flags.uncacheable = isValueSet(flags, CL_MEM_LOCALLY_UNCACHED_RESOURCE);
36+
AllocationProperties allocationProperties(allocateMemory, size, type, properties);
3837
return allocationProperties;
3938
}
4039

runtime/mem_obj/mem_obj_helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class MemObjHelper {
8787
return validateExtraMemoryProperties(properties);
8888
}
8989

90-
static AllocationProperties getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory,
90+
static AllocationProperties getAllocationProperties(MemoryProperties properties, bool allocateMemory,
9191
size_t size, GraphicsAllocation::AllocationType type);
9292
static AllocationProperties getAllocationProperties(ImageInfo *imgInfo, bool allocateMemory);
9393

runtime/mem_obj/pipe.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ Pipe *Pipe::create(Context *context,
5252
memoryProperties.flags = flags;
5353
while (true) {
5454
auto size = static_cast<size_t>(packetSize * (maxPackets + 1) + intelPipeHeaderReservedSpace);
55-
AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(flags, true, size, GraphicsAllocation::AllocationType::PIPE);
55+
AllocationProperties allocProperties =
56+
MemObjHelper::getAllocationProperties(memoryProperties, true, size, GraphicsAllocation::AllocationType::PIPE);
5657
StorageInfo storageInfo = MemObjHelper::getStorageInfo(memoryProperties);
5758
GraphicsAllocation *memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, storageInfo, nullptr);
5859
if (!memory) {

runtime/memory_manager/memory_manager.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
214214
bool forcePin = properties.flags.forcePin;
215215
bool uncacheable = properties.flags.uncacheable;
216216
bool mustBeZeroCopy = false;
217+
bool mayRequireL3Flush = false;
217218
bool multiOsContextCapable = properties.flags.multiOsContextCapable;
218219

219220
switch (properties.allocationType) {
@@ -265,6 +266,25 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
265266
break;
266267
}
267268

269+
switch (properties.allocationType) {
270+
case GraphicsAllocation::AllocationType::BUFFER:
271+
case GraphicsAllocation::AllocationType::BUFFER_COMPRESSED:
272+
case GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY:
273+
case GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR:
274+
case GraphicsAllocation::AllocationType::GLOBAL_SURFACE:
275+
case GraphicsAllocation::AllocationType::IMAGE:
276+
case GraphicsAllocation::AllocationType::PIPE:
277+
case GraphicsAllocation::AllocationType::SHARED_IMAGE:
278+
case GraphicsAllocation::AllocationType::SHARED_BUFFER:
279+
case GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY:
280+
case GraphicsAllocation::AllocationType::SVM:
281+
case GraphicsAllocation::AllocationType::UNDECIDED:
282+
mayRequireL3Flush = true;
283+
break;
284+
default:
285+
break;
286+
}
287+
268288
switch (properties.allocationType) {
269289
case GraphicsAllocation::AllocationType::UNDECIDED:
270290
case GraphicsAllocation::AllocationType::FILL_PATTERN:
@@ -283,7 +303,8 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
283303
allocationData.flags.allow64kbPages = allow64KbPages;
284304
allocationData.flags.forcePin = forcePin;
285305
allocationData.flags.uncacheable = uncacheable;
286-
allocationData.flags.flushL3 = properties.flags.flushL3RequiredForRead | properties.flags.flushL3RequiredForWrite;
306+
allocationData.flags.flushL3 =
307+
(mayRequireL3Flush ? properties.flags.flushL3RequiredForRead | properties.flags.flushL3RequiredForWrite : 0u);
287308
allocationData.flags.preferRenderCompressed = GraphicsAllocation::AllocationType::BUFFER_COMPRESSED == properties.allocationType;
288309
allocationData.flags.multiOsContextCapable = multiOsContextCapable;
289310

runtime/memory_manager/memory_manager.h

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#pragma once
9+
#include "common/helpers/bit_helpers.h"
910
#include "public/cl_ext_private.h"
1011
#include "runtime/command_stream/preemption_mode.h"
1112
#include "runtime/helpers/aligned_memory.h"
@@ -16,6 +17,7 @@
1617
#include "runtime/os_interface/32bit_memory.h"
1718

1819
#include "engine_node.h"
20+
#include "mem_obj_types.h"
1921

2022
#include <bitset>
2123
#include <cstdint>
@@ -67,26 +69,51 @@ struct AllocationProperties {
6769
ImageInfo *imgInfo = nullptr;
6870
uint32_t deviceIndex = AllocationProperties::noDeviceSpecified;
6971

70-
AllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType)
71-
: AllocationProperties(true, size, allocationType) {}
72-
73-
AllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType, uint32_t deviceIndex)
74-
: AllocationProperties(true, size, allocationType, false, deviceIndex) {}
75-
AllocationProperties(bool allocateMemory, size_t size, GraphicsAllocation::AllocationType allocationType)
76-
: AllocationProperties(allocateMemory, size, allocationType, false, AllocationProperties::noDeviceSpecified) {}
77-
AllocationProperties(bool allocateMemory, size_t size, GraphicsAllocation::AllocationType allocationType,
78-
bool multiOsContextCapable, uint32_t deviceIndex)
72+
AllocationProperties(size_t size,
73+
GraphicsAllocation::AllocationType allocationType)
74+
: AllocationProperties(true, size, allocationType, 0) {}
75+
76+
AllocationProperties(size_t size,
77+
GraphicsAllocation::AllocationType allocationType,
78+
uint32_t deviceIndex)
79+
: AllocationProperties(true, size, allocationType, false, deviceIndex, 0) {}
80+
81+
AllocationProperties(bool allocateMemory,
82+
size_t size,
83+
GraphicsAllocation::AllocationType allocationType)
84+
: AllocationProperties(allocateMemory, size, allocationType, 0) {}
85+
86+
AllocationProperties(bool allocateMemory,
87+
size_t size,
88+
GraphicsAllocation::AllocationType allocationType,
89+
MemoryProperties memoryProperties)
90+
: AllocationProperties(allocateMemory, size, allocationType, false, AllocationProperties::noDeviceSpecified,
91+
memoryProperties) {}
92+
93+
AllocationProperties(bool allocateMemory,
94+
size_t size,
95+
GraphicsAllocation::AllocationType allocationType,
96+
bool multiOsContextCapable,
97+
uint32_t deviceIndex,
98+
MemoryProperties memoryProperties)
7999
: size(size), allocationType(allocationType), deviceIndex(deviceIndex) {
80100
allFlags = 0;
81-
flags.flushL3RequiredForRead = 1;
82-
flags.flushL3RequiredForWrite = 1;
101+
flags.uncacheable = isValueSet(memoryProperties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE);
102+
auto cacheFlushRequired = !flags.uncacheable && !isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY);
103+
flags.flushL3RequiredForRead = cacheFlushRequired;
104+
flags.flushL3RequiredForWrite = cacheFlushRequired;
83105
flags.allocateMemory = allocateMemory;
84106
flags.multiOsContextCapable = multiOsContextCapable;
85107
}
86-
AllocationProperties(ImageInfo *imgInfo, bool allocateMemory) : AllocationProperties(allocateMemory, 0, GraphicsAllocation::AllocationType::IMAGE) {
108+
AllocationProperties(ImageInfo *imgInfo,
109+
bool allocateMemory)
110+
: AllocationProperties(allocateMemory, 0, GraphicsAllocation::AllocationType::IMAGE, 0) {
87111
this->imgInfo = imgInfo;
88112
}
89-
AllocationProperties(ImageInfo *imgInfo, bool allocateMemory, GraphicsAllocation::AllocationType allocationType) : AllocationProperties(allocateMemory, 0, allocationType) {
113+
AllocationProperties(ImageInfo *imgInfo,
114+
bool allocateMemory,
115+
GraphicsAllocation::AllocationType allocationType)
116+
: AllocationProperties(allocateMemory, 0, allocationType, 0) {
90117
this->imgInfo = imgInfo;
91118
}
92119
};

runtime/memory_manager/os_agnostic_memory_manager.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,22 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment
3535
MemoryAllocation *memoryAllocation = nullptr;
3636

3737
if (fakeBigAllocations && allocationData.size > bigAllocation) {
38-
memoryAllocation = new MemoryAllocation(allocationData.type, nullptr, (void *)dummyAddress, static_cast<uint64_t>(dummyAddress),
39-
allocationData.size, counter, MemoryPool::System4KBPages, allocationData.flags.multiOsContextCapable);
38+
memoryAllocation = new MemoryAllocation(
39+
allocationData.type, nullptr, (void *)dummyAddress, static_cast<uint64_t>(dummyAddress), allocationData.size, counter,
40+
MemoryPool::System4KBPages, allocationData.flags.multiOsContextCapable, allocationData.flags.uncacheable,
41+
allocationData.flags.flushL3);
4042
counter++;
41-
memoryAllocation->uncacheable = allocationData.flags.uncacheable;
4243
return memoryAllocation;
4344
}
4445
auto ptr = allocateSystemMemory(sizeAligned, allocationData.alignment ? alignUp(allocationData.alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize);
4546
if (ptr != nullptr) {
46-
memoryAllocation = new MemoryAllocation(allocationData.type, ptr, ptr, reinterpret_cast<uint64_t>(ptr),
47-
allocationData.size, counter, MemoryPool::System4KBPages, allocationData.flags.multiOsContextCapable);
47+
memoryAllocation = new MemoryAllocation(allocationData.type, ptr, ptr, reinterpret_cast<uint64_t>(ptr), allocationData.size,
48+
counter, MemoryPool::System4KBPages, allocationData.flags.multiOsContextCapable,
49+
allocationData.flags.uncacheable, allocationData.flags.flushL3);
4850
if (!memoryAllocation) {
4951
alignedFreeWrapper(ptr);
5052
return nullptr;
5153
}
52-
memoryAllocation->uncacheable = allocationData.flags.uncacheable;
5354
}
5455
counter++;
5556
return memoryAllocation;
@@ -59,12 +60,11 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHost
5960
auto alignedPtr = alignDown(allocationData.hostPtr, MemoryConstants::pageSize);
6061
auto offsetInPage = ptrDiff(allocationData.hostPtr, alignedPtr);
6162

62-
auto memoryAllocation = new MemoryAllocation(allocationData.type, nullptr, const_cast<void *>(allocationData.hostPtr), reinterpret_cast<uint64_t>(alignedPtr),
63-
allocationData.size, counter, MemoryPool::System4KBPages, false);
63+
auto memoryAllocation = new MemoryAllocation(allocationData.type, nullptr, const_cast<void *>(allocationData.hostPtr),
64+
reinterpret_cast<uint64_t>(alignedPtr), allocationData.size, counter,
65+
MemoryPool::System4KBPages, false, false, allocationData.flags.flushL3);
6466

6567
memoryAllocation->setAllocationOffset(offsetInPage);
66-
memoryAllocation->uncacheable = false;
67-
6868
counter++;
6969
return memoryAllocation;
7070
}
@@ -88,8 +88,9 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con
8888
return nullptr;
8989
}
9090
uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(allocationData.hostPtr) & MemoryConstants::pageMask);
91-
MemoryAllocation *memAlloc = new MemoryAllocation(allocationData.type, nullptr, const_cast<void *>(allocationData.hostPtr), GmmHelper::canonize(gpuVirtualAddress + offset),
92-
allocationData.size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing, false);
91+
MemoryAllocation *memAlloc = new MemoryAllocation(
92+
allocationData.type, nullptr, const_cast<void *>(allocationData.hostPtr), GmmHelper::canonize(gpuVirtualAddress + offset),
93+
allocationData.size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing, false, false, false);
9394
memAlloc->set32BitAllocation(true);
9495
memAlloc->setGpuBaseAddress(GmmHelper::canonize(allocator32Bit->getBase()));
9596
memAlloc->sizeToFree = allocationSize;
@@ -109,7 +110,8 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con
109110
MemoryAllocation *memoryAllocation = nullptr;
110111
if (ptrAlloc != nullptr) {
111112
memoryAllocation = new MemoryAllocation(allocationData.type, ptrAlloc, ptrAlloc, GmmHelper::canonize(gpuAddress),
112-
allocationData.size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing, false);
113+
allocationData.size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing, false,
114+
false, false);
113115
memoryAllocation->set32BitAllocation(true);
114116
memoryAllocation->setGpuBaseAddress(GmmHelper::canonize(allocator32Bit->getBase()));
115117
memoryAllocation->sizeToFree = allocationSize;
@@ -120,7 +122,8 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con
120122

121123
GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) {
122124
auto graphicsAllocation = new MemoryAllocation(GraphicsAllocation::AllocationType::UNDECIDED, nullptr, reinterpret_cast<void *>(1), 1,
123-
4096u, static_cast<uint64_t>(handle), MemoryPool::SystemCpuInaccessible, false);
125+
4096u, static_cast<uint64_t>(handle), MemoryPool::SystemCpuInaccessible, false,
126+
false, false);
124127
graphicsAllocation->setSharedHandle(handle);
125128
graphicsAllocation->set32BitAllocation(requireSpecificBitness);
126129

@@ -196,8 +199,9 @@ uint64_t OsAgnosticMemoryManager::getInternalHeapBaseAddress() {
196199
}
197200

198201
GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) {
199-
auto allocation = new MemoryAllocation(allocationData.type, nullptr, const_cast<void *>(allocationData.hostPtr), reinterpret_cast<uint64_t>(allocationData.hostPtr),
200-
allocationData.size, counter++, MemoryPool::System4KBPages, false);
202+
auto allocation = new MemoryAllocation(allocationData.type, nullptr, const_cast<void *>(allocationData.hostPtr),
203+
reinterpret_cast<uint64_t>(allocationData.hostPtr), allocationData.size, counter++,
204+
MemoryPool::System4KBPages, false, false, false);
201205
allocation->fragmentsStorage = handleStorage;
202206
return allocation;
203207
}
@@ -241,8 +245,8 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForImageImpl(
241245

242246
auto ptr = allocateSystemMemory(alignUp(allocationData.imgInfo->size, MemoryConstants::pageSize), MemoryConstants::pageSize);
243247
if (ptr != nullptr) {
244-
alloc = new MemoryAllocation(allocationData.type, ptr, ptr, reinterpret_cast<uint64_t>(ptr),
245-
allocationData.imgInfo->size, counter, MemoryPool::SystemCpuInaccessible, false);
248+
alloc = new MemoryAllocation(allocationData.type, ptr, ptr, reinterpret_cast<uint64_t>(ptr), allocationData.imgInfo->size,
249+
counter, MemoryPool::SystemCpuInaccessible, false, false, false);
246250
counter++;
247251
}
248252

0 commit comments

Comments
 (0)