2018-10-02 10:37:17 +02:00
|
|
|
/*
|
2021-05-16 20:51:16 +02:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2018-10-02 10:37:17 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/command_stream/preemption.h"
|
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2021-01-21 13:10:13 +01:00
|
|
|
#include "shared/test/common/helpers/default_hw_info.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2020-02-22 22:50:57 +01:00
|
|
|
#include "opencl/source/command_stream/aub_command_stream_receiver_hw.h"
|
|
|
|
#include "opencl/source/platform/platform.h"
|
2020-02-23 15:20:22 +01:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_allocation_properties.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2018-10-02 10:37:17 +02:00
|
|
|
#include "gmock/gmock.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2018-10-02 10:37:17 +02:00
|
|
|
#include <string>
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2018-10-02 10:37:17 +02:00
|
|
|
|
2018-10-23 01:17:11 -07:00
|
|
|
struct MockAubFileStreamMockMmioWrite : public AubMemDump::AubFileStream {
|
2018-11-01 22:28:20 -07:00
|
|
|
void writeMMIOImpl(uint32_t offset, uint32_t value) override {
|
2018-10-23 01:17:11 -07: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-30 11:08:09 -07: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 10:37:17 +02:00
|
|
|
template <typename GfxFamily>
|
|
|
|
struct MockAubCsr : public AUBCommandStreamReceiverHw<GfxFamily> {
|
2018-12-06 16:06:51 +01:00
|
|
|
using CommandStreamReceiverHw<GfxFamily>::defaultSshSize;
|
2019-01-29 10:39:34 +01:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::taskCount;
|
2019-03-15 10:27:23 +01:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::latestSentTaskCount;
|
2019-01-29 10:39:34 +01:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::pollForCompletionTaskCount;
|
2021-05-14 16:34:47 +00:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::getParametersForWriteMemory;
|
2019-02-06 13:32:49 +01:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::writeMemory;
|
2019-10-29 08:01:53 +01:00
|
|
|
using AUBCommandStreamReceiverHw<GfxFamily>::AUBCommandStreamReceiverHw;
|
2018-12-06 16:06:51 +01:00
|
|
|
|
2018-10-02 10:37:17 +02:00
|
|
|
DispatchMode peekDispatchMode() const {
|
|
|
|
return this->dispatchMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsAllocation *getTagAllocation() const {
|
|
|
|
return this->tagAllocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLatestSentTaskCount(uint32_t latestSentTaskCount) {
|
|
|
|
this->latestSentTaskCount = latestSentTaskCount;
|
|
|
|
}
|
|
|
|
|
2019-11-24 14:50:41 +01:00
|
|
|
bool flushBatchedSubmissions() override {
|
2018-10-02 10:37:17 +02:00
|
|
|
flushBatchedSubmissionsCalled = true;
|
2019-11-24 14:50:41 +01:00
|
|
|
return true;
|
2018-10-02 10:37:17 +02:00
|
|
|
}
|
|
|
|
void initProgrammingFlags() override {
|
|
|
|
initProgrammingFlagsCalled = true;
|
|
|
|
}
|
2020-03-13 09:17:01 +01:00
|
|
|
void initializeEngine() override {
|
2019-01-29 11:48:54 +01:00
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::initializeEngine();
|
2018-11-26 23:31:00 -08:00
|
|
|
initializeEngineCalled = true;
|
|
|
|
}
|
2019-02-15 11:31:47 +01: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-26 18:17:57 -08:00
|
|
|
writeMemoryCalled = true;
|
|
|
|
}
|
2021-02-22 12:02:08 +00:00
|
|
|
void writeMMIO(uint32_t offset, uint32_t value) override {
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::writeMMIO(offset, value);
|
|
|
|
writeMMIOCalled = true;
|
|
|
|
}
|
2019-01-29 11:48:54 +01: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-25 14:58:12 -08:00
|
|
|
submitBatchBufferCalled = true;
|
|
|
|
}
|
2019-02-06 13:32:49 +01:00
|
|
|
|
|
|
|
void writeMemoryWithAubManager(GraphicsAllocation &graphicsAllocation) override {
|
|
|
|
CommandStreamReceiverSimulatedHw<GfxFamily>::writeMemoryWithAubManager(graphicsAllocation);
|
|
|
|
writeMemoryWithAubManagerCalled = true;
|
|
|
|
}
|
|
|
|
|
2019-01-28 14:20:58 +01:00
|
|
|
void pollForCompletion() override {
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::pollForCompletion();
|
2018-08-24 00:16:32 +02:00
|
|
|
pollForCompletionCalled = true;
|
|
|
|
}
|
2020-04-01 21:01:39 +02:00
|
|
|
bool expectMemoryEqual(void *gfxAddress, const void *srcAddress, size_t length) override {
|
2018-12-04 12:03:36 -08:00
|
|
|
expectMemoryEqualCalled = true;
|
2020-04-01 21:01:39 +02:00
|
|
|
return AUBCommandStreamReceiverHw<GfxFamily>::expectMemoryEqual(gfxAddress, srcAddress, length);
|
2018-12-04 12:03:36 -08:00
|
|
|
}
|
2020-04-01 21:01:39 +02:00
|
|
|
bool expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length) override {
|
2018-12-04 12:03:36 -08:00
|
|
|
expectMemoryNotEqualCalled = true;
|
2020-04-01 21:01:39 +02:00
|
|
|
return AUBCommandStreamReceiverHw<GfxFamily>::expectMemoryNotEqual(gfxAddress, srcAddress, length);
|
2018-12-04 12:03:36 -08:00
|
|
|
}
|
2021-02-22 12:02:08 +00:00
|
|
|
bool expectMemoryCompressed(void *gfxAddress, const void *srcAddress, size_t length) override {
|
|
|
|
expectMemoryCompressedCalled = true;
|
|
|
|
return AUBCommandStreamReceiverHw<GfxFamily>::expectMemoryCompressed(gfxAddress, srcAddress, length);
|
|
|
|
}
|
2020-03-13 09:17:01 +01:00
|
|
|
bool waitForCompletionWithTimeout(bool enableTimeout, int64_t timeoutMicroseconds, uint32_t taskCountToWait) override {
|
2019-01-29 10:39:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
2020-03-13 09:17:01 +01:00
|
|
|
void addAubComment(const char *message) override {
|
2019-04-01 09:33:19 +02:00
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::addAubComment(message);
|
|
|
|
addAubCommentCalled = true;
|
|
|
|
}
|
2019-04-18 10:43:08 +02:00
|
|
|
void dumpAllocation(GraphicsAllocation &gfxAllocation) override {
|
|
|
|
AUBCommandStreamReceiverHw<GfxFamily>::dumpAllocation(gfxAllocation);
|
|
|
|
dumpAllocationCalled = true;
|
|
|
|
}
|
2019-09-16 14:59:54 +02:00
|
|
|
bool isMultiOsContextCapable() const override {
|
|
|
|
return multiOsContextCapable;
|
|
|
|
}
|
|
|
|
bool multiOsContextCapable = false;
|
2018-10-02 10:37:17 +02:00
|
|
|
bool flushBatchedSubmissionsCalled = false;
|
|
|
|
bool initProgrammingFlagsCalled = false;
|
2018-11-26 23:31:00 -08:00
|
|
|
bool initializeEngineCalled = false;
|
2018-11-26 18:17:57 -08:00
|
|
|
bool writeMemoryCalled = false;
|
2019-02-06 13:32:49 +01:00
|
|
|
bool writeMemoryWithAubManagerCalled = false;
|
2021-02-22 12:02:08 +00:00
|
|
|
bool writeMMIOCalled = false;
|
2018-11-25 14:58:12 -08:00
|
|
|
bool submitBatchBufferCalled = false;
|
2018-08-24 00:16:32 +02:00
|
|
|
bool pollForCompletionCalled = false;
|
2018-12-04 12:03:36 -08:00
|
|
|
bool expectMemoryEqualCalled = false;
|
|
|
|
bool expectMemoryNotEqualCalled = false;
|
2021-02-22 12:02:08 +00:00
|
|
|
bool expectMemoryCompressedCalled = false;
|
2019-04-01 09:33:19 +02:00
|
|
|
bool addAubCommentCalled = false;
|
2019-04-18 10:43:08 +02:00
|
|
|
bool dumpAllocationCalled = false;
|
2018-10-02 10:37:17 +02: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-19 22:50:52 +01:00
|
|
|
const std::string getFileName() override {
|
2018-10-02 10:37:17 +02:00
|
|
|
return openFileName;
|
|
|
|
}
|
|
|
|
bool fileIsOpen = false;
|
|
|
|
std::string openFileName = "";
|
|
|
|
|
2020-05-18 12:05:00 +02:00
|
|
|
MOCK_METHOD(bool, addPatchInfoComments, (), (override));
|
2018-10-02 10:37:17 +02:00
|
|
|
|
|
|
|
using CommandStreamReceiverHw<GfxFamily>::localMemoryEnabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AubExecutionEnvironment {
|
|
|
|
std::unique_ptr<ExecutionEnvironment> executionEnvironment;
|
|
|
|
GraphicsAllocation *commandBuffer = nullptr;
|
2019-11-05 13:38:20 +01:00
|
|
|
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver;
|
2018-10-02 10:37:17 +02:00
|
|
|
template <typename CsrType>
|
|
|
|
CsrType *getCsr() {
|
2019-11-05 13:38:20 +01:00
|
|
|
return static_cast<CsrType *>(commandStreamReceiver.get());
|
2018-10-02 10:37:17 +02: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);
|
2020-10-28 16:08:37 +01:00
|
|
|
DeviceBitfield deviceBitfield(1);
|
2019-11-15 09:59:48 +01:00
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(1);
|
2020-03-25 15:15:03 +01:00
|
|
|
uint32_t rootDeviceIndex = 0u;
|
|
|
|
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(defaultHwInfo.get());
|
|
|
|
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->aubCenter.reset(new AubCenter());
|
2018-12-10 17:12:32 +01:00
|
|
|
|
2019-03-15 10:22:35 +01:00
|
|
|
executionEnvironment->initializeMemoryManager();
|
2020-10-28 16:08:37 +01:00
|
|
|
auto commandStreamReceiver = std::make_unique<CsrType>("", standalone, *executionEnvironment, rootDeviceIndex, deviceBitfield);
|
2018-10-02 10:37:17 +02:00
|
|
|
|
2019-11-05 13:38:20 +01:00
|
|
|
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(),
|
2021-03-08 18:50:32 +00:00
|
|
|
EngineTypeUsage{getChosenEngineType(*defaultHwInfo), EngineUsage::Regular},
|
|
|
|
deviceBitfield,
|
2020-03-24 11:42:54 +01:00
|
|
|
PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo),
|
2021-03-08 18:50:32 +00:00
|
|
|
false);
|
2019-11-05 13:38:20 +01:00
|
|
|
commandStreamReceiver->setupContext(*osContext);
|
2018-11-26 14:04:52 +01:00
|
|
|
|
2020-07-08 12:09:05 +02:00
|
|
|
if (createTagAllocation) {
|
|
|
|
commandStreamReceiver->initializeTagAllocation();
|
|
|
|
}
|
|
|
|
commandStreamReceiver->createGlobalFenceAllocation();
|
|
|
|
|
2018-10-02 10:37:17 +02:00
|
|
|
std::unique_ptr<AubExecutionEnvironment> aubExecutionEnvironment(new AubExecutionEnvironment);
|
|
|
|
if (allocateCommandBuffer) {
|
2020-03-25 15:15:03 +01:00
|
|
|
aubExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, MemoryConstants::pageSize});
|
2018-10-02 10:37:17 +02:00
|
|
|
}
|
|
|
|
aubExecutionEnvironment->executionEnvironment = std::move(executionEnvironment);
|
2019-11-05 13:38:20 +01:00
|
|
|
aubExecutionEnvironment->commandStreamReceiver = std::move(commandStreamReceiver);
|
2018-10-02 10:37:17 +02:00
|
|
|
return aubExecutionEnvironment;
|
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|