2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2023-01-01 19:22:01 +00:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2021-09-29 19:10:53 +00:00
|
|
|
#include "shared/source/program/kernel_info.h"
|
|
|
|
|
|
|
|
|
|
#include "shared/source/device/device.h"
|
2023-02-16 15:09:51 +00:00
|
|
|
#include "shared/source/device_binary_format/zebin/zebin_elf.h"
|
2020-10-13 13:14:51 +02:00
|
|
|
#include "shared/source/helpers/kernel_helpers.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
2022-12-07 11:51:44 +00:00
|
|
|
#include "shared/source/memory_manager/allocation_properties.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <cstdint>
|
2019-02-27 11:39:32 +01:00
|
|
|
#include <unordered_map>
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
struct KernelArgumentType {
|
|
|
|
|
const char *argTypeQualifier;
|
|
|
|
|
uint64_t argTypeQualifierValue;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
KernelInfo::~KernelInfo() {
|
|
|
|
|
delete[] crossThreadData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t KernelInfo::getSamplerStateArrayCount() const {
|
Remove PatchTokens from KernelInfo
Use KernelDescriptor instead of patchTokens stored in KernelInfo's
patchInfo.
Removed: SPatchMediaInterfaceDescriptorLoad, SPatchAllocateLocalSurface,
SPatchMediaVFEState(slot 0), SPatchMediaVFEState(slot 1),
SPatchInterfaceDescriptorData, SPatchSamplerStateArray,
SPatchBindingTableState, SPatchDataParameterBuffer,
SPatchDataParameterStream, SPatchThreadPayload,
SPatchKernelAttributesInfo, SPatchAllocateStatelessPrivateSurface,
SPatchAllocateSyncBuffer,
SPatchAllocateStatelessConstantMemorySurfaceWithInitialization,
SPatchAllocateStatelessGlobalMemorySurfaceWithInitialization,
SPatchAllocateSystemThreadSurface.
Related-To: NEO-4729
Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
2021-03-04 10:14:23 +01:00
|
|
|
return kernelDescriptor.payloadMappings.samplerTable.numSamplers;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t KernelInfo::getBorderColorOffset() const {
|
|
|
|
|
size_t borderColorOffset = 0;
|
Remove PatchTokens from KernelInfo
Use KernelDescriptor instead of patchTokens stored in KernelInfo's
patchInfo.
Removed: SPatchMediaInterfaceDescriptorLoad, SPatchAllocateLocalSurface,
SPatchMediaVFEState(slot 0), SPatchMediaVFEState(slot 1),
SPatchInterfaceDescriptorData, SPatchSamplerStateArray,
SPatchBindingTableState, SPatchDataParameterBuffer,
SPatchDataParameterStream, SPatchThreadPayload,
SPatchKernelAttributesInfo, SPatchAllocateStatelessPrivateSurface,
SPatchAllocateSyncBuffer,
SPatchAllocateStatelessConstantMemorySurfaceWithInitialization,
SPatchAllocateStatelessGlobalMemorySurfaceWithInitialization,
SPatchAllocateSystemThreadSurface.
Related-To: NEO-4729
Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
2021-03-04 10:14:23 +01:00
|
|
|
if (kernelDescriptor.payloadMappings.samplerTable.numSamplers > 0U) {
|
|
|
|
|
borderColorOffset = kernelDescriptor.payloadMappings.samplerTable.borderColor;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
return borderColorOffset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t KernelInfo::getConstantBufferSize() const {
|
Remove PatchTokens from KernelInfo
Use KernelDescriptor instead of patchTokens stored in KernelInfo's
patchInfo.
Removed: SPatchMediaInterfaceDescriptorLoad, SPatchAllocateLocalSurface,
SPatchMediaVFEState(slot 0), SPatchMediaVFEState(slot 1),
SPatchInterfaceDescriptorData, SPatchSamplerStateArray,
SPatchBindingTableState, SPatchDataParameterBuffer,
SPatchDataParameterStream, SPatchThreadPayload,
SPatchKernelAttributesInfo, SPatchAllocateStatelessPrivateSurface,
SPatchAllocateSyncBuffer,
SPatchAllocateStatelessConstantMemorySurfaceWithInitialization,
SPatchAllocateStatelessGlobalMemorySurfaceWithInitialization,
SPatchAllocateSystemThreadSurface.
Related-To: NEO-4729
Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
2021-03-04 10:14:23 +01:00
|
|
|
return kernelDescriptor.kernelAttributes.crossThreadDataSize;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
2021-04-08 11:05:45 +02:00
|
|
|
int32_t KernelInfo::getArgNumByName(const char *name) const {
|
|
|
|
|
int32_t argNum = 0;
|
|
|
|
|
for (const auto &argMeta : kernelDescriptor.explicitArgsExtendedMetadata) {
|
|
|
|
|
if (argMeta.argName.compare(name) == 0) {
|
|
|
|
|
return argNum;
|
|
|
|
|
}
|
|
|
|
|
++argNum;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2018-04-04 19:02:07 +02:00
|
|
|
|
2022-03-01 14:17:54 +00:00
|
|
|
bool KernelInfo::createKernelAllocation(const Device &device, bool internalIsa) {
|
2018-04-04 19:02:07 +02:00
|
|
|
UNRECOVERABLE_IF(kernelAllocation);
|
2023-04-28 09:38:31 +00:00
|
|
|
auto kernelIsaSize = heapInfo.kernelHeapSize;
|
2023-12-11 14:24:36 +00:00
|
|
|
const auto allocType = internalIsa ? AllocationType::kernelIsaInternal : AllocationType::kernelIsa;
|
2022-02-24 14:12:06 +00:00
|
|
|
|
|
|
|
|
if (device.getMemoryManager()->isKernelBinaryReuseEnabled()) {
|
|
|
|
|
auto lock = device.getMemoryManager()->lockKernelAllocationMap();
|
|
|
|
|
auto kernelName = this->kernelDescriptor.kernelMetadata.kernelName;
|
|
|
|
|
auto &storedAllocations = device.getMemoryManager()->getKernelAllocationMap();
|
|
|
|
|
auto kernelAllocations = storedAllocations.find(kernelName);
|
|
|
|
|
if (kernelAllocations != storedAllocations.end()) {
|
|
|
|
|
kernelAllocation = kernelAllocations->second.kernelAllocation;
|
|
|
|
|
kernelAllocations->second.reuseCounter++;
|
2023-01-26 16:21:09 +00:00
|
|
|
auto &rootDeviceEnvironment = device.getRootDeviceEnvironment();
|
2022-12-15 13:33:28 +00:00
|
|
|
auto &productHelper = device.getProductHelper();
|
2022-02-24 14:12:06 +00:00
|
|
|
|
2023-01-26 16:21:09 +00:00
|
|
|
return MemoryTransferHelper::transferMemoryToAllocation(productHelper.isBlitCopyRequiredForLocalMemory(rootDeviceEnvironment, *kernelAllocation),
|
2022-02-24 14:12:06 +00:00
|
|
|
device, kernelAllocation, 0, heapInfo.pKernelHeap,
|
|
|
|
|
static_cast<size_t>(kernelIsaSize));
|
|
|
|
|
} else {
|
|
|
|
|
kernelAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({device.getRootDeviceIndex(), kernelIsaSize, allocType, device.getDeviceBitfield()});
|
|
|
|
|
storedAllocations.insert(std::make_pair(kernelName, MemoryManager::KernelAllocationInfo(kernelAllocation, 1u)));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
kernelAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({device.getRootDeviceIndex(), kernelIsaSize, allocType, device.getDeviceBitfield()});
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-11 11:13:17 +01:00
|
|
|
if (!kernelAllocation) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-09-15 15:45:26 +02:00
|
|
|
|
2023-01-26 16:21:09 +00:00
|
|
|
auto &rootDeviceEnvironment = device.getRootDeviceEnvironment();
|
2022-12-15 13:33:28 +00:00
|
|
|
auto &productHelper = device.getProductHelper();
|
2020-09-15 15:45:26 +02:00
|
|
|
|
2023-01-26 16:21:09 +00:00
|
|
|
return MemoryTransferHelper::transferMemoryToAllocation(productHelper.isBlitCopyRequiredForLocalMemory(rootDeviceEnvironment, *kernelAllocation),
|
2020-10-09 11:52:00 +02:00
|
|
|
device, kernelAllocation, 0, heapInfo.pKernelHeap,
|
|
|
|
|
static_cast<size_t>(kernelIsaSize));
|
2018-04-04 19:02:07 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-25 19:18:48 +01:00
|
|
|
void KernelInfo::apply(const DeviceInfoKernelPayloadConstants &constants) {
|
|
|
|
|
if (nullptr == this->crossThreadData) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-29 12:34:25 +02:00
|
|
|
const auto &implicitArgs = kernelDescriptor.payloadMappings.implicitArgs;
|
|
|
|
|
const auto privateMemorySize = static_cast<uint32_t>(KernelHelper::getPrivateSurfaceSize(kernelDescriptor.kernelAttributes.perHwThreadPrivateMemorySize,
|
|
|
|
|
constants.computeUnitsUsedForScratch));
|
2020-01-25 19:18:48 +01:00
|
|
|
|
2021-03-29 12:34:25 +02:00
|
|
|
auto setIfValidOffset = [&](auto value, NEO::CrossThreadDataOffset offset) {
|
|
|
|
|
if (isValidOffset(offset)) {
|
|
|
|
|
*ptrOffset(reinterpret_cast<decltype(value) *>(crossThreadData), offset) = value;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
setIfValidOffset(reinterpret_cast<uintptr_t>(constants.slmWindow), implicitArgs.localMemoryStatelessWindowStartAddres);
|
|
|
|
|
setIfValidOffset(constants.slmWindowSize, implicitArgs.localMemoryStatelessWindowSize);
|
|
|
|
|
setIfValidOffset(privateMemorySize, implicitArgs.privateMemorySize);
|
|
|
|
|
setIfValidOffset(constants.maxWorkGroupSize, implicitArgs.maxWorkGroupSize);
|
2020-01-25 19:18:48 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-11 18:25:26 +01:00
|
|
|
std::string concatenateKernelNames(ArrayRef<KernelInfo *> kernelInfos) {
|
|
|
|
|
std::string semiColonDelimitedKernelNameStr;
|
|
|
|
|
|
|
|
|
|
for (const auto &kernelInfo : kernelInfos) {
|
2022-12-01 12:19:45 +00:00
|
|
|
const auto &kernelName = kernelInfo->kernelDescriptor.kernelMetadata.kernelName;
|
2023-02-16 15:09:51 +00:00
|
|
|
if (kernelName == NEO::Zebin::Elf::SectionNames::externalFunctions) {
|
2022-12-01 12:19:45 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-11 18:25:26 +01:00
|
|
|
if (!semiColonDelimitedKernelNameStr.empty()) {
|
|
|
|
|
semiColonDelimitedKernelNameStr += ';';
|
|
|
|
|
}
|
2022-12-01 12:19:45 +00:00
|
|
|
semiColonDelimitedKernelNameStr += kernelName;
|
2020-01-11 18:25:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return semiColonDelimitedKernelNameStr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|