[27/n] Internal 4GB allocator.

- Allow indirect heap to work in 2 modes:
first mode is when it will be used as an allocation from 4GB allocator.
In such scenario driver will return offset from base of the allocator region.
Second mode is the legacy mode which will be used by device enqueue, this
will results in heap CPU base address being programmed in State Base Address
commands and during programming heap offset base of 0 will be returned.

Change-Id: Ica098f3278b6b6ed5036b4c5ab7461dc61d8ee86
This commit is contained in:
Mrozek, Michal 2018-04-16 15:26:45 +02:00 committed by sys_ocldev
parent e7ab0b2d33
commit cb06fad983
4 changed files with 37 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -27,6 +27,9 @@ namespace OCLRT {
IndirectHeap::IndirectHeap(GraphicsAllocation *gfxAllocation) : BaseClass(gfxAllocation) {
}
IndirectHeap::IndirectHeap(GraphicsAllocation *gfxAllocation, bool canBeUtilizedAs4GbHeap) : BaseClass(gfxAllocation), canBeUtilizedAs4GbHeap(canBeUtilizedAs4GbHeap) {
}
IndirectHeap::IndirectHeap(void *buffer, size_t bufferSize) : BaseClass(buffer, bufferSize) {
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -46,16 +46,28 @@ class IndirectHeap : public LinearStream {
IndirectHeap(void *buffer, size_t bufferSize);
IndirectHeap(GraphicsAllocation *buffer);
IndirectHeap(GraphicsAllocation *buffer, bool canBeUtilizedAs4GbHeap);
// Disallow copy'ing
IndirectHeap(const IndirectHeap &) = delete;
IndirectHeap &operator=(const IndirectHeap &) = delete;
void align(size_t alignment);
uint64_t getHeapGpuStartOffset();
protected:
bool canBeUtilizedAs4GbHeap = false;
};
inline void IndirectHeap::align(size_t alignment) {
auto address = alignUp(ptrOffset(buffer, sizeUsed), alignment);
sizeUsed = ptrDiff(address, buffer);
}
inline uint64_t IndirectHeap::getHeapGpuStartOffset() {
if (this->canBeUtilizedAs4GbHeap) {
return this->graphicsAllocation->getGpuAddressToPatch();
} else {
return 0llu;
}
}
}

View File

@ -637,7 +637,7 @@ TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWhenGetHeapMemoryIsCalledW
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(context.get(), pDevice, props);
IndirectHeap heap(nullptr, 100);
IndirectHeap heap(nullptr, size_t{100});
IndirectHeap *indirectHeap = &heap;
cmdQ.allocateHeapMemory(this->GetParam(), 100, indirectHeap);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -27,8 +27,6 @@
using namespace OCLRT;
struct IndirectHeapTest : public ::testing::Test {
IndirectHeapTest() {
}
uint8_t buffer[256];
MockGraphicsAllocation gfxAllocation = {(void *)buffer, sizeof(buffer)};
IndirectHeap indirectHeap = {&gfxAllocation};
@ -102,3 +100,21 @@ TEST_F(IndirectHeapTest, givenIndirectHeapWhenGetCpuBaseIsCalledThenCpuAddressIs
auto base = indirectHeap.getCpuBase();
EXPECT_EQ(base, buffer);
}
TEST(IndirectHeapWith4GbAllocatorTest, givenIndirectHeapNotSupporting4GbModeWhenAskedForHeapGpuStartOffsetThenZeroIsReturned) {
auto cpuBaseAddress = reinterpret_cast<void *>(0x3000);
GraphicsAllocation graphicsAllocation(cpuBaseAddress, 4096u);
graphicsAllocation.gpuBaseAddress = 4096u;
IndirectHeap indirectHeap(&graphicsAllocation, false);
EXPECT_EQ(0u, indirectHeap.getHeapGpuStartOffset());
}
TEST(IndirectHeapWith4GbAllocatorTest, givenIndirectHeapSupporting4GbModeWhenAskedForHeapGpuStartOffsetThenZeroIsReturned) {
auto cpuBaseAddress = reinterpret_cast<void *>(0x3000);
GraphicsAllocation graphicsAllocation(cpuBaseAddress, 4096u);
graphicsAllocation.gpuBaseAddress = 4096u;
IndirectHeap indirectHeap(&graphicsAllocation, true);
EXPECT_EQ(8192u, indirectHeap.getHeapGpuStartOffset());
}