Skip to content

Commit 6b4375e

Browse files
Re-enable use case where application allocates own RTDispatchGlobals.
Implementation was assuming that if HasRTCalls is true then the RTDispatchGlobals patch token is also valid, but that isn't the case when the application is using its own RTDispatchGlobals instead of the one provided by the L0 UMD. Related-To: LOCI-3323 Signed-off-by: Jim Snow <[email protected]>
1 parent 61510e9 commit 6b4375e

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

level_zero/core/source/kernel/kernel_imp.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -903,22 +903,28 @@ ze_result_t KernelImp::initialize(const ze_kernel_desc_t *desc) {
903903

904904
if (this->usesRayTracing()) {
905905
uint32_t bvhLevels = NEO::RayTracingHelper::maxBvhLevels;
906-
neoDevice->initializeRayTracing(bvhLevels);
907-
auto rtDispatchGlobalsInfo = neoDevice->getRTDispatchGlobals(bvhLevels);
908-
if (rtDispatchGlobalsInfo == nullptr) {
909-
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
910-
}
906+
auto arg = this->getImmutableData()->getDescriptor().payloadMappings.implicitArgs.rtDispatchGlobals;
907+
if (arg.pointerSize == 0) {
908+
// kernel is allocating its own RTDispatchGlobals manually
909+
neoDevice->initializeRayTracing(0);
910+
} else {
911+
neoDevice->initializeRayTracing(bvhLevels);
912+
auto rtDispatchGlobalsInfo = neoDevice->getRTDispatchGlobals(bvhLevels);
913+
if (rtDispatchGlobalsInfo == nullptr) {
914+
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
915+
}
911916

912-
for (auto rtDispatchGlobals : rtDispatchGlobalsInfo->rtDispatchGlobals) {
913-
this->residencyContainer.push_back(rtDispatchGlobals);
914-
}
917+
for (auto rtDispatchGlobals : rtDispatchGlobalsInfo->rtDispatchGlobals) {
918+
this->residencyContainer.push_back(rtDispatchGlobals);
919+
}
915920

916-
auto address = rtDispatchGlobalsInfo->rtDispatchGlobals[0]->getGpuAddressToPatch();
917-
NEO::patchPointer(ArrayRef<uint8_t>(crossThreadData.get(), crossThreadDataSize),
918-
this->getImmutableData()->getDescriptor().payloadMappings.implicitArgs.rtDispatchGlobals,
919-
static_cast<uintptr_t>(address));
921+
auto address = rtDispatchGlobalsInfo->rtDispatchGlobals[0]->getGpuAddressToPatch();
922+
NEO::patchPointer(ArrayRef<uint8_t>(crossThreadData.get(), crossThreadDataSize),
923+
arg,
924+
static_cast<uintptr_t>(address));
920925

921-
this->residencyContainer.push_back(neoDevice->getRTMemoryBackedBuffer());
926+
this->residencyContainer.push_back(neoDevice->getRTMemoryBackedBuffer());
927+
}
922928
}
923929

924930
return ZE_RESULT_SUCCESS;

level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,49 @@ TEST_F(KernelImmutableDataTests, whenHasRTCallsIsTrueThenRayTracingIsInitialized
734734
EXPECT_NE(nullptr, rtDispatchGlobals);
735735
}
736736

737+
TEST_F(KernelImmutableDataTests, whenHasRTCallsIsTrueAndPatchTokenPointerSizeIsZeroThenRayTracingIsInitialized) {
738+
static_cast<OsAgnosticMemoryManager *>(device->getNEODevice()->getMemoryManager())->turnOnFakingBigAllocations();
739+
740+
KernelDescriptor mockDescriptor = {};
741+
mockDescriptor.kernelAttributes.flags.hasRTCalls = true;
742+
mockDescriptor.kernelMetadata.kernelName = "rt_test";
743+
for (auto i = 0u; i < 3u; i++) {
744+
mockDescriptor.kernelAttributes.requiredWorkgroupSize[i] = 0;
745+
}
746+
747+
std::unique_ptr<MockImmutableData> mockKernelImmutableData =
748+
std::make_unique<MockImmutableData>(32u);
749+
mockKernelImmutableData->kernelDescriptor = &mockDescriptor;
750+
mockDescriptor.payloadMappings.implicitArgs.rtDispatchGlobals.pointerSize = 0;
751+
752+
ModuleBuildLog *moduleBuildLog = nullptr;
753+
module = std::make_unique<MockModule>(device,
754+
moduleBuildLog,
755+
ModuleType::User,
756+
32u,
757+
mockKernelImmutableData.get());
758+
module->maxGroupSize = 10;
759+
760+
std::unique_ptr<ModuleImmutableDataFixture::MockKernel> kernel;
761+
kernel = std::make_unique<ModuleImmutableDataFixture::MockKernel>(module.get());
762+
763+
ze_kernel_desc_t kernelDesc = {};
764+
kernelDesc.pKernelName = "rt_test";
765+
766+
auto immDataVector =
767+
const_cast<std::vector<std::unique_ptr<KernelImmutableData>> *>(&module->getKernelImmutableDataVector());
768+
769+
immDataVector->push_back(std::move(mockKernelImmutableData));
770+
771+
auto result = kernel->initialize(&kernelDesc);
772+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
773+
EXPECT_NE(nullptr, module->getDevice()->getNEODevice()->getRTMemoryBackedBuffer());
774+
775+
// Application is expected to allocate its own RTDispatchGlobals manually in this case.
776+
auto rtDispatchGlobals = neoDevice->getRTDispatchGlobals(NEO::RayTracingHelper::maxBvhLevels);
777+
EXPECT_EQ(nullptr, rtDispatchGlobals);
778+
}
779+
737780
HWTEST2_F(KernelImmutableDataTests, whenHasRTCallsIsTrueAndNoRTDispatchGlobalsIsAllocatedThenRayTracingIsNotInitialized, IsAtLeastXeHpgCore) {
738781
KernelDescriptor mockDescriptor = {};
739782
mockDescriptor.kernelAttributes.flags.hasRTCalls = true;

0 commit comments

Comments
 (0)