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"
|
2019-02-27 17:06:14 +08:00
|
|
|
#include "runtime/platform/platform.h"
|
2019-08-07 00:01:26 +08:00
|
|
|
#include "unit_tests/mocks/mock_allocation_properties.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2018-10-02 16:37:17 +08:00
|
|
|
#include "gmock/gmock.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2018-10-02 16:37:17 +08:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
|
|
|
|
#endif
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-10-02 16:37:17 +08:00
|
|
|
|
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> {
|
2018-12-06 23:06:51 +08:00
|
|
|
using CommandStreamReceiverHw<GfxFamily>::defaultSshSize;
|
2019-01-29 17:39:34 +08:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::taskCount;
|
2019-03-15 17:27:23 +08:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::latestSentTaskCount;
|
2019-01-29 17:39:34 +08:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::pollForCompletionTaskCount;
|
2019-02-06 20:32:49 +08:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::writeMemory;
|
2019-10-29 15:01:53 +08:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::AUBCommandStreamReceiverHw;
|
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;
|
|
|
|
}
|
2019-04-01 15:33:19 +08:00
|
|
|
void addAubComment(const char *message) {
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::addAubComment(message);
|
|
|
|
addAubCommentCalled = true;
|
|
|
|
}
|
2019-04-18 16:43:08 +08:00
|
|
|
void dumpAllocation(GraphicsAllocation &gfxAllocation) override {
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::dumpAllocation(gfxAllocation);
|
|
|
|
dumpAllocationCalled = true;
|
|
|
|
}
|
2019-09-16 20:59:54 +08:00
|
|
|
bool isMultiOsContextCapable() const override {
|
|
|
|
return multiOsContextCapable;
|
|
|
|
}
|
|
|
|
bool multiOsContextCapable = false;
|
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;
|
2019-04-01 15:33:19 +08:00
|
|
|
bool addAubCommentCalled = false;
|
2019-04-18 16:43:08 +08:00
|
|
|
bool dumpAllocationCalled = 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;
|
|
|
|
}
|
2019-02-20 05:50:52 +08:00
|
|
|
const std::string getFileName() override {
|
2018-10-02 16:37:17 +08:00
|
|
|
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() {
|
2019-10-24 19:34:25 +08:00
|
|
|
return static_cast<CsrType *>(executionEnvironment->rootDeviceEnvironments[0].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);
|
2019-02-27 17:06:14 +08:00
|
|
|
executionEnvironment->setHwInfo(*platformDevices);
|
2019-10-24 19:34:25 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0].aubCenter.reset(new AubCenter());
|
2018-12-11 00:12:32 +08:00
|
|
|
|
2019-10-24 19:34:25 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1);
|
2019-10-29 15:01:53 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::make_unique<CsrType>("", standalone, *executionEnvironment, 0));
|
2019-03-15 17:22:35 +08:00
|
|
|
executionEnvironment->initializeMemoryManager();
|
2018-10-02 16:37:17 +08:00
|
|
|
if (createTagAllocation) {
|
2019-10-24 19:34:25 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->initializeTagAllocation();
|
2018-10-02 16:37:17 +08:00
|
|
|
}
|
|
|
|
|
2019-10-24 19:34:25 +08:00
|
|
|
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].get(),
|
2019-02-18 20:59:16 +08:00
|
|
|
getChosenEngineType(*platformDevices[0]), 1,
|
2019-03-18 20:57:59 +08:00
|
|
|
PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false);
|
2019-10-24 19:34:25 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0].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;
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|
2018-10-02 16:37:17 +08:00
|
|
|
|
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif
|