Command stream receiver: use memory manager from execution environment

Change-Id: I236218a73bd7dac6e5744e3596f146b77b5ca1c8
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2018-10-11 11:19:49 +02:00
committed by sys_ocldev
parent 97c56b9de0
commit 4f028d13a1
47 changed files with 158 additions and 256 deletions

View File

@@ -80,9 +80,12 @@ class BuiltinDispatchInfoBuilder {
protected:
template <typename KernelNameT, typename... KernelsDescArgsT>
void grabKernels(KernelNameT &&kernelName, Kernel *&kernelDst, KernelsDescArgsT &&... kernelsDesc) {
const KernelInfo *ki = prog->getKernelInfo(kernelName);
const KernelInfo *kernelInfo = prog->getKernelInfo(kernelName);
if (!kernelInfo) {
return;
}
cl_int err = 0;
kernelDst = Kernel::create(prog.get(), *ki, &err);
kernelDst = Kernel::create(prog.get(), *kernelInfo, &err);
kernelDst->isBuiltIn = true;
usedKernels.push_back(std::unique_ptr<Kernel>(kernelDst));
grabKernels(std::forward<KernelsDescArgsT>(kernelsDesc)...);

View File

@@ -69,9 +69,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
void freeEngineInfoTable();
MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) override {
this->memoryManager = new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, true, this->executionEnvironment);
this->flatBatchBufferHelper->setMemoryManager(this->memoryManager);
return this->memoryManager;
return new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, true, this->executionEnvironment);
}
static const AubMemDump::LrcaHelper &getCsTraits(EngineType engineType);

View File

@@ -43,7 +43,7 @@ CommandStreamReceiver::~CommandStreamReceiver() {
if (indirectHeap[i] != nullptr) {
auto allocation = indirectHeap[i]->getGraphicsAllocation();
if (allocation != nullptr) {
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
getMemoryManager()->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
}
delete indirectHeap[i];
}
@@ -119,7 +119,7 @@ void CommandStreamReceiver::makeResidentHostPtrAllocation(GraphicsAllocation *gf
void CommandStreamReceiver::waitForTaskCountAndCleanAllocationList(uint32_t requiredTaskCount, uint32_t allocationType) {
auto address = getTagAddress();
if (address && requiredTaskCount != (unsigned int)-1) {
if (address && requiredTaskCount != ObjectNotUsed) {
while (*address < requiredTaskCount)
;
}
@@ -131,21 +131,12 @@ void CommandStreamReceiver::waitForTaskCountAndCleanAllocationList(uint32_t requ
getMemoryManager()->freeAllocationsList(requiredTaskCount, allocationList);
}
MemoryManager *CommandStreamReceiver::getMemoryManager() {
return memoryManager;
}
void CommandStreamReceiver::setMemoryManager(MemoryManager *mm) {
memoryManager = mm;
if (flatBatchBufferHelper) {
flatBatchBufferHelper->setMemoryManager(mm);
}
MemoryManager *CommandStreamReceiver::getMemoryManager() const {
DEBUG_BREAK_IF(!executionEnvironment.memoryManager);
return executionEnvironment.memoryManager.get();
}
LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) {
auto memoryManager = this->getMemoryManager();
DEBUG_BREAK_IF(nullptr == memoryManager);
if (commandStream.getAvailableSpace() < minRequiredSize) {
// Make sure we have enough room for a MI_BATCH_BUFFER_END and any padding.
// Currently reserving 64bytes (cacheline) which should be more than enough.
@@ -156,16 +147,16 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) {
auto requiredSize = minRequiredSize + CSRequirements::csOverfetchSize;
auto allocation = memoryManager->obtainReusableAllocation(requiredSize, false).release();
auto allocation = getMemoryManager()->obtainReusableAllocation(requiredSize, false).release();
if (!allocation) {
allocation = memoryManager->allocateGraphicsMemory(requiredSize);
allocation = getMemoryManager()->allocateGraphicsMemory(requiredSize);
}
allocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM);
//pass current allocation to reusable list
if (commandStream.getCpuBase()) {
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(commandStream.getGraphicsAllocation()), REUSABLE_ALLOCATION);
getMemoryManager()->storeAllocation(std::unique_ptr<GraphicsAllocation>(commandStream.getGraphicsAllocation()), REUSABLE_ALLOCATION);
}
commandStream.replaceBuffer(allocation->getUnderlyingBuffer(), minRequiredSize - sizeForSubmission);
@@ -176,30 +167,30 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) {
}
void CommandStreamReceiver::cleanupResources() {
if (!memoryManager)
if (!getMemoryManager())
return;
waitForTaskCountAndCleanAllocationList(this->latestFlushedTaskCount, TEMPORARY_ALLOCATION);
waitForTaskCountAndCleanAllocationList(this->latestFlushedTaskCount, REUSABLE_ALLOCATION);
if (scratchAllocation) {
memoryManager->freeGraphicsMemory(scratchAllocation);
getMemoryManager()->freeGraphicsMemory(scratchAllocation);
scratchAllocation = nullptr;
}
if (debugSurface) {
memoryManager->freeGraphicsMemory(debugSurface);
getMemoryManager()->freeGraphicsMemory(debugSurface);
debugSurface = nullptr;
}
if (commandStream.getCpuBase()) {
memoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation());
getMemoryManager()->freeGraphicsMemory(commandStream.getGraphicsAllocation());
commandStream.replaceGraphicsAllocation(nullptr);
commandStream.replaceBuffer(nullptr, 0);
}
if (tagAllocation) {
memoryManager->freeGraphicsMemory(tagAllocation);
getMemoryManager()->freeGraphicsMemory(tagAllocation);
tagAllocation = nullptr;
tagAddress = nullptr;
}
@@ -267,7 +258,7 @@ void CommandStreamReceiver::activateAubSubCapture(const MultiDispatchInfo &dispa
GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) {
UNRECOVERABLE_IF(debugSurface != nullptr);
debugSurface = memoryManager->allocateGraphicsMemory(size);
debugSurface = getMemoryManager()->allocateGraphicsMemory(size);
return debugSurface;
}
@@ -281,7 +272,7 @@ IndirectHeap &CommandStreamReceiver::getIndirectHeap(IndirectHeap::Type heapType
heapMemory = heap->getGraphicsAllocation();
if (heap && heap->getAvailableSpace() < minRequiredSize && heapMemory) {
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
getMemoryManager()->storeAllocation(std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
heapMemory = nullptr;
}
@@ -309,13 +300,13 @@ void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType,
finalHeapSize = alignUp(std::max(finalHeapSize, minRequiredSize), MemoryConstants::pageSize);
auto heapMemory = memoryManager->obtainReusableAllocation(finalHeapSize, requireInternalHeap).release();
auto heapMemory = getMemoryManager()->obtainReusableAllocation(finalHeapSize, requireInternalHeap).release();
if (!heapMemory) {
if (requireInternalHeap) {
heapMemory = memoryManager->allocate32BitGraphicsMemory(finalHeapSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION);
heapMemory = getMemoryManager()->allocate32BitGraphicsMemory(finalHeapSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION);
} else {
heapMemory = memoryManager->allocateGraphicsMemory(finalHeapSize);
heapMemory = getMemoryManager()->allocateGraphicsMemory(finalHeapSize);
}
} else {
finalHeapSize = std::max(heapMemory->getUnderlyingBufferSize(), finalHeapSize);
@@ -344,7 +335,7 @@ void CommandStreamReceiver::releaseIndirectHeap(IndirectHeap::Type heapType) {
if (heap) {
auto heapMemory = heap->getGraphicsAllocation();
if (heapMemory != nullptr)
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
getMemoryManager()->storeAllocation(std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
heap->replaceBuffer(nullptr, 0);
heap->replaceGraphicsAllocation(nullptr);
}
@@ -355,7 +346,7 @@ void CommandStreamReceiver::setExperimentalCmdBuffer(std::unique_ptr<Experimenta
}
bool CommandStreamReceiver::initializeTagAllocation() {
auto tagAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t));
auto tagAllocation = getMemoryManager()->allocateGraphicsMemory(sizeof(uint32_t));
if (!tagAllocation) {
return false;
}

View File

@@ -72,9 +72,8 @@ class CommandStreamReceiver {
virtual void addPipeControl(LinearStream &commandStream, bool dcFlush) = 0;
MemoryManager *getMemoryManager();
MemoryManager *getMemoryManager() const;
virtual MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) { return nullptr; }
void setMemoryManager(MemoryManager *mm);
ResidencyContainer &getResidencyAllocations();
ResidencyContainer &getEvictionAllocations();
@@ -193,8 +192,6 @@ class CommandStreamReceiver {
GraphicsAllocation *scratchAllocation = nullptr;
GraphicsAllocation *preemptionCsrAllocation = nullptr;
GraphicsAllocation *debugSurface = nullptr;
MemoryManager *memoryManager = nullptr;
OSInterface *osInterface = nullptr;
std::unique_ptr<SubmissionAggregator> submissionAggregator;

View File

@@ -38,7 +38,7 @@ CommandStreamReceiverHw<GfxFamily>::CommandStreamReceiverHw(const HardwareInfo &
localMemoryEnabled(HwHelper::get(hwInfo.pPlatform->eRenderCoreFamily).isLocalMemoryEnabled(hwInfo)) {
requiredThreadArbitrationPolicy = PreambleHelper<GfxFamily>::getDefaultThreadArbitrationPolicy();
resetKmdNotifyHelper(new KmdNotifyHelper(&(hwInfoIn.capabilityTable.kmdNotifyProperties)));
flatBatchBufferHelper.reset(new FlatBatchBufferHelperHw<GfxFamily>(this->memoryManager));
flatBatchBufferHelper.reset(new FlatBatchBufferHelperHw<GfxFamily>(executionEnvironment));
defaultSshSize = getSshHeapSize();
}
@@ -303,7 +303,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
if (is64bit && scratchAllocation && !force32BitAllocations) {
newGSHbase = (uint64_t)scratchAllocation->getUnderlyingBuffer() - PreambleHelper<GfxFamily>::getScratchSpaceOffsetFor64bit();
} else if (is64bit && force32BitAllocations && dispatchFlags.GSBA32BitRequired) {
newGSHbase = memoryManager->allocator32Bit->getBase();
newGSHbase = getMemoryManager()->allocator32Bit->getBase();
GSBAFor32BitProgrammed = true;
}
@@ -316,7 +316,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
ssh,
newGSHbase,
requiredL3Index,
memoryManager->getInternalHeapBaseAddress(),
getMemoryManager()->getInternalHeapBaseAddress(),
device.getGmmHelper());
if (sshDirty) {

View File

@@ -13,6 +13,7 @@ namespace OCLRT {
template <typename BaseCSR>
class CommandStreamReceiverWithAUBDump : public BaseCSR {
public:
using BaseCSR::createMemoryManager;
CommandStreamReceiverWithAUBDump(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment);
~CommandStreamReceiverWithAUBDump() override;
@@ -24,8 +25,6 @@ class CommandStreamReceiverWithAUBDump : public BaseCSR {
void activateAubSubCapture(const MultiDispatchInfo &dispatchInfo) override;
MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) override;
CommandStreamReceiver *aubCSR = nullptr;
};

View File

@@ -50,13 +50,4 @@ void CommandStreamReceiverWithAUBDump<BaseCSR>::activateAubSubCapture(const Mult
}
}
template <typename BaseCSR>
MemoryManager *CommandStreamReceiverWithAUBDump<BaseCSR>::createMemoryManager(bool enable64kbPages, bool enableLocalMemory) {
auto memoryManager = BaseCSR::createMemoryManager(enable64kbPages, enableLocalMemory);
if (aubCSR) {
aubCSR->setMemoryManager(memoryManager);
}
return memoryManager;
}
} // namespace OCLRT

View File

@@ -37,14 +37,12 @@ ExperimentalCommandBuffer::~ExperimentalCommandBuffer() {
timestamp += 2;
}
MemoryManager *memoryManager = commandStreamReceiver->getMemoryManager();
if (memoryManager) {
memoryManager->freeGraphicsMemory(timestamps);
memoryManager->freeGraphicsMemory(experimentalAllocation);
memoryManager->freeGraphicsMemory(timestamps);
memoryManager->freeGraphicsMemory(experimentalAllocation);
if (currentStream.get()) {
memoryManager->freeGraphicsMemory(currentStream->getGraphicsAllocation());
currentStream->replaceGraphicsAllocation(nullptr);
}
if (currentStream.get()) {
memoryManager->freeGraphicsMemory(currentStream->getGraphicsAllocation());
currentStream->replaceGraphicsAllocation(nullptr);
}
}

View File

@@ -28,7 +28,6 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
typedef CommandStreamReceiverSimulatedHw<GfxFamily> BaseClass;
typedef typename OCLRT::AUBFamilyMapper<GfxFamily>::AUB AUB;
typedef typename AUB::MiContextDescriptorReg MiContextDescriptorReg;
using CommandStreamReceiverHw<GfxFamily>::memoryManager;
public:
FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer &allocationsForResidency, OsContext &osContext) override;
@@ -65,8 +64,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
} engineInfoTable[EngineType::NUM_ENGINES];
MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) override {
memoryManager = new TbxMemoryManager(enable64kbPages, enableLocalMemory, this->executionEnvironment);
return memoryManager;
return new TbxMemoryManager(enable64kbPages, enableLocalMemory, this->executionEnvironment);
}
TbxMemoryManager *getMemoryManager() {
return (TbxMemoryManager *)CommandStreamReceiver::getMemoryManager();

View File

@@ -54,12 +54,10 @@ bool ExecutionEnvironment::initializeCommandStreamReceiver(const HardwareInfo *p
}
void ExecutionEnvironment::initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory, uint32_t deviceIndex) {
if (this->memoryManager) {
commandStreamReceivers[deviceIndex]->setMemoryManager(this->memoryManager.get());
return;
}
memoryManager.reset(commandStreamReceivers[deviceIndex]->createMemoryManager(enable64KBpages, enableLocalMemory));
commandStreamReceivers[deviceIndex]->setMemoryManager(memoryManager.get());
DEBUG_BREAK_IF(!this->memoryManager);
}
void ExecutionEnvironment::initSourceLevelDebugger(const HardwareInfo &hwInfo) {

View File

@@ -5,6 +5,7 @@
*
*/
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/helpers/flat_batch_buffer_helper.h"
#include "runtime/memory_manager/graphics_allocation.h"
@@ -61,4 +62,8 @@ void FlatBatchBufferHelper::fixCrossThreadDataInfo(std::vector<PatchInfoData> &d
}
}
}
MemoryManager *FlatBatchBufferHelper::getMemoryManager() const {
return executionEnvironemnt.memoryManager.get();
}
}; // namespace OCLRT

View File

@@ -16,10 +16,11 @@ namespace OCLRT {
enum class DispatchMode;
class MemoryManager;
class ExecutionEnvironment;
class FlatBatchBufferHelper {
public:
FlatBatchBufferHelper(MemoryManager *memoryManager) : memoryManager(memoryManager) {}
FlatBatchBufferHelper(ExecutionEnvironment &executionEnvironemnt) : executionEnvironemnt(executionEnvironemnt) {}
virtual ~FlatBatchBufferHelper(){};
MOCKABLE_VIRTUAL bool setPatchInfoData(const PatchInfoData &data);
MOCKABLE_VIRTUAL bool removePatchInfoData(uint64_t targetLocation);
@@ -30,7 +31,6 @@ class FlatBatchBufferHelper {
virtual GraphicsAllocation *flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer, DispatchMode dispatchMode) = 0;
virtual char *getIndirectPatchCommands(size_t &indirectPatchCommandsSize, std::vector<PatchInfoData> &indirectPatchInfo) = 0;
virtual void removePipeControlData(size_t pipeControlLocationSize, void *pipeControlForNooping) = 0;
void setMemoryManager(MemoryManager *memoryManager) { this->memoryManager = memoryManager; }
static void fixCrossThreadDataInfo(std::vector<PatchInfoData> &data, size_t offsetCrossThreadData, uint64_t gpuAddress);
std::vector<CommandChunk> &getCommandChunkList() { return commandChunkList; }
@@ -38,7 +38,8 @@ class FlatBatchBufferHelper {
std::map<uint64_t, uint64_t> &getBatchBufferStartAddressSequence() { return batchBufferStartAddressSequence; }
protected:
MemoryManager *memoryManager = nullptr;
MemoryManager *getMemoryManager() const;
ExecutionEnvironment &executionEnvironemnt;
std::vector<PatchInfoData> patchInfoCollection;
std::vector<CommandChunk> commandChunkList;

View File

@@ -14,7 +14,7 @@ namespace OCLRT {
template <typename GfxFamily>
class FlatBatchBufferHelperHw : public FlatBatchBufferHelper {
public:
FlatBatchBufferHelperHw(MemoryManager *memoryManager) : FlatBatchBufferHelper(memoryManager) {}
using FlatBatchBufferHelper::FlatBatchBufferHelper;
GraphicsAllocation *flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer, DispatchMode dispatchMode) override;
char *getIndirectPatchCommands(size_t &indirectPatchCommandsSize, std::vector<PatchInfoData> &indirectPatchInfo) override;
void removePipeControlData(size_t pipeControlLocationSize, void *pipeControlForNooping) override;

View File

@@ -33,7 +33,7 @@ GraphicsAllocation *FlatBatchBufferHelperHw<GfxFamily>::flattenBatchBuffer(Batch
auto flatBatchBufferSize = alignUp(sizeMainBatchBuffer + indirectPatchCommandsSize + batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize(), MemoryConstants::pageSize);
flatBatchBuffer =
this->memoryManager->allocateGraphicsMemory(flatBatchBufferSize, MemoryConstants::pageSize, false, false);
getMemoryManager()->allocateGraphicsMemory(flatBatchBufferSize, MemoryConstants::pageSize, false, false);
UNRECOVERABLE_IF(flatBatchBuffer == nullptr);
// Copy main batchbuffer
memcpy_s(flatBatchBuffer->getUnderlyingBuffer(), sizeMainBatchBuffer,
@@ -108,8 +108,8 @@ GraphicsAllocation *FlatBatchBufferHelperHw<GfxFamily>::flattenBatchBuffer(Batch
flatBatchBufferSize = alignUp(flatBatchBufferSize, MemoryConstants::pageSize);
flatBatchBufferSize += CSRequirements::csOverfetchSize;
flatBatchBuffer = this->memoryManager->allocateGraphicsMemory(static_cast<size_t>(flatBatchBufferSize),
MemoryConstants::pageSize, false, false);
flatBatchBuffer = getMemoryManager()->allocateGraphicsMemory(static_cast<size_t>(flatBatchBufferSize),
MemoryConstants::pageSize, false, false);
UNRECOVERABLE_IF(flatBatchBuffer == nullptr);
char *ptr = reinterpret_cast<char *>(flatBatchBuffer->getUnderlyingBuffer());

View File

@@ -22,7 +22,6 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver<GfxFamily> {
protected:
typedef DeviceCommandStreamReceiver<GfxFamily> BaseClass;
using CommandStreamReceiverHw<GfxFamily>::CommandStreamReceiver::getTagAddress;
using CommandStreamReceiverHw<GfxFamily>::CommandStreamReceiver::memoryManager;
using BaseClass::getScratchPatchAddress;
using BaseClass::hwInfo;
using BaseClass::makeNonResident;

View File

@@ -152,8 +152,7 @@ DrmMemoryManager *DrmCommandStreamReceiver<GfxFamily>::getMemoryManager() {
template <typename GfxFamily>
MemoryManager *DrmCommandStreamReceiver<GfxFamily>::createMemoryManager(bool enable64kbPages, bool enableLocalMemory) {
memoryManager = new DrmMemoryManager(this->drm, this->gemCloseWorkerOperationMode, DebugManager.flags.EnableForcePin.get(), true, this->executionEnvironment);
return memoryManager;
return new DrmMemoryManager(this->drm, this->gemCloseWorkerOperationMode, DebugManager.flags.EnableForcePin.get(), true, this->executionEnvironment);
}
template <typename GfxFamily>

View File

@@ -19,7 +19,6 @@ class Wddm;
template <typename GfxFamily>
class WddmCommandStreamReceiver : public DeviceCommandStreamReceiver<GfxFamily> {
typedef DeviceCommandStreamReceiver<GfxFamily> BaseClass;
using CommandStreamReceiverHw<GfxFamily>::CommandStreamReceiver::memoryManager;
public:
WddmCommandStreamReceiver(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment);

View File

@@ -150,12 +150,12 @@ void WddmCommandStreamReceiver<GfxFamily>::processEviction(OsContext &osContext)
template <typename GfxFamily>
WddmMemoryManager *WddmCommandStreamReceiver<GfxFamily>::getMemoryManager() {
return (WddmMemoryManager *)CommandStreamReceiver::getMemoryManager();
return static_cast<WddmMemoryManager *>(CommandStreamReceiver::getMemoryManager());
}
template <typename GfxFamily>
MemoryManager *WddmCommandStreamReceiver<GfxFamily>::createMemoryManager(bool enable64kbPages, bool enableLocalMemory) {
return memoryManager = new WddmMemoryManager(enable64kbPages, enableLocalMemory, this->wddm, executionEnvironment);
return new WddmMemoryManager(enable64kbPages, enableLocalMemory, this->wddm, executionEnvironment);
}
template <typename GfxFamily>