1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
/*
* Copyright (C) 2019-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/blit_commands_helper.h"
#include "shared/source/utilities/wait_util.h"
#include "opencl/source/built_ins/aux_translation_builtin.h"
#include "opencl/source/command_queue/enqueue_barrier.h"
#include "opencl/source/command_queue/enqueue_copy_buffer.h"
#include "opencl/source/command_queue/enqueue_copy_buffer_rect.h"
#include "opencl/source/command_queue/enqueue_copy_buffer_to_image.h"
#include "opencl/source/command_queue/enqueue_copy_image.h"
#include "opencl/source/command_queue/enqueue_copy_image_to_buffer.h"
#include "opencl/source/command_queue/enqueue_fill_buffer.h"
#include "opencl/source/command_queue/enqueue_fill_image.h"
#include "opencl/source/command_queue/enqueue_kernel.h"
#include "opencl/source/command_queue/enqueue_marker.h"
#include "opencl/source/command_queue/enqueue_migrate_mem_objects.h"
#include "opencl/source/command_queue/enqueue_read_buffer.h"
#include "opencl/source/command_queue/enqueue_read_buffer_rect.h"
#include "opencl/source/command_queue/enqueue_read_image.h"
#include "opencl/source/command_queue/enqueue_svm.h"
#include "opencl/source/command_queue/enqueue_write_buffer.h"
#include "opencl/source/command_queue/enqueue_write_buffer_rect.h"
#include "opencl/source/command_queue/enqueue_write_image.h"
#include "opencl/source/command_queue/finish.h"
#include "opencl/source/command_queue/flush.h"
#include "opencl/source/command_queue/gpgpu_walker.h"
namespace NEO {
template <typename Family>
void CommandQueueHw<Family>::notifyEnqueueReadBuffer(Buffer *buffer, bool blockingRead, bool notifyBcsCsr) {
if (debugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.get()) {
buffer->getGraphicsAllocation(getDevice().getRootDeviceIndex())->setAllocDumpable(blockingRead, notifyBcsCsr);
buffer->forceDisallowCPUCopy = blockingRead;
}
}
template <typename Family>
void CommandQueueHw<Family>::notifyEnqueueReadImage(Image *image, bool blockingRead, bool notifyBcsCsr) {
if (debugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.get()) {
image->getGraphicsAllocation(getDevice().getRootDeviceIndex())->setAllocDumpable(blockingRead, notifyBcsCsr);
}
}
template <typename Family>
void CommandQueueHw<Family>::notifyEnqueueSVMMemcpy(GraphicsAllocation *gfxAllocation, bool blockingCopy, bool notifyBcsCsr) {
if (debugManager.flags.AUBDumpAllocsOnEnqueueSVMMemcpyOnly.get()) {
gfxAllocation->setAllocDumpable(blockingCopy, notifyBcsCsr);
}
}
template <typename Family>
cl_int CommandQueueHw<Family>::enqueueReadWriteBufferOnCpuWithMemoryTransfer(cl_command_type commandType, Buffer *buffer,
size_t offset, size_t size, void *ptr, cl_uint numEventsInWaitList,
const cl_event *eventWaitList, cl_event *event) {
cl_int retVal = CL_SUCCESS;
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, event);
TransferProperties transferProperties(buffer, commandType, 0, true, &offset, &size, ptr, true, getDevice().getRootDeviceIndex());
cpuDataTransferHandler(transferProperties, eventsRequest, retVal);
return retVal;
}
template <typename Family>
cl_int CommandQueueHw<Family>::enqueueReadWriteBufferOnCpuWithoutMemoryTransfer(cl_command_type commandType, Buffer *buffer,
size_t offset, size_t size, void *ptr, cl_uint numEventsInWaitList,
const cl_event *eventWaitList, cl_event *event) {
cl_int retVal = CL_SUCCESS;
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, event);
TransferProperties transferProperties(buffer, CL_COMMAND_MARKER, 0, true, &offset, &size, ptr, false, getDevice().getRootDeviceIndex());
cpuDataTransferHandler(transferProperties, eventsRequest, retVal);
if (event) {
auto pEvent = castToObjectOrAbort<Event>(*event);
pEvent->setCmdType(commandType);
}
if (context->isProvidingPerformanceHints()) {
context->providePerformanceHintForMemoryTransfer(commandType, false, static_cast<cl_mem>(buffer), ptr);
}
return retVal;
}
template <typename Family>
cl_int CommandQueueHw<Family>::enqueueMarkerForReadWriteOperation(MemObj *memObj, void *ptr, cl_command_type commandType, cl_bool blocking, cl_uint numEventsInWaitList,
const cl_event *eventWaitList, cl_event *event) {
MultiDispatchInfo multiDispatchInfo;
NullSurface s;
Surface *surfaces[] = {&s};
const auto enqueueResult = enqueueHandler<CL_COMMAND_MARKER>(
surfaces,
blocking == CL_TRUE,
multiDispatchInfo,
numEventsInWaitList,
eventWaitList,
event);
if (enqueueResult != CL_SUCCESS) {
return enqueueResult;
}
if (event) {
auto pEvent = castToObjectOrAbort<Event>(*event);
pEvent->setCmdType(commandType);
}
if (context->isProvidingPerformanceHints()) {
context->providePerformanceHintForMemoryTransfer(commandType, false, static_cast<cl_mem>(memObj), ptr);
}
return CL_SUCCESS;
}
template <typename Family>
void CommandQueueHw<Family>::dispatchAuxTranslationBuiltin(MultiDispatchInfo &multiDispatchInfo,
AuxTranslationDirection auxTranslationDirection) {
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::auxTranslation, getClDevice());
auto &auxTranslationBuilder = static_cast<BuiltInOp<EBuiltInOps::auxTranslation> &>(builder);
BuiltinOpParams dispatchParams;
dispatchParams.auxTranslationDirection = auxTranslationDirection;
auxTranslationBuilder.buildDispatchInfosForAuxTranslation<Family>(multiDispatchInfo, dispatchParams);
}
template <typename Family>
bool CommandQueueHw<Family>::forceStateless(size_t size) {
return isForceStateless || size >= 4ull * MemoryConstants::gigaByte;
}
template <typename Family>
bool CommandQueueHw<Family>::isCacheFlushForBcsRequired() const {
if (debugManager.flags.ForceCacheFlushForBcs.get() != -1) {
return !!debugManager.flags.ForceCacheFlushForBcs.get();
}
const auto &productHelper = this->device->getProductHelper();
return productHelper.isDcFlushAllowed();
}
template <typename TSPacketType>
inline bool waitForTimestampsWithinContainer(TimestampPacketContainer *container, CommandStreamReceiver &csr, WaitStatus &status) {
bool printWaitForCompletion = debugManager.flags.LogWaitingForCompletion.get();
bool waited = false;
status = WaitStatus::notReady;
if (container) {
auto lastHangCheckTime = std::chrono::high_resolution_clock::now();
auto waitStartTime = lastHangCheckTime;
for (const auto ×tamp : container->peekNodes()) {
for (uint32_t i = 0; i < timestamp->getPacketsUsed(); i++) {
if (printWaitForCompletion) {
printf("\nWaiting for TS 0x%" PRIx64, timestamp->getGpuAddress() + (i * timestamp->getSinglePacketSize()));
}
while (timestamp->getContextEndValue(i) == 1) {
csr.downloadAllocation(*timestamp->getBaseGraphicsAllocation()->getGraphicsAllocation(csr.getRootDeviceIndex()));
auto currentTime = std::chrono::high_resolution_clock::now();
WaitUtils::waitFunctionWithPredicate<const TSPacketType>(static_cast<TSPacketType const *>(timestamp->getContextEndAddress(i)), 1u, std::not_equal_to<TSPacketType>(), std::chrono::duration_cast<std::chrono::microseconds>(currentTime - waitStartTime).count());
if (csr.checkGpuHangDetected(currentTime, lastHangCheckTime)) {
status = WaitStatus::gpuHang;
if (printWaitForCompletion) {
printf("\nWaiting for TS failed");
}
return false;
}
}
if (printWaitForCompletion) {
printf("\nWaiting for TS completed");
}
status = WaitStatus::ready;
waited = true;
}
}
}
return waited;
}
template <typename Family>
bool CommandQueueHw<Family>::waitForTimestamps(std::span<CopyEngineState> copyEnginesToWait, WaitStatus &status, TimestampPacketContainer *mainContainer, TimestampPacketContainer *deferredContainer) {
using TSPacketType = typename Family::TimestampPacketType;
bool waited = false;
if (isWaitForTimestampsEnabled()) {
{
TakeOwnershipWrapper<CommandQueue> queueOwnership(*this);
waited = waitForTimestampsWithinContainer<TSPacketType>(mainContainer, getGpgpuCommandStreamReceiver(), status);
}
if (waited) {
getGpgpuCommandStreamReceiver().downloadAllocations(true);
for (const auto ©Engine : copyEnginesToWait) {
auto bcsCsr = getBcsCommandStreamReceiver(copyEngine.engineType);
bcsCsr->downloadAllocations(true);
}
}
}
return waited;
}
template <typename Family>
void CommandQueueHw<Family>::setupBlitAuxTranslation(MultiDispatchInfo &multiDispatchInfo) {
multiDispatchInfo.begin()->dispatchInitCommands.registerMethod(
TimestampPacketHelper::programSemaphoreForAuxTranslation<Family, AuxTranslationDirection::auxToNonAux>);
multiDispatchInfo.begin()->dispatchInitCommands.registerCommandsSizeEstimationMethod(
TimestampPacketHelper::getRequiredCmdStreamSizeForAuxTranslationNodeDependency<Family, AuxTranslationDirection::auxToNonAux>);
multiDispatchInfo.rbegin()->dispatchEpilogueCommands.registerMethod(
TimestampPacketHelper::programSemaphoreForAuxTranslation<Family, AuxTranslationDirection::nonAuxToAux>);
multiDispatchInfo.rbegin()->dispatchEpilogueCommands.registerCommandsSizeEstimationMethod(
TimestampPacketHelper::getRequiredCmdStreamSizeForAuxTranslationNodeDependency<Family, AuxTranslationDirection::nonAuxToAux>);
}
template <typename Family>
bool CommandQueueHw<Family>::isGpgpuSubmissionForBcsRequired(bool queueBlocked, TimestampPacketDependencies ×tampPacketDependencies, bool containsCrossEngineDependency, bool textureCacheFlushRequired) const {
if (queueBlocked || timestampPacketDependencies.barrierNodes.peekNodes().size() > 0u) {
return true;
}
if (isOOQEnabled()) {
return containsCrossEngineDependency;
}
bool required = false;
switch (latestSentEnqueueType) {
case NEO::EnqueueProperties::Operation::explicitCacheFlush:
case NEO::EnqueueProperties::Operation::enqueueWithoutSubmission:
case NEO::EnqueueProperties::Operation::gpuKernel:
case NEO::EnqueueProperties::Operation::profilingOnly:
required = isCacheFlushForBcsRequired() || !(getGpgpuCommandStreamReceiver().getDispatchMode() == DispatchMode::immediateDispatch || getGpgpuCommandStreamReceiver().isLatestTaskCountFlushed());
break;
case NEO::EnqueueProperties::Operation::dependencyResolveOnGpu:
return true;
break;
case NEO::EnqueueProperties::Operation::none:
case NEO::EnqueueProperties::Operation::blit:
default:
break;
}
required |= textureCacheFlushRequired;
if (debugManager.flags.ForceGpgpuSubmissionForBcsEnqueue.get() == 1) {
required = true;
}
return required;
}
template <typename Family>
void CommandQueueHw<Family>::setupEvent(EventBuilder &eventBuilder, cl_event *outEvent, uint32_t cmdType) {
if (outEvent) {
eventBuilder.create<Event>(this, cmdType, CompletionStamp::notReady, 0);
auto eventObj = eventBuilder.getEvent();
*outEvent = eventObj;
if (eventObj->isProfilingEnabled()) {
eventObj->setQueueTimeStamp();
if (isCommandWithoutKernel(cmdType) && !isFlushForProfilingRequired(cmdType)) {
eventObj->setCPUProfilingPath(true);
}
}
DBG_LOG(EventsDebugEnable, "enqueueHandler commandType", cmdType, "output Event", eventObj);
}
}
template <typename Family>
CommandQueueHw<Family>::~CommandQueueHw() {
unregisterGpgpuAndBcsCsrClients();
}
} // namespace NEO
|