Repository navigation
fix(usm): rebind stale svm kernel args at enqueue - #1063
Draft
rajathkumarravi wants to merge 1 commit into
Draft
rajathkumarravi wants to merge 1 commit into
rajathkumarravi wants to merge 1 commit into
Conversation
clSetKernelArgMemPointerINTEL and clSetKernelArgSVMPointer cache the GraphicsAllocation behind the pointer. When that allocation is released (e.g. an emptied host usm pool is trimmed) and a new one is created at the same address, enqueueing the kernel without setting the argument again used the released allocation: makeArgsResident and getResidency read freed memory and the new allocation was never made resident. Count allocations leaving the svm tracker and, at enqueue, re-resolve pointer arguments whose allocation may have been released since they were resolved. An argument whose pointer is no longer allocated drops the cached allocation and is looked up again once something is allocated. Arguments are not checked at all when no allocation was created or released since the previous check. clCloneKernel resolves outdated arguments of the source kernel instead of copying their allocation, and CL_KERNEL_ALLOCATIONS_INFO_INTEL resolves arguments by pointer value. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
USM/SVM kernel arguments cache the
GraphicsAllocationbehind the pointer. If the app frees that memory and a new allocation lands at the same address (for example after an empty host USM pool is trimmed), the next enqueue used the freed allocation: a crash, or a GPU fault because the new memory was never made resident.How it is fixed:
SVMAllocsManagernow counts frees. At enqueue, a USM/SVM argument is looked up again by its pointer, but only if something was freed since it was set, and is re-bound to the current allocation (or dropped if nothing is there). If nothing was allocated or freed since the kernel's last enqueue, the check is just two atomic loads.Reproduction
NEOReadDebugKeys=1 ExperimentalEnableHostAllocationCache=0makes it immediate).Kernel::makeArgsResident, orCL_OUT_OF_RESOURCESat finish.Frameworks that skip
clSetKernelArg*when the pointer did not change (e.g. the OpenVINO GPU plugin) hit this. Seen on PTL (Windows); reproduced on Linux with current master.Changes
SVMAllocsManager::freedAllocationsCounter: bumped inremoveSVMAlloc/freeSVMData. Moving an allocation into the reuse cache does not count; it stays alive there.Kernel::revalidateSvmAllocArgs(): called fromCommandQueueHw::enqueueKernel, next to the shared-object re-patch. It re-binds throughsetArgSvmAlloc, so surface state and allocId are refreshed.cloneKernelandgetAllocationsInforesolve such arguments by pointer instead of using a possibly freed allocation.Testing
target_unit_testsconfigs: ~558k test runs, 0 failures.-Werror; clang-format and clang-tidy (repo configs) clean.CL_OUT_OF_RESOURCES). With the fix, ~1,000 stress cycles pass and ASan is clean.Not in this PR
clSetKernelExecInfopointer lists and Level Zero kernel arguments cache allocations the same way.