2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2024-01-18 22:21:34 +08:00
|
|
|
* Copyright (C) 2018-2024 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-20 11:54:29 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 20:10:44 +08:00
|
|
|
#include "shared/source/built_ins/built_ins.h"
|
2021-08-03 19:42:37 +08:00
|
|
|
#include "shared/source/command_container/implicit_scaling.h"
|
2023-01-18 01:04:14 +08:00
|
|
|
#include "shared/source/command_stream/aub_subcapture_status.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/experimental_command_buffer.h"
|
|
|
|
#include "shared/source/command_stream/preemption.h"
|
|
|
|
#include "shared/source/command_stream/scratch_space_controller.h"
|
2022-12-22 19:31:28 +08:00
|
|
|
#include "shared/source/command_stream/submission_status.h"
|
2023-01-18 01:04:14 +08:00
|
|
|
#include "shared/source/command_stream/submissions_aggregator.h"
|
2022-12-06 15:32:34 +08:00
|
|
|
#include "shared/source/command_stream/tag_allocation_layout.h"
|
2022-03-09 20:36:51 +08:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/device/device.h"
|
2021-10-29 19:54:52 +08:00
|
|
|
#include "shared/source/direct_submission/direct_submission_controller.h"
|
2022-12-29 20:27:52 +08:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2022-06-27 22:58:29 +08:00
|
|
|
#include "shared/source/gmm_helper/cache_settings_helper.h"
|
2021-09-29 23:59:41 +08:00
|
|
|
#include "shared/source/gmm_helper/page_table_mngr.h"
|
2021-12-04 01:48:12 +08:00
|
|
|
#include "shared/source/helpers/api_specific_config.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/array_count.h"
|
2023-11-23 21:58:58 +08:00
|
|
|
#include "shared/source/helpers/compiler_product_helper.h"
|
2023-01-18 01:04:14 +08:00
|
|
|
#include "shared/source/helpers/flat_batch_buffer_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/flush_stamp.h"
|
2023-02-02 00:23:01 +08:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2021-02-06 22:38:55 +08:00
|
|
|
#include "shared/source/helpers/pause_on_gpu_properties.h"
|
2022-04-25 22:54:13 +08:00
|
|
|
#include "shared/source/helpers/ray_tracing_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/string.h"
|
|
|
|
#include "shared/source/helpers/timestamp_packet.h"
|
2022-12-07 19:51:44 +08:00
|
|
|
#include "shared/source/memory_manager/allocation_properties.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/internal_allocation_storage.h"
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
|
|
|
#include "shared/source/memory_manager/surface.h"
|
|
|
|
#include "shared/source/os_interface/os_context.h"
|
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2022-12-22 19:31:28 +08:00
|
|
|
#include "shared/source/os_interface/os_thread.h"
|
2023-03-10 20:28:11 +08:00
|
|
|
#include "shared/source/os_interface/product_helper.h"
|
2022-02-12 00:28:08 +08:00
|
|
|
#include "shared/source/os_interface/sys_calls_common.h"
|
2022-07-24 12:21:16 +08:00
|
|
|
#include "shared/source/utilities/hw_timestamps.h"
|
|
|
|
#include "shared/source/utilities/perf_counter.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/utilities/tag_allocator.h"
|
2021-03-31 02:11:00 +08:00
|
|
|
#include "shared/source/utilities/wait_util.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2023-01-18 01:04:14 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2022-12-02 03:42:57 +08:00
|
|
|
namespace AubMemDump {
|
|
|
|
#include "aub_services.h"
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2020-02-19 23:32:40 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
// Global table of CommandStreamReceiver factories for HW and tests
|
|
|
|
CommandStreamReceiverCreateFunc commandStreamReceiverFactory[2 * IGFX_MAX_CORE] = {};
|
|
|
|
|
2020-10-29 22:33:35 +08:00
|
|
|
CommandStreamReceiver::CommandStreamReceiver(ExecutionEnvironment &executionEnvironment,
|
|
|
|
uint32_t rootDeviceIndex,
|
|
|
|
const DeviceBitfield deviceBitfield)
|
2020-10-28 23:08:37 +08:00
|
|
|
: executionEnvironment(executionEnvironment), rootDeviceIndex(rootDeviceIndex), deviceBitfield(deviceBitfield) {
|
2022-04-06 21:59:23 +08:00
|
|
|
residencyAllocations.reserve(startingResidencyContainerSize);
|
2018-09-13 21:49:38 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
latestSentStatelessMocsConfig = CacheSettings::unknownMocs;
|
|
|
|
submissionAggregator.reset(new SubmissionAggregator());
|
2022-01-21 05:20:56 +08:00
|
|
|
if (ApiSpecificConfig::getApiType() == ApiSpecificConfig::L0) {
|
2023-12-13 17:17:24 +08:00
|
|
|
this->dispatchMode = DispatchMode::immediateDispatch;
|
2022-01-21 05:20:56 +08:00
|
|
|
}
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.CsrDispatchMode.get()) {
|
|
|
|
this->dispatchMode = (DispatchMode)debugManager.flags.CsrDispatchMode.get();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
flushStamp.reset(new FlushStampTracker(true));
|
2023-12-14 00:09:52 +08:00
|
|
|
for (int i = 0; i < IndirectHeap::Type::numTypes; ++i) {
|
2018-04-26 16:01:01 +08:00
|
|
|
indirectHeap[i] = nullptr;
|
|
|
|
}
|
2018-10-22 21:17:32 +08:00
|
|
|
internalAllocationStorage = std::make_unique<InternalAllocationStorage>(*this);
|
2022-01-12 03:41:57 +08:00
|
|
|
const auto &hwInfo = peekHwInfo();
|
2021-11-18 03:51:43 +08:00
|
|
|
uint32_t subDeviceCount = static_cast<uint32_t>(deviceBitfield.count());
|
2022-12-09 22:37:32 +08:00
|
|
|
auto &gfxCoreHelper = getGfxCoreHelper();
|
2023-01-30 08:09:45 +08:00
|
|
|
auto &rootDeviceEnvironment = peekRootDeviceEnvironment();
|
|
|
|
bool platformImplicitScaling = gfxCoreHelper.platformSupportsImplicitScaling(rootDeviceEnvironment);
|
2022-01-12 03:41:57 +08:00
|
|
|
if (NEO::ImplicitScalingHelper::isImplicitScalingEnabled(deviceBitfield, platformImplicitScaling) &&
|
2021-11-18 03:51:43 +08:00
|
|
|
subDeviceCount > 1 &&
|
2023-11-30 16:32:25 +08:00
|
|
|
debugManager.flags.EnableStaticPartitioning.get() != 0) {
|
2021-11-18 03:51:43 +08:00
|
|
|
this->activePartitions = subDeviceCount;
|
2021-02-17 01:04:00 +08:00
|
|
|
this->staticWorkPartitioningEnabled = true;
|
|
|
|
}
|
2023-03-10 07:12:09 +08:00
|
|
|
this->streamProperties.initSupport(rootDeviceEnvironment);
|
2022-12-15 20:13:57 +08:00
|
|
|
auto &productHelper = getProductHelper();
|
|
|
|
productHelper.fillFrontEndPropertiesSupportStructure(feSupportFlags, hwInfo);
|
|
|
|
productHelper.fillPipelineSelectPropertiesSupportStructure(pipelineSupportFlags, hwInfo);
|
2023-02-03 02:57:24 +08:00
|
|
|
productHelper.fillStateBaseAddressPropertiesSupportStructure(sbaSupportFlags);
|
2023-02-23 05:30:40 +08:00
|
|
|
this->doubleSbaWa = productHelper.isAdditionalStateBaseAddressWARequired(hwInfo);
|
2023-02-25 00:55:21 +08:00
|
|
|
this->l1CachePolicyData.init(productHelper);
|
2023-09-25 15:58:39 +08:00
|
|
|
|
|
|
|
registeredClients.reserve(16);
|
2023-11-23 21:58:58 +08:00
|
|
|
|
|
|
|
auto &compilerProductHelper = rootDeviceEnvironment.getHelper<CompilerProductHelper>();
|
|
|
|
this->heaplessModeEnabled = compilerProductHelper.isHeaplessModeEnabled();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CommandStreamReceiver::~CommandStreamReceiver() {
|
2020-06-17 17:31:08 +08:00
|
|
|
if (userPauseConfirmation) {
|
2020-11-06 20:01:29 +08:00
|
|
|
{
|
|
|
|
std::unique_lock<SpinLock> lock{debugPauseStateLock};
|
|
|
|
*debugPauseStateAddress = DebugPauseState::terminate;
|
|
|
|
}
|
|
|
|
|
2020-06-17 17:31:08 +08:00
|
|
|
userPauseConfirmation->join();
|
2020-04-30 23:12:01 +08:00
|
|
|
}
|
|
|
|
|
2023-12-14 00:09:52 +08:00
|
|
|
for (int i = 0; i < IndirectHeap::Type::numTypes; ++i) {
|
2018-04-26 16:01:01 +08:00
|
|
|
if (indirectHeap[i] != nullptr) {
|
|
|
|
auto allocation = indirectHeap[i]->getGraphicsAllocation();
|
|
|
|
if (allocation != nullptr) {
|
2018-10-24 20:25:04 +08:00
|
|
|
internalAllocationStorage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
|
2018-04-26 16:01:01 +08:00
|
|
|
}
|
|
|
|
delete indirectHeap[i];
|
|
|
|
}
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
cleanupResources();
|
2018-10-09 17:50:58 +08:00
|
|
|
|
2018-10-29 20:26:58 +08:00
|
|
|
internalAllocationStorage->cleanAllocationList(-1, REUSABLE_ALLOCATION);
|
|
|
|
internalAllocationStorage->cleanAllocationList(-1, TEMPORARY_ALLOCATION);
|
2023-10-28 00:43:33 +08:00
|
|
|
internalAllocationStorage->cleanAllocationList(-1, DEFERRED_DEALLOCATION);
|
2019-09-02 19:23:25 +08:00
|
|
|
getMemoryManager()->unregisterEngineForCsr(this);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-01-07 22:53:31 +08:00
|
|
|
SubmissionStatus CommandStreamReceiver::submitBatchBuffer(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
|
2020-02-18 20:51:01 +08:00
|
|
|
this->latestSentTaskCount = taskCount + 1;
|
|
|
|
|
2022-01-07 22:53:31 +08:00
|
|
|
SubmissionStatus retVal = this->flush(batchBuffer, allocationsForResidency);
|
2022-05-27 11:58:07 +08:00
|
|
|
|
2023-12-13 17:17:24 +08:00
|
|
|
if (retVal != NEO::SubmissionStatus::success) {
|
2022-05-27 11:58:07 +08:00
|
|
|
return retVal;
|
|
|
|
}
|
2021-10-28 17:21:44 +08:00
|
|
|
if (!isUpdateTagFromWaitEnabled()) {
|
|
|
|
this->latestFlushedTaskCount = taskCount + 1;
|
|
|
|
}
|
2020-02-18 20:51:01 +08:00
|
|
|
taskCount++;
|
|
|
|
|
2022-01-07 22:53:31 +08:00
|
|
|
return retVal;
|
2020-02-18 20:51:01 +08:00
|
|
|
}
|
|
|
|
|
2021-05-15 00:46:50 +08:00
|
|
|
void CommandStreamReceiver::makeResident(MultiGraphicsAllocation &gfxAllocation) {
|
|
|
|
makeResident(*gfxAllocation.getGraphicsAllocation(rootDeviceIndex));
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void CommandStreamReceiver::makeResident(GraphicsAllocation &gfxAllocation) {
|
2018-11-07 16:33:55 +08:00
|
|
|
auto submissionTaskCount = this->taskCount + 1;
|
2018-12-18 21:02:08 +08:00
|
|
|
if (gfxAllocation.isResidencyTaskCountBelow(submissionTaskCount, osContext->getContextId())) {
|
2022-02-08 20:14:24 +08:00
|
|
|
auto pushAllocations = true;
|
|
|
|
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.MakeEachAllocationResident.get() != -1) {
|
|
|
|
pushAllocations = !debugManager.flags.MakeEachAllocationResident.get();
|
2022-02-08 20:14:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pushAllocations) {
|
|
|
|
this->getResidencyAllocations().push_back(&gfxAllocation);
|
|
|
|
}
|
|
|
|
|
2018-12-03 17:05:36 +08:00
|
|
|
gfxAllocation.updateTaskCount(submissionTaskCount, osContext->getContextId());
|
2023-12-13 17:17:24 +08:00
|
|
|
if (this->dispatchMode == DispatchMode::batchedDispatch) {
|
2022-10-11 02:57:10 +08:00
|
|
|
checkForNewResources(submissionTaskCount, gfxAllocation.getTaskCount(osContext->getContextId()), gfxAllocation);
|
|
|
|
if (!gfxAllocation.isResident(osContext->getContextId())) {
|
|
|
|
this->totalMemoryUsed += gfxAllocation.getUnderlyingBufferSize();
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
2018-12-03 17:05:36 +08:00
|
|
|
gfxAllocation.updateResidencyTaskCount(submissionTaskCount, osContext->getContextId());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-11-26 21:04:52 +08:00
|
|
|
void CommandStreamReceiver::processEviction() {
|
2018-09-14 19:48:02 +08:00
|
|
|
this->getEvictionAllocations().clear();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandStreamReceiver::makeNonResident(GraphicsAllocation &gfxAllocation) {
|
2018-12-03 17:05:36 +08:00
|
|
|
if (gfxAllocation.isResident(osContext->getContextId())) {
|
2018-04-12 16:05:35 +08:00
|
|
|
if (gfxAllocation.peekEvictable()) {
|
2018-09-14 19:48:02 +08:00
|
|
|
this->getEvictionAllocations().push_back(&gfxAllocation);
|
2018-04-12 16:05:35 +08:00
|
|
|
} else {
|
|
|
|
gfxAllocation.setEvictable(true);
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-01-25 21:24:45 +08:00
|
|
|
if (!gfxAllocation.isAlwaysResident(this->osContext->getContextId())) {
|
|
|
|
gfxAllocation.releaseResidencyInOsContext(this->osContext->getContextId());
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-05-27 11:58:07 +08:00
|
|
|
void CommandStreamReceiver::makeSurfacePackNonResident(ResidencyContainer &allocationsForResidency, bool clearAllocations) {
|
2018-09-25 19:13:14 +08:00
|
|
|
for (auto &surface : allocationsForResidency) {
|
2017-12-21 07:45:38 +08:00
|
|
|
this->makeNonResident(*surface);
|
|
|
|
}
|
2022-05-27 11:58:07 +08:00
|
|
|
if (clearAllocations) {
|
|
|
|
allocationsForResidency.clear();
|
|
|
|
}
|
2018-11-26 21:04:52 +08:00
|
|
|
this->processEviction();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-12-22 19:31:28 +08:00
|
|
|
SubmissionStatus CommandStreamReceiver::processResidency(const ResidencyContainer &allocationsForResidency, uint32_t handleId) {
|
2023-12-13 17:17:24 +08:00
|
|
|
return SubmissionStatus::success;
|
2022-12-22 19:31:28 +08:00
|
|
|
}
|
|
|
|
|
2018-02-09 05:52:58 +08:00
|
|
|
void CommandStreamReceiver::makeResidentHostPtrAllocation(GraphicsAllocation *gfxAllocation) {
|
|
|
|
makeResident(*gfxAllocation);
|
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
WaitStatus CommandStreamReceiver::waitForTaskCount(TaskCountType requiredTaskCount) {
|
2021-10-20 03:28:05 +08:00
|
|
|
auto address = getTagAddress();
|
2022-05-17 23:23:15 +08:00
|
|
|
if (!skipResourceCleanup() && address) {
|
2022-04-13 00:07:22 +08:00
|
|
|
this->downloadTagAllocation(requiredTaskCount);
|
2022-03-23 22:36:07 +08:00
|
|
|
return baseWaitFunction(address, WaitParams{false, false, 0}, requiredTaskCount);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2022-02-22 20:51:29 +08:00
|
|
|
|
2023-12-01 17:12:59 +08:00
|
|
|
return WaitStatus::ready;
|
2021-10-21 07:29:53 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
WaitStatus CommandStreamReceiver::waitForTaskCountAndCleanAllocationList(TaskCountType requiredTaskCount, uint32_t allocationUsage) {
|
2023-12-01 17:12:59 +08:00
|
|
|
WaitStatus waitStatus{WaitStatus::ready};
|
2021-11-17 23:31:39 +08:00
|
|
|
auto &list = allocationUsage == TEMPORARY_ALLOCATION ? internalAllocationStorage->getTemporaryAllocations() : internalAllocationStorage->getAllocationsForReuse();
|
|
|
|
if (!list.peekIsEmpty()) {
|
2022-02-22 20:51:29 +08:00
|
|
|
waitStatus = this->CommandStreamReceiver::waitForTaskCount(requiredTaskCount);
|
2021-11-17 23:31:39 +08:00
|
|
|
}
|
2018-11-02 17:01:56 +08:00
|
|
|
internalAllocationStorage->cleanAllocationList(requiredTaskCount, allocationUsage);
|
2023-10-28 00:43:33 +08:00
|
|
|
if (allocationUsage == TEMPORARY_ALLOCATION) {
|
|
|
|
internalAllocationStorage->cleanAllocationList(requiredTaskCount, DEFERRED_DEALLOCATION);
|
|
|
|
}
|
2022-02-22 20:51:29 +08:00
|
|
|
|
|
|
|
return waitStatus;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
WaitStatus CommandStreamReceiver::waitForTaskCountAndCleanTemporaryAllocationList(TaskCountType requiredTaskCount) {
|
2022-02-22 20:51:29 +08:00
|
|
|
return waitForTaskCountAndCleanAllocationList(requiredTaskCount, TEMPORARY_ALLOCATION);
|
|
|
|
}
|
2019-12-17 17:35:25 +08:00
|
|
|
|
2019-02-20 17:31:32 +08:00
|
|
|
void CommandStreamReceiver::ensureCommandBufferAllocation(LinearStream &commandStream, size_t minimumRequiredSize, size_t additionalAllocationSize) {
|
|
|
|
if (commandStream.getAvailableSpace() >= minimumRequiredSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-09 20:33:43 +08:00
|
|
|
auto alignment = MemoryConstants::pageSize64k;
|
|
|
|
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.ForceCommandBufferAlignment.get() != -1) {
|
|
|
|
alignment = debugManager.flags.ForceCommandBufferAlignment.get() * MemoryConstants::kiloByte;
|
2022-02-09 20:33:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto allocationSize = alignUp(minimumRequiredSize + additionalAllocationSize, alignment);
|
2023-12-11 22:24:36 +08:00
|
|
|
constexpr static auto allocationType = AllocationType::commandBuffer;
|
2019-02-20 17:31:32 +08:00
|
|
|
auto allocation = this->getInternalAllocationStorage()->obtainReusableAllocation(allocationSize, allocationType).release();
|
|
|
|
if (allocation == nullptr) {
|
2019-11-07 21:15:04 +08:00
|
|
|
const AllocationProperties commandStreamAllocationProperties{rootDeviceIndex, true, allocationSize, allocationType,
|
2019-12-10 19:16:07 +08:00
|
|
|
isMultiOsContextCapable(), false, osContext->getDeviceBitfield()};
|
2019-02-20 17:31:32 +08:00
|
|
|
allocation = this->getMemoryManager()->allocateGraphicsMemoryWithProperties(commandStreamAllocationProperties);
|
|
|
|
}
|
|
|
|
DEBUG_BREAK_IF(allocation == nullptr);
|
|
|
|
|
|
|
|
if (commandStream.getGraphicsAllocation() != nullptr) {
|
|
|
|
getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(commandStream.getGraphicsAllocation()), REUSABLE_ALLOCATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
commandStream.replaceBuffer(allocation->getUnderlyingBuffer(), allocationSize - additionalAllocationSize);
|
|
|
|
commandStream.replaceGraphicsAllocation(allocation);
|
|
|
|
}
|
|
|
|
|
2023-11-17 20:14:15 +08:00
|
|
|
void CommandStreamReceiver::preallocateAllocation(AllocationType type, size_t size) {
|
|
|
|
const AllocationProperties commandStreamAllocationProperties{rootDeviceIndex, true, size, type,
|
2023-10-27 23:54:45 +08:00
|
|
|
isMultiOsContextCapable(), false, deviceBitfield};
|
|
|
|
auto allocation = this->getMemoryManager()->allocateGraphicsMemoryWithProperties(commandStreamAllocationProperties);
|
2023-11-08 20:44:01 +08:00
|
|
|
if (allocation) {
|
|
|
|
getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
|
|
|
|
this->makeResident(*allocation);
|
|
|
|
}
|
2023-10-27 23:54:45 +08:00
|
|
|
}
|
|
|
|
|
2023-11-17 20:14:15 +08:00
|
|
|
void CommandStreamReceiver::preallocateCommandBuffer() {
|
2023-12-11 22:24:36 +08:00
|
|
|
preallocateAllocation(AllocationType::commandBuffer, MemoryConstants::pageSize64k);
|
2023-11-17 20:14:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandStreamReceiver::preallocateInternalHeap() {
|
2023-12-11 22:24:36 +08:00
|
|
|
preallocateAllocation(AllocationType::internalHeap, MemoryConstants::pageSize64k);
|
2023-11-17 20:14:15 +08:00
|
|
|
}
|
|
|
|
|
2022-10-13 23:53:33 +08:00
|
|
|
void CommandStreamReceiver::fillReusableAllocationsList() {
|
2022-12-09 22:37:32 +08:00
|
|
|
auto &gfxCoreHelper = getGfxCoreHelper();
|
|
|
|
auto amountToFill = gfxCoreHelper.getAmountOfAllocationsToFill();
|
2022-10-13 23:53:33 +08:00
|
|
|
for (auto i = 0u; i < amountToFill; i++) {
|
2023-10-27 23:54:45 +08:00
|
|
|
preallocateCommandBuffer();
|
|
|
|
}
|
2023-11-17 20:14:15 +08:00
|
|
|
|
|
|
|
auto internalHeapsToFill = getProductHelper().getInternalHeapsPreallocated();
|
|
|
|
for (auto i = 0u; i < internalHeapsToFill; i++) {
|
|
|
|
preallocateInternalHeap();
|
|
|
|
}
|
2023-10-27 23:54:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandStreamReceiver::requestPreallocation() {
|
|
|
|
auto preallocationsPerQueue = getProductHelper().getCommandBuffersPreallocatedPerCommandQueue();
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.SetAmountOfReusableAllocationsPerCmdQueue.get() != -1) {
|
|
|
|
preallocationsPerQueue = debugManager.flags.SetAmountOfReusableAllocationsPerCmdQueue.get();
|
2023-10-27 23:54:45 +08:00
|
|
|
}
|
|
|
|
auto lock = obtainUniqueOwnership();
|
|
|
|
requestedPreallocationsAmount += preallocationsPerQueue;
|
|
|
|
const int64_t amountToPreallocate = static_cast<int64_t>(requestedPreallocationsAmount.load()) - preallocatedAmount;
|
|
|
|
DEBUG_BREAK_IF(amountToPreallocate > preallocationsPerQueue);
|
|
|
|
if (amountToPreallocate > 0) {
|
|
|
|
for (auto i = 0u; i < amountToPreallocate; i++) {
|
|
|
|
preallocateCommandBuffer();
|
|
|
|
}
|
|
|
|
preallocatedAmount += static_cast<uint32_t>(amountToPreallocate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandStreamReceiver::releasePreallocationRequest() {
|
|
|
|
auto preallocationsPerQueue = getProductHelper().getCommandBuffersPreallocatedPerCommandQueue();
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.SetAmountOfReusableAllocationsPerCmdQueue.get() != -1) {
|
|
|
|
preallocationsPerQueue = debugManager.flags.SetAmountOfReusableAllocationsPerCmdQueue.get();
|
2022-10-13 23:53:33 +08:00
|
|
|
}
|
2023-10-27 23:54:45 +08:00
|
|
|
DEBUG_BREAK_IF(preallocationsPerQueue > requestedPreallocationsAmount);
|
|
|
|
requestedPreallocationsAmount -= preallocationsPerQueue;
|
2022-10-13 23:53:33 +08:00
|
|
|
}
|
|
|
|
|
2023-02-12 06:03:06 +08:00
|
|
|
bool CommandStreamReceiver::initializeResources() {
|
2022-11-03 23:25:30 +08:00
|
|
|
if (!resourcesInitialized) {
|
|
|
|
auto lock = obtainUniqueOwnership();
|
|
|
|
if (!resourcesInitialized) {
|
2023-02-12 06:03:06 +08:00
|
|
|
if (!osContext->ensureContextInitialized()) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-11-03 23:25:30 +08:00
|
|
|
this->fillReusableAllocationsList();
|
|
|
|
this->resourcesInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
2023-02-12 06:03:06 +08:00
|
|
|
|
|
|
|
return true;
|
2022-11-03 23:25:30 +08:00
|
|
|
}
|
|
|
|
|
2018-10-11 17:19:49 +08:00
|
|
|
MemoryManager *CommandStreamReceiver::getMemoryManager() const {
|
|
|
|
DEBUG_BREAK_IF(!executionEnvironment.memoryManager);
|
|
|
|
return executionEnvironment.memoryManager.get();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) {
|
2019-02-20 17:31:32 +08:00
|
|
|
constexpr static auto additionalAllocationSize = MemoryConstants::cacheLineSize + CSRequirements::csOverfetchSize;
|
|
|
|
ensureCommandBufferAllocation(this->commandStream, minRequiredSize, additionalAllocationSize);
|
2017-12-21 07:45:38 +08:00
|
|
|
return commandStream;
|
|
|
|
}
|
|
|
|
|
2020-02-03 20:24:53 +08:00
|
|
|
OSInterface *CommandStreamReceiver::getOSInterface() const {
|
|
|
|
return executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface.get();
|
|
|
|
}
|
|
|
|
|
2022-04-28 17:05:59 +08:00
|
|
|
GmmHelper *CommandStreamReceiver::peekGmmHelper() const {
|
|
|
|
return executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->gmmHelper.get();
|
|
|
|
}
|
|
|
|
|
2021-02-19 18:37:39 +08:00
|
|
|
uint64_t CommandStreamReceiver::getWorkPartitionAllocationGpuAddress() const {
|
|
|
|
if (isStaticWorkPartitioningEnabled()) {
|
|
|
|
return getWorkPartitionAllocation()->getGpuAddress();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-19 22:15:51 +08:00
|
|
|
bool CommandStreamReceiver::isRcs() const {
|
|
|
|
return this->osContext->getEngineType() == aub_stream::ENGINE_RCS;
|
|
|
|
}
|
|
|
|
|
2021-11-20 05:58:46 +08:00
|
|
|
bool CommandStreamReceiver::skipResourceCleanup() const {
|
2022-10-26 19:31:37 +08:00
|
|
|
return ((this->getOSInterface() && this->getOSInterface()->getDriverModel() && this->getOSInterface()->getDriverModel()->skipResourceCleanup()) || forceSkipResourceCleanupRequired);
|
2021-11-20 05:58:46 +08:00
|
|
|
}
|
|
|
|
|
2022-01-21 00:56:19 +08:00
|
|
|
bool CommandStreamReceiver::isGpuHangDetected() const {
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.DisableGpuHangDetection.get()) {
|
2022-03-09 20:36:51 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-05 00:03:36 +08:00
|
|
|
return this->osContext && this->getOSInterface() && this->getOSInterface()->getDriverModel() && this->getOSInterface()->getDriverModel()->isGpuHangDetected(*osContext);
|
2022-01-21 00:56:19 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void CommandStreamReceiver::cleanupResources() {
|
2018-01-12 23:41:45 +08:00
|
|
|
waitForTaskCountAndCleanAllocationList(this->latestFlushedTaskCount, TEMPORARY_ALLOCATION);
|
|
|
|
waitForTaskCountAndCleanAllocationList(this->latestFlushedTaskCount, REUSABLE_ALLOCATION);
|
|
|
|
|
2018-03-21 19:58:30 +08:00
|
|
|
if (debugSurface) {
|
2018-10-11 17:19:49 +08:00
|
|
|
getMemoryManager()->freeGraphicsMemory(debugSurface);
|
2018-03-21 19:58:30 +08:00
|
|
|
debugSurface = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-03-05 18:03:38 +08:00
|
|
|
if (commandStream.getCpuBase()) {
|
2018-10-11 17:19:49 +08:00
|
|
|
getMemoryManager()->freeGraphicsMemory(commandStream.getGraphicsAllocation());
|
2017-12-21 07:45:38 +08:00
|
|
|
commandStream.replaceGraphicsAllocation(nullptr);
|
|
|
|
commandStream.replaceBuffer(nullptr, 0);
|
|
|
|
}
|
2018-07-13 20:11:04 +08:00
|
|
|
|
2021-02-25 16:38:48 +08:00
|
|
|
if (tagsMultiAllocation) {
|
2022-03-29 23:31:51 +08:00
|
|
|
// Null tag address to prevent waiting for tag update when freeing it
|
2021-05-12 16:35:07 +08:00
|
|
|
tagAllocation = nullptr;
|
|
|
|
tagAddress = nullptr;
|
2021-05-27 20:23:40 +08:00
|
|
|
DEBUG_BREAK_IF(tagAllocation != nullptr);
|
|
|
|
DEBUG_BREAK_IF(tagAddress != nullptr);
|
|
|
|
|
2021-02-25 16:38:48 +08:00
|
|
|
for (auto graphicsAllocation : tagsMultiAllocation->getGraphicsAllocations()) {
|
|
|
|
getMemoryManager()->freeGraphicsMemory(graphicsAllocation);
|
|
|
|
}
|
|
|
|
delete tagsMultiAllocation;
|
|
|
|
tagsMultiAllocation = nullptr;
|
2018-07-13 20:11:04 +08:00
|
|
|
}
|
2019-06-28 03:33:05 +08:00
|
|
|
|
2020-02-06 03:00:08 +08:00
|
|
|
if (globalFenceAllocation) {
|
|
|
|
getMemoryManager()->freeGraphicsMemory(globalFenceAllocation);
|
|
|
|
globalFenceAllocation = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-28 03:33:05 +08:00
|
|
|
if (preemptionAllocation) {
|
|
|
|
getMemoryManager()->freeGraphicsMemory(preemptionAllocation);
|
|
|
|
preemptionAllocation = nullptr;
|
|
|
|
}
|
2019-09-04 22:44:27 +08:00
|
|
|
|
|
|
|
if (perDssBackedBuffer) {
|
|
|
|
getMemoryManager()->freeGraphicsMemory(perDssBackedBuffer);
|
|
|
|
perDssBackedBuffer = nullptr;
|
|
|
|
}
|
2020-11-19 07:58:42 +08:00
|
|
|
|
|
|
|
if (clearColorAllocation) {
|
|
|
|
getMemoryManager()->freeGraphicsMemory(clearColorAllocation);
|
|
|
|
clearColorAllocation = nullptr;
|
|
|
|
}
|
2021-02-17 01:04:00 +08:00
|
|
|
|
|
|
|
if (workPartitionAllocation) {
|
|
|
|
getMemoryManager()->freeGraphicsMemory(workPartitionAllocation);
|
|
|
|
workPartitionAllocation = nullptr;
|
|
|
|
}
|
2022-08-03 19:54:08 +08:00
|
|
|
|
2023-03-07 04:33:50 +08:00
|
|
|
if (globalStatelessHeapAllocation) {
|
|
|
|
getMemoryManager()->freeGraphicsMemory(globalStatelessHeapAllocation);
|
|
|
|
globalStatelessHeapAllocation = nullptr;
|
|
|
|
}
|
2023-08-10 23:40:21 +08:00
|
|
|
for (auto &alloc : ownedPrivateAllocations) {
|
|
|
|
getMemoryManager()->freeGraphicsMemory(alloc.second);
|
|
|
|
}
|
|
|
|
ownedPrivateAllocations.clear();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
WaitStatus CommandStreamReceiver::waitForCompletionWithTimeout(const WaitParams ¶ms, TaskCountType taskCountToWait) {
|
2023-11-30 16:32:25 +08:00
|
|
|
bool printWaitForCompletion = debugManager.flags.LogWaitingForCompletion.get();
|
2022-04-22 01:41:33 +08:00
|
|
|
if (printWaitForCompletion) {
|
|
|
|
printTagAddressContent(taskCountToWait, params.waitTimeout, true);
|
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
TaskCountType latestSentTaskCount = this->latestFlushedTaskCount;
|
2017-12-21 07:45:38 +08:00
|
|
|
if (latestSentTaskCount < taskCountToWait) {
|
2019-11-24 21:50:41 +08:00
|
|
|
if (!this->flushBatchedSubmissions()) {
|
2022-01-21 00:56:19 +08:00
|
|
|
const auto isGpuHang{isGpuHangDetected()};
|
2023-12-01 17:12:59 +08:00
|
|
|
return isGpuHang ? WaitStatus::gpuHang : WaitStatus::notReady;
|
2019-11-24 21:50:41 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-04-22 01:41:33 +08:00
|
|
|
auto retCode = baseWaitFunction(getTagAddress(), params, taskCountToWait);
|
|
|
|
if (printWaitForCompletion) {
|
|
|
|
printTagAddressContent(taskCountToWait, params.waitTimeout, false);
|
|
|
|
}
|
|
|
|
return retCode;
|
2021-10-08 02:09:36 +08:00
|
|
|
}
|
|
|
|
|
2022-09-19 18:20:14 +08:00
|
|
|
bool CommandStreamReceiver::checkGpuHangDetected(TimeType currentTime, TimeType &lastHangCheckTime) const {
|
|
|
|
std::chrono::microseconds elapsedTimeSinceGpuHangCheck = std::chrono::duration_cast<std::chrono::microseconds>(currentTime - lastHangCheckTime);
|
|
|
|
|
|
|
|
if (elapsedTimeSinceGpuHangCheck.count() >= gpuHangCheckPeriod.count()) {
|
|
|
|
lastHangCheckTime = currentTime;
|
|
|
|
if (isGpuHangDetected()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
WaitStatus CommandStreamReceiver::baseWaitFunction(volatile TagAddressType *pollAddress, const WaitParams ¶ms, TaskCountType taskCountToWait) {
|
2022-01-21 00:56:19 +08:00
|
|
|
std::chrono::high_resolution_clock::time_point waitStartTime, lastHangCheckTime, currentTime;
|
2021-10-08 02:09:36 +08:00
|
|
|
int64_t timeDiff = 0;
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
TaskCountType latestSentTaskCount = this->latestFlushedTaskCount;
|
2021-10-28 17:21:44 +08:00
|
|
|
if (latestSentTaskCount < taskCountToWait) {
|
2023-12-13 17:17:24 +08:00
|
|
|
if (this->flushTagUpdate() != NEO::SubmissionStatus::success) {
|
2023-12-01 17:12:59 +08:00
|
|
|
return WaitStatus::notReady;
|
2023-03-15 23:10:06 +08:00
|
|
|
}
|
2021-10-28 17:21:44 +08:00
|
|
|
}
|
2022-11-22 21:53:59 +08:00
|
|
|
volatile TagAddressType *partitionAddress = pollAddress;
|
2021-10-28 17:21:44 +08:00
|
|
|
|
2022-01-21 00:56:19 +08:00
|
|
|
waitStartTime = std::chrono::high_resolution_clock::now();
|
|
|
|
lastHangCheckTime = waitStartTime;
|
2021-09-17 21:05:26 +08:00
|
|
|
for (uint32_t i = 0; i < activePartitions; i++) {
|
2022-03-23 22:36:07 +08:00
|
|
|
while (*partitionAddress < taskCountToWait && timeDiff <= params.waitTimeout) {
|
2022-04-19 19:43:40 +08:00
|
|
|
this->downloadTagAllocation(taskCountToWait);
|
|
|
|
|
2022-03-23 22:36:07 +08:00
|
|
|
if (!params.indefinitelyPoll && WaitUtils::waitFunction(partitionAddress, taskCountToWait)) {
|
2021-09-07 06:29:47 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-02-21 17:27:31 +08:00
|
|
|
|
2022-01-21 00:56:19 +08:00
|
|
|
currentTime = std::chrono::high_resolution_clock::now();
|
2022-09-19 18:20:14 +08:00
|
|
|
if (checkGpuHangDetected(currentTime, lastHangCheckTime)) {
|
2023-12-01 17:12:59 +08:00
|
|
|
return WaitStatus::gpuHang;
|
2022-01-21 00:56:19 +08:00
|
|
|
}
|
|
|
|
|
2022-03-23 22:36:07 +08:00
|
|
|
if (params.enableTimeout) {
|
2022-01-21 00:56:19 +08:00
|
|
|
timeDiff = std::chrono::duration_cast<std::chrono::microseconds>(currentTime - waitStartTime).count();
|
2021-09-07 06:29:47 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2021-09-07 06:29:47 +08:00
|
|
|
|
2023-06-06 23:11:09 +08:00
|
|
|
partitionAddress = ptrOffset(partitionAddress, this->immWritePostSyncWriteOffset);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2021-09-03 19:42:31 +08:00
|
|
|
|
2022-03-17 17:43:17 +08:00
|
|
|
partitionAddress = pollAddress;
|
|
|
|
for (uint32_t i = 0; i < activePartitions; i++) {
|
|
|
|
if (*partitionAddress < taskCountToWait) {
|
2023-12-01 17:12:59 +08:00
|
|
|
return WaitStatus::notReady;
|
2022-03-17 17:43:17 +08:00
|
|
|
}
|
2023-06-06 23:11:09 +08:00
|
|
|
partitionAddress = ptrOffset(partitionAddress, this->immWritePostSyncWriteOffset);
|
2022-03-17 17:43:17 +08:00
|
|
|
}
|
|
|
|
|
2023-12-01 17:12:59 +08:00
|
|
|
return WaitStatus::ready;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandStreamReceiver::setTagAllocation(GraphicsAllocation *allocation) {
|
|
|
|
this->tagAllocation = allocation;
|
2019-07-23 03:28:59 +08:00
|
|
|
UNRECOVERABLE_IF(allocation == nullptr);
|
2022-11-22 21:53:59 +08:00
|
|
|
this->tagAddress = reinterpret_cast<TagAddressType *>(allocation->getUnderlyingBuffer());
|
2020-04-30 23:12:01 +08:00
|
|
|
this->debugPauseStateAddress = reinterpret_cast<DebugPauseState *>(
|
2022-12-06 15:32:34 +08:00
|
|
|
reinterpret_cast<uint8_t *>(allocation->getUnderlyingBuffer()) + TagAllocationLayout::debugPauseStateAddressOffset);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 22:23:53 +08:00
|
|
|
MultiGraphicsAllocation &CommandStreamReceiver::createTagsMultiAllocation() {
|
2022-04-07 21:09:40 +08:00
|
|
|
RootDeviceIndicesContainer rootDeviceIndices;
|
2021-02-25 16:38:48 +08:00
|
|
|
|
2023-06-12 21:52:45 +08:00
|
|
|
rootDeviceIndices.pushUnique(rootDeviceIndex);
|
2021-02-25 16:38:48 +08:00
|
|
|
|
2023-01-13 18:36:23 +08:00
|
|
|
auto maxRootDeviceIndex = static_cast<uint32_t>(this->executionEnvironment.rootDeviceEnvironments.size() - 1);
|
2021-02-25 16:38:48 +08:00
|
|
|
auto allocations = new MultiGraphicsAllocation(maxRootDeviceIndex);
|
|
|
|
|
2023-12-11 22:24:36 +08:00
|
|
|
AllocationProperties unifiedMemoryProperties{rootDeviceIndex, MemoryConstants::pageSize, AllocationType::tagBuffer, systemMemoryBitfield};
|
2021-02-25 16:38:48 +08:00
|
|
|
|
2021-03-11 22:23:53 +08:00
|
|
|
this->getMemoryManager()->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, unifiedMemoryProperties, *allocations);
|
2021-02-25 16:38:48 +08:00
|
|
|
return *allocations;
|
|
|
|
}
|
2023-01-13 18:36:23 +08:00
|
|
|
bool CommandStreamReceiver::ensureTagAllocationForRootDeviceIndex(uint32_t rootDeviceIndex) {
|
|
|
|
UNRECOVERABLE_IF(!tagsMultiAllocation);
|
|
|
|
if (rootDeviceIndex >= tagsMultiAllocation->getGraphicsAllocations().size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (tagsMultiAllocation->getGraphicsAllocation(rootDeviceIndex)) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-11 22:24:36 +08:00
|
|
|
AllocationProperties allocationProperties{rootDeviceIndex, MemoryConstants::pageSize, AllocationType::tagBuffer, systemMemoryBitfield};
|
2023-01-13 18:36:23 +08:00
|
|
|
allocationProperties.flags.allocateMemory = false;
|
|
|
|
auto graphicsAllocation = this->getMemoryManager()->createGraphicsAllocationFromExistingStorage(allocationProperties, tagAllocation->getUnderlyingBuffer(), *tagsMultiAllocation);
|
|
|
|
if (!graphicsAllocation) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
tagsMultiAllocation->addAllocation(graphicsAllocation);
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-25 16:38:48 +08:00
|
|
|
|
2019-07-10 13:57:54 +08:00
|
|
|
FlushStamp CommandStreamReceiver::obtainCurrentFlushStamp() const {
|
|
|
|
return flushStamp->peekStamp();
|
|
|
|
}
|
|
|
|
|
2024-01-23 18:41:31 +08:00
|
|
|
void CommandStreamReceiver::setRequiredScratchSizes(uint32_t newRequiredScratchSlot0Size, uint32_t newRequiredScratchSlot1Size) {
|
|
|
|
if (newRequiredScratchSlot0Size > requiredScratchSlot0Size) {
|
|
|
|
requiredScratchSlot0Size = newRequiredScratchSlot0Size;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2024-01-23 18:41:31 +08:00
|
|
|
if (newRequiredScratchSlot1Size > requiredScratchSlot1Size) {
|
|
|
|
requiredScratchSlot1Size = newRequiredScratchSlot1Size;
|
2019-06-28 15:37:04 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-01-08 22:58:02 +08:00
|
|
|
|
2018-11-22 22:16:20 +08:00
|
|
|
GraphicsAllocation *CommandStreamReceiver::getScratchAllocation() {
|
2024-01-23 18:41:31 +08:00
|
|
|
return scratchSpaceController->getScratchSpaceSlot0Allocation();
|
2018-11-22 22:16:20 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 01:04:14 +08:00
|
|
|
void CommandStreamReceiver::overwriteFlatBatchBufferHelper(FlatBatchBufferHelper *newHelper) {
|
|
|
|
flatBatchBufferHelper.reset(newHelper);
|
|
|
|
}
|
|
|
|
|
2018-06-13 02:33:03 +08:00
|
|
|
void CommandStreamReceiver::initProgrammingFlags() {
|
|
|
|
isPreambleSent = false;
|
2023-04-28 17:38:31 +08:00
|
|
|
gsbaFor32BitProgrammed = false;
|
2019-04-26 23:04:03 +08:00
|
|
|
bindingTableBaseAddressRequired = true;
|
2018-06-13 02:33:03 +08:00
|
|
|
mediaVfeStateDirty = true;
|
|
|
|
lastVmeSubslicesConfig = false;
|
2023-03-10 21:20:23 +08:00
|
|
|
stateComputeModeDirty = true;
|
2018-06-13 02:33:03 +08:00
|
|
|
|
|
|
|
lastSentL3Config = 0;
|
|
|
|
lastMediaSamplerConfig = -1;
|
|
|
|
lastPreemptionMode = PreemptionMode::Initial;
|
2023-02-03 02:57:24 +08:00
|
|
|
|
2023-02-11 01:54:13 +08:00
|
|
|
latestSentStatelessMocsConfig = CacheSettings::unknownMocs;
|
2023-02-03 02:57:24 +08:00
|
|
|
this->streamProperties.stateBaseAddress.statelessMocs = {};
|
2018-06-13 02:33:03 +08:00
|
|
|
}
|
|
|
|
|
2019-06-03 15:57:27 +08:00
|
|
|
void CommandStreamReceiver::programForAubSubCapture(bool wasActiveInPreviousEnqueue, bool isActive) {
|
|
|
|
if (!wasActiveInPreviousEnqueue && isActive) {
|
|
|
|
// force CSR reprogramming upon subcapture activation
|
|
|
|
this->initProgrammingFlags();
|
|
|
|
}
|
|
|
|
if (wasActiveInPreviousEnqueue && !isActive) {
|
|
|
|
// flush BB upon subcapture deactivation
|
|
|
|
this->flushBatchedSubmissions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-11 17:19:21 +08:00
|
|
|
ResidencyContainer &CommandStreamReceiver::getResidencyAllocations() {
|
2018-09-13 21:49:38 +08:00
|
|
|
return this->residencyAllocations;
|
2018-09-11 17:19:21 +08:00
|
|
|
}
|
|
|
|
|
2018-09-12 16:44:35 +08:00
|
|
|
ResidencyContainer &CommandStreamReceiver::getEvictionAllocations() {
|
2018-09-13 21:49:38 +08:00
|
|
|
return this->evictionAllocations;
|
2018-09-12 16:44:35 +08:00
|
|
|
}
|
2023-09-04 17:42:02 +08:00
|
|
|
PrivateAllocsToReuseContainer &CommandStreamReceiver::getOwnedPrivateAllocations() {
|
2023-08-10 23:40:21 +08:00
|
|
|
return this->ownedPrivateAllocations;
|
|
|
|
}
|
2018-09-12 16:44:35 +08:00
|
|
|
|
2021-09-23 03:25:21 +08:00
|
|
|
AubSubCaptureStatus CommandStreamReceiver::checkAndActivateAubSubCapture(const std::string &kernelName) { return {false, false}; }
|
2018-06-13 02:33:03 +08:00
|
|
|
|
2019-04-01 15:33:19 +08:00
|
|
|
void CommandStreamReceiver::addAubComment(const char *comment) {}
|
|
|
|
|
2022-03-29 23:31:51 +08:00
|
|
|
void CommandStreamReceiver::downloadAllocation(GraphicsAllocation &gfxAllocation) {
|
|
|
|
if (this->downloadAllocationImpl) {
|
|
|
|
this->downloadAllocationImpl(gfxAllocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-29 19:54:52 +08:00
|
|
|
void CommandStreamReceiver::startControllingDirectSubmissions() {
|
|
|
|
auto controller = this->executionEnvironment.directSubmissionController.get();
|
|
|
|
if (controller) {
|
2024-03-22 19:18:35 +08:00
|
|
|
controller->setTimeoutParamsForPlatform(this->getProductHelper());
|
2021-10-29 19:54:52 +08:00
|
|
|
controller->startControlling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-21 19:58:30 +08:00
|
|
|
GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) {
|
|
|
|
UNRECOVERABLE_IF(debugSurface != nullptr);
|
2023-12-11 22:24:36 +08:00
|
|
|
debugSurface = getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, size, AllocationType::debugContextSaveArea, getOsContext().getDeviceBitfield()});
|
2018-03-21 19:58:30 +08:00
|
|
|
return debugSurface;
|
|
|
|
}
|
|
|
|
|
2023-02-03 02:57:24 +08:00
|
|
|
void *CommandStreamReceiver::getIndirectHeapCurrentPtr(IndirectHeapType heapType) const {
|
|
|
|
auto heap = indirectHeap[heapType];
|
|
|
|
if (heap) {
|
|
|
|
return heap->getSpace(0);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-26 16:01:01 +08:00
|
|
|
IndirectHeap &CommandStreamReceiver::getIndirectHeap(IndirectHeap::Type heapType,
|
|
|
|
size_t minRequiredSize) {
|
2018-08-13 15:27:49 +08:00
|
|
|
DEBUG_BREAK_IF(static_cast<uint32_t>(heapType) >= arrayCount(indirectHeap));
|
2018-04-26 16:01:01 +08:00
|
|
|
auto &heap = indirectHeap[heapType];
|
|
|
|
GraphicsAllocation *heapMemory = nullptr;
|
|
|
|
|
|
|
|
if (heap)
|
|
|
|
heapMemory = heap->getGraphicsAllocation();
|
|
|
|
|
|
|
|
if (heap && heap->getAvailableSpace() < minRequiredSize && heapMemory) {
|
2018-10-24 20:25:04 +08:00
|
|
|
internalAllocationStorage->storeAllocation(std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
|
2018-04-26 16:01:01 +08:00
|
|
|
heapMemory = nullptr;
|
2023-02-08 01:23:45 +08:00
|
|
|
this->heapStorageRequiresRecyclingTag = true;
|
2018-04-26 16:01:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!heapMemory) {
|
|
|
|
allocateHeapMemory(heapType, minRequiredSize, heap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *heap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType,
|
|
|
|
size_t minRequiredSize, IndirectHeap *&indirectHeap) {
|
|
|
|
size_t reservedSize = 0;
|
2023-03-16 08:12:49 +08:00
|
|
|
auto finalHeapSize = HeapSize::getDefaultHeapSize(HeapSize::defaultHeapSize);
|
2023-12-14 00:09:52 +08:00
|
|
|
if (IndirectHeap::Type::surfaceState == heapType) {
|
2018-08-29 19:39:27 +08:00
|
|
|
finalHeapSize = defaultSshSize;
|
|
|
|
}
|
2023-12-14 00:09:52 +08:00
|
|
|
bool requireInternalHeap = IndirectHeap::Type::indirectObject == heapType ? canUse4GbHeaps : false;
|
2018-04-26 16:01:01 +08:00
|
|
|
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
|
2018-04-26 16:01:01 +08:00
|
|
|
requireInternalHeap = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
minRequiredSize += reservedSize;
|
|
|
|
|
|
|
|
finalHeapSize = alignUp(std::max(finalHeapSize, minRequiredSize), MemoryConstants::pageSize);
|
2023-12-11 22:24:36 +08:00
|
|
|
auto allocationType = AllocationType::linearStream;
|
2019-02-01 20:49:24 +08:00
|
|
|
if (requireInternalHeap) {
|
2023-12-11 22:24:36 +08:00
|
|
|
allocationType = AllocationType::internalHeap;
|
2019-02-01 20:49:24 +08:00
|
|
|
}
|
|
|
|
auto heapMemory = internalAllocationStorage->obtainReusableAllocation(finalHeapSize, allocationType).release();
|
2018-04-26 16:01:01 +08:00
|
|
|
|
|
|
|
if (!heapMemory) {
|
2019-11-07 21:15:04 +08:00
|
|
|
heapMemory = getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, true, finalHeapSize, allocationType,
|
2019-12-10 19:16:07 +08:00
|
|
|
isMultiOsContextCapable(), false, osContext->getDeviceBitfield()});
|
2018-04-26 16:01:01 +08:00
|
|
|
} else {
|
|
|
|
finalHeapSize = std::max(heapMemory->getUnderlyingBufferSize(), finalHeapSize);
|
|
|
|
}
|
|
|
|
|
2023-12-14 00:09:52 +08:00
|
|
|
if (IndirectHeap::Type::surfaceState == heapType) {
|
2018-08-29 19:39:27 +08:00
|
|
|
DEBUG_BREAK_IF(minRequiredSize > defaultSshSize - MemoryConstants::pageSize);
|
|
|
|
finalHeapSize = defaultSshSize - MemoryConstants::pageSize;
|
2018-04-26 16:01:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (indirectHeap) {
|
|
|
|
indirectHeap->replaceBuffer(heapMemory->getUnderlyingBuffer(), finalHeapSize);
|
|
|
|
indirectHeap->replaceGraphicsAllocation(heapMemory);
|
|
|
|
} else {
|
|
|
|
indirectHeap = new IndirectHeap(heapMemory, requireInternalHeap);
|
|
|
|
indirectHeap->overrideMaxSize(finalHeapSize);
|
|
|
|
}
|
2018-11-22 22:16:20 +08:00
|
|
|
scratchSpaceController->reserveHeap(heapType, indirectHeap);
|
2018-04-26 16:01:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandStreamReceiver::releaseIndirectHeap(IndirectHeap::Type heapType) {
|
2018-08-13 15:27:49 +08:00
|
|
|
DEBUG_BREAK_IF(static_cast<uint32_t>(heapType) >= arrayCount(indirectHeap));
|
2018-04-26 16:01:01 +08:00
|
|
|
auto &heap = indirectHeap[heapType];
|
|
|
|
|
|
|
|
if (heap) {
|
|
|
|
auto heapMemory = heap->getGraphicsAllocation();
|
|
|
|
if (heapMemory != nullptr)
|
2018-10-24 20:25:04 +08:00
|
|
|
internalAllocationStorage->storeAllocation(std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
|
2018-04-26 16:01:01 +08:00
|
|
|
heap->replaceBuffer(nullptr, 0);
|
|
|
|
heap->replaceGraphicsAllocation(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-05 17:23:28 +08:00
|
|
|
void CommandStreamReceiver::setExperimentalCmdBuffer(std::unique_ptr<ExperimentalCommandBuffer> &&cmdBuffer) {
|
|
|
|
experimentalCmdBuffer = std::move(cmdBuffer);
|
|
|
|
}
|
|
|
|
|
2020-06-17 17:31:08 +08:00
|
|
|
void *CommandStreamReceiver::asyncDebugBreakConfirmation(void *arg) {
|
|
|
|
auto self = reinterpret_cast<CommandStreamReceiver *>(arg);
|
|
|
|
|
2020-11-06 20:01:29 +08:00
|
|
|
do {
|
2021-02-06 22:38:55 +08:00
|
|
|
auto debugPauseStateValue = DebugPauseState::waitingForUserStartConfirmation;
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.PauseOnGpuMode.get() != PauseOnGpuProperties::PauseMode::AfterWorkload) {
|
2021-02-06 22:38:55 +08:00
|
|
|
do {
|
|
|
|
{
|
|
|
|
std::unique_lock<SpinLock> lock{self->debugPauseStateLock};
|
|
|
|
debugPauseStateValue = *self->debugPauseStateAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debugPauseStateValue == DebugPauseState::terminate) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
std::this_thread::yield();
|
|
|
|
} while (debugPauseStateValue != DebugPauseState::waitingForUserStartConfirmation);
|
|
|
|
std::cout << "Debug break: Press enter to start workload" << std::endl;
|
|
|
|
self->debugConfirmationFunction();
|
|
|
|
debugPauseStateValue = DebugPauseState::hasUserStartConfirmation;
|
|
|
|
{
|
|
|
|
std::unique_lock<SpinLock> lock{self->debugPauseStateLock};
|
|
|
|
*self->debugPauseStateAddress = debugPauseStateValue;
|
|
|
|
}
|
2021-02-12 18:49:34 +08:00
|
|
|
}
|
|
|
|
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.PauseOnGpuMode.get() != PauseOnGpuProperties::PauseMode::BeforeWorkload) {
|
2021-02-06 22:38:55 +08:00
|
|
|
do {
|
|
|
|
{
|
|
|
|
std::unique_lock<SpinLock> lock{self->debugPauseStateLock};
|
|
|
|
debugPauseStateValue = *self->debugPauseStateAddress;
|
|
|
|
}
|
|
|
|
if (debugPauseStateValue == DebugPauseState::terminate) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
std::this_thread::yield();
|
|
|
|
} while (debugPauseStateValue != DebugPauseState::waitingForUserEndConfirmation);
|
|
|
|
|
|
|
|
std::cout << "Debug break: Workload ended, press enter to continue" << std::endl;
|
|
|
|
self->debugConfirmationFunction();
|
|
|
|
|
|
|
|
{
|
|
|
|
std::unique_lock<SpinLock> lock{self->debugPauseStateLock};
|
|
|
|
*self->debugPauseStateAddress = DebugPauseState::hasUserEndConfirmation;
|
|
|
|
}
|
2021-02-12 18:49:34 +08:00
|
|
|
}
|
2023-11-30 16:32:25 +08:00
|
|
|
} while (debugManager.flags.PauseOnEnqueue.get() == PauseOnGpuProperties::DebugFlagValues::OnEachEnqueue || debugManager.flags.PauseOnBlitCopy.get() == PauseOnGpuProperties::DebugFlagValues::OnEachEnqueue);
|
2020-06-17 17:31:08 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-07-16 23:11:43 +08:00
|
|
|
bool CommandStreamReceiver::initializeTagAllocation() {
|
2021-03-11 22:23:53 +08:00
|
|
|
this->tagsMultiAllocation = &this->createTagsMultiAllocation();
|
2021-02-25 16:38:48 +08:00
|
|
|
|
|
|
|
auto tagAllocation = tagsMultiAllocation->getGraphicsAllocation(rootDeviceIndex);
|
2018-07-16 23:11:43 +08:00
|
|
|
if (!tagAllocation) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setTagAllocation(tagAllocation);
|
2023-11-30 16:32:25 +08:00
|
|
|
auto initValue = debugManager.flags.EnableNullHardware.get() ? static_cast<uint32_t>(-1) : initialHardwareTag;
|
2021-10-08 02:09:36 +08:00
|
|
|
auto tagAddress = this->tagAddress;
|
2022-12-06 15:32:34 +08:00
|
|
|
auto completionFence = reinterpret_cast<TaskCountType *>(getCompletionAddress());
|
|
|
|
UNRECOVERABLE_IF(!completionFence);
|
2021-10-08 02:09:36 +08:00
|
|
|
uint32_t subDevices = static_cast<uint32_t>(this->deviceBitfield.count());
|
|
|
|
for (uint32_t i = 0; i < subDevices; i++) {
|
|
|
|
*tagAddress = initValue;
|
2023-06-06 23:11:09 +08:00
|
|
|
tagAddress = ptrOffset(tagAddress, this->immWritePostSyncWriteOffset);
|
2022-12-06 15:32:34 +08:00
|
|
|
*completionFence = 0;
|
2023-06-06 23:11:09 +08:00
|
|
|
completionFence = ptrOffset(completionFence, this->immWritePostSyncWriteOffset);
|
2021-10-08 02:09:36 +08:00
|
|
|
}
|
2023-11-30 16:32:25 +08:00
|
|
|
*this->debugPauseStateAddress = debugManager.flags.EnableNullHardware.get() ? DebugPauseState::disabled : DebugPauseState::waitingForFirstSemaphore;
|
2020-04-30 23:12:01 +08:00
|
|
|
|
2023-11-30 16:32:25 +08:00
|
|
|
PRINT_DEBUG_STRING(debugManager.flags.PrintTagAllocationAddress.get(), stdout,
|
2020-09-25 15:49:10 +08:00
|
|
|
"\nCreated tag allocation %p for engine %u\n",
|
|
|
|
this->tagAddress, static_cast<uint32_t>(osContext->getEngineType()));
|
|
|
|
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.PauseOnEnqueue.get() != -1 || debugManager.flags.PauseOnBlitCopy.get() != -1) {
|
2020-06-17 17:31:08 +08:00
|
|
|
userPauseConfirmation = Thread::create(CommandStreamReceiver::asyncDebugBreakConfirmation, reinterpret_cast<void *>(this));
|
2020-04-30 23:12:01 +08:00
|
|
|
}
|
2018-07-31 20:27:26 +08:00
|
|
|
|
2023-02-06 18:12:34 +08:00
|
|
|
this->barrierCountTagAddress = ptrOffset(this->tagAddress, TagAllocationLayout::barrierCountOffset);
|
|
|
|
|
2018-07-16 23:11:43 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-17 01:04:00 +08:00
|
|
|
bool CommandStreamReceiver::createWorkPartitionAllocation(const Device &device) {
|
|
|
|
if (!staticWorkPartitioningEnabled) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-01 00:49:46 +08:00
|
|
|
UNRECOVERABLE_IF(device.getNumGenericSubDevices() < 2);
|
2021-02-17 01:04:00 +08:00
|
|
|
|
2023-12-11 22:24:36 +08:00
|
|
|
AllocationProperties properties{this->rootDeviceIndex, true, 4096u, AllocationType::workPartitionSurface, true, false, deviceBitfield};
|
2021-02-17 01:04:00 +08:00
|
|
|
this->workPartitionAllocation = getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
|
|
|
if (this->workPartitionAllocation == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-01-11 02:32:25 +08:00
|
|
|
uint32_t logicalId = 0;
|
2021-02-17 01:04:00 +08:00
|
|
|
for (uint32_t deviceIndex = 0; deviceIndex < deviceBitfield.size(); deviceIndex++) {
|
|
|
|
if (!deviceBitfield.test(deviceIndex)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-01-11 02:32:25 +08:00
|
|
|
const uint32_t copySrc[2] = {logicalId++, deviceIndex};
|
2021-02-17 01:04:00 +08:00
|
|
|
DeviceBitfield copyBitfield{};
|
|
|
|
copyBitfield.set(deviceIndex);
|
2022-01-11 02:32:25 +08:00
|
|
|
auto copySuccess = MemoryTransferHelper::transferMemoryToAllocationBanks(device, workPartitionAllocation, 0, copySrc, sizeof(copySrc), copyBitfield);
|
2021-02-17 01:04:00 +08:00
|
|
|
|
2021-10-21 19:16:19 +08:00
|
|
|
if (!copySuccess) {
|
2021-02-17 01:04:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-06 03:00:08 +08:00
|
|
|
bool CommandStreamReceiver::createGlobalFenceAllocation() {
|
2022-12-09 22:37:32 +08:00
|
|
|
auto &gfxCoreHelper = getGfxCoreHelper();
|
|
|
|
auto &hwInfo = peekHwInfo();
|
2022-12-08 20:22:35 +08:00
|
|
|
if (!gfxCoreHelper.isFenceAllocationRequired(hwInfo)) {
|
2020-02-06 03:00:08 +08:00
|
|
|
return true;
|
|
|
|
}
|
2020-02-13 20:28:21 +08:00
|
|
|
|
2020-02-06 03:00:08 +08:00
|
|
|
DEBUG_BREAK_IF(this->globalFenceAllocation != nullptr);
|
2023-12-11 22:24:36 +08:00
|
|
|
this->globalFenceAllocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, MemoryConstants::pageSize, AllocationType::globalFence, osContext->getDeviceBitfield()});
|
2020-02-06 03:00:08 +08:00
|
|
|
return this->globalFenceAllocation != nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-28 03:33:05 +08:00
|
|
|
bool CommandStreamReceiver::createPreemptionAllocation() {
|
2024-01-18 22:21:34 +08:00
|
|
|
if (EngineHelpers::isBcs(osContext->getEngineType())) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-02-12 18:27:28 +08:00
|
|
|
auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo();
|
2022-12-09 22:37:32 +08:00
|
|
|
auto &gfxCoreHelper = getGfxCoreHelper();
|
2021-04-16 20:14:03 +08:00
|
|
|
size_t preemptionSurfaceSize = hwInfo->capabilityTable.requiredPreemptionSurfaceSize;
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.OverrideCsrAllocationSize.get() > 0) {
|
|
|
|
preemptionSurfaceSize = debugManager.flags.OverrideCsrAllocationSize.get();
|
2021-04-16 20:14:03 +08:00
|
|
|
}
|
2023-12-11 22:24:36 +08:00
|
|
|
AllocationProperties properties{rootDeviceIndex, true, preemptionSurfaceSize, AllocationType::preemption, isMultiOsContextCapable(), false, deviceBitfield};
|
2021-11-25 17:31:14 +08:00
|
|
|
properties.flags.uncacheable = hwInfo->workaroundTable.flags.waCSRUncachable;
|
2022-12-09 22:37:32 +08:00
|
|
|
properties.alignment = gfxCoreHelper.getPreemptionAllocationAlignment();
|
2019-06-28 03:33:05 +08:00
|
|
|
this->preemptionAllocation = getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
|
|
|
return this->preemptionAllocation != nullptr;
|
|
|
|
}
|
|
|
|
|
2018-08-06 20:55:04 +08:00
|
|
|
std::unique_lock<CommandStreamReceiver::MutexType> CommandStreamReceiver::obtainUniqueOwnership() {
|
|
|
|
return std::unique_lock<CommandStreamReceiver::MutexType>(this->ownershipMutex);
|
|
|
|
}
|
2021-10-07 01:34:44 +08:00
|
|
|
std::unique_lock<CommandStreamReceiver::MutexType> CommandStreamReceiver::obtainHostPtrSurfaceCreationLock() {
|
|
|
|
return std::unique_lock<CommandStreamReceiver::MutexType>(this->hostPtrSurfaceCreationMutex);
|
|
|
|
}
|
2018-10-29 20:26:58 +08:00
|
|
|
AllocationsList &CommandStreamReceiver::getTemporaryAllocations() { return internalAllocationStorage->getTemporaryAllocations(); }
|
|
|
|
AllocationsList &CommandStreamReceiver::getAllocationsForReuse() { return internalAllocationStorage->getAllocationsForReuse(); }
|
2022-07-13 23:05:42 +08:00
|
|
|
AllocationsList &CommandStreamReceiver::getDeferredAllocations() { return internalAllocationStorage->getDeferredAllocations(); }
|
2018-08-06 20:55:04 +08:00
|
|
|
|
2019-03-12 19:00:41 +08:00
|
|
|
bool CommandStreamReceiver::createAllocationForHostSurface(HostPtrSurface &surface, bool requiresL3Flush) {
|
2021-10-07 01:34:44 +08:00
|
|
|
std::unique_lock<decltype(hostPtrSurfaceCreationMutex)> lock = this->obtainHostPtrSurfaceCreationLock();
|
2023-12-11 22:24:36 +08:00
|
|
|
auto allocation = internalAllocationStorage->obtainTemporaryAllocationWithPtr(surface.getSurfaceSize(), surface.getMemoryPointer(), AllocationType::externalHostPtr);
|
2020-04-15 19:39:09 +08:00
|
|
|
|
|
|
|
if (allocation == nullptr) {
|
|
|
|
auto memoryManager = getMemoryManager();
|
|
|
|
AllocationProperties properties{rootDeviceIndex,
|
|
|
|
false, // allocateMemory
|
2023-12-11 22:24:36 +08:00
|
|
|
surface.getSurfaceSize(), AllocationType::externalHostPtr,
|
2020-04-15 19:39:09 +08:00
|
|
|
false, // isMultiStorageAllocation
|
|
|
|
osContext->getDeviceBitfield()};
|
|
|
|
properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = requiresL3Flush;
|
|
|
|
allocation.reset(memoryManager->allocateGraphicsMemoryWithProperties(properties, surface.getMemoryPointer()));
|
|
|
|
if (allocation == nullptr && surface.peekIsPtrCopyAllowed()) {
|
|
|
|
// Try with no host pointer allocation and copy
|
2020-10-01 13:21:42 +08:00
|
|
|
allocation.reset(memoryManager->allocateInternalGraphicsMemoryWithHostCopy(rootDeviceIndex,
|
|
|
|
internalAllocationStorage->getDeviceBitfield(),
|
|
|
|
surface.getMemoryPointer(),
|
|
|
|
surface.getSurfaceSize()));
|
2018-10-29 17:38:53 +08:00
|
|
|
}
|
|
|
|
}
|
2020-04-15 19:39:09 +08:00
|
|
|
|
2018-10-29 17:38:53 +08:00
|
|
|
if (allocation == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-05-05 20:01:59 +08:00
|
|
|
allocation->hostPtrTaskCountAssignment++;
|
|
|
|
allocation->updateTaskCount(0u, osContext->getContextId());
|
2020-04-15 19:39:09 +08:00
|
|
|
surface.setAllocation(allocation.get());
|
|
|
|
internalAllocationStorage->storeAllocation(std::move(allocation), TEMPORARY_ALLOCATION);
|
2018-10-29 17:38:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-25 02:21:13 +08:00
|
|
|
TagAllocatorBase *CommandStreamReceiver::getEventTsAllocator() {
|
2018-11-27 20:07:41 +08:00
|
|
|
if (profilingTimeStampAllocator.get() == nullptr) {
|
2022-04-07 21:09:40 +08:00
|
|
|
RootDeviceIndicesContainer rootDeviceIndices = {rootDeviceIndex};
|
2021-05-13 02:48:41 +08:00
|
|
|
profilingTimeStampAllocator = std::make_unique<TagAllocator<HwTimeStamps>>(rootDeviceIndices, getMemoryManager(), getPreferredTagPoolSize(), MemoryConstants::cacheLineSize,
|
2021-03-25 02:21:13 +08:00
|
|
|
sizeof(HwTimeStamps), false, osContext->getDeviceBitfield());
|
2018-11-27 20:07:41 +08:00
|
|
|
}
|
|
|
|
return profilingTimeStampAllocator.get();
|
|
|
|
}
|
|
|
|
|
2021-03-25 02:21:13 +08:00
|
|
|
TagAllocatorBase *CommandStreamReceiver::getEventPerfCountAllocator(const uint32_t tagSize) {
|
2018-11-27 20:07:41 +08:00
|
|
|
if (perfCounterAllocator.get() == nullptr) {
|
2022-04-07 21:09:40 +08:00
|
|
|
RootDeviceIndicesContainer rootDeviceIndices = {rootDeviceIndex};
|
2019-12-02 15:37:42 +08:00
|
|
|
perfCounterAllocator = std::make_unique<TagAllocator<HwPerfCounter>>(
|
2021-05-13 02:48:41 +08:00
|
|
|
rootDeviceIndices, getMemoryManager(), getPreferredTagPoolSize(), MemoryConstants::cacheLineSize, tagSize, false, osContext->getDeviceBitfield());
|
2018-11-27 20:07:41 +08:00
|
|
|
}
|
|
|
|
return perfCounterAllocator.get();
|
|
|
|
}
|
|
|
|
|
2020-02-03 17:52:12 +08:00
|
|
|
size_t CommandStreamReceiver::getPreferredTagPoolSize() const {
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.DisableTimestampPacketOptimizations.get()) {
|
2020-02-03 17:52:12 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-05-26 23:03:23 +08:00
|
|
|
return 2048;
|
2020-02-03 17:52:12 +08:00
|
|
|
}
|
|
|
|
|
2020-03-19 20:48:13 +08:00
|
|
|
bool CommandStreamReceiver::expectMemory(const void *gfxAddress, const void *srcAddress,
|
|
|
|
size_t length, uint32_t compareOperation) {
|
2019-03-29 01:28:23 +08:00
|
|
|
auto isMemoryEqual = (memcmp(gfxAddress, srcAddress, length) == 0);
|
2019-12-27 18:32:12 +08:00
|
|
|
auto isEqualMemoryExpected = (compareOperation == AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual);
|
2019-03-29 01:28:23 +08:00
|
|
|
|
2020-03-19 20:48:13 +08:00
|
|
|
return (isMemoryEqual == isEqualMemoryExpected);
|
2018-11-28 22:32:13 +08:00
|
|
|
}
|
|
|
|
|
2021-10-06 20:42:30 +08:00
|
|
|
bool CommandStreamReceiver::needsPageTableManager() const {
|
2020-02-12 18:27:28 +08:00
|
|
|
auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo();
|
2022-12-15 20:13:57 +08:00
|
|
|
auto &productHelper = getProductHelper();
|
2021-09-29 23:59:41 +08:00
|
|
|
|
|
|
|
if (pageTableManager.get() != nullptr) {
|
2019-12-27 18:32:12 +08:00
|
|
|
return false;
|
|
|
|
}
|
2022-12-15 20:13:57 +08:00
|
|
|
return productHelper.isPageTableManagerSupported(*hwInfo);
|
2019-12-27 18:32:12 +08:00
|
|
|
}
|
|
|
|
|
2020-04-30 19:24:34 +08:00
|
|
|
void CommandStreamReceiver::printDeviceIndex() {
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.PrintDeviceAndEngineIdOnSubmission.get()) {
|
2022-02-12 00:28:08 +08:00
|
|
|
printf("%u: Submission to RootDevice Index: %u, Sub-Devices Mask: %lu, EngineId: %u (%s, %s)\n",
|
|
|
|
SysCalls::getProcessId(),
|
2021-06-23 00:07:47 +08:00
|
|
|
this->getRootDeviceIndex(),
|
|
|
|
this->osContext->getDeviceBitfield().to_ulong(),
|
|
|
|
this->osContext->getEngineType(),
|
|
|
|
EngineHelpers::engineTypeToString(this->osContext->getEngineType()).c_str(),
|
|
|
|
EngineHelpers::engineUsageToString(this->osContext->getEngineUsage()).c_str());
|
2020-04-30 19:24:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
void CommandStreamReceiver::checkForNewResources(TaskCountType submittedTaskCount, TaskCountType allocationTaskCount, GraphicsAllocation &gfxAllocation) {
|
2020-09-22 22:29:34 +08:00
|
|
|
if (useNewResourceImplicitFlush) {
|
2020-11-13 02:53:30 +08:00
|
|
|
if (allocationTaskCount == GraphicsAllocation::objectNotUsed && !GraphicsAllocation::isIsaAllocationType(gfxAllocation.getAllocationType())) {
|
2020-09-22 22:29:34 +08:00
|
|
|
newResources = true;
|
2023-11-30 16:32:25 +08:00
|
|
|
if (debugManager.flags.ProvideVerboseImplicitFlush.get()) {
|
2020-09-22 22:29:34 +08:00
|
|
|
printf("New resource detected of type %llu\n", static_cast<unsigned long long>(gfxAllocation.getAllocationType()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CommandStreamReceiver::checkImplicitFlushForGpuIdle() {
|
|
|
|
if (useGpuIdleImplicitFlush) {
|
2023-01-16 21:58:53 +08:00
|
|
|
if (this->taskCount == *getTagAddress()) {
|
2020-09-22 22:29:34 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
void CommandStreamReceiver::downloadTagAllocation(TaskCountType taskCountToWait) {
|
2022-03-29 23:31:51 +08:00
|
|
|
if (this->getTagAllocation()) {
|
2022-04-13 00:07:22 +08:00
|
|
|
if (taskCountToWait && taskCountToWait <= this->peekLatestFlushedTaskCount()) {
|
|
|
|
this->downloadAllocation(*this->getTagAllocation());
|
|
|
|
}
|
2022-03-29 23:31:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
bool CommandStreamReceiver::testTaskCountReady(volatile TagAddressType *pollAddress, TaskCountType taskCountToWait) {
|
2022-04-13 00:07:22 +08:00
|
|
|
this->downloadTagAllocation(taskCountToWait);
|
2021-10-13 06:08:25 +08:00
|
|
|
for (uint32_t i = 0; i < activePartitions; i++) {
|
2022-03-17 17:43:17 +08:00
|
|
|
if (!WaitUtils::waitFunction(pollAddress, taskCountToWait)) {
|
2021-10-13 06:08:25 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-06 23:11:09 +08:00
|
|
|
pollAddress = ptrOffset(pollAddress, this->immWritePostSyncWriteOffset);
|
2021-10-13 06:08:25 +08:00
|
|
|
}
|
2023-07-25 16:51:03 +08:00
|
|
|
|
|
|
|
downloadAllocations();
|
|
|
|
|
2021-10-13 06:08:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-12 03:41:57 +08:00
|
|
|
const HardwareInfo &CommandStreamReceiver::peekHwInfo() const {
|
2022-04-19 22:44:06 +08:00
|
|
|
return *peekRootDeviceEnvironment().getHardwareInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
const RootDeviceEnvironment &CommandStreamReceiver::peekRootDeviceEnvironment() const {
|
|
|
|
return *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex];
|
2022-01-12 03:41:57 +08:00
|
|
|
}
|
|
|
|
|
2022-12-09 22:37:32 +08:00
|
|
|
const GfxCoreHelper &CommandStreamReceiver::getGfxCoreHelper() const {
|
|
|
|
return peekRootDeviceEnvironment().getHelper<GfxCoreHelper>();
|
|
|
|
}
|
|
|
|
|
2022-12-15 20:13:57 +08:00
|
|
|
const ProductHelper &CommandStreamReceiver::getProductHelper() const {
|
|
|
|
return peekRootDeviceEnvironment().getHelper<ProductHelper>();
|
|
|
|
}
|
|
|
|
|
2023-05-12 22:49:39 +08:00
|
|
|
const ReleaseHelper *CommandStreamReceiver::getReleaseHelper() const {
|
|
|
|
return peekRootDeviceEnvironment().getReleaseHelper();
|
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
TaskCountType CommandStreamReceiver::getCompletionValue(const GraphicsAllocation &gfxAllocation) {
|
2022-04-26 21:29:31 +08:00
|
|
|
if (completionFenceValuePointer) {
|
|
|
|
return *completionFenceValuePointer;
|
|
|
|
}
|
2022-04-20 19:26:46 +08:00
|
|
|
auto osContextId = osContext->getContextId();
|
|
|
|
return gfxAllocation.getTaskCount(osContextId);
|
|
|
|
}
|
|
|
|
|
2022-04-25 22:54:13 +08:00
|
|
|
bool CommandStreamReceiver::createPerDssBackedBuffer(Device &device) {
|
|
|
|
UNRECOVERABLE_IF(perDssBackedBuffer != nullptr);
|
|
|
|
auto size = RayTracingHelper::getTotalMemoryBackedFifoSize(device);
|
|
|
|
|
2023-12-11 22:24:36 +08:00
|
|
|
perDssBackedBuffer = getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, size, AllocationType::buffer, device.getDeviceBitfield()});
|
2022-04-25 22:54:13 +08:00
|
|
|
|
|
|
|
return perDssBackedBuffer != nullptr;
|
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
void CommandStreamReceiver::printTagAddressContent(TaskCountType taskCountToWait, int64_t waitTimeout, bool start) {
|
2022-04-22 01:41:33 +08:00
|
|
|
auto postSyncAddress = getTagAddress();
|
|
|
|
if (start) {
|
|
|
|
PRINT_DEBUG_STRING(true, stdout,
|
2022-11-29 17:35:05 +08:00
|
|
|
"\nWaiting for task count %llu at location %p with timeout %llx. Current value:",
|
2022-04-22 01:41:33 +08:00
|
|
|
taskCountToWait, postSyncAddress, waitTimeout);
|
|
|
|
} else {
|
|
|
|
PRINT_DEBUG_STRING(true, stdout,
|
|
|
|
"%s", "\nWaiting completed. Current value:");
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < activePartitions; i++) {
|
|
|
|
PRINT_DEBUG_STRING(true, stdout, " %u", *postSyncAddress);
|
2023-06-06 23:11:09 +08:00
|
|
|
postSyncAddress = ptrOffset(postSyncAddress, this->immWritePostSyncWriteOffset);
|
2022-04-22 01:41:33 +08:00
|
|
|
}
|
|
|
|
PRINT_DEBUG_STRING(true, stdout, "%s", "\n");
|
|
|
|
}
|
|
|
|
|
2022-12-22 19:31:28 +08:00
|
|
|
bool CommandStreamReceiver::isTbxMode() const {
|
2024-04-09 20:43:12 +08:00
|
|
|
return (getType() == NEO::CommandStreamReceiverType::tbx || getType() == NEO::CommandStreamReceiverType::tbxWithAub);
|
2022-12-22 19:31:28 +08:00
|
|
|
}
|
|
|
|
|
2022-11-22 21:53:59 +08:00
|
|
|
TaskCountType CompletionStamp::getTaskCountFromSubmissionStatusError(SubmissionStatus status) {
|
2022-11-05 01:02:46 +08:00
|
|
|
switch (status) {
|
2023-12-13 17:17:24 +08:00
|
|
|
case SubmissionStatus::outOfHostMemory:
|
2022-11-05 01:02:46 +08:00
|
|
|
return CompletionStamp::outOfHostMemory;
|
2023-12-13 17:17:24 +08:00
|
|
|
case SubmissionStatus::outOfMemory:
|
2022-11-05 01:02:46 +08:00
|
|
|
return CompletionStamp::outOfDeviceMemory;
|
2023-12-13 17:17:24 +08:00
|
|
|
case SubmissionStatus::failed:
|
2023-03-13 10:56:47 +08:00
|
|
|
return CompletionStamp::failed;
|
2023-12-13 17:17:24 +08:00
|
|
|
case SubmissionStatus::unsupported:
|
2023-06-29 02:05:36 +08:00
|
|
|
return CompletionStamp::unsupported;
|
2022-11-05 01:02:46 +08:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2023-02-06 18:12:34 +08:00
|
|
|
uint64_t CommandStreamReceiver::getBarrierCountGpuAddress() const { return ptrOffset(this->tagAllocation->getGpuAddress(), TagAllocationLayout::barrierCountOffset); }
|
2022-12-06 15:32:34 +08:00
|
|
|
uint64_t CommandStreamReceiver::getDebugPauseStateGPUAddress() const { return tagAllocation->getGpuAddress() + TagAllocationLayout::debugPauseStateAddressOffset; }
|
|
|
|
uint64_t CommandStreamReceiver::getCompletionAddress() const {
|
|
|
|
uint64_t completionFenceAddress = castToUint64(const_cast<TagAddressType *>(tagAddress));
|
|
|
|
if (completionFenceAddress == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
completionFenceAddress += TagAllocationLayout::completionFenceOffset;
|
|
|
|
return completionFenceAddress;
|
|
|
|
}
|
2023-01-18 01:04:14 +08:00
|
|
|
|
2023-03-07 04:33:50 +08:00
|
|
|
void CommandStreamReceiver::createGlobalStatelessHeap() {
|
|
|
|
if (this->globalStatelessHeapAllocation == nullptr) {
|
|
|
|
auto lock = obtainUniqueOwnership();
|
|
|
|
if (this->globalStatelessHeapAllocation == nullptr) {
|
|
|
|
constexpr size_t heapSize = 16 * MemoryConstants::kiloByte;
|
2023-12-11 22:24:36 +08:00
|
|
|
constexpr AllocationType allocationType = AllocationType::linearStream;
|
2023-03-07 04:33:50 +08:00
|
|
|
|
|
|
|
AllocationProperties properties{rootDeviceIndex, true, heapSize, allocationType,
|
|
|
|
isMultiOsContextCapable(), false, osContext->getDeviceBitfield()};
|
|
|
|
|
|
|
|
this->globalStatelessHeapAllocation = getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
|
|
|
|
|
|
|
|
this->globalStatelessHeap = std::make_unique<IndirectHeap>(this->globalStatelessHeapAllocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-31 04:03:12 +08:00
|
|
|
bool CommandStreamReceiver::isRayTracingStateProgramingNeeded(Device &device) const {
|
|
|
|
return device.getRTMemoryBackedBuffer() && getBtdCommandDirty();
|
|
|
|
}
|
|
|
|
|
2023-09-25 15:58:39 +08:00
|
|
|
void CommandStreamReceiver::registerClient(void *client) {
|
|
|
|
std::unique_lock<MutexType> lock(registeredClientsMutex);
|
|
|
|
auto element = std::find(registeredClients.begin(), registeredClients.end(), client);
|
|
|
|
if (element == registeredClients.end()) {
|
|
|
|
registeredClients.push_back(client);
|
|
|
|
numClients++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandStreamReceiver::unregisterClient(void *client) {
|
|
|
|
std::unique_lock<MutexType> lock(registeredClientsMutex);
|
|
|
|
|
|
|
|
auto element = std::find(registeredClients.begin(), registeredClients.end(), client);
|
|
|
|
if (element != registeredClients.end()) {
|
|
|
|
registeredClients.erase(element);
|
|
|
|
numClients--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-18 01:04:14 +08:00
|
|
|
std::function<void()> CommandStreamReceiver::debugConfirmationFunction = []() { std::cin.get(); };
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|