2018-10-02 16:37:17 +08:00
|
|
|
/*
|
2019-01-10 16:37:56 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2018-10-02 16:37:17 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "runtime/command_stream/aub_command_stream_receiver_hw.h"
|
2018-12-10 17:30:39 +08:00
|
|
|
#include "runtime/command_stream/preemption.h"
|
2018-10-02 16:37:17 +08:00
|
|
|
#include "runtime/execution_environment/execution_environment.h"
|
|
|
|
#include "runtime/helpers/hw_info.h"
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
2018-10-23 16:17:11 +08:00
|
|
|
struct MockAubFileStreamMockMmioWrite : public AubMemDump::AubFileStream {
|
2018-11-02 13:28:20 +08:00
|
|
|
void writeMMIOImpl(uint32_t offset, uint32_t value) override {
|
2018-10-23 16:17:11 +08:00
|
|
|
mmioList.push_back(std::make_pair(offset, value));
|
|
|
|
}
|
|
|
|
bool isOnMmioList(const MMIOPair &mmio) {
|
|
|
|
bool mmioFound = false;
|
|
|
|
for (auto &mmioPair : mmioList) {
|
|
|
|
if (mmioPair.first == mmio.first && mmioPair.second == mmio.second) {
|
|
|
|
mmioFound = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mmioFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::pair<uint32_t, uint32_t>> mmioList;
|
|
|
|
};
|
|
|
|
|
2018-10-31 02:08:09 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
struct MockAubCsrToTestDumpContext : public AUBCommandStreamReceiverHw<GfxFamily> {
|
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::AUBCommandStreamReceiverHw;
|
|
|
|
|
|
|
|
void addContextToken(uint32_t dumpHandle) override {
|
|
|
|
handle = dumpHandle;
|
|
|
|
}
|
|
|
|
uint32_t handle = 0;
|
|
|
|
};
|
|
|
|
|
2018-10-02 16:37:17 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
struct MockAubCsr : public AUBCommandStreamReceiverHw<GfxFamily> {
|
|
|
|
MockAubCsr(const HardwareInfo &hwInfoIn, const std::string &fileName, bool standalone, ExecutionEnvironment &executionEnvironment)
|
|
|
|
: AUBCommandStreamReceiverHw<GfxFamily>(hwInfoIn, fileName, standalone, executionEnvironment){};
|
|
|
|
|
2018-12-06 23:06:51 +08:00
|
|
|
using CommandStreamReceiverHw<GfxFamily>::defaultSshSize;
|
2019-01-29 17:39:34 +08:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::taskCount;
|
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::pollForCompletionTaskCount;
|
2019-02-06 20:32:49 +08:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::writeMemory;
|
2018-12-06 23:06:51 +08:00
|
|
|
|
2018-10-02 16:37:17 +08:00
|
|
|
DispatchMode peekDispatchMode() const {
|
|
|
|
return this->dispatchMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsAllocation *getTagAllocation() const {
|
|
|
|
return this->tagAllocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLatestSentTaskCount(uint32_t latestSentTaskCount) {
|
|
|
|
this->latestSentTaskCount = latestSentTaskCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void flushBatchedSubmissions() override {
|
|
|
|
flushBatchedSubmissionsCalled = true;
|
|
|
|
}
|
|
|
|
void initProgrammingFlags() override {
|
|
|
|
initProgrammingFlagsCalled = true;
|
|
|
|
}
|
2019-01-29 18:48:54 +08:00
|
|
|
void initializeEngine() {
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::initializeEngine();
|
2018-11-27 15:31:00 +08:00
|
|
|
initializeEngineCalled = true;
|
|
|
|
}
|
2019-02-15 18:31:47 +08:00
|
|
|
void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits) override {
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(gpuAddress, cpuAddress, size, memoryBank, entryBits);
|
2018-11-27 10:17:57 +08:00
|
|
|
writeMemoryCalled = true;
|
|
|
|
}
|
2019-01-29 18:48:54 +08:00
|
|
|
void submitBatchBuffer(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) override {
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::submitBatchBuffer(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, entryBits);
|
2018-11-26 06:58:12 +08:00
|
|
|
submitBatchBufferCalled = true;
|
|
|
|
}
|
2019-02-06 20:32:49 +08:00
|
|
|
|
|
|
|
void writeMemoryWithAubManager(GraphicsAllocation &graphicsAllocation) override {
|
|
|
|
CommandStreamReceiverSimulatedHw<GfxFamily>::writeMemoryWithAubManager(graphicsAllocation);
|
|
|
|
writeMemoryWithAubManagerCalled = true;
|
|
|
|
}
|
|
|
|
|
2019-01-28 21:20:58 +08:00
|
|
|
void pollForCompletion() override {
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::pollForCompletion();
|
2018-08-24 06:16:32 +08:00
|
|
|
pollForCompletionCalled = true;
|
|
|
|
}
|
2018-12-05 04:03:36 +08:00
|
|
|
void expectMemoryEqual(void *gfxAddress, const void *srcAddress, size_t length) {
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::expectMemoryEqual(gfxAddress, srcAddress, length);
|
|
|
|
expectMemoryEqualCalled = true;
|
|
|
|
}
|
|
|
|
void expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length) {
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::expectMemoryNotEqual(gfxAddress, srcAddress, length);
|
|
|
|
expectMemoryNotEqualCalled = true;
|
|
|
|
}
|
2019-01-29 17:39:34 +08:00
|
|
|
bool waitForCompletionWithTimeout(bool enableTimeout, int64_t timeoutMicroseconds, uint32_t taskCountToWait) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-10-02 16:37:17 +08:00
|
|
|
bool flushBatchedSubmissionsCalled = false;
|
|
|
|
bool initProgrammingFlagsCalled = false;
|
2018-11-27 15:31:00 +08:00
|
|
|
bool initializeEngineCalled = false;
|
2018-11-27 10:17:57 +08:00
|
|
|
bool writeMemoryCalled = false;
|
2019-02-06 20:32:49 +08:00
|
|
|
bool writeMemoryWithAubManagerCalled = false;
|
2018-11-26 06:58:12 +08:00
|
|
|
bool submitBatchBufferCalled = false;
|
2018-08-24 06:16:32 +08:00
|
|
|
bool pollForCompletionCalled = false;
|
2018-12-05 04:03:36 +08:00
|
|
|
bool expectMemoryEqualCalled = false;
|
|
|
|
bool expectMemoryNotEqualCalled = false;
|
2018-10-02 16:37:17 +08:00
|
|
|
|
|
|
|
void initFile(const std::string &fileName) override {
|
|
|
|
fileIsOpen = true;
|
|
|
|
openFileName = fileName;
|
|
|
|
}
|
|
|
|
void closeFile() override {
|
|
|
|
fileIsOpen = false;
|
|
|
|
openFileName = "";
|
|
|
|
}
|
|
|
|
bool isFileOpen() const override {
|
|
|
|
return fileIsOpen;
|
|
|
|
}
|
|
|
|
const std::string &getFileName() override {
|
|
|
|
return openFileName;
|
|
|
|
}
|
|
|
|
bool fileIsOpen = false;
|
|
|
|
std::string openFileName = "";
|
|
|
|
|
|
|
|
MOCK_METHOD0(addPatchInfoComments, bool(void));
|
|
|
|
|
|
|
|
using CommandStreamReceiverHw<GfxFamily>::localMemoryEnabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AubExecutionEnvironment {
|
|
|
|
std::unique_ptr<ExecutionEnvironment> executionEnvironment;
|
|
|
|
GraphicsAllocation *commandBuffer = nullptr;
|
|
|
|
template <typename CsrType>
|
|
|
|
CsrType *getCsr() {
|
2018-11-20 20:58:15 +08:00
|
|
|
return static_cast<CsrType *>(executionEnvironment->commandStreamReceivers[0][0].get());
|
2018-10-02 16:37:17 +08:00
|
|
|
}
|
|
|
|
~AubExecutionEnvironment() {
|
|
|
|
if (commandBuffer) {
|
|
|
|
executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename CsrType>
|
|
|
|
std::unique_ptr<AubExecutionEnvironment> getEnvironment(bool createTagAllocation, bool allocateCommandBuffer, bool standalone) {
|
|
|
|
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
|
2018-12-11 00:12:32 +08:00
|
|
|
executionEnvironment->aubCenter.reset(new AubCenter());
|
|
|
|
|
2018-11-20 20:58:15 +08:00
|
|
|
executionEnvironment->commandStreamReceivers.resize(1);
|
2019-01-10 20:57:40 +08:00
|
|
|
executionEnvironment->commandStreamReceivers[0].push_back(std::make_unique<CsrType>(*platformDevices[0], "", standalone, *executionEnvironment));
|
2018-11-20 20:58:15 +08:00
|
|
|
executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0][0]->createMemoryManager(false, false));
|
2018-10-02 16:37:17 +08:00
|
|
|
if (createTagAllocation) {
|
2018-11-20 20:58:15 +08:00
|
|
|
executionEnvironment->commandStreamReceivers[0][0]->initializeTagAllocation();
|
2018-10-02 16:37:17 +08:00
|
|
|
}
|
|
|
|
|
2019-02-18 20:59:16 +08:00
|
|
|
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(executionEnvironment->commandStreamReceivers[0][0].get(),
|
|
|
|
getChosenEngineType(*platformDevices[0]), 1,
|
|
|
|
PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]));
|
2019-01-10 16:37:56 +08:00
|
|
|
executionEnvironment->commandStreamReceivers[0][0]->setupContext(*osContext);
|
2018-11-26 21:04:52 +08:00
|
|
|
|
2018-10-02 16:37:17 +08:00
|
|
|
std::unique_ptr<AubExecutionEnvironment> aubExecutionEnvironment(new AubExecutionEnvironment);
|
|
|
|
if (allocateCommandBuffer) {
|
2018-12-12 01:56:37 +08:00
|
|
|
aubExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
|
2018-10-02 16:37:17 +08:00
|
|
|
}
|
|
|
|
aubExecutionEnvironment->executionEnvironment = std::move(executionEnvironment);
|
|
|
|
return aubExecutionEnvironment;
|
|
|
|
}
|
|
|
|
} // namespace OCLRT
|
|
|
|
|
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif
|