From b11e0825c98f17053d427846d159cd55b1eefe67 Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Sun, 27 Jan 2019 17:36:42 +0100 Subject: [PATCH] AUB capture with support for allocation dumps Change-Id: I90a2b75043c33af92e4557be37cde4b9699582c6 --- runtime/aub_mem_dump/CMakeLists.txt | 4 +- runtime/aub_mem_dump/aub_alloc_dump.h | 48 +++ runtime/aub_mem_dump/aub_alloc_dump.inl | 178 +++++++++ runtime/command_queue/command_queue_hw.inl | 9 +- .../aub_command_stream_receiver_hw.h | 1 + .../aub_command_stream_receiver_hw.inl | 31 +- .../tbx_command_stream_receiver_hw.inl | 5 +- runtime/gen10/aub_mem_dump_gen10.cpp | 20 +- runtime/gen8/aub_mem_dump_gen8.cpp | 20 +- runtime/gen9/aub_mem_dump_gen9.cpp | 20 +- runtime/os_interface/debug_variables_base.inl | 3 + .../aub_stream/headers/hardware_context.h | 5 +- unit_tests/aub_mem_dump/CMakeLists.txt | 3 +- .../aub_mem_dump/aub_alloc_dump_tests.cpp | 338 ++++++++++++++++++ .../enqueue_read_buffer_tests.cpp | 42 +++ .../enqueue_read_image_tests.cpp | 34 +- .../aub_command_stream_receiver_2_tests.cpp | 120 +++++++ unit_tests/mocks/mock_aub_manager.h | 2 + unit_tests/test_files/igdrcl.config | 3 + 19 files changed, 873 insertions(+), 13 deletions(-) create mode 100644 runtime/aub_mem_dump/aub_alloc_dump.h create mode 100644 runtime/aub_mem_dump/aub_alloc_dump.inl create mode 100644 unit_tests/aub_mem_dump/aub_alloc_dump_tests.cpp diff --git a/runtime/aub_mem_dump/CMakeLists.txt b/runtime/aub_mem_dump/CMakeLists.txt index 7a9ed2f420..ec4eec2eb6 100644 --- a/runtime/aub_mem_dump/CMakeLists.txt +++ b/runtime/aub_mem_dump/CMakeLists.txt @@ -1,11 +1,13 @@ # -# Copyright (C) 2018 Intel Corporation +# Copyright (C) 2019 Intel Corporation # # SPDX-License-Identifier: MIT # set(RUNTIME_SRCS_AUB_MEM_DUMP ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/aub_alloc_dump.h + ${CMAKE_CURRENT_SOURCE_DIR}/aub_alloc_dump.inl ${CMAKE_CURRENT_SOURCE_DIR}/aub_data.h ${CMAKE_CURRENT_SOURCE_DIR}/aub_header.h ${CMAKE_CURRENT_SOURCE_DIR}/aub_mem_dump.cpp diff --git a/runtime/aub_mem_dump/aub_alloc_dump.h b/runtime/aub_mem_dump/aub_alloc_dump.h new file mode 100644 index 0000000000..ac505cfe7c --- /dev/null +++ b/runtime/aub_mem_dump/aub_alloc_dump.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "runtime/aub_mem_dump/aub_mem_dump.h" +#include "runtime/gmm_helper/gmm_helper.h" +#include "runtime/gmm_helper/resource_info.h" +#include "runtime/helpers/options.h" +#include "runtime/memory_manager/graphics_allocation.h" +#include "runtime/os_interface/debug_settings_manager.h" + +using namespace OCLRT; + +namespace AubAllocDump { + +inline bool isWritableBuffer(GraphicsAllocation &gfxAllocation) { + return (gfxAllocation.getAllocationType() == GraphicsAllocation::AllocationType::BUFFER || gfxAllocation.getAllocationType() == GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY) && + gfxAllocation.isMemObjectsAllocationWithWritableFlags(); +} + +inline bool isWritableImage(GraphicsAllocation &gfxAllocation) { + return (gfxAllocation.getAllocationType() == GraphicsAllocation::AllocationType::IMAGE) && + gfxAllocation.isMemObjectsAllocationWithWritableFlags(); +} + +template +uint32_t getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE gmmResourceType); + +template +void dumpBufferInBinFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template +void dumpImageInBmpFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template +void dumpBufferInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template +void dumpImageInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template +void dumpAllocation(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); +} // namespace AubAllocDump diff --git a/runtime/aub_mem_dump/aub_alloc_dump.inl b/runtime/aub_mem_dump/aub_alloc_dump.inl new file mode 100644 index 0000000000..9c0790120e --- /dev/null +++ b/runtime/aub_mem_dump/aub_alloc_dump.inl @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/aub_mem_dump/aub_alloc_dump.h" +#include "runtime/gmm_helper/gmm.h" + +using namespace OCLRT; + +namespace AubAllocDump { + +template +uint32_t getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE gmmResourceType) { + using RENDER_SURFACE_STATE = typename GfxFamily::RENDER_SURFACE_STATE; + auto surfaceType = RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_NULL; + + switch (gmmResourceType) { + case GMM_RESOURCE_TYPE::RESOURCE_1D: + surfaceType = RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_1D; + break; + case GMM_RESOURCE_TYPE::RESOURCE_2D: + surfaceType = RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_2D; + break; + case GMM_RESOURCE_TYPE::RESOURCE_3D: + surfaceType = RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_3D; + break; + default: + DEBUG_BREAK_IF(true); + break; + } + return surfaceType; +} + +template +void dumpBufferInBinFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context) { + AubMemDump::AubCaptureBinaryDumpHD cmd; + memset(&cmd, 0, sizeof(cmd)); + cmd.Header.Type = 0x7; + cmd.Header.Opcode = 0x1; + cmd.Header.SubOp = 0x15; + cmd.Header.DwordLength = ((sizeof(cmd) - sizeof(cmd.Header)) / sizeof(uint32_t)) - 1; + + cmd.setHeight(1); + cmd.setWidth(gfxAllocation.getUnderlyingBufferSize()); + cmd.setBaseAddr(gfxAllocation.getGpuAddress()); + cmd.setPitch(gfxAllocation.getUnderlyingBufferSize()); + cmd.GttType = 1; + cmd.DirectoryHandle = context; + + stream->write(reinterpret_cast(&cmd), sizeof(cmd)); +} + +template +void dumpImageInBmpFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context) { + auto gmm = gfxAllocation.gmm; + + AubMemDump::AubCmdDumpBmpHd cmd; + memset(&cmd, 0, sizeof(cmd)); + cmd.Header.Type = 0x7; + cmd.Header.Opcode = 0x1; + cmd.Header.SubOp = 0x44; + cmd.Header.DwordLength = ((sizeof(cmd) - sizeof(cmd.Header)) / sizeof(uint32_t)) - 1; + + cmd.Xmin = 0; + cmd.Ymin = 0; + auto pitch = gmm->gmmResourceInfo->getRenderPitch(); + auto bitsPerPixel = gmm->gmmResourceInfo->getBitsPerPixel(); + auto pitchInPixels = static_cast(8 * pitch / bitsPerPixel); + cmd.BufferPitch = pitchInPixels; + cmd.BitsPerPixel = bitsPerPixel; + cmd.Format = gmm->gmmResourceInfo->getResourceFormatSurfaceState(); + cmd.Xsize = static_cast(gmm->gmmResourceInfo->getBaseWidth()); + cmd.Ysize = static_cast(gmm->gmmResourceInfo->getBaseHeight()); + cmd.setBaseAddr(gfxAllocation.getGpuAddress()); + cmd.Secure = 0; + cmd.UseFence = 0; + auto flagInfo = gmm->gmmResourceInfo->getResourceFlags()->Info; + cmd.TileOn = flagInfo.TiledW || flagInfo.TiledX || flagInfo.TiledY || flagInfo.TiledYf || flagInfo.TiledYs; + cmd.WalkY = flagInfo.TiledY; + cmd.UsePPGTT = 1; + cmd.Use32BitDump = 1; // Dump out in 32bpp vs 24bpp + cmd.UseFullFormat = 1; + cmd.DirectoryHandle = context; + + stream->write(reinterpret_cast(&cmd), sizeof(cmd)); +} + +template +void dumpBufferInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context) { + using RENDER_SURFACE_STATE = typename GfxFamily::RENDER_SURFACE_STATE; + using SURFACE_FORMAT = typename RENDER_SURFACE_STATE::SURFACE_FORMAT; + + AubMemDump::CmdServicesMemTraceDumpCompress cmd; + memset(&cmd, 0, sizeof(AubMemDump::CmdServicesMemTraceDumpCompress)); + + cmd.dwordCount = (sizeof(AubMemDump::CmdServicesMemTraceDumpCompress) - 1) / 4; + cmd.instructionSubOpcode = 0x10; + cmd.instructionOpcode = 0x2e; + cmd.instructionType = 0x7; + + cmd.setSurfaceAddress(gfxAllocation.getGpuAddress()); + cmd.surfaceWidth = static_cast(gfxAllocation.getUnderlyingBufferSize()); + cmd.surfaceHeight = 1; + cmd.surfacePitch = static_cast(gfxAllocation.getUnderlyingBufferSize()); + cmd.surfaceFormat = SURFACE_FORMAT::SURFACE_FORMAT_RAW; + cmd.dumpType = AubMemDump::CmdServicesMemTraceDumpCompress::DumpTypeValues::Tre; + cmd.surfaceTilingType = RENDER_SURFACE_STATE::TILE_MODE_LINEAR; + cmd.surfaceType = RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_BUFFER; + + cmd.algorithm = AubMemDump::CmdServicesMemTraceDumpCompress::AlgorithmValues::Uncompressed; + + cmd.gttType = 1; + cmd.directoryHandle = context; + + stream->write(reinterpret_cast(&cmd), sizeof(cmd)); +} + +template +void dumpImageInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context) { + using RENDER_SURFACE_STATE = typename GfxFamily::RENDER_SURFACE_STATE; + auto gmm = gfxAllocation.gmm; + if ((gmm->gmmResourceInfo->getNumSamples() > 1) || (gmm->isRenderCompressed)) { + DEBUG_BREAK_IF(true); //unsupported + return; + } + + auto surfaceType = getImageSurfaceTypeFromGmmResourceType(gmm->gmmResourceInfo->getResourceType()); + + AubMemDump::CmdServicesMemTraceDumpCompress cmd; + memset(&cmd, 0, sizeof(AubMemDump::CmdServicesMemTraceDumpCompress)); + + cmd.dwordCount = (sizeof(AubMemDump::CmdServicesMemTraceDumpCompress) - 1) / 4; + cmd.instructionSubOpcode = 0x10; + cmd.instructionOpcode = 0x2e; + cmd.instructionType = 0x7; + + cmd.setSurfaceAddress(gfxAllocation.getGpuAddress()); + cmd.surfaceWidth = static_cast(gmm->gmmResourceInfo->getBaseWidth()); + cmd.surfaceHeight = static_cast(gmm->gmmResourceInfo->getBaseHeight()); + cmd.surfacePitch = static_cast(gmm->gmmResourceInfo->getRenderPitch()); + cmd.surfaceFormat = gmm->gmmResourceInfo->getResourceFormatSurfaceState(); + cmd.dumpType = AubMemDump::CmdServicesMemTraceDumpCompress::DumpTypeValues::Tre; + cmd.surfaceTilingType = gmm->gmmResourceInfo->getTileModeSurfaceState(); + cmd.surfaceType = surfaceType; + + cmd.algorithm = AubMemDump::CmdServicesMemTraceDumpCompress::AlgorithmValues::Uncompressed; + + cmd.gttType = 1; + cmd.directoryHandle = context; + + stream->write(reinterpret_cast(&cmd), sizeof(cmd)); +} + +template +void dumpAllocation(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context) { + auto dumpBufferFormat = DebugManager.flags.AUBDumpBufferFormat.get(); + auto dumpImageFormat = DebugManager.flags.AUBDumpImageFormat.get(); + auto isDumpableBuffer = isWritableBuffer(gfxAllocation); + auto isDumpableImage = isWritableImage(gfxAllocation); + + if (isDumpableBuffer) { + if (0 == dumpBufferFormat.compare("BIN")) { + dumpBufferInBinFormat(gfxAllocation, stream, context); + } else if (0 == dumpBufferFormat.compare("TRE")) { + dumpBufferInTreFormat(gfxAllocation, stream, context); + } + } else if (isDumpableImage) { + if (0 == dumpImageFormat.compare("BMP")) { + dumpImageInBmpFormat(gfxAllocation, stream, context); + } else if (0 == dumpImageFormat.compare("TRE")) { + dumpImageInTreFormat(gfxAllocation, stream, context); + } + } +} +} // namespace AubAllocDump diff --git a/runtime/command_queue/command_queue_hw.inl b/runtime/command_queue/command_queue_hw.inl index 36ab0b0ba2..ce53b1f5f4 100644 --- a/runtime/command_queue/command_queue_hw.inl +++ b/runtime/command_queue/command_queue_hw.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -30,8 +30,15 @@ namespace OCLRT { template void CommandQueueHw::notifyEnqueueReadBuffer(Buffer *buffer, bool blockingRead) { + if (DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.get()) { + buffer->getGraphicsAllocation()->setAllocDumpable(blockingRead); + buffer->forceDisallowCPUCopy = blockingRead; + } } template void CommandQueueHw::notifyEnqueueReadImage(Image *image, bool blockingRead) { + if (DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.get()) { + image->getGraphicsAllocation()->setAllocDumpable(blockingRead); + } } } // namespace OCLRT diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index ae8a24e1f7..eac24f85f4 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -64,6 +64,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw void AUBCommandStreamReceiverHw::submitBatchBuffer(size_t engineIndex, uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) { if (hardwareContext) { if (batchBufferSize) { - hardwareContext->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank); + hardwareContext->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, MemoryConstants::pageSize64k); } return; } @@ -605,7 +608,7 @@ template void AUBCommandStreamReceiverHw::writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits, DevicesBitfield devicesBitfield) { if (aubManager) { int hint = AubMemDump::DataTypeHintValues::TraceNotype; - aubManager->writeMemory(gpuAddress, cpuAddress, size, memoryBank, hint); + aubManager->writeMemory(gpuAddress, cpuAddress, size, memoryBank, hint, MemoryConstants::pageSize64k); return; } @@ -738,9 +741,33 @@ void AUBCommandStreamReceiverHw::processResidency(ResidencyContainer dumpAubNonWritable = false; } +template +void AUBCommandStreamReceiverHw::dumpAllocation(GraphicsAllocation &gfxAllocation) { + if (DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.get()) { + if (!gfxAllocation.isAllocDumpable()) { + return; + } + gfxAllocation.setAllocDumpable(false); + } + + if (hardwareContext) { + if (AubAllocDump::isWritableBuffer(gfxAllocation)) { + if (0 == DebugManager.flags.AUBDumpBufferFormat.get().compare("BIN")) { + auto gpuAddress = GmmHelper::decanonize(gfxAllocation.getGpuAddress()); + auto size = gfxAllocation.getUnderlyingBufferSize(); + hardwareContext->dumpBufferBIN(gpuAddress, size); + } + } + return; + } + + AubAllocDump::dumpAllocation(gfxAllocation, getAubStream(), getDumpHandle()); +} + template void AUBCommandStreamReceiverHw::makeNonResident(GraphicsAllocation &gfxAllocation) { if (gfxAllocation.isResident(this->osContext->getContextId())) { + dumpAllocation(gfxAllocation); this->getEvictionAllocations().push_back(&gfxAllocation); gfxAllocation.releaseResidencyInOsContext(this->osContext->getContextId()); } diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.inl b/runtime/command_stream/tbx_command_stream_receiver_hw.inl index 7da9c90f02..28f1b4bfb0 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.inl +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.inl @@ -16,6 +16,7 @@ #include "runtime/helpers/ptr_math.h" #include "runtime/memory_manager/graphics_allocation.h" #include "runtime/memory_manager/memory_banks.h" +#include "runtime/memory_manager/memory_constants.h" #include "runtime/memory_manager/physical_address_allocator.h" #include "runtime/command_stream/command_stream_receiver_with_aub_dump.h" #include "runtime/os_interface/debug_settings_manager.h" @@ -218,7 +219,7 @@ template void TbxCommandStreamReceiverHw::submitBatchBuffer(size_t engineIndex, uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) { if (hardwareContext) { if (batchBufferSize) { - hardwareContext->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank); + hardwareContext->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, MemoryConstants::pageSize64k); } return; } @@ -366,7 +367,7 @@ template void TbxCommandStreamReceiverHw::writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits, DevicesBitfield devicesBitfield) { if (hardwareContext) { int hint = AubMemDump::DataTypeHintValues::TraceNotype; - hardwareContext->writeMemory(gpuAddress, cpuAddress, size, memoryBank, hint); + hardwareContext->writeMemory(gpuAddress, cpuAddress, size, memoryBank, hint, MemoryConstants::pageSize64k); return; } diff --git a/runtime/gen10/aub_mem_dump_gen10.cpp b/runtime/gen10/aub_mem_dump_gen10.cpp index b7f91188df..6a330deeba 100644 --- a/runtime/gen10/aub_mem_dump_gen10.cpp +++ b/runtime/gen10/aub_mem_dump_gen10.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,8 +7,10 @@ #include "config.h" #include "aub_mapper.h" +#include "runtime/aub_mem_dump/aub_alloc_dump.inl" #include "runtime/aub_mem_dump/aub_mem_dump.inl" #include "runtime/helpers/completion_stamp.h" +#include "runtime/helpers/hw_helper.h" namespace AubMemDump { @@ -76,3 +78,19 @@ const MMIOList *AUBFamilyMapper::perEngineMMIO[EngineType::NUM_ENGINES] &mmioListVCS, &mmioListVECS}; } // namespace OCLRT + +namespace AubAllocDump { +using namespace OCLRT; + +template uint32_t getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE gmmResourceType); + +template void dumpBufferInBinFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpImageInBmpFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpBufferInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpImageInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpAllocation(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); +} // namespace AubAllocDump diff --git a/runtime/gen8/aub_mem_dump_gen8.cpp b/runtime/gen8/aub_mem_dump_gen8.cpp index 00268875c7..aac73e77d9 100644 --- a/runtime/gen8/aub_mem_dump_gen8.cpp +++ b/runtime/gen8/aub_mem_dump_gen8.cpp @@ -1,12 +1,14 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "aub_mapper.h" +#include "runtime/aub_mem_dump/aub_alloc_dump.inl" #include "runtime/aub_mem_dump/aub_mem_dump.inl" +#include "runtime/helpers/hw_helper.h" namespace AubMemDump { @@ -61,3 +63,19 @@ const MMIOList *AUBFamilyMapper::perEngineMMIO[EngineType::NUM_ENGINES] &mmioListVCS, &mmioListVECS}; } // namespace OCLRT + +namespace AubAllocDump { +using namespace OCLRT; + +template uint32_t getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE gmmResourceType); + +template void dumpBufferInBinFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpImageInBmpFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpBufferInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpImageInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpAllocation(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); +} // namespace AubAllocDump diff --git a/runtime/gen9/aub_mem_dump_gen9.cpp b/runtime/gen9/aub_mem_dump_gen9.cpp index 6a0a5c5495..6c9593a6a4 100644 --- a/runtime/gen9/aub_mem_dump_gen9.cpp +++ b/runtime/gen9/aub_mem_dump_gen9.cpp @@ -1,12 +1,14 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "aub_mapper.h" +#include "runtime/aub_mem_dump/aub_alloc_dump.inl" #include "runtime/aub_mem_dump/aub_mem_dump.inl" +#include "runtime/helpers/hw_helper.h" namespace AubMemDump { @@ -74,3 +76,19 @@ const MMIOList *AUBFamilyMapper::perEngineMMIO[EngineType::NUM_ENGINES] &mmioListVECS}; } // namespace OCLRT + +namespace AubAllocDump { +using namespace OCLRT; + +template uint32_t getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE gmmResourceType); + +template void dumpBufferInBinFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpImageInBmpFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpBufferInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpImageInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); + +template void dumpAllocation(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context); +} // namespace AubAllocDump diff --git a/runtime/os_interface/debug_variables_base.inl b/runtime/os_interface/debug_variables_base.inl index e8b56bb5d6..6ec34020aa 100644 --- a/runtime/os_interface/debug_variables_base.inl +++ b/runtime/os_interface/debug_variables_base.inl @@ -10,6 +10,8 @@ DECLARE_DEBUG_VARIABLE(std::string, TbxServer, std::string("127.0.0.1"), "TCP-IP DECLARE_DEBUG_VARIABLE(std::string, ProductFamilyOverride, std::string("unk"), "Specify product for use in AUB/TBX") DECLARE_DEBUG_VARIABLE(std::string, HardwareInfoOverride, std::string("default"), "Specify hardware info config, i.e 1x4x8, for use in AUB/TBX") DECLARE_DEBUG_VARIABLE(std::string, ForceCompilerUsePlatform, std::string("unk"), "Specify product for use in compiler interface") +DECLARE_DEBUG_VARIABLE(std::string, AUBDumpBufferFormat, std::string("unk"), "Specify buffer format to be dumped in AUB files (TRE or BIN)") +DECLARE_DEBUG_VARIABLE(std::string, AUBDumpImageFormat, std::string("unk"), "Specify image format to to be dumped in AUB files (TRE or BMP)") DECLARE_DEBUG_VARIABLE(std::string, AUBDumpCaptureFileName, std::string("unk"), "Name of file to save AUB capture into") DECLARE_DEBUG_VARIABLE(std::string, AUBDumpFilterKernelName, std::string("unk"), "Name of kernel to AUB capture") DECLARE_DEBUG_VARIABLE(std::string, AUBDumpToggleFileName, std::string("unk"), "Name of file to save AUB in toggle mode") @@ -28,6 +30,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, TbxPort, 4321, "TCP-IP port of TBX server") DECLARE_DEBUG_VARIABLE(bool, FlattenBatchBufferForAUBDump, false, "Dump multi-level batch buffers to AUB as single, flat batch buffer") DECLARE_DEBUG_VARIABLE(bool, AddPatchInfoCommentsForAUBDump, false, "Dump comments containing allocations and patching information") DECLARE_DEBUG_VARIABLE(bool, UseAubStream, true, "Use aub_stream for aub dumping") +DECLARE_DEBUG_VARIABLE(bool, AUBDumpAllocsOnEnqueueReadOnly, false, "Force dumping buffers and images on clEnqueueReadBuffer/Image only (blocking calls)") DECLARE_DEBUG_VARIABLE(bool, AUBDumpForceAllToLocalMemory, false, "Force placing every allocation in local memory address space") DECLARE_DEBUG_VARIABLE(bool, AUBDumpConcurrentCS, false, "Enable concurrent execution on CS (disabled by default)") diff --git a/third_party/aub_stream/headers/hardware_context.h b/third_party/aub_stream/headers/hardware_context.h index 0162d67182..c23f473374 100644 --- a/third_party/aub_stream/headers/hardware_context.h +++ b/third_party/aub_stream/headers/hardware_context.h @@ -14,11 +14,12 @@ namespace aub_stream { struct HardwareContext { virtual void initialize() = 0; virtual void pollForCompletion() = 0; - virtual void submit(uint64_t gfxAddress, const void *batchBuffer, size_t size, uint32_t memoryBanks, size_t pageSize = 65536) = 0; - virtual void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize = 65536) = 0; + virtual void submit(uint64_t gfxAddress, const void *batchBuffer, size_t size, uint32_t memoryBanks, size_t pageSize) = 0; + virtual void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize) = 0; virtual void freeMemory(uint64_t gfxAddress, size_t size) = 0; virtual void expectMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t compareOperation) = 0; virtual void readMemory(uint64_t gfxAddress, void *memory, size_t size) = 0; + virtual void dumpBufferBIN(uint64_t gfxAddress, size_t size) = 0; virtual ~HardwareContext() = default; }; diff --git a/unit_tests/aub_mem_dump/CMakeLists.txt b/unit_tests/aub_mem_dump/CMakeLists.txt index 8846aad6a7..974964c88e 100644 --- a/unit_tests/aub_mem_dump/CMakeLists.txt +++ b/unit_tests/aub_mem_dump/CMakeLists.txt @@ -1,11 +1,12 @@ # -# Copyright (C) 2018 Intel Corporation +# Copyright (C) 2018-2019 Intel Corporation # # SPDX-License-Identifier: MIT # set(IGDRCL_SRCS_aub_mem_dump_tests ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/aub_alloc_dump_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/lrca_helper_tests.cpp ) target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_aub_mem_dump_tests}) diff --git a/unit_tests/aub_mem_dump/aub_alloc_dump_tests.cpp b/unit_tests/aub_mem_dump/aub_alloc_dump_tests.cpp new file mode 100644 index 0000000000..40b4ddc117 --- /dev/null +++ b/unit_tests/aub_mem_dump/aub_alloc_dump_tests.cpp @@ -0,0 +1,338 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/aub_mem_dump/aub_alloc_dump.h" +#include "runtime/gmm_helper/gmm.h" +#include "runtime/mem_obj/buffer.h" +#include "test.h" +#include "unit_tests/fixtures/device_fixture.h" +#include "unit_tests/fixtures/image_fixture.h" +#include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/mocks/mock_gmm_resource_info.h" + +using namespace OCLRT; + +typedef Test AubAllocDumpTests; + +struct AubFileStreamMock : public AubMemDump::AubFileStream { + void write(const char *data, size_t size) override { + buffer.resize(size); + memcpy(buffer.data(), data, size); + } + char *getData() { + return buffer.data(); + } + size_t getSize() { + return buffer.size(); + } + std::vector buffer; +}; + +HWTEST_F(AubAllocDumpTests, givenBufferOrImageWhenGraphicsAllocationIsKnownThenItsTypeCanBeCheckedIfItIsWritable) { + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + + gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); + EXPECT_FALSE(gfxAllocation->isMemObjectsAllocationWithWritableFlags()); + EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation)); + + gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); + gfxAllocation->setMemObjectsAllocationWithWritableFlags(true); + EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation)); + + gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE); + gfxAllocation->setMemObjectsAllocationWithWritableFlags(false); + EXPECT_FALSE(AubAllocDump::isWritableImage(*gfxAllocation)); + + gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE); + gfxAllocation->setMemObjectsAllocationWithWritableFlags(true); + EXPECT_TRUE(AubAllocDump::isWritableImage(*gfxAllocation)); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(AubAllocDumpTests, givenImageResourceWhenGmmResourceInfoIsAvailableThenImageSurfaceTypeCanBeDeducedFromGmmResourceType) { + using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE; + + EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_1D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE::RESOURCE_1D)); + EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_2D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE::RESOURCE_2D)); + EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_3D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE::RESOURCE_3D)); + EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_NULL, AubAllocDump::getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE::RESOURCE_INVALID)); +} + +HWTEST_F(AubAllocDumpTests, givenGraphicsAllocationWhenDumpAllocationIsCalledInDefaultModeThenGraphicsAllocationShouldNotBeDumped) { + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), 0); + + EXPECT_EQ(0u, mockAubFileStream->getSize()); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(AubAllocDumpTests, givenGraphicsAllocationWhenDumpAllocationIsCalledButDumpFormatIsUnspecifiedThenGraphicsAllocationShouldNotBeDumped) { + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), 0); + + EXPECT_EQ(0u, mockAubFileStream->getSize()); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(AubAllocDumpTests, givenNonWritableBufferWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenBufferShouldNotBeDumped) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); + + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), 0); + + EXPECT_EQ(0u, mockAubFileStream->getSize()); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(AubAllocDumpTests, givenNonWritableImageWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenImageShouldNotBeDumped) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpBufferFormat.set("BMP"); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE); + + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), 0); + + EXPECT_EQ(0u, mockAubFileStream->getSize()); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(AubAllocDumpTests, givenWritableBufferWhenDumpAllocationIsCalledAndAubDumpBufferFormatIsNotSetThenBufferShouldNotBeDumped) { + MockContext context; + size_t bufferSize = 10; + auto retVal = CL_INVALID_VALUE; + std::unique_ptr buffer(Buffer::create(&context, CL_MEM_READ_WRITE, bufferSize, nullptr, retVal)); + ASSERT_NE(nullptr, buffer); + + auto gfxAllocation = buffer->getGraphicsAllocation(); + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + auto handle = static_cast(reinterpret_cast(this)); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), handle); + EXPECT_EQ(0u, mockAubFileStream->getSize()); +} + +HWTEST_F(AubAllocDumpTests, givenWritableImageWhenDumpAllocationIsCalledAndAubDumpImageFormatIsNotSetThenImageShouldNotBeDumped) { + MockContext context; + std::unique_ptr image(ImageHelper::create(&context)); + ASSERT_NE(nullptr, image); + + auto gfxAllocation = image->getGraphicsAllocation(); + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + auto handle = static_cast(reinterpret_cast(this)); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), handle); + EXPECT_EQ(0u, mockAubFileStream->getSize()); +} + +HWTEST_F(AubAllocDumpTests, givenWritableBufferWhenDumpAllocationIsCalledAndAubDumpBufferFormatIsSetToBinThenBufferShouldBeDumpedInBinFormat) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + + MockContext context; + size_t bufferSize = 10; + auto retVal = CL_INVALID_VALUE; + std::unique_ptr buffer(Buffer::create(&context, CL_MEM_READ_WRITE, bufferSize, nullptr, retVal)); + ASSERT_NE(nullptr, buffer); + + auto gfxAllocation = buffer->getGraphicsAllocation(); + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + auto handle = static_cast(reinterpret_cast(this)); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), handle); + ASSERT_EQ(sizeof(AubMemDump::AubCaptureBinaryDumpHD), mockAubFileStream->getSize()); + + AubMemDump::AubCaptureBinaryDumpHD cmd; + memcpy(&cmd, mockAubFileStream->getData(), mockAubFileStream->getSize()); + + EXPECT_EQ(0x7u, cmd.Header.Type); + EXPECT_EQ(0x1u, cmd.Header.Opcode); + EXPECT_EQ(0x15u, cmd.Header.SubOp); + EXPECT_EQ(((sizeof(cmd) - sizeof(cmd.Header)) / sizeof(uint32_t)) - 1, cmd.Header.DwordLength); + + EXPECT_EQ(gfxAllocation->getGpuAddress(), cmd.getBaseAddr()); + EXPECT_EQ(static_cast(gfxAllocation->getUnderlyingBufferSize()), cmd.getWidth()); + EXPECT_EQ(1u, cmd.getHeight()); + EXPECT_EQ(static_cast(gfxAllocation->getUnderlyingBufferSize()), cmd.getPitch()); + EXPECT_EQ(1u, cmd.GttType); + EXPECT_EQ(handle, cmd.DirectoryHandle); +} + +HWTEST_F(AubAllocDumpTests, givenWritableBufferWhenDumpAllocationIsCalledAndAubDumpBufferFormatIsSetToTreThenBufferShouldBeDumpedInTreFormat) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpBufferFormat.set("TRE"); + + MockContext context; + size_t bufferSize = 10; + auto retVal = CL_INVALID_VALUE; + std::unique_ptr buffer(Buffer::create(&context, CL_MEM_READ_WRITE, bufferSize, nullptr, retVal)); + ASSERT_NE(nullptr, buffer); + + auto gfxAllocation = buffer->getGraphicsAllocation(); + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + auto handle = static_cast(reinterpret_cast(this)); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), handle); + ASSERT_EQ(sizeof(AubMemDump::CmdServicesMemTraceDumpCompress), mockAubFileStream->getSize()); + + AubMemDump::CmdServicesMemTraceDumpCompress cmd; + memcpy(&cmd, mockAubFileStream->getData(), mockAubFileStream->getSize()); + + EXPECT_EQ((sizeof(AubMemDump::CmdServicesMemTraceDumpCompress) - 1) / 4, cmd.dwordCount); + EXPECT_EQ(0x7u, cmd.instructionType); + EXPECT_EQ(0x10u, cmd.instructionSubOpcode); + EXPECT_EQ(0x2eu, cmd.instructionOpcode); + + using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE; + using SURFACE_FORMAT = typename RENDER_SURFACE_STATE::SURFACE_FORMAT; + EXPECT_EQ(gfxAllocation->getGpuAddress(), cmd.getSurfaceAddress()); + EXPECT_EQ(static_cast(gfxAllocation->getUnderlyingBufferSize()), cmd.surfaceWidth); + EXPECT_EQ(1u, cmd.surfaceHeight); + EXPECT_EQ(static_cast(gfxAllocation->getUnderlyingBufferSize()), cmd.surfacePitch); + EXPECT_EQ(SURFACE_FORMAT::SURFACE_FORMAT_RAW, cmd.surfaceFormat); + EXPECT_EQ(AubMemDump::CmdServicesMemTraceDumpCompress::DumpTypeValues::Tre, cmd.dumpType); + EXPECT_EQ(RENDER_SURFACE_STATE::TILE_MODE_LINEAR, cmd.surfaceTilingType); + EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_BUFFER, cmd.surfaceType); + + EXPECT_EQ(AubMemDump::CmdServicesMemTraceDumpCompress::AlgorithmValues::Uncompressed, cmd.algorithm); + + EXPECT_EQ(1u, cmd.gttType); + EXPECT_EQ(handle, cmd.directoryHandle); +} + +HWTEST_F(AubAllocDumpTests, givenWritableImageWhenDumpAllocationIsCalledAndAubDumpImageFormatIsSetToBmpThenImageShouldBeDumpedInBmpFormat) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpImageFormat.set("BMP"); + + MockContext context; + std::unique_ptr image(ImageHelper::create(&context)); + ASSERT_NE(nullptr, image); + + auto gfxAllocation = image->getGraphicsAllocation(); + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + auto handle = static_cast(reinterpret_cast(this)); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), handle); + ASSERT_EQ(sizeof(AubMemDump::AubCmdDumpBmpHd), mockAubFileStream->getSize()); + + AubMemDump::AubCmdDumpBmpHd cmd; + memcpy(&cmd, mockAubFileStream->getData(), mockAubFileStream->getSize()); + + EXPECT_EQ(0x7u, cmd.Header.Type); + EXPECT_EQ(0x1u, cmd.Header.Opcode); + EXPECT_EQ(0x44u, cmd.Header.SubOp); + EXPECT_EQ(((sizeof(cmd) - sizeof(cmd.Header)) / sizeof(uint32_t)) - 1, cmd.Header.DwordLength); + + EXPECT_EQ(0u, cmd.Xmin); + EXPECT_EQ(0u, cmd.Ymin); + auto gmm = gfxAllocation->gmm; + EXPECT_EQ((8 * gmm->gmmResourceInfo->getRenderPitch()) / gmm->gmmResourceInfo->getBitsPerPixel(), cmd.BufferPitch); + EXPECT_EQ(gmm->gmmResourceInfo->getBitsPerPixel(), cmd.BitsPerPixel); + EXPECT_EQ(static_cast(gmm->gmmResourceInfo->getResourceFormatSurfaceState()), cmd.Format); + EXPECT_EQ(static_cast(gmm->gmmResourceInfo->getBaseWidth()), cmd.Xsize); + EXPECT_EQ(static_cast(gmm->gmmResourceInfo->getBaseHeight()), cmd.Ysize); + EXPECT_EQ(gfxAllocation->getGpuAddress(), cmd.getBaseAddr()); + EXPECT_EQ(0u, cmd.Secure); + EXPECT_EQ(0u, cmd.UseFence); + auto flagInfo = gmm->gmmResourceInfo->getResourceFlags()->Info; + EXPECT_EQ(static_cast(flagInfo.TiledW || flagInfo.TiledX || flagInfo.TiledY || flagInfo.TiledYf || flagInfo.TiledYs), cmd.TileOn); + EXPECT_EQ(flagInfo.TiledY, cmd.WalkY); + EXPECT_EQ(1u, cmd.UsePPGTT); + EXPECT_EQ(1u, cmd.Use32BitDump); + EXPECT_EQ(1u, cmd.UseFullFormat); + EXPECT_EQ(handle, cmd.DirectoryHandle); +} + +HWTEST_F(AubAllocDumpTests, givenWritableImageWhenDumpAllocationIsCalledAndAubDumpImageFormatIsSetToTreThenImageShouldBeDumpedInTreFormat) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpImageFormat.set("TRE"); + + MockContext context; + std::unique_ptr image(ImageHelper::create(&context)); + ASSERT_NE(nullptr, image); + + auto gfxAllocation = image->getGraphicsAllocation(); + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + auto handle = static_cast(reinterpret_cast(this)); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), handle); + ASSERT_EQ(sizeof(AubMemDump::CmdServicesMemTraceDumpCompress), mockAubFileStream->getSize()); + + AubMemDump::CmdServicesMemTraceDumpCompress cmd; + memcpy(&cmd, mockAubFileStream->getData(), mockAubFileStream->getSize()); + + EXPECT_EQ((sizeof(AubMemDump::CmdServicesMemTraceDumpCompress) - 1) / 4, cmd.dwordCount); + EXPECT_EQ(0x7u, cmd.instructionType); + EXPECT_EQ(0x10u, cmd.instructionSubOpcode); + EXPECT_EQ(0x2eu, cmd.instructionOpcode); + + using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE; + using SURFACE_FORMAT = typename RENDER_SURFACE_STATE::SURFACE_FORMAT; + EXPECT_EQ(gfxAllocation->getGpuAddress(), cmd.getSurfaceAddress()); + EXPECT_EQ(static_cast(gfxAllocation->gmm->gmmResourceInfo->getBaseWidth()), cmd.surfaceWidth); + EXPECT_EQ(static_cast(gfxAllocation->gmm->gmmResourceInfo->getBaseHeight()), cmd.surfaceHeight); + EXPECT_EQ(static_cast(gfxAllocation->gmm->gmmResourceInfo->getRenderPitch()), cmd.surfacePitch); + EXPECT_EQ(static_cast(gfxAllocation->gmm->gmmResourceInfo->getResourceFormatSurfaceState()), cmd.surfaceFormat); + EXPECT_EQ(AubMemDump::CmdServicesMemTraceDumpCompress::DumpTypeValues::Tre, cmd.dumpType); + EXPECT_EQ(gfxAllocation->gmm->gmmResourceInfo->getTileModeSurfaceState(), cmd.surfaceTilingType); + EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_2D, cmd.surfaceType); + + EXPECT_EQ(AubMemDump::CmdServicesMemTraceDumpCompress::AlgorithmValues::Uncompressed, cmd.algorithm); + + EXPECT_EQ(1u, cmd.gttType); + EXPECT_EQ(handle, cmd.directoryHandle); +} + +HWTEST_F(AubAllocDumpTests, givenCompressedImageWritableWhenDumpAllocationIsCalledAndAubDumpImageFormatIsSetToTreThenImageShouldBeDumpedInTreFormat) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpImageFormat.set("TRE"); + + MockContext context; + std::unique_ptr image(ImageHelper::create(&context)); + ASSERT_NE(nullptr, image); + + auto gfxAllocation = image->getGraphicsAllocation(); + gfxAllocation->gmm->isRenderCompressed = true; + + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + auto handle = static_cast(reinterpret_cast(this)); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), handle); + + EXPECT_EQ(0u, mockAubFileStream->getSize()); +} + +HWTEST_F(AubAllocDumpTests, givenMultisampleImageWritableWhenDumpAllocationIsCalledAndAubDumpImageFormatIsSetToTreThenImageDumpIsNotSupported) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpImageFormat.set("TRE"); + + MockContext context; + std::unique_ptr image(ImageHelper::create(&context)); + ASSERT_NE(nullptr, image); + + auto gfxAllocation = image->getGraphicsAllocation(); + auto mockGmmResourceInfo = reinterpret_cast(gfxAllocation->gmm->gmmResourceInfo.get()); + mockGmmResourceInfo->mockResourceCreateParams.MSAA.NumSamples = 2; + + std::unique_ptr mockAubFileStream(new AubFileStreamMock()); + auto handle = static_cast(reinterpret_cast(this)); + AubAllocDump::dumpAllocation(*gfxAllocation, mockAubFileStream.get(), handle); + + EXPECT_EQ(0u, mockAubFileStream->getSize()); +} diff --git a/unit_tests/command_queue/enqueue_read_buffer_tests.cpp b/unit_tests/command_queue/enqueue_read_buffer_tests.cpp index 3d3cbffa92..b4a488fef5 100644 --- a/unit_tests/command_queue/enqueue_read_buffer_tests.cpp +++ b/unit_tests/command_queue/enqueue_read_buffer_tests.cpp @@ -508,6 +508,48 @@ HWTEST_F(EnqueueReadBufferTypeTest, gicenEnqueueReadBufferCalledWhenLockedPtrInT EXPECT_EQ(0u, memoryManager.unlockResourceCalled); } +HWTEST_F(EnqueueReadBufferTypeTest, givenEnqueueReadBufferBlockingWhenAUBDumpAllocsOnEnqueueReadOnlyIsOnThenBufferShouldBeSetDumpable) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true); + + ASSERT_FALSE(srcBuffer->getGraphicsAllocation()->isAllocDumpable()); + cl_int retVal = CL_SUCCESS; + void *ptr = nonZeroCopyBuffer->getCpuAddressForMemoryTransfer(); + retVal = pCmdQ->enqueueReadBuffer(srcBuffer.get(), + CL_TRUE, + 0, + MemoryConstants::cacheLineSize, + ptr, + 0, + nullptr, + nullptr); + + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_TRUE(srcBuffer->getGraphicsAllocation()->isAllocDumpable()); + EXPECT_TRUE(srcBuffer->forceDisallowCPUCopy); +} + +HWTEST_F(EnqueueReadBufferTypeTest, givenEnqueueReadBufferNonBlockingWhenAUBDumpAllocsOnEnqueueReadOnlyIsOnThenBufferShouldntBeSetDumpable) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true); + + ASSERT_FALSE(srcBuffer->getGraphicsAllocation()->isAllocDumpable()); + cl_int retVal = CL_SUCCESS; + void *ptr = nonZeroCopyBuffer->getCpuAddressForMemoryTransfer(); + retVal = pCmdQ->enqueueReadBuffer(srcBuffer.get(), + CL_FALSE, + 0, + MemoryConstants::cacheLineSize, + ptr, + 0, + nullptr, + nullptr); + + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_FALSE(srcBuffer->getGraphicsAllocation()->isAllocDumpable()); + EXPECT_FALSE(srcBuffer->forceDisallowCPUCopy); +} + using NegativeFailAllocationTest = Test; HWTEST_F(NegativeFailAllocationTest, givenEnqueueReadBufferWhenHostPtrAllocationCreationFailsThenReturnOutOfResource) { diff --git a/unit_tests/command_queue/enqueue_read_image_tests.cpp b/unit_tests/command_queue/enqueue_read_image_tests.cpp index 94d5ed078a..2d424f36c5 100644 --- a/unit_tests/command_queue/enqueue_read_image_tests.cpp +++ b/unit_tests/command_queue/enqueue_read_image_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -391,6 +391,38 @@ HWTEST_F(EnqueueReadImageTest, givenCommandQueueWhenEnqueueReadImageIsCalledThen EXPECT_TRUE(mockCmdQ->notifyEnqueueReadImageCalled); } +HWTEST_F(EnqueueReadImageTest, givenEnqueueReadImageBlockingWhenAUBDumpAllocsOnEnqueueReadOnlyIsOnThenImageShouldBeSetDumpable) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true); + + std::unique_ptr srcImage(Image2dArrayHelper<>::create(context)); + auto imageDesc = srcImage->getImageDesc(); + size_t origin[] = {0, 0, 0}; + size_t region[] = {imageDesc.image_width, imageDesc.image_height, imageDesc.image_array_size}; + + ASSERT_FALSE(srcImage->getGraphicsAllocation()->isAllocDumpable()); + + EnqueueReadImageHelper<>::enqueueReadImage(pCmdQ, srcImage.get(), CL_TRUE, origin, region); + + EXPECT_TRUE(srcImage->getGraphicsAllocation()->isAllocDumpable()); +} + +HWTEST_F(EnqueueReadImageTest, givenEnqueueReadImageNonBlockingWhenAUBDumpAllocsOnEnqueueReadOnlyIsOnThenImageShouldntBeSetDumpable) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true); + + std::unique_ptr srcImage(Image2dArrayHelper<>::create(context)); + auto imageDesc = srcImage->getImageDesc(); + size_t origin[] = {0, 0, 0}; + size_t region[] = {imageDesc.image_width, imageDesc.image_height, imageDesc.image_array_size}; + + ASSERT_FALSE(srcImage->getGraphicsAllocation()->isAllocDumpable()); + + EnqueueReadImageHelper<>::enqueueReadImage(pCmdQ, srcImage.get(), CL_FALSE, origin, region); + + EXPECT_FALSE(srcImage->getGraphicsAllocation()->isAllocDumpable()); +} + typedef EnqueueReadImageMipMapTest MipMapReadImageTest; HWTEST_P(MipMapReadImageTest, GivenImageWithMipLevelNonZeroWhenReadImageIsCalledThenProperMipLevelIsSet) { diff --git a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp index e4fcab59e2..82321a3f51 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "runtime/aub_mem_dump/aub_alloc_dump.h" #include "runtime/aub_mem_dump/page_table_entry_bits.h" #include "runtime/mem_obj/mem_obj_helper.h" #include "test.h" @@ -13,6 +14,7 @@ #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/mocks/mock_aub_csr.h" #include "unit_tests/mocks/mock_aub_file_stream.h" +#include "unit_tests/mocks/mock_aub_manager.h" #include "unit_tests/mocks/mock_aub_subcapture_manager.h" #include "unit_tests/mocks/mock_command_queue.h" #include "unit_tests/mocks/mock_csr.h" @@ -878,3 +880,121 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenPhysica std::unique_ptr allocator(aubCsr.createPhysicalAddressAllocator(&hwInfoHelper)); ASSERT_NE(nullptr, allocator); } + +HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenGraphicsAllocationShouldBeDumped) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + auto mockManager = std::make_unique(); + auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + aubCsr.hardwareContext = std::unique_ptr(mockHardwareContext); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + + gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); + gfxAllocation->setMemObjectsAllocationWithWritableFlags(true); + EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation)); + + aubCsr.dumpAllocation(*gfxAllocation); + + EXPECT_TRUE(mockHardwareContext->dumpBufferBINCalled); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledButDumpFormatIsNotSpecifiedThenGraphicsAllocationShouldNotBeDumped) { + DebugManagerStateRestore dbgRestore; + + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + auto mockManager = std::make_unique(); + auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + aubCsr.hardwareContext = std::unique_ptr(mockHardwareContext); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + + gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); + gfxAllocation->setMemObjectsAllocationWithWritableFlags(true); + EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation)); + + aubCsr.dumpAllocation(*gfxAllocation); + + EXPECT_FALSE(mockHardwareContext->dumpBufferBINCalled); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNonWritableWhenDumpAllocationIsCalledAndFormatIsSpecifiedThenGraphicsAllocationShouldNotBeDumped) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + auto mockManager = std::make_unique(); + auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + aubCsr.hardwareContext = std::unique_ptr(mockHardwareContext); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + + gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); + gfxAllocation->setMemObjectsAllocationWithWritableFlags(false); + EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation)); + + aubCsr.dumpAllocation(*gfxAllocation); + + EXPECT_FALSE(mockHardwareContext->dumpBufferBINCalled); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNotDumpableWhenDumpAllocationIsCalledAndAUBDumpAllocsOnEnqueueReadOnlyIsSetThenGraphicsAllocationShouldNotBeDumpedAndRemainNonDumpable) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true); + DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + auto mockManager = std::make_unique(); + auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + aubCsr.hardwareContext = std::unique_ptr(mockHardwareContext); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + + gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); + gfxAllocation->setMemObjectsAllocationWithWritableFlags(true); + gfxAllocation->setAllocDumpable(false); + + aubCsr.dumpAllocation(*gfxAllocation); + + EXPECT_FALSE(gfxAllocation->isAllocDumpable()); + EXPECT_FALSE(mockHardwareContext->dumpBufferBINCalled); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpAllocationIsCalledAndAUBDumpAllocsOnEnqueueReadOnlyIsOnThenGraphicsAllocationShouldBeDumpedAndMarkedNonDumpable) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true); + DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + auto mockManager = std::make_unique(); + auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + aubCsr.hardwareContext = std::unique_ptr(mockHardwareContext); + + auto memoryManager = pDevice->getMemoryManager(); + auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + + gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER); + gfxAllocation->setMemObjectsAllocationWithWritableFlags(true); + gfxAllocation->setAllocDumpable(true); + + aubCsr.dumpAllocation(*gfxAllocation); + + EXPECT_FALSE(gfxAllocation->isAllocDumpable()); + EXPECT_TRUE(mockHardwareContext->dumpBufferBINCalled); + + memoryManager->freeGraphicsMemory(gfxAllocation); +} diff --git a/unit_tests/mocks/mock_aub_manager.h b/unit_tests/mocks/mock_aub_manager.h index f555eb2e17..8391f04f2c 100644 --- a/unit_tests/mocks/mock_aub_manager.h +++ b/unit_tests/mocks/mock_aub_manager.h @@ -20,6 +20,7 @@ struct MockHardwareContext : public aub_stream::HardwareContext { void freeMemory(uint64_t gfxAddress, size_t size) override { freeMemoryCalled = true; } void expectMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t compareOperation) override { expectMemoryCalled = true; } void readMemory(uint64_t gfxAddress, void *memory, size_t size) override { readMemoryCalled = true; }; + void dumpBufferBIN(uint64_t gfxAddress, size_t size) override { dumpBufferBINCalled = true; }; bool initializeCalled = false; bool pollForCompletionCalled = false; @@ -28,6 +29,7 @@ struct MockHardwareContext : public aub_stream::HardwareContext { bool freeMemoryCalled = false; bool expectMemoryCalled = false; bool readMemoryCalled = false; + bool dumpBufferBINCalled = false; uint32_t deviceIndex = 0; uint32_t engineIndex = 0; diff --git a/unit_tests/test_files/igdrcl.config b/unit_tests/test_files/igdrcl.config index 3b3d2c45ef..102f749199 100644 --- a/unit_tests/test_files/igdrcl.config +++ b/unit_tests/test_files/igdrcl.config @@ -71,6 +71,8 @@ OverrideAubDeviceId = -1 ForceCompilerUsePlatform = unk ForceCsrFlushing = 0 ForceCsrReprogramming = 0 +AUBDumpBufferFormat = unk +AUBDumpImageFormat = unk AUBDumpCaptureFileName = unk AUBDumpSubCaptureMode = 0 AUBDumpToggleFileName = unk @@ -100,6 +102,7 @@ PowerSavingMode = 0 AubDumpAddMmioRegistersList = unk RenderCompressedImagesEnabled = -1 RenderCompressedBuffersEnabled = -1 +AUBDumpAllocsOnEnqueueReadOnly = 0 AUBDumpForceAllToLocalMemory = 0 EnableCacheFlushAfterWalker = 0 EnableHostPtrTracking = 1