2018-06-13 02:33:03 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2018-2019 Intel Corporation
|
2018-06-13 02:33:03 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-06-13 02:33:03 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "runtime/command_stream/aub_subcapture.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2018-06-13 02:33:03 +08:00
|
|
|
#include "runtime/helpers/dispatch_info.h"
|
|
|
|
#include "runtime/kernel/kernel.h"
|
|
|
|
#include "runtime/utilities/debug_settings_reader.h"
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
2018-07-09 17:31:36 +08:00
|
|
|
AubSubCaptureManager::AubSubCaptureManager(const std::string &fileName)
|
|
|
|
: initialFileName(fileName) {
|
2018-07-02 00:44:29 +08:00
|
|
|
settingsReader.reset(SettingsReader::createOsReader(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
AubSubCaptureManager::~AubSubCaptureManager() = default;
|
|
|
|
|
2018-07-09 17:31:36 +08:00
|
|
|
bool AubSubCaptureManager::activateSubCapture(const MultiDispatchInfo &dispatchInfo) {
|
2018-06-13 02:33:03 +08:00
|
|
|
if (dispatchInfo.empty()) {
|
2018-07-09 17:31:36 +08:00
|
|
|
return false;
|
2018-06-13 02:33:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
subCaptureWasActive = subCaptureIsActive;
|
|
|
|
subCaptureIsActive = false;
|
|
|
|
|
|
|
|
switch (subCaptureMode) {
|
|
|
|
case SubCaptureMode::Toggle:
|
|
|
|
subCaptureIsActive = isSubCaptureToggleActive();
|
|
|
|
break;
|
|
|
|
case SubCaptureMode::Filter:
|
2018-07-26 17:35:13 +08:00
|
|
|
subCaptureIsActive = isSubCaptureFilterActive(dispatchInfo);
|
2018-06-13 02:33:03 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DEBUG_BREAK_IF(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-09 17:31:36 +08:00
|
|
|
kernelCurrentIdx++;
|
2018-06-13 02:33:03 +08:00
|
|
|
setDebugManagerFlags();
|
2018-07-09 17:31:36 +08:00
|
|
|
|
|
|
|
return subCaptureIsActive;
|
2018-06-13 02:33:03 +08:00
|
|
|
}
|
|
|
|
|
2018-07-09 17:31:36 +08:00
|
|
|
const std::string &AubSubCaptureManager::getSubCaptureFileName(const MultiDispatchInfo &dispatchInfo) {
|
|
|
|
if (useExternalFileName) {
|
|
|
|
currentFileName = getExternalFileName();
|
|
|
|
}
|
|
|
|
switch (subCaptureMode) {
|
|
|
|
case SubCaptureMode::Filter:
|
|
|
|
if (currentFileName.empty()) {
|
|
|
|
currentFileName = generateFilterFileName();
|
|
|
|
useExternalFileName = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SubCaptureMode::Toggle:
|
|
|
|
if (currentFileName.empty()) {
|
|
|
|
currentFileName = generateToggleFileName(dispatchInfo);
|
|
|
|
useExternalFileName = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DEBUG_BREAK_IF(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentFileName;
|
2018-06-13 02:33:03 +08:00
|
|
|
}
|
|
|
|
|
2018-07-26 17:35:13 +08:00
|
|
|
bool AubSubCaptureManager::isKernelIndexInSubCaptureRange(uint32_t kernelIdx, uint32_t rangeStartIdx, uint32_t rangeEndIdx) const {
|
|
|
|
return ((rangeStartIdx <= kernelIdx) && (kernelIdx <= rangeEndIdx));
|
2018-06-13 02:33:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AubSubCaptureManager::isSubCaptureToggleActive() const {
|
2018-07-02 00:44:29 +08:00
|
|
|
return settingsReader->getSetting("AUBDumpToggleCaptureOnOff", false);
|
2018-06-13 02:33:03 +08:00
|
|
|
}
|
|
|
|
|
2018-07-09 17:31:36 +08:00
|
|
|
std::string AubSubCaptureManager::getExternalFileName() const {
|
|
|
|
return settingsReader->getSetting("AUBDumpToggleFileName", std::string(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AubSubCaptureManager::generateFilterFileName() const {
|
|
|
|
std::string baseFileName = initialFileName.substr(0, initialFileName.length() - strlen(".aub"));
|
|
|
|
std::string filterFileName = baseFileName + "_filter";
|
|
|
|
filterFileName += "_from_" + std::to_string(subCaptureFilter.dumpKernelStartIdx);
|
|
|
|
filterFileName += "_to_" + std::to_string(subCaptureFilter.dumpKernelEndIdx);
|
|
|
|
if (!subCaptureFilter.dumpKernelName.empty()) {
|
|
|
|
filterFileName += "_" + subCaptureFilter.dumpKernelName;
|
2018-07-26 17:35:13 +08:00
|
|
|
filterFileName += "_from_" + std::to_string(subCaptureFilter.dumpNamedKernelStartIdx);
|
|
|
|
filterFileName += "_to_" + std::to_string(subCaptureFilter.dumpNamedKernelEndIdx);
|
2018-07-09 17:31:36 +08:00
|
|
|
}
|
|
|
|
filterFileName += ".aub";
|
|
|
|
return filterFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AubSubCaptureManager::generateToggleFileName(const MultiDispatchInfo &dispatchInfo) const {
|
|
|
|
std::string baseFileName = initialFileName.substr(0, initialFileName.length() - strlen(".aub"));
|
|
|
|
std::string toggleFileName = baseFileName + "_toggle";
|
|
|
|
toggleFileName += "_from_" + std::to_string(kernelCurrentIdx - 1);
|
|
|
|
if (!dispatchInfo.empty()) {
|
2018-08-17 21:13:04 +08:00
|
|
|
toggleFileName += "_" + dispatchInfo.peekMainKernel()->getKernelInfo().name;
|
2018-07-09 17:31:36 +08:00
|
|
|
}
|
|
|
|
toggleFileName += ".aub";
|
|
|
|
return toggleFileName;
|
|
|
|
}
|
|
|
|
|
2018-07-26 17:35:13 +08:00
|
|
|
bool AubSubCaptureManager::isSubCaptureFilterActive(const MultiDispatchInfo &dispatchInfo) {
|
2018-08-17 21:13:04 +08:00
|
|
|
auto kernelName = dispatchInfo.peekMainKernel()->getKernelInfo().name;
|
2018-06-13 02:33:03 +08:00
|
|
|
auto subCaptureIsActive = false;
|
|
|
|
|
2018-07-26 17:35:13 +08:00
|
|
|
if (subCaptureFilter.dumpKernelName.empty()) {
|
|
|
|
if (isKernelIndexInSubCaptureRange(kernelCurrentIdx, subCaptureFilter.dumpKernelStartIdx, subCaptureFilter.dumpKernelEndIdx)) {
|
2018-06-13 02:33:03 +08:00
|
|
|
subCaptureIsActive = true;
|
2018-07-26 17:35:13 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (0 == kernelName.compare(subCaptureFilter.dumpKernelName)) {
|
|
|
|
if (isKernelIndexInSubCaptureRange(kernelNameMatchesNum, subCaptureFilter.dumpNamedKernelStartIdx, subCaptureFilter.dumpNamedKernelEndIdx)) {
|
2018-06-13 02:33:03 +08:00
|
|
|
subCaptureIsActive = true;
|
|
|
|
}
|
2018-07-26 17:35:13 +08:00
|
|
|
kernelNameMatchesNum++;
|
2018-06-13 02:33:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return subCaptureIsActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AubSubCaptureManager::setDebugManagerFlags() const {
|
|
|
|
DebugManager.flags.MakeEachEnqueueBlocking.set(!subCaptureIsActive);
|
|
|
|
DebugManager.flags.ForceCsrFlushing.set(false);
|
|
|
|
if (!subCaptureIsActive && subCaptureWasActive) {
|
|
|
|
DebugManager.flags.ForceCsrFlushing.set(true);
|
|
|
|
}
|
|
|
|
DebugManager.flags.ForceCsrReprogramming.set(false);
|
|
|
|
if (subCaptureIsActive && !subCaptureWasActive) {
|
|
|
|
DebugManager.flags.ForceCsrReprogramming.set(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace OCLRT
|