Move blit_commands_helper files to core

Change-Id: I29fb4e6a91e9fc32f5017eb966d478f51b3b3487
Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2020-02-05 16:07:52 +01:00
committed by sys_ocldev
parent f77814a546
commit 3682e29ddc
57 changed files with 109 additions and 99 deletions

View File

@@ -12,6 +12,10 @@ set(NEO_CORE_HELPERS
${CMAKE_CURRENT_SOURCE_DIR}/array_count.h
${CMAKE_CURRENT_SOURCE_DIR}/aux_translation.h
${CMAKE_CURRENT_SOURCE_DIR}/basic_math.h
${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper_base.inl
${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper_bdw_plus.inl
${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/cache_policy.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cache_policy.h
${CMAKE_CURRENT_SOURCE_DIR}/common_types.h

View File

@@ -0,0 +1,125 @@
/*
* Copyright (C) 2019-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "core/helpers/blit_commands_helper.h"
#include "core/helpers/timestamp_packet.h"
#include "core/memory_manager/surface.h"
namespace NEO {
BlitProperties BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection blitDirection,
CommandStreamReceiver &commandStreamReceiver,
GraphicsAllocation *memObjAllocation,
GraphicsAllocation *preallocatedHostAllocation,
void *hostPtr, uint64_t memObjGpuVa,
uint64_t hostAllocGpuVa, size_t hostPtrOffset,
size_t copyOffset, uint64_t copySize) {
GraphicsAllocation *hostAllocation = nullptr;
if (preallocatedHostAllocation) {
hostAllocation = preallocatedHostAllocation;
UNRECOVERABLE_IF(hostAllocGpuVa == 0);
} else {
HostPtrSurface hostPtrSurface(hostPtr, static_cast<size_t>(copySize), true);
bool success = commandStreamReceiver.createAllocationForHostSurface(hostPtrSurface, false);
UNRECOVERABLE_IF(!success);
hostAllocation = hostPtrSurface.getAllocation();
hostAllocGpuVa = hostAllocation->getGpuAddress();
}
if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection) {
return {
nullptr, // outputTimestampPacket
blitDirection, // blitDirection
{}, // csrDependencies
AuxTranslationDirection::None, // auxTranslationDirection
memObjAllocation, // dstAllocation
hostAllocation, // srcAllocation
memObjGpuVa, // dstGpuAddress
hostAllocGpuVa, // srcGpuAddress
copySize, // copySize
copyOffset, // dstOffset
hostPtrOffset}; // srcOffset
} else {
return {
nullptr, // outputTimestampPacket
blitDirection, // blitDirection
{}, // csrDependencies
AuxTranslationDirection::None, // auxTranslationDirection
hostAllocation, // dstAllocation
memObjAllocation, // srcAllocation
hostAllocGpuVa, // dstGpuAddress
memObjGpuVa, // srcGpuAddress
copySize, // copySize
hostPtrOffset, // dstOffset
copyOffset}; // srcOffset
}
}
BlitProperties BlitProperties::constructPropertiesForCopyBuffer(GraphicsAllocation *dstAllocation, GraphicsAllocation *srcAllocation,
size_t dstOffset, size_t srcOffset, uint64_t copySize) {
return {
nullptr, // outputTimestampPacket
BlitterConstants::BlitDirection::BufferToBuffer, // blitDirection
{}, // csrDependencies
AuxTranslationDirection::None, // auxTranslationDirection
dstAllocation, // dstAllocation
srcAllocation, // srcAllocation
dstAllocation->getGpuAddress(), // dstGpuAddress
srcAllocation->getGpuAddress(), // srcGpuAddress
copySize, // copySize
dstOffset, // dstOffset
srcOffset}; // srcOffset
}
BlitProperties BlitProperties::constructPropertiesForAuxTranslation(AuxTranslationDirection auxTranslationDirection,
GraphicsAllocation *allocation) {
auto allocationSize = allocation->getUnderlyingBufferSize();
return {
nullptr, // outputTimestampPacket
BlitterConstants::BlitDirection::BufferToBuffer, // blitDirection
{}, // csrDependencies
auxTranslationDirection, // auxTranslationDirection
allocation, // dstAllocation
allocation, // srcAllocation
allocation->getGpuAddress(), // dstGpuAddress
allocation->getGpuAddress(), // srcGpuAddress
allocationSize, // copySize
0, // dstOffset
0 // srcOffset
};
}
void BlitProperties::setupDependenciesForAuxTranslation(BlitPropertiesContainer &blitPropertiesContainer, TimestampPacketDependencies &timestampPacketDependencies,
TimestampPacketContainer &kernelTimestamps, const CsrDependencies &depsFromEvents,
CommandStreamReceiver &gpguCsr, CommandStreamReceiver &bcsCsr) {
auto numObjects = blitPropertiesContainer.size() / 2;
for (size_t i = 0; i < numObjects; i++) {
blitPropertiesContainer[i].outputTimestampPacket = timestampPacketDependencies.auxToNonAuxNodes.peekNodes()[i];
blitPropertiesContainer[i + numObjects].outputTimestampPacket = timestampPacketDependencies.nonAuxToAuxNodes.peekNodes()[i];
}
gpguCsr.requestStallingPipeControlOnNextFlush();
auto nodesAllocator = gpguCsr.getTimestampPacketAllocator();
timestampPacketDependencies.barrierNodes.add(nodesAllocator->getTag());
// wait for barrier and events before AuxToNonAux
blitPropertiesContainer[0].csrDependencies.push_back(&timestampPacketDependencies.barrierNodes);
for (auto dep : depsFromEvents) {
blitPropertiesContainer[0].csrDependencies.push_back(dep);
}
// wait for NDR before NonAuxToAux
blitPropertiesContainer[numObjects].csrDependencies.push_back(&kernelTimestamps);
}
} // namespace NEO

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2019-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "core/command_stream/csr_deps.h"
#include "core/helpers/aux_translation.h"
#include "core/memory_manager/memory_constants.h"
#include "core/utilities/stackvec.h"
#include <cstdint>
namespace NEO {
class CommandStreamReceiver;
class GraphicsAllocation;
class LinearStream;
struct TimestampPacketStorage;
template <typename TagType>
struct TagNode;
struct BlitProperties;
struct TimestampPacketDependencies;
using BlitPropertiesContainer = StackVec<BlitProperties, 16>;
struct BlitProperties {
static BlitProperties constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection blitDirection,
CommandStreamReceiver &commandStreamReceiver,
GraphicsAllocation *memObjAllocation,
GraphicsAllocation *preallocatedHostAllocation,
void *hostPtr, uint64_t memObjGpuVa,
uint64_t hostAllocGpuVa, size_t hostPtrOffset,
size_t copyOffset, uint64_t copySize);
static BlitProperties constructPropertiesForCopyBuffer(GraphicsAllocation *dstAllocation, GraphicsAllocation *srcAllocation,
size_t dstOffset, size_t srcOffset, uint64_t copySize);
static BlitProperties constructPropertiesForAuxTranslation(AuxTranslationDirection auxTranslationDirection,
GraphicsAllocation *allocation);
static void setupDependenciesForAuxTranslation(BlitPropertiesContainer &blitPropertiesContainer, TimestampPacketDependencies &timestampPacketDependencies,
TimestampPacketContainer &kernelTimestamps, const CsrDependencies &depsFromEvents,
CommandStreamReceiver &gpguCsr, CommandStreamReceiver &bcsCsr);
static BlitterConstants::BlitDirection obtainBlitDirection(uint32_t commandType);
TagNode<TimestampPacketStorage> *outputTimestampPacket = nullptr;
BlitterConstants::BlitDirection blitDirection;
CsrDependencies csrDependencies;
AuxTranslationDirection auxTranslationDirection = AuxTranslationDirection::None;
GraphicsAllocation *dstAllocation = nullptr;
GraphicsAllocation *srcAllocation = nullptr;
uint64_t dstGpuAddress = 0;
uint64_t srcGpuAddress = 0;
uint64_t copySize = 0;
size_t dstOffset = 0;
size_t srcOffset = 0;
};
template <typename GfxFamily>
struct BlitCommandsHelper {
static size_t estimateBlitCommandsSize(uint64_t copySize, const CsrDependencies &csrDependencies, bool updateTimestampPacket);
static size_t estimateBlitCommandsSize(const BlitPropertiesContainer &blitPropertiesContainer);
static void dispatchBlitCommandsForBuffer(const BlitProperties &blitProperties, LinearStream &linearStream);
static void appendBlitCommandsForBuffer(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd);
};
} // namespace NEO

View File

@@ -0,0 +1,89 @@
/*
* Copyright (C) 2019-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "core/helpers/blit_commands_helper.h"
#include "core/helpers/timestamp_packet.h"
namespace NEO {
template <typename GfxFamily>
size_t BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(uint64_t copySize, const CsrDependencies &csrDependencies, bool updateTimestampPacket) {
size_t numberOfBlits = 0;
uint64_t sizeToBlit = copySize;
uint64_t width = 1;
uint64_t height = 1;
while (sizeToBlit != 0) {
if (sizeToBlit > BlitterConstants::maxBlitWidth) {
// 2D: maxBlitWidth x (1 .. maxBlitHeight)
width = BlitterConstants::maxBlitWidth;
height = std::min((sizeToBlit / width), BlitterConstants::maxBlitHeight);
} else {
// 1D: (1 .. maxBlitWidth) x 1
width = sizeToBlit;
height = 1;
}
sizeToBlit -= (width * height);
numberOfBlits++;
}
return TimestampPacketHelper::getRequiredCmdStreamSize<GfxFamily>(csrDependencies) +
(sizeof(typename GfxFamily::XY_COPY_BLT) * numberOfBlits) +
(sizeof(typename GfxFamily::MI_FLUSH_DW) * static_cast<size_t>(updateTimestampPacket));
}
template <typename GfxFamily>
size_t BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(const BlitPropertiesContainer &blitPropertiesContainer) {
size_t size = 0;
for (auto &blitProperties : blitPropertiesContainer) {
size += BlitCommandsHelper<GfxFamily>::estimateBlitCommandsSize(blitProperties.copySize, blitProperties.csrDependencies,
blitProperties.outputTimestampPacket != nullptr);
}
size += sizeof(typename GfxFamily::MI_FLUSH_DW) + sizeof(typename GfxFamily::MI_BATCH_BUFFER_END);
return alignUp(size, MemoryConstants::cacheLineSize);
}
template <typename GfxFamily>
void BlitCommandsHelper<GfxFamily>::dispatchBlitCommandsForBuffer(const BlitProperties &blitProperties, LinearStream &linearStream) {
uint64_t sizeToBlit = blitProperties.copySize;
uint64_t width = 1;
uint64_t height = 1;
uint64_t offset = 0;
while (sizeToBlit != 0) {
if (sizeToBlit > BlitterConstants::maxBlitWidth) {
// dispatch 2D blit: maxBlitWidth x (1 .. maxBlitHeight)
width = BlitterConstants::maxBlitWidth;
height = std::min((sizeToBlit / width), BlitterConstants::maxBlitHeight);
} else {
// dispatch 1D blt: (1 .. maxBlitWidth) x 1
width = sizeToBlit;
height = 1;
}
auto bltCmd = linearStream.getSpaceForCmd<typename GfxFamily::XY_COPY_BLT>();
*bltCmd = GfxFamily::cmdInitXyCopyBlt;
bltCmd->setTransferWidth(static_cast<uint32_t>(width));
bltCmd->setTransferHeight(static_cast<uint32_t>(height));
bltCmd->setDestinationPitch(static_cast<uint32_t>(width));
bltCmd->setSourcePitch(static_cast<uint32_t>(width));
bltCmd->setDestinationBaseAddress(blitProperties.dstGpuAddress + blitProperties.dstOffset + offset);
bltCmd->setSourceBaseAddress(blitProperties.srcGpuAddress + blitProperties.srcOffset + offset);
appendBlitCommandsForBuffer(blitProperties, *bltCmd);
auto blitSize = width * height;
sizeToBlit -= blitSize;
offset += blitSize;
}
}
} // namespace NEO

View File

@@ -0,0 +1,15 @@
/*
* Copyright (C) 2019-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "core/helpers/blit_commands_helper_base.inl"
namespace NEO {
template <typename GfxFamily>
void BlitCommandsHelper<GfxFamily>::appendBlitCommandsForBuffer(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd) {}
} // namespace NEO

View File

@@ -37,6 +37,7 @@ set(NEO_CORE_MEMORY_MANAGER
${CMAKE_CURRENT_SOURCE_DIR}/residency.cpp
${CMAKE_CURRENT_SOURCE_DIR}/residency.h
${CMAKE_CURRENT_SOURCE_DIR}/residency_container.h
${CMAKE_CURRENT_SOURCE_DIR}/surface.h
${CMAKE_CURRENT_SOURCE_DIR}/unified_memory_manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/unified_memory_manager.h
)

View File

@@ -0,0 +1,110 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "core/helpers/cache_policy.h"
#include "core/memory_manager/graphics_allocation.h"
#include "runtime/command_stream/command_stream_receiver.h"
namespace NEO {
class Surface {
public:
Surface(bool isCoherent = false) : IsCoherent(isCoherent) {}
virtual ~Surface() = default;
virtual void makeResident(CommandStreamReceiver &csr) = 0;
virtual Surface *duplicate() = 0;
virtual bool allowsL3Caching() { return true; }
bool IsCoherent;
};
class NullSurface : public Surface {
public:
NullSurface(){};
~NullSurface() override = default;
void makeResident(CommandStreamReceiver &csr) override{};
Surface *duplicate() override { return new NullSurface(); };
};
class HostPtrSurface : public Surface {
public:
HostPtrSurface(void *ptr, size_t size) : memoryPointer(ptr), surfaceSize(size) {
UNRECOVERABLE_IF(!ptr);
gfxAllocation = nullptr;
}
HostPtrSurface(void *ptr, size_t size, bool copyAllowed) : HostPtrSurface(ptr, size) {
isPtrCopyAllowed = copyAllowed;
}
HostPtrSurface(void *ptr, size_t size, GraphicsAllocation *allocation) : memoryPointer(ptr), surfaceSize(size), gfxAllocation(allocation) {
DEBUG_BREAK_IF(!ptr);
}
~HostPtrSurface() override = default;
void makeResident(CommandStreamReceiver &csr) override {
DEBUG_BREAK_IF(!gfxAllocation);
csr.makeResidentHostPtrAllocation(gfxAllocation);
}
Surface *duplicate() override {
return new HostPtrSurface(this->memoryPointer, this->surfaceSize, this->gfxAllocation);
};
void *getMemoryPointer() const {
return memoryPointer;
}
size_t getSurfaceSize() const {
return surfaceSize;
}
void setAllocation(GraphicsAllocation *allocation) {
this->gfxAllocation = allocation;
}
GraphicsAllocation *getAllocation() {
return gfxAllocation;
}
bool peekIsPtrCopyAllowed() {
return isPtrCopyAllowed;
}
bool allowsL3Caching() override {
return isL3Capable(*gfxAllocation);
}
protected:
void *memoryPointer;
size_t surfaceSize;
GraphicsAllocation *gfxAllocation;
bool isPtrCopyAllowed = false;
};
class GeneralSurface : public Surface {
public:
GeneralSurface() : Surface(false) {
gfxAllocation = nullptr;
}
GeneralSurface(GraphicsAllocation *gfxAlloc) : Surface(gfxAlloc->isCoherent()) {
gfxAllocation = gfxAlloc;
};
~GeneralSurface() override = default;
void makeResident(CommandStreamReceiver &csr) override {
csr.makeResident(*gfxAllocation);
};
Surface *duplicate() override { return new GeneralSurface(gfxAllocation); };
void setGraphicsAllocation(GraphicsAllocation *newAllocation) {
gfxAllocation = newAllocation;
IsCoherent = newAllocation->isCoherent();
}
protected:
GraphicsAllocation *gfxAllocation;
};
} // namespace NEO