Refactor ult for preemption enabling

Refactoring in ULTs around preemption:
    -refactoring ULTS to not fail with default preemption mode
    -fixing ULT memory leaks observed after enabling preemption
    -mocking getSipKernel in ULTs (to minimize ULT execution time)

Change-Id: I194b56173d7cb23aae94eeeca60051759c817e10
This commit is contained in:
mplewka
2018-03-05 09:25:40 +01:00
committed by sys_ocldev
parent 37b0d07f8a
commit 079f94cd2d
29 changed files with 474 additions and 158 deletions

View File

@@ -24,8 +24,10 @@
#include "test.h"
#include "runtime/built_ins/built_ins.h"
#include "runtime/built_ins/vme_dispatch_builder.h"
#include "runtime/helpers/dispatch_info_builder.h"
#include "runtime/helpers/file_io.h"
#include "runtime/helpers/hash.h"
#include "runtime/helpers/string.h"
#include "runtime/kernel/kernel.h"
#include "runtime/platform/platform.h"
#include "unit_tests/global_environment.h"
@@ -34,14 +36,14 @@
#include "unit_tests/fixtures/context_fixture.h"
#include "unit_tests/fixtures/image_fixture.h"
#include "unit_tests/fixtures/run_kernel_fixture.h"
#include <string>
#include "runtime/helpers/string.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_builtins.h"
#include "unit_tests/mocks/mock_compilers.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "runtime/helpers/dispatch_info_builder.h"
#include "os_inc.h"
#include <string>
using namespace OCLRT;
class BuiltInTests
@@ -1473,6 +1475,7 @@ TEST_F(BuiltInTests, createBuiltInProgramForInvalidBuiltinKernelName) {
}
TEST_F(BuiltInTests, getSipKernelReturnsProgramCreatedOutOfIsaAcquiredFromCompilerInterface) {
MockBuiltins mockBuiltins;
MockCompilerInterface mockCompilerInterface;
mockCompilerInterface.overrideGlobalCompilerInterface();
mockCompilerInterface.sipKernelBinaryOverride = mockCompilerInterface.getDummyGenBinary();
@@ -1483,7 +1486,7 @@ TEST_F(BuiltInTests, getSipKernelReturnsProgramCreatedOutOfIsaAcquiredFromCompil
errCode = p->processGenBinary();
ASSERT_EQ(CL_SUCCESS, errCode);
const SipKernel &sipKern = BuiltIns::getInstance().getSipKernel(SipKernelType::Csr, *pContext->getDevice(0));
const SipKernel &sipKern = mockBuiltins.getSipKernel(SipKernelType::Csr, *pContext->getDevice(0));
const auto &sipKernelInfo = p->getKernelInfo(static_cast<size_t>(0));

View File

@@ -260,12 +260,14 @@ struct CommandQueueCommandStreamTest : public CommandQueueMemoryDevice,
public ::testing::Test {
void SetUp() override {
CommandQueueMemoryDevice::SetUp();
context.reset(new MockContext(pDevice));
}
void TearDown() override {
context.reset();
CommandQueueMemoryDevice::TearDown();
}
MockContext context;
std::unique_ptr<MockContext> context;
};
HWTEST_F(CommandQueueCommandStreamTest, givenCommandQueueThatWaitsOnAbortedUserEventWhenIsQueueBlockedIsCalledThenTaskLevelAlignsToCsr) {
@@ -287,7 +289,7 @@ HWTEST_F(CommandQueueCommandStreamTest, givenCommandQueueThatWaitsOnAbortedUserE
TEST_F(CommandQueueCommandStreamTest, GetCommandStreamReturnsValidObject) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue commandQueue(&context, pDevice, props);
CommandQueue commandQueue(context.get(), pDevice, props);
auto &cs = commandQueue.getCS();
EXPECT_NE(nullptr, &cs);
@@ -295,7 +297,7 @@ TEST_F(CommandQueueCommandStreamTest, GetCommandStreamReturnsValidObject) {
TEST_F(CommandQueueCommandStreamTest, GetCommandStreamReturnsCsWithCsOverfetchSizeIncludedInGraphicsAllocation) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue commandQueue(&context, pDevice, props);
CommandQueue commandQueue(context.get(), pDevice, props);
size_t minSizeRequested = 20;
auto &cs = commandQueue.getCS(minSizeRequested);
@@ -312,7 +314,7 @@ TEST_F(CommandQueueCommandStreamTest, GetCommandStreamReturnsCsWithCsOverfetchSi
TEST_F(CommandQueueCommandStreamTest, getCommandStreamContainsMemoryForRequest) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue commandQueue(&context, pDevice, props);
CommandQueue commandQueue(context.get(), pDevice, props);
size_t requiredSize = 16384;
const auto &commandStream = commandQueue.getCS(requiredSize);
@@ -322,7 +324,7 @@ TEST_F(CommandQueueCommandStreamTest, getCommandStreamContainsMemoryForRequest)
TEST_F(CommandQueueCommandStreamTest, getCommandStreamCanRecycle) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue commandQueue(&context, pDevice, props);
CommandQueue commandQueue(context.get(), pDevice, props);
auto &commandStreamInitial = commandQueue.getCS();
size_t requiredSize = commandStreamInitial.getMaxAvailableSpace() + 42;
@@ -334,7 +336,7 @@ TEST_F(CommandQueueCommandStreamTest, getCommandStreamCanRecycle) {
TEST_F(CommandQueueCommandStreamTest, MemoryManagerWithReusableAllocationsWhenAskedForCommandStreamReturnsAllocationFromReusablePool) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
auto memoryManager = pDevice->getMemoryManager();
size_t requiredSize = alignUp(100, MemoryConstants::pageSize) + CSRequirements::csOverfetchSize;
@@ -351,7 +353,7 @@ TEST_F(CommandQueueCommandStreamTest, MemoryManagerWithReusableAllocationsWhenAs
EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty());
}
TEST_F(CommandQueueCommandStreamTest, givenCommandQueueWhenItIsDestroyedThenCommandStreamIsPutOnTheReusabeList) {
auto cmdQ = new CommandQueue(&context, pDevice, 0);
auto cmdQ = new CommandQueue(context.get(), pDevice, 0);
auto memoryManager = pDevice->getMemoryManager();
const auto &commandStream = cmdQ->getCS(100);
auto graphicsAllocation = commandStream.getGraphicsAllocation();
@@ -365,7 +367,7 @@ TEST_F(CommandQueueCommandStreamTest, givenCommandQueueWhenItIsDestroyedThenComm
TEST_F(CommandQueueCommandStreamTest, CommandQueueWhenAskedForNewCommandStreamStoresOldHeapForReuse) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
auto memoryManager = pDevice->getMemoryManager();
@@ -386,7 +388,7 @@ TEST_F(CommandQueueCommandStreamTest, CommandQueueWhenAskedForNewCommandStreamSt
TEST_F(CommandQueueCommandStreamTest, givenCommandQueueWhenGetCSIsCalledThenCommandStreamAllocationTypeShouldBeSetToLinearStream) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
const auto &commandStream = cmdQ.getCS(100);
auto commandStreamAllocation = commandStream.getGraphicsAllocation();
@@ -399,17 +401,19 @@ struct CommandQueueIndirectHeapTest : public CommandQueueMemoryDevice,
public ::testing::TestWithParam<IndirectHeap::Type> {
void SetUp() override {
CommandQueueMemoryDevice::SetUp();
context.reset(new MockContext(pDevice));
}
void TearDown() override {
context.reset();
CommandQueueMemoryDevice::TearDown();
}
MockContext context;
std::unique_ptr<MockContext> context;
};
TEST_P(CommandQueueIndirectHeapTest, IndirectHeapIsProvidedByDevice) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), 8192);
EXPECT_NE(nullptr, &indirectHeap);
@@ -417,7 +421,7 @@ TEST_P(CommandQueueIndirectHeapTest, IndirectHeapIsProvidedByDevice) {
TEST_P(CommandQueueIndirectHeapTest, IndirectHeapContainsAtLeast64KB) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), sizeof(uint32_t));
if (this->GetParam() == IndirectHeap::SURFACE_STATE) {
@@ -429,7 +433,7 @@ TEST_P(CommandQueueIndirectHeapTest, IndirectHeapContainsAtLeast64KB) {
TEST_P(CommandQueueIndirectHeapTest, getIndirectHeapContainsMemoryForRequest) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
size_t requiredSize = 16384;
const auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), requiredSize);
@@ -439,7 +443,7 @@ TEST_P(CommandQueueIndirectHeapTest, getIndirectHeapContainsMemoryForRequest) {
TEST_P(CommandQueueIndirectHeapTest, getIndirectHeapCanRecycle) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
auto &indirectHeapInitial = cmdQ.getIndirectHeap(this->GetParam(), 10);
size_t requiredSize = indirectHeapInitial.getMaxAvailableSpace() + 42;
@@ -456,7 +460,7 @@ TEST_P(CommandQueueIndirectHeapTest, getIndirectHeapCanRecycle) {
TEST_P(CommandQueueIndirectHeapTest, alignSizeToCacheLine) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
size_t minHeapSize = 64 * KB;
auto &indirectHeapInitial = cmdQ.getIndirectHeap(this->GetParam(), 2 * minHeapSize + 1);
@@ -473,7 +477,7 @@ TEST_P(CommandQueueIndirectHeapTest, alignSizeToCacheLine) {
TEST_P(CommandQueueIndirectHeapTest, MemoryManagerWithReusableAllocationsWhenAskedForHeapAllocationReturnsAllocationFromReusablePool) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
auto memoryManager = pDevice->getMemoryManager();
auto allocationSize = defaultHeapSize * 2;
@@ -501,7 +505,7 @@ TEST_P(CommandQueueIndirectHeapTest, MemoryManagerWithReusableAllocationsWhenAsk
TEST_P(CommandQueueIndirectHeapTest, CommandQueueWhenAskedForNewHeapStoresOldHeapForReuse) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
auto memoryManager = pDevice->getMemoryManager();
EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty());
@@ -521,7 +525,7 @@ TEST_P(CommandQueueIndirectHeapTest, CommandQueueWhenAskedForNewHeapStoresOldHea
TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocationWhenAskedForNewHeapReturnsAcquiresNewAllocationWithoutStoring) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
MockCommandQueue cmdQ(&context, pDevice, props);
MockCommandQueue cmdQ(context.get(), pDevice, props);
auto memoryManager = pDevice->getMemoryManager();
EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty());
@@ -542,7 +546,7 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocationWhenA
}
TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWithResourceCachingActiveWhenQueueISDestroyedThenIndirectHeapIsPutOnReuseList) {
auto cmdQ = new CommandQueue(&context, pDevice, 0);
auto cmdQ = new CommandQueue(context.get(), pDevice, 0);
auto memoryManager = pDevice->getMemoryManager();
const auto &indirectHeap = cmdQ->getIndirectHeap(this->GetParam(), 100);
auto graphicsAllocation = indirectHeap.getGraphicsAllocation();
@@ -556,7 +560,7 @@ TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWithResourceCachingActiveW
TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapAllocatedWhenIndirectHeapIsReleasedThenHeapAllocationAndHeapBufferIsSetToNullptr) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
MockCommandQueue cmdQ(&context, pDevice, props);
MockCommandQueue cmdQ(context.get(), pDevice, props);
auto memoryManager = pDevice->getMemoryManager();
EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty());
@@ -579,7 +583,7 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapAllocatedWhenIndir
TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocatedWhenIndirectHeapIsReleasedThenIndirectHeapAllocationStaysNull) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
MockCommandQueue cmdQ(&context, pDevice, props);
MockCommandQueue cmdQ(context.get(), pDevice, props);
cmdQ.releaseIndirectHeap(this->GetParam());
@@ -588,7 +592,7 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocatedWhenIn
TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapWhenGraphicAllocationIsNullThenNothingOnReuseList) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
MockCommandQueue cmdQ(&context, pDevice, props);
MockCommandQueue cmdQ(context.get(), pDevice, props);
auto &ih = cmdQ.getIndirectHeap(this->GetParam());
auto allocation = ih.getGraphicsAllocation();
@@ -607,7 +611,7 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapWhenGraphicAllocat
TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWhenGetIndirectHeapIsCalledThenIndirectHeapAllocationTypeShouldBeSetToLinearStream) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
const auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), 100);
auto indirectHeapAllocation = indirectHeap.getGraphicsAllocation();
@@ -618,7 +622,7 @@ TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWhenGetIndirectHeapIsCalle
TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWhenGetHeapMemoryIsCalledThenHeapIsCreated) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
IndirectHeap *indirectHeap = nullptr;
cmdQ.allocateHeapMemory(this->GetParam(), 100, indirectHeap);
@@ -631,7 +635,7 @@ TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWhenGetHeapMemoryIsCalledT
TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWhenGetHeapMemoryIsCalledWithAlreadyAllocatedHeapThenGraphicsAllocationIsCreated) {
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
CommandQueue cmdQ(&context, pDevice, props);
CommandQueue cmdQ(context.get(), pDevice, props);
IndirectHeap heap(nullptr, 100);
@@ -915,7 +919,7 @@ HWTEST_F(CommandQueueCommandStreamTest, givenDebugKernelWhenSetupDebugSurfaceIsC
MockProgram program;
program.enableKernelDebug();
std::unique_ptr<MockDebugKernel> kernel(MockKernel::create<MockDebugKernel>(*pDevice, &program));
CommandQueue cmdQ(&context, pDevice, 0);
CommandQueue cmdQ(context.get(), pDevice, 0);
kernel->setSshLocal(nullptr, sizeof(RENDER_SURFACE_STATE) + kernel->getAllocatedKernelInfo()->patchInfo.pAllocateSystemThreadSurface->Offset);
kernel->getAllocatedKernelInfo()->usesSsh = true;
@@ -934,7 +938,7 @@ HWTEST_F(CommandQueueCommandStreamTest, givenCsrWithDebugSurfaceAllocatedWhenSet
MockProgram program;
program.enableKernelDebug();
std::unique_ptr<MockDebugKernel> kernel(MockKernel::create<MockDebugKernel>(*pDevice, &program));
CommandQueue cmdQ(&context, pDevice, 0);
CommandQueue cmdQ(context.get(), pDevice, 0);
kernel->setSshLocal(nullptr, sizeof(RENDER_SURFACE_STATE) + kernel->getAllocatedKernelInfo()->patchInfo.pAllocateSystemThreadSurface->Offset);
kernel->getAllocatedKernelInfo()->usesSsh = true;

View File

@@ -143,11 +143,10 @@ struct EnqueueCopyBufferRectTest : public CommandEnqueueFixture,
parseCommands<FamilyType>(*pCmdQ);
}
MockContext context;
Buffer *srcBuffer;
Buffer *dstBuffer;
static const size_t rowPitch = 100;
static const size_t slicePitch = 100 * 100;
};
}
} // namespace OCLRT

View File

@@ -274,8 +274,8 @@ struct EnqueueKernelTypeTest : public HelloWorldFixture<HelloWorldFixtureFactory
public HardwareParse,
::testing::TestWithParam<InputType> {
typedef HelloWorldFixture<HelloWorldFixtureFactory> ParentClass;
using ParentClass::pCmdBuffer;
using ParentClass::pCS;
using ParentClass::pCmdBuffer;
EnqueueKernelTypeTest() {
}
@@ -1064,7 +1064,9 @@ HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeWhenEnqueueK
EXPECT_FALSE(mockedSubmissionsAggregator->peekCmdBufferList().peekIsEmpty());
auto cmdBuffer = mockedSubmissionsAggregator->peekCmdBufferList().peekHead();
size_t csrSurfaceCount = (pDevice->getPreemptionMode() == PreemptionMode::MidThread) ? 1 : 0;
//Two more surfaces from preemptionAllocation and SipKernel
size_t csrSurfaceCount = (pDevice->getPreemptionMode() == PreemptionMode::MidThread) ? 2 : 0;
EXPECT_EQ(0, mockCsr->flushCalledCount);
EXPECT_EQ(5u + csrSurfaceCount, cmdBuffer->surfaces.size());

View File

@@ -40,16 +40,15 @@ struct EnqueueReadBufferRectTest : public CommandEnqueueFixture,
void SetUp() override {
CommandEnqueueFixture::SetUp();
contextMemoryManager = context.getMemoryManager();
context.setMemoryManager(pCmdQ->getDevice().getMemoryManager());
BufferDefaults::context = new MockContext;
context.reset(new MockContext(&pCmdQ->getDevice()));
BufferDefaults::context = context.get();
//For 3D
hostPtr = ::alignedMalloc(slicePitch * rowPitch, 4096);
auto retVal = CL_INVALID_VALUE;
buffer.reset(Buffer::create(
&context,
context.get(),
CL_MEM_READ_WRITE,
slicePitch * rowPitch,
nullptr,
@@ -62,10 +61,9 @@ struct EnqueueReadBufferRectTest : public CommandEnqueueFixture,
void TearDown() override {
nonZeroCopyBuffer.reset(nullptr);
buffer.reset(nullptr);
delete BufferDefaults::context;
::alignedFree(hostPtr);
context.setMemoryManager(contextMemoryManager);
context.reset();
CommandEnqueueFixture::TearDown();
}
@@ -97,11 +95,10 @@ struct EnqueueReadBufferRectTest : public CommandEnqueueFixture,
parseCommands<FamilyType>(*pCmdQ);
}
MockContext context;
std::unique_ptr<MockContext> context;
std::unique_ptr<Buffer> buffer;
std::unique_ptr<Buffer> nonZeroCopyBuffer;
void *hostPtr;
MemoryManager *contextMemoryManager;
static const size_t rowPitch = 100;
static const size_t slicePitch = 100 * 100;

View File

@@ -41,17 +41,15 @@ struct EnqueueWriteBufferRectTest : public CommandEnqueueFixture,
void SetUp() override {
CommandEnqueueFixture::SetUp();
contextMemoryManager = context.getMemoryManager();
context.setMemoryManager(pCmdQ->getDevice().getMemoryManager());
BufferDefaults::context = new MockContext;
context.reset(new MockContext(&pCmdQ->getDevice()));
BufferDefaults::context = context.get();
//For 3D
hostPtr = ::alignedMalloc(slicePitch * rowPitch, 4096);
auto retVal = CL_INVALID_VALUE;
buffer.reset(Buffer::create(
&context,
context.get(),
CL_MEM_READ_WRITE,
slicePitch * rowPitch,
nullptr,
@@ -65,10 +63,8 @@ struct EnqueueWriteBufferRectTest : public CommandEnqueueFixture,
void TearDown() override {
buffer.reset(nullptr);
nonZeroCopyBuffer.reset(nullptr);
delete BufferDefaults::context;
::alignedFree(hostPtr);
context.setMemoryManager(contextMemoryManager);
context.reset(nullptr);
CommandEnqueueFixture::TearDown();
}
@@ -100,14 +96,12 @@ struct EnqueueWriteBufferRectTest : public CommandEnqueueFixture,
parseCommands<FamilyType>(*pCmdQ);
}
MockContext context;
std::unique_ptr<MockContext> context;
std::unique_ptr<Buffer> buffer;
std::unique_ptr<Buffer> nonZeroCopyBuffer;
void *hostPtr;
MemoryManager *contextMemoryManager;
static const size_t rowPitch = 100;
static const size_t slicePitch = 100 * 100;
};

View File

@@ -51,7 +51,6 @@ struct GetSizeRequiredTest : public CommandEnqueueFixture,
CommandEnqueueFixture::TearDown();
}
MockContext context;
IndirectHeap *dsh;
IndirectHeap *ioh;
IndirectHeap *ssh;

View File

@@ -57,8 +57,8 @@
using namespace OCLRT;
using ::testing::_;
using ::testing::Invoke;
using ::testing::_;
HWTEST_F(UltCommandStreamReceiverTest, requiredCmdSizeForPreamble) {
auto expectedCmdSize =
@@ -171,6 +171,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTaskIsSu
auto fillSize = MemoryConstants::cacheLineSize - sizeof(typename FamilyType::MI_BATCH_BUFFER_END);
commandStream.getSpace(fillSize);
DispatchFlags dispatchFlags;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -285,16 +286,17 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, sameTaskLevelShouldntSendAPipeCont
EXPECT_EQ(sizeUsed, 0u);
}
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenDeviceWithPreemptionSupportThenDontSendMediaVfeStateIfNotDirty) {
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenDeviceWithThreadGroupPreemptionSupportThenDontSendMediaVfeStateIfNotDirty) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForcePreemptionMode.set(static_cast<int32_t>(PreemptionMode::ThreadGroup));
WhitelistedRegisters forceRegs = {0};
pDevice->setForceWhitelistedRegs(true, &forceRegs);
auto commandStreamReceiver = new MockCsrHw<FamilyType>(*platformDevices[0]);
pDevice->setPreemptionMode(PreemptionMode::ThreadGroup);
pDevice->resetCommandStreamReceiver(commandStreamReceiver);
// Configure the CSR to not need to submit any state or commands.
configureCSRtoNonDirtyState<FamilyType>();
pDevice->setPreemptionMode(PreemptionMode::ThreadGroup);
flushTask(*commandStreamReceiver);
@@ -803,7 +805,6 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, flushTaskWithBothCSCallsFlushOnce)
commandStream.getSpace(sizeof(typename FamilyType::MI_NOOP));
flushTask(commandStreamReceiver);
EXPECT_EQ(1, commandStreamReceiver.flushCount);
}
@@ -859,6 +860,7 @@ HWTEST_F(CommandStreamReceiverCQFlushTaskTests, getCSShouldReturnACSWithEnoughSi
auto blocking = true;
DispatchFlags dispatchFlags;
dispatchFlags.blocking = blocking;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
commandStreamReceiver.flushTask(
commandStream,
@@ -905,6 +907,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, blockingFlushTaskWithOnlyPipeContr
DispatchFlags dispatchFlags;
dispatchFlags.blocking = blocking;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
commandStreamReceiver->flushTask(
commandStreamTask,
@@ -947,6 +950,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, FlushTaskBlockingHasPipeControlWit
dispatchFlags.blocking = true;
dispatchFlags.dcFlush = true;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
commandStreamReceiver.flushTask(
commandStreamTask,
@@ -1900,6 +1904,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, flushTaskWithPCWhenPreambleSentAnd
DispatchFlags dispatchFlags;
dispatchFlags.useSLM = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
commandStreamReceiver.flushTask(commandStream, 0, dsh, ioh, ssh, taskLevel, dispatchFlags);
@@ -2016,6 +2021,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInNonDirtyStateWhenflushTa
configureCSRtoNonDirtyState<FamilyType>();
DispatchFlags dispatchFlags;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
dsh,
@@ -2027,7 +2033,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInNonDirtyStateWhenflushTa
EXPECT_EQ(0, mockCsr->flushCalledCount);
}
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInNonDirtyStateAndBatchingModeWhenflushTaskIsCalledThenSubmissionIsNotRecorded) {
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInNonDirtyStateAndBatchingModeWhenflushTaskIsCalledWithDisabledPreemptionThenSubmissionIsNotRecorded) {
CommandQueueHw<FamilyType> commandQueue(nullptr, pDevice, 0);
auto &commandStream = commandQueue.getCS(4096u);
@@ -2042,6 +2048,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInNonDirtyStateAndBatching
configureCSRtoNonDirtyState<FamilyType>();
DispatchFlags dispatchFlags;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
dsh,
@@ -2074,6 +2081,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenFlushTas
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2088,8 +2096,11 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenFlushTas
EXPECT_EQ(cmdBufferList.peekHead(), cmdBufferList.peekTail());
auto cmdBuffer = cmdBufferList.peekHead();
//two more because of preemption allocation and sipKernel in Mid Thread preemption mode
size_t csrSurfaceCount = (pDevice->getPreemptionMode() == PreemptionMode::MidThread) ? 2 : 0;
//we should have 3 heaps, tag allocation and csr command stream + cq
EXPECT_EQ(5u, cmdBuffer->surfaces.size());
EXPECT_EQ(5u + csrSurfaceCount, cmdBuffer->surfaces.size());
EXPECT_EQ(0, mockCsr->flushCalledCount);
@@ -2175,6 +2186,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndThreeReco
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2236,6 +2248,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndThreeReco
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2297,6 +2310,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenFlushTas
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2366,11 +2380,10 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenRecorded
mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator);
configureCSRtoNonDirtyState<FamilyType>();
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.requiresCoherency = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->lastSentCoherencyRequest = 1;
commandStream.getSpace(4);
@@ -2392,7 +2405,10 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenRecorded
EXPECT_FALSE(cmdBufferList.peekIsEmpty());
auto cmdBuffer = cmdBufferList.peekHead();
EXPECT_EQ(4u, cmdBuffer->surfaces.size());
//preemption allocation + sip kernel
size_t csrSurfaceCount = (pDevice->getPreemptionMode() == PreemptionMode::MidThread) ? 2 : 0;
EXPECT_EQ(4u + csrSurfaceCount, cmdBuffer->surfaces.size());
//copy those surfaces
std::vector<GraphicsAllocation *> residentSurfaces = cmdBuffer->surfaces;
@@ -2442,6 +2458,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenBlocking
DispatchFlags dispatchFlags;
dispatchFlags.blocking = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2493,6 +2510,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenFlushTas
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2517,6 +2535,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInDefaultModeWhenFlushTask
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
auto &csr = pDevice->getCommandStreamReceiver();
csr.flushTask(commandStream,
@@ -2545,6 +2564,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenWaitForT
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2583,6 +2603,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenEnqueueI
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2621,6 +2642,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenSusbsequ
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2669,6 +2691,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTotalRes
mockedMemoryManager->device = pDevice;
mockCsr->setMemoryManager(mockedMemoryManager.get());
mockCsr->setTagAllocation(pDevice->getTagAllocation());
mockCsr->setPreemptionCsrAllocation(pDevice->getPreemptionAllocation());
mockCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch);
auto mockedSubmissionsAggregator = new mockSubmissionsAggregator();
@@ -2676,6 +2699,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTotalRes
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockedMemoryManager->budgetExhausted = true;
@@ -2729,6 +2753,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTwoTasks
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.outOfOrderExecutionAllowed = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
auto taskLevelPriorToSubmission = mockCsr->peekTaskLevel();
@@ -2803,6 +2828,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenDcFlushI
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2830,6 +2856,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenCommandA
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.outOfOrderExecutionAllowed = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2859,6 +2886,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWithOutOfOrd
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.outOfOrderExecutionAllowed = false;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2891,6 +2919,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenDcFlushI
DispatchFlags dispatchFlags;
dispatchFlags.dcFlush = true;
dispatchFlags.outOfOrderExecutionAllowed = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -2976,6 +3005,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenPipeCont
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.outOfOrderExecutionAllowed = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
auto taskLevelPriorToSubmission = mockCsr->peekTaskLevel();
@@ -3034,6 +3064,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenThreeTas
DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.outOfOrderExecutionAllowed = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
auto taskLevelPriorToSubmission = mockCsr->peekTaskLevel();
@@ -3168,6 +3199,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenDispatchFlagsWithThrottleSetT
DispatchFlags dispatchFlags;
dispatchFlags.throttle = QueueThrottle::LOW;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -3198,6 +3230,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenDispatchFlagsWithThrottleSetT
DispatchFlags dispatchFlags;
dispatchFlags.throttle = QueueThrottle::MEDIUM;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -3228,6 +3261,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenDispatchFlagsWithThrottleSetT
DispatchFlags dispatchFlags;
dispatchFlags.throttle = QueueThrottle::HIGH;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
mockCsr->flushTask(commandStream,
0,
@@ -3255,7 +3289,8 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenMockCommandStreamerWhenAddPat
DispatchFlags dispatchFlags;
dispatchFlags.throttle = QueueThrottle::MEDIUM;
EXPECT_CALL(*mockCsr, setPatchInfoData(_)).Times(0);
EXPECT_CALL(*mockCsr, setPatchInfoData(_))
.Times(0);
mockCsr->flushTask(commandStream,
0,
@@ -3281,10 +3316,12 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenMockCommandStreamerWhenAddPat
dispatchFlags.throttle = QueueThrottle::MEDIUM;
std::vector<PatchInfoData> patchInfoDataVector;
EXPECT_CALL(*mockCsr, setPatchInfoData(_)).Times(5).WillRepeatedly(Invoke([&](PatchInfoData &data) {
patchInfoDataVector.push_back(data);
return true;
}));
EXPECT_CALL(*mockCsr, setPatchInfoData(_))
.Times(5)
.WillRepeatedly(Invoke([&](PatchInfoData &data) {
patchInfoDataVector.push_back(data);
return true;
}));
mockCsr->flushTask(commandStream,
0,
@@ -3335,10 +3372,12 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenMockCsrWhenCollectStateBaseAd
std::unique_ptr<MockCsrBase<FamilyType>> mockCsr(new MockCsrBase<FamilyType>(tag));
std::vector<PatchInfoData> patchInfoDataVector;
EXPECT_CALL(*mockCsr, setPatchInfoData(_)).Times(5).WillRepeatedly(Invoke([&](PatchInfoData &data) {
patchInfoDataVector.push_back(data);
return true;
}));
EXPECT_CALL(*mockCsr, setPatchInfoData(_))
.Times(5)
.WillRepeatedly(Invoke([&](PatchInfoData &data) {
patchInfoDataVector.push_back(data);
return true;
}));
uint64_t baseAddress = 0xabcdef;
uint64_t commandOffset = 0xa;

View File

@@ -99,6 +99,7 @@ struct UltCommandStreamReceiverTest
flushTaskFlags.blocking = block;
flushTaskFlags.requiresCoherency = requiresCoherency;
flushTaskFlags.lowPriority = lowPriority;
flushTaskFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
return commandStreamReceiver.flushTask(
commandStream,

View File

@@ -26,6 +26,7 @@
#include "runtime/helpers/preamble.h"
#include "unit_tests/preamble/preamble_fixture.h"
#include "unit_tests/gen_common/gen_cmd_parse.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
using namespace OCLRT;
@@ -75,6 +76,8 @@ SKLTEST_F(Gen9L3Config, checkSLM) {
typedef PreambleFixture ThreadArbitration;
SKLTEST_F(ThreadArbitration, givenPreambleWhenItIsProgrammedThenThreadArbitrationIsSetToRoundRobin) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForcePreemptionMode.set(static_cast<int32_t>(PreemptionMode::Disabled));
typedef SKLFamily::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM;
typedef SKLFamily::PIPE_CONTROL PIPE_CONTROL;
LinearStream &cs = linearStream;

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 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"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/helpers/built_ins_helper.h"
#include "unit_tests/mocks/mock_compilers.h"
namespace OCLRT {
const SipKernel &initSipKernel(SipKernelType type, Device &device) {
CompilerInterface::getInstance();
std::unique_ptr<MockCompilerInterface> mockCompilerInterface(new MockCompilerInterface());
mockCompilerInterface->overrideGlobalCompilerInterface();
mockCompilerInterface->sipKernelBinaryOverride = mockCompilerInterface->getDummyGenBinary();
return BuiltIns::getInstance().getSipKernel(type, device);
}
} // namespace OCLRT

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"),

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"),
@@ -31,15 +31,19 @@ class PatchedKernelTest : public ::testing::Test {
public:
void SetUp() override {
device.reset(MockDevice::create<MockDevice>(nullptr));
program.reset(Program::create("FillBufferBytes", &context, *device.get(), true, &retVal));
context.reset(new MockContext(device.get()));
program.reset(Program::create("FillBufferBytes", context.get(), *device.get(), true, &retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
cl_device_id clDevice = device.get();
program->build(1, &clDevice, nullptr, nullptr, nullptr, false);
kernel.reset(Kernel::create(program.get(), *program->getKernelInfo("FillBufferBytes"), &retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
}
void TearDown() override {
context.reset();
}
MockContext context;
std::unique_ptr<MockContext> context;
std::unique_ptr<MockDevice> device;
std::unique_ptr<Program> program;
std::unique_ptr<Kernel> kernel;
@@ -51,7 +55,7 @@ TEST_F(PatchedKernelTest, givenKernelWithoutPatchedArgsWhenIsPatchedIsCalledThen
}
TEST_F(PatchedKernelTest, givenKernelWithAllArgsSetWithBufferWhenIsPatchedIsCalledThenReturnsTrue) {
auto buffer = clCreateBuffer(&context, CL_MEM_READ_ONLY, sizeof(int), nullptr, &retVal);
auto buffer = clCreateBuffer(context.get(), CL_MEM_READ_ONLY, sizeof(int), nullptr, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
auto argsNum = kernel->getKernelArgsNumber();
for (uint32_t i = 0; i < argsNum; i++) {
@@ -62,7 +66,7 @@ TEST_F(PatchedKernelTest, givenKernelWithAllArgsSetWithBufferWhenIsPatchedIsCall
}
TEST_F(PatchedKernelTest, givenKernelWithoutAllArgsSetWhenIsPatchedIsCalledThenReturnsFalse) {
auto buffer = clCreateBuffer(&context, CL_MEM_READ_ONLY, sizeof(int), nullptr, &retVal);
auto buffer = clCreateBuffer(context.get(), CL_MEM_READ_ONLY, sizeof(int), nullptr, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
auto argsNum = kernel->getKernelArgsNumber();
for (uint32_t i = 0; i < argsNum; i++) {
@@ -99,7 +103,7 @@ TEST_F(PatchedKernelTest, givenKernelWithAllArgsSetWithSvmWhenIsPatchedIsCalledT
TEST_F(PatchedKernelTest, givenKernelWithOneArgumentToPatchWhichIsNonzeroIndexedWhenThatArgumentIsSetThenKernelIsPatched) {
uint32_t size = sizeof(int);
MockKernelWithInternals mockKernel(*device.get(), &context);
MockKernelWithInternals mockKernel(*device.get(), context.get());
EXPECT_EQ(0u, mockKernel.kernelInfo.argumentsToPatchNum);
mockKernel.kernelInfo.storeKernelArgPatchInfo(1, 0, 0, 0, 0);
EXPECT_EQ(1u, mockKernel.kernelInfo.argumentsToPatchNum);

View File

@@ -38,11 +38,14 @@ apply_macro_for_each_gen("TESTED")
set(IGDRCL_SRCS_LIB_ULT
${IGDRCL_SOURCE_DIR}/unit_tests/abort.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/libult/create_tbx_sockets.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/libult/ult_command_stream_receiver.h
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/built_ins_helper.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/debug_helpers.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/memory_management.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/memory_management.h
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/test_files.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/test_files.h
${IGDRCL_SOURCE_DIR}/unit_tests/libult/create_tbx_sockets.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/libult/ult_command_stream_receiver.h
${IGDRCL_SOURCE_DIR}/unit_tests/program/evaluate_unhandled_token_ult.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_gfx_family.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_gfx_family.cpp
@@ -92,8 +95,6 @@ set(IGDRCL_SRCS_LIB_ULT_ENV
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/kernel_binary_helper.h
${IGDRCL_SOURCE_DIR}/unit_tests/indirect_heap/indirect_heap_fixture.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/indirect_heap/indirect_heap_fixture.h
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/test_files.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/test_files.h
)
add_library (igdrcl_libult_env OBJECT
${IGDRCL_SRCS_LIB_ULT_ENV}

View File

@@ -67,6 +67,10 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily> {
this->tagAllocation = tempTagLocation;
this->tagAddress = reinterpret_cast<uint32_t *>(tempTagLocation->getUnderlyingBuffer());
this->storeMakeResidentAllocations = false;
if (hwInfoIn.capabilityTable.defaultPreemptionMode == PreemptionMode::MidThread) {
tempPreemptionLocation = new GraphicsAllocation(nullptr, 0);
this->preemptionCsrAllocation = tempPreemptionLocation;
}
}
virtual MemoryManager *createMemoryManager(bool enable64kbPages) override {
@@ -112,12 +116,17 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily> {
using BaseClass::CommandStreamReceiver::waitForTaskCountAndCleanAllocationList;
GraphicsAllocation *tempTagLocation;
GraphicsAllocation *tempPreemptionLocation = nullptr;
};
template <typename GfxFamily>
UltCommandStreamReceiver<GfxFamily>::~UltCommandStreamReceiver() {
this->setTagAllocation(nullptr);
delete tempTagLocation;
if (tempPreemptionLocation) {
this->setPreemptionCsrAllocation(nullptr);
delete tempPreemptionLocation;
}
}
} // namespace OCLRT

View File

@@ -27,6 +27,7 @@
#include "helpers/test_files.h"
#include "unit_tests/memory_leak_listener.h"
#include "unit_tests/mocks/mock_gmm.h"
#include "unit_tests/mocks/mock_sip.h"
#include "runtime/gmm_helper/resource_info.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "gmock/gmock.h"
@@ -138,10 +139,12 @@ void initializeTestHelpers() {
auto initialized = Gmm::initContext(hwinfo->pPlatform, hwinfo->pSkuTable,
hwinfo->pWaTable, hwinfo->pSysInfo);
ASSERT_TRUE(initialized);
MockSipKernel::initDummyBinary();
}
void cleanTestHelpers() {
Gmm::destroyContext();
MockSipKernel::shutDown();
}
std::string getHardwarePrefix() {

View File

@@ -225,17 +225,16 @@ class BufferTest : public DeviceFixture,
void SetUp() override {
flags = GetParam();
DeviceFixture::SetUp();
contextMemoryManager = context.getMemoryManager();
context.setMemoryManager(pDevice->getMemoryManager());
context.reset(new MockContext(pDevice));
}
void TearDown() override {
context.setMemoryManager(contextMemoryManager);
context.reset();
DeviceFixture::TearDown();
}
cl_int retVal = CL_SUCCESS;
MockContext context;
std::unique_ptr<MockContext> context;
MemoryManager *contextMemoryManager;
cl_mem_flags flags = 0;
unsigned char pHostPtr[g_scTestBufferSizeInBytes];
@@ -245,7 +244,7 @@ typedef BufferTest NoHostPtr;
TEST_P(NoHostPtr, ValidFlags) {
auto buffer = Buffer::create(
&context,
context.get(),
flags,
g_scTestBufferSizeInBytes,
nullptr,
@@ -279,7 +278,7 @@ TEST_P(NoHostPtr, GivenNoHostPtrWhenHwBufferCreationFailsThenReturnNullptr) {
}
auto buffer = Buffer::create(
&context,
context.get(),
flags,
g_scTestBufferSizeInBytes,
nullptr,
@@ -294,7 +293,7 @@ TEST_P(NoHostPtr, GivenNoHostPtrWhenHwBufferCreationFailsThenReturnNullptr) {
TEST_P(NoHostPtr, completionStamp) {
auto buffer = Buffer::create(
&context,
context.get(),
flags,
g_scTestBufferSizeInBytes,
nullptr,
@@ -325,7 +324,7 @@ TEST_P(NoHostPtr, completionStamp) {
TEST_P(NoHostPtr, WithUseHostPtr_returnsError) {
auto buffer = Buffer::create(
&context,
context.get(),
flags | CL_MEM_USE_HOST_PTR,
g_scTestBufferSizeInBytes,
nullptr,
@@ -338,7 +337,7 @@ TEST_P(NoHostPtr, WithUseHostPtr_returnsError) {
TEST_P(NoHostPtr, WithCopyHostPtr_returnsError) {
auto buffer = Buffer::create(
&context,
context.get(),
flags | CL_MEM_COPY_HOST_PTR,
g_scTestBufferSizeInBytes,
nullptr,
@@ -351,7 +350,7 @@ TEST_P(NoHostPtr, WithCopyHostPtr_returnsError) {
TEST_P(NoHostPtr, withBufferGraphicsAllocationReportsBufferType) {
auto buffer = Buffer::create(
&context,
context.get(),
flags,
g_scTestBufferSizeInBytes,
nullptr,
@@ -417,7 +416,7 @@ struct ValidHostPtr
Buffer *createBuffer() {
return Buffer::create(
&context,
context.get(),
flags,
g_scTestBufferSizeInBytes,
pHostPtr,
@@ -475,7 +474,7 @@ TEST_P(ValidHostPtr, getSize) {
TEST_P(ValidHostPtr, givenValidHostPtrParentFlagsWhenSubBufferIsCreatedWithZeroFlagsThenItCreatesSuccesfuly) {
auto retVal = CL_SUCCESS;
auto clBuffer = clCreateBuffer(&context,
auto clBuffer = clCreateBuffer(context.get(),
flags,
g_scTestBufferSizeInBytes,
pHostPtr,
@@ -498,7 +497,7 @@ TEST_P(ValidHostPtr, givenValidHostPtrParentFlagsWhenSubBufferIsCreatedWithZeroF
}
TEST_P(ValidHostPtr, givenValidHostPtrParentFlagsWhenSubBufferIsCreatedWithParentFlagsThenItIsCreatedSuccesfuly) {
auto retVal = CL_SUCCESS;
auto clBuffer = clCreateBuffer(&context,
auto clBuffer = clCreateBuffer(context.get(),
flags,
g_scTestBufferSizeInBytes,
pHostPtr,
@@ -547,7 +546,7 @@ TEST_P(ValidHostPtr, givenValidHostPtrParentFlagsWhenSubBufferIsCreatedWithInval
return;
}
auto clBuffer = clCreateBuffer(&context,
auto clBuffer = clCreateBuffer(context.get(),
flags,
g_scTestBufferSizeInBytes,
pHostPtr,
@@ -589,15 +588,15 @@ TEST_P(ValidHostPtr, failedAllocationInjection) {
TEST_P(ValidHostPtr, SvmHostPtr) {
const DeviceInfo &devInfo = pPlatform->getDevice(0)->getDeviceInfo();
if (devInfo.svmCapabilities != 0) {
auto ptr = clSVMAlloc(&context, CL_MEM_READ_WRITE, 64, 64);
auto ptr = clSVMAlloc(context.get(), CL_MEM_READ_WRITE, 64, 64);
auto bufferSvm = Buffer::create(&context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, 64, ptr, retVal);
auto bufferSvm = Buffer::create(context.get(), CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, 64, ptr, retVal);
EXPECT_NE(nullptr, bufferSvm);
EXPECT_TRUE(bufferSvm->isMemObjWithHostPtrSVM());
EXPECT_EQ(context.getSVMAllocsManager()->getSVMAlloc(ptr), bufferSvm->getGraphicsAllocation());
EXPECT_EQ(context->getSVMAllocsManager()->getSVMAlloc(ptr), bufferSvm->getGraphicsAllocation());
EXPECT_EQ(CL_SUCCESS, retVal);
clSVMFree(&context, ptr);
clSVMFree(context.get(), ptr);
delete bufferSvm;
}
}

View File

@@ -43,16 +43,21 @@ void CL_CALLBACK emptyDestructorCallback(cl_mem memObj, void *userData) {
class MemObjDestructionTest : public ::testing::TestWithParam<bool> {
public:
void SetUp() override {
context.reset(new MockContext());
memoryManager = new MockMemoryManager;
device = static_cast<MockDevice *>(context.getDevice(0));
device = static_cast<MockDevice *>(context->getDevice(0));
device->injectMemoryManager(memoryManager);
context.setMemoryManager(memoryManager);
context->setMemoryManager(memoryManager);
allocation = memoryManager->allocateGraphicsMemory(size, MemoryConstants::pageSize);
memObj = new MemObj(&context, CL_MEM_OBJECT_BUFFER,
memObj = new MemObj(context.get(), CL_MEM_OBJECT_BUFFER,
CL_MEM_READ_WRITE,
size,
nullptr, nullptr, allocation, true, false, false);
*context.getDevice(0)->getTagAddress() = 0;
*context->getDevice(0)->getTagAddress() = 0;
}
void TearDown() override {
context.reset();
}
void makeMemObjUsed() {
@@ -61,17 +66,17 @@ class MemObjDestructionTest : public ::testing::TestWithParam<bool> {
void makeMemObjNotReady() {
makeMemObjUsed();
*context.getDevice(0)->getTagAddress() = memObj->getGraphicsAllocation()->taskCount - 1;
*context->getDevice(0)->getTagAddress() = memObj->getGraphicsAllocation()->taskCount - 1;
}
void makeMemObjReady() {
makeMemObjUsed();
*context.getDevice(0)->getTagAddress() = memObj->getGraphicsAllocation()->taskCount;
*context->getDevice(0)->getTagAddress() = memObj->getGraphicsAllocation()->taskCount;
}
MockDevice *device;
MockMemoryManager *memoryManager;
MockContext context;
std::unique_ptr<MockContext> context;
GraphicsAllocation *allocation;
MemObj *memObj;
size_t size = MemoryConstants::pageSize;
@@ -140,12 +145,15 @@ HWTEST_P(MemObjAsyncDestructionTest, givenUsedMemObjWithAsyncDestructionsEnabled
auto waitForCompletionWithTimeoutMock = [=](bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait) -> bool { return desired; };
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_))
.WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
if (hasCallbacks) {
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, TimeoutControls::maxTimeout, allocation->taskCount)).Times(1);
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, TimeoutControls::maxTimeout, allocation->taskCount))
.Times(1);
} else {
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_)).Times(0);
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_))
.Times(0);
}
delete memObj;
}
@@ -167,12 +175,15 @@ HWTEST_P(MemObjAsyncDestructionTest, givenUsedMemObjWithAsyncDestructionsEnabled
auto waitForCompletionWithTimeoutMock = [=](bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait) -> bool { return desired; };
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_))
.WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
if (hasAllocatedMappedPtr) {
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, TimeoutControls::maxTimeout, allocation->taskCount)).Times(1);
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, TimeoutControls::maxTimeout, allocation->taskCount))
.Times(1);
} else {
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_)).Times(0);
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_))
.Times(0);
}
delete memObj;
}
@@ -188,7 +199,7 @@ HWTEST_P(MemObjAsyncDestructionTest, givenUsedMemObjWithAsyncDestructionsEnabled
MemObjOffsetArray origin = {{0, 0, 0}};
MemObjSizeArray region = {{1, 1, 1}};
cl_map_flags mapFlags = CL_MAP_READ;
memObj = new MemObj(&context, CL_MEM_OBJECT_BUFFER,
memObj = new MemObj(context.get(), CL_MEM_OBJECT_BUFFER,
CL_MEM_READ_WRITE,
size,
storage, nullptr, allocation, true, false, false);
@@ -205,12 +216,15 @@ HWTEST_P(MemObjAsyncDestructionTest, givenUsedMemObjWithAsyncDestructionsEnabled
auto waitForCompletionWithTimeoutMock = [=](bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait) -> bool { return desired; };
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_))
.WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
if (hasAllocatedMappedPtr) {
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, TimeoutControls::maxTimeout, allocation->taskCount)).Times(1);
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, TimeoutControls::maxTimeout, allocation->taskCount))
.Times(1);
} else {
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_)).Times(0);
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_))
.Times(0);
}
delete memObj;
@@ -235,9 +249,11 @@ HWTEST_P(MemObjSyncDestructionTest, givenMemObjWithDestructableAllocationWhenAsy
auto waitForCompletionWithTimeoutMock = [=](bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait) -> bool { return desired; };
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_))
.WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, TimeoutControls::maxTimeout, allocation->taskCount)).Times(1);
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, TimeoutControls::maxTimeout, allocation->taskCount))
.Times(1);
delete memObj;
}
@@ -258,7 +274,8 @@ HWTEST_P(MemObjSyncDestructionTest, givenMemObjWithDestructableAllocationWhenAsy
auto waitForCompletionWithTimeoutMock = [=](bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait) -> bool { return desired; };
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_))
.WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
delete memObj;
EXPECT_TRUE(memoryManager->isAllocationListEmpty());

View File

@@ -56,6 +56,8 @@ set(IGDRCL_SRCS_tests_mocks
${CMAKE_CURRENT_SOURCE_DIR}/mock_program.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_program.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_sampler.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_sip.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_sip.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_submissions_aggregator.h
)

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,7 @@
#include "runtime/helpers/options.h"
#include "runtime/os_interface/os_inc_base.h"
#include "unit_tests/helpers/test_files.h"
#include "unit_tests/mocks/mock_sip.h"
#include "ocl_igc_interface/igc_ocl_device_ctx.h"
@@ -112,7 +113,7 @@ void MockCompilerEnableGuard::Disable() {
enabled = false;
}
}
}
} // namespace OCLRT
namespace IGC {
@@ -313,7 +314,7 @@ IGC::FclOclTranslationCtxBase *CIF_GET_INTERFACE_CLASS(FclOclDeviceCtx, 1)::Crea
IGC::CodeType::CodeType_t outType) {
return nullptr;
}
}
} // namespace IGC
#include "cif/macros/disable.h"
@@ -513,15 +514,6 @@ IGC::FclOclTranslationCtxBase *MockFclOclDeviceCtx::CreateTranslationCtxImpl(CIF
}
std::vector<char> MockCompilerInterface::getDummyGenBinary() {
std::string testFile(testFiles);
testFile.append("CopyBuffer_simd8_");
testFile.append(hardwarePrefix[platformDevices[0]->pPlatform->eProductFamily]);
testFile.append(".gen");
void *binary = nullptr;
auto binarySize = loadDataFromFile(testFile.c_str(), binary);
std::vector<char> ret{reinterpret_cast<char *>(binary), reinterpret_cast<char *>(binary) + binarySize};
deleteDataReadFromFile(binary);
return ret;
}
return MockSipKernel::getDummyGenBinary();
}
} // namespace OCLRT

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 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"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/helpers/file_io.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/options.h"
#include "runtime/os_interface/os_inc_base.h"
#include "unit_tests/helpers/test_files.h"
#include "unit_tests/mocks/mock_sip.h"
#include "unit_tests/mocks/mock_compilers.h"
#include "ocl_igc_interface/igc_ocl_device_ctx.h"
#include <fstream>
#include <map>
#include "cif/macros/enable.h"
namespace OCLRT {
std::vector<char> MockSipKernel::dummyBinaryForSip;
std::vector<char> MockSipKernel::getDummyGenBinary() {
if (dummyBinaryForSip.size() == 0) {
dummyBinaryForSip = getBinary();
}
return dummyBinaryForSip;
}
std::vector<char> MockSipKernel::getBinary() {
std::string testFile(testFiles);
testFile.append("CopyBuffer_simd8_");
testFile.append(hardwarePrefix[platformDevices[0]->pPlatform->eProductFamily]);
testFile.append(".gen");
void *binary = nullptr;
auto binarySize = loadDataFromFile(testFile.c_str(), binary);
std::vector<char> ret{reinterpret_cast<char *>(binary), reinterpret_cast<char *>(binary) + binarySize};
deleteDataReadFromFile(binary);
return ret;
}
void MockSipKernel::initDummyBinary() {
dummyBinaryForSip = getBinary();
}
void MockSipKernel::shutDown() {
MockSipKernel::dummyBinaryForSip.clear();
}
} // namespace OCLRT

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 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"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/built_ins/sip.h"
#include <vector>
namespace OCLRT {
class MockSipKernel : public SipKernel {
public:
static std::vector<char> dummyBinaryForSip;
static std::vector<char> getDummyGenBinary();
static std::vector<char> getBinary();
static void initDummyBinary();
static void shutDown();
};
} // namespace OCLRT

View File

@@ -21,9 +21,9 @@
*/
#include "hw_cmds.h"
#include "runtime/command_stream/command_stream_receiver_hw.inl"
#include "runtime/command_stream/device_command_stream.h"
#include "runtime/command_stream/linear_stream.h"
#include "runtime/command_stream/preemption.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/options.h"
#include "runtime/mem_obj/buffer.h"
@@ -66,7 +66,8 @@ class DrmCommandStreamFixture {
ASSERT_NE(nullptr, csr);
// Memory manager creates pinBB with ioctl, expect one call
EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_)).Times(1);
EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_))
.Times(1);
mm = csr->createMemoryManager(false);
::testing::Mock::VerifyAndClearExpectations(mock);
@@ -79,7 +80,8 @@ class DrmCommandStreamFixture {
::testing::Mock::VerifyAndClearExpectations(mock);
delete csr;
// Memory manager closes pinBB with ioctl, expect one call
EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_)).Times(::testing::AtLeast(1));
EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_))
.Times(::testing::AtLeast(1));
delete mm;
delete this->mock;
this->mock = 0;
@@ -102,7 +104,9 @@ TEST_F(DrmCommandStreamTest, givenFlushStampWhenWaitCalledThenWaitForSpecifiedBo
expectedWait.bo_handle = static_cast<uint32_t>(handleToWait);
expectedWait.timeout_ns = -1;
EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_)).Times(1).WillRepeatedly(copyIoctlParam(&calledWait));
EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
.Times(1)
.WillRepeatedly(copyIoctlParam(&calledWait));
csr->waitForFlushStamp(handleToWait);
EXPECT_TRUE(memcmp(&expectedWait, &calledWait, sizeof(drm_i915_gem_wait)) == 0);
@@ -935,7 +939,25 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenDrmCsrCreatedWithInactiveGemCloseWor
EXPECT_EQ(gemCloseWorkerMode::gemCloseWorkerInactive, testedCsr.peekGemCloseWorkerOperationMode());
}
typedef Test<DrmCommandStreamEnhancedFixture> DrmCommandStreamBatchingTests;
class DrmCommandStreamBatchingTests : public Test<DrmCommandStreamEnhancedFixture> {
public:
DrmAllocation *tagAllocation;
DrmAllocation *preemptionAllocation = nullptr;
void SetUp() override {
DrmCommandStreamEnhancedFixture::SetUp();
tagAllocation = mm->allocateGraphicsMemory(1024, 4096);
if (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) {
preemptionAllocation = mm->allocateGraphicsMemory(1024, 4096);
}
}
void TearDown() override {
if (preemptionAllocation) {
mm->freeGraphicsMemory(preemptionAllocation);
}
mm->freeGraphicsMemory(tagAllocation);
DrmCommandStreamEnhancedFixture::TearDown();
}
};
TEST_F(DrmCommandStreamBatchingTests, givenCSRWhenFlushIsCalledThenProperFlagsArePassed) {
tCsr->overrideGemCloseWorkerOperationMode(gemCloseWorkerMode::gemCloseWorkerInactive);
@@ -952,7 +974,10 @@ TEST_F(DrmCommandStreamBatchingTests, givenCSRWhenFlushIsCalledThenProperFlagsAr
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr);
EXPECT_EQ(4, this->mock->ioctl_cnt.total);
//preemption allocation in Mid Thread preemption mode
int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 1 : 0;
EXPECT_EQ(5 + ioctlExtraCnt, this->mock->ioctl_cnt.total);
uint64_t flags = I915_EXEC_RENDER | I915_EXEC_NO_RELOC;
EXPECT_EQ(flags, this->mock->execBuffer.flags);
@@ -969,7 +994,6 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT
auto commandBuffer = mm->allocateGraphicsMemory(1024, 4096);
auto dummyAllocation = mm->allocateGraphicsMemory(1024, 4096);
auto tagAllocation = mm->allocateGraphicsMemory(1024, 4096);
ASSERT_NE(nullptr, commandBuffer);
ASSERT_EQ(0u, reinterpret_cast<uintptr_t>(commandBuffer->getUnderlyingBuffer()) & 0xFFF);
LinearStream cs(commandBuffer);
@@ -981,7 +1005,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT
tCsr->getMemoryManager()->device = device.get();
tCsr->setTagAllocation(tagAllocation);
tCsr->setPreemptionCsrAllocation(preemptionAllocation);
DispatchFlags dispatchFlags;
tCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags);
@@ -990,8 +1014,14 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT
EXPECT_FALSE(cmdBuffers.peekIsEmpty());
EXPECT_NE(nullptr, cmdBuffers.peekHead());
//preemption allocation
size_t csrSurfaceCount = (tCsr->getMemoryManager()->device->getPreemptionMode() == PreemptionMode::MidThread) ? 1 : 0;
//preemption allocation in Mid Thread preemption mode
int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 1 : 0;
auto recordedCmdBuffer = cmdBuffers.peekHead();
EXPECT_EQ(3u, recordedCmdBuffer->surfaces.size());
EXPECT_EQ(3u + csrSurfaceCount, recordedCmdBuffer->surfaces.size());
//try to find all allocations
auto elementInVector = std::find(recordedCmdBuffer->surfaces.begin(), recordedCmdBuffer->surfaces.end(), dummyAllocation);
@@ -1005,14 +1035,14 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT
EXPECT_EQ(tCsr->commandStream.getGraphicsAllocation(), recordedCmdBuffer->batchBuffer.commandBufferAllocation);
EXPECT_EQ(5, this->mock->ioctl_cnt.total);
EXPECT_EQ(5 + ioctlExtraCnt, this->mock->ioctl_cnt.total);
EXPECT_EQ(0u, this->mock->execBuffer.flags);
mm->freeGraphicsMemory(dummyAllocation);
mm->freeGraphicsMemory(commandBuffer);
mm->freeGraphicsMemory(tagAllocation);
tCsr->setTagAllocation(nullptr);
tCsr->setPreemptionCsrAllocation(nullptr);
}
TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmittedThenFlushTaskIsProperlyCalled) {
@@ -1024,12 +1054,12 @@ TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmitte
auto commandBuffer = mm->allocateGraphicsMemory(1024, 4096);
auto dummyAllocation = mm->allocateGraphicsMemory(1024, 4096);
auto tagAllocation = mm->allocateGraphicsMemory(1024, 4096);
LinearStream cs(commandBuffer);
std::unique_ptr<Device> device(DeviceHelper<>::create(nullptr));
tCsr->getMemoryManager()->device = device.get();
tCsr->setTagAllocation(tagAllocation);
tCsr->setPreemptionCsrAllocation(preemptionAllocation);
auto &submittedCommandBuffer = tCsr->getCS(1024);
//use some bytes
submittedCommandBuffer.getSpace(4);
@@ -1051,8 +1081,14 @@ TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmitte
auto commandBufferGraphicsAllocation = submittedCommandBuffer.getGraphicsAllocation();
EXPECT_FALSE(commandBufferGraphicsAllocation->isResident());
//preemption allocation
size_t csrSurfaceCount = (tCsr->getMemoryManager()->device->getPreemptionMode() == PreemptionMode::MidThread) ? 1 : 0;
//preemption allocation in Mid Thread preemption mode
int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 1 : 0;
//validate that submited command buffer has what we want
EXPECT_EQ(3u, this->mock->execBuffer.buffer_count);
EXPECT_EQ(3u + csrSurfaceCount, this->mock->execBuffer.buffer_count);
EXPECT_EQ(4u, this->mock->execBuffer.batch_start_offset);
EXPECT_EQ(submittedCommandBuffer.getUsed(), this->mock->execBuffer.batch_len);
@@ -1071,12 +1107,12 @@ TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmitte
EXPECT_TRUE(handleFound);
}
EXPECT_EQ(6, this->mock->ioctl_cnt.total);
EXPECT_EQ(6 + ioctlExtraCnt, this->mock->ioctl_cnt.total);
mm->freeGraphicsMemory(dummyAllocation);
mm->freeGraphicsMemory(commandBuffer);
mm->freeGraphicsMemory(tagAllocation);
tCsr->setTagAllocation(nullptr);
tCsr->setPreemptionCsrAllocation(nullptr);
}
typedef Test<DrmCommandStreamEnhancedFixture> DrmCommandStreamLeaksTest;

View File

@@ -29,6 +29,7 @@
#include "runtime/command_stream/aub_command_stream_receiver.h"
#include "runtime/command_stream/device_command_stream.h"
#include "runtime/command_stream/linear_stream.h"
#include "runtime/command_stream/preemption.h"
#include "runtime/helpers/options.h"
#include "runtime/gen_common/hw_cmds.h"
#include "runtime/memory_manager/memory_manager.h"
@@ -99,6 +100,7 @@ class WddmCommandStreamWithMockGdiFixture : public WddmFixture {
MockGdi gdi;
DebugManagerStateRestore stateRestore;
GraphicsAllocation *tagAllocation;
GraphicsAllocation *preemptionAllocation = nullptr;
void SetUp() {
WddmFixture::SetUp(&gdi);
@@ -115,12 +117,18 @@ class WddmCommandStreamWithMockGdiFixture : public WddmFixture {
memManager->device = device;
tagAllocation = memManager->allocateGraphicsMemory(1024, 4096);
if (device->getPreemptionMode() == PreemptionMode::MidThread) {
preemptionAllocation = memManager->allocateGraphicsMemory(1024, 4096);
}
auto tagBuffer = (uint32_t *)tagAllocation->getUnderlyingBuffer();
tagBuffer[0] = initialHardwareTag;
}
void TearDown() {
memManager->freeGraphicsMemory(tagAllocation);
if (preemptionAllocation) {
memManager->freeGraphicsMemory(preemptionAllocation);
}
delete csr->getTagAddress();
delete csr;
delete memManager;
@@ -673,6 +681,7 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
auto sshAlloc = memManager->allocateGraphicsMemory(1024, 4096);
mockCsr->setTagAllocation(tagAllocation);
mockCsr->setPreemptionCsrAllocation(preemptionAllocation);
LinearStream cs(commandBuffer);
LinearStream dsh(dshAlloc);
@@ -694,11 +703,14 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
EXPECT_TRUE(cmdBuffers.peekIsEmpty());
//preemption allocation
size_t csrSurfaceCount = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 1 : 0;
EXPECT_EQ(1u, mockWddm->submitResult.called);
auto csrCommandStream = mockCsr->commandStream.getGraphicsAllocation();
EXPECT_EQ(reinterpret_cast<uint64_t>(csrCommandStream->getUnderlyingBuffer()), mockWddm->submitResult.commandBufferSubmitted);
EXPECT_TRUE(((COMMAND_BUFFER_HEADER *)mockWddm->submitResult.commandHeaderSubmitted)->RequiresCoherency);
EXPECT_EQ(6u, mockWddm->makeResidentResult.handleCount);
EXPECT_EQ(6u + csrSurfaceCount, mockWddm->makeResidentResult.handleCount);
std::vector<D3DKMT_HANDLE> expectedHandles;
expectedHandles.push_back(((WddmAllocation *)tagAllocation)->handle);
@@ -812,7 +824,7 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTra
auto mockMngr = reinterpret_cast<MockGmmPageTableMngr *>(myMockWddm->getPageTableManager());
mockWddmCsr.setMemoryManager(memManager);
mockWddmCsr.setTagAllocation(tagAllocation);
mockWddmCsr.setPreemptionCsrAllocation(preemptionAllocation);
auto &csrCS = mockWddmCsr.getCS();
auto graphicsAllocation = memManager->allocateGraphicsMemory(1024, 4096);
@@ -820,8 +832,12 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTra
EXPECT_FALSE(mockWddmCsr.pageTableManagerInitialized);
EXPECT_CALL(*mockMngr, initContextAuxTableRegister(&mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS)).Times(1).WillOnce(Return(GMM_SUCCESS));
EXPECT_CALL(*mockMngr, initContextTRTableRegister(&mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS)).Times(1).WillOnce(Return(GMM_SUCCESS));
EXPECT_CALL(*mockMngr, initContextAuxTableRegister(&mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS))
.Times(1)
.WillOnce(Return(GMM_SUCCESS));
EXPECT_CALL(*mockMngr, initContextTRTableRegister(&mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS))
.Times(1)
.WillOnce(Return(GMM_SUCCESS));
DispatchFlags dispatchFlags;
mockWddmCsr.flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags);
@@ -844,6 +860,7 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontIn
mockWddmCsr.setMemoryManager(memManager);
mockWddmCsr.setTagAllocation(tagAllocation);
mockWddmCsr.setPreemptionCsrAllocation(preemptionAllocation);
auto graphicsAllocation = memManager->allocateGraphicsMemory(1024, 4096);
LinearStream cs(graphicsAllocation);