Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

[SYCL] fix memory leak #705

Merged
merged 2 commits into from
Jan 10, 2022
Merged

[SYCL] fix memory leak #705

merged 2 commits into from
Jan 10, 2022

Conversation

bso-intel
Copy link

Add calls to free() to release memory properly.

Signed-off-by: Byoungro So [email protected]

Signed-off-by: Byoungro So <[email protected]>
@bso-intel bso-intel requested a review from a team as a code owner January 6, 2022 06:15
@@ -63,8 +63,10 @@ int main() {
unsigned char *HostAlloc = (unsigned char *)malloc_host(1, c);
auto e = q.memset(HostAlloc, 42, 1);
if (e.get_backend() != plt.get_backend()) {
free(HostAlloc, c);

Choose a reason for hiding this comment

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

Since HostAlloc is freed no matter which path is taken here, could they be unified before the if?

Copy link
Author

Choose a reason for hiding this comment

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

Done. I was not sure if it is safe to free memory before e.get_backend() because e is associated with HostAlloc USM memory.

Choose a reason for hiding this comment

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

I believe freeing will synchronize with the event, but from there it should be valid even after related resources are freed. Until recently you would have to do an explicit wait for e before freeing, but in that case the previous code would be broken as well. If you want peace of mind you can call and store e.get_backend ahead of freeing and then use the result in the if, but I'd argue if it didn't work as-is it is a bug. 😄

Signed-off-by: Byoungro So <[email protected]>
Copy link

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

LGTM!

@vladimirlaz vladimirlaz merged commit 5f4d951 into intel:intel Jan 10, 2022
@bso-intel bso-intel deleted the get-backend branch January 10, 2022 07:01
aelovikov-intel pushed a commit to aelovikov-intel/llvm that referenced this pull request Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants