acts-project / vecmem

Vectorised data model base and helper classes.
https://acts-project.github.io/vecmem/
Mozilla Public License 2.0
19 stars 13 forks source link

Synchronized Memory Resource, main branch (2023.12.27.) #260

Closed krasznaa closed 8 months ago

krasznaa commented 8 months ago

After #259, this is "the other" memory resource that I want to steal from the Thrust memory resources.

In Thrust there is an "unsynchronized" (thread-unsafe) and "synchronized" (thread-safe) version of every memory resource. They need to do that (in the end...), because thrust::mr::memory_resource is templated. But since std::pmr::memory_resource is not, instead of adding a "thread-safe wrapper" around all of our currently thread-unsafe memory resources, we can also do what this PR does. Just add a single vecmem::synchronized_memory_resource that makes sure that all allocations and de-allocations happen one-at-a-time for its upstream memory resource.

The code is trivially simple in the end, but I think it could be useful in a couple of cases. šŸ¤”

Note that Thrust also provides a "thread local version" of every one of its memory resources. But that I don't want to copy for our project. šŸ¤” thread_local is a bit heavy. So I want to leave it up to the frameworks using our memory resources, to deal with instantiating multiple memory resource objects for their multiple threads. As the frameworks themselves should be able to do it much more efficiently. (At least with TBB this can be done more efficiently than with thread_local.)

krasznaa commented 8 months ago

Let's merge this one in at first then. :wink: