From b8fb16c603c8f5e5865822db7ae998683d7b0b74 Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Wed, 18 Sep 2024 10:26:36 +0000 Subject: [PATCH] fix: initialize kernel members at the beginning Signed-off-by: Bartosz Dunajski --- level_zero/core/source/kernel/kernel_imp.cpp | 41 +++++++++++-------- level_zero/core/source/module/module_imp.cpp | 12 ------ .../unit_tests/sources/module/test_module.cpp | 4 +- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/level_zero/core/source/kernel/kernel_imp.cpp b/level_zero/core/source/kernel/kernel_imp.cpp index 8ab192a824..3eea41f3ef 100644 --- a/level_zero/core/source/kernel/kernel_imp.cpp +++ b/level_zero/core/source/kernel/kernel_imp.cpp @@ -995,10 +995,19 @@ ze_result_t KernelImp::initialize(const ze_kernel_desc_t *desc) { if (this->kernelImmData == nullptr) { return ZE_RESULT_ERROR_INVALID_KERNEL_NAME; } + auto neoDevice = module->getDevice()->getNEODevice(); + + auto localMemSize = static_cast(neoDevice->getDeviceInfo().localMemSize); + auto slmInlineSize = this->kernelImmData->getDescriptor().kernelAttributes.slmInlineSize; + if (slmInlineSize > 0 && localMemSize < slmInlineSize) { + CREATE_DEBUG_STRING(str, "Size of SLM (%u) larger than available (%u)\n", slmInlineSize, localMemSize); + module->getDevice()->getDriverHandle()->setErrorDescription(std::string(str.get())); + PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Size of SLM (%u) larger than available (%u)\n", slmInlineSize, localMemSize); + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } auto isaAllocation = this->kernelImmData->getIsaGraphicsAllocation(); - auto neoDevice = module->getDevice()->getNEODevice(); const auto &productHelper = neoDevice->getProductHelper(); const auto &rootDeviceEnvironment = module->getDevice()->getNEODevice()->getRootDeviceEnvironment(); auto &kernelDescriptor = kernelImmData->getDescriptor(); @@ -1011,6 +1020,21 @@ ze_result_t KernelImp::initialize(const ze_kernel_desc_t *desc) { } UNRECOVERABLE_IF(!this->kernelImmData->getKernelInfo()->heapInfo.pKernelHeap); + const auto &hwInfo = neoDevice->getHardwareInfo(); + auto deviceBitfield = neoDevice->getDeviceBitfield(); + const auto &gfxHelper = rootDeviceEnvironment.getHelper(); + + this->midThreadPreemptionDisallowedForRayTracingKernels = productHelper.isMidThreadPreemptionDisallowedForRayTracingKernels(); + + this->heaplessEnabled = rootDeviceEnvironment.getHelper().isHeaplessModeEnabled(); + this->localDispatchSupport = productHelper.getSupportedLocalDispatchSizes(hwInfo).size() > 0; + + bool platformImplicitScaling = gfxHelper.platformSupportsImplicitScaling(rootDeviceEnvironment); + this->implicitScalingEnabled = NEO::ImplicitScalingHelper::isImplicitScalingEnabled(deviceBitfield, platformImplicitScaling); + + this->rcsAvailable = gfxHelper.isRcsAvailable(hwInfo); + this->cooperativeSupport = productHelper.isCooperativeEngineSupported(hwInfo); + if (isaAllocation->getAllocationType() == NEO::AllocationType::kernelIsaInternal && this->kernelImmData->getIsaParentAllocation() == nullptr) { isaAllocation->setTbxWritable(true, std::numeric_limits::max()); isaAllocation->setAubWritable(true, std::numeric_limits::max()); @@ -1162,21 +1186,6 @@ ze_result_t KernelImp::initialize(const ze_kernel_desc_t *desc) { this->internalResidencyContainer.push_back(rtDispatchGlobalsInfo->rtDispatchGlobalsArray); } - const auto &hwInfo = neoDevice->getHardwareInfo(); - auto deviceBitfield = neoDevice->getDeviceBitfield(); - const auto &gfxHelper = rootDeviceEnvironment.getHelper(); - - this->midThreadPreemptionDisallowedForRayTracingKernels = productHelper.isMidThreadPreemptionDisallowedForRayTracingKernels(); - - this->heaplessEnabled = rootDeviceEnvironment.getHelper().isHeaplessModeEnabled(); - this->localDispatchSupport = productHelper.getSupportedLocalDispatchSizes(hwInfo).size() > 0; - - bool platformImplicitScaling = gfxHelper.platformSupportsImplicitScaling(rootDeviceEnvironment); - this->implicitScalingEnabled = NEO::ImplicitScalingHelper::isImplicitScalingEnabled(deviceBitfield, platformImplicitScaling); - - this->rcsAvailable = gfxHelper.isRcsAvailable(hwInfo); - this->cooperativeSupport = productHelper.isCooperativeEngineSupported(hwInfo); - return ZE_RESULT_SUCCESS; } diff --git a/level_zero/core/source/module/module_imp.cpp b/level_zero/core/source/module/module_imp.cpp index f68c0be8c4..4b2cf5c5f3 100644 --- a/level_zero/core/source/module/module_imp.cpp +++ b/level_zero/core/source/module/module_imp.cpp @@ -983,18 +983,6 @@ ze_result_t ModuleImp::createKernel(const ze_kernel_desc_t *desc, driverHandle->clearErrorDescription(); } - auto localMemSize = static_cast(this->getDevice()->getNEODevice()->getDeviceInfo().localMemSize); - for (const auto &kernelImmutableData : this->getKernelImmutableDataVector()) { - auto slmInlineSize = kernelImmutableData->getDescriptor().kernelAttributes.slmInlineSize; - if (slmInlineSize > 0 && localMemSize < slmInlineSize) { - CREATE_DEBUG_STRING(str, "Size of SLM (%u) larger than available (%u)\n", slmInlineSize, localMemSize); - driverHandle->setErrorDescription(std::string(str.get())); - PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Size of SLM (%u) larger than available (%u)\n", slmInlineSize, localMemSize); - res = ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; - break; - } - } - return res; } diff --git a/level_zero/core/test/unit_tests/sources/module/test_module.cpp b/level_zero/core/test/unit_tests/sources/module/test_module.cpp index 4dbebcc075..724a5d9f2d 100644 --- a/level_zero/core/test/unit_tests/sources/module/test_module.cpp +++ b/level_zero/core/test/unit_tests/sources/module/test_module.cpp @@ -4612,9 +4612,7 @@ TEST_F(ModuleTests, givenFullyLinkedModuleAndSlmSizeExceedingLocalMemorySizeWhen std::string output = testing::internal::GetCapturedStderr(); const std::string expectedPart = "Size of SLM (" + std::to_string(slmInlineSizeCopy) + ") larger than available (" + std::to_string(localMemSize) + ")\n"; - EXPECT_TRUE(output.find(expectedPart)); - - Kernel::fromHandle(kernelHandle)->destroy(); + EXPECT_NE(std::string::npos, output.find(expectedPart)); } TEST_F(ModuleTests, givenFullyLinkedModuleWhenCreatingKernelThenDebugMsgOnPrivateAndScratchUsageIsPrinted) {