[llvm] [Offload] Initialize all platforms before plugin device creation (PR #160702)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 06:41:58 PDT 2025


jhuber6 wrote:

> > How difficult would it be to just make `SmallVector<ol_platform_impl_t, 4> Platforms{};` take a unique pointer instead?
> 
> I was thinking of `SmallVector<shared_ptr<ol_platform_impl_t>, 4> Platforms{};` in the context and `weak_ptr<ol_platform_impl_t> Platform` in devices. That's one of the options I mentioned in the commit message. Using unique_ptr would probably be simpler, but would require the devices to have a non-owning raw pointer taken from that unique_ptr (or a reference maybe? platforms will outlive devices). I have no strong preference.
>

I figured we'd just keep a reference since the platform outlives all the devices, but I don't know the code intimately.

> > In the future I really want to remove this restriction that _all_ platforms and devices must be initialized at init time, as it's extremely expensive if you don't end up needing them.
> 
> I did see #159636, maybe we could represent that as a fixed-size collection of optionals that are initialized on first use? Given we have an enum of backends (`enum ol_platform_backend_t`), it could be a simple array. Devices could just store the enum / index into that array.

Since all access goes through this, I was wondering if we turned it first into a smart pointers we could then wrap that interface with some kind of lazy initializer that checks if it's active and does so on first use. Would mean we have some fixed overhead on every single API call, but I'm assuming it's worthwhile.

https://github.com/llvm/llvm-project/pull/160702


More information about the llvm-commits mailing list