Initial commit

Change-Id: I4bf1707bd3dfeadf2c17b0a7daff372b1925ebbd
This commit is contained in:
Brandon Fliflet
2017-12-21 00:45:38 +01:00
commit 7e9ad41290
1350 changed files with 233156 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
# Copyright (c) 2017, 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.
set(IGDRCL_SRCS_tests_command_stream
"${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt"
"${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_tests.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/command_stream_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_hw_tests.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_tests.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/cmd_parse_tests.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/linear_stream_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/linear_stream_tests.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/submissions_aggregator_tests.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/tbx_command_stream_fixture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/tbx_command_stream_fixture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/tbx_command_stream_tests.cpp"
PARENT_SCOPE
)

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 2017, 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/command_stream/aub_command_stream_receiver_hw.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/memory_manager/memory_manager.h"
#include "test.h"
#include "unit_tests/fixtures/device_fixture.h"
using OCLRT::AUBCommandStreamReceiver;
using OCLRT::AUBCommandStreamReceiverHw;
using OCLRT::BatchBuffer;
using OCLRT::CommandStreamReceiver;
using OCLRT::GraphicsAllocation;
using OCLRT::HardwareInfo;
using OCLRT::LinearStream;
using OCLRT::MemoryManager;
using OCLRT::ObjectNotResident;
using OCLRT::platformDevices;
typedef Test<DeviceFixture> AubCommandStreamReceiverTests;
TEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCreatedWithWrongGfxCoreFamilyThenNullPointerShouldBeReturned) {
HardwareInfo hwInfo = *platformDevices[0];
GFXCORE_FAMILY family = hwInfo.pPlatform->eRenderCoreFamily;
const_cast<PLATFORM *>(hwInfo.pPlatform)->eRenderCoreFamily = GFXCORE_FAMILY_FORCE_ULONG; // wrong gfx core family
CommandStreamReceiver *csr = AUBCommandStreamReceiver::create(hwInfo, "");
EXPECT_EQ(nullptr, csr);
const_cast<PLATFORM *>(hwInfo.pPlatform)->eRenderCoreFamily = family;
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCreatedThenMemoryManagerIsNotNull) {
HardwareInfo hwInfo;
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(new AUBCommandStreamReceiverHw<FamilyType>(hwInfo));
std::unique_ptr<MemoryManager> memoryManager(aubCsr->createMemoryManager(false));
EXPECT_NE(nullptr, memoryManager.get());
aubCsr->setMemoryManager(nullptr);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWhenMakeResidentCalledMultipleTimesAffectsResidencyOnce) {
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(new AUBCommandStreamReceiverHw<FamilyType>(*platformDevices[0]));
std::unique_ptr<MemoryManager> memoryManager(aubCsr->createMemoryManager(false));
auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false);
// First makeResident marks the allocation resident
aubCsr->makeResident(*gfxAllocation);
EXPECT_NE(ObjectNotResident, gfxAllocation->residencyTaskCount);
EXPECT_EQ((int)aubCsr->peekTaskCount(), gfxAllocation->residencyTaskCount);
EXPECT_EQ(1u, memoryManager->getResidencyAllocations().size());
// Second makeResident should have no impact
aubCsr->makeResident(*gfxAllocation);
EXPECT_NE(ObjectNotResident, gfxAllocation->residencyTaskCount);
EXPECT_EQ((int)aubCsr->peekTaskCount(), gfxAllocation->residencyTaskCount);
EXPECT_EQ(1u, memoryManager->getResidencyAllocations().size());
// First makeNonResident marks the allocation as nonresident
aubCsr->makeNonResident(*gfxAllocation);
EXPECT_EQ(ObjectNotResident, gfxAllocation->residencyTaskCount);
EXPECT_EQ(1u, memoryManager->getEvictionAllocations().size());
// Second makeNonResident should have no impact
aubCsr->makeNonResident(*gfxAllocation);
EXPECT_EQ(ObjectNotResident, gfxAllocation->residencyTaskCount);
EXPECT_EQ(1u, memoryManager->getEvictionAllocations().size());
memoryManager->freeGraphicsMemoryImpl(gfxAllocation);
aubCsr->setMemoryManager(nullptr);
}
HWTEST_F(AubCommandStreamReceiverTests, flushShouldLeaveProperRingTailAlignment) {
auto csr = new AUBCommandStreamReceiverHw<FamilyType>(*platformDevices[0]);
auto mm = csr->createMemoryManager(false);
GraphicsAllocation *commandBuffer = mm->allocateGraphicsMemory(4096, 4096);
ASSERT_NE(nullptr, commandBuffer);
LinearStream cs(commandBuffer);
auto engineOrdinal = OCLRT::ENGINE_RCS;
auto ringTailAlignment = sizeof(uint64_t);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, false, false, cs.getUsed(), &cs};
// First flush typically includes a preamble and chain to command buffer
csr->flush(batchBuffer, engineOrdinal, nullptr);
EXPECT_EQ(0ull, csr->engineInfoTable[engineOrdinal].tailRingBuffer % ringTailAlignment);
// Second flush should just submit command buffer
cs.getSpace(sizeof(uint64_t));
csr->flush(batchBuffer, engineOrdinal, nullptr);
EXPECT_EQ(0ull, csr->engineInfoTable[engineOrdinal].tailRingBuffer % ringTailAlignment);
mm->freeGraphicsMemory(commandBuffer);
delete csr;
delete mm;
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2017, 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 "unit_tests/gen_common/gen_cmd_parse.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "test.h"
using namespace OCLRT;
struct CommandParse
: public DeviceFixture,
public ::testing::Test {
void SetUp() override {
DeviceFixture::SetUp();
}
void TearDown() override {
DeviceFixture::TearDown();
}
};
HWTEST_F(CommandParse, parseCommandBufferWithNULLBuffer) {
typedef typename FamilyType::PARSE PARSE;
GenCmdList cmds;
EXPECT_FALSE(PARSE::parseCommandBuffer(cmds, nullptr, sizeof(void *)));
}
HWTEST_F(CommandParse, parseCommandBufferWithGarbage) {
typedef typename FamilyType::PARSE PARSE;
uint32_t buffer = 0xbaadf00d;
GenCmdList cmds;
EXPECT_FALSE(PARSE::parseCommandBuffer(cmds, &buffer, sizeof(buffer)));
}
HWTEST_F(CommandParse, getCommandLengthWithGarbage) {
typedef typename FamilyType::PARSE PARSE;
uint32_t buffer = 0xbaadf00d;
EXPECT_EQ(0u, PARSE::getCommandLength(&buffer));
}
HWTEST_F(CommandParse, parseCommandBufferWithLength) {
typedef typename FamilyType::PARSE PARSE;
typedef typename FamilyType::GPGPU_WALKER GPGPU_WALKER;
GenCmdList cmds;
GPGPU_WALKER buffer = GPGPU_WALKER::sInit();
EXPECT_TRUE(PARSE::parseCommandBuffer(cmds, &buffer, 0));
EXPECT_FALSE(PARSE::parseCommandBuffer(cmds, &buffer, 1));
EXPECT_FALSE(PARSE::parseCommandBuffer(cmds, &buffer, 2));
EXPECT_FALSE(PARSE::parseCommandBuffer(cmds, &buffer, 3));
EXPECT_FALSE(PARSE::parseCommandBuffer(cmds, &buffer, 4));
EXPECT_TRUE(PARSE::parseCommandBuffer(cmds, &buffer, sizeof(buffer)));
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2017, 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/command_queue/command_queue.h"
#include <cstdint>
namespace OCLRT {
struct CommandStreamFixture {
CommandStreamFixture(void)
: pCS(nullptr),
pCmdBuffer(nullptr) {
}
void SetUp(CommandQueue *pCmdQ) {
pCS = &pCmdQ->getCS();
pCmdBuffer = pCS->getBase();
}
virtual void TearDown(void) {
}
LinearStream *pCS;
void *pCmdBuffer;
};
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,206 @@
/*
* Copyright (c) 2017, 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/command_stream/linear_stream.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/command_stream/thread_arbitration_policy.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/memory_manager/graphics_allocation.h"
#include "runtime/mem_obj/buffer.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/mocks/mock_csr.h"
#include "test.h"
#include "runtime/helpers/cache_policy.h"
using namespace OCLRT;
struct CommandStreamReceiverTest : public DeviceFixture,
public MemoryManagementFixture,
public ::testing::Test {
void SetUp() override {
MemoryManagementFixture::SetUp();
DeviceFixture::SetUp();
commandStreamReceiver = &pDevice->getCommandStreamReceiver();
ASSERT_NE(nullptr, commandStreamReceiver);
}
void TearDown() override {
DeviceFixture::TearDown();
MemoryManagementFixture::TearDown();
}
CommandStreamReceiver *commandStreamReceiver;
};
HWTEST_F(CommandStreamReceiverTest, testCtor) {
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
EXPECT_EQ(0u, csr.peekTaskLevel());
EXPECT_EQ(0u, csr.peekTaskCount());
EXPECT_FALSE(csr.isPreambleSent);
}
TEST_F(CommandStreamReceiverTest, makeResident_setsBufferResidencyFlag) {
MockContext context;
float srcMemory[] = {1.0f};
auto retVal = CL_INVALID_VALUE;
auto buffer = Buffer::create(
&context,
CL_MEM_USE_HOST_PTR,
sizeof(srcMemory),
srcMemory,
retVal);
ASSERT_NE(nullptr, buffer);
EXPECT_FALSE(buffer->getGraphicsAllocation()->isResident());
commandStreamReceiver->makeResident(*buffer->getGraphicsAllocation());
EXPECT_TRUE(buffer->getGraphicsAllocation()->isResident());
delete buffer;
}
TEST_F(CommandStreamReceiverTest, commandStreamReceiverFromDeviceHasATagValue) {
EXPECT_NE(nullptr, const_cast<uint32_t *>(commandStreamReceiver->getTagAddress()));
}
TEST_F(CommandStreamReceiverTest, GetCommandStreamReturnsValidObject) {
auto &cs = commandStreamReceiver->getCS();
EXPECT_NE(nullptr, &cs);
}
TEST_F(CommandStreamReceiverTest, getCommandStreamContainsMemoryForRequest) {
size_t requiredSize = 16384;
const auto &commandStream = commandStreamReceiver->getCS(requiredSize);
ASSERT_NE(nullptr, &commandStream);
EXPECT_GE(commandStream.getAvailableSpace(), requiredSize);
}
TEST_F(CommandStreamReceiverTest, getCsReturnsCsWithCsOverfetchSizeIncludedInGraphicsAllocation) {
size_t sizeRequested = 560;
const auto &commandStream = commandStreamReceiver->getCS(sizeRequested);
ASSERT_NE(nullptr, &commandStream);
auto *allocation = commandStream.getGraphicsAllocation();
ASSERT_NE(nullptr, allocation);
size_t expectedTotalSize = alignUp(sizeRequested + MemoryConstants::cacheLineSize, MemoryConstants::pageSize) + CSRequirements::csOverfetchSize;
EXPECT_LT(commandStream.getAvailableSpace(), expectedTotalSize);
EXPECT_LE(commandStream.getAvailableSpace(), expectedTotalSize - CSRequirements::csOverfetchSize);
EXPECT_EQ(expectedTotalSize, allocation->getUnderlyingBufferSize());
}
TEST_F(CommandStreamReceiverTest, getCommandStreamCanRecycle) {
auto &commandStreamInitial = commandStreamReceiver->getCS();
size_t requiredSize = commandStreamInitial.getMaxAvailableSpace() + 42;
const auto &commandStream = commandStreamReceiver->getCS(requiredSize);
ASSERT_NE(nullptr, &commandStream);
EXPECT_GE(commandStream.getMaxAvailableSpace(), requiredSize);
}
TEST_F(CommandStreamReceiverTest, createAllocationAndHandleResidency) {
void *host_ptr = (void *)0x1212341;
auto size = 17262u;
GraphicsAllocation *graphicsAllocation = commandStreamReceiver->createAllocationAndHandleResidency(host_ptr, size);
ASSERT_NE(nullptr, graphicsAllocation);
EXPECT_EQ(host_ptr, graphicsAllocation->getUnderlyingBuffer());
EXPECT_EQ(size, graphicsAllocation->getUnderlyingBufferSize());
}
TEST_F(CommandStreamReceiverTest, memoryManagerHasAccessToCSR) {
auto *memoryManager = commandStreamReceiver->getMemoryManager();
EXPECT_EQ(commandStreamReceiver, memoryManager->csr);
}
HWTEST_F(CommandStreamReceiverTest, storedAllocationsHaveCSRtaskCount) {
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
auto *memoryManager = csr.getMemoryManager();
void *host_ptr = (void *)0x1234;
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
csr.taskCount = 2u;
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
EXPECT_EQ(csr.peekTaskCount(), allocation->taskCount);
}
HWTEST_F(CommandStreamReceiverTest, dontReuseSurfaceIfStillInUse) {
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
auto *memoryManager = csr.getMemoryManager();
void *host_ptr = (void *)0x1234;
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
csr.taskCount = 2u;
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
auto *hwTag = csr.getTagAddress();
*hwTag = 1;
auto newAllocation = memoryManager->obtainReusableAllocation(1);
EXPECT_EQ(nullptr, newAllocation);
}
HWTEST_F(CommandStreamReceiverTest, givenCommandStreamReceiverWhenCheckedForInitialStatusOfStatelessMocsIndexThenUnknownMocsIsReturend) {
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
EXPECT_EQ(CacheSettings::unknownMocs, csr.latestSentStatelessMocsConfig);
EXPECT_FALSE(csr.disableL3Cache);
}
TEST_F(CommandStreamReceiverTest, makeResidentPushesAllocationToMemoryManagerResidencyList) {
auto *memoryManager = commandStreamReceiver->getMemoryManager();
GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemory(0x1000, 0x34000);
ASSERT_NE(nullptr, graphicsAllocation);
commandStreamReceiver->makeResident(*graphicsAllocation);
auto &residencyAllocations = memoryManager->getResidencyAllocations();
ASSERT_EQ(1u, residencyAllocations.size());
EXPECT_EQ(graphicsAllocation, residencyAllocations[0]);
memoryManager->freeGraphicsMemory(graphicsAllocation);
}
TEST_F(CommandStreamReceiverTest, makeResidentWithoutParametersDoesNothing) {
auto *memoryManager = commandStreamReceiver->getMemoryManager();
commandStreamReceiver->processResidency(nullptr);
auto &residencyAllocations = memoryManager->getResidencyAllocations();
EXPECT_EQ(0u, residencyAllocations.size());
}
HWTEST_F(CommandStreamReceiverTest, givenDefaultCommandStreamReceiverThenDefaultDispatchingPolicyIsImmediateSubmission) {
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
EXPECT_EQ(CommandStreamReceiver::DispatchMode::ImmediateDispatch, csr.dispatchMode);
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2017, 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 "test.h"
#include "runtime/command_stream/linear_stream.h"
#include "unit_tests/mocks/mock_graphics_allocation.h"
#include <cstdint>
namespace OCLRT {
struct LinearStreamFixture {
LinearStreamFixture(void)
: gfxAllocation((void *)pCmdBuffer, sizeof(pCmdBuffer)), linearStream(&gfxAllocation) {
}
virtual void SetUp(void) {
}
virtual void TearDown(void) {
}
MockGraphicsAllocation gfxAllocation;
LinearStream linearStream;
uint32_t pCmdBuffer[1024];
};
typedef Test<LinearStreamFixture> LinearStreamTest;
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2017, 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/command_stream/linear_stream.h"
#include "unit_tests/command_stream/linear_stream_fixture.h"
using namespace OCLRT;
TEST(LinearStreamCtorTest, establishInitialValues) {
LinearStream linearStream;
EXPECT_EQ(nullptr, linearStream.getBase());
EXPECT_EQ(0u, linearStream.getMaxAvailableSpace());
}
TEST_F(LinearStreamTest, getSpaceTestSizeZero) {
EXPECT_NE(nullptr, linearStream.getSpace(0));
}
TEST_F(LinearStreamTest, getSpaceTestSizeNonZero) {
EXPECT_NE(nullptr, linearStream.getSpace(sizeof(uint32_t)));
}
TEST_F(LinearStreamTest, getSpaceIncrementsPointerCorrectly) {
size_t allocSize = 1;
auto ptr1 = linearStream.getSpace(allocSize);
ASSERT_NE(nullptr, ptr1);
auto ptr2 = linearStream.getSpace(2);
ASSERT_NE(nullptr, ptr2);
EXPECT_EQ(allocSize, (uintptr_t)ptr2 - (uintptr_t)ptr1);
}
TEST_F(LinearStreamTest, getSpaceTestReturnsWritablePointer) {
uint32_t cmd = 0xbaddf00d;
auto pCmd = linearStream.getSpace(sizeof(cmd));
ASSERT_NE(nullptr, pCmd);
*(uint32_t *)pCmd = cmd;
}
TEST_F(LinearStreamTest, getSpaceReturnsDifferentPointersForEachRequest) {
auto pCmd = linearStream.getSpace(sizeof(uint32_t));
ASSERT_NE(nullptr, pCmd);
auto pCmd2 = linearStream.getSpace(sizeof(uint32_t));
ASSERT_NE(pCmd2, pCmd);
}
TEST_F(LinearStreamTest, getMaxAvailableSpace) {
ASSERT_EQ(linearStream.getMaxAvailableSpace(), linearStream.getAvailableSpace());
}
TEST_F(LinearStreamTest, getAvailableSpaceShouldBeNonZeroAfterInit) {
EXPECT_NE(0u, linearStream.getAvailableSpace());
}
TEST_F(LinearStreamTest, getSpaceReducesAvailableSpace) {
auto originalAvailable = linearStream.getAvailableSpace();
linearStream.getSpace(sizeof(uint32_t));
EXPECT_LT(linearStream.getAvailableSpace(), originalAvailable);
}
TEST_F(LinearStreamTest, putSpaceReducesAvailableSpace) {
auto originalAvailable = linearStream.getAvailableSpace();
size_t sizeToAllocate = 2 * sizeof(uint32_t);
ASSERT_NE(nullptr, linearStream.getSpace(sizeToAllocate));
linearStream.putSpace(sizeToAllocate);
EXPECT_EQ(linearStream.getAvailableSpace(), originalAvailable);
}
TEST_F(LinearStreamTest, testGetUsed) {
size_t sizeToAllocate = 2 * sizeof(uint32_t);
ASSERT_NE(nullptr, linearStream.getSpace(sizeToAllocate));
EXPECT_EQ(sizeToAllocate, linearStream.getUsed());
}
TEST_F(LinearStreamTest, testGetBase) {
ASSERT_EQ(pCmdBuffer, linearStream.getBase());
}
TEST_F(LinearStreamTest, testReplaceBuffer) {
char buffer[256];
linearStream.replaceBuffer(buffer, sizeof(buffer));
EXPECT_EQ(buffer, linearStream.getBase());
EXPECT_EQ(sizeof(buffer), linearStream.getAvailableSpace());
EXPECT_EQ(0u, linearStream.getUsed());
}

View File

@@ -0,0 +1,579 @@
/*
* Copyright (c) 2017, 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 "test.h"
#include "runtime/command_stream/submissions_aggregator.h"
#include "runtime/helpers/flush_stamp.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_device.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_command_queue.h"
using namespace OCLRT;
struct MockSubmissionAggregator : public SubmissionAggregator {
CommandBufferList &peekCommandBuffersList() {
return this->cmdBuffers;
}
};
TEST(SubmissionsAggregator, givenDefaultSubmissionsAggregatorWhenItIsCreatedThenCreationIsSuccesful) {
MockSubmissionAggregator submissionsAggregator;
EXPECT_TRUE(submissionsAggregator.peekCommandBuffersList().peekIsEmpty());
}
TEST(SubmissionsAggregator, givenCommandBufferWhenItIsPassedToSubmissionsAggregatorThenItIsRecorded) {
MockSubmissionAggregator submissionsAggregator;
CommandBuffer *cmdBuffer = new CommandBuffer;
submissionsAggregator.recordCommandBuffer(cmdBuffer);
EXPECT_FALSE(submissionsAggregator.peekCommandBuffersList().peekIsEmpty());
EXPECT_EQ(cmdBuffer, submissionsAggregator.peekCommandBuffersList().peekHead());
EXPECT_EQ(cmdBuffer, submissionsAggregator.peekCommandBuffersList().peekTail());
EXPECT_EQ(cmdBuffer->surfaces.size(), 0u);
//idlist holds the ownership
}
TEST(SubmissionsAggregator, givenTwoCommandBuffersWhenMergeResourcesIsCalledThenDuplicatesAreEliminated) {
MockSubmissionAggregator submissionsAggregator;
CommandBuffer *cmdBuffer = new CommandBuffer;
CommandBuffer *cmdBuffer2 = new CommandBuffer;
GraphicsAllocation alloc1(nullptr, 1);
GraphicsAllocation alloc2(nullptr, 2);
GraphicsAllocation alloc3(nullptr, 3);
GraphicsAllocation alloc4(nullptr, 4);
GraphicsAllocation alloc5(nullptr, 5);
GraphicsAllocation alloc6(nullptr, 6);
cmdBuffer->surfaces.push_back(&alloc1);
cmdBuffer->surfaces.push_back(&alloc6);
cmdBuffer->surfaces.push_back(&alloc5);
cmdBuffer->surfaces.push_back(&alloc3);
cmdBuffer->surfaces.push_back(&alloc6);
cmdBuffer2->surfaces.push_back(&alloc1);
cmdBuffer2->surfaces.push_back(&alloc2);
cmdBuffer2->surfaces.push_back(&alloc5);
cmdBuffer2->surfaces.push_back(&alloc4);
size_t totalUsedSize = 0;
size_t totalMemoryBudget = -1;
ResourcePackage resourcePackage;
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
EXPECT_EQ(0u, totalUsedSize);
submissionsAggregator.recordCommandBuffer(cmdBuffer);
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
EXPECT_EQ(15u, totalUsedSize);
totalUsedSize = 0;
resourcePackage.clear();
submissionsAggregator.recordCommandBuffer(cmdBuffer2);
EXPECT_EQ(cmdBuffer, submissionsAggregator.peekCommandBuffersList().peekHead());
EXPECT_EQ(cmdBuffer2, submissionsAggregator.peekCommandBuffersList().peekTail());
EXPECT_NE(submissionsAggregator.peekCommandBuffersList().peekHead(), submissionsAggregator.peekCommandBuffersList().peekTail());
EXPECT_EQ(5u, cmdBuffer->surfaces.size());
EXPECT_EQ(4u, cmdBuffer2->surfaces.size());
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
//command buffer 2 is aggregated to command buffer 1
auto primaryBatchInstepctionId = submissionsAggregator.peekCommandBuffersList().peekHead()->inspectionId;
EXPECT_EQ(primaryBatchInstepctionId, submissionsAggregator.peekCommandBuffersList().peekHead()->next->inspectionId);
EXPECT_EQ(submissionsAggregator.peekCommandBuffersList().peekHead(), cmdBuffer);
EXPECT_EQ(6u, resourcePackage.size());
EXPECT_EQ(21u, totalUsedSize);
}
TEST(SubmissionsAggregator, givenSubmissionAggregatorWhenThreeCommandBuffersAreSubmittedThenTheyAreAggregated) {
MockSubmissionAggregator submissionsAggregator;
CommandBuffer *cmdBuffer = new CommandBuffer;
CommandBuffer *cmdBuffer2 = new CommandBuffer;
CommandBuffer *cmdBuffer3 = new CommandBuffer;
GraphicsAllocation alloc1(nullptr, 1);
GraphicsAllocation alloc2(nullptr, 2);
GraphicsAllocation alloc3(nullptr, 3);
GraphicsAllocation alloc4(nullptr, 4);
GraphicsAllocation alloc5(nullptr, 5);
GraphicsAllocation alloc6(nullptr, 6);
GraphicsAllocation alloc7(nullptr, 7);
cmdBuffer->surfaces.push_back(&alloc5);
cmdBuffer->surfaces.push_back(&alloc6);
cmdBuffer->surfaces.push_back(&alloc5);
cmdBuffer->surfaces.push_back(&alloc3);
cmdBuffer->surfaces.push_back(&alloc6);
cmdBuffer2->surfaces.push_back(&alloc1);
cmdBuffer2->surfaces.push_back(&alloc2);
cmdBuffer2->surfaces.push_back(&alloc5);
cmdBuffer2->surfaces.push_back(&alloc4);
cmdBuffer3->surfaces.push_back(&alloc7);
cmdBuffer3->surfaces.push_back(&alloc5);
size_t totalUsedSize = 0;
size_t totalMemoryBudget = -1;
ResourcePackage resourcePackage;
submissionsAggregator.recordCommandBuffer(cmdBuffer);
submissionsAggregator.recordCommandBuffer(cmdBuffer2);
submissionsAggregator.recordCommandBuffer(cmdBuffer3);
EXPECT_EQ(cmdBuffer, submissionsAggregator.peekCommandBuffersList().peekHead());
EXPECT_EQ(cmdBuffer3, submissionsAggregator.peekCommandBuffersList().peekTail());
EXPECT_EQ(cmdBuffer3->prev, cmdBuffer2);
EXPECT_EQ(cmdBuffer2->next, cmdBuffer3);
EXPECT_EQ(cmdBuffer->next, cmdBuffer2);
EXPECT_EQ(cmdBuffer2->prev, cmdBuffer);
EXPECT_NE(submissionsAggregator.peekCommandBuffersList().peekHead(), submissionsAggregator.peekCommandBuffersList().peekTail());
EXPECT_EQ(5u, cmdBuffer->surfaces.size());
EXPECT_EQ(4u, cmdBuffer2->surfaces.size());
EXPECT_EQ(2u, cmdBuffer3->surfaces.size());
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
//command buffer 3 and 2 is aggregated to command buffer 1
auto primaryBatchInstepctionId = submissionsAggregator.peekCommandBuffersList().peekHead()->inspectionId;
EXPECT_EQ(primaryBatchInstepctionId, submissionsAggregator.peekCommandBuffersList().peekHead()->next->inspectionId);
EXPECT_EQ(primaryBatchInstepctionId, submissionsAggregator.peekCommandBuffersList().peekHead()->next->next->inspectionId);
EXPECT_EQ(submissionsAggregator.peekCommandBuffersList().peekHead(), cmdBuffer);
EXPECT_EQ(7u, resourcePackage.size());
EXPECT_EQ(28u, totalUsedSize);
}
TEST(SubmissionsAggregator, givenMultipleCommandBuffersWhenTheyAreAggreagateWithCertainMemoryLimitThenOnlyThatFitAreAggregated) {
MockSubmissionAggregator submissionsAggregator;
CommandBuffer *cmdBuffer = new CommandBuffer;
CommandBuffer *cmdBuffer2 = new CommandBuffer;
CommandBuffer *cmdBuffer3 = new CommandBuffer;
GraphicsAllocation alloc1(nullptr, 1);
GraphicsAllocation alloc2(nullptr, 2);
GraphicsAllocation alloc3(nullptr, 3);
GraphicsAllocation alloc4(nullptr, 4);
GraphicsAllocation alloc5(nullptr, 5);
GraphicsAllocation alloc6(nullptr, 6);
GraphicsAllocation alloc7(nullptr, 7);
//14 bytes consumed
cmdBuffer->surfaces.push_back(&alloc5);
cmdBuffer->surfaces.push_back(&alloc6);
cmdBuffer->surfaces.push_back(&alloc5);
cmdBuffer->surfaces.push_back(&alloc3);
cmdBuffer->surfaces.push_back(&alloc6);
//12 bytes total , only 7 new
cmdBuffer2->surfaces.push_back(&alloc1);
cmdBuffer2->surfaces.push_back(&alloc2);
cmdBuffer2->surfaces.push_back(&alloc5);
cmdBuffer2->surfaces.push_back(&alloc4);
//12 bytes total, only 7 new
cmdBuffer3->surfaces.push_back(&alloc7);
cmdBuffer3->surfaces.push_back(&alloc5);
size_t totalUsedSize = 0;
size_t totalMemoryBudget = 22;
ResourcePackage resourcePackage;
submissionsAggregator.recordCommandBuffer(cmdBuffer);
submissionsAggregator.recordCommandBuffer(cmdBuffer2);
submissionsAggregator.recordCommandBuffer(cmdBuffer3);
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
//command buffer 2 is aggregated to command buffer 1, comand buffer 3 becomes command buffer 2
EXPECT_EQ(submissionsAggregator.peekCommandBuffersList().peekHead(), cmdBuffer);
EXPECT_EQ(submissionsAggregator.peekCommandBuffersList().peekTail(), cmdBuffer3);
EXPECT_EQ(cmdBuffer->next, cmdBuffer2);
EXPECT_EQ(cmdBuffer3->prev, cmdBuffer2);
EXPECT_EQ(cmdBuffer2->inspectionId, cmdBuffer->inspectionId);
EXPECT_NE(cmdBuffer3->inspectionId, cmdBuffer2->inspectionId);
EXPECT_EQ(0u, cmdBuffer3->inspectionId);
EXPECT_EQ(6u, resourcePackage.size());
EXPECT_EQ(21u, totalUsedSize);
}
TEST(SubmissionsAggregator, givenMultipleCommandBuffersWhenAggregateIsCalledMultipleTimesThenFurtherInspectionAreHandledCorrectly) {
MockSubmissionAggregator submissionsAggregator;
CommandBuffer *cmdBuffer = new CommandBuffer;
CommandBuffer *cmdBuffer2 = new CommandBuffer;
CommandBuffer *cmdBuffer3 = new CommandBuffer;
GraphicsAllocation alloc1(nullptr, 1);
GraphicsAllocation alloc2(nullptr, 2);
GraphicsAllocation alloc3(nullptr, 3);
GraphicsAllocation alloc4(nullptr, 4);
GraphicsAllocation alloc5(nullptr, 5);
GraphicsAllocation alloc6(nullptr, 6);
GraphicsAllocation alloc7(nullptr, 7);
//14 bytes consumed
cmdBuffer->surfaces.push_back(&alloc5);
cmdBuffer->surfaces.push_back(&alloc6);
cmdBuffer->surfaces.push_back(&alloc5);
cmdBuffer->surfaces.push_back(&alloc3);
cmdBuffer->surfaces.push_back(&alloc6);
//12 bytes total , only 7 new
cmdBuffer2->surfaces.push_back(&alloc1);
cmdBuffer2->surfaces.push_back(&alloc2);
cmdBuffer2->surfaces.push_back(&alloc5);
cmdBuffer2->surfaces.push_back(&alloc4);
//12 bytes total, only 7 new
cmdBuffer3->surfaces.push_back(&alloc7);
cmdBuffer3->surfaces.push_back(&alloc5);
size_t totalUsedSize = 0;
size_t totalMemoryBudget = 14;
ResourcePackage resourcePackage;
submissionsAggregator.recordCommandBuffer(cmdBuffer);
submissionsAggregator.recordCommandBuffer(cmdBuffer2);
submissionsAggregator.recordCommandBuffer(cmdBuffer3);
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
//command buffers not aggregated due to too low limit
EXPECT_EQ(submissionsAggregator.peekCommandBuffersList().peekHead(), cmdBuffer);
EXPECT_EQ(cmdBuffer->next, cmdBuffer2);
EXPECT_EQ(submissionsAggregator.peekCommandBuffersList().peekTail(), cmdBuffer3);
//budget is now larger we can fit everything
totalMemoryBudget = 28;
resourcePackage.clear();
totalUsedSize = 0;
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
//all cmd buffers are merged to 1
EXPECT_EQ(cmdBuffer3->inspectionId, cmdBuffer2->inspectionId);
EXPECT_EQ(cmdBuffer->inspectionId, cmdBuffer2->inspectionId);
EXPECT_EQ(submissionsAggregator.peekCommandBuffersList().peekTail(), cmdBuffer3);
EXPECT_EQ(submissionsAggregator.peekCommandBuffersList().peekHead(), cmdBuffer);
EXPECT_EQ(totalMemoryBudget, totalUsedSize);
EXPECT_EQ(7u, resourcePackage.size());
}
TEST(SubmissionsAggregator, givenMultipleCommandBuffersWithDifferentGraphicsAllocationsWhenAggregateIsCalledThenResourcePackContainSecondBatchBuffer) {
MockSubmissionAggregator submissionsAggregator;
CommandBuffer *cmdBuffer = new CommandBuffer;
CommandBuffer *cmdBuffer2 = new CommandBuffer;
GraphicsAllocation alloc1(nullptr, 1);
GraphicsAllocation alloc2(nullptr, 2);
GraphicsAllocation alloc5(nullptr, 5);
GraphicsAllocation alloc7(nullptr, 7);
//5 bytes consumed
cmdBuffer->surfaces.push_back(&alloc5);
//10 bytes total
cmdBuffer2->surfaces.push_back(&alloc1);
cmdBuffer2->surfaces.push_back(&alloc2);
cmdBuffer2->batchBuffer.commandBufferAllocation = &alloc7;
size_t totalUsedSize = 0;
size_t totalMemoryBudget = 200;
ResourcePackage resourcePackage;
submissionsAggregator.recordCommandBuffer(cmdBuffer);
submissionsAggregator.recordCommandBuffer(cmdBuffer2);
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
EXPECT_EQ(4u, resourcePackage.size());
EXPECT_EQ(15u, totalUsedSize);
}
TEST(SubmissionsAggregator, givenTwoCommandBufferWhereSecondContainsFirstOnResourceListWhenItIsAggregatedThenResourcePackDoesntContainPrimaryBatch) {
MockSubmissionAggregator submissionsAggregator;
CommandBuffer *cmdBuffer = new CommandBuffer;
CommandBuffer *cmdBuffer2 = new CommandBuffer;
GraphicsAllocation cmdBufferAllocation1(nullptr, 1);
GraphicsAllocation cmdBufferAllocation2(nullptr, 2);
GraphicsAllocation alloc5(nullptr, 5);
GraphicsAllocation alloc7(nullptr, 7);
cmdBuffer->batchBuffer.commandBufferAllocation = &cmdBufferAllocation1;
cmdBuffer2->batchBuffer.commandBufferAllocation = &cmdBufferAllocation2;
//cmdBuffer2 has commandBufferAllocation on the surface list
cmdBuffer2->surfaces.push_back(&cmdBufferAllocation1);
cmdBuffer2->surfaces.push_back(&alloc7);
cmdBuffer->surfaces.push_back(&alloc5);
size_t totalUsedSize = 0;
size_t totalMemoryBudget = 200;
ResourcePackage resourcePackage;
submissionsAggregator.recordCommandBuffer(cmdBuffer);
submissionsAggregator.recordCommandBuffer(cmdBuffer2);
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
//resource pack shuold have 3 surfaces
EXPECT_EQ(3u, resourcePackage.size());
EXPECT_EQ(14u, totalUsedSize);
}
TEST(SubmissionsAggregator, givenTwoCommandBufferWhereSecondContainsTheFirstCommandBufferGraphicsAllocaitonWhenItIsAggregatedThenResourcePackDoesntContainPrimaryBatch) {
MockSubmissionAggregator submissionsAggregator;
CommandBuffer *cmdBuffer = new CommandBuffer;
CommandBuffer *cmdBuffer2 = new CommandBuffer;
GraphicsAllocation cmdBufferAllocation1(nullptr, 1);
GraphicsAllocation alloc5(nullptr, 5);
GraphicsAllocation alloc7(nullptr, 7);
cmdBuffer->batchBuffer.commandBufferAllocation = &cmdBufferAllocation1;
cmdBuffer2->batchBuffer.commandBufferAllocation = &cmdBufferAllocation1;
//cmdBuffer2 has commandBufferAllocation on the surface list
cmdBuffer2->surfaces.push_back(&alloc7);
cmdBuffer->surfaces.push_back(&alloc5);
size_t totalUsedSize = 0;
size_t totalMemoryBudget = 200;
ResourcePackage resourcePackage;
submissionsAggregator.recordCommandBuffer(cmdBuffer);
submissionsAggregator.recordCommandBuffer(cmdBuffer2);
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
//resource pack shuold have 3 surfaces
EXPECT_EQ(2u, resourcePackage.size());
EXPECT_EQ(12u, totalUsedSize);
}
TEST(SubmissionsAggregator, givenCommandBuffersRequiringDifferenctCoherencySettingWhenAggregateIsCalledThenTheyAreNotAgggregated) {
MockSubmissionAggregator submissionsAggregator;
CommandBuffer *cmdBuffer = new CommandBuffer;
CommandBuffer *cmdBuffer2 = new CommandBuffer;
GraphicsAllocation alloc1(nullptr, 1);
GraphicsAllocation alloc7(nullptr, 7);
cmdBuffer->batchBuffer.requiresCoherency = true;
cmdBuffer2->batchBuffer.requiresCoherency = false;
cmdBuffer->surfaces.push_back(&alloc1);
cmdBuffer2->surfaces.push_back(&alloc7);
submissionsAggregator.recordCommandBuffer(cmdBuffer);
submissionsAggregator.recordCommandBuffer(cmdBuffer2);
ResourcePackage resourcePackage;
size_t totalUsedSize = 0;
size_t totalMemoryBudget = 200;
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
EXPECT_EQ(1u, totalUsedSize);
EXPECT_EQ(1u, resourcePackage.size());
EXPECT_NE(cmdBuffer->inspectionId, cmdBuffer2->inspectionId);
EXPECT_EQ(1u, cmdBuffer->inspectionId);
}
TEST(SubmissionsAggregator, givenCommandBuffersRequiringDifferenctPrioritySettingWhenAggregateIsCalledThenTheyAreNotAgggregated) {
MockSubmissionAggregator submissionsAggregator;
CommandBuffer *cmdBuffer = new CommandBuffer;
CommandBuffer *cmdBuffer2 = new CommandBuffer;
GraphicsAllocation alloc1(nullptr, 1);
GraphicsAllocation alloc7(nullptr, 7);
cmdBuffer->batchBuffer.low_priority = true;
cmdBuffer2->batchBuffer.low_priority = false;
cmdBuffer->surfaces.push_back(&alloc1);
cmdBuffer2->surfaces.push_back(&alloc7);
submissionsAggregator.recordCommandBuffer(cmdBuffer);
submissionsAggregator.recordCommandBuffer(cmdBuffer2);
ResourcePackage resourcePackage;
size_t totalUsedSize = 0;
size_t totalMemoryBudget = 200;
submissionsAggregator.aggregateCommandBuffers(resourcePackage, totalUsedSize, totalMemoryBudget);
EXPECT_EQ(1u, totalUsedSize);
EXPECT_EQ(1u, resourcePackage.size());
EXPECT_NE(cmdBuffer->inspectionId, cmdBuffer2->inspectionId);
EXPECT_EQ(1u, cmdBuffer->inspectionId);
}
TEST(SubmissionsAggregator, dontAllocateFlushStamp) {
CommandBuffer cmdBuffer;
EXPECT_EQ(nullptr, cmdBuffer.flushStamp->getStampReference());
}
struct SubmissionsAggregatorTests : public ::testing::Test {
void SetUp() override {
device.reset(Device::create<MockDevice>(platformDevices[0]));
context.reset(new MockContext(device.get()));
}
template <typename T>
void overrideCsr(T *newCsr) {
device->resetCommandStreamReceiver(newCsr);
newCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch);
}
std::unique_ptr<MockDevice> device;
std::unique_ptr<MockContext> context;
};
HWTEST_F(SubmissionsAggregatorTests, givenMultipleQueuesWhenCmdBuffersAreRecordedThenAssignFlushStampObjFromCmdQueue) {
MockKernelWithInternals kernel(*device.get());
CommandQueueHw<FamilyType> cmdQ1(context.get(), device.get(), 0);
CommandQueueHw<FamilyType> cmdQ2(context.get(), device.get(), 0);
auto mockCsr = new MockCsrHw2<FamilyType>(*platformDevices[0]);
size_t GWS = 1;
overrideCsr(mockCsr);
auto expectRefCounts = [&](int32_t cmdQRef1, int32_t cmdQRef2) {
EXPECT_EQ(cmdQRef1, cmdQ1.flushStamp->getStampReference()->getRefInternalCount());
EXPECT_EQ(cmdQRef2, cmdQ2.flushStamp->getStampReference()->getRefInternalCount());
};
expectRefCounts(1, 1);
cmdQ1.enqueueKernel(kernel, 1, nullptr, &GWS, nullptr, 0, nullptr, nullptr);
expectRefCounts(2, 1);
cmdQ2.enqueueKernel(kernel, 1, nullptr, &GWS, nullptr, 0, nullptr, nullptr);
expectRefCounts(2, 2);
{
auto cmdBuffer = mockCsr->peekSubmissionAggregator()->peekCmdBufferList().removeFrontOne();
EXPECT_EQ(cmdQ1.flushStamp->getStampReference(), cmdBuffer->flushStamp->getStampReference());
}
expectRefCounts(1, 2);
{
auto cmdBuffer = mockCsr->peekSubmissionAggregator()->peekCmdBufferList().removeFrontOne();
EXPECT_EQ(cmdQ2.flushStamp->getStampReference(), cmdBuffer->flushStamp->getStampReference());
}
expectRefCounts(1, 1);
}
HWTEST_F(SubmissionsAggregatorTests, givenCmdQueueWhenCmdBufferWithEventIsRecordedThenAssignFlushStampObjForEveryone) {
MockKernelWithInternals kernel(*device.get());
CommandQueueHw<FamilyType> cmdQ1(context.get(), device.get(), 0);
auto mockCsr = new MockCsrHw2<FamilyType>(*platformDevices[0]);
size_t GWS = 1;
overrideCsr(mockCsr);
cl_event event1;
EXPECT_EQ(1, cmdQ1.flushStamp->getStampReference()->getRefInternalCount());
cmdQ1.enqueueKernel(kernel, 1, nullptr, &GWS, nullptr, 0, nullptr, &event1);
EXPECT_EQ(3, cmdQ1.flushStamp->getStampReference()->getRefInternalCount());
EXPECT_EQ(castToObject<Event>(event1)->flushStamp->getStampReference(), cmdQ1.flushStamp->getStampReference());
{
auto cmdBuffer = mockCsr->peekSubmissionAggregator()->peekCmdBufferList().removeFrontOne();
EXPECT_EQ(cmdQ1.flushStamp->getStampReference(), cmdBuffer->flushStamp->getStampReference());
}
EXPECT_EQ(2, cmdQ1.flushStamp->getStampReference()->getRefInternalCount());
castToObject<Event>(event1)->release();
EXPECT_EQ(1, cmdQ1.flushStamp->getStampReference()->getRefInternalCount());
}
HWTEST_F(SubmissionsAggregatorTests, givenMultipleCmdBuffersWhenFlushThenUpdateAllRelatedFlushStamps) {
MockKernelWithInternals kernel(*device.get());
CommandQueueHw<FamilyType> cmdQ1(context.get(), device.get(), 0);
CommandQueueHw<FamilyType> cmdQ2(context.get(), device.get(), 0);
auto mockCsr = new MockCsrHw2<FamilyType>(*platformDevices[0]);
size_t GWS = 1;
overrideCsr(mockCsr);
mockCsr->taskCount = 5;
mockCsr->flushStamp->setStamp(5);
cl_event event1, event2;
cmdQ1.enqueueKernel(kernel, 1, nullptr, &GWS, nullptr, 0, nullptr, &event1);
cmdQ2.enqueueKernel(kernel, 1, nullptr, &GWS, nullptr, 0, nullptr, &event2);
mockCsr->flushBatchedSubmissions();
auto expectedFlushStamp = mockCsr->flushStamp->peekStamp();
EXPECT_EQ(expectedFlushStamp, cmdQ1.flushStamp->peekStamp());
EXPECT_EQ(expectedFlushStamp, cmdQ2.flushStamp->peekStamp());
EXPECT_EQ(expectedFlushStamp, castToObject<Event>(event1)->flushStamp->peekStamp());
EXPECT_EQ(expectedFlushStamp, castToObject<Event>(event2)->flushStamp->peekStamp());
castToObject<Event>(event1)->release();
castToObject<Event>(event2)->release();
}
HWTEST_F(SubmissionsAggregatorTests, givenMultipleCmdBuffersWhenNotAggregatedDuringFlushThenUpdateAllRelatedFlushStamps) {
MockKernelWithInternals kernel(*device.get());
CommandQueueHw<FamilyType> cmdQ1(context.get(), device.get(), 0);
CommandQueueHw<FamilyType> cmdQ2(context.get(), device.get(), 0);
auto mockCsr = new MockCsrHw2<FamilyType>(*platformDevices[0]);
size_t GWS = 1;
overrideCsr(mockCsr);
mockCsr->taskCount = 5;
mockCsr->flushStamp->setStamp(5);
cl_event event1, event2;
cmdQ1.enqueueKernel(kernel, 1, nullptr, &GWS, nullptr, 0, nullptr, &event1);
cmdQ2.enqueueKernel(kernel, 1, nullptr, &GWS, nullptr, 0, nullptr, &event2);
// dont aggregate
mockCsr->peekSubmissionAggregator()->peekCmdBufferList().peekHead()->batchBuffer.low_priority = true;
mockCsr->peekSubmissionAggregator()->peekCmdBufferList().peekTail()->batchBuffer.low_priority = false;
mockCsr->flushBatchedSubmissions();
EXPECT_EQ(6, cmdQ1.flushStamp->peekStamp());
EXPECT_EQ(6, castToObject<Event>(event1)->flushStamp->peekStamp());
EXPECT_EQ(7, cmdQ2.flushStamp->peekStamp());
EXPECT_EQ(7, castToObject<Event>(event2)->flushStamp->peekStamp());
castToObject<Event>(event1)->release();
castToObject<Event>(event2)->release();
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2017, 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/command_queue/command_queue.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/device/device.h"
#include "gen_cmd_parse.h"
#include "unit_tests/command_stream/tbx_command_stream_fixture.h"
#include "unit_tests/mocks/mock_device.h"
#include "gtest/gtest.h"
namespace OCLRT {
void TbxCommandStreamFixture::SetUp(MockDevice *pDevice) {
// Create our TBX command stream receiver based on HW type
const auto &hwInfo = pDevice->getHardwareInfo();
pCommandStreamReceiver = TbxCommandStreamReceiver::create(hwInfo);
ASSERT_NE(nullptr, pCommandStreamReceiver);
mmTbx = pCommandStreamReceiver->createMemoryManager(false);
pDevice->resetCommandStreamReceiver(pCommandStreamReceiver);
}
void TbxCommandStreamFixture::TearDown() {
delete mmTbx;
CommandStreamFixture::TearDown();
}
} // namespace OCLRT

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2017, 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/command_stream/tbx_command_stream_receiver_hw.h"
#include "unit_tests/command_stream/command_stream_fixture.h"
#include <cstdint>
namespace OCLRT {
class CommandStreamReceiver;
class MockDevice;
class TbxCommandStreamFixture : public CommandStreamFixture {
public:
virtual void SetUp(MockDevice *pDevice);
virtual void TearDown(void);
CommandStreamReceiver *pCommandStreamReceiver = nullptr;
MemoryManager *mmTbx;
};
} // namespace OCLRT

View File

@@ -0,0 +1,156 @@
/*
* Copyright (c) 2017, 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/mem_obj/mem_obj.h"
#include "tbx_command_stream_fixture.h"
#include "runtime/command_stream/tbx_command_stream_receiver_hw.h"
#include "runtime/command_stream/command_stream_receiver_hw.h"
#include "runtime/helpers/ptr_math.h"
#include "gen_cmd_parse.h"
#include "unit_tests/command_queue/command_queue_fixture.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "test.h"
#include <cstdint>
using namespace OCLRT;
namespace Os {
extern const char *tbxLibName;
}
struct TbxFixture : public TbxCommandStreamFixture,
public DeviceFixture {
using TbxCommandStreamFixture::SetUp;
void SetUp() {
DeviceFixture::SetUp();
TbxCommandStreamFixture::SetUp(pDevice);
}
void TearDown() override {
TbxCommandStreamFixture::TearDown();
DeviceFixture::TearDown();
}
};
typedef Test<TbxFixture> Tbx_command_stream;
TEST_F(Tbx_command_stream, DISABLED_testFactory) {
}
HWTEST_F(Tbx_command_stream, DISABLED_testTbxMemoryManager) {
TbxCommandStreamReceiverHw<FamilyType> *tbxCsr = (TbxCommandStreamReceiverHw<FamilyType> *)pCommandStreamReceiver;
TbxMemoryManager *getMM = tbxCsr->getMemoryManager();
EXPECT_NE(nullptr, getMM);
EXPECT_EQ(1 * GB, getMM->getSystemSharedMemory());
}
TEST_F(Tbx_command_stream, DISABLED_makeResident) {
uint8_t buffer[0x10000];
size_t size = sizeof(buffer);
GraphicsAllocation *graphicsAllocation = mmTbx->allocateGraphicsMemory(size, buffer);
pCommandStreamReceiver->makeResident(*graphicsAllocation);
pCommandStreamReceiver->makeNonResident(*graphicsAllocation);
mmTbx->freeGraphicsMemory(graphicsAllocation);
}
TEST_F(Tbx_command_stream, DISABLED_makeResidentOnZeroSizedBufferShouldDoNothing) {
GraphicsAllocation graphicsAllocation(nullptr, 0);
pCommandStreamReceiver->makeResident(graphicsAllocation);
pCommandStreamReceiver->makeNonResident(graphicsAllocation);
}
TEST_F(Tbx_command_stream, DISABLED_flush) {
char buffer[4096];
memset(buffer, 0, 4096);
LinearStream cs(buffer, 4096);
size_t startOffset = 0;
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), startOffset, false, false, cs.getUsed(), &cs};
pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr);
}
HWTEST_F(Tbx_command_stream, DISABLED_flushUntilTailRCSLargerThanSizeRCS) {
char buffer[4096];
memset(buffer, 0, 4096);
LinearStream cs(buffer, 4096);
size_t startOffset = 0;
TbxCommandStreamReceiverHw<FamilyType> *tbxCsr = (TbxCommandStreamReceiverHw<FamilyType> *)pCommandStreamReceiver;
auto &engineInfo = tbxCsr->engineInfoTable[EngineType::ENGINE_RCS];
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), startOffset, false, false, cs.getUsed(), &cs};
pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr);
auto size = engineInfo.sizeRCS;
engineInfo.sizeRCS = 64;
pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr);
pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr);
pCommandStreamReceiver->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr);
engineInfo.sizeRCS = size;
}
HWTEST_F(Tbx_command_stream, DISABLED_getCsTraits) {
TbxCommandStreamReceiverHw<FamilyType> *tbxCsr = (TbxCommandStreamReceiverHw<FamilyType> *)pCommandStreamReceiver;
tbxCsr->getCsTraits(EngineType::ENGINE_RCS);
tbxCsr->getCsTraits(EngineType::ENGINE_BCS);
tbxCsr->getCsTraits(EngineType::ENGINE_VCS);
tbxCsr->getCsTraits(EngineType::ENGINE_VECS);
}
#if defined(__linux__)
TEST(TbxCommandStreamReceiverTest, DISABLED_createShouldReturnFunctionPointer) {
TbxCommandStreamReceiver tbx;
const HardwareInfo *hwInfo = platformDevices[0];
CommandStreamReceiver *csr = tbx.create(*hwInfo);
EXPECT_NE(nullptr, csr);
delete csr;
}
namespace OCLRT {
TEST(TbxCommandStreamReceiverTest, createShouldReturnNullptrForEmptyEntryInFactory) {
extern TbxCommandStreamReceiverCreateFunc tbxCommandStreamReceiverFactory[IGFX_MAX_PRODUCT];
TbxCommandStreamReceiver tbx;
const HardwareInfo *hwInfo = platformDevices[0];
GFXCORE_FAMILY family = hwInfo->pPlatform->eRenderCoreFamily;
auto pCreate = tbxCommandStreamReceiverFactory[family];
tbxCommandStreamReceiverFactory[family] = nullptr;
CommandStreamReceiver *csr = tbx.create(*hwInfo);
EXPECT_EQ(nullptr, csr);
tbxCommandStreamReceiverFactory[family] = pCreate;
}
} // namespace OCLRT
#endif
TEST(TbxCommandStreamReceiverTest, givenTbxCommandStreamReceiverWhenItIsCreatedWithWrongGfxCoreFamilyThenNullPointerShouldBeReturned) {
HardwareInfo hwInfo = *platformDevices[0];
GFXCORE_FAMILY family = hwInfo.pPlatform->eRenderCoreFamily;
const_cast<PLATFORM *>(hwInfo.pPlatform)->eRenderCoreFamily = GFXCORE_FAMILY_FORCE_ULONG; // wrong gfx core family
CommandStreamReceiver *csr = TbxCommandStreamReceiver::create(hwInfo);
EXPECT_EQ(nullptr, csr);
const_cast<PLATFORM *>(hwInfo.pPlatform)->eRenderCoreFamily = family;
}