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

Piotr Balcer via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 06:31:28 PDT 2025


pbalcer wrote:

> How difficult would it be to just make `SmallVector<ol_platform_impl_t, 4> Platforms{};` take a unique pointer instead? 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 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.

> 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 https://github.com/llvm/llvm-project/issues/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. Then, devices could just store the enum / index into that array.

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


More information about the llvm-commits mailing list