2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2024-12-23 21:42:43 +00:00
|
|
|
* Copyright (C) 2018-2025 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 13:17:55 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-10-16 12:10:52 +02:00
|
|
|
#include "shared/source/aub/aub_center.h"
|
|
|
|
|
#include "shared/source/aub/aub_helper.h"
|
|
|
|
|
#include "shared/source/aub_mem_dump/aub_alloc_dump.h"
|
|
|
|
|
#include "shared/source/aub_mem_dump/aub_alloc_dump.inl"
|
|
|
|
|
#include "shared/source/aub_mem_dump/page_table_entry_bits.h"
|
2021-07-06 15:44:16 +02:00
|
|
|
#include "shared/source/command_stream/aub_command_stream_receiver.h"
|
2021-09-22 22:03:07 +00:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver_with_aub_dump.h"
|
2023-01-02 11:14:39 +00:00
|
|
|
#include "shared/source/command_stream/submission_status.h"
|
2023-01-17 17:04:14 +00:00
|
|
|
#include "shared/source/command_stream/submissions_aggregator.h"
|
2022-11-07 13:04:52 +00:00
|
|
|
#include "shared/source/command_stream/tbx_command_stream_receiver_hw.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
|
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
|
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
2021-09-22 22:03:07 +00:00
|
|
|
#include "shared/source/helpers/api_specific_config.h"
|
2020-04-02 11:28:38 +02:00
|
|
|
#include "shared/source/helpers/constants.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/debug_helpers.h"
|
2020-04-15 15:30:29 +02:00
|
|
|
#include "shared/source/helpers/engine_node_helper.h"
|
2023-02-01 16:23:01 +00:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2023-02-14 10:19:05 +00:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
2024-12-23 21:42:43 +00:00
|
|
|
#include "shared/source/memory_manager/allocation_type.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2024-12-23 21:42:43 +00:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2024-06-14 14:15:14 +00:00
|
|
|
#include "shared/source/os_interface/aub_memory_operations_handler.h"
|
2023-03-10 12:28:11 +00:00
|
|
|
#include "shared/source/os_interface/product_helper.h"
|
2024-12-23 21:42:43 +00:00
|
|
|
#include "shared/source/page_fault_manager/tbx_page_fault_manager.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <cstring>
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2024-12-23 21:42:43 +00:00
|
|
|
template <typename GfxFamily>
|
|
|
|
|
CpuPageFaultManager *TbxCommandStreamReceiverHw<GfxFamily>::getTbxPageFaultManager() {
|
|
|
|
|
return this->getMemoryManager()->getPageFaultManager();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
template <typename GfxFamily>
|
2020-10-28 16:08:37 +01:00
|
|
|
TbxCommandStreamReceiverHw<GfxFamily>::TbxCommandStreamReceiverHw(ExecutionEnvironment &executionEnvironment,
|
|
|
|
|
uint32_t rootDeviceIndex,
|
2020-10-29 15:33:35 +01:00
|
|
|
const DeviceBitfield deviceBitfield)
|
2020-10-28 16:08:37 +01:00
|
|
|
: BaseClass(executionEnvironment, rootDeviceIndex, deviceBitfield) {
|
2018-09-20 13:54:19 -07:00
|
|
|
|
2022-10-26 11:31:37 +00:00
|
|
|
forceSkipResourceCleanupRequired = true;
|
|
|
|
|
|
2024-03-05 15:43:36 +00:00
|
|
|
auto releaseHelper = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getReleaseHelper();
|
|
|
|
|
physicalAddressAllocator.reset(this->createPhysicalAddressAllocator(&this->peekHwInfo(), releaseHelper));
|
2019-11-15 09:59:48 +01:00
|
|
|
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->initAubCenter(this->localMemoryEnabled, "", this->getType());
|
|
|
|
|
auto aubCenter = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->aubCenter.get();
|
2018-12-19 13:15:14 +01:00
|
|
|
UNRECOVERABLE_IF(nullptr == aubCenter);
|
|
|
|
|
|
|
|
|
|
aubManager = aubCenter->getAubManager();
|
2018-09-20 13:54:19 -07:00
|
|
|
|
2018-09-27 15:08:57 +02:00
|
|
|
ppgtt = std::make_unique<std::conditional<is64bit, PML4, PDPE>::type>(physicalAddressAllocator.get());
|
2018-09-20 13:54:19 -07:00
|
|
|
ggtt = std::make_unique<PDPE>(physicalAddressAllocator.get());
|
|
|
|
|
|
2022-03-29 15:31:51 +00:00
|
|
|
this->downloadAllocationImpl = [this](GraphicsAllocation &graphicsAllocation) {
|
|
|
|
|
this->downloadAllocationTbx(graphicsAllocation);
|
|
|
|
|
};
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
TbxCommandStreamReceiverHw<GfxFamily>::~TbxCommandStreamReceiverHw() {
|
2022-03-29 15:31:51 +00:00
|
|
|
this->downloadAllocationImpl = nullptr;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-23 21:42:43 +00:00
|
|
|
template <typename GfxFamily>
|
|
|
|
|
bool TbxCommandStreamReceiverHw<GfxFamily>::isAllocTbxFaultable(GraphicsAllocation *gfxAlloc) {
|
|
|
|
|
// indicates host memory not managed by the driver
|
2025-03-18 20:46:23 +00:00
|
|
|
if ((gfxAlloc->getDriverAllocatedCpuPtr() == nullptr) ||
|
|
|
|
|
(debugManager.isTbxPageFaultManagerEnabled() == false) ||
|
|
|
|
|
(this->getTbxPageFaultManager() == nullptr)) {
|
2024-12-23 21:42:43 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
auto allocType = gfxAlloc->getAllocationType();
|
2025-03-11 23:44:27 +00:00
|
|
|
|
2025-05-21 23:55:55 +00:00
|
|
|
if (allocType == AllocationType::bufferHostMemory) {
|
2025-03-11 23:44:27 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2024-12-23 21:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::registerAllocationWithTbxFaultMngrIfTbxFaultable(GraphicsAllocation *gfxAlloc, void *cpuAddress, size_t size) {
|
|
|
|
|
if (!isAllocTbxFaultable(gfxAlloc)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto bank = this->getMemoryBank(gfxAlloc);
|
|
|
|
|
if (bank == 0u || gfxAlloc->storageInfo.cloningOfPageTables) {
|
|
|
|
|
bank = GraphicsAllocation::defaultBank;
|
|
|
|
|
}
|
|
|
|
|
auto faultManager = getTbxPageFaultManager();
|
|
|
|
|
faultManager->insertAllocation(this, gfxAlloc, bank, cpuAddress, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::allowCPUMemoryAccessIfTbxFaultable(GraphicsAllocation *gfxAlloc, void *cpuAddress, size_t size) {
|
|
|
|
|
if (!isAllocTbxFaultable(gfxAlloc)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto faultManager = getTbxPageFaultManager();
|
|
|
|
|
faultManager->allowCPUMemoryAccess(cpuAddress, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::protectCPUMemoryAccessIfTbxFaultable(GraphicsAllocation *gfxAlloc, void *cpuAddress, size_t size) {
|
|
|
|
|
if (!isAllocTbxFaultable(gfxAlloc)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto faultManager = getTbxPageFaultManager();
|
|
|
|
|
faultManager->protectCPUMemoryAccess(cpuAddress, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::protectCPUMemoryFromWritesIfTbxFaultable(GraphicsAllocation *gfxAlloc, void *cpuAddress, size_t size) {
|
|
|
|
|
if (!isAllocTbxFaultable(gfxAlloc)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto faultManager = getTbxPageFaultManager();
|
|
|
|
|
faultManager->protectCpuMemoryFromWrites(cpuAddress, size);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
template <typename GfxFamily>
|
2019-01-29 11:48:54 +01:00
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::initializeEngine() {
|
2025-09-15 15:35:18 +00:00
|
|
|
if (!isEngineInitialized) {
|
|
|
|
|
isEngineInitialized = true;
|
2021-10-14 11:47:16 +00:00
|
|
|
|
2025-09-15 15:35:18 +00:00
|
|
|
if (hardwareContextController) {
|
|
|
|
|
hardwareContextController->initialize();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-12-19 13:15:14 +01:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2020-10-29 15:33:35 +01:00
|
|
|
CommandStreamReceiver *TbxCommandStreamReceiverHw<GfxFamily>::create(const std::string &baseName,
|
|
|
|
|
bool withAubDump,
|
|
|
|
|
ExecutionEnvironment &executionEnvironment,
|
|
|
|
|
uint32_t rootDeviceIndex,
|
|
|
|
|
const DeviceBitfield deviceBitfield) {
|
2018-03-05 22:16:21 +01:00
|
|
|
TbxCommandStreamReceiverHw<GfxFamily> *csr;
|
2022-12-09 15:11:27 +00:00
|
|
|
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex];
|
|
|
|
|
auto &hwInfo = *rootDeviceEnvironment.getHardwareInfo();
|
|
|
|
|
auto &gfxCoreHelper = rootDeviceEnvironment.getHelper<GfxCoreHelper>();
|
2018-03-05 22:16:21 +01:00
|
|
|
if (withAubDump) {
|
2022-12-08 12:22:35 +00:00
|
|
|
auto localMemoryEnabled = gfxCoreHelper.getEnableLocalMemory(hwInfo);
|
2023-10-26 15:04:39 +02:00
|
|
|
auto fullName = AUBCommandStreamReceiver::createFullFilePath(hwInfo, baseName, rootDeviceIndex);
|
2023-11-30 08:32:25 +00:00
|
|
|
if (debugManager.flags.AUBDumpCaptureFileName.get() != "unk") {
|
|
|
|
|
fullName.assign(debugManager.flags.AUBDumpCaptureFileName.get());
|
2019-10-17 22:12:31 +02:00
|
|
|
}
|
2024-04-09 12:43:12 +00:00
|
|
|
rootDeviceEnvironment.initAubCenter(localMemoryEnabled, fullName, CommandStreamReceiverType::tbxWithAub);
|
2019-02-05 17:38:57 +01:00
|
|
|
|
2020-10-28 16:08:37 +01:00
|
|
|
csr = new CommandStreamReceiverWithAUBDump<TbxCommandStreamReceiverHw<GfxFamily>>(baseName, executionEnvironment, rootDeviceIndex, deviceBitfield);
|
2019-10-02 22:42:40 +02:00
|
|
|
|
2022-12-09 15:11:27 +00:00
|
|
|
auto aubCenter = rootDeviceEnvironment.aubCenter.get();
|
2019-10-02 22:42:40 +02:00
|
|
|
UNRECOVERABLE_IF(nullptr == aubCenter);
|
|
|
|
|
|
|
|
|
|
auto subCaptureCommon = aubCenter->getSubCaptureCommon();
|
|
|
|
|
UNRECOVERABLE_IF(nullptr == subCaptureCommon);
|
|
|
|
|
|
2023-12-19 10:17:17 +00:00
|
|
|
if (subCaptureCommon->subCaptureMode > AubSubCaptureManager::SubCaptureMode::off) {
|
2021-09-22 22:03:07 +00:00
|
|
|
csr->subCaptureManager = std::make_unique<AubSubCaptureManager>(fullName, *subCaptureCommon, ApiSpecificConfig::getRegistryPath());
|
2019-10-02 22:42:40 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-27 20:41:06 +01:00
|
|
|
if (csr->aubManager) {
|
|
|
|
|
if (!csr->aubManager->isOpen()) {
|
2020-10-14 19:22:01 +02:00
|
|
|
csr->aubManager->open(csr->subCaptureManager ? csr->subCaptureManager->getSubCaptureFileName("") : fullName);
|
2019-03-27 20:41:06 +01:00
|
|
|
UNRECOVERABLE_IF(!csr->aubManager->isOpen());
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-05 22:16:21 +01:00
|
|
|
} else {
|
2020-10-28 16:08:37 +01:00
|
|
|
csr = new TbxCommandStreamReceiverHw<GfxFamily>(executionEnvironment, rootDeviceIndex, deviceBitfield);
|
2018-03-05 22:16:21 +01:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
return csr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2022-01-07 14:53:31 +00:00
|
|
|
SubmissionStatus TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
|
2019-10-02 22:42:40 +02:00
|
|
|
if (subCaptureManager) {
|
|
|
|
|
if (aubManager) {
|
|
|
|
|
aubManager->pause(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 11:48:54 +01:00
|
|
|
initializeEngine();
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
// Write our batch buffer
|
|
|
|
|
auto pBatchBuffer = ptrOffset(batchBuffer.commandBufferAllocation->getUnderlyingBuffer(), batchBuffer.startOffset);
|
2018-12-19 13:15:14 +01:00
|
|
|
auto batchBufferGpuAddress = ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset);
|
2017-12-21 00:45:38 +01:00
|
|
|
auto currentOffset = batchBuffer.usedSize;
|
|
|
|
|
DEBUG_BREAK_IF(currentOffset < batchBuffer.startOffset);
|
|
|
|
|
auto sizeBatchBuffer = currentOffset - batchBuffer.startOffset;
|
2019-10-17 11:32:55 +02:00
|
|
|
auto overrideRingHead = false;
|
2018-12-19 13:15:14 +01:00
|
|
|
|
2019-07-01 10:11:07 +02:00
|
|
|
auto submissionTaskCount = this->taskCount + 1;
|
|
|
|
|
allocationsForResidency.push_back(batchBuffer.commandBufferAllocation);
|
|
|
|
|
batchBuffer.commandBufferAllocation->updateResidencyTaskCount(submissionTaskCount, this->osContext->getContextId());
|
|
|
|
|
batchBuffer.commandBufferAllocation->updateTaskCount(submissionTaskCount, osContext->getContextId());
|
2018-12-19 13:15:14 +01:00
|
|
|
|
|
|
|
|
// Write allocations for residency
|
2020-02-03 17:50:53 +01:00
|
|
|
processResidency(allocationsForResidency, 0u);
|
2018-12-19 13:15:14 +01:00
|
|
|
|
2019-10-17 11:32:55 +02:00
|
|
|
if (subCaptureManager) {
|
2019-10-02 22:42:40 +02:00
|
|
|
if (aubManager) {
|
2019-10-17 11:32:55 +02:00
|
|
|
auto status = subCaptureManager->getSubCaptureStatus();
|
|
|
|
|
if (!status.wasActiveInPreviousEnqueue && status.isActive) {
|
|
|
|
|
overrideRingHead = true;
|
|
|
|
|
}
|
|
|
|
|
if (!status.wasActiveInPreviousEnqueue && !status.isActive) {
|
|
|
|
|
aubManager->pause(true);
|
|
|
|
|
}
|
2019-10-02 22:42:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 15:24:14 +00:00
|
|
|
submitBatchBufferTbx(
|
2019-10-17 11:32:55 +02:00
|
|
|
batchBufferGpuAddress, pBatchBuffer, sizeBatchBuffer,
|
|
|
|
|
this->getMemoryBank(batchBuffer.commandBufferAllocation),
|
|
|
|
|
this->getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation),
|
|
|
|
|
overrideRingHead);
|
2019-10-02 22:42:40 +02:00
|
|
|
|
|
|
|
|
if (subCaptureManager) {
|
|
|
|
|
pollForCompletion();
|
|
|
|
|
subCaptureManager->disableSubCapture();
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-13 09:17:24 +00:00
|
|
|
return SubmissionStatus::success;
|
2018-12-19 13:15:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2021-06-21 15:24:14 +00:00
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::submitBatchBufferTbx(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits, bool overrideRingHead) {
|
2025-05-27 11:55:16 +00:00
|
|
|
if (hardwareContextController && batchBufferSize) {
|
|
|
|
|
hardwareContextController->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, MemoryConstants::pageSize64k, overrideRingHead);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2024-11-20 12:36:45 +00:00
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::pollForCompletion(bool skipTaskCountCheck) {
|
2019-02-07 13:21:58 +01:00
|
|
|
if (hardwareContextController) {
|
|
|
|
|
hardwareContextController->pollForCompletion();
|
2018-12-19 13:15:14 +01:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2018-12-19 13:15:14 +01:00
|
|
|
template <typename GfxFamily>
|
2019-02-15 11:31:47 +01:00
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits) {
|
2021-10-14 11:47:16 +00:00
|
|
|
UNRECOVERABLE_IF(!isEngineInitialized);
|
2018-12-19 13:15:14 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
template <typename GfxFamily>
|
2023-10-18 13:54:46 +00:00
|
|
|
bool TbxCommandStreamReceiverHw<GfxFamily>::writeMemory(GraphicsAllocation &gfxAllocation, bool isChunkCopy, uint64_t gpuVaChunkOffset, size_t chunkSize) {
|
2024-12-23 21:42:43 +00:00
|
|
|
uint64_t gpuAddress;
|
|
|
|
|
void *cpuAddress;
|
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
|
|
if (!this->getParametersForMemory(gfxAllocation, gpuAddress, cpuAddress, size)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto allocType = gfxAllocation.getAllocationType();
|
|
|
|
|
this->registerAllocationWithTbxFaultMngrIfTbxFaultable(&gfxAllocation, cpuAddress, size);
|
|
|
|
|
|
2024-12-03 00:28:34 +00:00
|
|
|
if (!this->isTbxWritable(gfxAllocation)) {
|
2018-03-05 22:16:21 +01:00
|
|
|
return false;
|
2019-02-06 13:32:49 +01:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2025-03-11 23:44:27 +00:00
|
|
|
this->protectCPUMemoryFromWritesIfTbxFaultable(&gfxAllocation, cpuAddress, size);
|
2024-12-23 21:42:43 +00:00
|
|
|
|
2025-09-15 15:35:18 +00:00
|
|
|
initializeEngine();
|
2024-12-03 00:28:34 +00:00
|
|
|
|
2019-02-06 13:32:49 +01:00
|
|
|
if (aubManager) {
|
2023-10-18 13:54:46 +00:00
|
|
|
this->writeMemoryWithAubManager(gfxAllocation, isChunkCopy, gpuVaChunkOffset, chunkSize);
|
2019-02-06 13:32:49 +01:00
|
|
|
} else {
|
2023-10-18 13:54:46 +00:00
|
|
|
if (isChunkCopy) {
|
|
|
|
|
gpuAddress += gpuVaChunkOffset;
|
2023-10-23 12:34:38 +00:00
|
|
|
cpuAddress = ptrOffset(cpuAddress, static_cast<uintptr_t>(gpuVaChunkOffset));
|
2023-10-18 13:54:46 +00:00
|
|
|
size = chunkSize;
|
|
|
|
|
}
|
2019-02-15 11:31:47 +01:00
|
|
|
writeMemory(gpuAddress, cpuAddress, size, this->getMemoryBank(&gfxAllocation), this->getPPGTTAdditionalBits(&gfxAllocation));
|
2019-02-06 13:32:49 +01:00
|
|
|
}
|
2018-09-14 05:31:37 -07:00
|
|
|
|
2024-12-23 21:42:43 +00:00
|
|
|
if (AubHelper::isOneTimeAubWritableAllocationType(allocType)) {
|
2019-08-06 18:01:26 +02:00
|
|
|
this->setTbxWritable(false, gfxAllocation);
|
2019-04-16 15:32:15 +02:00
|
|
|
}
|
2024-12-23 21:42:43 +00:00
|
|
|
this->protectCPUMemoryAccessIfTbxFaultable(&gfxAllocation, cpuAddress, size);
|
2019-04-16 15:32:15 +02:00
|
|
|
|
2018-03-05 22:16:21 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2021-02-22 12:02:08 +00:00
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::writeMMIO(uint32_t offset, uint32_t value) {
|
|
|
|
|
if (hardwareContextController) {
|
|
|
|
|
hardwareContextController->writeMMIO(offset, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 21:01:39 +02:00
|
|
|
template <typename GfxFamily>
|
|
|
|
|
bool TbxCommandStreamReceiverHw<GfxFamily>::expectMemory(const void *gfxAddress, const void *srcAddress,
|
|
|
|
|
size_t length, uint32_t compareOperation) {
|
|
|
|
|
if (hardwareContextController) {
|
|
|
|
|
auto readMemory = std::make_unique<char[]>(length);
|
2022-12-28 23:30:03 +00:00
|
|
|
// note: memory bank should not matter assuming that we call expect on the memory that was previously allocated
|
2020-04-01 21:01:39 +02:00
|
|
|
hardwareContextController->readMemory((uint64_t)gfxAddress, readMemory.get(), length, this->getMemoryBankForGtt(), MemoryConstants::pageSize64k);
|
|
|
|
|
auto isMemoryEqual = (memcmp(readMemory.get(), srcAddress, length) == 0);
|
2025-10-13 13:40:44 +00:00
|
|
|
auto isEqualMemoryExpected = (compareOperation == aub_stream::CompareOperationValues::CompareEqual);
|
2020-04-01 21:01:39 +02:00
|
|
|
return (isMemoryEqual == isEqualMemoryExpected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BaseClass::expectMemory(gfxAddress, srcAddress, length, compareOperation);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-16 16:23:08 +00:00
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::writePooledMemory(SharedPoolAllocation &sharedPoolAllocation, bool initFullPageTables) {
|
|
|
|
|
auto &gfxAllocation = *sharedPoolAllocation.getGraphicsAllocation();
|
|
|
|
|
|
|
|
|
|
auto writeMemoryOperation = [&]() {
|
|
|
|
|
constexpr uint32_t allBanks = std::numeric_limits<uint32_t>::max();
|
|
|
|
|
if (initFullPageTables && gfxAllocation.isTbxWritable(allBanks)) {
|
|
|
|
|
writeMemory(gfxAllocation, false, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gfxAllocation.setTbxWritable(true, allBanks);
|
|
|
|
|
[[maybe_unused]] const auto writeMemoryStatus = writeMemory(gfxAllocation, true, sharedPoolAllocation.getOffset(), sharedPoolAllocation.getSize());
|
|
|
|
|
DEBUG_BREAK_IF(!writeMemoryStatus);
|
|
|
|
|
gfxAllocation.setTbxWritable(false, allBanks);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (auto mutex = sharedPoolAllocation.getMutex(); mutex) {
|
|
|
|
|
std::lock_guard<std::mutex> lock(*mutex);
|
|
|
|
|
writeMemoryOperation();
|
|
|
|
|
} else {
|
|
|
|
|
writeMemoryOperation();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-18 12:37:57 +02:00
|
|
|
template <typename GfxFamily>
|
2024-08-06 12:54:11 +00:00
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::flushSubmissionsAndDownloadAllocations(TaskCountType taskCountToWait, bool skipAllocationsDownload) {
|
2019-04-18 12:37:57 +02:00
|
|
|
this->flushBatchedSubmissions();
|
|
|
|
|
|
2021-11-24 11:27:50 +00:00
|
|
|
if (this->latestFlushedTaskCount < taskCountToWait) {
|
|
|
|
|
this->flushTagUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 13:53:59 +00:00
|
|
|
volatile TagAddressType *pollAddress = this->getTagAddress();
|
2021-09-23 18:13:37 +00:00
|
|
|
for (uint32_t i = 0; i < this->activePartitions; i++) {
|
|
|
|
|
while (*pollAddress < this->latestFlushedTaskCount) {
|
2022-03-29 15:31:51 +00:00
|
|
|
this->downloadAllocation(*this->getTagAllocation());
|
2021-09-23 18:13:37 +00:00
|
|
|
}
|
2023-06-06 15:11:09 +00:00
|
|
|
pollAddress = ptrOffset(pollAddress, this->immWritePostSyncWriteOffset);
|
2019-04-18 12:37:57 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-06 12:54:11 +00:00
|
|
|
if (skipAllocationsDownload) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-15 14:57:50 +00:00
|
|
|
auto lockCSR = this->obtainUniqueOwnership();
|
2019-04-18 12:37:57 +02:00
|
|
|
for (GraphicsAllocation *graphicsAllocation : this->allocationsForDownload) {
|
2022-03-29 15:31:51 +00:00
|
|
|
this->downloadAllocation(*graphicsAllocation);
|
2019-04-18 12:37:57 +02:00
|
|
|
}
|
|
|
|
|
this->allocationsForDownload.clear();
|
2020-05-06 11:52:48 +02:00
|
|
|
}
|
2019-04-18 12:37:57 +02:00
|
|
|
|
2020-05-06 11:52:48 +02:00
|
|
|
template <typename GfxFamily>
|
2022-11-22 13:53:59 +00:00
|
|
|
WaitStatus TbxCommandStreamReceiverHw<GfxFamily>::waitForTaskCountWithKmdNotifyFallback(TaskCountType taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep, QueueThrottle throttle) {
|
2024-08-06 12:54:11 +00:00
|
|
|
flushSubmissionsAndDownloadAllocations(taskCountToWait, false);
|
2022-03-23 14:36:07 +00:00
|
|
|
return BaseClass::waitForTaskCountWithKmdNotifyFallback(taskCountToWait, flushStampToWait, useQuickKmdSleep, throttle);
|
2019-04-18 12:37:57 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-06 11:52:48 +02:00
|
|
|
template <typename GfxFamily>
|
2022-11-22 13:53:59 +00:00
|
|
|
WaitStatus TbxCommandStreamReceiverHw<GfxFamily>::waitForCompletionWithTimeout(const WaitParams ¶ms, TaskCountType taskCountToWait) {
|
2024-08-06 12:54:11 +00:00
|
|
|
flushSubmissionsAndDownloadAllocations(taskCountToWait, params.skipTbxDownload);
|
2022-03-23 14:36:07 +00:00
|
|
|
return BaseClass::waitForCompletionWithTimeout(params, taskCountToWait);
|
2020-05-06 11:52:48 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-18 12:37:57 +02:00
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::processEviction() {
|
2025-09-17 18:02:28 +00:00
|
|
|
auto lockCSR = this->obtainUniqueOwnership();
|
2019-04-18 12:37:57 +02:00
|
|
|
BaseClass::processEviction();
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-10 13:48:47 +00:00
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::makeNonResident(GraphicsAllocation &gfxAllocation) {
|
2025-10-13 12:47:09 +00:00
|
|
|
auto lock = this->obtainUniqueOwnership();
|
2025-10-10 13:48:47 +00:00
|
|
|
if (gfxAllocation.isResident(osContext->getContextId())) {
|
|
|
|
|
this->allocationsForDownload.insert(&gfxAllocation);
|
|
|
|
|
}
|
|
|
|
|
BaseClass::makeNonResident(gfxAllocation);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-05 22:16:21 +01:00
|
|
|
template <typename GfxFamily>
|
2024-08-22 10:25:49 +00:00
|
|
|
SubmissionStatus TbxCommandStreamReceiverHw<GfxFamily>::processResidency(ResidencyContainer &allocationsForResidency, uint32_t handleId) {
|
2024-12-23 21:42:43 +00:00
|
|
|
|
2018-09-14 10:39:21 +02:00
|
|
|
for (auto &gfxAllocation : allocationsForResidency) {
|
2019-10-02 22:42:40 +02:00
|
|
|
if (dumpTbxNonWritable) {
|
|
|
|
|
this->setTbxWritable(true, *gfxAllocation);
|
|
|
|
|
}
|
2018-03-05 22:16:21 +01:00
|
|
|
if (!writeMemory(*gfxAllocation)) {
|
2019-08-06 18:01:26 +02:00
|
|
|
DEBUG_BREAK_IF(!((gfxAllocation->getUnderlyingBufferSize() == 0) ||
|
|
|
|
|
!this->isTbxWritable(*gfxAllocation)));
|
2018-03-05 22:16:21 +01:00
|
|
|
}
|
2018-12-03 10:05:36 +01:00
|
|
|
gfxAllocation->updateResidencyTaskCount(this->taskCount + 1, this->osContext->getContextId());
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
2019-10-02 22:42:40 +02:00
|
|
|
|
2024-06-14 14:15:14 +00:00
|
|
|
if (this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface) {
|
|
|
|
|
this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface->processFlushResidency(this);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-02 22:42:40 +02:00
|
|
|
dumpTbxNonWritable = false;
|
2023-12-13 09:17:24 +00:00
|
|
|
return SubmissionStatus::success;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2022-03-29 15:31:51 +00:00
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::downloadAllocationTbx(GraphicsAllocation &gfxAllocation) {
|
2024-12-23 21:42:43 +00:00
|
|
|
|
2023-07-26 16:03:49 +00:00
|
|
|
uint64_t gpuAddress = 0;
|
|
|
|
|
void *cpuAddress = nullptr;
|
|
|
|
|
size_t size = 0;
|
|
|
|
|
|
|
|
|
|
this->getParametersForMemory(gfxAllocation, gpuAddress, cpuAddress, size);
|
|
|
|
|
|
2024-12-23 21:42:43 +00:00
|
|
|
this->allowCPUMemoryAccessIfTbxFaultable(&gfxAllocation, cpuAddress, size);
|
|
|
|
|
|
2019-02-07 13:21:58 +01:00
|
|
|
if (hardwareContextController) {
|
2023-07-26 16:03:49 +00:00
|
|
|
hardwareContextController->readMemory(gpuAddress, cpuAddress, size,
|
2023-08-29 13:01:36 +00:00
|
|
|
this->getMemoryBank(&gfxAllocation), gfxAllocation.getUsedPageSize());
|
2024-12-23 21:42:43 +00:00
|
|
|
this->protectCPUMemoryFromWritesIfTbxFaultable(&gfxAllocation, cpuAddress, size);
|
2018-12-19 13:15:14 +01:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
2018-05-09 15:25:01 +02:00
|
|
|
|
2020-05-13 11:25:29 +02:00
|
|
|
template <typename GfxFamily>
|
2024-08-28 13:59:25 +00:00
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::downloadAllocations(bool blockingWait, TaskCountType taskCount) {
|
2022-11-22 13:53:59 +00:00
|
|
|
volatile TagAddressType *pollAddress = this->getTagAddress();
|
2024-08-28 13:59:25 +00:00
|
|
|
|
|
|
|
|
auto waitTaskCount = std::min(taskCount, this->latestFlushedTaskCount.load());
|
2024-08-22 14:04:53 +00:00
|
|
|
|
2021-09-23 18:13:37 +00:00
|
|
|
for (uint32_t i = 0; i < this->activePartitions; i++) {
|
2024-08-28 13:59:25 +00:00
|
|
|
if (*pollAddress < waitTaskCount) {
|
2022-03-29 15:31:51 +00:00
|
|
|
this->downloadAllocation(*this->getTagAllocation());
|
2024-08-28 13:59:25 +00:00
|
|
|
|
|
|
|
|
auto startTime = std::chrono::high_resolution_clock::now();
|
|
|
|
|
uint64_t timeDiff = 0;
|
|
|
|
|
|
|
|
|
|
while (*pollAddress < waitTaskCount) {
|
|
|
|
|
if (!blockingWait) {
|
|
|
|
|
// Additional delay to reach PC in case of Event wait
|
|
|
|
|
timeDiff = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime).count();
|
2024-09-09 15:31:32 +00:00
|
|
|
if (timeDiff > getNonBlockingDownloadTimeoutMs()) {
|
2024-08-28 13:59:25 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this->downloadAllocation(*this->getTagAllocation());
|
|
|
|
|
}
|
2021-09-23 18:13:37 +00:00
|
|
|
}
|
2024-08-28 13:59:25 +00:00
|
|
|
|
2023-06-06 15:11:09 +00:00
|
|
|
pollAddress = ptrOffset(pollAddress, this->immWritePostSyncWriteOffset);
|
2020-05-27 12:11:20 +02:00
|
|
|
}
|
2022-02-15 14:57:50 +00:00
|
|
|
auto lockCSR = this->obtainUniqueOwnership();
|
2024-08-22 14:04:53 +00:00
|
|
|
|
|
|
|
|
std::vector<GraphicsAllocation *> notReadyAllocations;
|
|
|
|
|
|
2020-05-13 11:25:29 +02:00
|
|
|
for (GraphicsAllocation *graphicsAllocation : this->allocationsForDownload) {
|
2022-03-29 15:31:51 +00:00
|
|
|
this->downloadAllocation(*graphicsAllocation);
|
2024-08-22 14:04:53 +00:00
|
|
|
|
|
|
|
|
// Used again while waiting for completion. Another download will be needed.
|
2024-08-28 13:59:25 +00:00
|
|
|
if (graphicsAllocation->getTaskCount(this->osContext->getContextId()) > taskCount) {
|
2024-08-22 14:04:53 +00:00
|
|
|
notReadyAllocations.push_back(graphicsAllocation);
|
|
|
|
|
}
|
2020-05-13 11:25:29 +02:00
|
|
|
}
|
2020-05-22 15:28:11 +02:00
|
|
|
this->allocationsForDownload.clear();
|
2024-08-22 14:04:53 +00:00
|
|
|
this->allocationsForDownload = std::set<GraphicsAllocation *>(notReadyAllocations.begin(), notReadyAllocations.end());
|
2020-05-13 11:25:29 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-05 14:53:38 +01:00
|
|
|
template <typename GfxFamily>
|
|
|
|
|
uint32_t TbxCommandStreamReceiverHw<GfxFamily>::getMaskAndValueForPollForCompletion() const {
|
|
|
|
|
return 0x100;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
bool TbxCommandStreamReceiverHw<GfxFamily>::getpollNotEqualValueForPollForCompletion() const {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-10-02 22:42:40 +02:00
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2021-09-22 19:25:21 +00:00
|
|
|
AubSubCaptureStatus TbxCommandStreamReceiverHw<GfxFamily>::checkAndActivateAubSubCapture(const std::string &kernelName) {
|
2019-10-02 22:42:40 +02:00
|
|
|
if (!subCaptureManager) {
|
|
|
|
|
return {false, false};
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 19:22:01 +02:00
|
|
|
auto status = subCaptureManager->checkAndActivateSubCapture(kernelName);
|
2019-10-02 22:42:40 +02:00
|
|
|
if (status.isActive && !status.wasActiveInPreviousEnqueue) {
|
|
|
|
|
dumpTbxNonWritable = true;
|
|
|
|
|
}
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2020-04-15 15:30:29 +02:00
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::dumpAllocation(GraphicsAllocation &gfxAllocation) {
|
|
|
|
|
if (!hardwareContextController) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 16:04:01 +02:00
|
|
|
bool isBcsCsr = EngineHelpers::isBcs(this->osContext->getEngineType());
|
|
|
|
|
|
|
|
|
|
if (isBcsCsr != gfxAllocation.getAubInfo().bcsDumpOnly) {
|
2020-04-15 15:30:29 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 08:32:25 +00:00
|
|
|
if (debugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.get() || debugManager.flags.AUBDumpAllocsOnEnqueueSVMMemcpyOnly.get()) {
|
2020-04-15 15:30:29 +02:00
|
|
|
if (!gfxAllocation.isAllocDumpable()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-07-10 16:04:01 +02:00
|
|
|
gfxAllocation.setAllocDumpable(false, isBcsCsr);
|
2020-04-15 15:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto dumpFormat = AubAllocDump::getDumpFormat(gfxAllocation);
|
2023-07-03 09:44:27 +00:00
|
|
|
auto surfaceInfo = std::unique_ptr<aub_stream::SurfaceInfo>(AubAllocDump::getDumpSurfaceInfo<GfxFamily>(gfxAllocation, *this->peekGmmHelper(), dumpFormat));
|
2020-04-15 15:30:29 +02:00
|
|
|
if (surfaceInfo) {
|
|
|
|
|
hardwareContextController->pollForCompletion();
|
|
|
|
|
hardwareContextController->dumpSurface(*surfaceInfo.get());
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-31 15:44:14 +00:00
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
|
void TbxCommandStreamReceiverHw<GfxFamily>::removeDownloadAllocation(GraphicsAllocation *alloc) {
|
|
|
|
|
auto lockCSR = this->obtainUniqueOwnership();
|
2024-12-23 21:42:43 +00:00
|
|
|
|
2023-10-31 15:44:14 +00:00
|
|
|
this->allocationsForDownload.erase(alloc);
|
2024-12-23 21:42:43 +00:00
|
|
|
|
|
|
|
|
auto faultManager = getTbxPageFaultManager();
|
|
|
|
|
if (faultManager != nullptr) {
|
|
|
|
|
faultManager->removeAllocation(alloc);
|
|
|
|
|
}
|
2023-10-31 15:44:14 +00:00
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|