Skip to content

[SYCL][L0] Fix memory leak when tracking indirect accesses #7105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 24, 2022

Conversation

aelovikov-intel
Copy link
Contributor

On the plugin API boundaries extra piKernelRetain/piKernelRelease can be called in arbitrary moments (from other threads) include before the kernel was submitted to the actual GPU HW. As such, piKernelRelease has nothing to do with submissions and indirect memory tracking updates should be initiated from the points where the kernel actually finishes - CleanupCompletedEvent.

On the plugin API boundaries extra piKernelRetain/piKernelRelease can be
called in arbitrary moments (from other threads) include *before* the
kernel was submitted to the actual GPU HW. As such, piKernelRelease has
nothing to do with submissions and indirect memory tracking updates
should be initiated from the points where the kernel actually finishes -
CleanupCompletedEvent.
@aelovikov-intel aelovikov-intel requested a review from a team as a code owner October 18, 2022 20:36
Comment on lines 5819 to 5842
if (AssociatedKernel) {
if (IndirectAccessTrackingEnabled) {
auto Kernel = AssociatedKernel;
// piKernelRelease is called by CleanupCompletedEvent(Event) as soon as
// kernel execution has finished. This is the place where we need to
// release memory allocations. If kernel is not in use (not submitted by
// some other thread) then release referenced memory allocations. As a
// result, memory can be deallocated and context can be removed from
// container in the platform. That's why we need to lock a mutex here.
pi_platform Plt = Kernel->Program->Context->getPlatform();
std::scoped_lock<pi_shared_mutex> ContextsLock(Plt->ContextsMutex);

if (--Kernel->SubmissionsCount == 0) {
// Kernel is not submitted for execution, release referenced memory
// allocations.
for (auto &MemAlloc : Kernel->MemAllocs) {
// std::pair<void *const, MemAllocRecord> *, Hash
USMFreeHelper(MemAlloc->second.Context, MemAlloc->first,
MemAlloc->second.OwnZeMemHandle);
}
Kernel->MemAllocs.clear();
}
}
PI_CALL(piKernelRelease(AssociatedKernel));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call piKernelRelease for dependent events below in this function - https://github.com/intel/llvm/pull/7105/files#diff-15dd1eb076d2164bd9e87d9057f05f652a716498e8cdf5975e564c65309a0985L5895-L5896

It looks like we need to do the same for them as well.

@againull againull merged commit 1b79491 into intel:sycl Oct 24, 2022
@aelovikov-intel aelovikov-intel deleted the l0-ind-mem-leak branch November 8, 2022 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants