xtensor-stack / xtensor

C++ tensors with broadcasting and lazy computing
BSD 3-Clause "New" or "Revised" License
3.37k stars 400 forks source link

Memory pool for Xtensor #2566

Open spectre-ns opened 2 years ago

spectre-ns commented 2 years ago

I would like to use xtensor in a real time computing application and I need to avoid allocations from new and delete while computing the data with all the allocations occurring prior to computation starting. I can use std::pmr to accomplish this is there any way to pin xtensor to this memory object?

wolfv commented 2 years ago

I think you can use your own allocator as an argument in the template.

spectre-ns commented 2 years ago

@wolfv thanks! I have been able to use the polymorphic_allocator<> to get xtensor working from a pool. Would there be anyway to pass it the resource like std::pmr:vector does so I don't have to set the global resource pointer?

JohanMabille commented 2 years ago

This requires to update the constructors of the xtensor and xarray classes, so they accept an additional argument and forward it to the storage container. This is definitely a PR that we would accept, I can provide some guidance if needed.

spectre-ns commented 2 years ago

@JohanMabille I have another pull request on my queue right now. After I complete that I might work on this. Is QuantStack still adding features to xtensor as well or are their other priorities right now?

JohanMabille commented 2 years ago

Both, xtensor is not funded at this time, so we are maintaining it on our free time, but we still have ideas and a plan for xtensor ;)

spectre-ns commented 2 years ago

@JohanMabille I think making xtensor work with pmr would require C++17.