Skip to content

Commit f0e7e24

Browse files
Add support for AUB subcapture in TBX mode
Resolves: NEO-3051 Change-Id: If7c2d550227d0c5d09c35a53387f34f968e7c7b7 Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
1 parent c3fc8d8 commit f0e7e24

File tree

6 files changed

+299
-2
lines changed

6 files changed

+299
-2
lines changed

runtime/command_stream/tbx_command_stream_receiver_hw.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
namespace NEO {
2020

21+
class AubSubCaptureManager;
2122
class TbxStream;
2223

2324
class TbxMemoryManager : public OsAgnosticMemoryManager {
@@ -57,6 +58,8 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
5758
void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits) override;
5859
bool writeMemory(GraphicsAllocation &gfxAllocation) override;
5960

61+
AubSubCaptureStatus checkAndActivateAubSubCapture(const MultiDispatchInfo &dispatchInfo) override;
62+
6063
// Family specific version
6164
MOCKABLE_VIRTUAL void submitBatchBuffer(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits);
6265
void pollForCompletion() override;
@@ -73,7 +76,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
7376
}
7477

7578
TbxStream tbxStream;
76-
79+
std::unique_ptr<AubSubCaptureManager> subCaptureManager;
7780
uint32_t aubDeviceId;
7881
bool streamInitialized = false;
7982

@@ -88,5 +91,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
8891
CommandStreamReceiverType getType() override {
8992
return CommandStreamReceiverType::CSR_TBX;
9093
}
94+
95+
bool dumpTbxNonWritable = false;
9196
};
9297
} // namespace NEO

runtime/command_stream/tbx_command_stream_receiver_hw.inl

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "runtime/command_stream/aub_command_stream_receiver.h"
1717
#include "runtime/command_stream/command_stream_receiver_with_aub_dump.h"
1818
#include "runtime/execution_environment/execution_environment.h"
19+
#include "runtime/helpers/dispatch_info.h"
1920
#include "runtime/helpers/hardware_context_controller.h"
2021
#include "runtime/helpers/hw_helper.h"
2122
#include "runtime/memory_manager/memory_banks.h"
@@ -156,9 +157,21 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw<GfxFamily>::create(const std::
156157
executionEnvironment.initAubCenter(localMemoryEnabled, fullName, CommandStreamReceiverType::CSR_TBX_WITH_AUB);
157158

158159
csr = new CommandStreamReceiverWithAUBDump<TbxCommandStreamReceiverHw<GfxFamily>>(baseName, executionEnvironment);
160+
161+
auto aubCenter = executionEnvironment.aubCenter.get();
162+
UNRECOVERABLE_IF(nullptr == aubCenter);
163+
164+
auto subCaptureCommon = aubCenter->getSubCaptureCommon();
165+
UNRECOVERABLE_IF(nullptr == subCaptureCommon);
166+
167+
if (subCaptureCommon->subCaptureMode > AubSubCaptureManager::SubCaptureMode::Off) {
168+
csr->subCaptureManager = std::make_unique<AubSubCaptureManager>(fullName, *subCaptureCommon);
169+
}
170+
159171
if (csr->aubManager) {
160172
if (!csr->aubManager->isOpen()) {
161-
csr->aubManager->open(fullName);
173+
MultiDispatchInfo dispatchInfo;
174+
csr->aubManager->open(csr->subCaptureManager ? csr->subCaptureManager->getSubCaptureFileName(dispatchInfo) : fullName);
162175
UNRECOVERABLE_IF(!csr->aubManager->isOpen());
163176
}
164177
}
@@ -179,6 +192,12 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw<GfxFamily>::create(const std::
179192

180193
template <typename GfxFamily>
181194
FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
195+
if (subCaptureManager) {
196+
if (aubManager) {
197+
aubManager->pause(false);
198+
}
199+
}
200+
182201
initializeEngine();
183202

184203
// Write our batch buffer
@@ -196,7 +215,19 @@ FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
196215
// Write allocations for residency
197216
processResidency(allocationsForResidency);
198217

218+
if (subCaptureManager && !subCaptureManager->isSubCaptureEnabled()) {
219+
if (aubManager) {
220+
aubManager->pause(true);
221+
}
222+
}
223+
199224
submitBatchBuffer(batchBufferGpuAddress, pBatchBuffer, sizeBatchBuffer, this->getMemoryBank(batchBuffer.commandBufferAllocation), this->getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation));
225+
226+
if (subCaptureManager) {
227+
pollForCompletion();
228+
subCaptureManager->disableSubCapture();
229+
}
230+
200231
return 0;
201232
}
202233

@@ -412,12 +443,17 @@ void TbxCommandStreamReceiverHw<GfxFamily>::processEviction() {
412443
template <typename GfxFamily>
413444
void TbxCommandStreamReceiverHw<GfxFamily>::processResidency(const ResidencyContainer &allocationsForResidency) {
414445
for (auto &gfxAllocation : allocationsForResidency) {
446+
if (dumpTbxNonWritable) {
447+
this->setTbxWritable(true, *gfxAllocation);
448+
}
415449
if (!writeMemory(*gfxAllocation)) {
416450
DEBUG_BREAK_IF(!((gfxAllocation->getUnderlyingBufferSize() == 0) ||
417451
!this->isTbxWritable(*gfxAllocation)));
418452
}
419453
gfxAllocation->updateResidencyTaskCount(this->taskCount + 1, this->osContext->getContextId());
420454
}
455+
456+
dumpTbxNonWritable = false;
421457
}
422458

423459
template <typename GfxFamily>
@@ -450,4 +486,17 @@ template <typename GfxFamily>
450486
bool TbxCommandStreamReceiverHw<GfxFamily>::getpollNotEqualValueForPollForCompletion() const {
451487
return false;
452488
}
489+
490+
template <typename GfxFamily>
491+
AubSubCaptureStatus TbxCommandStreamReceiverHw<GfxFamily>::checkAndActivateAubSubCapture(const MultiDispatchInfo &dispatchInfo) {
492+
if (!subCaptureManager) {
493+
return {false, false};
494+
}
495+
496+
auto status = subCaptureManager->checkAndActivateSubCapture(dispatchInfo);
497+
if (status.isActive && !status.wasActiveInPreviousEnqueue) {
498+
dumpTbxNonWritable = true;
499+
}
500+
return status;
501+
}
453502
} // namespace NEO

third_party/aub_stream/headers/aub_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class AubManager {
2323
virtual void close() = 0;
2424
virtual bool isOpen() = 0;
2525
virtual const std::string getFileName() = 0;
26+
virtual void pause(bool onoff) = 0;
2627

2728
virtual void addComment(const char *message) = 0;
2829
virtual void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize) = 0;

unit_tests/command_stream/aub_subcapture_tests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,15 @@ TEST_F(AubSubCaptureTest, givenSubCaptureManagerInToggleModeWhenGetSubCaptureFil
356356
EXPECT_STREQ(toggleFileName.c_str(), aubSubCaptureManager.getSubCaptureFileName(multiDispatchInfo).c_str());
357357
}
358358

359+
TEST_F(AubSubCaptureTest, givenSubCaptureManagerInToggleModeWhenGetSubCaptureFileNameIsCalledForEmptyDispatchInfoThenGenerateToggleFileNameWithoutKernelName) {
360+
AubSubCaptureManagerMock aubSubCaptureManager("aubfile.aub", subCaptureCommon);
361+
362+
MultiDispatchInfo dispatchInfo;
363+
subCaptureCommon.subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle;
364+
auto toggleFileName = aubSubCaptureManager.generateToggleFileName(dispatchInfo);
365+
EXPECT_STREQ(toggleFileName.c_str(), aubSubCaptureManager.getSubCaptureFileName(dispatchInfo).c_str());
366+
}
367+
359368
TEST_F(AubSubCaptureTest, givenSubCaptureManagerInFilterModeWhenGetSubCaptureFileNameIsCalledManyTimesAndExternalFileNameIsNotSpecifiedThenItGeneratesFilterFileNameOnceOnly) {
360369
struct AubSubCaptureManagerMockWithFilterFileNameGenerationCount : AubSubCaptureManager {
361370
using AubSubCaptureManager::AubSubCaptureManager;

0 commit comments

Comments
 (0)