[SYCL] Enqueuing USM memory free
- Dominant language
- LLVM
- Stars
- 1.5k
- Forks
- 854
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 137
Description
In cases where a user wants to create an asynchronous function which creates some USM there is currently no good way to release the memory. It would be useful to have a method to enqueue the release of USM depending on an event.
A possible solution could be something along the lines of a queue member function: `sycl::event queue::free(void *ptr, const std::vector &depEvents);`.
Currently, a user could enqueue freeing USM with a `host_task`. However, I think this does not lineup with how people expect
to use the `host_task` or `sycl::free`.
It could also argue `malloc` should also have an asychronous call. However this may be more complicated then enqueuing freeing memory. As a pointer would have to be returned to the user, prior to the actual pointer being known.
Options:
- USM `free`/`malloc` cannot be enqueued.
- USM `free`/`malloc` enqueuing should be done via host_task.
- USM `free`/`malloc` should be done with a queue member function.
Example use case, for enqueued free.
```
sycl::event Foo(sycl::queue &queue, float *a) {
// Create scratch usm
float *scratch = int *ipiv32 =
(float *)malloc_device(sizeof(float) * size, queue);
// Do work on a and scratch
sycl::event event = queue.submit([&](sycl::handler &cgh) {
cgh.parallel_for(sycl::range<1>{size}, [=](sycl::id<1> index) {
// Do work
});
});
// Can free memory using `host_task`, to make asynchronous.
// This should work but is quite verbose, and goes against expected language
// syntax
sycl::event final_event = queue.submit([&](sycl::handler &cgh) {
cgh.depends_on(event);
cgh.host_task([=](sycl::interop_handle ih) { sycl::free(scratch, queue); });
});
// Desired
sycl::event final_event = queue.free(scratch, e);
return final_event
}
```
Contributor guide
Assessment
This issue has not been assessed yet.