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
|
/*
* Copyright (C) 2023-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/blit_helper.h"
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/device/device.h"
#include "shared/source/helpers/blit_properties.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/memory_manager/graphics_allocation.h"
namespace NEO {
namespace BlitHelperFunctions {
BlitMemoryToAllocationFunc blitMemoryToAllocation = BlitHelper::blitMemoryToAllocation;
BlitMemsetAllocationFunc blitMemsetAllocation = BlitHelper::blitMemsetAllocation;
} // namespace BlitHelperFunctions
BlitOperationResult BlitHelper::blitMemoryToAllocation(const Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr,
const Vec3<size_t> &size) {
auto memoryBanks = memory->storageInfo.getMemoryBanks();
return blitMemoryToAllocationBanks(device, memory, offset, hostPtr, size, memoryBanks);
}
BlitOperationResult BlitHelper::blitMemoryToAllocationBanks(const Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr,
const Vec3<size_t> &size, DeviceBitfield memoryBanks) {
const auto &hwInfo = device.getHardwareInfo();
if (!hwInfo.capabilityTable.blitterOperationsSupported) {
return BlitOperationResult::unsupported;
}
auto &gfxCoreHelper = device.getGfxCoreHelper();
UNRECOVERABLE_IF(memoryBanks.none());
auto pRootDevice = device.getRootDevice();
for (uint8_t tileId = 0u; tileId < 4u; tileId++) {
if (!memoryBanks.test(tileId)) {
continue;
}
UNRECOVERABLE_IF(!pRootDevice->getDeviceBitfield().test(tileId));
auto pDeviceForBlit = pRootDevice->getNearestGenericSubDevice(tileId);
auto &selectorCopyEngine = pDeviceForBlit->getSelectorCopyEngine();
auto deviceBitfield = pDeviceForBlit->getDeviceBitfield();
auto internalUsage = true;
auto bcsEngineType = EngineHelpers::getBcsEngineType(pDeviceForBlit->getRootDeviceEnvironment(), deviceBitfield, selectorCopyEngine, internalUsage);
auto bcsEngineUsage = gfxCoreHelper.preferInternalBcsEngine() ? EngineUsage::internal : EngineUsage::regular;
auto bcsEngine = pDeviceForBlit->tryGetEngine(bcsEngineType, bcsEngineUsage);
if (!bcsEngine) {
return BlitOperationResult::unsupported;
}
bcsEngine->commandStreamReceiver->initializeResources(false, device.getPreemptionMode());
bcsEngine->commandStreamReceiver->initDirectSubmission();
BlitPropertiesContainer blitPropertiesContainer;
blitPropertiesContainer.push_back(
BlitProperties::constructPropertiesForReadWrite(BlitterConstants::BlitDirection::hostPtrToBuffer,
*bcsEngine->commandStreamReceiver, memory, nullptr,
hostPtr,
(memory->getGpuAddress() + offset),
0, 0, 0, size, 0, 0, 0, 0));
const auto newTaskCount = bcsEngine->commandStreamReceiver->flushBcsTask(blitPropertiesContainer, true, *pDeviceForBlit);
if (newTaskCount == CompletionStamp::gpuHang) {
return BlitOperationResult::gpuHang;
}
}
return BlitOperationResult::success;
}
BlitOperationResult BlitHelper::blitMemsetAllocation(const Device &device, GraphicsAllocation *memory, size_t offset, int value, size_t size) {
auto memoryBanks = memory->storageInfo.getMemoryBanks();
return blitMemsetAllocationBanks(device, memory, offset, value, size, memoryBanks);
}
BlitOperationResult BlitHelper::blitMemsetAllocationBanks(const Device &device, GraphicsAllocation *memory, size_t offset, int value,
size_t size, DeviceBitfield memoryBanks) {
const auto &hwInfo = device.getHardwareInfo();
if (!hwInfo.capabilityTable.blitterOperationsSupported) {
return BlitOperationResult::unsupported;
}
auto &gfxCoreHelper = device.getGfxCoreHelper();
UNRECOVERABLE_IF(memoryBanks.none());
auto pRootDevice = device.getRootDevice();
uint8_t byteValue = static_cast<uint8_t>(value);
uint32_t patternToCommand[4] = {};
memcpy_s(patternToCommand, sizeof(patternToCommand), &byteValue, 1);
for (uint8_t tileId = 0u; tileId < 4u; tileId++) {
if (!memoryBanks.test(tileId)) {
continue;
}
UNRECOVERABLE_IF(!pRootDevice->getDeviceBitfield().test(tileId));
auto pDeviceForBlit = pRootDevice->getNearestGenericSubDevice(tileId);
auto &selectorCopyEngine = pDeviceForBlit->getSelectorCopyEngine();
auto deviceBitfield = pDeviceForBlit->getDeviceBitfield();
auto internalUsage = true;
auto bcsEngineType = EngineHelpers::getBcsEngineType(pDeviceForBlit->getRootDeviceEnvironment(), deviceBitfield, selectorCopyEngine, internalUsage);
auto bcsEngineUsage = gfxCoreHelper.preferInternalBcsEngine() ? EngineUsage::internal : EngineUsage::regular;
auto bcsEngine = pDeviceForBlit->tryGetEngine(bcsEngineType, bcsEngineUsage);
if (!bcsEngine) {
return BlitOperationResult::unsupported;
}
bcsEngine->commandStreamReceiver->initializeResources(false, device.getPreemptionMode());
bcsEngine->commandStreamReceiver->initDirectSubmission();
BlitPropertiesContainer blitPropertiesContainer;
blitPropertiesContainer.push_back(
BlitProperties::constructPropertiesForMemoryFill(
memory, 0, size, patternToCommand, 1, offset));
const auto newTaskCount = bcsEngine->commandStreamReceiver->flushBcsTask(blitPropertiesContainer, true, *pDeviceForBlit);
if (newTaskCount == CompletionStamp::gpuHang) {
return BlitOperationResult::gpuHang;
}
}
return BlitOperationResult::success;
}
} // namespace NEO
|