2020-01-15 17:02:47 +01:00
/*
2022-02-04 13:59:01 +00:00
* Copyright (C) 2020-2022 Intel Corporation
2020-01-15 17:02:47 +01:00
*
* SPDX-License-Identifier: MIT
*
*/
2020-02-23 22:44:01 +01:00
#include "shared/source/command_container/command_encoder.h"
2022-04-06 14:41:45 +00:00
#include "shared/source/command_stream/command_stream_receiver.h"
2020-02-23 22:44:01 +01:00
#include "shared/source/command_stream/submissions_aggregator.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/device/device.h"
#include "shared/source/direct_submission/direct_submission_hw.h"
2020-03-27 16:32:07 +01:00
#include "shared/source/direct_submission/direct_submission_hw_diagnostic_mode.h"
2022-11-16 17:24:04 +00:00
#include "shared/source/direct_submission/relaxed_ordering_helper.h"
2020-02-23 22:44:01 +01:00
#include "shared/source/helpers/flush_stamp.h"
2022-06-23 09:44:45 +00:00
#include "shared/source/helpers/logical_state_helper.h"
2020-02-23 22:44:01 +01:00
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/memory_manager/allocation_properties.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/memory_manager/memory_manager.h"
2020-07-17 11:28:59 +02:00
#include "shared/source/memory_manager/memory_operations_handler.h"
2022-04-06 14:41:45 +00:00
#include "shared/source/os_interface/hw_info_config.h"
2020-02-23 22:44:01 +01:00
#include "shared/source/os_interface/os_context.h"
#include "shared/source/utilities/cpu_info.h"
#include "shared/source/utilities/cpuintrinsics.h"
2020-01-15 17:02:47 +01:00
2021-06-05 12:09:29 +02:00
#include "create_direct_submission_hw.inl"
2020-01-15 17:02:47 +01:00
#include <cstring>
namespace NEO {
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
2022-04-20 13:55:31 +00:00
DirectSubmissionHw<GfxFamily, Dispatcher>::DirectSubmissionHw(const DirectSubmissionInputParams &inputParams)
2022-06-01 10:05:07 +00:00
: ringBuffers(RingBufferUse::initialRingBufferCount), osContext(inputParams.osContext), rootDeviceIndex(inputParams.rootDeviceIndex) {
2022-04-20 13:55:31 +00:00
memoryManager = inputParams.memoryManager;
globalFenceAllocation = inputParams.globalFenceAllocation;
2022-06-23 09:44:45 +00:00
logicalStateHelper = inputParams.logicalStateHelper;
2022-04-20 13:55:31 +00:00
hwInfo = inputParams.rootDeviceEnvironment.getHardwareInfo();
memoryOperationHandler = inputParams.rootDeviceEnvironment.memoryOperationsInterface.get();
2022-04-06 14:41:45 +00:00
auto hwInfoConfig = HwInfoConfig::get(hwInfo->platform.eProductFamily);
2020-01-15 17:02:47 +01:00
2020-09-22 17:49:06 +02:00
disableCacheFlush = UllsDefaults::defaultDisableCacheFlush;
disableMonitorFence = UllsDefaults::defaultDisableMonitorFence;
2022-06-01 10:05:07 +00:00
if (DebugManager.flags.DirectSubmissionMaxRingBuffers.get() != -1) {
this->maxRingBufferCount = DebugManager.flags.DirectSubmissionMaxRingBuffers.get();
}
2020-09-22 17:49:06 +02:00
if (DebugManager.flags.DirectSubmissionDisableCacheFlush.get() != -1) {
disableCacheFlush = !!DebugManager.flags.DirectSubmissionDisableCacheFlush.get();
}
2020-03-27 16:32:07 +01:00
2022-07-05 10:25:16 +00:00
miMemFenceRequired = hwInfoConfig->isGlobalFenceInDirectSubmissionRequired(*hwInfo);
2022-04-06 14:41:45 +00:00
if (DebugManager.flags.DirectSubmissionInsertExtraMiMemFenceCommands.get() == 0) {
miMemFenceRequired = false;
}
2022-04-06 11:32:56 +00:00
if (DebugManager.flags.DirectSubmissionInsertSfenceInstructionPriorToSubmission.get() != -1) {
sfenceMode = static_cast<DirectSubmissionSfenceMode>(DebugManager.flags.DirectSubmissionInsertSfenceInstructionPriorToSubmission.get());
}
2020-01-15 17:02:47 +01:00
int32_t disableCacheFlushKey = DebugManager.flags.DirectSubmissionDisableCpuCacheFlush.get();
if (disableCacheFlushKey != -1) {
disableCpuCacheFlush = disableCacheFlushKey == 1 ? true : false;
}
2021-11-03 12:05:33 +00:00
2022-08-10 11:52:06 +00:00
isDisablePrefetcherRequired = hwInfoConfig->isPrefetcherDisablingInDirectSubmissionRequired();
if (DebugManager.flags.DirectSubmissionDisablePrefetcher.get() != -1) {
isDisablePrefetcherRequired = !!DebugManager.flags.DirectSubmissionDisablePrefetcher.get();
}
2021-11-03 12:05:33 +00:00
UNRECOVERABLE_IF(!CpuInfo::getInstance().isFeatureSupported(CpuInfo::featureClflush) && !disableCpuCacheFlush);
2020-03-27 16:32:07 +01:00
createDiagnostic();
2021-11-30 14:41:26 +00:00
setPostSyncOffset();
2022-10-11 18:47:13 +00:00
dcFlushRequired = MemorySynchronizationCommands<GfxFamily>::getDcFlushEnable(true, *hwInfo);
2022-11-16 17:24:04 +00:00
relaxedOrderingEnabled = (DebugManager.flags.DirectSubmissionRelaxedOrdering.get() == 1);
2020-01-15 17:02:47 +01:00
}
2022-11-18 09:56:59 +00:00
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchRelaxedOrderingSchedulerSection(uint32_t value) {
uint64_t schedulerStartAddress = getCommandBufferPositionGpuAddress(ringCommandStream.getSpace(0));
uint64_t deferredTasksListGpuVa = deferredTasksListAllocation->getGpuAddress();
// 1. Init section
{
EncodeMiPredicate<GfxFamily>::encode(ringCommandStream, MiPredicateType::Disable);
EncodeBatchBufferStartOrEnd<GfxFamily>::programConditionalDataRegBatchBufferStart(ringCommandStream,
schedulerStartAddress + RelaxedOrderingHelper::SchedulerSizeAndOffsetSection<GfxFamily>::semaphoreSectionStart,
CS_GPR_R1, 0, CompareOperation::Equal, false);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R2, 0, true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R2 + 4, 0, true);
uint64_t removeTaskVa = schedulerStartAddress + RelaxedOrderingHelper::SchedulerSizeAndOffsetSection<GfxFamily>::removeTaskSectionStart;
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R3, static_cast<uint32_t>(removeTaskVa & 0xFFFF'FFFFULL), true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R3 + 4, static_cast<uint32_t>(removeTaskVa >> 32), true);
uint64_t walkersLoopConditionCheckVa = schedulerStartAddress + RelaxedOrderingHelper::SchedulerSizeAndOffsetSection<GfxFamily>::tasksListLoopCheckSectionStart;
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R4, static_cast<uint32_t>(walkersLoopConditionCheckVa & 0xFFFF'FFFFULL), true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R4 + 4, static_cast<uint32_t>(walkersLoopConditionCheckVa >> 32), true);
}
// 2. Dispatch task section (loop start)
{
EncodeMiPredicate<GfxFamily>::encode(ringCommandStream, MiPredicateType::Disable);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R6, 8, true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R6 + 4, 0, true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R8, static_cast<uint32_t>(deferredTasksListGpuVa & 0xFFFF'FFFFULL), true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R8 + 4, static_cast<uint32_t>(deferredTasksListGpuVa >> 32), true);
EncodeAluHelper<GfxFamily, 10> aluHelper;
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCA, AluRegisters::R_2);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCB, AluRegisters::R_6);
aluHelper.setNextAlu(AluRegisters::OPCODE_SHL);
aluHelper.setNextAlu(AluRegisters::OPCODE_STORE, AluRegisters::R_7, AluRegisters::R_ACCU);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCA, AluRegisters::R_7);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCB, AluRegisters::R_8);
aluHelper.setNextAlu(AluRegisters::OPCODE_ADD);
aluHelper.setNextAlu(AluRegisters::OPCODE_STORE, AluRegisters::R_6, AluRegisters::R_ACCU);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOADIND, AluRegisters::R_0, AluRegisters::R_ACCU);
aluHelper.setNextAlu(AluRegisters::OPCODE_FENCE_RD);
aluHelper.copyToCmdStream(ringCommandStream);
EncodeBatchBufferStartOrEnd<GfxFamily>::programBatchBufferStart(&ringCommandStream, 0, false, true, false);
}
// 3. Remove task section
{
EncodeMiPredicate<GfxFamily>::encode(ringCommandStream, MiPredicateType::Disable);
EncodeMathMMIO<GfxFamily>::encodeDecrement(ringCommandStream, AluRegisters::R_1);
EncodeMathMMIO<GfxFamily>::encodeDecrement(ringCommandStream, AluRegisters::R_2);
EncodeBatchBufferStartOrEnd<GfxFamily>::programConditionalDataRegBatchBufferStart(ringCommandStream,
schedulerStartAddress + RelaxedOrderingHelper::SchedulerSizeAndOffsetSection<GfxFamily>::semaphoreSectionStart,
CS_GPR_R1, 0, CompareOperation::Equal, false);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R7, 8, true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R7 + 4, 0, true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R8, static_cast<uint32_t>(deferredTasksListGpuVa & 0xFFFF'FFFFULL), true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R8 + 4, static_cast<uint32_t>(deferredTasksListGpuVa >> 32), true);
EncodeAluHelper<GfxFamily, 14> aluHelper;
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCA, AluRegisters::R_1);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCB, AluRegisters::R_7);
aluHelper.setNextAlu(AluRegisters::OPCODE_SHL);
aluHelper.setNextAlu(AluRegisters::OPCODE_STORE, AluRegisters::R_7, AluRegisters::R_ACCU);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCA, AluRegisters::R_7);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCB, AluRegisters::R_8);
aluHelper.setNextAlu(AluRegisters::OPCODE_ADD);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOADIND, AluRegisters::R_7, AluRegisters::R_ACCU);
aluHelper.setNextAlu(AluRegisters::OPCODE_FENCE_RD);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCA, AluRegisters::R_6);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD0, AluRegisters::R_SRCB, AluRegisters::OPCODE_NONE);
aluHelper.setNextAlu(AluRegisters::OPCODE_ADD);
aluHelper.setNextAlu(AluRegisters::OPCODE_STOREIND, AluRegisters::R_ACCU, AluRegisters::R_7);
aluHelper.setNextAlu(AluRegisters::OPCODE_FENCE_WR);
aluHelper.copyToCmdStream(ringCommandStream);
}
// 4. List loop check section
{
EncodeMiPredicate<GfxFamily>::encode(ringCommandStream, MiPredicateType::Disable);
EncodeMathMMIO<GfxFamily>::encodeIncrement(ringCommandStream, AluRegisters::R_2);
EncodeBatchBufferStartOrEnd<GfxFamily>::programConditionalRegRegBatchBufferStart(ringCommandStream,
schedulerStartAddress + RelaxedOrderingHelper::SchedulerSizeAndOffsetSection<GfxFamily>::loopStartSectionStart,
AluRegisters::R_1, AluRegisters::R_2, CompareOperation::NotEqual, false);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R2, 0, true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R2 + 4, 0, true);
}
// 5. Drain request section
{
*ringCommandStream.getSpaceForCmd<typename GfxFamily::MI_ARB_CHECK>() = GfxFamily::cmdInitArbCheck;
EncodeBatchBufferStartOrEnd<GfxFamily>::programConditionalDataRegBatchBufferStart(ringCommandStream,
schedulerStartAddress + RelaxedOrderingHelper::SchedulerSizeAndOffsetSection<GfxFamily>::loopStartSectionStart,
CS_GPR_R5, 1, CompareOperation::Equal, false);
}
// 6. Scheduler loop check section
{
EncodeBatchBufferStartOrEnd<GfxFamily>::programConditionalDataMemBatchBufferStart(ringCommandStream, schedulerStartAddress + RelaxedOrderingHelper::SchedulerSizeAndOffsetSection<GfxFamily>::endSectionStart,
semaphoreGpuVa, value, CompareOperation::GreaterOrEqual, false);
EncodeBatchBufferStartOrEnd<GfxFamily>::programBatchBufferStart(&ringCommandStream, schedulerStartAddress + RelaxedOrderingHelper::SchedulerSizeAndOffsetSection<GfxFamily>::loopStartSectionStart, false, false, false);
}
// 7. Semaphore section
{
using MI_SEMAPHORE_WAIT = typename GfxFamily::MI_SEMAPHORE_WAIT;
using COMPARE_OPERATION = typename GfxFamily::MI_SEMAPHORE_WAIT::COMPARE_OPERATION;
EncodeMiPredicate<GfxFamily>::encode(ringCommandStream, MiPredicateType::Disable);
EncodeSempahore<GfxFamily>::addMiSemaphoreWaitCommand(ringCommandStream,
semaphoreGpuVa,
value,
COMPARE_OPERATION::COMPARE_OPERATION_SAD_GREATER_THAN_OR_EQUAL_SDD);
}
// 8. End section
{
EncodeMiPredicate<GfxFamily>::encode(ringCommandStream, MiPredicateType::Disable);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R5, 0, true);
}
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
2020-03-27 16:32:07 +01:00
DirectSubmissionHw<GfxFamily, Dispatcher>::~DirectSubmissionHw() = default;
2020-01-15 17:02:47 +01:00
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
bool DirectSubmissionHw<GfxFamily, Dispatcher>::allocateResources() {
2020-01-15 17:02:47 +01:00
DirectSubmissionAllocations allocations;
bool isMultiOsContextCapable = osContext.getNumSupportedDevices() > 1u;
constexpr size_t minimumRequiredSize = 256 * MemoryConstants::kiloByte;
constexpr size_t additionalAllocationSize = MemoryConstants::pageSize;
const auto allocationSize = alignUp(minimumRequiredSize + additionalAllocationSize, MemoryConstants::pageSize64k);
2022-04-20 13:55:31 +00:00
const AllocationProperties commandStreamAllocationProperties{rootDeviceIndex,
2020-01-15 17:02:47 +01:00
true, allocationSize,
2022-02-04 13:59:01 +00:00
AllocationType::RING_BUFFER,
2022-03-16 18:41:29 +00:00
isMultiOsContextCapable, false, osContext.getDeviceBitfield()};
2020-01-15 17:02:47 +01:00
2022-06-01 10:05:07 +00:00
for (uint32_t ringBufferIndex = 0; ringBufferIndex < RingBufferUse::initialRingBufferCount; ringBufferIndex++) {
auto ringBuffer = memoryManager->allocateGraphicsMemoryWithProperties(commandStreamAllocationProperties);
this->ringBuffers[ringBufferIndex].ringBuffer = ringBuffer;
UNRECOVERABLE_IF(ringBuffer == nullptr);
allocations.push_back(ringBuffer);
memset(ringBuffer->getUnderlyingBuffer(), 0, allocationSize);
}
2020-01-15 17:02:47 +01:00
2022-04-20 13:55:31 +00:00
const AllocationProperties semaphoreAllocationProperties{rootDeviceIndex,
2020-01-15 17:02:47 +01:00
true, MemoryConstants::pageSize,
2022-02-04 13:59:01 +00:00
AllocationType::SEMAPHORE_BUFFER,
2022-03-16 18:41:29 +00:00
isMultiOsContextCapable, false, osContext.getDeviceBitfield()};
2020-01-15 17:02:47 +01:00
semaphores = memoryManager->allocateGraphicsMemoryWithProperties(semaphoreAllocationProperties);
UNRECOVERABLE_IF(semaphores == nullptr);
allocations.push_back(semaphores);
2021-10-12 21:28:34 +00:00
if (this->workPartitionAllocation != nullptr) {
allocations.push_back(workPartitionAllocation);
}
2022-04-20 17:32:39 +00:00
if (completionFenceAllocation != nullptr) {
allocations.push_back(completionFenceAllocation);
}
2022-11-16 17:24:04 +00:00
if (this->relaxedOrderingEnabled) {
const AllocationProperties allocationProperties(rootDeviceIndex,
true, MemoryConstants::pageSize64k,
AllocationType::DEFERRED_TASKS_LIST,
isMultiOsContextCapable, false, osContext.getDeviceBitfield());
deferredTasksListAllocation = memoryManager->allocateGraphicsMemoryWithProperties(allocationProperties);
UNRECOVERABLE_IF(deferredTasksListAllocation == nullptr);
allocations.push_back(deferredTasksListAllocation);
}
2021-11-23 11:16:29 +00:00
if (DebugManager.flags.DirectSubmissionPrintBuffers.get()) {
2022-06-01 10:05:07 +00:00
for (uint32_t ringBufferIndex = 0; ringBufferIndex < RingBufferUse::initialRingBufferCount; ringBufferIndex++) {
const auto ringBuffer = this->ringBuffers[ringBufferIndex].ringBuffer;
printf("Ring buffer %u - gpu address: %" PRIx64 " - %" PRIx64 ", cpu address: %p - %p, size: %zu \n",
ringBufferIndex,
ringBuffer->getGpuAddress(),
ptrOffset(ringBuffer->getGpuAddress(), ringBuffer->getUnderlyingBufferSize()),
ringBuffer->getUnderlyingBuffer(),
ptrOffset(ringBuffer->getUnderlyingBuffer(), ringBuffer->getUnderlyingBufferSize()),
ringBuffer->getUnderlyingBufferSize());
}
2021-11-23 11:16:29 +00:00
}
2020-01-15 17:02:47 +01:00
handleResidency();
2022-06-01 10:05:07 +00:00
ringCommandStream.replaceBuffer(this->ringBuffers[0u].ringBuffer->getUnderlyingBuffer(), minimumRequiredSize);
ringCommandStream.replaceGraphicsAllocation(this->ringBuffers[0].ringBuffer);
2020-01-15 17:02:47 +01:00
semaphorePtr = semaphores->getUnderlyingBuffer();
semaphoreGpuVa = semaphores->getGpuAddress();
semaphoreData = static_cast<volatile RingSemaphoreData *>(semaphorePtr);
memset(semaphorePtr, 0, sizeof(RingSemaphoreData));
semaphoreData->QueueWorkCount = 0;
cpuCachelineFlush(semaphorePtr, MemoryConstants::cacheLineSize);
2020-08-18 13:54:23 +02:00
workloadModeOneStoreAddress = static_cast<volatile void *>(&semaphoreData->DiagnosticModeCounter);
2020-03-27 16:32:07 +01:00
*static_cast<volatile uint32_t *>(workloadModeOneStoreAddress) = 0u;
2020-07-17 11:28:59 +02:00
2021-09-27 23:27:46 +00:00
this->gpuVaForMiFlush = this->semaphoreGpuVa + offsetof(RingSemaphoreData, miFlushSpace);
2021-07-29 06:40:42 +00:00
2020-07-17 11:28:59 +02:00
auto ret = makeResourcesResident(allocations);
return ret && allocateOsResources();
}
template <typename GfxFamily, typename Dispatcher>
bool DirectSubmissionHw<GfxFamily, Dispatcher>::makeResourcesResident(DirectSubmissionAllocations &allocations) {
2022-04-20 13:55:31 +00:00
auto ret = memoryOperationHandler->makeResidentWithinOsContext(&this->osContext, ArrayRef<GraphicsAllocation *>(allocations), false) == MemoryOperationsStatus::SUCCESS;
2020-07-17 11:28:59 +02:00
return ret;
2020-01-15 17:02:47 +01:00
}
2022-11-09 14:43:02 +00:00
template <typename GfxFamily, typename Dispatcher>
inline void DirectSubmissionHw<GfxFamily, Dispatcher>::unblockGpu() {
if (sfenceMode >= DirectSubmissionSfenceMode::BeforeSemaphoreOnly) {
CpuIntrinsics::sfence();
}
semaphoreData->QueueWorkCount = currentQueueWorkCount;
if (sfenceMode == DirectSubmissionSfenceMode::BeforeAndAfterSemaphore) {
CpuIntrinsics::sfence();
}
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
inline void DirectSubmissionHw<GfxFamily, Dispatcher>::cpuCachelineFlush(void *ptr, size_t size) {
2020-01-15 17:02:47 +01:00
if (disableCpuCacheFlush) {
return;
}
constexpr size_t cachlineBit = 6;
static_assert(MemoryConstants::cacheLineSize == 1 << cachlineBit, "cachlineBit has invalid value");
char *flushPtr = reinterpret_cast<char *>(ptr);
char *flushEndPtr = reinterpret_cast<char *>(ptr) + size;
flushPtr = alignDown(flushPtr, MemoryConstants::cacheLineSize);
flushEndPtr = alignUp(flushEndPtr, MemoryConstants::cacheLineSize);
size_t cachelines = (flushEndPtr - flushPtr) >> cachlineBit;
for (size_t i = 0; i < cachelines; i++) {
CpuIntrinsics::clFlush(flushPtr);
flushPtr += MemoryConstants::cacheLineSize;
}
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
2021-12-22 19:28:02 +00:00
bool DirectSubmissionHw<GfxFamily, Dispatcher>::initialize(bool submitOnInit, bool useNotify) {
useNotifyForPostSync = useNotify;
2020-01-15 17:02:47 +01:00
bool ret = allocateResources();
2020-03-27 16:32:07 +01:00
initDiagnostic(submitOnInit);
2020-01-15 17:02:47 +01:00
if (ret && submitOnInit) {
2020-03-26 20:13:10 +01:00
size_t startBufferSize = Dispatcher::getSizePreemption() +
2022-11-18 09:56:59 +00:00
getSizeSemaphoreSection(true);
2021-10-26 11:53:01 +00:00
2020-03-26 20:13:10 +01:00
Dispatcher::dispatchPreemption(ringCommandStream);
2021-10-12 21:28:34 +00:00
if (this->partitionedMode) {
2021-11-17 19:51:43 +00:00
startBufferSize += getSizePartitionRegisterConfigurationSection();
dispatchPartitionRegisterConfiguration();
2021-10-26 11:53:01 +00:00
this->partitionConfigSet = true;
2021-10-12 21:28:34 +00:00
}
2022-04-06 14:41:45 +00:00
if (this->miMemFenceRequired) {
startBufferSize += getSizeSystemMemoryFenceAddress();
dispatchSystemMemoryFenceAddress();
this->systemMemoryFenceAddressSet = true;
}
2022-11-16 17:24:04 +00:00
if (this->relaxedOrderingEnabled) {
preinitializeTaskStoreSection();
2022-11-18 09:56:59 +00:00
initRelaxedOrderingRegisters();
startBufferSize += RelaxedOrderingHelper::getSizeRegistersInit<GfxFamily>();
2022-11-16 17:24:04 +00:00
this->relaxedOrderingInitialized = true;
}
2020-05-18 18:48:43 +02:00
if (workloadMode == 1) {
dispatchDiagnosticModeSection();
2020-08-18 13:54:23 +02:00
startBufferSize += getDiagnosticModeSection();
2020-05-18 18:48:43 +02:00
}
2022-11-18 09:56:59 +00:00
dispatchSemaphoreSection(currentQueueWorkCount, true);
2020-01-15 17:02:47 +01:00
ringStart = submit(ringCommandStream.getGraphicsAllocation()->getGpuAddress(), startBufferSize);
2020-03-27 16:32:07 +01:00
performDiagnosticMode();
2020-01-15 17:02:47 +01:00
return ringStart;
}
return ret;
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
bool DirectSubmissionHw<GfxFamily, Dispatcher>::startRingBuffer() {
2020-01-15 17:02:47 +01:00
if (ringStart) {
return true;
}
2021-08-25 15:19:44 +00:00
2022-11-18 09:56:59 +00:00
size_t startSize = getSizeSemaphoreSection(true);
2021-10-26 11:53:01 +00:00
if (!this->partitionConfigSet) {
2021-11-17 19:51:43 +00:00
startSize += getSizePartitionRegisterConfigurationSection();
2021-10-26 11:53:01 +00:00
}
2022-04-06 14:41:45 +00:00
if (this->miMemFenceRequired && !this->systemMemoryFenceAddressSet) {
startSize += getSizeSystemMemoryFenceAddress();
}
2022-11-18 09:56:59 +00:00
if (this->relaxedOrderingEnabled && !this->relaxedOrderingInitialized) {
startSize += RelaxedOrderingHelper::getSizeRegistersInit<GfxFamily>();
}
2022-04-06 14:41:45 +00:00
2020-01-15 17:02:47 +01:00
size_t requiredSize = startSize + getSizeDispatch() + getSizeEnd();
if (ringCommandStream.getAvailableSpace() < requiredSize) {
switchRingBuffers();
}
uint64_t gpuStartVa = getCommandBufferPositionGpuAddress(ringCommandStream.getSpace(0));
2021-10-26 11:53:01 +00:00
if (!this->partitionConfigSet) {
2021-11-17 19:51:43 +00:00
dispatchPartitionRegisterConfiguration();
2021-10-26 11:53:01 +00:00
this->partitionConfigSet = true;
}
2022-04-06 14:41:45 +00:00
if (this->miMemFenceRequired && !this->systemMemoryFenceAddressSet) {
dispatchSystemMemoryFenceAddress();
this->systemMemoryFenceAddressSet = true;
}
2022-11-16 17:24:04 +00:00
if (this->relaxedOrderingEnabled && !this->relaxedOrderingInitialized) {
preinitializeTaskStoreSection();
2022-11-18 09:56:59 +00:00
initRelaxedOrderingRegisters();
2022-11-16 17:24:04 +00:00
this->relaxedOrderingInitialized = true;
}
2020-01-15 17:02:47 +01:00
currentQueueWorkCount++;
2022-11-18 09:56:59 +00:00
dispatchSemaphoreSection(currentQueueWorkCount, true);
2020-01-15 17:02:47 +01:00
ringStart = submit(gpuStartVa, startSize);
2022-11-19 18:25:04 +00:00
firstSubmissionAfterRingStart = true;
2020-01-15 17:02:47 +01:00
return ringStart;
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
bool DirectSubmissionHw<GfxFamily, Dispatcher>::stopRingBuffer() {
2021-08-25 15:19:44 +00:00
if (!ringStart) {
return true;
}
2022-11-19 18:25:04 +00:00
if (this->relaxedOrderingEnabled && !firstSubmissionAfterRingStart) {
dispatchRelaxedOrderingQueueStall();
}
2020-01-15 17:02:47 +01:00
void *flushPtr = ringCommandStream.getSpace(0);
2021-07-29 06:40:42 +00:00
Dispatcher::dispatchCacheFlush(ringCommandStream, *hwInfo, gpuVaForMiFlush);
2020-03-23 10:14:50 +01:00
if (disableMonitorFence) {
2020-03-18 14:14:04 +01:00
TagData currentTagData = {};
getTagAddressValue(currentTagData);
2022-10-11 18:47:13 +00:00
Dispatcher::dispatchMonitorFence(ringCommandStream, currentTagData.tagAddress, currentTagData.tagValue, *hwInfo,
this->useNotifyForPostSync, this->partitionedMode, this->dcFlushRequired);
2020-03-18 14:14:04 +01:00
}
2020-03-27 16:32:07 +01:00
Dispatcher::dispatchStopCommandBuffer(ringCommandStream);
2021-07-30 09:56:58 +00:00
auto bytesToPad = Dispatcher::getSizeStartCommandBuffer() - Dispatcher::getSizeStopCommandBuffer();
2021-11-17 22:36:00 +00:00
EncodeNoop<GfxFamily>::emitNoop(ringCommandStream, bytesToPad);
EncodeNoop<GfxFamily>::alignToCacheLine(ringCommandStream);
2021-07-30 09:56:58 +00:00
2020-01-15 17:02:47 +01:00
cpuCachelineFlush(flushPtr, getSizeEnd());
2022-11-09 14:43:02 +00:00
this->unblockGpu();
2020-01-15 17:02:47 +01:00
cpuCachelineFlush(semaphorePtr, MemoryConstants::cacheLineSize);
2021-08-25 15:19:44 +00:00
this->handleStopRingBuffer();
2021-07-30 09:56:58 +00:00
this->ringStart = false;
2020-01-15 17:02:47 +01:00
return true;
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
2022-11-18 09:56:59 +00:00
inline void DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchSemaphoreSection(uint32_t value, bool firstSubmission) {
2020-01-15 17:02:47 +01:00
using MI_SEMAPHORE_WAIT = typename GfxFamily::MI_SEMAPHORE_WAIT;
using COMPARE_OPERATION = typename GfxFamily::MI_SEMAPHORE_WAIT::COMPARE_OPERATION;
2022-03-30 14:11:26 +00:00
2020-08-18 11:27:44 +02:00
dispatchDisablePrefetcher(true);
2022-11-18 09:56:59 +00:00
if (this->relaxedOrderingEnabled && !firstSubmission) {
dispatchRelaxedOrderingSchedulerSection(value);
} else {
EncodeSempahore<GfxFamily>::addMiSemaphoreWaitCommand(ringCommandStream,
semaphoreGpuVa,
value,
COMPARE_OPERATION::COMPARE_OPERATION_SAD_GREATER_THAN_OR_EQUAL_SDD);
}
2022-03-30 14:11:26 +00:00
2022-04-06 14:41:45 +00:00
if (miMemFenceRequired) {
2022-07-05 10:25:16 +00:00
MemorySynchronizationCommands<GfxFamily>::addAdditionalSynchronizationForDirectSubmission(ringCommandStream, this->gpuVaForAdditionalSynchronizationWA, true, *hwInfo);
2022-03-30 14:11:26 +00:00
}
2020-08-18 11:27:44 +02:00
dispatchPrefetchMitigation();
dispatchDisablePrefetcher(false);
2020-01-15 17:02:47 +01:00
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
2022-11-18 09:56:59 +00:00
inline size_t DirectSubmissionHw<GfxFamily, Dispatcher>::getSizeSemaphoreSection(bool firstSubmission) {
size_t semaphoreSize = (this->relaxedOrderingEnabled && !firstSubmission) ? RelaxedOrderingHelper::SchedulerSizeAndOffsetSection<GfxFamily>::totalSize
: EncodeSempahore<GfxFamily>::getSizeMiSemaphoreWait();
2020-08-18 11:27:44 +02:00
semaphoreSize += getSizePrefetchMitigation();
2022-08-10 11:52:06 +00:00
if (isDisablePrefetcherRequired) {
semaphoreSize += 2 * getSizeDisablePrefetcher();
}
2022-03-30 14:11:26 +00:00
2022-04-06 14:41:45 +00:00
if (miMemFenceRequired) {
2022-07-05 10:25:16 +00:00
semaphoreSize += MemorySynchronizationCommands<GfxFamily>::getSizeForSingleAdditionalSynchronizationForDirectSubmission(*hwInfo);
2022-03-30 14:11:26 +00:00
}
2020-08-18 11:27:44 +02:00
return semaphoreSize;
2020-01-15 17:02:47 +01:00
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
inline void DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchStartSection(uint64_t gpuStartAddress) {
Dispatcher::dispatchStartCommandBuffer(ringCommandStream, gpuStartAddress);
2020-01-15 17:02:47 +01:00
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
inline size_t DirectSubmissionHw<GfxFamily, Dispatcher>::getSizeStartSection() {
return Dispatcher::getSizeStartCommandBuffer();
2020-01-15 17:02:47 +01:00
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
inline void DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchSwitchRingBufferSection(uint64_t nextBufferGpuAddress) {
2021-03-29 12:23:38 +00:00
if (disableMonitorFence) {
TagData currentTagData = {};
getTagAddressValue(currentTagData);
2022-10-11 18:47:13 +00:00
Dispatcher::dispatchMonitorFence(ringCommandStream, currentTagData.tagAddress, currentTagData.tagValue, *hwInfo,
this->useNotifyForPostSync, this->partitionedMode, this->dcFlushRequired);
2021-03-29 12:23:38 +00:00
}
2020-03-26 20:13:10 +01:00
Dispatcher::dispatchStartCommandBuffer(ringCommandStream, nextBufferGpuAddress);
2020-01-15 17:02:47 +01:00
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
inline size_t DirectSubmissionHw<GfxFamily, Dispatcher>::getSizeSwitchRingBufferSection() {
2021-03-29 12:23:38 +00:00
size_t size = Dispatcher::getSizeStartCommandBuffer();
if (disableMonitorFence) {
size += Dispatcher::getSizeMonitorFence(*hwInfo);
}
return size;
2020-01-15 17:02:47 +01:00
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
inline size_t DirectSubmissionHw<GfxFamily, Dispatcher>::getSizeEnd() {
2020-03-27 16:32:07 +01:00
size_t size = Dispatcher::getSizeStopCommandBuffer() +
2021-07-30 09:56:58 +00:00
Dispatcher::getSizeCacheFlush(*hwInfo) +
(Dispatcher::getSizeStartCommandBuffer() - Dispatcher::getSizeStopCommandBuffer()) +
MemoryConstants::cacheLineSize;
2020-03-23 10:14:50 +01:00
if (disableMonitorFence) {
2020-03-27 16:32:07 +01:00
size += Dispatcher::getSizeMonitorFence(*hwInfo);
2020-03-18 14:14:04 +01:00
}
2022-11-19 18:25:04 +00:00
if (this->relaxedOrderingEnabled) {
size += getSizeDispatchRelaxedOrderingQueueStall();
}
2020-03-18 14:14:04 +01:00
return size;
2020-01-15 17:02:47 +01:00
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
inline uint64_t DirectSubmissionHw<GfxFamily, Dispatcher>::getCommandBufferPositionGpuAddress(void *position) {
2020-01-15 17:02:47 +01:00
void *currentBase = ringCommandStream.getCpuBase();
size_t offset = ptrDiff(position, currentBase);
return ringCommandStream.getGraphicsAllocation()->getGpuAddress() + static_cast<uint64_t>(offset);
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
inline size_t DirectSubmissionHw<GfxFamily, Dispatcher>::getSizeDispatch() {
2022-11-18 09:56:59 +00:00
size_t size = getSizeSemaphoreSection(false);
2020-03-23 10:14:50 +01:00
if (workloadMode == 0) {
2020-03-18 14:14:04 +01:00
size += getSizeStartSection();
2022-11-21 14:55:39 +00:00
if (this->relaxedOrderingEnabled) {
size += RelaxedOrderingHelper::getSizeReturnPtrRegs<GfxFamily>();
}
2020-03-23 10:14:50 +01:00
} else if (workloadMode == 1) {
2020-05-18 18:48:43 +02:00
size += getDiagnosticModeSection();
2020-03-18 14:14:04 +01:00
}
2022-11-16 17:24:04 +00:00
// mode 2 does not dispatch any commands
2020-03-18 14:14:04 +01:00
2020-03-23 10:14:50 +01:00
if (!disableCacheFlush) {
2020-03-27 16:32:07 +01:00
size += Dispatcher::getSizeCacheFlush(*hwInfo);
2020-03-18 14:14:04 +01:00
}
2020-03-23 10:14:50 +01:00
if (!disableMonitorFence) {
2020-03-27 16:32:07 +01:00
size += Dispatcher::getSizeMonitorFence(*hwInfo);
2020-03-18 14:14:04 +01:00
}
2021-04-14 14:40:23 +00:00
size += getSizeNewResourceHandler();
2020-03-18 14:14:04 +01:00
return size;
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
void *DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchWorkloadSection(BatchBuffer &batchBuffer) {
2020-03-18 14:14:04 +01:00
void *currentPosition = ringCommandStream.getSpace(0);
2020-03-23 10:14:50 +01:00
2021-11-23 11:16:29 +00:00
if (DebugManager.flags.DirectSubmissionPrintBuffers.get()) {
printf("Client buffer:\n");
printf("Command buffer allocation - gpu address: %" PRIx64 " - %" PRIx64 ", cpu address: %p - %p, size: %zu \n",
batchBuffer.commandBufferAllocation->getGpuAddress(),
ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.commandBufferAllocation->getUnderlyingBufferSize()),
batchBuffer.commandBufferAllocation->getUnderlyingBuffer(),
ptrOffset(batchBuffer.commandBufferAllocation->getUnderlyingBuffer(), batchBuffer.commandBufferAllocation->getUnderlyingBufferSize()),
batchBuffer.commandBufferAllocation->getUnderlyingBufferSize());
printf("Command buffer - start gpu address: %" PRIx64 " - %" PRIx64 ", start cpu address: %p - %p, start offset: %zu, used size: %zu \n",
ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset),
ptrOffset(ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset), batchBuffer.usedSize),
ptrOffset(batchBuffer.commandBufferAllocation->getUnderlyingBuffer(), batchBuffer.startOffset),
ptrOffset(ptrOffset(batchBuffer.commandBufferAllocation->getUnderlyingBuffer(), batchBuffer.startOffset), batchBuffer.usedSize),
batchBuffer.startOffset,
batchBuffer.usedSize);
}
2020-03-23 10:14:50 +01:00
if (workloadMode == 0) {
2020-03-18 14:14:04 +01:00
auto commandStreamAddress = ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset);
void *returnCmd = batchBuffer.endCmdPtr;
2022-11-21 14:55:39 +00:00
LinearStream relaxedOrderingReturnPtrCmdStream;
if (this->relaxedOrderingEnabled) {
// preallocate and patch after start section
auto relaxedOrderingReturnPtrCmds = ringCommandStream.getSpace(RelaxedOrderingHelper::getSizeReturnPtrRegs<GfxFamily>());
relaxedOrderingReturnPtrCmdStream.replaceBuffer(relaxedOrderingReturnPtrCmds, RelaxedOrderingHelper::getSizeReturnPtrRegs<GfxFamily>());
}
2020-03-18 14:14:04 +01:00
dispatchStartSection(commandStreamAddress);
void *returnPosition = ringCommandStream.getSpace(0);
2022-11-21 14:55:39 +00:00
uint64_t returnGpuPointer = getCommandBufferPositionGpuAddress(returnPosition);
2020-03-18 14:14:04 +01:00
2022-11-21 14:55:39 +00:00
if (this->relaxedOrderingEnabled) {
dispatchRelaxedOrderingReturnPtrRegs(relaxedOrderingReturnPtrCmdStream, returnGpuPointer);
} else {
setReturnAddress(returnCmd, returnGpuPointer);
}
2020-03-23 10:14:50 +01:00
} else if (workloadMode == 1) {
2020-03-27 16:32:07 +01:00
DirectSubmissionDiagnostics::diagnosticModeOneDispatch(diagnostic.get());
2020-05-18 18:48:43 +02:00
dispatchDiagnosticModeSection();
2020-03-18 14:14:04 +01:00
}
2022-11-16 17:24:04 +00:00
// mode 2 does not dispatch any commands
if (this->relaxedOrderingEnabled) {
2022-11-18 21:02:29 +00:00
dispatchTaskStoreSection(batchBuffer.taskStartAddress);
2022-11-16 17:24:04 +00:00
}
2020-03-18 14:14:04 +01:00
2020-03-23 10:14:50 +01:00
if (!disableCacheFlush) {
2021-07-29 06:40:42 +00:00
Dispatcher::dispatchCacheFlush(ringCommandStream, *hwInfo, gpuVaForMiFlush);
2020-03-18 14:14:04 +01:00
}
2020-03-23 10:14:50 +01:00
if (!disableMonitorFence) {
2020-03-18 14:14:04 +01:00
TagData currentTagData = {};
getTagAddressValue(currentTagData);
2022-10-11 18:47:13 +00:00
Dispatcher::dispatchMonitorFence(ringCommandStream, currentTagData.tagAddress, currentTagData.tagValue, *hwInfo,
this->useNotifyForPostSync, this->partitionedMode, this->dcFlushRequired);
2020-03-18 14:14:04 +01:00
}
2022-11-18 09:56:59 +00:00
dispatchSemaphoreSection(currentQueueWorkCount + 1, false);
2020-03-18 14:14:04 +01:00
return currentPosition;
}
2022-11-19 18:25:04 +00:00
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchRelaxedOrderingQueueStall() {
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R5, 1, true);
dispatchSemaphoreSection(currentQueueWorkCount, false);
}
template <typename GfxFamily, typename Dispatcher>
size_t DirectSubmissionHw<GfxFamily, Dispatcher>::getSizeDispatchRelaxedOrderingQueueStall() {
return getSizeSemaphoreSection(false) + sizeof(typename GfxFamily::MI_LOAD_REGISTER_IMM);
}
2022-11-21 14:55:39 +00:00
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchRelaxedOrderingReturnPtrRegs(LinearStream &cmdStream, uint64_t returnPtr) {
LriHelper<GfxFamily>::program(&cmdStream, CS_GPR_R4, static_cast<uint32_t>(returnPtr & 0xFFFF'FFFFULL), true);
LriHelper<GfxFamily>::program(&cmdStream, CS_GPR_R4 + 4, static_cast<uint32_t>(returnPtr >> 32), true);
uint64_t returnPtrAfterTaskStoreSection = returnPtr + RelaxedOrderingHelper::getSizeTaskStoreSection<GfxFamily>();
LriHelper<GfxFamily>::program(&cmdStream, CS_GPR_R3, static_cast<uint32_t>(returnPtrAfterTaskStoreSection & 0xFFFF'FFFFULL), true);
LriHelper<GfxFamily>::program(&cmdStream, CS_GPR_R3 + 4, static_cast<uint32_t>(returnPtrAfterTaskStoreSection >> 32), true);
}
2022-11-18 09:56:59 +00:00
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::initRelaxedOrderingRegisters() {
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R1, 0, true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R1 + 4, 0, true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R5, 0, true);
LriHelper<GfxFamily>::program(&ringCommandStream, CS_GPR_R5 + 4, 0, true);
}
2022-11-16 17:24:04 +00:00
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::preinitializeTaskStoreSection() {
preinitializedTaskStoreSection = std::make_unique<uint8_t[]>(RelaxedOrderingHelper::getSizeTaskStoreSection<GfxFamily>());
LinearStream stream(preinitializedTaskStoreSection.get(), RelaxedOrderingHelper::getSizeTaskStoreSection<GfxFamily>());
EncodeMiPredicate<GfxFamily>::encode(stream, MiPredicateType::Disable);
2022-11-18 21:02:29 +00:00
uint64_t deferredTasksListGpuVa = deferredTasksListAllocation->getGpuAddress();
LriHelper<GfxFamily>::program(&stream, CS_GPR_R6, static_cast<uint32_t>(deferredTasksListGpuVa & 0xFFFF'FFFFULL), true);
LriHelper<GfxFamily>::program(&stream, CS_GPR_R6 + 4, static_cast<uint32_t>(deferredTasksListGpuVa >> 32), true);
2022-11-16 17:24:04 +00:00
// Task start VA
LriHelper<GfxFamily>::program(&stream, CS_GPR_R7, 0, true);
LriHelper<GfxFamily>::program(&stream, CS_GPR_R7 + 4, 0, true);
// Shift by 8 = multiply by 256. Address must by 64b aligned (shift by 6), but SHL accepts only 1, 2, 4, 8, 16 and 32
LriHelper<GfxFamily>::program(&stream, CS_GPR_R8, 8, true);
LriHelper<GfxFamily>::program(&stream, CS_GPR_R8 + 4, 0, true);
EncodeAluHelper<GfxFamily, 9> aluHelper;
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCA, AluRegisters::R_1);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCB, AluRegisters::R_8);
aluHelper.setNextAlu(AluRegisters::OPCODE_SHL);
aluHelper.setNextAlu(AluRegisters::OPCODE_STORE, AluRegisters::R_8, AluRegisters::R_ACCU);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCA, AluRegisters::R_8);
aluHelper.setNextAlu(AluRegisters::OPCODE_LOAD, AluRegisters::R_SRCB, AluRegisters::R_6);
aluHelper.setNextAlu(AluRegisters::OPCODE_ADD);
aluHelper.setNextAlu(AluRegisters::OPCODE_STOREIND, AluRegisters::R_ACCU, AluRegisters::R_7);
aluHelper.setNextAlu(AluRegisters::OPCODE_FENCE_WR);
aluHelper.copyToCmdStream(stream);
EncodeMathMMIO<GfxFamily>::encodeIncrement(stream, AluRegisters::R_1);
UNRECOVERABLE_IF(stream.getUsed() != RelaxedOrderingHelper::getSizeTaskStoreSection<GfxFamily>());
}
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchTaskStoreSection(uint64_t taskStartSectionVa) {
using MI_LOAD_REGISTER_IMM = typename GfxFamily::MI_LOAD_REGISTER_IMM;
constexpr size_t patchOffset = EncodeMiPredicate<GfxFamily>::getCmdSize() + (2 * sizeof(MI_LOAD_REGISTER_IMM));
auto lri = reinterpret_cast<MI_LOAD_REGISTER_IMM *>(ptrOffset(preinitializedTaskStoreSection.get(), patchOffset));
lri->setDataDword(static_cast<uint32_t>(taskStartSectionVa & 0xFFFF'FFFFULL));
lri++;
lri->setDataDword(static_cast<uint32_t>(taskStartSectionVa >> 32));
auto dst = ringCommandStream.getSpace(RelaxedOrderingHelper::getSizeTaskStoreSection<GfxFamily>());
memcpy_s(dst, RelaxedOrderingHelper::getSizeTaskStoreSection<GfxFamily>(), preinitializedTaskStoreSection.get(), RelaxedOrderingHelper::getSizeTaskStoreSection<GfxFamily>());
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
bool DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchCommandBuffer(BatchBuffer &batchBuffer, FlushStampTracker &flushStamp) {
2022-11-16 17:24:04 +00:00
// for now workloads requiring cache coherency are not supported
2020-03-26 20:13:10 +01:00
UNRECOVERABLE_IF(batchBuffer.requiresCoherency);
2022-05-10 12:37:40 +00:00
if (batchBuffer.ringBufferRestartRequest) {
this->stopRingBuffer();
}
2021-07-30 09:56:58 +00:00
this->startRingBuffer();
2020-01-15 17:02:47 +01:00
size_t dispatchSize = getSizeDispatch();
size_t cycleSize = getSizeSwitchRingBufferSection();
size_t requiredMinimalSize = dispatchSize + cycleSize + getSizeEnd();
2022-11-16 17:24:04 +00:00
if (this->relaxedOrderingEnabled) {
2022-11-19 18:25:04 +00:00
if (batchBuffer.hasStallingCmds && !firstSubmissionAfterRingStart) {
requiredMinimalSize += getSizeDispatchRelaxedOrderingQueueStall();
}
2022-11-21 14:55:39 +00:00
requiredMinimalSize += RelaxedOrderingHelper::getSizeTaskStoreSection<GfxFamily>() + RelaxedOrderingHelper::getSizeReturnPtrRegs<GfxFamily>();
2022-11-16 17:24:04 +00:00
}
2020-01-15 17:02:47 +01:00
2021-09-27 23:27:46 +00:00
getCommandBufferPositionGpuAddress(ringCommandStream.getSpace(0));
2020-01-15 17:02:47 +01:00
if (ringCommandStream.getAvailableSpace() < requiredMinimalSize) {
2021-09-27 23:27:46 +00:00
switchRingBuffers();
2020-01-15 17:02:47 +01:00
}
2022-11-19 18:25:04 +00:00
if (this->relaxedOrderingEnabled && batchBuffer.hasStallingCmds && !firstSubmissionAfterRingStart) {
dispatchRelaxedOrderingQueueStall();
}
2021-04-14 14:40:23 +00:00
handleNewResourcesSubmission();
2020-03-18 14:14:04 +01:00
void *currentPosition = dispatchWorkloadSection(batchBuffer);
2020-01-15 17:02:47 +01:00
2021-07-30 09:56:58 +00:00
cpuCachelineFlush(currentPosition, dispatchSize);
handleResidency();
2020-01-15 17:02:47 +01:00
2022-03-25 18:13:00 +00:00
if (DebugManager.flags.DirectSubmissionReadBackCommandBuffer.get() == 1) {
volatile auto cmdBufferStart = reinterpret_cast<uint32_t *>(batchBuffer.commandBufferAllocation->getUnderlyingBuffer());
reserved = *cmdBufferStart;
}
if (DebugManager.flags.DirectSubmissionReadBackRingBuffer.get() == 1) {
volatile auto ringBufferStart = reinterpret_cast<uint32_t *>(ringCommandStream.getSpace(0));
reserved = *ringBufferStart;
}
2022-11-09 14:43:02 +00:00
this->unblockGpu();
2022-04-01 11:47:24 +00:00
2020-01-15 17:02:47 +01:00
cpuCachelineFlush(semaphorePtr, MemoryConstants::cacheLineSize);
currentQueueWorkCount++;
2020-03-27 16:32:07 +01:00
DirectSubmissionDiagnostics::diagnosticModeOneSubmit(diagnostic.get());
2021-07-30 09:56:58 +00:00
2020-01-15 17:02:47 +01:00
uint64_t flushValue = updateTagValue();
flushStamp.setStamp(flushValue);
2022-11-19 18:25:04 +00:00
firstSubmissionAfterRingStart = false;
2020-01-15 17:02:47 +01:00
return ringStart;
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
inline void DirectSubmissionHw<GfxFamily, Dispatcher>::setReturnAddress(void *returnCmd, uint64_t returnAddress) {
2020-01-15 17:02:47 +01:00
using MI_BATCH_BUFFER_START = typename GfxFamily::MI_BATCH_BUFFER_START;
2020-04-08 18:33:03 +02:00
MI_BATCH_BUFFER_START cmd = GfxFamily::cmdInitBatchBufferStart;
2021-12-16 18:02:45 +00:00
cmd.setBatchBufferStartAddress(returnAddress);
2020-04-08 18:33:03 +02:00
cmd.setAddressSpaceIndicator(MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT);
2020-01-15 17:02:47 +01:00
MI_BATCH_BUFFER_START *returnBBStart = static_cast<MI_BATCH_BUFFER_START *>(returnCmd);
2020-04-08 18:33:03 +02:00
*returnBBStart = cmd;
2020-01-15 17:02:47 +01:00
}
2020-08-18 11:27:44 +02:00
template <typename GfxFamily, typename Dispatcher>
2021-04-14 14:40:23 +00:00
inline void DirectSubmissionHw<GfxFamily, Dispatcher>::handleNewResourcesSubmission() {
}
template <typename GfxFamily, typename Dispatcher>
inline size_t DirectSubmissionHw<GfxFamily, Dispatcher>::getSizeNewResourceHandler() {
return 0u;
}
2020-07-17 11:28:59 +02:00
template <typename GfxFamily, typename Dispatcher>
inline uint64_t DirectSubmissionHw<GfxFamily, Dispatcher>::switchRingBuffers() {
GraphicsAllocation *nextRingBuffer = switchRingBuffersAllocations();
void *flushPtr = ringCommandStream.getSpace(0);
uint64_t currentBufferGpuVa = getCommandBufferPositionGpuAddress(flushPtr);
if (ringStart) {
dispatchSwitchRingBufferSection(nextRingBuffer->getGpuAddress());
cpuCachelineFlush(flushPtr, getSizeSwitchRingBufferSection());
}
ringCommandStream.replaceBuffer(nextRingBuffer->getUnderlyingBuffer(), ringCommandStream.getMaxAvailableSpace());
ringCommandStream.replaceGraphicsAllocation(nextRingBuffer);
handleSwitchRingBuffers();
return currentBufferGpuVa;
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
inline GraphicsAllocation *DirectSubmissionHw<GfxFamily, Dispatcher>::switchRingBuffersAllocations() {
2022-06-01 10:05:07 +00:00
this->previousRingBuffer = this->currentRingBuffer;
2020-01-15 17:02:47 +01:00
GraphicsAllocation *nextAllocation = nullptr;
2022-06-01 10:05:07 +00:00
for (uint32_t ringBufferIndex = 0; ringBufferIndex < this->ringBuffers.size(); ringBufferIndex++) {
if (ringBufferIndex != this->currentRingBuffer && this->isCompleted(ringBufferIndex)) {
this->currentRingBuffer = ringBufferIndex;
nextAllocation = this->ringBuffers[ringBufferIndex].ringBuffer;
break;
}
2020-01-15 17:02:47 +01:00
}
2022-06-01 10:05:07 +00:00
if (nextAllocation == nullptr) {
if (this->ringBuffers.size() == this->maxRingBufferCount) {
this->currentRingBuffer = (this->currentRingBuffer + 1) % this->ringBuffers.size();
nextAllocation = this->ringBuffers[this->currentRingBuffer].ringBuffer;
} else {
bool isMultiOsContextCapable = osContext.getNumSupportedDevices() > 1u;
constexpr size_t minimumRequiredSize = 256 * MemoryConstants::kiloByte;
constexpr size_t additionalAllocationSize = MemoryConstants::pageSize;
const auto allocationSize = alignUp(minimumRequiredSize + additionalAllocationSize, MemoryConstants::pageSize64k);
const AllocationProperties commandStreamAllocationProperties{rootDeviceIndex,
true, allocationSize,
AllocationType::RING_BUFFER,
isMultiOsContextCapable, false, osContext.getDeviceBitfield()};
nextAllocation = memoryManager->allocateGraphicsMemoryWithProperties(commandStreamAllocationProperties);
this->currentRingBuffer = static_cast<uint32_t>(this->ringBuffers.size());
this->ringBuffers.emplace_back(0ull, nextAllocation);
auto ret = memoryOperationHandler->makeResidentWithinOsContext(&this->osContext, ArrayRef<GraphicsAllocation *>(&nextAllocation, 1u), false) == MemoryOperationsStatus::SUCCESS;
UNRECOVERABLE_IF(!ret);
}
}
UNRECOVERABLE_IF(this->currentRingBuffer == this->previousRingBuffer);
2020-01-15 17:02:47 +01:00
return nextAllocation;
}
2020-03-26 20:13:10 +01:00
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::deallocateResources() {
2022-06-01 10:05:07 +00:00
for (uint32_t ringBufferIndex = 0; ringBufferIndex < this->ringBuffers.size(); ringBufferIndex++) {
memoryManager->freeGraphicsMemory(this->ringBuffers[ringBufferIndex].ringBuffer);
2020-01-15 17:02:47 +01:00
}
2022-06-01 10:05:07 +00:00
this->ringBuffers.clear();
2020-01-15 17:02:47 +01:00
if (semaphores) {
memoryManager->freeGraphicsMemory(semaphores);
semaphores = nullptr;
}
2022-11-16 17:24:04 +00:00
memoryManager->freeGraphicsMemory(deferredTasksListAllocation);
2020-01-15 17:02:47 +01:00
}
2020-03-27 16:32:07 +01:00
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::createDiagnostic() {
if (directSubmissionDiagnosticAvailable) {
workloadMode = DebugManager.flags.DirectSubmissionEnableDebugBuffer.get();
if (workloadMode > 0) {
disableCacheFlush = DebugManager.flags.DirectSubmissionDisableCacheFlush.get();
disableMonitorFence = DebugManager.flags.DirectSubmissionDisableMonitorFence.get();
uint32_t executions = static_cast<uint32_t>(DebugManager.flags.DirectSubmissionDiagnosticExecutionCount.get());
2020-04-03 14:43:13 +02:00
diagnostic = std::make_unique<DirectSubmissionDiagnosticsCollector>(
executions,
workloadMode == 1,
DebugManager.flags.DirectSubmissionBufferPlacement.get(),
DebugManager.flags.DirectSubmissionSemaphorePlacement.get(),
workloadMode,
disableCacheFlush,
disableMonitorFence);
2020-03-27 16:32:07 +01:00
}
}
}
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::initDiagnostic(bool &submitOnInit) {
if (directSubmissionDiagnosticAvailable) {
if (diagnostic.get()) {
submitOnInit = true;
diagnostic->diagnosticModeAllocation();
}
}
}
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::performDiagnosticMode() {
if (directSubmissionDiagnosticAvailable) {
if (diagnostic.get()) {
diagnostic->diagnosticModeDiagnostic();
2020-05-18 18:48:43 +02:00
if (workloadMode == 1) {
diagnostic->diagnosticModeOneWait(workloadModeOneStoreAddress, workloadModeOneExpectedValue);
}
2020-03-27 16:32:07 +01:00
BatchBuffer dummyBuffer = {};
FlushStampTracker dummyTracker(true);
for (uint32_t execution = 0; execution < diagnostic->getExecutionsCount(); execution++) {
dispatchCommandBuffer(dummyBuffer, dummyTracker);
if (workloadMode == 1) {
2020-05-18 18:48:43 +02:00
diagnostic->diagnosticModeOneWaitCollect(execution, workloadModeOneStoreAddress, workloadModeOneExpectedValue);
2020-03-27 16:32:07 +01:00
}
}
workloadMode = 0;
2020-09-22 17:49:06 +02:00
disableCacheFlush = UllsDefaults::defaultDisableCacheFlush;
disableMonitorFence = UllsDefaults::defaultDisableMonitorFence;
2020-03-27 16:32:07 +01:00
diagnostic.reset(nullptr);
}
}
}
2020-05-18 18:48:43 +02:00
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchDiagnosticModeSection() {
workloadModeOneExpectedValue++;
uint64_t storeAddress = semaphoreGpuVa;
storeAddress += ptrDiff(workloadModeOneStoreAddress, semaphorePtr);
Dispatcher::dispatchStoreDwordCommand(ringCommandStream, storeAddress, workloadModeOneExpectedValue);
}
template <typename GfxFamily, typename Dispatcher>
size_t DirectSubmissionHw<GfxFamily, Dispatcher>::getDiagnosticModeSection() {
return Dispatcher::getSizeStoreDwordCommand();
}
2022-04-06 14:41:45 +00:00
template <typename GfxFamily, typename Dispatcher>
void DirectSubmissionHw<GfxFamily, Dispatcher>::dispatchSystemMemoryFenceAddress() {
2022-06-23 09:44:45 +00:00
EncodeMemoryFence<GfxFamily>::encodeSystemMemoryFence(ringCommandStream, this->globalFenceAllocation, this->logicalStateHelper);
if (logicalStateHelper) {
2022-07-04 14:16:44 +00:00
logicalStateHelper->writeStreamInline(ringCommandStream, false);
2022-06-23 09:44:45 +00:00
}
2022-04-06 14:41:45 +00:00
}
template <typename GfxFamily, typename Dispatcher>
size_t DirectSubmissionHw<GfxFamily, Dispatcher>::getSizeSystemMemoryFenceAddress() {
return EncodeMemoryFence<GfxFamily>::getSystemMemoryFenceSize();
}
2020-01-15 17:02:47 +01:00
} // namespace NEO