AUB CSRs to use a shared physical address allocator

This commit introduces AUB-specific control class to execution environment.

Change-Id: I525c9c93a4f10f769dbedb7d097674c35693f0b1
This commit is contained in:
Milczarek, Slawomir
2018-09-26 15:28:11 +02:00
committed by sys_ocldev
parent 6aab39fd9b
commit efdbde245a
11 changed files with 252 additions and 131 deletions

View File

@ -6,6 +6,7 @@
set(RUNTIME_SRCS_COMMAND_STREAM set(RUNTIME_SRCS_COMMAND_STREAM
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/aub_center.h
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver.h ${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver.h
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_hw.h ${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_hw.h

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2018 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "runtime/command_stream/aub_stream_provider.h"
#include "runtime/memory_manager/physical_address_allocator.h"
namespace OCLRT {
class AubCenter {
public:
AubCenter() {
streamProvider = std::make_unique<AubFileStreamProvider>();
}
virtual ~AubCenter() = default;
void initPhysicalAddressAllocator(PhysicalAddressAllocator *pPhysicalAddressAllocator) {
physicalAddressAllocator = std::unique_ptr<PhysicalAddressAllocator>(pPhysicalAddressAllocator);
}
PhysicalAddressAllocator *getPhysicalAddressAllocator() const {
return physicalAddressAllocator.get();
}
AubStreamProvider *getStreamProvider() const {
return streamProvider.get();
}
protected:
std::unique_ptr<PhysicalAddressAllocator> physicalAddressAllocator;
std::unique_ptr<AubStreamProvider> streamProvider;
};
} // namespace OCLRT

View File

@ -8,9 +8,11 @@
#pragma once #pragma once
#include "runtime/gen_common/aub_mapper.h" #include "runtime/gen_common/aub_mapper.h"
#include "command_stream_receiver_simulated_hw.h" #include "command_stream_receiver_simulated_hw.h"
#include "runtime/command_stream/aub_center.h"
#include "runtime/command_stream/aub_command_stream_receiver.h" #include "runtime/command_stream/aub_command_stream_receiver.h"
#include "runtime/memory_manager/address_mapper.h" #include "runtime/memory_manager/address_mapper.h"
#include "runtime/memory_manager/page_table.h" #include "runtime/memory_manager/page_table.h"
#include "runtime/memory_manager/physical_address_allocator.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "runtime/memory_manager/os_agnostic_memory_manager.h"
namespace OCLRT { namespace OCLRT {
@ -90,7 +92,6 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
uint32_t aubDeviceId; uint32_t aubDeviceId;
bool standalone; bool standalone;
std::unique_ptr<PhysicalAddressAllocator> physicalAddressAllocator;
std::unique_ptr<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type> ppgtt; std::unique_ptr<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type> ppgtt;
std::unique_ptr<PDPE> ggtt; std::unique_ptr<PDPE> ggtt;
// remap CPU VA -> GGTT VA // remap CPU VA -> GGTT VA
@ -111,7 +112,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
protected: protected:
int getAddressSpace(int hint); int getAddressSpace(int hint);
void createPhysicalAddressAllocator(); PhysicalAddressAllocator *createPhysicalAddressAllocator();
bool dumpAubNonWritable = false; bool dumpAubNonWritable = false;
ExternalAllocationsContainer externalAllocations; ExternalAllocationsContainer externalAllocations;

View File

@ -21,6 +21,7 @@
#include "runtime/memory_manager/graphics_allocation.h" #include "runtime/memory_manager/graphics_allocation.h"
#include "runtime/memory_manager/memory_banks.h" #include "runtime/memory_manager/memory_banks.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "runtime/memory_manager/physical_address_allocator.h"
#include "runtime/os_interface/debug_settings_manager.h" #include "runtime/os_interface/debug_settings_manager.h"
#include <cstring> #include <cstring>
@ -32,17 +33,29 @@ AUBCommandStreamReceiverHw<GfxFamily>::AUBCommandStreamReceiverHw(const Hardware
subCaptureManager(std::make_unique<AubSubCaptureManager>(fileName)), subCaptureManager(std::make_unique<AubSubCaptureManager>(fileName)),
standalone(standalone) { standalone(standalone) {
createPhysicalAddressAllocator(); executionEnvironment.initAubCenter();
auto aubCenter = executionEnvironment.aubCenter.get();
UNRECOVERABLE_IF(nullptr == aubCenter);
ppgtt = std::make_unique<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type>(physicalAddressAllocator.get()); if (!aubCenter->getPhysicalAddressAllocator()) {
ggtt = std::make_unique<PDPE>(physicalAddressAllocator.get()); aubCenter->initPhysicalAddressAllocator(createPhysicalAddressAllocator());
}
auto physicalAddressAllocator = aubCenter->getPhysicalAddressAllocator();
UNRECOVERABLE_IF(nullptr == physicalAddressAllocator);
ppgtt = std::make_unique<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type>(physicalAddressAllocator);
ggtt = std::make_unique<PDPE>(physicalAddressAllocator);
auto streamProvider = aubCenter->getStreamProvider();
UNRECOVERABLE_IF(nullptr == streamProvider);
stream = streamProvider->getStream();
UNRECOVERABLE_IF(nullptr == stream);
this->dispatchMode = DispatchMode::BatchedDispatch; this->dispatchMode = DispatchMode::BatchedDispatch;
if (DebugManager.flags.CsrDispatchMode.get()) { if (DebugManager.flags.CsrDispatchMode.get()) {
this->dispatchMode = (DispatchMode)DebugManager.flags.CsrDispatchMode.get(); this->dispatchMode = (DispatchMode)DebugManager.flags.CsrDispatchMode.get();
} }
executionEnvironment.initAubStreamProvider();
stream = executionEnvironment.aubStreamProvider->getStream();
if (DebugManager.flags.AUBDumpSubCaptureMode.get()) { if (DebugManager.flags.AUBDumpSubCaptureMode.get()) {
this->subCaptureManager->subCaptureMode = static_cast<AubSubCaptureManager::SubCaptureMode>(DebugManager.flags.AUBDumpSubCaptureMode.get()); this->subCaptureManager->subCaptureMode = static_cast<AubSubCaptureManager::SubCaptureMode>(DebugManager.flags.AUBDumpSubCaptureMode.get());
this->subCaptureManager->subCaptureFilter.dumpKernelStartIdx = static_cast<uint32_t>(DebugManager.flags.AUBDumpFilterKernelStartIdx.get()); this->subCaptureManager->subCaptureFilter.dumpKernelStartIdx = static_cast<uint32_t>(DebugManager.flags.AUBDumpFilterKernelStartIdx.get());
@ -770,8 +783,8 @@ uint32_t AUBCommandStreamReceiverHw<GfxFamily>::getMemoryBankForGtt() const {
} }
template <typename GfxFamily> template <typename GfxFamily>
void AUBCommandStreamReceiverHw<GfxFamily>::createPhysicalAddressAllocator() { PhysicalAddressAllocator *AUBCommandStreamReceiverHw<GfxFamily>::createPhysicalAddressAllocator() {
physicalAddressAllocator = std::make_unique<PhysicalAddressAllocator>(); return new PhysicalAddressAllocator();
} }
} // namespace OCLRT } // namespace OCLRT

View File

@ -6,7 +6,7 @@
*/ */
#include "runtime/execution_environment/execution_environment.h" #include "runtime/execution_environment/execution_environment.h"
#include "runtime/command_stream/aub_stream_provider.h" #include "runtime/command_stream/aub_center.h"
#include "runtime/command_stream/command_stream_receiver.h" #include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/compiler_interface/compiler_interface.h" #include "runtime/compiler_interface/compiler_interface.h"
#include "runtime/source_level_debugger/source_level_debugger.h" #include "runtime/source_level_debugger/source_level_debugger.h"
@ -22,9 +22,9 @@ ExecutionEnvironment::ExecutionEnvironment() = default;
ExecutionEnvironment::~ExecutionEnvironment() = default; ExecutionEnvironment::~ExecutionEnvironment() = default;
extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo, ExecutionEnvironment &executionEnvironment); extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo, ExecutionEnvironment &executionEnvironment);
void ExecutionEnvironment::initAubStreamProvider() { void ExecutionEnvironment::initAubCenter() {
if (!aubStreamProvider) { if (!aubCenter) {
aubStreamProvider.reset(new AubFileStreamProvider()); aubCenter.reset(new AubCenter());
} }
} }
void ExecutionEnvironment::initGmm(const HardwareInfo *hwInfo) { void ExecutionEnvironment::initGmm(const HardwareInfo *hwInfo) {

View File

@ -13,7 +13,7 @@
#include <vector> #include <vector>
namespace OCLRT { namespace OCLRT {
class AubStreamProvider; class AubCenter;
class GmmHelper; class GmmHelper;
class CommandStreamReceiver; class CommandStreamReceiver;
class MemoryManager; class MemoryManager;
@ -35,7 +35,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
ExecutionEnvironment(); ExecutionEnvironment();
~ExecutionEnvironment() override; ~ExecutionEnvironment() override;
void initAubStreamProvider(); void initAubCenter();
void initGmm(const HardwareInfo *hwInfo); void initGmm(const HardwareInfo *hwInfo);
bool initializeCommandStreamReceiver(const HardwareInfo *pHwInfo, uint32_t deviceIndex); bool initializeCommandStreamReceiver(const HardwareInfo *pHwInfo, uint32_t deviceIndex);
void initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory, uint32_t deviceIndex); void initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory, uint32_t deviceIndex);
@ -47,7 +47,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
std::unique_ptr<OSInterface> osInterface; std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<MemoryManager> memoryManager; std::unique_ptr<MemoryManager> memoryManager;
std::unique_ptr<AubStreamProvider> aubStreamProvider; std::unique_ptr<AubCenter> aubCenter;
std::vector<std::unique_ptr<CommandStreamReceiver>> commandStreamReceivers; std::vector<std::unique_ptr<CommandStreamReceiver>> commandStreamReceivers;
std::unique_ptr<BuiltIns> builtins; std::unique_ptr<BuiltIns> builtins;
std::unique_ptr<CompilerInterface> compilerInterface; std::unique_ptr<CompilerInterface> compilerInterface;

View File

@ -7,6 +7,7 @@
set(IGDRCL_SRCS_tests_command_stream set(IGDRCL_SRCS_tests_command_stream
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/aub_file_stream_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/aub_subcapture_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/aub_subcapture_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cmd_parse_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cmd_parse_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/command_stream_fixture.h

View File

@ -18,6 +18,7 @@
#include "test.h" #include "test.h"
#include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_aub_file_stream.h"
#include "unit_tests/mocks/mock_aub_subcapture_manager.h" #include "unit_tests/mocks/mock_aub_subcapture_manager.h"
#include "unit_tests/mocks/mock_csr.h" #include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_gmm.h" #include "unit_tests/mocks/mock_gmm.h"
@ -98,33 +99,6 @@ struct MockAubCsrToTestDumpAubNonWritable : public AUBCommandStreamReceiverHw<Gf
} }
}; };
struct MockAubFileStream : public AUBCommandStreamReceiver::AubFileStream {
bool init(uint32_t stepping, uint32_t device) override {
initCalledCnt++;
return true;
}
void flush() override {
flushCalled = true;
}
std::unique_lock<std::mutex> lockStream() override {
lockStreamCalled = true;
return AUBCommandStreamReceiver::AubFileStream::lockStream();
}
void expectMemory(uint64_t physAddress, const void *memory, size_t size, uint32_t addressSpace) override {
physAddressCapturedFromExpectMemory = physAddress;
memoryCapturedFromExpectMemory = reinterpret_cast<uintptr_t>(memory);
sizeCapturedFromExpectMemory = size;
addressSpaceCapturedFromExpectMemory = addressSpace;
}
uint32_t initCalledCnt = 0;
bool flushCalled = false;
bool lockStreamCalled = false;
uint64_t physAddressCapturedFromExpectMemory = 0;
uintptr_t memoryCapturedFromExpectMemory = 0;
size_t sizeCapturedFromExpectMemory = 0;
uint32_t addressSpaceCapturedFromExpectMemory = 0;
};
struct GmockAubFileStream : public AUBCommandStreamReceiver::AubFileStream { struct GmockAubFileStream : public AUBCommandStreamReceiver::AubFileStream {
MOCK_METHOD1(addComment, bool(const char *message)); MOCK_METHOD1(addComment, bool(const char *message));
}; };
@ -229,6 +203,28 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipl
EXPECT_EQ(aubCsr1->stream, aubCsr2->stream); EXPECT_EQ(aubCsr1->stream, aubCsr2->stream);
} }
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSameFileStream) {
ExecutionEnvironment executionEnvironment;
auto aubCsr1 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
auto streamProvider1 = executionEnvironment.aubCenter->getStreamProvider();
EXPECT_NE(nullptr, streamProvider1);
auto aubCsr2 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
auto streamProvider2 = executionEnvironment.aubCenter->getStreamProvider();
EXPECT_NE(nullptr, streamProvider2);
EXPECT_EQ(streamProvider1, streamProvider2);
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSamePhysicalAddressAllocator) {
ExecutionEnvironment executionEnvironment;
auto aubCsr1 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
auto physicalAddressAlocator1 = executionEnvironment.aubCenter->getPhysicalAddressAllocator();
EXPECT_NE(nullptr, physicalAddressAlocator1);
auto aubCsr2 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
auto physicalAddressAlocator2 = executionEnvironment.aubCenter->getPhysicalAddressAllocator();
EXPECT_NE(nullptr, physicalAddressAlocator2);
EXPECT_EQ(physicalAddressAlocator1, physicalAddressAlocator2);
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenItIsCreatedThenFileIsNotCreated) { HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenItIsCreatedThenFileIsNotCreated) {
DebugManagerStateRestore stateRestore; DebugManagerStateRestore stateRestore;
DebugManager.flags.AUBDumpSubCaptureMode.set(static_cast<int32_t>(AubSubCaptureManager::SubCaptureMode::Filter)); DebugManager.flags.AUBDumpSubCaptureMode.set(static_cast<int32_t>(AubSubCaptureManager::SubCaptureMode::Filter));
@ -260,84 +256,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrInSubCaptureModeWhenItIsCreat
EXPECT_STREQ(DebugManager.flags.AUBDumpFilterKernelName.get().c_str(), aubCsr->subCaptureManager->subCaptureFilter.dumpKernelName.c_str()); EXPECT_STREQ(DebugManager.flags.AUBDumpFilterKernelName.get().c_str(), aubCsr->subCaptureManager->subCaptureFilter.dumpKernelName.c_str());
} }
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenInitFileIsCalledWithInvalidFileNameThenFileIsNotOpened) {
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(new AUBCommandStreamReceiverHw<FamilyType>(**platformDevices, "", true, *pDevice->executionEnvironment));
std::string invalidFileName = "";
aubCsr->initFile(invalidFileName);
EXPECT_FALSE(aubCsr->isFileOpen());
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenInitFileIsCalledThenFileIsOpenedAndFileNameIsStored) {
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(new AUBCommandStreamReceiverHw<FamilyType>(**platformDevices, "", true, *pDevice->executionEnvironment));
std::string fileName = "file_name.aub";
aubCsr->initFile(fileName);
EXPECT_TRUE(aubCsr->isFileOpen());
EXPECT_STREQ(fileName.c_str(), aubCsr->getFileName().c_str());
aubCsr->closeFile();
EXPECT_FALSE(aubCsr->isFileOpen());
EXPECT_TRUE(aubCsr->getFileName().empty());
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenReopenFileIsCalledThenFileWithSpecifiedNameIsReopened) {
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, *pDevice->executionEnvironment);
std::string fileName = "file_name.aub";
std::string newFileName = "new_file_name.aub";
aubCsr->reopenFile(fileName);
EXPECT_TRUE(aubCsr->isFileOpen());
EXPECT_STREQ(fileName.c_str(), aubCsr->getFileName().c_str());
aubCsr->reopenFile(newFileName);
EXPECT_TRUE(aubCsr->isFileOpen());
EXPECT_STREQ(newFileName.c_str(), aubCsr->getFileName().c_str());
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenInitFileIsCalledThenFileShouldBeInitializedWithHeaderOnce) {
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, *pDevice->executionEnvironment);
std::string fileName = "file_name.aub";
std::unique_ptr<AUBCommandStreamReceiver::AubFileStream> mockAubFileStream(new MockAubFileStream());
MockAubFileStream *mockAubFileStreamPtr = static_cast<MockAubFileStream *>(mockAubFileStream.get());
ASSERT_NE(nullptr, mockAubFileStreamPtr);
aubCsr->stream = mockAubFileStreamPtr;
aubCsr->initFile(fileName);
aubCsr->initFile(fileName);
EXPECT_EQ(1u, mockAubFileStreamPtr->initCalledCnt);
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenOpenFileIsCalledThenFileStreamShouldBeLocked) {
auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true);
auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>();
std::string fileName = "file_name.aub";
std::unique_ptr<AUBCommandStreamReceiver::AubFileStream> mockAubFileStream(new MockAubFileStream());
MockAubFileStream *mockAubFileStreamPtr = static_cast<MockAubFileStream *>(mockAubFileStream.get());
ASSERT_NE(nullptr, mockAubFileStreamPtr);
aubCsr->stream = mockAubFileStreamPtr;
aubCsr->openFile(fileName);
EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled);
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenReopenFileIsCalledThenFileStreamShouldBeLocked) {
auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true);
auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>();
std::string fileName = "file_name.aub";
std::unique_ptr<AUBCommandStreamReceiver::AubFileStream> mockAubFileStream(new MockAubFileStream());
MockAubFileStream *mockAubFileStreamPtr = static_cast<MockAubFileStream *>(mockAubFileStream.get());
ASSERT_NE(nullptr, mockAubFileStreamPtr);
aubCsr->stream = mockAubFileStreamPtr;
aubCsr->reopenFile(fileName);
EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled);
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeLocked) { HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeLocked) {
auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true); auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true);
auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>(); auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>();

View File

@ -0,0 +1,107 @@
/*
* Copyright (C) 2017-2018 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "runtime/command_stream/aub_command_stream_receiver_hw.h"
#include "test.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/mocks/mock_aub_file_stream.h"
#include <fstream>
#include <memory>
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
#endif
using namespace OCLRT;
using ::testing::_;
using ::testing::Invoke;
using ::testing::Return;
typedef Test<DeviceFixture> AubFileStreamTests;
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenInitFileIsCalledWithInvalidFileNameThenFileIsNotOpened) {
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, *pDevice->executionEnvironment);
std::string invalidFileName = "";
aubCsr->initFile(invalidFileName);
EXPECT_FALSE(aubCsr->isFileOpen());
}
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenInitFileIsCalledThenFileIsOpenedAndFileNameIsStored) {
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, *pDevice->executionEnvironment);
std::string fileName = "file_name.aub";
aubCsr->initFile(fileName);
EXPECT_TRUE(aubCsr->isFileOpen());
EXPECT_STREQ(fileName.c_str(), aubCsr->getFileName().c_str());
aubCsr->closeFile();
EXPECT_FALSE(aubCsr->isFileOpen());
EXPECT_TRUE(aubCsr->getFileName().empty());
}
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenReopenFileIsCalledThenFileWithSpecifiedNameIsReopened) {
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, *pDevice->executionEnvironment);
std::string fileName = "file_name.aub";
std::string newFileName = "new_file_name.aub";
aubCsr->reopenFile(fileName);
EXPECT_TRUE(aubCsr->isFileOpen());
EXPECT_STREQ(fileName.c_str(), aubCsr->getFileName().c_str());
aubCsr->reopenFile(newFileName);
EXPECT_TRUE(aubCsr->isFileOpen());
EXPECT_STREQ(newFileName.c_str(), aubCsr->getFileName().c_str());
}
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenInitFileIsCalledThenFileShouldBeInitializedWithHeaderOnce) {
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, *pDevice->executionEnvironment);
std::string fileName = "file_name.aub";
std::unique_ptr<AUBCommandStreamReceiver::AubFileStream> mockAubFileStream(new MockAubFileStream());
MockAubFileStream *mockAubFileStreamPtr = static_cast<MockAubFileStream *>(mockAubFileStream.get());
ASSERT_NE(nullptr, mockAubFileStreamPtr);
aubCsr->stream = mockAubFileStreamPtr;
aubCsr->initFile(fileName);
aubCsr->initFile(fileName);
EXPECT_EQ(1u, mockAubFileStreamPtr->initCalledCnt);
}
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenOpenFileIsCalledThenFileStreamShouldBeLocked) {
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, *pDevice->executionEnvironment);
std::string fileName = "file_name.aub";
std::unique_ptr<AUBCommandStreamReceiver::AubFileStream> mockAubFileStream(new MockAubFileStream());
MockAubFileStream *mockAubFileStreamPtr = static_cast<MockAubFileStream *>(mockAubFileStream.get());
ASSERT_NE(nullptr, mockAubFileStreamPtr);
aubCsr->stream = mockAubFileStreamPtr;
aubCsr->openFile(fileName);
EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled);
}
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenReopenFileIsCalledThenFileStreamShouldBeLocked) {
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, *pDevice->executionEnvironment);
std::string fileName = "file_name.aub";
std::unique_ptr<AUBCommandStreamReceiver::AubFileStream> mockAubFileStream(new MockAubFileStream());
MockAubFileStream *mockAubFileStreamPtr = static_cast<MockAubFileStream *>(mockAubFileStream.get());
ASSERT_NE(nullptr, mockAubFileStreamPtr);
aubCsr->stream = mockAubFileStreamPtr;
aubCsr->reopenFile(fileName);
EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled);
}
#if defined(__clang__)
#pragma clang diagnostic pop
#endif

View File

@ -6,7 +6,7 @@
*/ */
#include "runtime/built_ins/built_ins.h" #include "runtime/built_ins/built_ins.h"
#include "runtime/command_stream/aub_stream_provider.h" #include "runtime/command_stream/aub_center.h"
#include "runtime/compiler_interface/compiler_interface.h" #include "runtime/compiler_interface/compiler_interface.h"
#include "runtime/device/device.h" #include "runtime/device/device.h"
#include "runtime/execution_environment/execution_environment.h" #include "runtime/execution_environment/execution_environment.h"
@ -120,16 +120,19 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeIsCalledMultip
EXPECT_EQ(nullptr, executionEnvironment->commandStreamReceivers[0u].get()); EXPECT_EQ(nullptr, executionEnvironment->commandStreamReceivers[0u].get());
} }
TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubStreamProviderIsCalledThenItIsInitalizedOnce) { TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCalledThenItIsInitalizedOnce) {
ExecutionEnvironment executionEnvironment; ExecutionEnvironment executionEnvironment;
executionEnvironment.initAubStreamProvider(); executionEnvironment.initAubCenter();
auto currentAubStreamProvider = executionEnvironment.aubStreamProvider.get(); auto currentAubCenter = executionEnvironment.aubCenter.get();
EXPECT_NE(nullptr, currentAubCenter);
auto currentAubStreamProvider = currentAubCenter->getStreamProvider();
EXPECT_NE(nullptr, currentAubStreamProvider); EXPECT_NE(nullptr, currentAubStreamProvider);
auto currentAubFileStream = currentAubStreamProvider->getStream(); auto currentAubFileStream = currentAubStreamProvider->getStream();
EXPECT_NE(nullptr, currentAubFileStream); EXPECT_NE(nullptr, currentAubFileStream);
executionEnvironment.initAubStreamProvider(); executionEnvironment.initAubCenter();
EXPECT_EQ(currentAubStreamProvider, executionEnvironment.aubStreamProvider.get()); EXPECT_EQ(currentAubCenter, executionEnvironment.aubCenter.get());
EXPECT_EQ(currentAubFileStream, executionEnvironment.aubStreamProvider->getStream()); EXPECT_EQ(currentAubStreamProvider, executionEnvironment.aubCenter->getStreamProvider());
EXPECT_EQ(currentAubFileStream, executionEnvironment.aubCenter->getStreamProvider()->getStream());
} }
TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenItIsInitalized) { TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenItIsInitalized) {
@ -155,8 +158,8 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe
struct MemoryMangerMock : public DestructorCounted<OsAgnosticMemoryManager, 5> { struct MemoryMangerMock : public DestructorCounted<OsAgnosticMemoryManager, 5> {
MemoryMangerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} MemoryMangerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
}; };
struct AubFileStreamProviderMock : public DestructorCounted<AubFileStreamProvider, 4> { struct AubCenterMock : public DestructorCounted<AubCenter, 4> {
AubFileStreamProviderMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} AubCenterMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
}; };
struct CommandStreamReceiverMock : public DestructorCounted<MockCommandStreamReceiver, 3> { struct CommandStreamReceiverMock : public DestructorCounted<MockCommandStreamReceiver, 3> {
CommandStreamReceiverMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} CommandStreamReceiverMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
@ -175,7 +178,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe
executionEnvironment->gmmHelper = std::make_unique<GmmHelperMock>(destructorId, platformDevices[0]); executionEnvironment->gmmHelper = std::make_unique<GmmHelperMock>(destructorId, platformDevices[0]);
executionEnvironment->osInterface = std::make_unique<OsInterfaceMock>(destructorId); executionEnvironment->osInterface = std::make_unique<OsInterfaceMock>(destructorId);
executionEnvironment->memoryManager = std::make_unique<MemoryMangerMock>(destructorId); executionEnvironment->memoryManager = std::make_unique<MemoryMangerMock>(destructorId);
executionEnvironment->aubStreamProvider = std::make_unique<AubFileStreamProviderMock>(destructorId); executionEnvironment->aubCenter = std::make_unique<AubCenterMock>(destructorId);
executionEnvironment->commandStreamReceivers.push_back(std::make_unique<CommandStreamReceiverMock>(destructorId)); executionEnvironment->commandStreamReceivers.push_back(std::make_unique<CommandStreamReceiverMock>(destructorId));
executionEnvironment->builtins = std::make_unique<BuiltinsMock>(destructorId); executionEnvironment->builtins = std::make_unique<BuiltinsMock>(destructorId);
executionEnvironment->compilerInterface = std::make_unique<CompilerInterfaceMock>(destructorId); executionEnvironment->compilerInterface = std::make_unique<CompilerInterfaceMock>(destructorId);

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2017-2018 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "runtime/command_stream/aub_command_stream_receiver.h"
namespace OCLRT {
struct MockAubFileStream : public AUBCommandStreamReceiver::AubFileStream {
bool init(uint32_t stepping, uint32_t device) override {
initCalledCnt++;
return true;
}
void flush() override {
flushCalled = true;
}
std::unique_lock<std::mutex> lockStream() override {
lockStreamCalled = true;
return AUBCommandStreamReceiver::AubFileStream::lockStream();
}
void expectMemory(uint64_t physAddress, const void *memory, size_t size, uint32_t addressSpace) override {
physAddressCapturedFromExpectMemory = physAddress;
memoryCapturedFromExpectMemory = reinterpret_cast<uintptr_t>(memory);
sizeCapturedFromExpectMemory = size;
addressSpaceCapturedFromExpectMemory = addressSpace;
}
uint32_t initCalledCnt = 0;
bool flushCalled = false;
bool lockStreamCalled = false;
uint64_t physAddressCapturedFromExpectMemory = 0;
uintptr_t memoryCapturedFromExpectMemory = 0;
size_t sizeCapturedFromExpectMemory = 0;
uint32_t addressSpaceCapturedFromExpectMemory = 0;
};
} // namespace OCLRT