mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 07:14:10 +08:00
Enable custom allocation alignments on Linux
Related-To: NEO-5750 Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
21690dcea5
commit
33e8f73775
@@ -230,6 +230,9 @@ DECLARE_DEBUG_VARIABLE(int32_t, WaitLoopCount, -1, "-1: use default, >=0: number
|
||||
DECLARE_DEBUG_VARIABLE(int32_t, GTPinAllocateBufferInSharedMemory, -1, "Force GTPin to allocate buffer in shared memory")
|
||||
DECLARE_DEBUG_VARIABLE(int32_t, AlignLocalMemoryVaTo2MB, -1, "Allow 2MB pages for allocations with size>=2MB. On Linux it means aligned VA, on Windows it means aligned size. -1: default, 0: disabled, 1: enabled")
|
||||
|
||||
/*EXPERIMENTAL TOGGLES*/
|
||||
DECLARE_DEBUG_VARIABLE(int32_t, ExperimentalEnableCustomLocalMemoryAlignment, 0, "Align local memory allocations to a given value. Works only with allocations at least as big as the value. 0: no effect, 2097152: 2 megabytes, 1073741824: 1 gigabyte")
|
||||
|
||||
/*DRIVER TOGGLES*/
|
||||
DECLARE_DEBUG_VARIABLE(int32_t, ForceOCLVersion, 0, "Force specific OpenCL API version")
|
||||
DECLARE_DEBUG_VARIABLE(int32_t, ForceOCL21FeaturesSupport, -1, "-1: default, 0: disable, 1:enable. Force support of OpenCL 2.0 and OpenCL 2.1 API features")
|
||||
|
||||
@@ -69,6 +69,10 @@ class GfxPartition {
|
||||
return getHeap(heapIndex).allocate(size);
|
||||
}
|
||||
|
||||
uint64_t heapAllocateWithCustomAlignment(HeapIndex heapIndex, size_t &size, size_t alignment) {
|
||||
return getHeap(heapIndex).allocateWithCustomAlignment(size, alignment);
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void heapFree(HeapIndex heapIndex, uint64_t ptr, size_t size) {
|
||||
getHeap(heapIndex).free(ptr, size);
|
||||
}
|
||||
@@ -129,6 +133,7 @@ class GfxPartition {
|
||||
uint64_t getSize() const { return size; }
|
||||
uint64_t getLimit() const { return size ? base + size - 1 : 0; }
|
||||
uint64_t allocate(size_t &size) { return alloc->allocate(size); }
|
||||
uint64_t allocateWithCustomAlignment(size_t &sizeToAllocate, size_t alignment) { return alloc->allocateWithCustomAlignment(sizeToAllocate, alignment); }
|
||||
void free(uint64_t ptr, size_t size) { alloc->free(ptr, size); }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -144,17 +144,25 @@ uint64_t getGpuAddress(HeapAssigner &heapAssigner, const HardwareInfo &hwInfo, G
|
||||
sizeAllocated = 0;
|
||||
break;
|
||||
default:
|
||||
const bool prefer2MBAlignment = DebugManager.flags.AlignLocalMemoryVaTo2MB.get() != 0 && sizeAllocated >= 2 * MemoryConstants::megaByte;
|
||||
const size_t customAlignment = static_cast<size_t>(DebugManager.flags.ExperimentalEnableCustomLocalMemoryAlignment.get());
|
||||
const bool preferCustomAlignment = customAlignment > 0 && sizeAllocated >= customAlignment;
|
||||
const bool prefer2MBAlignment = DebugManager.flags.AlignLocalMemoryVaTo2MB.get() != 0 &&
|
||||
sizeAllocated >= 2 * MemoryConstants::megaByte &&
|
||||
(!preferCustomAlignment || customAlignment <= 2 * MemoryConstants::megaByte);
|
||||
const bool prefer57bitAddressing = gfxPartition->getHeapLimit(HeapIndex::HEAP_EXTENDED) > 0 && !resource48Bit;
|
||||
|
||||
auto heapIndex = HeapIndex::HEAP_STANDARD64KB;
|
||||
size_t alignment = 0u;
|
||||
if (prefer2MBAlignment) {
|
||||
heapIndex = HeapIndex::HEAP_STANDARD2MB;
|
||||
} else if (preferCustomAlignment) {
|
||||
heapIndex = customAlignment > 2 * MemoryConstants::megaByte ? HeapIndex::HEAP_STANDARD2MB : HeapIndex::HEAP_STANDARD64KB;
|
||||
alignment = customAlignment;
|
||||
} else if (prefer57bitAddressing) {
|
||||
heapIndex = HeapIndex::HEAP_EXTENDED;
|
||||
}
|
||||
|
||||
gpuAddress = GmmHelper::canonize(gfxPartition->heapAllocate(heapIndex, sizeAllocated));
|
||||
gpuAddress = GmmHelper::canonize(gfxPartition->heapAllocateWithCustomAlignment(heapIndex, sizeAllocated, alignment));
|
||||
break;
|
||||
}
|
||||
return gpuAddress;
|
||||
|
||||
@@ -40,10 +40,14 @@ class HeapAllocator {
|
||||
}
|
||||
|
||||
uint64_t allocate(size_t &sizeToAllocate) {
|
||||
return allocateWithCustomAlignment(sizeToAllocate, this->allocationAlignment);
|
||||
return allocateWithCustomAlignment(sizeToAllocate, 0u);
|
||||
}
|
||||
|
||||
uint64_t allocateWithCustomAlignment(size_t &sizeToAllocate, size_t alignment) {
|
||||
if (alignment == 0) {
|
||||
alignment = this->allocationAlignment;
|
||||
}
|
||||
|
||||
UNRECOVERABLE_IF(alignment % allocationAlignment != 0); // custom alignment have to be a multiple of allocator alignment
|
||||
sizeToAllocate = alignUp(sizeToAllocate, allocationAlignment);
|
||||
|
||||
|
||||
@@ -1363,3 +1363,13 @@ TEST(HeapAllocatorTest, givenUnalignedFreedChunkAvailableWhenAllocatingMemoryWit
|
||||
EXPECT_EQ(1u, heapAllocator.getFreedChunksBig().size());
|
||||
EXPECT_EQ(heapSize - 3 * ptrSize - MemoryConstants::pageSize, heapAllocator.getavailableSize());
|
||||
}
|
||||
|
||||
TEST(HeapAllocatorTest, givenZeroAlignmentPassedWhenAllocatingMemoryWithCustomAlignmentThenUseDefaultAllocatorAlignment) {
|
||||
const uint64_t heapBase = 0x111111llu;
|
||||
const size_t heapSize = 1024u * 4096u;
|
||||
HeapAllocatorUnderTest heapAllocator(heapBase, heapSize, allocationAlignment, 0);
|
||||
|
||||
size_t ptrSize = 1;
|
||||
uint64_t ptr = heapAllocator.allocateWithCustomAlignment(ptrSize, 0u);
|
||||
EXPECT_EQ(alignUp(heapBase, allocationAlignment), ptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user