Skip to content
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

Should sycl::free synchronize-with sycl::malloc? #687

Open
Pennycook opened this issue Jan 14, 2025 · 1 comment
Open

Should sycl::free synchronize-with sycl::malloc? #687

Pennycook opened this issue Jan 14, 2025 · 1 comment

Comments

@Pennycook
Copy link
Contributor

The definition of std::free in C++ redirects to the definition of free in C, which says (in Section 7.22.3 of the C11 draft, "Memory management functions"):

A call to free or realloc that deallocates a region p of memory synchronizes with any allocation call that allocates all or part of the region p. This synchronization occurs after any access of p by the deallocating function, and before any such access by the allocating function.

Should this guarantee hold for sycl::free as well?

I cannot immediately see how a developer could detect or rely upon this behavior, but it does seem reasonable to say that sycl::free on a particular memory region always "happens before" any sycl::malloc call that returns the same memory, and that simply accessing the pointer returned by sycl::malloc cannot lead to a race condition.

@TApplencourt
Copy link
Contributor

TApplencourt commented Jan 14, 2025

Free and Maloc are blocking. And all our API are thread-safe.

SYCL guarantees that all the member functions and special member functions of the SYCL classes described are thread safe.

So I don't understand how any of this can be a problem... But the C people are far smarter than me, so I guess they put it for a reason; so why not copy them : )


Side note for our editor @gmlueck before i forgot. We use both "thread-safe" and "thread safe", I guess we may want to converge to one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants