Skip to content

Commit efdbde2

Browse files
AUB CSRs to use a shared physical address allocator
This commit introduces AUB-specific control class to execution environment. Change-Id: I525c9c93a4f10f769dbedb7d097674c35693f0b1
1 parent 6aab39f commit efdbde2

File tree

11 files changed

+252
-131
lines changed

11 files changed

+252
-131
lines changed

runtime/command_stream/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
set(RUNTIME_SRCS_COMMAND_STREAM
88
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
9+
${CMAKE_CURRENT_SOURCE_DIR}/aub_center.h
910
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver.cpp
1011
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver.h
1112
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_hw.h
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2018 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
#include "runtime/command_stream/aub_stream_provider.h"
10+
#include "runtime/memory_manager/physical_address_allocator.h"
11+
12+
namespace OCLRT {
13+
14+
class AubCenter {
15+
public:
16+
AubCenter() {
17+
streamProvider = std::make_unique<AubFileStreamProvider>();
18+
}
19+
virtual ~AubCenter() = default;
20+
21+
void initPhysicalAddressAllocator(PhysicalAddressAllocator *pPhysicalAddressAllocator) {
22+
physicalAddressAllocator = std::unique_ptr<PhysicalAddressAllocator>(pPhysicalAddressAllocator);
23+
}
24+
25+
PhysicalAddressAllocator *getPhysicalAddressAllocator() const {
26+
return physicalAddressAllocator.get();
27+
}
28+
29+
AubStreamProvider *getStreamProvider() const {
30+
return streamProvider.get();
31+
}
32+
33+
protected:
34+
std::unique_ptr<PhysicalAddressAllocator> physicalAddressAllocator;
35+
std::unique_ptr<AubStreamProvider> streamProvider;
36+
};
37+
} // namespace OCLRT

runtime/command_stream/aub_command_stream_receiver_hw.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
#pragma once
99
#include "runtime/gen_common/aub_mapper.h"
1010
#include "command_stream_receiver_simulated_hw.h"
11+
#include "runtime/command_stream/aub_center.h"
1112
#include "runtime/command_stream/aub_command_stream_receiver.h"
1213
#include "runtime/memory_manager/address_mapper.h"
1314
#include "runtime/memory_manager/page_table.h"
15+
#include "runtime/memory_manager/physical_address_allocator.h"
1416
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
1517

1618
namespace OCLRT {
@@ -90,7 +92,6 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
9092
uint32_t aubDeviceId;
9193
bool standalone;
9294

93-
std::unique_ptr<PhysicalAddressAllocator> physicalAddressAllocator;
9495
std::unique_ptr<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type> ppgtt;
9596
std::unique_ptr<PDPE> ggtt;
9697
// remap CPU VA -> GGTT VA
@@ -111,7 +112,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
111112

112113
protected:
113114
int getAddressSpace(int hint);
114-
void createPhysicalAddressAllocator();
115+
PhysicalAddressAllocator *createPhysicalAddressAllocator();
115116

116117
bool dumpAubNonWritable = false;
117118
ExternalAllocationsContainer externalAllocations;

runtime/command_stream/aub_command_stream_receiver_hw.inl

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "runtime/memory_manager/graphics_allocation.h"
2222
#include "runtime/memory_manager/memory_banks.h"
2323
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
24+
#include "runtime/memory_manager/physical_address_allocator.h"
2425
#include "runtime/os_interface/debug_settings_manager.h"
2526
#include <cstring>
2627

@@ -32,17 +33,29 @@ AUBCommandStreamReceiverHw<GfxFamily>::AUBCommandStreamReceiverHw(const Hardware
3233
subCaptureManager(std::make_unique<AubSubCaptureManager>(fileName)),
3334
standalone(standalone) {
3435

35-
createPhysicalAddressAllocator();
36+
executionEnvironment.initAubCenter();
37+
auto aubCenter = executionEnvironment.aubCenter.get();
38+
UNRECOVERABLE_IF(nullptr == aubCenter);
3639

37-
ppgtt = std::make_unique<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type>(physicalAddressAllocator.get());
38-
ggtt = std::make_unique<PDPE>(physicalAddressAllocator.get());
40+
if (!aubCenter->getPhysicalAddressAllocator()) {
41+
aubCenter->initPhysicalAddressAllocator(createPhysicalAddressAllocator());
42+
}
43+
auto physicalAddressAllocator = aubCenter->getPhysicalAddressAllocator();
44+
UNRECOVERABLE_IF(nullptr == physicalAddressAllocator);
45+
46+
ppgtt = std::make_unique<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type>(physicalAddressAllocator);
47+
ggtt = std::make_unique<PDPE>(physicalAddressAllocator);
48+
49+
auto streamProvider = aubCenter->getStreamProvider();
50+
UNRECOVERABLE_IF(nullptr == streamProvider);
51+
52+
stream = streamProvider->getStream();
53+
UNRECOVERABLE_IF(nullptr == stream);
3954

4055
this->dispatchMode = DispatchMode::BatchedDispatch;
4156
if (DebugManager.flags.CsrDispatchMode.get()) {
4257
this->dispatchMode = (DispatchMode)DebugManager.flags.CsrDispatchMode.get();
4358
}
44-
executionEnvironment.initAubStreamProvider();
45-
stream = executionEnvironment.aubStreamProvider->getStream();
4659
if (DebugManager.flags.AUBDumpSubCaptureMode.get()) {
4760
this->subCaptureManager->subCaptureMode = static_cast<AubSubCaptureManager::SubCaptureMode>(DebugManager.flags.AUBDumpSubCaptureMode.get());
4861
this->subCaptureManager->subCaptureFilter.dumpKernelStartIdx = static_cast<uint32_t>(DebugManager.flags.AUBDumpFilterKernelStartIdx.get());
@@ -770,8 +783,8 @@ uint32_t AUBCommandStreamReceiverHw<GfxFamily>::getMemoryBankForGtt() const {
770783
}
771784

772785
template <typename GfxFamily>
773-
void AUBCommandStreamReceiverHw<GfxFamily>::createPhysicalAddressAllocator() {
774-
physicalAddressAllocator = std::make_unique<PhysicalAddressAllocator>();
786+
PhysicalAddressAllocator *AUBCommandStreamReceiverHw<GfxFamily>::createPhysicalAddressAllocator() {
787+
return new PhysicalAddressAllocator();
775788
}
776789

777790
} // namespace OCLRT

runtime/execution_environment/execution_environment.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
#include "runtime/execution_environment/execution_environment.h"
9-
#include "runtime/command_stream/aub_stream_provider.h"
9+
#include "runtime/command_stream/aub_center.h"
1010
#include "runtime/command_stream/command_stream_receiver.h"
1111
#include "runtime/compiler_interface/compiler_interface.h"
1212
#include "runtime/source_level_debugger/source_level_debugger.h"
@@ -22,9 +22,9 @@ ExecutionEnvironment::ExecutionEnvironment() = default;
2222
ExecutionEnvironment::~ExecutionEnvironment() = default;
2323
extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo, ExecutionEnvironment &executionEnvironment);
2424

25-
void ExecutionEnvironment::initAubStreamProvider() {
26-
if (!aubStreamProvider) {
27-
aubStreamProvider.reset(new AubFileStreamProvider());
25+
void ExecutionEnvironment::initAubCenter() {
26+
if (!aubCenter) {
27+
aubCenter.reset(new AubCenter());
2828
}
2929
}
3030
void ExecutionEnvironment::initGmm(const HardwareInfo *hwInfo) {

runtime/execution_environment/execution_environment.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <vector>
1414

1515
namespace OCLRT {
16-
class AubStreamProvider;
16+
class AubCenter;
1717
class GmmHelper;
1818
class CommandStreamReceiver;
1919
class MemoryManager;
@@ -35,7 +35,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
3535
ExecutionEnvironment();
3636
~ExecutionEnvironment() override;
3737

38-
void initAubStreamProvider();
38+
void initAubCenter();
3939
void initGmm(const HardwareInfo *hwInfo);
4040
bool initializeCommandStreamReceiver(const HardwareInfo *pHwInfo, uint32_t deviceIndex);
4141
void initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory, uint32_t deviceIndex);
@@ -47,7 +47,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
4747

4848
std::unique_ptr<OSInterface> osInterface;
4949
std::unique_ptr<MemoryManager> memoryManager;
50-
std::unique_ptr<AubStreamProvider> aubStreamProvider;
50+
std::unique_ptr<AubCenter> aubCenter;
5151
std::vector<std::unique_ptr<CommandStreamReceiver>> commandStreamReceivers;
5252
std::unique_ptr<BuiltIns> builtins;
5353
std::unique_ptr<CompilerInterface> compilerInterface;

unit_tests/command_stream/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
set(IGDRCL_SRCS_tests_command_stream
88
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
99
${CMAKE_CURRENT_SOURCE_DIR}/aub_command_stream_receiver_tests.cpp
10+
${CMAKE_CURRENT_SOURCE_DIR}/aub_file_stream_tests.cpp
1011
${CMAKE_CURRENT_SOURCE_DIR}/aub_subcapture_tests.cpp
1112
${CMAKE_CURRENT_SOURCE_DIR}/cmd_parse_tests.cpp
1213
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_fixture.h

unit_tests/command_stream/aub_command_stream_receiver_tests.cpp

Lines changed: 23 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "test.h"
1919
#include "unit_tests/fixtures/device_fixture.h"
2020
#include "unit_tests/helpers/debug_manager_state_restore.h"
21+
#include "unit_tests/mocks/mock_aub_file_stream.h"
2122
#include "unit_tests/mocks/mock_aub_subcapture_manager.h"
2223
#include "unit_tests/mocks/mock_csr.h"
2324
#include "unit_tests/mocks/mock_gmm.h"
@@ -98,33 +99,6 @@ struct MockAubCsrToTestDumpAubNonWritable : public AUBCommandStreamReceiverHw<Gf
9899
}
99100
};
100101

101-
struct MockAubFileStream : public AUBCommandStreamReceiver::AubFileStream {
102-
bool init(uint32_t stepping, uint32_t device) override {
103-
initCalledCnt++;
104-
return true;
105-
}
106-
void flush() override {
107-
flushCalled = true;
108-
}
109-
std::unique_lock<std::mutex> lockStream() override {
110-
lockStreamCalled = true;
111-
return AUBCommandStreamReceiver::AubFileStream::lockStream();
112-
}
113-
void expectMemory(uint64_t physAddress, const void *memory, size_t size, uint32_t addressSpace) override {
114-
physAddressCapturedFromExpectMemory = physAddress;
115-
memoryCapturedFromExpectMemory = reinterpret_cast<uintptr_t>(memory);
116-
sizeCapturedFromExpectMemory = size;
117-
addressSpaceCapturedFromExpectMemory = addressSpace;
118-
}
119-
uint32_t initCalledCnt = 0;
120-
bool flushCalled = false;
121-
bool lockStreamCalled = false;
122-
uint64_t physAddressCapturedFromExpectMemory = 0;
123-
uintptr_t memoryCapturedFromExpectMemory = 0;
124-
size_t sizeCapturedFromExpectMemory = 0;
125-
uint32_t addressSpaceCapturedFromExpectMemory = 0;
126-
};
127-
128102
struct GmockAubFileStream : public AUBCommandStreamReceiver::AubFileStream {
129103
MOCK_METHOD1(addComment, bool(const char *message));
130104
};
@@ -229,6 +203,28 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipl
229203
EXPECT_EQ(aubCsr1->stream, aubCsr2->stream);
230204
}
231205

206+
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSameFileStream) {
207+
ExecutionEnvironment executionEnvironment;
208+
auto aubCsr1 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
209+
auto streamProvider1 = executionEnvironment.aubCenter->getStreamProvider();
210+
EXPECT_NE(nullptr, streamProvider1);
211+
auto aubCsr2 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
212+
auto streamProvider2 = executionEnvironment.aubCenter->getStreamProvider();
213+
EXPECT_NE(nullptr, streamProvider2);
214+
EXPECT_EQ(streamProvider1, streamProvider2);
215+
}
216+
217+
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSamePhysicalAddressAllocator) {
218+
ExecutionEnvironment executionEnvironment;
219+
auto aubCsr1 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
220+
auto physicalAddressAlocator1 = executionEnvironment.aubCenter->getPhysicalAddressAllocator();
221+
EXPECT_NE(nullptr, physicalAddressAlocator1);
222+
auto aubCsr2 = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, executionEnvironment);
223+
auto physicalAddressAlocator2 = executionEnvironment.aubCenter->getPhysicalAddressAllocator();
224+
EXPECT_NE(nullptr, physicalAddressAlocator2);
225+
EXPECT_EQ(physicalAddressAlocator1, physicalAddressAlocator2);
226+
}
227+
232228
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenItIsCreatedThenFileIsNotCreated) {
233229
DebugManagerStateRestore stateRestore;
234230
DebugManager.flags.AUBDumpSubCaptureMode.set(static_cast<int32_t>(AubSubCaptureManager::SubCaptureMode::Filter));
@@ -260,84 +256,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrInSubCaptureModeWhenItIsCreat
260256
EXPECT_STREQ(DebugManager.flags.AUBDumpFilterKernelName.get().c_str(), aubCsr->subCaptureManager->subCaptureFilter.dumpKernelName.c_str());
261257
}
262258

263-
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenInitFileIsCalledWithInvalidFileNameThenFileIsNotOpened) {
264-
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(new AUBCommandStreamReceiverHw<FamilyType>(**platformDevices, "", true, *pDevice->executionEnvironment));
265-
std::string invalidFileName = "";
266-
267-
aubCsr->initFile(invalidFileName);
268-
EXPECT_FALSE(aubCsr->isFileOpen());
269-
}
270-
271-
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenInitFileIsCalledThenFileIsOpenedAndFileNameIsStored) {
272-
std::unique_ptr<AUBCommandStreamReceiverHw<FamilyType>> aubCsr(new AUBCommandStreamReceiverHw<FamilyType>(**platformDevices, "", true, *pDevice->executionEnvironment));
273-
std::string fileName = "file_name.aub";
274-
275-
aubCsr->initFile(fileName);
276-
EXPECT_TRUE(aubCsr->isFileOpen());
277-
EXPECT_STREQ(fileName.c_str(), aubCsr->getFileName().c_str());
278-
279-
aubCsr->closeFile();
280-
EXPECT_FALSE(aubCsr->isFileOpen());
281-
EXPECT_TRUE(aubCsr->getFileName().empty());
282-
}
283-
284-
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenReopenFileIsCalledThenFileWithSpecifiedNameIsReopened) {
285-
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, *pDevice->executionEnvironment);
286-
std::string fileName = "file_name.aub";
287-
std::string newFileName = "new_file_name.aub";
288-
289-
aubCsr->reopenFile(fileName);
290-
EXPECT_TRUE(aubCsr->isFileOpen());
291-
EXPECT_STREQ(fileName.c_str(), aubCsr->getFileName().c_str());
292-
293-
aubCsr->reopenFile(newFileName);
294-
EXPECT_TRUE(aubCsr->isFileOpen());
295-
EXPECT_STREQ(newFileName.c_str(), aubCsr->getFileName().c_str());
296-
}
297-
298-
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenInitFileIsCalledThenFileShouldBeInitializedWithHeaderOnce) {
299-
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(**platformDevices, "", true, *pDevice->executionEnvironment);
300-
std::string fileName = "file_name.aub";
301-
302-
std::unique_ptr<AUBCommandStreamReceiver::AubFileStream> mockAubFileStream(new MockAubFileStream());
303-
MockAubFileStream *mockAubFileStreamPtr = static_cast<MockAubFileStream *>(mockAubFileStream.get());
304-
ASSERT_NE(nullptr, mockAubFileStreamPtr);
305-
aubCsr->stream = mockAubFileStreamPtr;
306-
307-
aubCsr->initFile(fileName);
308-
aubCsr->initFile(fileName);
309-
310-
EXPECT_EQ(1u, mockAubFileStreamPtr->initCalledCnt);
311-
}
312-
313-
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenOpenFileIsCalledThenFileStreamShouldBeLocked) {
314-
auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true);
315-
auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>();
316-
std::string fileName = "file_name.aub";
317-
318-
std::unique_ptr<AUBCommandStreamReceiver::AubFileStream> mockAubFileStream(new MockAubFileStream());
319-
MockAubFileStream *mockAubFileStreamPtr = static_cast<MockAubFileStream *>(mockAubFileStream.get());
320-
ASSERT_NE(nullptr, mockAubFileStreamPtr);
321-
aubCsr->stream = mockAubFileStreamPtr;
322-
323-
aubCsr->openFile(fileName);
324-
EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled);
325-
}
326-
327-
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenReopenFileIsCalledThenFileStreamShouldBeLocked) {
328-
auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true);
329-
auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>();
330-
std::string fileName = "file_name.aub";
331-
332-
std::unique_ptr<AUBCommandStreamReceiver::AubFileStream> mockAubFileStream(new MockAubFileStream());
333-
MockAubFileStream *mockAubFileStreamPtr = static_cast<MockAubFileStream *>(mockAubFileStream.get());
334-
ASSERT_NE(nullptr, mockAubFileStreamPtr);
335-
aubCsr->stream = mockAubFileStreamPtr;
336-
337-
aubCsr->reopenFile(fileName);
338-
EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled);
339-
}
340-
341259
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeLocked) {
342260
auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true);
343261
auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>();

0 commit comments

Comments
 (0)