Move indirect heaps from command queues to csr.

-This is required to enable N:1 submission model.
-If heaps are coming from different command queues that always
mean that STATE_BASE_ADDRESS needs to be reloaded
-In order to not emit any non pipelined state in CSR, this change
moves the ownership of IndirectHeap to one centralized place which is
CommandStreamReceiver
-This way when there are submissions from multiple command queues then
they reuse the same heaps, therefore preventing SBA reload

Change-Id: I5caf5dc5cb05d7a2d8766883d9bc51c29062e980
This commit is contained in:
Mrozek, Michal
2018-04-26 10:01:01 +02:00
committed by sys_ocldev
parent be7393fcfe
commit 8d2df3c332
13 changed files with 231 additions and 123 deletions

View File

@@ -86,9 +86,7 @@ CommandQueue::CommandQueue(Context *context,
if (context) {
context->incRefInternal();
}
for (int i = 0; i < NUM_HEAPS; ++i) {
indirectHeap[i] = nullptr;
}
commandQueueProperties = getCmdQueueProperties<cl_command_queue_properties>(properties);
flushStamp.reset(new FlushStampTracker(true));
}
@@ -110,15 +108,6 @@ CommandQueue::~CommandQueue() {
}
delete commandStream;
for (int i = 0; i < NUM_HEAPS; ++i) {
if (indirectHeap[i] != nullptr) {
auto allocation = indirectHeap[i]->getGraphicsAllocation();
if (allocation != nullptr) {
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
}
delete indirectHeap[i];
}
}
if (perfConfigurationData) {
delete perfConfigurationData;
}
@@ -220,48 +209,6 @@ uint32_t CommandQueue::getTaskLevelFromWaitList(uint32_t taskLevel,
return taskLevel;
}
IndirectHeap &CommandQueue::getIndirectHeap(IndirectHeap::Type heapType,
size_t minRequiredSize) {
DEBUG_BREAK_IF(static_cast<uint32_t>(heapType) >= ARRAY_COUNT(indirectHeap));
auto &heap = indirectHeap[heapType];
GraphicsAllocation *heapMemory = nullptr;
DEBUG_BREAK_IF(nullptr == device);
auto memoryManager = device->getMemoryManager();
DEBUG_BREAK_IF(nullptr == memoryManager);
if (heap)
heapMemory = heap->getGraphicsAllocation();
if (heap && heap->getAvailableSpace() < minRequiredSize && heapMemory) {
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
heapMemory = nullptr;
}
if (!heapMemory) {
allocateHeapMemory(heapType, minRequiredSize, heap);
}
return *heap;
}
void CommandQueue::releaseIndirectHeap(IndirectHeap::Type heapType) {
DEBUG_BREAK_IF(static_cast<uint32_t>(heapType) >= ARRAY_COUNT(indirectHeap));
auto &heap = indirectHeap[heapType];
DEBUG_BREAK_IF(nullptr == device);
auto memoryManager = device->getMemoryManager();
DEBUG_BREAK_IF(nullptr == memoryManager);
if (heap) {
auto heapMemory = heap->getGraphicsAllocation();
if (heapMemory != nullptr)
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
heap->replaceBuffer(nullptr, 0);
heap->replaceGraphicsAllocation(nullptr);
}
}
LinearStream &CommandQueue::getCS(size_t minRequiredSize) {
DEBUG_BREAK_IF(nullptr == device);
auto &commandStreamReceiver = device->getCommandStreamReceiver();
@@ -633,46 +580,16 @@ bool CommandQueue::setupDebugSurface(Kernel *kernel) {
return true;
}
void CommandQueue::allocateHeapMemory(IndirectHeap::Type heapType,
size_t minRequiredSize, IndirectHeap *&indirectHeap) {
auto memoryManager = device->getMemoryManager();
size_t reservedSize = 0;
auto finalHeapSize = defaultHeapSize;
bool requireInternalHeap = IndirectHeap::INDIRECT_OBJECT == heapType ? true : false;
if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
requireInternalHeap = false;
}
minRequiredSize += reservedSize;
finalHeapSize = alignUp(std::max(finalHeapSize, minRequiredSize), MemoryConstants::pageSize);
auto heapMemory = memoryManager->obtainReusableAllocation(finalHeapSize, requireInternalHeap).release();
if (!heapMemory) {
if (requireInternalHeap) {
heapMemory = memoryManager->createInternalGraphicsAllocation(nullptr, finalHeapSize);
} else {
heapMemory = memoryManager->allocateGraphicsMemory(finalHeapSize, MemoryConstants::pageSize);
}
} else {
finalHeapSize = std::max(heapMemory->getUnderlyingBufferSize(), finalHeapSize);
}
heapMemory->setAllocationType(GraphicsAllocation::ALLOCATION_TYPE_LINEAR_STREAM);
if (IndirectHeap::SURFACE_STATE == heapType) {
DEBUG_BREAK_IF(minRequiredSize > maxSshSize);
finalHeapSize = maxSshSize;
}
if (indirectHeap) {
indirectHeap->replaceBuffer(heapMemory->getUnderlyingBuffer(), finalHeapSize);
indirectHeap->replaceGraphicsAllocation(heapMemory);
} else {
indirectHeap = new IndirectHeap(heapMemory, requireInternalHeap);
indirectHeap->overrideMaxSize(finalHeapSize);
}
IndirectHeap &CommandQueue::getIndirectHeap(IndirectHeap::Type heapType, size_t minRequiredSize) {
return this->getDevice().getCommandStreamReceiver().getIndirectHeap(heapType, minRequiredSize);
}
void CommandQueue::allocateHeapMemory(IndirectHeap::Type heapType, size_t minRequiredSize, IndirectHeap *&indirectHeap) {
this->getDevice().getCommandStreamReceiver().allocateHeapMemory(heapType, minRequiredSize, indirectHeap);
}
void CommandQueue::releaseIndirectHeap(IndirectHeap::Type heapType) {
this->getDevice().getCommandStreamReceiver().releaseIndirectHeap(heapType);
}
} // namespace OCLRT

View File

@@ -56,7 +56,6 @@ struct OpenCLObjectMapper<_cl_command_queue> {
class CommandQueue : public BaseObject<_cl_command_queue> {
public:
static const cl_ulong objectMagic = 0x1234567890987654LL;
enum { NUM_HEAPS = IndirectHeap::NUM_TYPES };
static CommandQueue *create(Context *context, Device *device,
const cl_queue_properties *properties,
@@ -432,7 +431,6 @@ class CommandQueue : public BaseObject<_cl_command_queue> {
bool perfCountersRegsCfgPending;
LinearStream *commandStream;
IndirectHeap *indirectHeap[NUM_HEAPS];
bool mapDcFlushRequired = false;
bool isSpecialCommandQueue = false;

View File

@@ -25,6 +25,7 @@
#include "runtime/command_stream/preemption.h"
#include "runtime/device/device.h"
#include "runtime/gtpin/gtpin_notify.h"
#include "runtime/helpers/array_count.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/helpers/cache_policy.h"
#include "runtime/os_interface/os_interface.h"
@@ -42,9 +43,21 @@ CommandStreamReceiver::CommandStreamReceiver() {
this->dispatchMode = (DispatchMode)DebugManager.flags.CsrDispatchMode.get();
}
flushStamp.reset(new FlushStampTracker(true));
for (int i = 0; i < IndirectHeap::NUM_TYPES; ++i) {
indirectHeap[i] = nullptr;
}
}
CommandStreamReceiver::~CommandStreamReceiver() {
for (int i = 0; i < IndirectHeap::NUM_TYPES; ++i) {
if (indirectHeap[i] != nullptr) {
auto allocation = indirectHeap[i]->getGraphicsAllocation();
if (allocation != nullptr) {
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
}
delete indirectHeap[i];
}
}
cleanupResources();
}
@@ -232,4 +245,80 @@ GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) {
return debugSurface;
}
IndirectHeap &CommandStreamReceiver::getIndirectHeap(IndirectHeap::Type heapType,
size_t minRequiredSize) {
DEBUG_BREAK_IF(static_cast<uint32_t>(heapType) >= ARRAY_COUNT(indirectHeap));
auto &heap = indirectHeap[heapType];
GraphicsAllocation *heapMemory = nullptr;
if (heap)
heapMemory = heap->getGraphicsAllocation();
if (heap && heap->getAvailableSpace() < minRequiredSize && heapMemory) {
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
heapMemory = nullptr;
}
if (!heapMemory) {
allocateHeapMemory(heapType, minRequiredSize, heap);
}
return *heap;
}
void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType,
size_t minRequiredSize, IndirectHeap *&indirectHeap) {
size_t reservedSize = 0;
auto finalHeapSize = defaultHeapSize;
bool requireInternalHeap = IndirectHeap::INDIRECT_OBJECT == heapType ? true : false;
if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
requireInternalHeap = false;
}
minRequiredSize += reservedSize;
finalHeapSize = alignUp(std::max(finalHeapSize, minRequiredSize), MemoryConstants::pageSize);
auto heapMemory = memoryManager->obtainReusableAllocation(finalHeapSize, requireInternalHeap).release();
if (!heapMemory) {
if (requireInternalHeap) {
heapMemory = memoryManager->createInternalGraphicsAllocation(nullptr, finalHeapSize);
} else {
heapMemory = memoryManager->allocateGraphicsMemory(finalHeapSize, MemoryConstants::pageSize);
}
} else {
finalHeapSize = std::max(heapMemory->getUnderlyingBufferSize(), finalHeapSize);
}
heapMemory->setAllocationType(GraphicsAllocation::ALLOCATION_TYPE_LINEAR_STREAM);
if (IndirectHeap::SURFACE_STATE == heapType) {
DEBUG_BREAK_IF(minRequiredSize > maxSshSize);
finalHeapSize = maxSshSize;
}
if (indirectHeap) {
indirectHeap->replaceBuffer(heapMemory->getUnderlyingBuffer(), finalHeapSize);
indirectHeap->replaceGraphicsAllocation(heapMemory);
} else {
indirectHeap = new IndirectHeap(heapMemory, requireInternalHeap);
indirectHeap->overrideMaxSize(finalHeapSize);
}
}
void CommandStreamReceiver::releaseIndirectHeap(IndirectHeap::Type heapType) {
DEBUG_BREAK_IF(static_cast<uint32_t>(heapType) >= ARRAY_COUNT(indirectHeap));
auto &heap = indirectHeap[heapType];
if (heap) {
auto heapMemory = heap->getGraphicsAllocation();
if (heapMemory != nullptr)
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
heap->replaceBuffer(nullptr, 0);
heap->replaceGraphicsAllocation(nullptr);
}
}
} // namespace OCLRT

View File

@@ -27,6 +27,7 @@
#include "runtime/helpers/completion_stamp.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/address_patch.h"
#include "runtime/indirect_heap/indirect_heap.h"
#include "runtime/helpers/flat_batch_buffer_helper.h"
#include "runtime/command_stream/csr_definitions.h"
#include <cstddef>
@@ -126,6 +127,10 @@ class CommandStreamReceiver {
FlatBatchBufferHelper &getFlatBatchBufferHelper() { return *flatBatchBufferHelper.get(); }
void overwriteFlatBatchBufferHelper(FlatBatchBufferHelper *newHelper) { flatBatchBufferHelper.reset(newHelper); }
IndirectHeap &getIndirectHeap(IndirectHeap::Type heapType, size_t minRequiredSize);
void allocateHeapMemory(IndirectHeap::Type heapType, size_t minRequiredSize, IndirectHeap *&indirectHeap);
void releaseIndirectHeap(IndirectHeap::Type heapType);
protected:
void setDisableL3Cache(bool val) {
disableL3Cache = val;
@@ -173,6 +178,7 @@ class CommandStreamReceiver {
uint32_t requiredScratchSize = 0;
uint64_t totalMemoryUsed = 0u;
SamplerCacheFlushState samplerCacheFlushRequired = SamplerCacheFlushState::samplerCacheFlushNotRequired;
IndirectHeap *indirectHeap[IndirectHeap::NUM_TYPES];
std::unique_ptr<FlatBatchBufferHelper> flatBatchBufferHelper;
};

View File

@@ -547,6 +547,7 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocationWhenA
MockCommandQueue cmdQ(context.get(), pDevice, props);
auto memoryManager = pDevice->getMemoryManager();
auto &csr = pDevice->getUltCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>();
EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty());
const auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), 100);
@@ -554,8 +555,8 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocationWhenA
auto graphicsAllocation = indirectHeap.getGraphicsAllocation();
cmdQ.indirectHeap[this->GetParam()]->replaceGraphicsAllocation(nullptr);
cmdQ.indirectHeap[this->GetParam()]->replaceBuffer(nullptr, 0);
csr.indirectHeap[this->GetParam()]->replaceGraphicsAllocation(nullptr);
csr.indirectHeap[this->GetParam()]->replaceBuffer(nullptr, 0);
// Request a larger heap than the first.
cmdQ.getIndirectHeap(this->GetParam(), heapSize + 6000);
@@ -564,17 +565,15 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocationWhenA
memoryManager->freeGraphicsMemory(graphicsAllocation);
}
TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWithResourceCachingActiveWhenQueueISDestroyedThenIndirectHeapIsPutOnReuseList) {
TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWithResourceCachingActiveWhenQueueISDestroyedThenIndirectHeapIsNotOnReuseList) {
auto cmdQ = new CommandQueue(context.get(), pDevice, 0);
auto memoryManager = pDevice->getMemoryManager();
const auto &indirectHeap = cmdQ->getIndirectHeap(this->GetParam(), 100);
auto graphicsAllocation = indirectHeap.getGraphicsAllocation();
cmdQ->getIndirectHeap(this->GetParam(), 100);
EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty());
//now destroy command queue, heap should go to reusable list
delete cmdQ;
EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty());
EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*graphicsAllocation));
EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty());
}
TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapAllocatedWhenIndirectHeapIsReleasedThenHeapAllocationAndHeapBufferIsSetToNullptr) {
@@ -593,8 +592,9 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapAllocatedWhenIndir
EXPECT_NE(nullptr, graphicsAllocation);
cmdQ.releaseIndirectHeap(this->GetParam());
auto &csr = pDevice->getUltCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>();
EXPECT_EQ(nullptr, cmdQ.indirectHeap[this->GetParam()]->getGraphicsAllocation());
EXPECT_EQ(nullptr, csr.indirectHeap[this->GetParam()]->getGraphicsAllocation());
EXPECT_EQ(nullptr, indirectHeap.getCpuBase());
EXPECT_EQ(0u, indirectHeap.getMaxAvailableSpace());
@@ -605,8 +605,9 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocatedWhenIn
MockCommandQueue cmdQ(context.get(), pDevice, props);
cmdQ.releaseIndirectHeap(this->GetParam());
auto &csr = pDevice->getUltCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>();
EXPECT_EQ(nullptr, cmdQ.indirectHeap[this->GetParam()]);
EXPECT_EQ(nullptr, csr.indirectHeap[this->GetParam()]);
}
TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapWhenGraphicAllocationIsNullThenNothingOnReuseList) {
@@ -616,9 +617,10 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapWhenGraphicAllocat
auto &ih = cmdQ.getIndirectHeap(this->GetParam(), 0u);
auto allocation = ih.getGraphicsAllocation();
EXPECT_NE(nullptr, allocation);
auto &csr = pDevice->getUltCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>();
cmdQ.indirectHeap[this->GetParam()]->replaceGraphicsAllocation(nullptr);
cmdQ.indirectHeap[this->GetParam()]->replaceBuffer(nullptr, 0);
csr.indirectHeap[this->GetParam()]->replaceGraphicsAllocation(nullptr);
csr.indirectHeap[this->GetParam()]->replaceBuffer(nullptr, 0);
cmdQ.releaseIndirectHeap(this->GetParam());

View File

@@ -1530,6 +1530,25 @@ HWTEST_F(EnqueueKernelTest, givenKernelWhenItIsEnqueuedThenAllResourceGraphicsAl
EXPECT_EQ(csrTaskCount, allocation->taskCount);
}
}
HWTEST_F(EnqueueKernelTest, givenKernelWhenItIsSubmittedFromTwoDifferentCommandQueuesThenCsrDoesntReloadAnyCommands) {
auto &csr = this->pDevice->getUltCommandStreamReceiver<FamilyType>();
MockKernelWithInternals mockKernel(*pDevice);
size_t gws[3] = {1, 0, 0};
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
auto currentUsed = csr.commandStream.getUsed();
const cl_queue_properties props[] = {0};
auto inOrderQueue = clCreateCommandQueueWithProperties(context, pDevice, props, nullptr);
clEnqueueNDRangeKernel(inOrderQueue, mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
auto usedAfterSubmission = csr.commandStream.getUsed();
EXPECT_EQ(usedAfterSubmission, currentUsed);
clReleaseCommandQueue(inOrderQueue);
}
TEST_F(EnqueueKernelTest, givenKernelWhenAllArgsAreNotAndEventExistSetThenClEnqueueNDRangeKernelReturnsInvalidKernelArgsAndSetEventToNull) {
const size_t n = 512;
size_t globalWorkSize[3] = {n, 1, 1};

View File

@@ -123,7 +123,11 @@ HWTEST_P(OOMCommandQueueBufferTest, enqueueCopyBuffer) {
auto usedAfterCS = commandStream.getUsed();
auto usedAfterISH = indirectHeap.getUsed();
EXPECT_LE(usedAfterCS - usedBeforeCS, commandStream.getMaxAvailableSpace());
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
if (usedAfterISH > usedBeforeISH) {
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
} else {
EXPECT_LE(usedAfterISH, indirectHeap.getMaxAvailableSpace());
}
}
HWTEST_P(OOMCommandQueueBufferTest, enqueueFillBuffer) {
@@ -143,7 +147,11 @@ HWTEST_P(OOMCommandQueueBufferTest, enqueueFillBuffer) {
auto usedAfterCS = commandStream.getUsed();
auto usedAfterISH = indirectHeap.getUsed();
EXPECT_LE(usedAfterCS - usedBeforeCS, commandStream.getMaxAvailableSpace());
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
if (usedAfterISH > usedBeforeISH) {
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
} else {
EXPECT_LE(usedAfterISH, indirectHeap.getMaxAvailableSpace());
}
}
HWTEST_P(OOMCommandQueueBufferTest, enqueueReadBuffer) {
@@ -163,7 +171,11 @@ HWTEST_P(OOMCommandQueueBufferTest, enqueueReadBuffer) {
auto usedAfterCS = commandStream.getUsed();
auto usedAfterISH = indirectHeap.getUsed();
EXPECT_LE(usedAfterCS - usedBeforeCS, commandStream.getMaxAvailableSpace());
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
if (usedAfterISH > usedBeforeISH) {
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
} else {
EXPECT_LE(usedAfterISH, indirectHeap.getMaxAvailableSpace());
}
}
HWTEST_P(OOMCommandQueueBufferTest, enqueueWriteBuffer) {
@@ -183,7 +195,11 @@ HWTEST_P(OOMCommandQueueBufferTest, enqueueWriteBuffer) {
auto usedAfterCS = commandStream.getUsed();
auto usedAfterISH = indirectHeap.getUsed();
EXPECT_LE(usedAfterCS - usedBeforeCS, commandStream.getMaxAvailableSpace());
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
if (usedAfterISH > usedBeforeISH) {
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
} else {
EXPECT_LE(usedAfterISH, indirectHeap.getMaxAvailableSpace());
}
}
HWTEST_P(OOMCommandQueueBufferTest, enqueueWriteBufferRect) {
@@ -203,7 +219,11 @@ HWTEST_P(OOMCommandQueueBufferTest, enqueueWriteBufferRect) {
auto usedAfterCS = commandStream.getUsed();
auto usedAfterISH = indirectHeap.getUsed();
EXPECT_LE(usedAfterCS - usedBeforeCS, commandStream.getMaxAvailableSpace());
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
if (usedAfterISH > usedBeforeISH) {
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
} else {
EXPECT_LE(usedAfterISH, indirectHeap.getMaxAvailableSpace());
}
}
HWTEST_P(OOMCommandQueueBufferTest, enqueueKernelHelloWorld) {
@@ -226,7 +246,11 @@ HWTEST_P(OOMCommandQueueBufferTest, enqueueKernelHelloWorld) {
auto usedAfterCS = commandStream.getUsed();
auto usedAfterISH = indirectHeap.getUsed();
EXPECT_LE(usedAfterCS - usedBeforeCS, commandStream.getMaxAvailableSpace());
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
if (usedAfterISH > usedBeforeISH) {
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
} else {
EXPECT_LE(usedAfterISH, indirectHeap.getMaxAvailableSpace());
}
EXPECT_EQ(CL_SUCCESS, retVal1);
EXPECT_EQ(CL_SUCCESS, retVal2);
@@ -252,7 +276,11 @@ HWTEST_P(OOMCommandQueueBufferTest, enqueueKernelSimpleArg) {
auto usedAfterCS = commandStream.getUsed();
auto usedAfterISH = indirectHeap.getUsed();
EXPECT_LE(usedAfterCS - usedBeforeCS, commandStream.getMaxAvailableSpace());
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
if (usedAfterISH > usedBeforeISH) {
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
} else {
EXPECT_LE(usedAfterISH, indirectHeap.getMaxAvailableSpace());
}
EXPECT_EQ(CL_SUCCESS, retVal1);
EXPECT_EQ(CL_SUCCESS, retVal2);

View File

@@ -104,7 +104,11 @@ HWTEST_P(OOMCommandQueueImageTest, enqueueCopyImage) {
auto usedAfterCS = commandStream.getUsed();
auto usedAfterISH = indirectHeap.getUsed();
EXPECT_LE(usedAfterCS - usedBeforeCS, commandStream.getMaxAvailableSpace());
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
if (usedAfterISH > usedBeforeISH) {
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
} else {
EXPECT_LE(usedAfterISH, indirectHeap.getMaxAvailableSpace());
}
EXPECT_EQ(CL_SUCCESS, retVal1);
EXPECT_EQ(CL_SUCCESS, retVal2);
@@ -124,7 +128,11 @@ HWTEST_P(OOMCommandQueueImageTest, enqueueFillImage) {
auto usedAfterCS = commandStream.getUsed();
auto usedAfterISH = indirectHeap.getUsed();
EXPECT_LE(usedAfterCS - usedBeforeCS, commandStream.getMaxAvailableSpace());
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
if (usedAfterISH > usedBeforeISH) {
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
} else {
EXPECT_LE(usedAfterISH, indirectHeap.getMaxAvailableSpace());
}
EXPECT_EQ(CL_SUCCESS, retVal1);
EXPECT_EQ(CL_SUCCESS, retVal2);
@@ -144,7 +152,11 @@ HWTEST_P(OOMCommandQueueImageTest, enqueueReadImage) {
auto usedAfterCS = commandStream.getUsed();
auto usedAfterISH = indirectHeap.getUsed();
EXPECT_LE(usedAfterCS - usedBeforeCS, commandStream.getMaxAvailableSpace());
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
if (usedAfterISH > usedBeforeISH) {
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
} else {
EXPECT_LE(usedAfterISH, indirectHeap.getMaxAvailableSpace());
}
EXPECT_EQ(CL_SUCCESS, retVal1);
EXPECT_EQ(CL_SUCCESS, retVal2);
@@ -164,7 +176,11 @@ HWTEST_P(OOMCommandQueueImageTest, enqueueWriteImage) {
auto usedAfterCS = commandStream.getUsed();
auto usedAfterISH = indirectHeap.getUsed();
EXPECT_LE(usedAfterCS - usedBeforeCS, commandStream.getMaxAvailableSpace());
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
if (usedAfterISH > usedBeforeISH) {
EXPECT_LE(usedAfterISH - usedBeforeISH, indirectHeap.getMaxAvailableSpace());
} else {
EXPECT_LE(usedAfterISH, indirectHeap.getMaxAvailableSpace());
}
EXPECT_EQ(CL_SUCCESS, retVal1);
EXPECT_EQ(CL_SUCCESS, retVal2);

View File

@@ -258,6 +258,32 @@ HWTEST_F(CommandStreamReceiverTest, givenDefaultCommandStreamReceiverThenDefault
EXPECT_EQ(DispatchMode::ImmediateDispatch, csr.dispatchMode);
}
HWTEST_F(CommandStreamReceiverTest, givenCsrWhenGetIndirectHeapIsCalledThenHeapIsReturned) {
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
auto &heap = csr.getIndirectHeap(IndirectHeap::DYNAMIC_STATE, 10u);
EXPECT_NE(nullptr, heap.getGraphicsAllocation());
EXPECT_NE(nullptr, csr.indirectHeap[IndirectHeap::DYNAMIC_STATE]);
EXPECT_EQ(&heap, csr.indirectHeap[IndirectHeap::DYNAMIC_STATE]);
}
HWTEST_F(CommandStreamReceiverTest, givenCsrWhenReleaseIndirectHeapIsCalledThenHeapAllocationIsNull) {
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
auto &heap = csr.getIndirectHeap(IndirectHeap::DYNAMIC_STATE, 10u);
csr.releaseIndirectHeap(IndirectHeap::DYNAMIC_STATE);
EXPECT_EQ(nullptr, heap.getGraphicsAllocation());
EXPECT_EQ(0u, heap.getMaxAvailableSpace());
}
HWTEST_F(CommandStreamReceiverTest, givenCsrWhenAllocateHeapMemoryIsCalledThenHeapMemoryIsAllocated) {
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
IndirectHeap *dsh = nullptr;
csr.allocateHeapMemory(IndirectHeap::DYNAMIC_STATE, 4096u, dsh);
EXPECT_NE(nullptr, dsh);
ASSERT_NE(nullptr, dsh->getGraphicsAllocation());
csr.getMemoryManager()->freeGraphicsMemory(dsh->getGraphicsAllocation());
delete dsh;
}
TEST(CommandStreamReceiverSimpleTest, givenCSRWithoutTagAllocationWhenGetTagAllocationIsCalledThenNullptrIsReturned) {
MockCommandStreamReceiver csr;
EXPECT_EQ(nullptr, csr.getTagAllocation());
@@ -268,4 +294,4 @@ TEST(CommandStreamReceiverSimpleTest, givenCSRWithTagAllocationSetWhenGetTagAllo
GraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
csr.setTagAllocation(&allocation);
EXPECT_EQ(&allocation, csr.getTagAllocation());
}
}

View File

@@ -566,6 +566,10 @@ HWTEST_F(KernelCommandsTest, usedBindingTableStatePointersForGlobalAndConstantAn
program.setGlobalSurface(nullptr);
program.setConstantSurface(nullptr);
//exhaust space to trigger reload
ssh.getSpace(ssh.getAvailableSpace());
dsh.getSpace(dsh.getAvailableSpace());
}
alignedFree(surfaceStateHeap);
delete pKernel;

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"),
@@ -36,6 +36,7 @@ TEST(CommandTest, mapUnmapSubmitWithoutTerminateFlagFlushesCsr) {
std::unique_ptr<Device> device(DeviceHelper<>::create());
std::unique_ptr<MockCommandQueue> cmdQ(new MockCommandQueue(nullptr, device.get(), nullptr));
MockCommandStreamReceiver csr;
csr.setMemoryManager(device->getMemoryManager());
MockBuffer buffer;
auto initialTaskCount = csr.peekTaskCount();
@@ -53,6 +54,7 @@ TEST(CommandTest, mapUnmapSubmitWithTerminateFlagAbortsFlush) {
std::unique_ptr<Device> device(DeviceHelper<>::create());
std::unique_ptr<MockCommandQueue> cmdQ(new MockCommandQueue(nullptr, device.get(), nullptr));
MockCommandStreamReceiver csr;
csr.setMemoryManager(device->getMemoryManager());
MockBuffer buffer;
auto initialTaskCount = csr.peekTaskCount();
@@ -73,6 +75,7 @@ TEST(CommandTest, markerSubmitWithoutTerminateFlagFlushesCsr) {
std::unique_ptr<Device> device(DeviceHelper<>::create());
std::unique_ptr<MockCommandQueue> cmdQ(new MockCommandQueue(nullptr, device.get(), nullptr));
MockCommandStreamReceiver csr;
csr.setMemoryManager(device->getMemoryManager());
MockBuffer buffer;
auto initialTaskCount = csr.peekTaskCount();

View File

@@ -35,7 +35,9 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily> {
public:
using BaseClass::dshState;
using BaseClass::hwInfo;
using BaseClass::indirectHeap;
using BaseClass::iohState;
using BaseClass::programPreamble;
using BaseClass::sshState;
using BaseClass::CommandStreamReceiver::commandStream;
using BaseClass::CommandStreamReceiver::disableL3Cache;
@@ -53,7 +55,6 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily> {
using BaseClass::CommandStreamReceiver::requiredThreadArbitrationPolicy;
using BaseClass::CommandStreamReceiver::taskCount;
using BaseClass::CommandStreamReceiver::taskLevel;
using BaseClass::programPreamble;
UltCommandStreamReceiver(const UltCommandStreamReceiver &) = delete;
UltCommandStreamReceiver &operator=(const UltCommandStreamReceiver &) = delete;

View File

@@ -31,7 +31,6 @@ namespace OCLRT {
class MockCommandQueue : public CommandQueue {
public:
using CommandQueue::device;
using CommandQueue::indirectHeap;
void setProfilingEnabled() {
commandQueueProperties |= CL_QUEUE_PROFILING_ENABLE;