Split test files

Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski
2021-06-01 19:35:06 +00:00
committed by Compute-Runtime-Automation
parent 2829226937
commit 8d0e2034fe
14 changed files with 1872 additions and 1782 deletions

View File

@@ -9,6 +9,7 @@ target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_1.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_4.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_api.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_append_barrier.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_append_event_reset.cpp

View File

@@ -168,107 +168,6 @@ HWTEST2_F(CommandListCreate, givenCommandListAnd3DWhbufferenMemoryCopyRegionCall
EXPECT_GT(cmdList.appendMemoryCopyKernel3dCalledTimes, 0u);
}
HWTEST2_F(CommandListCreate, givenCopyOnlyCommandListWhenAppendWriteGlobalTimestampCalledThenMiFlushDWWithTimestampEncoded, Platforms) {
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
using MI_FLUSH_DW = typename GfxFamily::MI_FLUSH_DW;
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, returnValue));
auto &commandContainer = commandList->commandContainer;
uint64_t timestampAddress = 0xfffffffffff0L;
uint64_t *dstptr = reinterpret_cast<uint64_t *>(timestampAddress);
const auto commandStreamOffset = commandContainer.getCommandStream()->getUsed();
commandList->appendWriteGlobalTimestamp(dstptr, nullptr, 0, nullptr);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList,
ptrOffset(commandContainer.getCommandStream()->getCpuBase(), commandStreamOffset),
commandContainer.getCommandStream()->getUsed() - commandStreamOffset));
auto iterator = findAll<MI_FLUSH_DW *>(cmdList.begin(), cmdList.end());
bool postSyncFound = false;
ASSERT_NE(0u, iterator.size());
for (auto it : iterator) {
auto cmd = genCmdCast<MI_FLUSH_DW *>(*it);
if ((cmd->getPostSyncOperation() == MI_FLUSH_DW::POST_SYNC_OPERATION_WRITE_TIMESTAMP_REGISTER) &&
(cmd->getDestinationAddress() == timestampAddress)) {
postSyncFound = true;
}
}
ASSERT_TRUE(postSyncFound);
}
HWTEST2_F(CommandListCreate, givenCommandListWhenAppendWriteGlobalTimestampCalledThenPipeControlWithTimestampWriteEncoded, Platforms) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
using POST_SYNC_OPERATION = typename PIPE_CONTROL::POST_SYNC_OPERATION;
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
auto &commandContainer = commandList->commandContainer;
uint64_t timestampAddress = 0x12345678555500;
uint32_t timestampAddressLow = (uint32_t)(timestampAddress & 0xFFFFFFFF);
uint32_t timestampAddressHigh = (uint32_t)(timestampAddress >> 32);
uint64_t *dstptr = reinterpret_cast<uint64_t *>(timestampAddress);
const auto commandStreamOffset = commandContainer.getCommandStream()->getUsed();
commandList->appendWriteGlobalTimestamp(dstptr, nullptr, 0, nullptr);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList,
ptrOffset(commandContainer.getCommandStream()->getCpuBase(), commandStreamOffset),
commandContainer.getCommandStream()->getUsed() - commandStreamOffset));
auto iterator = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
auto cmd = genCmdCast<PIPE_CONTROL *>(*iterator);
EXPECT_TRUE(cmd->getCommandStreamerStallEnable());
EXPECT_FALSE(cmd->getDcFlushEnable());
EXPECT_EQ(cmd->getAddressHigh(), timestampAddressHigh);
EXPECT_EQ(cmd->getAddress(), timestampAddressLow);
EXPECT_EQ(POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_TIMESTAMP, cmd->getPostSyncOperation());
}
HWTEST2_F(CommandListCreate, givenCommandListWhenAppendWriteGlobalTimestampCalledThenTimestampAllocationIsInsideResidencyContainer, Platforms) {
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
uint64_t timestampAddress = 0x12345678555500;
uint64_t *dstptr = reinterpret_cast<uint64_t *>(timestampAddress);
commandList->appendWriteGlobalTimestamp(dstptr, nullptr, 0, nullptr);
auto &commandContainer = commandList->commandContainer;
auto &residencyContainer = commandContainer.getResidencyContainer();
const bool addressIsInContainer = std::any_of(residencyContainer.begin(), residencyContainer.end(), [timestampAddress](NEO::GraphicsAllocation *alloc) {
return alloc->getGpuAddress() == timestampAddress;
});
EXPECT_TRUE(addressIsInContainer);
}
HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenAppendWriteGlobalTimestampThenReturnsSuccess, Platforms) {
Mock<CommandQueue> cmdQueue;
uint64_t timestampAddress = 0x12345678555500;
uint64_t *dstptr = reinterpret_cast<uint64_t *>(timestampAddress);
auto commandList = std::make_unique<WhiteBox<L0::CommandListCoreFamilyImmediate<gfxCoreFamily>>>();
ASSERT_NE(nullptr, commandList);
ze_result_t ret = commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
ASSERT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->device = device;
commandList->cmdQImmediate = &cmdQueue;
commandList->cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
EXPECT_CALL(cmdQueue, executeCommandLists).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
EXPECT_CALL(cmdQueue, synchronize).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
auto result = commandList->appendWriteGlobalTimestamp(dstptr, nullptr, 0, nullptr);
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
commandList->cmdQImmediate = nullptr;
}
using AppendMemoryCopy = CommandListCreate;
template <GFXCORE_FAMILY gfxCoreFamily>
@@ -1171,33 +1070,6 @@ HWTEST2_F(CommandListCreate, givenCommandListThenSshCorrectlyReserved, Supported
EXPECT_EQ(commandList.getReserveSshSize(), size);
}
HWTEST_F(CommandListCreate, GivenCommandListWhenUnalignedPtrThenLeftMiddleAndRightCopyAdded) {
using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT;
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, returnValue));
ASSERT_NE(nullptr, commandList);
EXPECT_EQ(device, commandList->device);
void *srcPtr = reinterpret_cast<void *>(0x4321);
void *dstPtr = reinterpret_cast<void *>(0x2345);
auto result = commandList->appendMemoryCopy(dstPtr, srcPtr, 2 * MemoryConstants::cacheLineSize, nullptr, 0, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandList->commandContainer.getCommandStream()->getCpuBase(), 0), commandList->commandContainer.getCommandStream()->getUsed()));
auto itor = find<XY_COPY_BLT *>(cmdList.begin(), cmdList.end());
EXPECT_NE(cmdList.end(), itor);
itor = find<XY_COPY_BLT *>(++itor, cmdList.end());
EXPECT_NE(cmdList.end(), itor);
itor = find<XY_COPY_BLT *>(++itor, cmdList.end());
EXPECT_NE(cmdList.end(), itor);
}
HWTEST2_F(CommandListCreate, givenCommandListWhenTimestampPassedToMemoryCopyThenAppendProfilingCalledOnceBeforeAndAfterCommand, SupportedPlatforms) {
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
using MI_LOAD_REGISTER_REG = typename GfxFamily::MI_LOAD_REGISTER_REG;

View File

@@ -6,12 +6,12 @@
*/
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "test.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
@@ -1100,429 +1100,5 @@ HWTEST2_F(CommandListCreate, givenNonEmptyCommandsToPatchWhenClearCommandsToPatc
EXPECT_TRUE(pCommandList->commandsToPatch.empty());
}
using HostPointerManagerCommandListTest = Test<HostPointerManagerFixure>;
HWTEST2_F(HostPointerManagerCommandListTest,
givenImportedHostPointerWhenAppendMemoryFillUsingHostPointerThenAppendFillUsingHostPointerAllocation,
Platforms) {
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int pattern = 1;
ret = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&pattern), sizeof(pattern), 64u, nullptr, 0, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
}
HWTEST2_F(HostPointerManagerCommandListTest,
givenImportedHostPointerAndCopyEngineWhenAppendMemoryFillUsingHostPointerThenAppendFillUsingHostPointerAllocation,
Platforms) {
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::Copy);
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int pattern = 1;
ret = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&pattern), sizeof(pattern), 64u, nullptr, 0, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
}
HWTEST2_F(HostPointerManagerCommandListTest,
givenHostPointerImportedWhenGettingAlignedAllocationThenRetrieveProperOffsetAndAddress,
Platforms) {
auto commandList = std::make_unique<::L0::ult::CommandListCoreFamily<gfxCoreFamily>>();
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
size_t mainOffset = 100;
size_t importSize = 100;
void *importPointer = ptrOffset(heapPointer, mainOffset);
auto ret = hostDriverHandle->importExternalPointer(importPointer, importSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
auto hostAllocation = hostDriverHandle->findHostPointerAllocation(importPointer, importSize, device->getRootDeviceIndex());
ASSERT_NE(nullptr, hostAllocation);
size_t allocOffset = 10;
size_t offsetSize = 20;
void *offsetPointer = ptrOffset(importPointer, allocOffset);
AlignedAllocationData outData = commandList->getAlignedAllocation(device, importPointer, importSize);
auto gpuBaseAddress = static_cast<size_t>(hostAllocation->getGpuAddress());
auto expectedAlignedAddress = alignDown(gpuBaseAddress, NEO::EncodeSurfaceState<FamilyType>::getSurfaceBaseAddressAlignment());
size_t expectedOffset = gpuBaseAddress - expectedAlignedAddress;
EXPECT_EQ(importPointer, hostAllocation->getUnderlyingBuffer());
EXPECT_EQ(expectedAlignedAddress, outData.alignedAllocationPtr);
EXPECT_EQ(hostAllocation, outData.alloc);
EXPECT_EQ(expectedOffset, outData.offset);
outData = commandList->getAlignedAllocation(device, offsetPointer, offsetSize);
expectedOffset += allocOffset;
EXPECT_EQ(importPointer, hostAllocation->getUnderlyingBuffer());
EXPECT_EQ(expectedAlignedAddress, outData.alignedAllocationPtr);
EXPECT_EQ(hostAllocation, outData.alloc);
EXPECT_EQ(expectedOffset, outData.offset);
ret = hostDriverHandle->releaseImportedPointer(importPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
}
HWTEST2_F(HostPointerManagerCommandListTest,
givenHostPointerImportedWhenGettingPointerFromAnotherPageThenRetrieveBaseAddressAndProperOffset,
Platforms) {
auto commandList = std::make_unique<::L0::ult::CommandListCoreFamily<gfxCoreFamily>>();
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
size_t pointerSize = MemoryConstants::pageSize;
size_t offset = 100u + 2 * MemoryConstants::pageSize;
void *offsetPointer = ptrOffset(heapPointer, offset);
auto ret = hostDriverHandle->importExternalPointer(heapPointer, heapSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
auto hostAllocation = hostDriverHandle->findHostPointerAllocation(offsetPointer, pointerSize, device->getRootDeviceIndex());
ASSERT_NE(nullptr, hostAllocation);
AlignedAllocationData outData = commandList->getAlignedAllocation(device, offsetPointer, pointerSize);
auto expectedAlignedAddress = static_cast<uintptr_t>(hostAllocation->getGpuAddress());
EXPECT_EQ(heapPointer, hostAllocation->getUnderlyingBuffer());
EXPECT_EQ(expectedAlignedAddress, outData.alignedAllocationPtr);
EXPECT_EQ(hostAllocation, outData.alloc);
EXPECT_EQ(offset, outData.offset);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
}
HWTEST2_F(HostPointerManagerCommandListTest, givenCommandListWhenMemoryFillWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsFound, Platforms) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
auto &commandContainer = commandList->commandContainer;
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, &events[1]);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
EXPECT_NE(cmdList.end(), itor);
}
using SupportedPlatforms = IsWithinProducts<IGFX_SKYLAKE, IGFX_ICELAKE>;
HWTEST2_F(HostPointerManagerCommandListTest, givenCommandListWhenMemoryFillWithSignalAndInvalidWaitHandleUsingRenderEngineThenErrorIsReturnedAndPipeControlIsNotAdded, SupportedPlatforms) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
auto &commandContainer = commandList->commandContainer;
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, nullptr);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
EXPECT_NE(cmdList.end(), itor);
itor++;
itor = find<PIPE_CONTROL *>(itor, cmdList.end());
EXPECT_NE(cmdList.end(), itor);
itor++;
itor = find<PIPE_CONTROL *>(itor, cmdList.end());
EXPECT_EQ(cmdList.end(), itor);
}
HWTEST2_F(HostPointerManagerCommandListTest, givenCommandListWhenMemoryFillWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned, Platforms) {
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::Copy);
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, &events[1]);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
}
using SupportedPlatforms = IsWithinProducts<IGFX_SKYLAKE, IGFX_ICELAKE>;
HWTEST2_F(HostPointerManagerCommandListTest, givenCommandListWhenMemoryFillWithSignalAndiInvalidWaitHandleUsingCopyEngineThenErrorIsReturned, SupportedPlatforms) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::Copy);
auto &commandContainer = commandList->commandContainer;
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, nullptr);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
EXPECT_EQ(cmdList.end(), itor);
}
HWTEST2_F(HostPointerManagerCommandListTest, givenImmediateCommandListWhenMemoryFillWithSignalAndWaitEventsUsingRenderEngineThenSuccessIsReturned, Platforms) {
Mock<CommandQueue> cmdQueue;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<L0::CommandListCoreFamilyImmediate<gfxCoreFamily>>>();
ASSERT_NE(nullptr, commandList);
ze_result_t ret = commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
ASSERT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->device = device;
commandList->cmdQImmediate = &cmdQueue;
commandList->cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
EXPECT_CALL(cmdQueue, executeCommandLists).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
EXPECT_CALL(cmdQueue, synchronize).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, &events[1]);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->cmdQImmediate = nullptr;
}
HWTEST2_F(HostPointerManagerCommandListTest, givenImmediateCommandListWhenMemoryFillWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned, Platforms) {
Mock<CommandQueue> cmdQueue;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<L0::CommandListCoreFamilyImmediate<gfxCoreFamily>>>();
ASSERT_NE(nullptr, commandList);
ze_result_t ret = commandList->initialize(device, NEO::EngineGroupType::Copy);
ASSERT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->device = device;
commandList->cmdQImmediate = &cmdQueue;
commandList->cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
EXPECT_CALL(cmdQueue, executeCommandLists).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
EXPECT_CALL(cmdQueue, synchronize).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, &events[1]);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->cmdQImmediate = nullptr;
}
using SupportedPlatforms = IsWithinProducts<IGFX_SKYLAKE, IGFX_ICELAKE>;
HWTEST2_F(HostPointerManagerCommandListTest, givenImmediateCommandListWhenMemoryFillWithSignalAndInvalidWaitHandleUsingCopyEngineThenErrorIsReturned, SupportedPlatforms) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
Mock<CommandQueue> cmdQueue;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<L0::CommandListCoreFamilyImmediate<gfxCoreFamily>>>();
ASSERT_NE(nullptr, commandList);
ze_result_t ret = commandList->initialize(device, NEO::EngineGroupType::Copy);
auto &commandContainer = commandList->commandContainer;
ASSERT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->device = device;
commandList->cmdQImmediate = &cmdQueue;
commandList->cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, nullptr);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
EXPECT_EQ(cmdList.end(), itor);
commandList->cmdQImmediate = nullptr;
}
HWTEST2_F(HostPointerManagerCommandListTest, givenDebugModeToRegisterAllHostPointerWhenFindIsCalledThenRegisterHappens, Platforms) {
DebugManagerStateRestore restorer;
DebugManager.flags.ForceHostPointerImport.set(1);
void *testPtr = heapPointer;
auto gfxAllocation = hostDriverHandle->findHostPointerAllocation(testPtr, 0x10u, device->getRootDeviceIndex());
EXPECT_NE(nullptr, gfxAllocation);
EXPECT_EQ(testPtr, gfxAllocation->getUnderlyingBuffer());
auto result = hostDriverHandle->releaseImportedPointer(testPtr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
} // namespace ult
} // namespace L0

View File

@@ -0,0 +1,575 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
#include "test.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
namespace L0 {
namespace ult {
using Platforms = IsAtLeastProduct<IGFX_SKYLAKE>;
using CommandListCreate = Test<DeviceFixture>;
HWTEST2_F(CommandListCreate, givenCopyOnlyCommandListWhenAppendWriteGlobalTimestampCalledThenMiFlushDWWithTimestampEncoded, Platforms) {
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
using MI_FLUSH_DW = typename GfxFamily::MI_FLUSH_DW;
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, returnValue));
auto &commandContainer = commandList->commandContainer;
uint64_t timestampAddress = 0xfffffffffff0L;
uint64_t *dstptr = reinterpret_cast<uint64_t *>(timestampAddress);
const auto commandStreamOffset = commandContainer.getCommandStream()->getUsed();
commandList->appendWriteGlobalTimestamp(dstptr, nullptr, 0, nullptr);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList,
ptrOffset(commandContainer.getCommandStream()->getCpuBase(), commandStreamOffset),
commandContainer.getCommandStream()->getUsed() - commandStreamOffset));
auto iterator = findAll<MI_FLUSH_DW *>(cmdList.begin(), cmdList.end());
bool postSyncFound = false;
ASSERT_NE(0u, iterator.size());
for (auto it : iterator) {
auto cmd = genCmdCast<MI_FLUSH_DW *>(*it);
if ((cmd->getPostSyncOperation() == MI_FLUSH_DW::POST_SYNC_OPERATION_WRITE_TIMESTAMP_REGISTER) &&
(cmd->getDestinationAddress() == timestampAddress)) {
postSyncFound = true;
}
}
ASSERT_TRUE(postSyncFound);
}
HWTEST2_F(CommandListCreate, givenCommandListWhenAppendWriteGlobalTimestampCalledThenPipeControlWithTimestampWriteEncoded, Platforms) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
using POST_SYNC_OPERATION = typename PIPE_CONTROL::POST_SYNC_OPERATION;
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
auto &commandContainer = commandList->commandContainer;
uint64_t timestampAddress = 0x12345678555500;
uint32_t timestampAddressLow = (uint32_t)(timestampAddress & 0xFFFFFFFF);
uint32_t timestampAddressHigh = (uint32_t)(timestampAddress >> 32);
uint64_t *dstptr = reinterpret_cast<uint64_t *>(timestampAddress);
const auto commandStreamOffset = commandContainer.getCommandStream()->getUsed();
commandList->appendWriteGlobalTimestamp(dstptr, nullptr, 0, nullptr);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList,
ptrOffset(commandContainer.getCommandStream()->getCpuBase(), commandStreamOffset),
commandContainer.getCommandStream()->getUsed() - commandStreamOffset));
auto iterator = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
auto cmd = genCmdCast<PIPE_CONTROL *>(*iterator);
EXPECT_TRUE(cmd->getCommandStreamerStallEnable());
EXPECT_FALSE(cmd->getDcFlushEnable());
EXPECT_EQ(cmd->getAddressHigh(), timestampAddressHigh);
EXPECT_EQ(cmd->getAddress(), timestampAddressLow);
EXPECT_EQ(POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_TIMESTAMP, cmd->getPostSyncOperation());
}
HWTEST2_F(CommandListCreate, givenCommandListWhenAppendWriteGlobalTimestampCalledThenTimestampAllocationIsInsideResidencyContainer, Platforms) {
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
uint64_t timestampAddress = 0x12345678555500;
uint64_t *dstptr = reinterpret_cast<uint64_t *>(timestampAddress);
commandList->appendWriteGlobalTimestamp(dstptr, nullptr, 0, nullptr);
auto &commandContainer = commandList->commandContainer;
auto &residencyContainer = commandContainer.getResidencyContainer();
const bool addressIsInContainer = std::any_of(residencyContainer.begin(), residencyContainer.end(), [timestampAddress](NEO::GraphicsAllocation *alloc) {
return alloc->getGpuAddress() == timestampAddress;
});
EXPECT_TRUE(addressIsInContainer);
}
HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenAppendWriteGlobalTimestampThenReturnsSuccess, Platforms) {
Mock<CommandQueue> cmdQueue;
uint64_t timestampAddress = 0x12345678555500;
uint64_t *dstptr = reinterpret_cast<uint64_t *>(timestampAddress);
auto commandList = std::make_unique<WhiteBox<L0::CommandListCoreFamilyImmediate<gfxCoreFamily>>>();
ASSERT_NE(nullptr, commandList);
ze_result_t ret = commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
ASSERT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->device = device;
commandList->cmdQImmediate = &cmdQueue;
commandList->cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
EXPECT_CALL(cmdQueue, executeCommandLists).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
EXPECT_CALL(cmdQueue, synchronize).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
auto result = commandList->appendWriteGlobalTimestamp(dstptr, nullptr, 0, nullptr);
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
commandList->cmdQImmediate = nullptr;
}
HWTEST_F(CommandListCreate, GivenCommandListWhenUnalignedPtrThenLeftMiddleAndRightCopyAdded) {
using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT;
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, returnValue));
ASSERT_NE(nullptr, commandList);
EXPECT_EQ(device, commandList->device);
void *srcPtr = reinterpret_cast<void *>(0x4321);
void *dstPtr = reinterpret_cast<void *>(0x2345);
auto result = commandList->appendMemoryCopy(dstPtr, srcPtr, 2 * MemoryConstants::cacheLineSize, nullptr, 0, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandList->commandContainer.getCommandStream()->getCpuBase(), 0), commandList->commandContainer.getCommandStream()->getUsed()));
auto itor = find<XY_COPY_BLT *>(cmdList.begin(), cmdList.end());
EXPECT_NE(cmdList.end(), itor);
itor = find<XY_COPY_BLT *>(++itor, cmdList.end());
EXPECT_NE(cmdList.end(), itor);
itor = find<XY_COPY_BLT *>(++itor, cmdList.end());
EXPECT_NE(cmdList.end(), itor);
}
using HostPointerManagerCommandListTest = Test<HostPointerManagerFixure>;
HWTEST2_F(HostPointerManagerCommandListTest,
givenImportedHostPointerWhenAppendMemoryFillUsingHostPointerThenAppendFillUsingHostPointerAllocation,
Platforms) {
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int pattern = 1;
ret = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&pattern), sizeof(pattern), 64u, nullptr, 0, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
}
HWTEST2_F(HostPointerManagerCommandListTest,
givenImportedHostPointerAndCopyEngineWhenAppendMemoryFillUsingHostPointerThenAppendFillUsingHostPointerAllocation,
Platforms) {
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::Copy);
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int pattern = 1;
ret = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&pattern), sizeof(pattern), 64u, nullptr, 0, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
}
HWTEST2_F(HostPointerManagerCommandListTest,
givenHostPointerImportedWhenGettingAlignedAllocationThenRetrieveProperOffsetAndAddress,
Platforms) {
auto commandList = std::make_unique<::L0::ult::CommandListCoreFamily<gfxCoreFamily>>();
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
size_t mainOffset = 100;
size_t importSize = 100;
void *importPointer = ptrOffset(heapPointer, mainOffset);
auto ret = hostDriverHandle->importExternalPointer(importPointer, importSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
auto hostAllocation = hostDriverHandle->findHostPointerAllocation(importPointer, importSize, device->getRootDeviceIndex());
ASSERT_NE(nullptr, hostAllocation);
size_t allocOffset = 10;
size_t offsetSize = 20;
void *offsetPointer = ptrOffset(importPointer, allocOffset);
AlignedAllocationData outData = commandList->getAlignedAllocation(device, importPointer, importSize);
auto gpuBaseAddress = static_cast<size_t>(hostAllocation->getGpuAddress());
auto expectedAlignedAddress = alignDown(gpuBaseAddress, NEO::EncodeSurfaceState<FamilyType>::getSurfaceBaseAddressAlignment());
size_t expectedOffset = gpuBaseAddress - expectedAlignedAddress;
EXPECT_EQ(importPointer, hostAllocation->getUnderlyingBuffer());
EXPECT_EQ(expectedAlignedAddress, outData.alignedAllocationPtr);
EXPECT_EQ(hostAllocation, outData.alloc);
EXPECT_EQ(expectedOffset, outData.offset);
outData = commandList->getAlignedAllocation(device, offsetPointer, offsetSize);
expectedOffset += allocOffset;
EXPECT_EQ(importPointer, hostAllocation->getUnderlyingBuffer());
EXPECT_EQ(expectedAlignedAddress, outData.alignedAllocationPtr);
EXPECT_EQ(hostAllocation, outData.alloc);
EXPECT_EQ(expectedOffset, outData.offset);
ret = hostDriverHandle->releaseImportedPointer(importPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
}
HWTEST2_F(HostPointerManagerCommandListTest,
givenHostPointerImportedWhenGettingPointerFromAnotherPageThenRetrieveBaseAddressAndProperOffset,
Platforms) {
auto commandList = std::make_unique<::L0::ult::CommandListCoreFamily<gfxCoreFamily>>();
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
size_t pointerSize = MemoryConstants::pageSize;
size_t offset = 100u + 2 * MemoryConstants::pageSize;
void *offsetPointer = ptrOffset(heapPointer, offset);
auto ret = hostDriverHandle->importExternalPointer(heapPointer, heapSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
auto hostAllocation = hostDriverHandle->findHostPointerAllocation(offsetPointer, pointerSize, device->getRootDeviceIndex());
ASSERT_NE(nullptr, hostAllocation);
AlignedAllocationData outData = commandList->getAlignedAllocation(device, offsetPointer, pointerSize);
auto expectedAlignedAddress = static_cast<uintptr_t>(hostAllocation->getGpuAddress());
EXPECT_EQ(heapPointer, hostAllocation->getUnderlyingBuffer());
EXPECT_EQ(expectedAlignedAddress, outData.alignedAllocationPtr);
EXPECT_EQ(hostAllocation, outData.alloc);
EXPECT_EQ(offset, outData.offset);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
}
HWTEST2_F(HostPointerManagerCommandListTest, givenCommandListWhenMemoryFillWithSignalAndWaitEventsUsingRenderEngineThenPipeControlIsFound, Platforms) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
auto &commandContainer = commandList->commandContainer;
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, &events[1]);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
EXPECT_NE(cmdList.end(), itor);
}
using SupportedPlatformsSklIcllp = IsWithinProducts<IGFX_SKYLAKE, IGFX_ICELAKE>;
HWTEST2_F(HostPointerManagerCommandListTest, givenCommandListWhenMemoryFillWithSignalAndInvalidWaitHandleUsingRenderEngineThenErrorIsReturnedAndPipeControlIsNotAdded, SupportedPlatformsSklIcllp) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
auto &commandContainer = commandList->commandContainer;
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, nullptr);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
EXPECT_NE(cmdList.end(), itor);
itor++;
itor = find<PIPE_CONTROL *>(itor, cmdList.end());
EXPECT_NE(cmdList.end(), itor);
itor++;
itor = find<PIPE_CONTROL *>(itor, cmdList.end());
EXPECT_EQ(cmdList.end(), itor);
}
HWTEST2_F(HostPointerManagerCommandListTest, givenCommandListWhenMemoryFillWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned, Platforms) {
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::Copy);
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, &events[1]);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
}
HWTEST2_F(HostPointerManagerCommandListTest, givenCommandListWhenMemoryFillWithSignalAndiInvalidWaitHandleUsingCopyEngineThenErrorIsReturned, SupportedPlatformsSklIcllp) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
commandList->initialize(device, NEO::EngineGroupType::Copy);
auto &commandContainer = commandList->commandContainer;
auto ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, nullptr);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
EXPECT_EQ(cmdList.end(), itor);
}
HWTEST2_F(HostPointerManagerCommandListTest, givenImmediateCommandListWhenMemoryFillWithSignalAndWaitEventsUsingRenderEngineThenSuccessIsReturned, Platforms) {
Mock<CommandQueue> cmdQueue;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<L0::CommandListCoreFamilyImmediate<gfxCoreFamily>>>();
ASSERT_NE(nullptr, commandList);
ze_result_t ret = commandList->initialize(device, NEO::EngineGroupType::RenderCompute);
ASSERT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->device = device;
commandList->cmdQImmediate = &cmdQueue;
commandList->cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
EXPECT_CALL(cmdQueue, executeCommandLists).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
EXPECT_CALL(cmdQueue, synchronize).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, &events[1]);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->cmdQImmediate = nullptr;
}
HWTEST2_F(HostPointerManagerCommandListTest, givenImmediateCommandListWhenMemoryFillWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned, Platforms) {
Mock<CommandQueue> cmdQueue;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<L0::CommandListCoreFamilyImmediate<gfxCoreFamily>>>();
ASSERT_NE(nullptr, commandList);
ze_result_t ret = commandList->initialize(device, NEO::EngineGroupType::Copy);
ASSERT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->device = device;
commandList->cmdQImmediate = &cmdQueue;
commandList->cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
EXPECT_CALL(cmdQueue, executeCommandLists).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
EXPECT_CALL(cmdQueue, synchronize).Times(1).WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, &events[1]);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->cmdQImmediate = nullptr;
}
HWTEST2_F(HostPointerManagerCommandListTest, givenImmediateCommandListWhenMemoryFillWithSignalAndInvalidWaitHandleUsingCopyEngineThenErrorIsReturned, SupportedPlatformsSklIcllp) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
Mock<CommandQueue> cmdQueue;
ze_result_t result = ZE_RESULT_SUCCESS;
auto commandList = std::make_unique<WhiteBox<L0::CommandListCoreFamilyImmediate<gfxCoreFamily>>>();
ASSERT_NE(nullptr, commandList);
ze_result_t ret = commandList->initialize(device, NEO::EngineGroupType::Copy);
auto &commandContainer = commandList->commandContainer;
ASSERT_EQ(ZE_RESULT_SUCCESS, ret);
commandList->device = device;
commandList->cmdQImmediate = &cmdQueue;
commandList->cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
ret = hostDriverHandle->importExternalPointer(heapPointer, MemoryConstants::pageSize);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
int one = 1;
size_t size = 16;
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 2;
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(hostDriverHandle.get(), context, 0, nullptr, &eventPoolDesc));
std::vector<ze_event_handle_t> events;
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event.get());
eventDesc.index = 1;
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
events.push_back(event1.get());
result = commandList->appendMemoryFill(heapPointer, reinterpret_cast<void *>(&one), sizeof(one), size,
events[0], 1u, nullptr);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
ret = hostDriverHandle->releaseImportedPointer(heapPointer);
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), commandContainer.getCommandStream()->getUsed()));
auto itor = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
EXPECT_EQ(cmdList.end(), itor);
commandList->cmdQImmediate = nullptr;
}
HWTEST2_F(HostPointerManagerCommandListTest, givenDebugModeToRegisterAllHostPointerWhenFindIsCalledThenRegisterHappens, Platforms) {
DebugManagerStateRestore restorer;
DebugManager.flags.ForceHostPointerImport.set(1);
void *testPtr = heapPointer;
auto gfxAllocation = hostDriverHandle->findHostPointerAllocation(testPtr, 0x10u, device->getRootDeviceIndex());
EXPECT_NE(nullptr, gfxAllocation);
EXPECT_EQ(testPtr, gfxAllocation->getUnderlyingBuffer());
auto result = hostDriverHandle->releaseImportedPointer(testPtr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
} // namespace ult
} // namespace L0

View File

@@ -8,6 +8,7 @@ set(IGDRCL_SRCS_tests_command_stream
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_1_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_2_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_3_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/aub_file_stream_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/aub_subcapture_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cmd_parse_tests.cpp
@@ -21,6 +22,7 @@ set(IGDRCL_SRCS_tests_command_stream
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_flush_task_1_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_flush_task_2_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_flush_task_3_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_flush_task_4_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_flush_task_gmock_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_with_aub_dump_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/create_command_stream_receiver_tests.cpp

View File

@@ -5,7 +5,6 @@
*
*/
#include "shared/source/aub_mem_dump/aub_alloc_dump.h"
#include "shared/source/aub_mem_dump/page_table_entry_bits.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/os_interface/os_context.h"
@@ -1180,245 +1179,3 @@ HWTEST_F(AubCommandStreamReceiverTests, givenDebugOverwritesForImplicitFlushesWh
EXPECT_FALSE(aubCsr->useGpuIdleImplicitFlush);
EXPECT_FALSE(aubCsr->useNewResourceImplicitFlush);
}
using AubCsrTest = ::testing::Test;
HWTEST_F(AubCsrTest, givenLocalMemoryEnabledWhenGettingAddressSpaceForRingDataTypeThenTraceLocalIsReturned) {
DebugManagerStateRestore restorer;
DebugManager.flags.EnableLocalMemory.set(1);
auto hwInfo = *NEO::defaultHwInfo.get();
hwInfo.featureTable.ftrLocalMemory = true;
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
DeviceBitfield deviceBitfield(1);
executionEnvironment->prepareRootDeviceEnvironments(1);
uint32_t rootDeviceIndex = 0u;
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(&hwInfo);
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->aubCenter.reset(new AubCenter());
executionEnvironment->initializeMemoryManager();
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>("", false, *executionEnvironment, rootDeviceIndex, deviceBitfield));
int types[] = {AubMemDump::DataTypeHintValues::TraceLogicalRingContextRcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextCcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextBcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextVcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextVecs,
AubMemDump::DataTypeHintValues::TraceCommandBuffer};
for (uint32_t i = 0; i < 6; i++) {
auto addressSpace = aubCsr->getAddressSpace(types[i]);
EXPECT_EQ(AubMemDump::AddressSpaceValues::TraceLocal, addressSpace);
}
auto addressSpace = aubCsr->getAddressSpace(AubMemDump::DataTypeHintValues::TraceNotype);
EXPECT_EQ(AubMemDump::AddressSpaceValues::TraceNonlocal, addressSpace);
}
HWTEST_F(AubCsrTest, givenAUBDumpForceAllToLocalMemoryWhenGettingAddressSpaceForAnyDataTypeThenTraceLocalIsReturned) {
DebugManagerStateRestore restorer;
DebugManager.flags.AUBDumpForceAllToLocalMemory.set(1);
auto hwInfo = *NEO::defaultHwInfo.get();
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
DeviceBitfield deviceBitfield(1);
executionEnvironment->prepareRootDeviceEnvironments(1);
uint32_t rootDeviceIndex = 0u;
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(&hwInfo);
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->aubCenter.reset(new AubCenter());
executionEnvironment->initializeMemoryManager();
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>("", false, *executionEnvironment, rootDeviceIndex, deviceBitfield));
int types[] = {AubMemDump::DataTypeHintValues::TraceLogicalRingContextRcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextCcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextBcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextVcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextVecs,
AubMemDump::DataTypeHintValues::TraceCommandBuffer};
for (uint32_t i = 0; i < 6; i++) {
auto addressSpace = aubCsr->getAddressSpace(types[i]);
EXPECT_EQ(AubMemDump::AddressSpaceValues::TraceLocal, addressSpace);
}
auto addressSpace = aubCsr->getAddressSpace(AubMemDump::DataTypeHintValues::TraceNotype);
EXPECT_EQ(AubMemDump::AddressSpaceValues::TraceLocal, addressSpace);
}
HWTEST_F(AubCsrTest, WhenWriteWithAubManagerIsCalledThenAubManagerIsInvokedWithCorrectHint) {
auto hwInfo = *NEO::defaultHwInfo.get();
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
DeviceBitfield deviceBitfield(1);
executionEnvironment->prepareRootDeviceEnvironments(1);
uint32_t rootDeviceIndex = 0u;
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(&hwInfo);
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->aubCenter.reset(new AubCenter());
executionEnvironment->initializeMemoryManager();
auto allocation = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, true, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::COMMAND_BUFFER});
MockAubManager aubManager;
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>("", false, *executionEnvironment, rootDeviceIndex, deviceBitfield));
aubCsr->aubManager = &aubManager;
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(aubCsr.get(),
EngineTypeUsage{getChosenEngineType(hwInfo), EngineUsage::Regular},
deviceBitfield,
PreemptionHelper::getDefaultPreemptionMode(hwInfo),
false);
aubCsr->setupContext(*osContext);
aubCsr->writeMemoryWithAubManager(*allocation);
EXPECT_TRUE(aubManager.writeMemory2Called);
EXPECT_EQ(AubMemDump::DataTypeHintValues::TraceBatchBuffer, aubManager.hintToWriteMemory);
aubManager.writeMemory2Called = false;
auto allocation2 = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, true, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::LINEAR_STREAM});
aubCsr->writeMemoryWithAubManager(*allocation2);
EXPECT_TRUE(aubManager.writeMemory2Called);
EXPECT_EQ(AubMemDump::DataTypeHintValues::TraceNotype, aubManager.hintToWriteMemory);
executionEnvironment->memoryManager->freeGraphicsMemory(allocation);
executionEnvironment->memoryManager->freeGraphicsMemory(allocation2);
}
using HardwareContextContainerTests = ::testing::Test;
TEST_F(HardwareContextContainerTests, givenOsContextWithMultipleDevicesSupportedThenInitialzeHwContextsWithValidIndexes) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b11, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextControler(aubManager, osContext, 0);
EXPECT_EQ(2u, hwContextControler.hardwareContexts.size());
EXPECT_EQ(2u, osContext.getNumSupportedDevices());
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextControler.hardwareContexts[0].get());
auto mockHwContext1 = static_cast<MockHardwareContext *>(hwContextControler.hardwareContexts[1].get());
EXPECT_EQ(0u, mockHwContext0->deviceIndex);
EXPECT_EQ(1u, mockHwContext1->deviceIndex);
}
TEST_F(HardwareContextContainerTests, givenSingleHwContextWhenSubmitMethodIsCalledOnHwContextControllerThenSubmitIsCalled) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextContainer(aubManager, osContext, 0);
EXPECT_EQ(1u, hwContextContainer.hardwareContexts.size());
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[0].get());
EXPECT_FALSE(mockHwContext0->writeAndSubmitCalled);
EXPECT_FALSE(mockHwContext0->writeMemory2Called);
hwContextContainer.submit(1, reinterpret_cast<const void *>(0x123), 2, 0, 1, false);
EXPECT_TRUE(mockHwContext0->submitCalled);
EXPECT_FALSE(mockHwContext0->writeAndSubmitCalled);
EXPECT_FALSE(mockHwContext0->writeMemory2Called);
}
TEST_F(HardwareContextContainerTests, givenSingleHwContextWhenWriteMemoryIsCalledThenWholeMemoryBanksArePassed) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextContainer(aubManager, osContext, 0);
EXPECT_EQ(1u, hwContextContainer.hardwareContexts.size());
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[0].get());
aub_stream::AllocationParams params(1, reinterpret_cast<const void *>(0x123), 2, 3u, 4, 5);
hwContextContainer.writeMemory(params);
EXPECT_TRUE(mockHwContext0->writeMemory2Called);
EXPECT_EQ(3u, mockHwContext0->memoryBanksPassed);
}
TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseAllContexts) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b11, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextContainer(aubManager, osContext, 0);
EXPECT_EQ(2u, hwContextContainer.hardwareContexts.size());
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[0].get());
auto mockHwContext1 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[1].get());
EXPECT_FALSE(mockHwContext0->initializeCalled);
EXPECT_FALSE(mockHwContext1->initializeCalled);
EXPECT_FALSE(mockHwContext0->pollForCompletionCalled);
EXPECT_FALSE(mockHwContext1->pollForCompletionCalled);
EXPECT_FALSE(mockHwContext0->expectMemoryCalled);
EXPECT_FALSE(mockHwContext1->expectMemoryCalled);
EXPECT_FALSE(mockHwContext0->submitCalled);
EXPECT_FALSE(mockHwContext1->submitCalled);
EXPECT_FALSE(mockHwContext0->writeMemory2Called);
EXPECT_FALSE(mockHwContext1->writeMemory2Called);
aub_stream::AllocationParams params(1, reinterpret_cast<const void *>(0x123), 2, 3u, 4, 5);
hwContextContainer.initialize();
hwContextContainer.pollForCompletion();
hwContextContainer.expectMemory(1, reinterpret_cast<const void *>(0x123), 2, 0);
hwContextContainer.submit(1, reinterpret_cast<const void *>(0x123), 2, 0, 1, false);
hwContextContainer.writeMemory(params);
EXPECT_TRUE(mockHwContext0->initializeCalled);
EXPECT_TRUE(mockHwContext1->initializeCalled);
EXPECT_TRUE(mockHwContext0->pollForCompletionCalled);
EXPECT_TRUE(mockHwContext1->pollForCompletionCalled);
EXPECT_TRUE(mockHwContext0->expectMemoryCalled);
EXPECT_TRUE(mockHwContext1->expectMemoryCalled);
EXPECT_TRUE(mockHwContext0->submitCalled);
EXPECT_TRUE(mockHwContext1->submitCalled);
EXPECT_TRUE(mockHwContext0->writeMemory2Called);
EXPECT_TRUE(mockHwContext1->writeMemory2Called);
EXPECT_EQ(1u, mockHwContext0->memoryBanksPassed);
EXPECT_EQ(2u, mockHwContext1->memoryBanksPassed);
}
TEST_F(HardwareContextContainerTests, givenHwContextWhenWriteMMIOIsCalledThenUseFirstContext) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextContainer(aubManager, osContext, 0);
EXPECT_EQ(1u, hwContextContainer.hardwareContexts.size());
auto mockHwContext = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[0].get());
EXPECT_FALSE(mockHwContext->writeMMIOCalled);
hwContextContainer.writeMMIO(0x01234567, 0x89ABCDEF);
EXPECT_TRUE(mockHwContext->writeMMIOCalled);
}
TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseFirstContext) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b11, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextContainer(aubManager, osContext, 0);
EXPECT_EQ(2u, hwContextContainer.hardwareContexts.size());
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[0].get());
auto mockHwContext1 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[1].get());
EXPECT_FALSE(mockHwContext0->dumpBufferBINCalled);
EXPECT_FALSE(mockHwContext1->dumpBufferBINCalled);
EXPECT_FALSE(mockHwContext0->dumpSurfaceCalled);
EXPECT_FALSE(mockHwContext1->dumpSurfaceCalled);
EXPECT_FALSE(mockHwContext0->readMemoryCalled);
EXPECT_FALSE(mockHwContext1->readMemoryCalled);
hwContextContainer.dumpBufferBIN(1, 2);
hwContextContainer.dumpSurface({1, 2, 3, 4, 5, 6, 7, false, 0});
hwContextContainer.readMemory(1, reinterpret_cast<void *>(0x123), 1, 2, 0);
EXPECT_TRUE(mockHwContext0->dumpBufferBINCalled);
EXPECT_FALSE(mockHwContext1->dumpBufferBINCalled);
EXPECT_TRUE(mockHwContext0->dumpSurfaceCalled);
EXPECT_FALSE(mockHwContext1->dumpSurfaceCalled);
EXPECT_TRUE(mockHwContext0->readMemoryCalled);
EXPECT_FALSE(mockHwContext1->readMemoryCalled);
}

View File

@@ -5,7 +5,6 @@
*
*/
#include "shared/source/aub_mem_dump/aub_alloc_dump.h"
#include "shared/source/aub_mem_dump/page_table_entry_bits.h"
#include "shared/source/helpers/engine_node_helper.h"
#include "shared/source/helpers/hw_helper.h"
@@ -33,7 +32,6 @@
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_os_context.h"
#include "opencl/test/unit_test/mocks/mock_platform.h"
#include "opencl/test/unit_test/mocks/mock_svm_manager.h"
#include "test.h"
#include "third_party/aub_stream/headers/aubstream.h"
@@ -1009,316 +1007,3 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWithHardwar
EXPECT_TRUE(mockHardwareContext->writeMMIOCalled);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenGraphicsAllocationShouldBeDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenBcsEngineWhenDumpAllocationCalledThenIgnore) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenCompressedGraphicsAllocationWritableWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenGraphicsAllocationShouldBeDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("TRE");
auto gmmHelper = pDevice->executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper();
MockAubCenter *mockAubCenter = new MockAubCenter(defaultHwInfo.get(), *gmmHelper, false, "aubfile", CommandStreamReceiverType::CSR_AUB);
mockAubCenter->aubManager = std::make_unique<MockAubManager>();
pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledButDumpFormatIsNotSpecifiedThenGraphicsAllocationShouldNotBeDumped) {
DebugManagerStateRestore dbgRestore;
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNonWritableWhenDumpAllocationIsCalledAndFormatIsSpecifiedThenGraphicsAllocationShouldNotBeDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(false);
EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNotDumpableWhenDumpAllocationIsCalledAndAUBDumpAllocsOnEnqueueReadOnlyIsSetThenGraphicsAllocationShouldNotBeDumpedAndRemainNonDumpable) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true);
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
gfxAllocation->setAllocDumpable(false, false);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(gfxAllocation->isAllocDumpable());
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpAllocationIsCalledAndAUBDumpAllocsOnEnqueueReadOnlyIsOnThenGraphicsAllocationShouldBeDumpedAndMarkedNonDumpable) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true);
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
auto &csrOsContext = aubCsr.getOsContext();
{
// Non-BCS engine, BCS dump
EXPECT_FALSE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, true);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(gfxAllocation->isAllocDumpable());
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
}
{
// Non-BCS engine, Non-BCS dump
EXPECT_FALSE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, false);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(gfxAllocation->isAllocDumpable());
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
mockHardwareContext->dumpSurfaceCalled = false;
}
{
// BCS engine, Non-BCS dump
csrOsContext.getEngineType() = aub_stream::EngineType::ENGINE_BCS;
EXPECT_TRUE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, false);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(gfxAllocation->isAllocDumpable());
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
}
{
// BCS engine, BCS dump
csrOsContext.getEngineType() = aub_stream::EngineType::ENGINE_BCS;
EXPECT_TRUE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, true);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(gfxAllocation->isAllocDumpable());
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
}
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWhenDumpAllocationIsCalledAndAUBDumpAllocsOnEnqueueSVMMemcpyOnlyIsSetThenDumpableFlagShouldBeRespected) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpAllocsOnEnqueueSVMMemcpyOnly.set(true);
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
gfxAllocation->setAllocDumpable(false, false);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
EXPECT_FALSE(gfxAllocation->isAllocDumpable());
gfxAllocation->setAllocDumpable(true, false);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(gfxAllocation->isAllocDumpable());
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenPollForCompletionShouldBeCalledBeforeGraphicsAllocationIsDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
aubCsr.latestSentTaskCount = 1;
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(mockHardwareContext->pollForCompletionCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenUsmAllocationWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenUsmAllocationIsDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = std::make_unique<MockMemoryManager>(false, true, *pDevice->executionEnvironment);
auto svmManager = std::make_unique<MockSVMAllocsManager>(memoryManager.get(), false);
std::set<uint32_t> rootDeviceIndices{rootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{rootDeviceIndex, pDevice->getDeviceBitfield()}};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
auto ptr = svmManager->createUnifiedMemoryAllocation(4096, unifiedMemoryProperties);
ASSERT_NE(nullptr, ptr);
auto gfxAllocation = svmManager->getSVMAlloc(ptr)->gpuAllocations.getGraphicsAllocation(0);
ASSERT_NE(nullptr, gfxAllocation);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
svmManager->freeSVMAlloc(ptr);
}
using SimulatedCsrTest = ::testing::Test;
HWTEST_F(SimulatedCsrTest, givenAubCsrTypeWhenCreateCommandStreamReceiverThenProperAubCenterIsInitalized) {
uint32_t expectedRootDeviceIndex = 10;
MockExecutionEnvironment executionEnvironment;
executionEnvironment.initializeMemoryManager();
executionEnvironment.prepareRootDeviceEnvironments(expectedRootDeviceIndex + 2);
auto rootDeviceEnvironment = new MockRootDeviceEnvironment(executionEnvironment);
executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex].reset(rootDeviceEnvironment);
rootDeviceEnvironment->setHwInfo(defaultHwInfo.get());
EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex]->aubCenter.get());
EXPECT_FALSE(rootDeviceEnvironment->initAubCenterCalled);
DeviceBitfield deviceBitfield(1);
auto csr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>("", true, executionEnvironment, expectedRootDeviceIndex, deviceBitfield);
EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled);
EXPECT_NE(nullptr, executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex]->aubCenter.get());
}

View File

@@ -0,0 +1,577 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/aub_mem_dump/aub_alloc_dump.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_aub_manager.h"
#include "opencl/source/helpers/hardware_context_controller.h"
#include "opencl/test/unit_test/fixtures/aub_command_stream_receiver_fixture.h"
#include "opencl/test/unit_test/mocks/mock_aub_csr.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_os_context.h"
#include "opencl/test/unit_test/mocks/mock_svm_manager.h"
#include "test.h"
using namespace NEO;
using AubCsrTest = ::testing::Test;
HWTEST_F(AubCsrTest, givenLocalMemoryEnabledWhenGettingAddressSpaceForRingDataTypeThenTraceLocalIsReturned) {
DebugManagerStateRestore restorer;
DebugManager.flags.EnableLocalMemory.set(1);
auto hwInfo = *NEO::defaultHwInfo.get();
hwInfo.featureTable.ftrLocalMemory = true;
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
DeviceBitfield deviceBitfield(1);
executionEnvironment->prepareRootDeviceEnvironments(1);
uint32_t rootDeviceIndex = 0u;
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(&hwInfo);
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->aubCenter.reset(new AubCenter());
executionEnvironment->initializeMemoryManager();
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>("", false, *executionEnvironment, rootDeviceIndex, deviceBitfield));
int types[] = {AubMemDump::DataTypeHintValues::TraceLogicalRingContextRcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextCcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextBcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextVcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextVecs,
AubMemDump::DataTypeHintValues::TraceCommandBuffer};
for (uint32_t i = 0; i < 6; i++) {
auto addressSpace = aubCsr->getAddressSpace(types[i]);
EXPECT_EQ(AubMemDump::AddressSpaceValues::TraceLocal, addressSpace);
}
auto addressSpace = aubCsr->getAddressSpace(AubMemDump::DataTypeHintValues::TraceNotype);
EXPECT_EQ(AubMemDump::AddressSpaceValues::TraceNonlocal, addressSpace);
}
HWTEST_F(AubCsrTest, givenAUBDumpForceAllToLocalMemoryWhenGettingAddressSpaceForAnyDataTypeThenTraceLocalIsReturned) {
DebugManagerStateRestore restorer;
DebugManager.flags.AUBDumpForceAllToLocalMemory.set(1);
auto hwInfo = *NEO::defaultHwInfo.get();
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
DeviceBitfield deviceBitfield(1);
executionEnvironment->prepareRootDeviceEnvironments(1);
uint32_t rootDeviceIndex = 0u;
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(&hwInfo);
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->aubCenter.reset(new AubCenter());
executionEnvironment->initializeMemoryManager();
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>("", false, *executionEnvironment, rootDeviceIndex, deviceBitfield));
int types[] = {AubMemDump::DataTypeHintValues::TraceLogicalRingContextRcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextCcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextBcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextVcs,
AubMemDump::DataTypeHintValues::TraceLogicalRingContextVecs,
AubMemDump::DataTypeHintValues::TraceCommandBuffer};
for (uint32_t i = 0; i < 6; i++) {
auto addressSpace = aubCsr->getAddressSpace(types[i]);
EXPECT_EQ(AubMemDump::AddressSpaceValues::TraceLocal, addressSpace);
}
auto addressSpace = aubCsr->getAddressSpace(AubMemDump::DataTypeHintValues::TraceNotype);
EXPECT_EQ(AubMemDump::AddressSpaceValues::TraceLocal, addressSpace);
}
HWTEST_F(AubCsrTest, WhenWriteWithAubManagerIsCalledThenAubManagerIsInvokedWithCorrectHint) {
auto hwInfo = *NEO::defaultHwInfo.get();
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
DeviceBitfield deviceBitfield(1);
executionEnvironment->prepareRootDeviceEnvironments(1);
uint32_t rootDeviceIndex = 0u;
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(&hwInfo);
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->aubCenter.reset(new AubCenter());
executionEnvironment->initializeMemoryManager();
auto allocation = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, true, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::COMMAND_BUFFER});
MockAubManager aubManager;
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>("", false, *executionEnvironment, rootDeviceIndex, deviceBitfield));
aubCsr->aubManager = &aubManager;
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(aubCsr.get(),
EngineTypeUsage{getChosenEngineType(hwInfo), EngineUsage::Regular},
deviceBitfield,
PreemptionHelper::getDefaultPreemptionMode(hwInfo),
false);
aubCsr->setupContext(*osContext);
aubCsr->writeMemoryWithAubManager(*allocation);
EXPECT_TRUE(aubManager.writeMemory2Called);
EXPECT_EQ(AubMemDump::DataTypeHintValues::TraceBatchBuffer, aubManager.hintToWriteMemory);
aubManager.writeMemory2Called = false;
auto allocation2 = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, true, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::LINEAR_STREAM});
aubCsr->writeMemoryWithAubManager(*allocation2);
EXPECT_TRUE(aubManager.writeMemory2Called);
EXPECT_EQ(AubMemDump::DataTypeHintValues::TraceNotype, aubManager.hintToWriteMemory);
executionEnvironment->memoryManager->freeGraphicsMemory(allocation);
executionEnvironment->memoryManager->freeGraphicsMemory(allocation2);
}
using HardwareContextContainerTests = ::testing::Test;
TEST_F(HardwareContextContainerTests, givenOsContextWithMultipleDevicesSupportedThenInitialzeHwContextsWithValidIndexes) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b11, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextControler(aubManager, osContext, 0);
EXPECT_EQ(2u, hwContextControler.hardwareContexts.size());
EXPECT_EQ(2u, osContext.getNumSupportedDevices());
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextControler.hardwareContexts[0].get());
auto mockHwContext1 = static_cast<MockHardwareContext *>(hwContextControler.hardwareContexts[1].get());
EXPECT_EQ(0u, mockHwContext0->deviceIndex);
EXPECT_EQ(1u, mockHwContext1->deviceIndex);
}
TEST_F(HardwareContextContainerTests, givenSingleHwContextWhenSubmitMethodIsCalledOnHwContextControllerThenSubmitIsCalled) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextContainer(aubManager, osContext, 0);
EXPECT_EQ(1u, hwContextContainer.hardwareContexts.size());
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[0].get());
EXPECT_FALSE(mockHwContext0->writeAndSubmitCalled);
EXPECT_FALSE(mockHwContext0->writeMemory2Called);
hwContextContainer.submit(1, reinterpret_cast<const void *>(0x123), 2, 0, 1, false);
EXPECT_TRUE(mockHwContext0->submitCalled);
EXPECT_FALSE(mockHwContext0->writeAndSubmitCalled);
EXPECT_FALSE(mockHwContext0->writeMemory2Called);
}
TEST_F(HardwareContextContainerTests, givenSingleHwContextWhenWriteMemoryIsCalledThenWholeMemoryBanksArePassed) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextContainer(aubManager, osContext, 0);
EXPECT_EQ(1u, hwContextContainer.hardwareContexts.size());
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[0].get());
aub_stream::AllocationParams params(1, reinterpret_cast<const void *>(0x123), 2, 3u, 4, 5);
hwContextContainer.writeMemory(params);
EXPECT_TRUE(mockHwContext0->writeMemory2Called);
EXPECT_EQ(3u, mockHwContext0->memoryBanksPassed);
}
TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseAllContexts) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b11, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextContainer(aubManager, osContext, 0);
EXPECT_EQ(2u, hwContextContainer.hardwareContexts.size());
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[0].get());
auto mockHwContext1 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[1].get());
EXPECT_FALSE(mockHwContext0->initializeCalled);
EXPECT_FALSE(mockHwContext1->initializeCalled);
EXPECT_FALSE(mockHwContext0->pollForCompletionCalled);
EXPECT_FALSE(mockHwContext1->pollForCompletionCalled);
EXPECT_FALSE(mockHwContext0->expectMemoryCalled);
EXPECT_FALSE(mockHwContext1->expectMemoryCalled);
EXPECT_FALSE(mockHwContext0->submitCalled);
EXPECT_FALSE(mockHwContext1->submitCalled);
EXPECT_FALSE(mockHwContext0->writeMemory2Called);
EXPECT_FALSE(mockHwContext1->writeMemory2Called);
aub_stream::AllocationParams params(1, reinterpret_cast<const void *>(0x123), 2, 3u, 4, 5);
hwContextContainer.initialize();
hwContextContainer.pollForCompletion();
hwContextContainer.expectMemory(1, reinterpret_cast<const void *>(0x123), 2, 0);
hwContextContainer.submit(1, reinterpret_cast<const void *>(0x123), 2, 0, 1, false);
hwContextContainer.writeMemory(params);
EXPECT_TRUE(mockHwContext0->initializeCalled);
EXPECT_TRUE(mockHwContext1->initializeCalled);
EXPECT_TRUE(mockHwContext0->pollForCompletionCalled);
EXPECT_TRUE(mockHwContext1->pollForCompletionCalled);
EXPECT_TRUE(mockHwContext0->expectMemoryCalled);
EXPECT_TRUE(mockHwContext1->expectMemoryCalled);
EXPECT_TRUE(mockHwContext0->submitCalled);
EXPECT_TRUE(mockHwContext1->submitCalled);
EXPECT_TRUE(mockHwContext0->writeMemory2Called);
EXPECT_TRUE(mockHwContext1->writeMemory2Called);
EXPECT_EQ(1u, mockHwContext0->memoryBanksPassed);
EXPECT_EQ(2u, mockHwContext1->memoryBanksPassed);
}
TEST_F(HardwareContextContainerTests, givenHwContextWhenWriteMMIOIsCalledThenUseFirstContext) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextContainer(aubManager, osContext, 0);
EXPECT_EQ(1u, hwContextContainer.hardwareContexts.size());
auto mockHwContext = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[0].get());
EXPECT_FALSE(mockHwContext->writeMMIOCalled);
hwContextContainer.writeMMIO(0x01234567, 0x89ABCDEF);
EXPECT_TRUE(mockHwContext->writeMMIOCalled);
}
TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseFirstContext) {
MockAubManager aubManager;
MockOsContext osContext(1, 0b11, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
HardwareContextController hwContextContainer(aubManager, osContext, 0);
EXPECT_EQ(2u, hwContextContainer.hardwareContexts.size());
auto mockHwContext0 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[0].get());
auto mockHwContext1 = static_cast<MockHardwareContext *>(hwContextContainer.hardwareContexts[1].get());
EXPECT_FALSE(mockHwContext0->dumpBufferBINCalled);
EXPECT_FALSE(mockHwContext1->dumpBufferBINCalled);
EXPECT_FALSE(mockHwContext0->dumpSurfaceCalled);
EXPECT_FALSE(mockHwContext1->dumpSurfaceCalled);
EXPECT_FALSE(mockHwContext0->readMemoryCalled);
EXPECT_FALSE(mockHwContext1->readMemoryCalled);
hwContextContainer.dumpBufferBIN(1, 2);
hwContextContainer.dumpSurface({1, 2, 3, 4, 5, 6, 7, false, 0});
hwContextContainer.readMemory(1, reinterpret_cast<void *>(0x123), 1, 2, 0);
EXPECT_TRUE(mockHwContext0->dumpBufferBINCalled);
EXPECT_FALSE(mockHwContext1->dumpBufferBINCalled);
EXPECT_TRUE(mockHwContext0->dumpSurfaceCalled);
EXPECT_FALSE(mockHwContext1->dumpSurfaceCalled);
EXPECT_TRUE(mockHwContext0->readMemoryCalled);
EXPECT_FALSE(mockHwContext1->readMemoryCalled);
}
using AubCommandStreamReceiverTests = Test<AubCommandStreamReceiverFixture>;
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenGraphicsAllocationShouldBeDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenBcsEngineWhenDumpAllocationCalledThenIgnore) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenCompressedGraphicsAllocationWritableWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenGraphicsAllocationShouldBeDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("TRE");
auto gmmHelper = pDevice->executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper();
MockAubCenter *mockAubCenter = new MockAubCenter(defaultHwInfo.get(), *gmmHelper, false, "aubfile", CommandStreamReceiverType::CSR_AUB);
mockAubCenter->aubManager = std::make_unique<MockAubManager>();
pDevice->executionEnvironment->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter);
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledButDumpFormatIsNotSpecifiedThenGraphicsAllocationShouldNotBeDumped) {
DebugManagerStateRestore dbgRestore;
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNonWritableWhenDumpAllocationIsCalledAndFormatIsSpecifiedThenGraphicsAllocationShouldNotBeDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(false);
EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNotDumpableWhenDumpAllocationIsCalledAndAUBDumpAllocsOnEnqueueReadOnlyIsSetThenGraphicsAllocationShouldNotBeDumpedAndRemainNonDumpable) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true);
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
gfxAllocation->setAllocDumpable(false, false);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(gfxAllocation->isAllocDumpable());
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpAllocationIsCalledAndAUBDumpAllocsOnEnqueueReadOnlyIsOnThenGraphicsAllocationShouldBeDumpedAndMarkedNonDumpable) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true);
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
auto &csrOsContext = aubCsr.getOsContext();
{
// Non-BCS engine, BCS dump
EXPECT_FALSE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, true);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(gfxAllocation->isAllocDumpable());
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
}
{
// Non-BCS engine, Non-BCS dump
EXPECT_FALSE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, false);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(gfxAllocation->isAllocDumpable());
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
mockHardwareContext->dumpSurfaceCalled = false;
}
{
// BCS engine, Non-BCS dump
csrOsContext.getEngineType() = aub_stream::EngineType::ENGINE_BCS;
EXPECT_TRUE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, false);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(gfxAllocation->isAllocDumpable());
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
}
{
// BCS engine, BCS dump
csrOsContext.getEngineType() = aub_stream::EngineType::ENGINE_BCS;
EXPECT_TRUE(EngineHelpers::isBcs(csrOsContext.getEngineType()));
gfxAllocation->setAllocDumpable(true, true);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(gfxAllocation->isAllocDumpable());
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
}
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWhenDumpAllocationIsCalledAndAUBDumpAllocsOnEnqueueSVMMemcpyOnlyIsSetThenDumpableFlagShouldBeRespected) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpAllocsOnEnqueueSVMMemcpyOnly.set(true);
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
gfxAllocation->setAllocDumpable(false, false);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(mockHardwareContext->dumpSurfaceCalled);
EXPECT_FALSE(gfxAllocation->isAllocDumpable());
gfxAllocation->setAllocDumpable(true, false);
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_FALSE(gfxAllocation->isAllocDumpable());
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenPollForCompletionShouldBeCalledBeforeGraphicsAllocationIsDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
aubCsr.latestSentTaskCount = 1;
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties({pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield()});
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(mockHardwareContext->pollForCompletionCalled);
memoryManager->freeGraphicsMemory(gfxAllocation);
}
HWTEST_F(AubCommandStreamReceiverTests, givenUsmAllocationWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenUsmAllocationIsDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
MockOsContext osContext(0, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
aubCsr.setupContext(osContext);
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
auto memoryManager = std::make_unique<MockMemoryManager>(false, true, *pDevice->executionEnvironment);
auto svmManager = std::make_unique<MockSVMAllocsManager>(memoryManager.get(), false);
std::set<uint32_t> rootDeviceIndices{rootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{rootDeviceIndex, pDevice->getDeviceBitfield()}};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields);
auto ptr = svmManager->createUnifiedMemoryAllocation(4096, unifiedMemoryProperties);
ASSERT_NE(nullptr, ptr);
auto gfxAllocation = svmManager->getSVMAlloc(ptr)->gpuAllocations.getGraphicsAllocation(0);
ASSERT_NE(nullptr, gfxAllocation);
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
aubCsr.dumpAllocation(*gfxAllocation);
EXPECT_TRUE(mockHardwareContext->dumpSurfaceCalled);
svmManager->freeSVMAlloc(ptr);
}
using SimulatedCsrTest = ::testing::Test;
HWTEST_F(SimulatedCsrTest, givenAubCsrTypeWhenCreateCommandStreamReceiverThenProperAubCenterIsInitalized) {
uint32_t expectedRootDeviceIndex = 10;
MockExecutionEnvironment executionEnvironment;
executionEnvironment.initializeMemoryManager();
executionEnvironment.prepareRootDeviceEnvironments(expectedRootDeviceIndex + 2);
auto rootDeviceEnvironment = new MockRootDeviceEnvironment(executionEnvironment);
executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex].reset(rootDeviceEnvironment);
rootDeviceEnvironment->setHwInfo(defaultHwInfo.get());
EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex]->aubCenter.get());
EXPECT_FALSE(rootDeviceEnvironment->initAubCenterCalled);
DeviceBitfield deviceBitfield(1);
auto csr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>("", true, executionEnvironment, expectedRootDeviceIndex, deviceBitfield);
EXPECT_TRUE(rootDeviceEnvironment->initAubCenterCalled);
EXPECT_NE(nullptr, executionEnvironment.rootDeviceEnvironments[expectedRootDeviceIndex]->aubCenter.get());
}

View File

@@ -11,12 +11,10 @@
#include "shared/test/common/helpers/dispatch_flags_helper.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "opencl/source/helpers/hardware_commands_helper.h"
#include "opencl/source/mem_obj/buffer.h"
#include "opencl/source/platform/platform.h"
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
#include "opencl/test/unit_test/fixtures/ult_command_stream_receiver_fixture.h"
#include "opencl/test/unit_test/mocks/mock_allocation_properties.h"
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
@@ -30,12 +28,11 @@
#include "opencl/test/unit_test/mocks/mock_program.h"
#include "opencl/test/unit_test/mocks/mock_submissions_aggregator.h"
#include "opencl/test/unit_test/mocks/mock_svm_manager.h"
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
#include "test.h"
using namespace NEO;
typedef UltCommandStreamReceiverTest CommandStreamReceiverFlushTaskTests;
using CommandStreamReceiverFlushTaskTests = UltCommandStreamReceiverTest;
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenFlushTaskIsCalledThenNothingIsSubmittedToTheHwAndSubmissionIsRecorded) {
typedef typename FamilyType::MI_BATCH_BUFFER_END MI_BATCH_BUFFER_END;
@@ -1993,387 +1990,3 @@ HWTEST_F(SingleRootDeviceCommandStreamReceiverTests, givenMultipleEventInSingleR
EXPECT_EQ(0u, semaphores.size());
}
}
using MultiRootDeviceCommandStreamReceiverTests = CommandStreamReceiverFlushTaskTests;
HWTEST_F(MultiRootDeviceCommandStreamReceiverTests, givenMultipleEventInMultiRootDeviceEnvironmentWhenTheyArePassedToEnqueueWithoutSubmissionThenCsIsWaitingForEventsFromPreviousDevices) {
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
auto deviceFactory = std::make_unique<UltClDeviceFactory>(4, 0);
auto device1 = deviceFactory->rootDevices[1];
auto device2 = deviceFactory->rootDevices[2];
auto device3 = deviceFactory->rootDevices[3];
auto mockCsr1 = new MockCommandStreamReceiver(*device1->executionEnvironment, device1->getRootDeviceIndex(), device1->getDeviceBitfield());
auto mockCsr2 = new MockCommandStreamReceiver(*device2->executionEnvironment, device2->getRootDeviceIndex(), device2->getDeviceBitfield());
auto mockCsr3 = new MockCommandStreamReceiver(*device3->executionEnvironment, device3->getRootDeviceIndex(), device3->getDeviceBitfield());
device1->resetCommandStreamReceiver(mockCsr1);
device2->resetCommandStreamReceiver(mockCsr2);
device3->resetCommandStreamReceiver(mockCsr3);
cl_device_id devices[] = {device1, device2, device3};
auto context = std::make_unique<MockContext>(ClDeviceVector(devices, 3), false);
auto pCmdQ1 = context.get()->getSpecialQueue(1u);
auto pCmdQ2 = context.get()->getSpecialQueue(2u);
auto pCmdQ3 = context.get()->getSpecialQueue(3u);
Event event1(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 5, 15);
Event event2(nullptr, CL_COMMAND_NDRANGE_KERNEL, 6, 16);
Event event3(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 4, 20);
Event event4(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 3, 4);
Event event5(pCmdQ3, CL_COMMAND_NDRANGE_KERNEL, 7, 21);
Event event6(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 2, 7);
UserEvent userEvent1(&pCmdQ1->getContext());
UserEvent userEvent2(&pCmdQ2->getContext());
userEvent1.setStatus(CL_COMPLETE);
userEvent2.setStatus(CL_COMPLETE);
cl_event eventWaitList[] =
{
&event1,
&event2,
&event3,
&event4,
&event5,
&event6,
&userEvent1,
&userEvent2,
};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
{
pCmdQ1->enqueueMarkerWithWaitList(
numEventsInWaitList,
eventWaitList,
nullptr);
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ1->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(3u, semaphores.size());
auto semaphoreCmd0 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[0]));
EXPECT_EQ(4u, semaphoreCmd0->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ2->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd0->getSemaphoreGraphicsAddress());
auto semaphoreCmd1 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[1]));
EXPECT_EQ(21u, semaphoreCmd1->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ3->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd1->getSemaphoreGraphicsAddress());
auto semaphoreCmd2 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[2]));
EXPECT_EQ(7u, semaphoreCmd2->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ2->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd2->getSemaphoreGraphicsAddress());
}
{
pCmdQ2->enqueueMarkerWithWaitList(
numEventsInWaitList,
eventWaitList,
nullptr);
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ2->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(3u, semaphores.size());
auto semaphoreCmd0 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[0]));
EXPECT_EQ(15u, semaphoreCmd0->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ1->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd0->getSemaphoreGraphicsAddress());
auto semaphoreCmd1 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[1]));
EXPECT_EQ(20u, semaphoreCmd1->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ1->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd1->getSemaphoreGraphicsAddress());
auto semaphoreCmd2 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[2]));
EXPECT_EQ(21u, semaphoreCmd2->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ3->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd2->getSemaphoreGraphicsAddress());
}
{
cl_event eventWaitList[] =
{
&event1,
&event2,
&event5,
&userEvent1,
};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
pCmdQ3->enqueueMarkerWithWaitList(
numEventsInWaitList,
eventWaitList,
nullptr);
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ3->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(1u, semaphores.size());
auto semaphoreCmd0 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[0]));
EXPECT_EQ(15u, semaphoreCmd0->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ1->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd0->getSemaphoreGraphicsAddress());
}
}
using MultiRootDeviceCommandStreamReceiverBufferTests = MultiRootDeviceFixture;
HWTEST_F(MultiRootDeviceCommandStreamReceiverBufferTests, givenMultipleEventInMultiRootDeviceEnvironmentWhenTheyArePassedToEnqueueWithSubmissionThenCsIsWaitingForEventsFromPreviousDevices) {
REQUIRE_SVM_OR_SKIP(device1);
REQUIRE_SVM_OR_SKIP(device2);
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
cl_int retVal = 0;
size_t offset = 0;
size_t size = 1;
auto pCmdQ1 = context.get()->getSpecialQueue(1u);
auto pCmdQ2 = context.get()->getSpecialQueue(2u);
std::unique_ptr<MockProgram> program(Program::createBuiltInFromSource<MockProgram>("FillBufferBytes", context.get(), context.get()->getDevices(), &retVal));
program->build(program->getDevices(), nullptr, false);
std::unique_ptr<MockKernel> kernel(Kernel::create<MockKernel>(program.get(), program->getKernelInfoForKernel("FillBufferBytes"), *context.get()->getDevice(0), &retVal));
size_t svmSize = 4096;
void *svmPtr = alignedMalloc(svmSize, MemoryConstants::pageSize);
MockGraphicsAllocation svmAlloc(svmPtr, svmSize);
Event event1(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 5, 15);
Event event2(nullptr, CL_COMMAND_NDRANGE_KERNEL, 6, 16);
Event event3(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 4, 20);
Event event4(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 3, 4);
Event event5(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 2, 7);
UserEvent userEvent1(&pCmdQ1->getContext());
UserEvent userEvent2(&pCmdQ2->getContext());
userEvent1.setStatus(CL_COMPLETE);
userEvent2.setStatus(CL_COMPLETE);
cl_event eventWaitList[] =
{
&event1,
&event2,
&event3,
&event4,
&event5,
&userEvent1,
&userEvent2,
};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
{
kernel->setSvmKernelExecInfo(&svmAlloc);
retVal = pCmdQ1->enqueueKernel(
kernel.get(),
1,
&offset,
&size,
&size,
numEventsInWaitList,
eventWaitList,
nullptr);
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ1->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(2u, semaphores.size());
auto semaphoreCmd0 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[0]));
EXPECT_EQ(4u, semaphoreCmd0->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ2->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd0->getSemaphoreGraphicsAddress());
auto semaphoreCmd1 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[1]));
EXPECT_EQ(7u, semaphoreCmd1->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ2->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd1->getSemaphoreGraphicsAddress());
}
{
kernel->setSvmKernelExecInfo(&svmAlloc);
retVal = pCmdQ2->enqueueKernel(
kernel.get(),
1,
&offset,
&size,
&size,
numEventsInWaitList,
eventWaitList,
nullptr);
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ2->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(2u, semaphores.size());
auto semaphoreCmd0 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[0]));
EXPECT_EQ(15u, semaphoreCmd0->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ1->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd0->getSemaphoreGraphicsAddress());
auto semaphoreCmd1 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[1]));
EXPECT_EQ(20u, semaphoreCmd1->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ1->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd1->getSemaphoreGraphicsAddress());
}
alignedFree(svmPtr);
}
HWTEST_F(MultiRootDeviceCommandStreamReceiverTests, givenMultipleEventInMultiRootDeviceEnvironmentWhenTheyArePassedToMarkerThenMiSemaphoreWaitCommandSizeIsIncluded) {
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
auto deviceFactory = std::make_unique<UltClDeviceFactory>(3, 0);
auto device1 = deviceFactory->rootDevices[1];
auto device2 = deviceFactory->rootDevices[2];
auto mockCsr1 = new MockCommandStreamReceiver(*device1->executionEnvironment, device1->getRootDeviceIndex(), device1->getDeviceBitfield());
auto mockCsr2 = new MockCommandStreamReceiver(*device2->executionEnvironment, device2->getRootDeviceIndex(), device2->getDeviceBitfield());
device1->resetCommandStreamReceiver(mockCsr1);
device2->resetCommandStreamReceiver(mockCsr2);
cl_device_id devices[] = {device1, device2};
auto context = std::make_unique<MockContext>(ClDeviceVector(devices, 2), false);
auto pCmdQ1 = context.get()->getSpecialQueue(1u);
auto pCmdQ2 = context.get()->getSpecialQueue(2u);
MockKernelWithInternals mockKernel(ClDeviceVector(devices, 2));
DispatchInfo dispatchInfo;
MultiDispatchInfo multiDispatchInfo(mockKernel.mockKernel);
dispatchInfo.setKernel(mockKernel.mockKernel);
multiDispatchInfo.push(dispatchInfo);
Event event1(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 5, 15);
Event event2(nullptr, CL_COMMAND_NDRANGE_KERNEL, 6, 16);
Event event3(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 1, 6);
Event event4(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 4, 20);
Event event5(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 3, 4);
Event event6(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 2, 7);
UserEvent userEvent1(&pCmdQ1->getContext());
UserEvent userEvent2(&pCmdQ2->getContext());
userEvent1.setStatus(CL_COMPLETE);
userEvent2.setStatus(CL_COMPLETE);
{
cl_event eventWaitList[] =
{
&event1,
&event2,
&event3,
&event4,
&userEvent1,
&userEvent2,
};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
pCmdQ1->enqueueMarkerWithWaitList(
numEventsInWaitList,
eventWaitList,
nullptr);
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, nullptr);
CsrDependencies csrDeps;
eventsRequest.fillCsrDependenciesForTaskCountContainer(csrDeps, pCmdQ1->getCommandStreamReceiver(false));
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ1->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(0u, semaphores.size());
EXPECT_EQ(0u, TimestampPacketHelper::getRequiredCmdStreamSizeForTaskCountContainer<FamilyType>(csrDeps));
}
{
cl_event eventWaitList[] =
{
&event1,
&event2,
&event3,
&event4,
&event5,
&event6,
&userEvent1,
};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
pCmdQ2->enqueueMarkerWithWaitList(
numEventsInWaitList,
eventWaitList,
nullptr);
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, nullptr);
CsrDependencies csrDeps;
eventsRequest.fillCsrDependenciesForTaskCountContainer(csrDeps, pCmdQ2->getCommandStreamReceiver(false));
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ2->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(3u, semaphores.size());
EXPECT_EQ(3u * sizeof(MI_SEMAPHORE_WAIT), TimestampPacketHelper::getRequiredCmdStreamSizeForTaskCountContainer<FamilyType>(csrDeps));
}
}
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenStaticPartitioningEnabledWhenFlushingTaskThenWorkPartitionAllocationIsMadeResident) {
DebugManagerStateRestore restore{};
DebugManager.flags.EnableStaticPartitioning.set(1);
DebugManager.flags.ForcePreemptionMode.set(PreemptionMode::Disabled);
UltDeviceFactory deviceFactory{1, 2};
MockDevice *device = deviceFactory.rootDevices[0];
auto &mockCsr = device->getUltCommandStreamReceiver<FamilyType>();
ASSERT_NE(nullptr, mockCsr.getWorkPartitionAllocation());
mockCsr.overrideDispatchPolicy(DispatchMode::BatchedDispatch);
mockCsr.storeMakeResidentAllocations = true;
DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags();
mockCsr.flushTask(commandStream,
0,
dsh,
ioh,
ssh,
taskLevel,
dispatchFlags,
*device);
bool found = false;
for (auto allocation : mockCsr.makeResidentAllocations) {
if (allocation.first == mockCsr.getWorkPartitionAllocation()) {
found = true;
break;
}
}
EXPECT_TRUE(found);
}
namespace CpuIntrinsicsTests {
extern volatile uint32_t *pauseAddress;
extern uint32_t pauseValue;
} // namespace CpuIntrinsicsTests
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenTagValueNotMeetingTaskCountToWaitWhenTagValueSwitchesThenWaitFunctionReturnsTrue) {
VariableBackup<volatile uint32_t *> backupPauseAddress(&CpuIntrinsicsTests::pauseAddress);
VariableBackup<uint32_t> backupPauseValue(&CpuIntrinsicsTests::pauseValue);
auto mockCsr = new MockCsrHw2<FamilyType>(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
pDevice->resetCommandStreamReceiver(mockCsr);
uint32_t taskCountToWait = 2u;
*mockCsr->tagAddress = 1u;
CpuIntrinsicsTests::pauseAddress = mockCsr->tagAddress;
CpuIntrinsicsTests::pauseValue = taskCountToWait;
bool ret = mockCsr->waitForCompletionWithTimeout(false, 1, taskCountToWait);
EXPECT_TRUE(ret);
}

View File

@@ -0,0 +1,404 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "opencl/source/event/user_event.h"
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
#include "opencl/test/unit_test/fixtures/ult_command_stream_receiver_fixture.h"
#include "opencl/test/unit_test/mocks/mock_kernel.h"
#include "opencl/test/unit_test/mocks/mock_program.h"
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
#include "test.h"
using namespace NEO;
using MultiRootDeviceCommandStreamReceiverBufferTests = MultiRootDeviceFixture;
HWTEST_F(MultiRootDeviceCommandStreamReceiverBufferTests, givenMultipleEventInMultiRootDeviceEnvironmentWhenTheyArePassedToEnqueueWithSubmissionThenCsIsWaitingForEventsFromPreviousDevices) {
REQUIRE_SVM_OR_SKIP(device1);
REQUIRE_SVM_OR_SKIP(device2);
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
cl_int retVal = 0;
size_t offset = 0;
size_t size = 1;
auto pCmdQ1 = context.get()->getSpecialQueue(1u);
auto pCmdQ2 = context.get()->getSpecialQueue(2u);
std::unique_ptr<MockProgram> program(Program::createBuiltInFromSource<MockProgram>("FillBufferBytes", context.get(), context.get()->getDevices(), &retVal));
program->build(program->getDevices(), nullptr, false);
std::unique_ptr<MockKernel> kernel(Kernel::create<MockKernel>(program.get(), program->getKernelInfoForKernel("FillBufferBytes"), *context.get()->getDevice(0), &retVal));
size_t svmSize = 4096;
void *svmPtr = alignedMalloc(svmSize, MemoryConstants::pageSize);
MockGraphicsAllocation svmAlloc(svmPtr, svmSize);
Event event1(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 5, 15);
Event event2(nullptr, CL_COMMAND_NDRANGE_KERNEL, 6, 16);
Event event3(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 4, 20);
Event event4(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 3, 4);
Event event5(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 2, 7);
UserEvent userEvent1(&pCmdQ1->getContext());
UserEvent userEvent2(&pCmdQ2->getContext());
userEvent1.setStatus(CL_COMPLETE);
userEvent2.setStatus(CL_COMPLETE);
cl_event eventWaitList[] =
{
&event1,
&event2,
&event3,
&event4,
&event5,
&userEvent1,
&userEvent2,
};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
{
kernel->setSvmKernelExecInfo(&svmAlloc);
retVal = pCmdQ1->enqueueKernel(
kernel.get(),
1,
&offset,
&size,
&size,
numEventsInWaitList,
eventWaitList,
nullptr);
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ1->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(2u, semaphores.size());
auto semaphoreCmd0 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[0]));
EXPECT_EQ(4u, semaphoreCmd0->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ2->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd0->getSemaphoreGraphicsAddress());
auto semaphoreCmd1 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[1]));
EXPECT_EQ(7u, semaphoreCmd1->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ2->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd1->getSemaphoreGraphicsAddress());
}
{
kernel->setSvmKernelExecInfo(&svmAlloc);
retVal = pCmdQ2->enqueueKernel(
kernel.get(),
1,
&offset,
&size,
&size,
numEventsInWaitList,
eventWaitList,
nullptr);
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ2->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(2u, semaphores.size());
auto semaphoreCmd0 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[0]));
EXPECT_EQ(15u, semaphoreCmd0->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ1->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd0->getSemaphoreGraphicsAddress());
auto semaphoreCmd1 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[1]));
EXPECT_EQ(20u, semaphoreCmd1->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ1->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd1->getSemaphoreGraphicsAddress());
}
alignedFree(svmPtr);
}
using CommandStreamReceiverFlushTaskTests = UltCommandStreamReceiverTest;
using MultiRootDeviceCommandStreamReceiverTests = CommandStreamReceiverFlushTaskTests;
HWTEST_F(MultiRootDeviceCommandStreamReceiverTests, givenMultipleEventInMultiRootDeviceEnvironmentWhenTheyArePassedToEnqueueWithoutSubmissionThenCsIsWaitingForEventsFromPreviousDevices) {
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
auto deviceFactory = std::make_unique<UltClDeviceFactory>(4, 0);
auto device1 = deviceFactory->rootDevices[1];
auto device2 = deviceFactory->rootDevices[2];
auto device3 = deviceFactory->rootDevices[3];
auto mockCsr1 = new MockCommandStreamReceiver(*device1->executionEnvironment, device1->getRootDeviceIndex(), device1->getDeviceBitfield());
auto mockCsr2 = new MockCommandStreamReceiver(*device2->executionEnvironment, device2->getRootDeviceIndex(), device2->getDeviceBitfield());
auto mockCsr3 = new MockCommandStreamReceiver(*device3->executionEnvironment, device3->getRootDeviceIndex(), device3->getDeviceBitfield());
device1->resetCommandStreamReceiver(mockCsr1);
device2->resetCommandStreamReceiver(mockCsr2);
device3->resetCommandStreamReceiver(mockCsr3);
cl_device_id devices[] = {device1, device2, device3};
auto context = std::make_unique<MockContext>(ClDeviceVector(devices, 3), false);
auto pCmdQ1 = context.get()->getSpecialQueue(1u);
auto pCmdQ2 = context.get()->getSpecialQueue(2u);
auto pCmdQ3 = context.get()->getSpecialQueue(3u);
Event event1(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 5, 15);
Event event2(nullptr, CL_COMMAND_NDRANGE_KERNEL, 6, 16);
Event event3(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 4, 20);
Event event4(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 3, 4);
Event event5(pCmdQ3, CL_COMMAND_NDRANGE_KERNEL, 7, 21);
Event event6(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 2, 7);
UserEvent userEvent1(&pCmdQ1->getContext());
UserEvent userEvent2(&pCmdQ2->getContext());
userEvent1.setStatus(CL_COMPLETE);
userEvent2.setStatus(CL_COMPLETE);
cl_event eventWaitList[] =
{
&event1,
&event2,
&event3,
&event4,
&event5,
&event6,
&userEvent1,
&userEvent2,
};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
{
pCmdQ1->enqueueMarkerWithWaitList(
numEventsInWaitList,
eventWaitList,
nullptr);
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ1->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(3u, semaphores.size());
auto semaphoreCmd0 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[0]));
EXPECT_EQ(4u, semaphoreCmd0->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ2->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd0->getSemaphoreGraphicsAddress());
auto semaphoreCmd1 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[1]));
EXPECT_EQ(21u, semaphoreCmd1->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ3->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd1->getSemaphoreGraphicsAddress());
auto semaphoreCmd2 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[2]));
EXPECT_EQ(7u, semaphoreCmd2->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ2->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd2->getSemaphoreGraphicsAddress());
}
{
pCmdQ2->enqueueMarkerWithWaitList(
numEventsInWaitList,
eventWaitList,
nullptr);
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ2->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(3u, semaphores.size());
auto semaphoreCmd0 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[0]));
EXPECT_EQ(15u, semaphoreCmd0->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ1->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd0->getSemaphoreGraphicsAddress());
auto semaphoreCmd1 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[1]));
EXPECT_EQ(20u, semaphoreCmd1->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ1->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd1->getSemaphoreGraphicsAddress());
auto semaphoreCmd2 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[2]));
EXPECT_EQ(21u, semaphoreCmd2->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ3->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd2->getSemaphoreGraphicsAddress());
}
{
cl_event eventWaitList[] =
{
&event1,
&event2,
&event5,
&userEvent1,
};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
pCmdQ3->enqueueMarkerWithWaitList(
numEventsInWaitList,
eventWaitList,
nullptr);
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ3->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(1u, semaphores.size());
auto semaphoreCmd0 = genCmdCast<MI_SEMAPHORE_WAIT *>(*(semaphores[0]));
EXPECT_EQ(15u, semaphoreCmd0->getSemaphoreDataDword());
EXPECT_EQ(reinterpret_cast<uint64_t>(pCmdQ1->getCommandStreamReceiver(false).getTagAddress()), semaphoreCmd0->getSemaphoreGraphicsAddress());
}
}
HWTEST_F(MultiRootDeviceCommandStreamReceiverTests, givenMultipleEventInMultiRootDeviceEnvironmentWhenTheyArePassedToMarkerThenMiSemaphoreWaitCommandSizeIsIncluded) {
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
auto deviceFactory = std::make_unique<UltClDeviceFactory>(3, 0);
auto device1 = deviceFactory->rootDevices[1];
auto device2 = deviceFactory->rootDevices[2];
auto mockCsr1 = new MockCommandStreamReceiver(*device1->executionEnvironment, device1->getRootDeviceIndex(), device1->getDeviceBitfield());
auto mockCsr2 = new MockCommandStreamReceiver(*device2->executionEnvironment, device2->getRootDeviceIndex(), device2->getDeviceBitfield());
device1->resetCommandStreamReceiver(mockCsr1);
device2->resetCommandStreamReceiver(mockCsr2);
cl_device_id devices[] = {device1, device2};
auto context = std::make_unique<MockContext>(ClDeviceVector(devices, 2), false);
auto pCmdQ1 = context.get()->getSpecialQueue(1u);
auto pCmdQ2 = context.get()->getSpecialQueue(2u);
MockKernelWithInternals mockKernel(ClDeviceVector(devices, 2));
DispatchInfo dispatchInfo;
MultiDispatchInfo multiDispatchInfo(mockKernel.mockKernel);
dispatchInfo.setKernel(mockKernel.mockKernel);
multiDispatchInfo.push(dispatchInfo);
Event event1(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 5, 15);
Event event2(nullptr, CL_COMMAND_NDRANGE_KERNEL, 6, 16);
Event event3(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 1, 6);
Event event4(pCmdQ1, CL_COMMAND_NDRANGE_KERNEL, 4, 20);
Event event5(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 3, 4);
Event event6(pCmdQ2, CL_COMMAND_NDRANGE_KERNEL, 2, 7);
UserEvent userEvent1(&pCmdQ1->getContext());
UserEvent userEvent2(&pCmdQ2->getContext());
userEvent1.setStatus(CL_COMPLETE);
userEvent2.setStatus(CL_COMPLETE);
{
cl_event eventWaitList[] =
{
&event1,
&event2,
&event3,
&event4,
&userEvent1,
&userEvent2,
};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
pCmdQ1->enqueueMarkerWithWaitList(
numEventsInWaitList,
eventWaitList,
nullptr);
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, nullptr);
CsrDependencies csrDeps;
eventsRequest.fillCsrDependenciesForTaskCountContainer(csrDeps, pCmdQ1->getCommandStreamReceiver(false));
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ1->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(0u, semaphores.size());
EXPECT_EQ(0u, TimestampPacketHelper::getRequiredCmdStreamSizeForTaskCountContainer<FamilyType>(csrDeps));
}
{
cl_event eventWaitList[] =
{
&event1,
&event2,
&event3,
&event4,
&event5,
&event6,
&userEvent1,
};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
pCmdQ2->enqueueMarkerWithWaitList(
numEventsInWaitList,
eventWaitList,
nullptr);
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, nullptr);
CsrDependencies csrDeps;
eventsRequest.fillCsrDependenciesForTaskCountContainer(csrDeps, pCmdQ2->getCommandStreamReceiver(false));
HardwareParse csHwParser;
csHwParser.parseCommands<FamilyType>(pCmdQ2->getCS(0));
auto semaphores = findAll<MI_SEMAPHORE_WAIT *>(csHwParser.cmdList.begin(), csHwParser.cmdList.end());
EXPECT_EQ(3u, semaphores.size());
EXPECT_EQ(3u * sizeof(MI_SEMAPHORE_WAIT), TimestampPacketHelper::getRequiredCmdStreamSizeForTaskCountContainer<FamilyType>(csrDeps));
}
}
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenStaticPartitioningEnabledWhenFlushingTaskThenWorkPartitionAllocationIsMadeResident) {
DebugManagerStateRestore restore{};
DebugManager.flags.EnableStaticPartitioning.set(1);
DebugManager.flags.ForcePreemptionMode.set(PreemptionMode::Disabled);
UltDeviceFactory deviceFactory{1, 2};
MockDevice *device = deviceFactory.rootDevices[0];
auto &mockCsr = device->getUltCommandStreamReceiver<FamilyType>();
ASSERT_NE(nullptr, mockCsr.getWorkPartitionAllocation());
mockCsr.overrideDispatchPolicy(DispatchMode::BatchedDispatch);
mockCsr.storeMakeResidentAllocations = true;
DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags();
mockCsr.flushTask(commandStream,
0,
dsh,
ioh,
ssh,
taskLevel,
dispatchFlags,
*device);
bool found = false;
for (auto allocation : mockCsr.makeResidentAllocations) {
if (allocation.first == mockCsr.getWorkPartitionAllocation()) {
found = true;
break;
}
}
EXPECT_TRUE(found);
}
namespace CpuIntrinsicsTests {
extern volatile uint32_t *pauseAddress;
extern uint32_t pauseValue;
} // namespace CpuIntrinsicsTests
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenTagValueNotMeetingTaskCountToWaitWhenTagValueSwitchesThenWaitFunctionReturnsTrue) {
VariableBackup<volatile uint32_t *> backupPauseAddress(&CpuIntrinsicsTests::pauseAddress);
VariableBackup<uint32_t> backupPauseValue(&CpuIntrinsicsTests::pauseValue);
auto mockCsr = new MockCsrHw2<FamilyType>(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
pDevice->resetCommandStreamReceiver(mockCsr);
uint32_t taskCountToWait = 2u;
*mockCsr->tagAddress = 1u;
CpuIntrinsicsTests::pauseAddress = mockCsr->tagAddress;
CpuIntrinsicsTests::pauseValue = taskCountToWait;
bool ret = mockCsr->waitForCompletionWithTimeout(false, 1, taskCountToWait);
EXPECT_TRUE(ret);
}

View File

@@ -31,7 +31,9 @@ set(IGDRCL_SRCS_tests_helpers
${CMAKE_CURRENT_SOURCE_DIR}/raii_hw_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/sampler_helpers_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/task_information_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timestamp_packet_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timestamp_packet_1_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timestamp_packet_2_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timestamp_packet_tests.h
${CMAKE_CURRENT_SOURCE_DIR}/transfer_properties_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ult_limits.h
${CMAKE_CURRENT_SOURCE_DIR}/uint16_sse4_tests.cpp

View File

@@ -9,9 +9,7 @@
#include "shared/source/helpers/timestamp_packet.h"
#include "shared/source/utilities/tag_allocator.h"
#include "shared/test/common/cmd_parse/hw_parse.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/dispatch_flags_helper.h"
#include "shared/test/common/helpers/unit_test_helper.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/unit_test/utilities/base_object_utils.h"
@@ -19,106 +17,16 @@
#include "opencl/source/command_queue/hardware_interface.h"
#include "opencl/source/event/user_event.h"
#include "opencl/source/platform/platform.h"
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
#include "opencl/test/unit_test/mocks/mock_context.h"
#include "opencl/test/unit_test/helpers/timestamp_packet_tests.h"
#include "opencl/test/unit_test/mocks/mock_csr.h"
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
#include "opencl/test/unit_test/mocks/mock_kernel.h"
#include "opencl/test/unit_test/mocks/mock_mdi.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_platform.h"
#include "opencl/test/unit_test/mocks/mock_timestamp_container.h"
#include "test.h"
#include "gmock/gmock.h"
using namespace NEO;
struct TimestampPacketSimpleTests : public ::testing::Test {
class MockTimestampPacketStorage : public TimestampPackets<uint32_t> {
public:
using TimestampPackets<uint32_t>::implicitGpuDependenciesCount;
using TimestampPackets<uint32_t>::packets;
};
void setTagToReadyState(TagNodeBase *tagNode) {
auto packetsUsed = tagNode->getPacketsUsed();
tagNode->initialize();
uint32_t zeros[4] = {};
for (uint32_t i = 0; i < TimestampPacketSizeControl::preferredPacketCount; i++) {
tagNode->assignDataToAllTimestamps(i, zeros);
}
tagNode->setPacketsUsed(packetsUsed);
}
const size_t gws[3] = {1, 1, 1};
};
struct TimestampPacketTests : public TimestampPacketSimpleTests {
struct MockTagNode : public TagNode<TimestampPackets<uint32_t>> {
using TagNode<TimestampPackets<uint32_t>>::gpuAddress;
};
void SetUp() override {
DebugManager.flags.EnableTimestampPacket.set(1);
executionEnvironment = platform()->peekExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(2);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
}
device = std::make_unique<MockClDevice>(Device::create<MockDevice>(executionEnvironment, 0u));
context = new MockContext(device.get());
kernel = std::make_unique<MockKernelWithInternals>(*device, context);
mockCmdQ = new MockCommandQueue(context, device.get(), nullptr);
}
void TearDown() override {
mockCmdQ->release();
context->release();
}
template <typename MI_SEMAPHORE_WAIT>
void verifySemaphore(MI_SEMAPHORE_WAIT *semaphoreCmd, TagNodeBase *timestampPacketNode, uint32_t packetId) {
EXPECT_NE(nullptr, semaphoreCmd);
EXPECT_EQ(semaphoreCmd->getCompareOperation(), MI_SEMAPHORE_WAIT::COMPARE_OPERATION::COMPARE_OPERATION_SAD_NOT_EQUAL_SDD);
EXPECT_EQ(1u, semaphoreCmd->getSemaphoreDataDword());
uint64_t compareOffset = packetId * TimestampPackets<uint32_t>::getSinglePacketSize();
auto dataAddress = TimestampPacketHelper::getContextEndGpuAddress(*timestampPacketNode) + compareOffset;
EXPECT_EQ(dataAddress, semaphoreCmd->getSemaphoreGraphicsAddress());
};
template <typename GfxFamily>
void verifyMiAtomic(typename GfxFamily::MI_ATOMIC *miAtomicCmd, TagNodeBase *timestampPacketNode) {
using MI_ATOMIC = typename GfxFamily::MI_ATOMIC;
EXPECT_NE(nullptr, miAtomicCmd);
auto writeAddress = TimestampPacketHelper::getGpuDependenciesCountGpuAddress(*timestampPacketNode);
EXPECT_EQ(MI_ATOMIC::ATOMIC_OPCODES::ATOMIC_4B_INCREMENT, miAtomicCmd->getAtomicOpcode());
EXPECT_EQ(writeAddress, UnitTestHelper<GfxFamily>::getMemoryAddress(*miAtomicCmd));
};
void verifyDependencyCounterValues(TimestampPacketContainer *timestampPacketContainer, uint32_t expectedValue) {
auto &nodes = timestampPacketContainer->peekNodes();
EXPECT_NE(0u, nodes.size());
for (auto &node : nodes) {
EXPECT_EQ(expectedValue, node->getImplicitCpuDependenciesCount());
}
}
ExecutionEnvironment *executionEnvironment;
std::unique_ptr<MockClDevice> device;
MockContext *context;
std::unique_ptr<MockKernelWithInternals> kernel;
MockCommandQueue *mockCmdQ;
DebugManagerStateRestore restorer;
};
HWTEST_F(TimestampPacketTests, givenTagNodeWhenSemaphoreAndAtomicAreProgrammedThenUseGpuAddress) {
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
using MI_ATOMIC = typename FamilyType::MI_ATOMIC;
@@ -1897,192 +1805,3 @@ HWTEST_F(TimestampPacketTests, givenWaitlistAndOutputEventWhenEnqueueingBarrierW
EXPECT_EQ(expectedQueueSemaphoresCount, queueSemaphores.size());
verifySemaphore(genCmdCast<MI_SEMAPHORE_WAIT *>(*(queueSemaphores[0])), node1.getNode(0), 0);
}
HWTEST_F(TimestampPacketTests, givenEmptyWaitlistAndNoOutputEventWhenEnqueueingMarkerThenDoNothing) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto cmdQ = clUniquePtr(new MockCommandQueueHw<FamilyType>(context, device.get(), nullptr));
cmdQ->enqueueMarkerWithWaitList(0, nullptr, nullptr);
EXPECT_EQ(0u, cmdQ->timestampPacketContainer->peekNodes().size());
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
}
HWTEST_F(TimestampPacketTests, givenEmptyWaitlistAndEventWhenEnqueueingMarkerWithProfilingEnabledThenObtainNewNode) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto cmdQ = clUniquePtr(new MockCommandQueueHw<FamilyType>(context, device.get(), nullptr));
cmdQ->setProfilingEnabled();
cl_event event;
cmdQ->enqueueMarkerWithWaitList(0, nullptr, &event);
EXPECT_EQ(1u, cmdQ->timestampPacketContainer->peekNodes().size());
clReleaseEvent(event);
}
HWTEST_F(TimestampPacketTests, whenEnqueueingBarrierThenRequestPipeControlOnCsrFlush) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
MockKernelWithInternals mockKernel(*device, context);
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); // obtain first TimestampPackets<uint32_t>
TimestampPacketContainer cmdQNodes;
cmdQNodes.assignAndIncrementNodesRefCounts(*cmdQ.timestampPacketContainer);
cmdQ.enqueueBarrierWithWaitList(0, nullptr, nullptr);
EXPECT_EQ(cmdQ.timestampPacketContainer->peekNodes().at(0), cmdQNodes.peekNodes().at(0)); // dont obtain new node
EXPECT_EQ(1u, cmdQ.timestampPacketContainer->peekNodes().size());
EXPECT_TRUE(csr.stallingPipeControlOnNextFlushRequired);
}
HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteDisabledWhenEnqueueingBarrierThenDontRequestPipeControlOnCsrFlush) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = false;
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
cmdQ.enqueueBarrierWithWaitList(0, nullptr, nullptr);
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
}
HWTEST_F(TimestampPacketTests, givenBlockedQueueWhenEnqueueingBarrierThenRequestPipeControlOnCsrFlush) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
auto userEvent = make_releaseable<UserEvent>();
cl_event waitlist[] = {userEvent.get()};
cmdQ.enqueueBarrierWithWaitList(1, waitlist, nullptr);
EXPECT_TRUE(csr.stallingPipeControlOnNextFlushRequired);
userEvent->setStatus(CL_COMPLETE);
}
HWTEST_F(TimestampPacketTests, givenPipeControlRequestWhenEstimatingCsrStreamSizeThenAddSizeForPipeControl) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
DispatchFlags flags = DispatchFlagsHelper::createDefaultDispatchFlags();
csr.stallingPipeControlOnNextFlushRequired = false;
auto sizeWithoutPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
csr.stallingPipeControlOnNextFlushRequired = true;
auto sizeWithPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
size_t extendedSize = sizeWithoutPcRequest + sizeof(typename FamilyType::PIPE_CONTROL);
EXPECT_EQ(sizeWithPcRequest, extendedSize);
}
HWTEST_F(TimestampPacketTests, givenPipeControlRequestWithBarrierWriteWhenEstimatingCsrStreamSizeThenAddSizeForPipeControlForWrite) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
DispatchFlags flags = DispatchFlagsHelper::createDefaultDispatchFlags();
TimestampPacketContainer barrierTimestampPacketNode;
barrierTimestampPacketNode.add(csr.getTimestampPacketAllocator()->getTag());
flags.barrierTimestampPacketNodes = &barrierTimestampPacketNode;
csr.stallingPipeControlOnNextFlushRequired = false;
auto sizeWithoutPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
csr.stallingPipeControlOnNextFlushRequired = true;
auto sizeWithPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
size_t extendedSize = sizeWithoutPcRequest + MemorySynchronizationCommands<FamilyType>::getSizeForPipeControlWithPostSyncOperation(device->getHardwareInfo());
EXPECT_EQ(sizeWithPcRequest, extendedSize);
}
HWTEST_F(TimestampPacketTests, givenInstructionCacheRequesWhenSizeIsEstimatedThenPipeControlIsAdded) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
DispatchFlags flags = DispatchFlagsHelper::createDefaultDispatchFlags();
csr.requiresInstructionCacheFlush = false;
auto sizeWithoutPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
csr.requiresInstructionCacheFlush = true;
auto sizeWithPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
size_t extendedSize = sizeWithoutPcRequest + sizeof(typename FamilyType::PIPE_CONTROL);
EXPECT_EQ(sizeWithPcRequest, extendedSize);
}
HWTEST_F(TimestampPacketTests, givenPipeControlRequestWhenFlushingThenProgramPipeControlAndResetRequestFlag) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.stallingPipeControlOnNextFlushRequired = true;
csr.timestampPacketWriteEnabled = true;
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
MockKernelWithInternals mockKernel(*device, context);
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
HardwareParse hwParser;
hwParser.parseCommands<FamilyType>(csr.commandStream, 0);
auto secondEnqueueOffset = csr.commandStream.getUsed();
auto pipeControl = genCmdCast<typename FamilyType::PIPE_CONTROL *>(*hwParser.cmdList.begin());
EXPECT_NE(nullptr, pipeControl);
EXPECT_EQ(PIPE_CONTROL::POST_SYNC_OPERATION::POST_SYNC_OPERATION_NO_WRITE, pipeControl->getPostSyncOperation());
EXPECT_TRUE(pipeControl->getCommandStreamerStallEnable());
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
EXPECT_EQ(secondEnqueueOffset, csr.commandStream.getUsed()); // nothing programmed when flag is not set
}
HWTEST_F(TimestampPacketTests, givenKernelWhichDoesntRequireFlushWhenEnqueueingKernelThenOneNodeIsCreated) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.EnableCacheFlushAfterWalker.set(false);
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto mockTagAllocator = new MockTagAllocator<>(device->getRootDeviceIndex(), executionEnvironment->memoryManager.get());
csr.timestampPacketAllocator.reset(mockTagAllocator);
auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, device.get(), nullptr);
// obtain first node for cmdQ and event1
cmdQ->enqueueKernel(kernel->mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
auto size = cmdQ->timestampPacketContainer->peekNodes().size();
EXPECT_EQ(size, 1u);
}
HWTEST_F(TimestampPacketTests, givenKernelWhichRequiresFlushWhenEnqueueingKernelThenTwoNodesAreCreated) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.EnableCacheFlushAfterWalker.set(true);
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto mockTagAllocator = new MockTagAllocator<>(device->getRootDeviceIndex(), executionEnvironment->memoryManager.get());
csr.timestampPacketAllocator.reset(mockTagAllocator);
auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, device.get(), nullptr);
kernel->mockKernel->svmAllocationsRequireCacheFlush = true;
// obtain first node for cmdQ and event1
cmdQ->enqueueKernel(kernel->mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
auto node1 = cmdQ->timestampPacketContainer->peekNodes().at(0);
auto node2 = cmdQ->timestampPacketContainer->peekNodes().at(1);
auto size = cmdQ->timestampPacketContainer->peekNodes().size();
EXPECT_EQ(size, 2u);
EXPECT_NE(nullptr, node1);
EXPECT_NE(nullptr, node2);
EXPECT_NE(node1, node2);
}

View File

@@ -0,0 +1,204 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/common/cmd_parse/hw_parse.h"
#include "shared/test/unit_test/utilities/base_object_utils.h"
#include "opencl/source/event/user_event.h"
#include "opencl/test/unit_test/helpers/timestamp_packet_tests.h"
#include "opencl/test/unit_test/mocks/mock_timestamp_container.h"
using namespace NEO;
HWTEST_F(TimestampPacketTests, givenEmptyWaitlistAndNoOutputEventWhenEnqueueingMarkerThenDoNothing) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto cmdQ = clUniquePtr(new MockCommandQueueHw<FamilyType>(context, device.get(), nullptr));
cmdQ->enqueueMarkerWithWaitList(0, nullptr, nullptr);
EXPECT_EQ(0u, cmdQ->timestampPacketContainer->peekNodes().size());
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
}
HWTEST_F(TimestampPacketTests, givenEmptyWaitlistAndEventWhenEnqueueingMarkerWithProfilingEnabledThenObtainNewNode) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto cmdQ = clUniquePtr(new MockCommandQueueHw<FamilyType>(context, device.get(), nullptr));
cmdQ->setProfilingEnabled();
cl_event event;
cmdQ->enqueueMarkerWithWaitList(0, nullptr, &event);
EXPECT_EQ(1u, cmdQ->timestampPacketContainer->peekNodes().size());
clReleaseEvent(event);
}
HWTEST_F(TimestampPacketTests, whenEnqueueingBarrierThenRequestPipeControlOnCsrFlush) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
MockKernelWithInternals mockKernel(*device, context);
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); // obtain first TimestampPackets<uint32_t>
TimestampPacketContainer cmdQNodes;
cmdQNodes.assignAndIncrementNodesRefCounts(*cmdQ.timestampPacketContainer);
cmdQ.enqueueBarrierWithWaitList(0, nullptr, nullptr);
EXPECT_EQ(cmdQ.timestampPacketContainer->peekNodes().at(0), cmdQNodes.peekNodes().at(0)); // dont obtain new node
EXPECT_EQ(1u, cmdQ.timestampPacketContainer->peekNodes().size());
EXPECT_TRUE(csr.stallingPipeControlOnNextFlushRequired);
}
HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteDisabledWhenEnqueueingBarrierThenDontRequestPipeControlOnCsrFlush) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = false;
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
cmdQ.enqueueBarrierWithWaitList(0, nullptr, nullptr);
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
}
HWTEST_F(TimestampPacketTests, givenBlockedQueueWhenEnqueueingBarrierThenRequestPipeControlOnCsrFlush) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
auto userEvent = make_releaseable<UserEvent>();
cl_event waitlist[] = {userEvent.get()};
cmdQ.enqueueBarrierWithWaitList(1, waitlist, nullptr);
EXPECT_TRUE(csr.stallingPipeControlOnNextFlushRequired);
userEvent->setStatus(CL_COMPLETE);
}
HWTEST_F(TimestampPacketTests, givenPipeControlRequestWhenEstimatingCsrStreamSizeThenAddSizeForPipeControl) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
DispatchFlags flags = DispatchFlagsHelper::createDefaultDispatchFlags();
csr.stallingPipeControlOnNextFlushRequired = false;
auto sizeWithoutPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
csr.stallingPipeControlOnNextFlushRequired = true;
auto sizeWithPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
size_t extendedSize = sizeWithoutPcRequest + sizeof(typename FamilyType::PIPE_CONTROL);
EXPECT_EQ(sizeWithPcRequest, extendedSize);
}
HWTEST_F(TimestampPacketTests, givenPipeControlRequestWithBarrierWriteWhenEstimatingCsrStreamSizeThenAddSizeForPipeControlForWrite) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
DispatchFlags flags = DispatchFlagsHelper::createDefaultDispatchFlags();
TimestampPacketContainer barrierTimestampPacketNode;
barrierTimestampPacketNode.add(csr.getTimestampPacketAllocator()->getTag());
flags.barrierTimestampPacketNodes = &barrierTimestampPacketNode;
csr.stallingPipeControlOnNextFlushRequired = false;
auto sizeWithoutPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
csr.stallingPipeControlOnNextFlushRequired = true;
auto sizeWithPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
size_t extendedSize = sizeWithoutPcRequest + MemorySynchronizationCommands<FamilyType>::getSizeForPipeControlWithPostSyncOperation(device->getHardwareInfo());
EXPECT_EQ(sizeWithPcRequest, extendedSize);
}
HWTEST_F(TimestampPacketTests, givenInstructionCacheRequesWhenSizeIsEstimatedThenPipeControlIsAdded) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
DispatchFlags flags = DispatchFlagsHelper::createDefaultDispatchFlags();
csr.requiresInstructionCacheFlush = false;
auto sizeWithoutPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
csr.requiresInstructionCacheFlush = true;
auto sizeWithPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
size_t extendedSize = sizeWithoutPcRequest + sizeof(typename FamilyType::PIPE_CONTROL);
EXPECT_EQ(sizeWithPcRequest, extendedSize);
}
HWTEST_F(TimestampPacketTests, givenPipeControlRequestWhenFlushingThenProgramPipeControlAndResetRequestFlag) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.stallingPipeControlOnNextFlushRequired = true;
csr.timestampPacketWriteEnabled = true;
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
MockKernelWithInternals mockKernel(*device, context);
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
HardwareParse hwParser;
hwParser.parseCommands<FamilyType>(csr.commandStream, 0);
auto secondEnqueueOffset = csr.commandStream.getUsed();
auto pipeControl = genCmdCast<typename FamilyType::PIPE_CONTROL *>(*hwParser.cmdList.begin());
EXPECT_NE(nullptr, pipeControl);
EXPECT_EQ(PIPE_CONTROL::POST_SYNC_OPERATION::POST_SYNC_OPERATION_NO_WRITE, pipeControl->getPostSyncOperation());
EXPECT_TRUE(pipeControl->getCommandStreamerStallEnable());
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
EXPECT_EQ(secondEnqueueOffset, csr.commandStream.getUsed()); // nothing programmed when flag is not set
}
HWTEST_F(TimestampPacketTests, givenKernelWhichDoesntRequireFlushWhenEnqueueingKernelThenOneNodeIsCreated) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.EnableCacheFlushAfterWalker.set(false);
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto mockTagAllocator = new MockTagAllocator<>(device->getRootDeviceIndex(), executionEnvironment->memoryManager.get());
csr.timestampPacketAllocator.reset(mockTagAllocator);
auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, device.get(), nullptr);
// obtain first node for cmdQ and event1
cmdQ->enqueueKernel(kernel->mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
auto size = cmdQ->timestampPacketContainer->peekNodes().size();
EXPECT_EQ(size, 1u);
}
HWTEST_F(TimestampPacketTests, givenKernelWhichRequiresFlushWhenEnqueueingKernelThenTwoNodesAreCreated) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.EnableCacheFlushAfterWalker.set(true);
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto mockTagAllocator = new MockTagAllocator<>(device->getRootDeviceIndex(), executionEnvironment->memoryManager.get());
csr.timestampPacketAllocator.reset(mockTagAllocator);
auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, device.get(), nullptr);
kernel->mockKernel->svmAllocationsRequireCacheFlush = true;
// obtain first node for cmdQ and event1
cmdQ->enqueueKernel(kernel->mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
auto node1 = cmdQ->timestampPacketContainer->peekNodes().at(0);
auto node2 = cmdQ->timestampPacketContainer->peekNodes().at(1);
auto size = cmdQ->timestampPacketContainer->peekNodes().size();
EXPECT_EQ(size, 2u);
EXPECT_NE(nullptr, node1);
EXPECT_NE(nullptr, node2);
EXPECT_NE(node1, node2);
}

View File

@@ -0,0 +1,103 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/unit_test_helper.h"
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
#include "opencl/test/unit_test/mocks/mock_context.h"
#include "opencl/test/unit_test/mocks/mock_kernel.h"
#include "test.h"
using namespace NEO;
struct TimestampPacketSimpleTests : public ::testing::Test {
class MockTimestampPacketStorage : public TimestampPackets<uint32_t> {
public:
using TimestampPackets<uint32_t>::implicitGpuDependenciesCount;
using TimestampPackets<uint32_t>::packets;
};
void setTagToReadyState(TagNodeBase *tagNode) {
auto packetsUsed = tagNode->getPacketsUsed();
tagNode->initialize();
uint32_t zeros[4] = {};
for (uint32_t i = 0; i < TimestampPacketSizeControl::preferredPacketCount; i++) {
tagNode->assignDataToAllTimestamps(i, zeros);
}
tagNode->setPacketsUsed(packetsUsed);
}
const size_t gws[3] = {1, 1, 1};
};
struct TimestampPacketTests : public TimestampPacketSimpleTests {
struct MockTagNode : public TagNode<TimestampPackets<uint32_t>> {
using TagNode<TimestampPackets<uint32_t>>::gpuAddress;
};
void SetUp() override {
DebugManager.flags.EnableTimestampPacket.set(1);
executionEnvironment = platform()->peekExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(2);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
}
device = std::make_unique<MockClDevice>(Device::create<MockDevice>(executionEnvironment, 0u));
context = new MockContext(device.get());
kernel = std::make_unique<MockKernelWithInternals>(*device, context);
mockCmdQ = new MockCommandQueue(context, device.get(), nullptr);
}
void TearDown() override {
mockCmdQ->release();
context->release();
}
template <typename MI_SEMAPHORE_WAIT>
void verifySemaphore(MI_SEMAPHORE_WAIT *semaphoreCmd, TagNodeBase *timestampPacketNode, uint32_t packetId) {
EXPECT_NE(nullptr, semaphoreCmd);
EXPECT_EQ(semaphoreCmd->getCompareOperation(), MI_SEMAPHORE_WAIT::COMPARE_OPERATION::COMPARE_OPERATION_SAD_NOT_EQUAL_SDD);
EXPECT_EQ(1u, semaphoreCmd->getSemaphoreDataDword());
uint64_t compareOffset = packetId * TimestampPackets<uint32_t>::getSinglePacketSize();
auto dataAddress = TimestampPacketHelper::getContextEndGpuAddress(*timestampPacketNode) + compareOffset;
EXPECT_EQ(dataAddress, semaphoreCmd->getSemaphoreGraphicsAddress());
};
template <typename GfxFamily>
void verifyMiAtomic(typename GfxFamily::MI_ATOMIC *miAtomicCmd, TagNodeBase *timestampPacketNode) {
using MI_ATOMIC = typename GfxFamily::MI_ATOMIC;
EXPECT_NE(nullptr, miAtomicCmd);
auto writeAddress = TimestampPacketHelper::getGpuDependenciesCountGpuAddress(*timestampPacketNode);
EXPECT_EQ(MI_ATOMIC::ATOMIC_OPCODES::ATOMIC_4B_INCREMENT, miAtomicCmd->getAtomicOpcode());
EXPECT_EQ(writeAddress, UnitTestHelper<GfxFamily>::getMemoryAddress(*miAtomicCmd));
};
void verifyDependencyCounterValues(TimestampPacketContainer *timestampPacketContainer, uint32_t expectedValue) {
auto &nodes = timestampPacketContainer->peekNodes();
EXPECT_NE(0u, nodes.size());
for (auto &node : nodes) {
EXPECT_EQ(expectedValue, node->getImplicitCpuDependenciesCount());
}
}
ExecutionEnvironment *executionEnvironment;
std::unique_ptr<MockClDevice> device;
MockContext *context;
std::unique_ptr<MockKernelWithInternals> kernel;
MockCommandQueue *mockCmdQ;
DebugManagerStateRestore restorer;
};