refactor: add checker for stateless only kernels

Related-To: NEO-10381

Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz 2024-03-21 15:52:25 +00:00 committed by Compute-Runtime-Automation
parent 4df0dd7894
commit b3be51fc35
6 changed files with 86 additions and 4 deletions

View File

@ -9,7 +9,6 @@
#include "shared/source/command_container/encode_surface_state.h"
#include "shared/source/command_container/implicit_scaling.h"
#include "shared/source/command_stream/preemption.h"
#include "shared/source/helpers/addressing_mode_helper.h"
#include "shared/source/helpers/cache_flush_xehp_and_later.inl"
#include "shared/source/helpers/pause_on_gpu_properties.h"
#include "shared/source/helpers/pipeline_select_helper.h"
@ -99,13 +98,13 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendLaunchKernelWithParams(K
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
KernelImp *kernelImp = static_cast<KernelImp *>(kernel);
if (this->cmdListHeapAddressModel == NEO::HeapAddressModel::globalStateless) {
if (NEO::AddressingModeHelper::containsStatefulAccess(kernelDescriptor, false)) {
if (kernelImp->checkKernelContainsStatefulAccess()) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
}
KernelImp *kernelImp = static_cast<KernelImp *>(kernel);
if (kernelImp->usesRayTracing()) {
NEO::GraphicsAllocation *memoryBackedBuffer = device->getNEODevice()->getRTMemoryBackedBuffer();
if (memoryBackedBuffer == nullptr) {

View File

@ -12,6 +12,7 @@
#include "shared/source/debugger/debugger_l0.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/helpers/addressing_mode_helper.h"
#include "shared/source/helpers/basic_math.h"
#include "shared/source/helpers/bindless_heaps_helper.h"
#include "shared/source/helpers/blit_commands_helper.h"
@ -1381,4 +1382,12 @@ void KernelImp::patchBindlessOffsetsForImplicitArgs(uint64_t bindlessSurfaceStat
}
}
bool KernelImp::checkKernelContainsStatefulAccess() {
auto moduleImp = static_cast<ModuleImp *>(this->module);
auto isUserKernel = (moduleImp->getModuleType() == ModuleType::user);
auto isGeneratedByIgc = moduleImp->getTranslationUnit()->isGeneratedByIgc;
auto containsStatefulAccess = NEO::AddressingModeHelper::containsStatefulAccess(getKernelDescriptor(), false);
return containsStatefulAccess && isUserKernel && isGeneratedByIgc;
}
} // namespace L0

View File

@ -186,6 +186,8 @@ struct KernelImp : Kernel {
KernelExt *getExtension(uint32_t extensionType);
bool checkKernelContainsStatefulAccess();
protected:
KernelImp() = default;

View File

@ -159,6 +159,9 @@ struct ModuleImp : public Module {
std::vector<std::shared_ptr<Kernel>> &getPrintfKernelContainer() { return this->printfKernelContainer; }
std::weak_ptr<Kernel> getPrintfKernelWeakPtr(ze_kernel_handle_t kernelHandle) const;
ze_result_t destroyPrintfKernel(ze_kernel_handle_t kernelHandle);
ModuleType getModuleType() const {
return this->type;
}
protected:
MOCKABLE_VIRTUAL ze_result_t initializeTranslationUnit(const ze_module_desc_t *desc, NEO::Device *neoDevice);

View File

@ -22,6 +22,7 @@ namespace ult {
struct MockModuleTranslationUnit : public L0::ModuleTranslationUnit {
using BaseClass = L0::ModuleTranslationUnit;
using BaseClass::isGeneratedByIgc;
MockModuleTranslationUnit(L0::Device *device) : BaseClass{device} {}

View File

@ -2615,8 +2615,10 @@ HWTEST2_F(CommandListStateBaseAddressGlobalStatelessTest,
EXPECT_EQ(nullptr, dsh);
}
HWTEST2_F(CommandListStateBaseAddressGlobalStatelessTest,
givenKernelUsingStatefulAccessWhenAppendingKernelOnGlobalStatelessThenExpectError,
givenUserKernelCreatedByIgcUsingStatefulAccessWhenAppendingKernelOnGlobalStatelessThenExpectError,
IsAtLeastXeHpCore) {
module->translationUnit->isGeneratedByIgc = true;
module->type = ModuleType::user;
mockKernelImmData->kernelDescriptor->payloadMappings.explicitArgs.resize(1);
auto ptrArg = ArgDescriptor(ArgDescriptor::argTPointer);
@ -2636,5 +2638,71 @@ HWTEST2_F(CommandListStateBaseAddressGlobalStatelessTest,
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
}
HWTEST2_F(CommandListStateBaseAddressGlobalStatelessTest,
givenUserKernelNotCreatedByIgcUsingStatefulAccessWhenAppendingKernelOnGlobalStatelessThenExpectSuccess,
IsAtLeastXeHpCore) {
module->translationUnit->isGeneratedByIgc = false;
module->type = ModuleType::user;
mockKernelImmData->kernelDescriptor->payloadMappings.explicitArgs.resize(1);
auto ptrArg = ArgDescriptor(ArgDescriptor::argTPointer);
ptrArg.as<ArgDescPointer>().bindless = 0x40;
mockKernelImmData->kernelDescriptor->payloadMappings.explicitArgs[0] = ptrArg;
ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {};
auto result = commandList->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ptrArg.as<ArgDescPointer>().bindless = undefined<CrossThreadDataOffset>;
ptrArg.as<ArgDescPointer>().bindful = 0x40;
mockKernelImmData->kernelDescriptor->payloadMappings.explicitArgs[0] = ptrArg;
result = commandList->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
HWTEST2_F(CommandListStateBaseAddressGlobalStatelessTest,
givenBuiltinKernelCreatedByIgcUsingStatefulAccessWhenAppendingKernelOnGlobalStatelessThenExpectSuccess,
IsAtLeastXeHpCore) {
module->translationUnit->isGeneratedByIgc = true;
module->type = ModuleType::builtin;
mockKernelImmData->kernelDescriptor->payloadMappings.explicitArgs.resize(1);
auto ptrArg = ArgDescriptor(ArgDescriptor::argTPointer);
ptrArg.as<ArgDescPointer>().bindless = 0x40;
mockKernelImmData->kernelDescriptor->payloadMappings.explicitArgs[0] = ptrArg;
ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {};
auto result = commandList->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ptrArg.as<ArgDescPointer>().bindless = undefined<CrossThreadDataOffset>;
ptrArg.as<ArgDescPointer>().bindful = 0x40;
mockKernelImmData->kernelDescriptor->payloadMappings.explicitArgs[0] = ptrArg;
result = commandList->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
HWTEST2_F(CommandListStateBaseAddressGlobalStatelessTest,
givenUserKernelCreatedByIgcUsingStatelessAccessWhenAppendingKernelOnGlobalStatelessThenExpectSuccess,
IsAtLeastXeHpCore) {
module->translationUnit->isGeneratedByIgc = true;
module->type = ModuleType::user;
mockKernelImmData->kernelDescriptor->payloadMappings.explicitArgs.resize(1);
auto ptrArg = ArgDescriptor(ArgDescriptor::argTPointer);
ptrArg.as<ArgDescPointer>().bindless = undefined<CrossThreadDataOffset>;
ptrArg.as<ArgDescPointer>().bindful = undefined<CrossThreadDataOffset>;
mockKernelImmData->kernelDescriptor->payloadMappings.explicitArgs[0] = ptrArg;
ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {};
auto result = commandList->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
} // namespace ult
} // namespace L0