Skip to content

Commit 79e4990

Browse files
fix: Return success for system address in setArg
This patch avoids returning error for system addresses in setArg Related-To: GSD-3597 Signed-off-by: Joshua Santosh Ranjan <joshua.santosh.ranjan@intel.com> Source: 91784a8
1 parent ac19ddf commit 79e4990

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

level_zero/core/source/kernel/kernel_imp.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -701,10 +701,7 @@ ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const voi
701701
allocData = svmAllocsManager->getSVMAlloc(requestedAddress);
702702
}
703703
NEO::SvmAllocationData *peerAllocData = nullptr;
704-
if (driverHandle->isRemoteResourceNeeded(requestedAddress, alloc, allocData, device)) {
705-
if (allocData == nullptr) {
706-
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
707-
}
704+
if (allocData && driverHandle->isRemoteResourceNeeded(requestedAddress, alloc, allocData, device)) {
708705

709706
uint64_t pbase = allocData->gpuAllocations.getDefaultGraphicsAllocation()->getGpuAddress();
710707
uint64_t offset = (uint64_t)requestedAddress - pbase;
@@ -714,10 +711,23 @@ ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const voi
714711
}
715712
gpuAddress += offset;
716713
}
717-
const uint32_t allocId = allocData ? allocData->getAllocId() : 0u;
714+
715+
if (allocData == nullptr) {
716+
if (NEO::DebugManager.flags.DisableSystemPointerKernelArgument.get() != 1) {
717+
const auto &argAsPtr = kernelImmData->getDescriptor().payloadMappings.explicitArgs[argIndex].as<NEO::ArgDescPointer>();
718+
auto patchLocation = ptrOffset(getCrossThreadData(), argAsPtr.stateless);
719+
patchWithRequiredSize(const_cast<uint8_t *>(patchLocation), argAsPtr.pointerSize, reinterpret_cast<uintptr_t>(requestedAddress));
720+
kernelArgInfos[argIndex] = KernelArgInfo{requestedAddress, 0, 0, false};
721+
return ZE_RESULT_SUCCESS;
722+
} else {
723+
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
724+
}
725+
}
726+
727+
const uint32_t allocId = allocData->getAllocId();
718728
kernelArgInfos[argIndex] = KernelArgInfo{requestedAddress, allocId, allocationsCounter, false};
719729

720-
if (allocData && allocData->virtualReservationData) {
730+
if (allocData->virtualReservationData) {
721731
for (const auto &mappedAllocationData : allocData->virtualReservationData->mappedAllocations) {
722732
// Add additional allocations to the residency container if the virtual reservation spans multiple allocations.
723733
if (requestedAddress != mappedAllocationData.second->ptr) {

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,17 @@ TEST_F(SetKernelArgCacheTest, givenValidBufferArgumentWhenSetMultipleTimesThenSe
274274
EXPECT_EQ(ZE_RESULT_SUCCESS, mockKernel.setArgBuffer(0, sizeof(secondSvmAllocation), &secondSvmAllocation));
275275
EXPECT_EQ(++callCounter, mockKernel.setArgBufferWithAllocCalled);
276276

277-
// same value but no svmData - ZE_RESULT_ERROR_INVALID_ARGUMENT
277+
// same value but no svmData - ZE_RESULT_SUCCESS with allocId as 0
278278
svmAllocsManager->freeSVMAlloc(secondSvmAllocation);
279279
++svmAllocsManager->allocationsCounter;
280280
ASSERT_GT(mockKernel.kernelArgInfos[0].allocId, 0u);
281281
ASSERT_LT(mockKernel.kernelArgInfos[0].allocId, SvmAllocationData::uninitializedAllocId);
282282
ASSERT_EQ(mockKernel.kernelArgInfos[0].value, secondSvmAllocation);
283283
ASSERT_GT(svmAllocsManager->allocationsCounter, 0u);
284284
ASSERT_NE(mockKernel.kernelArgInfos[0].allocIdMemoryManagerCounter, svmAllocsManager->allocationsCounter);
285-
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, mockKernel.setArgBuffer(0, sizeof(secondSvmAllocation), &secondSvmAllocation));
285+
EXPECT_EQ(ZE_RESULT_SUCCESS, mockKernel.setArgBuffer(0, sizeof(secondSvmAllocation), &secondSvmAllocation));
286+
ASSERT_EQ(mockKernel.kernelArgInfos[0].value, secondSvmAllocation);
287+
ASSERT_EQ(mockKernel.kernelArgInfos[0].allocId, 0u);
286288
EXPECT_EQ(callCounter, mockKernel.setArgBufferWithAllocCalled);
287289

288290
svmAllocsManager->freeSVMAlloc(svmAllocation);
@@ -626,15 +628,22 @@ HWTEST2_F(SetKernelArg, givenSamplerAndKernelWhenSetArgSamplerThenCrossThreadDat
626628
EXPECT_EQ(static_cast<uint32_t>(SamplerPatchValues::NormalizedCoordsTrue), *pSamplerNormalizedCoords);
627629
}
628630

629-
using ArgSupport = IsWithinProducts<IGFX_SKYLAKE, IGFX_TIGERLAKE_LP>;
630-
631-
HWTEST2_F(SetKernelArg, givenBufferArgumentWhichHasNotBeenAllocatedByRuntimeThenInvalidArgumentIsReturned, ArgSupport) {
631+
TEST_F(SetKernelArg, givenBufferArgumentWhichHasNotBeenAllocatedByRuntimeThenSuccessIsReturned) {
632632
createKernel();
633633

634634
uint64_t hostAddress = 0x1234;
635-
636635
ze_result_t res = kernel->setArgBuffer(0, sizeof(hostAddress), &hostAddress);
636+
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
637+
}
637638

639+
TEST_F(SetKernelArg, givenDisableSystemPointerKernelArgumentIsEnabledWhenBufferArgumentisNotAllocatedByRuntimeThenErrorIsReturned) {
640+
641+
DebugManagerStateRestore restorer;
642+
NEO::DebugManager.flags.DisableSystemPointerKernelArgument.set(1);
643+
createKernel();
644+
645+
uint64_t hostAddress = 0x1234;
646+
ze_result_t res = kernel->setArgBuffer(0, sizeof(hostAddress), &hostAddress);
638647
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res);
639648
}
640649

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, SynchronizeEventBeforeReset, -1, "-1: default, 0
250250
DECLARE_DEBUG_VARIABLE(int32_t, TrackNumCsrClientsOnSyncPoints, -1, "-1: default, 0: Disabled, 1: If set, synchronization points like zeEventHostSynchronize will unregister CmdQ from CSR clients")
251251
DECLARE_DEBUG_VARIABLE(int32_t, OverrideDriverVersion, -1, "-1: default, >=0: Use value as reported driver version")
252252
DECLARE_DEBUG_VARIABLE(int32_t, WaitForUserFenceOnEventHostSynchronize, -1, "-1: default, 0: Disabled, 1: Enabled. If enabled, use WaitUserFence KMD call for in-order Events instead of active polling on host.")
253+
DECLARE_DEBUG_VARIABLE(int32_t, DisableSystemPointerKernelArgument, -1, "-1: default, 0: Disabled, 1: using a system pointer for kernel argument returns an error.")
253254
DECLARE_DEBUG_VARIABLE(int32_t, ProgramUserInterruptOnResolvedDependency, -1, "-1: default, 0: Disabled, >=1: bitfield. 01b: program after semaphore, 10b: on signaling fence (non-walker append).")
254255

255256
/*LOGGING FLAGS*/

shared/test/common/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,5 +548,6 @@ EnableAIL=1
548548
WaitForUserFenceOnEventHostSynchronize = -1
549549
ProgramUserInterruptOnResolvedDependency = -1
550550
ProgramBarrierInCommandStreamTask = -1
551+
DisableSystemPointerKernelArgument = -1
551552
DoNotValidateDriverPath = 0
552553
# Please don't edit below this line

0 commit comments

Comments
 (0)