Files
compute-runtime/unit_tests/mocks/mock_tbx_csr.h
Maciej Dziuban e0e19c2432 Change TBX 'coherence' terminology to 'download'
Related-To: NEO-3054
Change-Id: Ic2d7fe76dc85b007acfe19ee2c29f8dd8539ccbc
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
2019-04-29 15:23:54 +02:00

105 lines
4.5 KiB
C++

/*
* Copyright (C) 2018-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "runtime/aub/aub_center.h"
#include "runtime/command_stream/preemption.h"
#include "runtime/command_stream/tbx_command_stream_receiver_hw.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/helpers/hw_info.h"
#include "gmock/gmock.h"
#include <string>
namespace NEO {
template <typename GfxFamily>
class MockTbxCsr : public TbxCommandStreamReceiverHw<GfxFamily> {
public:
using TbxCommandStreamReceiverHw<GfxFamily>::writeMemory;
using TbxCommandStreamReceiverHw<GfxFamily>::allocationsForDownload;
MockTbxCsr(ExecutionEnvironment &executionEnvironment)
: TbxCommandStreamReceiverHw<GfxFamily>(executionEnvironment) {}
void initializeEngine() {
TbxCommandStreamReceiverHw<GfxFamily>::initializeEngine();
initializeEngineCalled = true;
}
void writeMemoryWithAubManager(GraphicsAllocation &graphicsAllocation) override {
CommandStreamReceiverSimulatedHw<GfxFamily>::writeMemoryWithAubManager(graphicsAllocation);
writeMemoryWithAubManagerCalled = true;
}
void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits) override {
TbxCommandStreamReceiverHw<GfxFamily>::writeMemory(gpuAddress, cpuAddress, size, memoryBank, entryBits);
writeMemoryCalled = true;
}
void submitBatchBuffer(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) override {
TbxCommandStreamReceiverHw<GfxFamily>::submitBatchBuffer(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, entryBits);
submitBatchBufferCalled = true;
}
void pollForCompletion() override {
TbxCommandStreamReceiverHw<GfxFamily>::pollForCompletion();
pollForCompletionCalled = true;
}
void downloadAllocation(GraphicsAllocation &gfxAllocation) override {
TbxCommandStreamReceiverHw<GfxFamily>::downloadAllocation(gfxAllocation);
makeCoherentCalled = true;
}
bool initializeEngineCalled = false;
bool writeMemoryWithAubManagerCalled = false;
bool writeMemoryCalled = false;
bool submitBatchBufferCalled = false;
bool pollForCompletionCalled = false;
bool expectMemoryEqualCalled = false;
bool expectMemoryNotEqualCalled = false;
bool makeCoherentCalled = false;
};
struct TbxExecutionEnvironment {
std::unique_ptr<ExecutionEnvironment> executionEnvironment;
GraphicsAllocation *commandBuffer = nullptr;
template <typename CsrType>
CsrType *getCsr() {
return static_cast<CsrType *>(executionEnvironment->commandStreamReceivers[0][0].get());
}
~TbxExecutionEnvironment() {
if (commandBuffer) {
executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer);
}
}
};
template <typename CsrType>
std::unique_ptr<TbxExecutionEnvironment> getEnvironment(bool createTagAllocation, bool allocateCommandBuffer) {
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
executionEnvironment->aubCenter.reset(new AubCenter());
executionEnvironment->commandStreamReceivers.resize(1);
executionEnvironment->commandStreamReceivers[0].push_back(std::make_unique<CsrType>(*platformDevices[0], *executionEnvironment));
executionEnvironment->initializeMemoryManager();
if (createTagAllocation) {
executionEnvironment->commandStreamReceivers[0][0]->initializeTagAllocation();
}
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(executionEnvironment->commandStreamReceivers[0][0].get(),
getChosenEngineType(*platformDevices[0]), 1,
PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false);
executionEnvironment->commandStreamReceivers[0][0]->setupContext(*osContext);
std::unique_ptr<TbxExecutionEnvironment> tbxExecutionEnvironment(new TbxExecutionEnvironment);
if (allocateCommandBuffer) {
tbxExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
}
tbxExecutionEnvironment->executionEnvironment = std::move(executionEnvironment);
return tbxExecutionEnvironment;
}
} // namespace NEO