AUB capture with support for allocation dumps

Change-Id: I90a2b75043c33af92e4557be37cde4b9699582c6
This commit is contained in:
Milczarek, Slawomir 2019-01-27 17:36:42 +01:00
parent 7c390fa23b
commit b11e0825c9
19 changed files with 873 additions and 13 deletions

View File

@ -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

View File

@ -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 <typename GfxFamily>
uint32_t getImageSurfaceTypeFromGmmResourceType(GMM_RESOURCE_TYPE gmmResourceType);
template <typename GfxFamily>
void dumpBufferInBinFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template <typename GfxFamily>
void dumpImageInBmpFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template <typename GfxFamily>
void dumpBufferInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template <typename GfxFamily>
void dumpImageInTreFormat(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template <typename GfxFamily>
void dumpAllocation(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
} // namespace AubAllocDump

View File

@ -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 <typename GfxFamily>
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 <typename GfxFamily>
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<char *>(&cmd), sizeof(cmd));
}
template <typename GfxFamily>
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<uint32_t>(8 * pitch / bitsPerPixel);
cmd.BufferPitch = pitchInPixels;
cmd.BitsPerPixel = bitsPerPixel;
cmd.Format = gmm->gmmResourceInfo->getResourceFormatSurfaceState();
cmd.Xsize = static_cast<uint32_t>(gmm->gmmResourceInfo->getBaseWidth());
cmd.Ysize = static_cast<uint32_t>(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<char *>(&cmd), sizeof(cmd));
}
template <typename GfxFamily>
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<uint32_t>(gfxAllocation.getUnderlyingBufferSize());
cmd.surfaceHeight = 1;
cmd.surfacePitch = static_cast<uint32_t>(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<char *>(&cmd), sizeof(cmd));
}
template <typename GfxFamily>
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<GfxFamily>(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<uint32_t>(gmm->gmmResourceInfo->getBaseWidth());
cmd.surfaceHeight = static_cast<uint32_t>(gmm->gmmResourceInfo->getBaseHeight());
cmd.surfacePitch = static_cast<uint32_t>(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<char *>(&cmd), sizeof(cmd));
}
template <typename GfxFamily>
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<GfxFamily>(gfxAllocation, stream, context);
} else if (0 == dumpBufferFormat.compare("TRE")) {
dumpBufferInTreFormat<GfxFamily>(gfxAllocation, stream, context);
}
} else if (isDumpableImage) {
if (0 == dumpImageFormat.compare("BMP")) {
dumpImageInBmpFormat<GfxFamily>(gfxAllocation, stream, context);
} else if (0 == dumpImageFormat.compare("TRE")) {
dumpImageInTreFormat<GfxFamily>(gfxAllocation, stream, context);
}
}
}
} // namespace AubAllocDump

View File

@ -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 <typename Family>
void CommandQueueHw<Family>::notifyEnqueueReadBuffer(Buffer *buffer, bool blockingRead) {
if (DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.get()) {
buffer->getGraphicsAllocation()->setAllocDumpable(blockingRead);
buffer->forceDisallowCPUCopy = blockingRead;
}
}
template <typename Family>
void CommandQueueHw<Family>::notifyEnqueueReadImage(Image *image, bool blockingRead) {
if (DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.get()) {
image->getGraphicsAllocation()->setAllocDumpable(blockingRead);
}
}
} // namespace OCLRT

View File

@ -64,6 +64,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
uint32_t getDumpHandle();
MOCKABLE_VIRTUAL void addContextToken(uint32_t dumpHandle);
void dumpAllocation(GraphicsAllocation &gfxAllocation);
static CommandStreamReceiver *create(const HardwareInfo &hwInfoIn, const std::string &fileName, bool standalone, ExecutionEnvironment &executionEnvironment);

View File

@ -7,6 +7,8 @@
#include "hw_cmds.h"
#include "runtime/aub/aub_helper.h"
#include "runtime/aub_mem_dump/aub_alloc_dump.h"
#include "runtime/aub_mem_dump/aub_alloc_dump.inl"
#include "runtime/aub_mem_dump/page_table_entry_bits.h"
#include "runtime/command_stream/aub_stream_provider.h"
#include "runtime/command_stream/aub_subcapture.h"
@ -21,6 +23,7 @@
#include "runtime/helpers/string.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/os_agnostic_memory_manager.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "runtime/os_interface/os_context.h"
@ -407,7 +410,7 @@ template <typename GfxFamily>
void AUBCommandStreamReceiverHw<GfxFamily>::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 <typename GfxFamily>
void AUBCommandStreamReceiverHw<GfxFamily>::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<GfxFamily>::processResidency(ResidencyContainer
dumpAubNonWritable = false;
}
template <typename GfxFamily>
void AUBCommandStreamReceiverHw<GfxFamily>::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<GfxFamily>(gfxAllocation, getAubStream(), getDumpHandle());
}
template <typename GfxFamily>
void AUBCommandStreamReceiverHw<GfxFamily>::makeNonResident(GraphicsAllocation &gfxAllocation) {
if (gfxAllocation.isResident(this->osContext->getContextId())) {
dumpAllocation(gfxAllocation);
this->getEvictionAllocations().push_back(&gfxAllocation);
gfxAllocation.releaseResidencyInOsContext(this->osContext->getContextId());
}

View File

@ -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 <typename GfxFamily>
void TbxCommandStreamReceiverHw<GfxFamily>::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 <typename GfxFamily>
void TbxCommandStreamReceiverHw<GfxFamily>::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;
}

View File

@ -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<Family>::perEngineMMIO[EngineType::NUM_ENGINES]
&mmioListVCS,
&mmioListVECS};
} // namespace OCLRT
namespace AubAllocDump {
using namespace OCLRT;
template uint32_t getImageSurfaceTypeFromGmmResourceType<Family>(GMM_RESOURCE_TYPE gmmResourceType);
template void dumpBufferInBinFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpImageInBmpFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpBufferInTreFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpImageInTreFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpAllocation<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
} // namespace AubAllocDump

View File

@ -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<Family>::perEngineMMIO[EngineType::NUM_ENGINES]
&mmioListVCS,
&mmioListVECS};
} // namespace OCLRT
namespace AubAllocDump {
using namespace OCLRT;
template uint32_t getImageSurfaceTypeFromGmmResourceType<Family>(GMM_RESOURCE_TYPE gmmResourceType);
template void dumpBufferInBinFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpImageInBmpFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpBufferInTreFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpImageInTreFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpAllocation<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
} // namespace AubAllocDump

View File

@ -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<Family>::perEngineMMIO[EngineType::NUM_ENGINES]
&mmioListVECS};
} // namespace OCLRT
namespace AubAllocDump {
using namespace OCLRT;
template uint32_t getImageSurfaceTypeFromGmmResourceType<Family>(GMM_RESOURCE_TYPE gmmResourceType);
template void dumpBufferInBinFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpImageInBmpFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpBufferInTreFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpImageInTreFormat<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
template void dumpAllocation<Family>(GraphicsAllocation &gfxAllocation, AubMemDump::AubFileStream *stream, uint32_t context);
} // namespace AubAllocDump

View File

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

View File

@ -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;
};

View File

@ -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})

View File

@ -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<DeviceFixture> 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<char> 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<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_1D));
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_2D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_2D));
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_3D, AubAllocDump::getImageSurfaceTypeFromGmmResourceType<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_3D));
EXPECT_EQ(RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_NULL, AubAllocDump::getImageSurfaceTypeFromGmmResourceType<FamilyType>(GMM_RESOURCE_TYPE::RESOURCE_INVALID));
}
HWTEST_F(AubAllocDumpTests, givenGraphicsAllocationWhenDumpAllocationIsCalledInDefaultModeThenGraphicsAllocationShouldNotBeDumped) {
auto memoryManager = pDevice->getMemoryManager();
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
AubAllocDump::dumpAllocation<FamilyType>(*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<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
AubAllocDump::dumpAllocation<FamilyType>(*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<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
AubAllocDump::dumpAllocation<FamilyType>(*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<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
AubAllocDump::dumpAllocation<FamilyType>(*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(Buffer::create(&context, CL_MEM_READ_WRITE, bufferSize, nullptr, retVal));
ASSERT_NE(nullptr, buffer);
auto gfxAllocation = buffer->getGraphicsAllocation();
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto handle = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this));
AubAllocDump::dumpAllocation<FamilyType>(*gfxAllocation, mockAubFileStream.get(), handle);
EXPECT_EQ(0u, mockAubFileStream->getSize());
}
HWTEST_F(AubAllocDumpTests, givenWritableImageWhenDumpAllocationIsCalledAndAubDumpImageFormatIsNotSetThenImageShouldNotBeDumped) {
MockContext context;
std::unique_ptr<Image> image(ImageHelper<Image1dDefaults>::create(&context));
ASSERT_NE(nullptr, image);
auto gfxAllocation = image->getGraphicsAllocation();
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto handle = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this));
AubAllocDump::dumpAllocation<FamilyType>(*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(Buffer::create(&context, CL_MEM_READ_WRITE, bufferSize, nullptr, retVal));
ASSERT_NE(nullptr, buffer);
auto gfxAllocation = buffer->getGraphicsAllocation();
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto handle = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this));
AubAllocDump::dumpAllocation<FamilyType>(*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<uint32_t>(gfxAllocation->getUnderlyingBufferSize()), cmd.getWidth());
EXPECT_EQ(1u, cmd.getHeight());
EXPECT_EQ(static_cast<uint32_t>(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(Buffer::create(&context, CL_MEM_READ_WRITE, bufferSize, nullptr, retVal));
ASSERT_NE(nullptr, buffer);
auto gfxAllocation = buffer->getGraphicsAllocation();
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto handle = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this));
AubAllocDump::dumpAllocation<FamilyType>(*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<uint32_t>(gfxAllocation->getUnderlyingBufferSize()), cmd.surfaceWidth);
EXPECT_EQ(1u, cmd.surfaceHeight);
EXPECT_EQ(static_cast<uint32_t>(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> image(ImageHelper<Image1dDefaults>::create(&context));
ASSERT_NE(nullptr, image);
auto gfxAllocation = image->getGraphicsAllocation();
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto handle = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this));
AubAllocDump::dumpAllocation<FamilyType>(*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<uint32_t>(gmm->gmmResourceInfo->getResourceFormatSurfaceState()), cmd.Format);
EXPECT_EQ(static_cast<uint32_t>(gmm->gmmResourceInfo->getBaseWidth()), cmd.Xsize);
EXPECT_EQ(static_cast<uint32_t>(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<uint32_t>(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> image(ImageHelper<Image2dDefaults>::create(&context));
ASSERT_NE(nullptr, image);
auto gfxAllocation = image->getGraphicsAllocation();
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto handle = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this));
AubAllocDump::dumpAllocation<FamilyType>(*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<uint32_t>(gfxAllocation->gmm->gmmResourceInfo->getBaseWidth()), cmd.surfaceWidth);
EXPECT_EQ(static_cast<uint32_t>(gfxAllocation->gmm->gmmResourceInfo->getBaseHeight()), cmd.surfaceHeight);
EXPECT_EQ(static_cast<uint32_t>(gfxAllocation->gmm->gmmResourceInfo->getRenderPitch()), cmd.surfacePitch);
EXPECT_EQ(static_cast<uint32_t>(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> image(ImageHelper<Image2dDefaults>::create(&context));
ASSERT_NE(nullptr, image);
auto gfxAllocation = image->getGraphicsAllocation();
gfxAllocation->gmm->isRenderCompressed = true;
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto handle = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this));
AubAllocDump::dumpAllocation<FamilyType>(*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> image(ImageHelper<Image2dDefaults>::create(&context));
ASSERT_NE(nullptr, image);
auto gfxAllocation = image->getGraphicsAllocation();
auto mockGmmResourceInfo = reinterpret_cast<MockGmmResourceInfo *>(gfxAllocation->gmm->gmmResourceInfo.get());
mockGmmResourceInfo->mockResourceCreateParams.MSAA.NumSamples = 2;
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
auto handle = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(this));
AubAllocDump::dumpAllocation<FamilyType>(*gfxAllocation, mockAubFileStream.get(), handle);
EXPECT_EQ(0u, mockAubFileStream->getSize());
}

View File

@ -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<NegativeFailAllocationCommandEnqueueBaseFixture>;
HWTEST_F(NegativeFailAllocationTest, givenEnqueueReadBufferWhenHostPtrAllocationCreationFailsThenReturnOutOfResource) {

View File

@ -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<Image> 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<Image> 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) {

View File

@ -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<PhysicalAddressAllocator> allocator(aubCsr.createPhysicalAddressAllocator(&hwInfoHelper));
ASSERT_NE(nullptr, allocator);
}
HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledAndDumpFormatIsSpecifiedThenGraphicsAllocationShouldBeDumped) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
MockAubCsr<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
auto mockManager = std::make_unique<MockAubManager>();
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
aubCsr.hardwareContext = std::unique_ptr<MockHardwareContext>(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<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
auto mockManager = std::make_unique<MockAubManager>();
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
aubCsr.hardwareContext = std::unique_ptr<MockHardwareContext>(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<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
auto mockManager = std::make_unique<MockAubManager>();
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
aubCsr.hardwareContext = std::unique_ptr<MockHardwareContext>(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<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
auto mockManager = std::make_unique<MockAubManager>();
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
aubCsr.hardwareContext = std::unique_ptr<MockHardwareContext>(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<FamilyType> aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment);
auto mockManager = std::make_unique<MockAubManager>();
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
aubCsr.hardwareContext = std::unique_ptr<MockHardwareContext>(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);
}

View File

@ -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;

View File

@ -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