Skip to main content

fuel_vulkan_dispatch/
lib.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2//! Vulkan kernel bindings for [`fuel_dispatch`] (ROADMAP row 137, step 6.1).
3//!
4//! These lived inside `fuel-dispatch` behind `feature = "vulkan"`; they now sit **above** it, the way the
5//! vendor CPU backends (`fuel-aocl-cpu-backend`, `fuel-mkl-cpu-backend`) already do: they use the public
6//! kernel-table API of `fuel-dispatch` and hand it a registrar. `fuel-dispatch` no longer registers
7//! Vulkan kernels itself, so **something has to call [`install_global`]** before the process-wide binding
8//! table is read for a plan. `fuel-tensor` does it (its `cpu_accel::ensure_installed`, which runs right
9//! before the bridge takes its snapshot, see the hazard below). A caller that builds its own
10//! `KernelBindingTable` calls [`register_vulkan_kernels`] on it instead.
11//!
12//! # The snapshot hazard
13//!
14//! Readers of the global table take a snapshot (`fuel_dispatch::dispatch::global_bindings`). An
15//! extension (`extend_global_bindings`) publishes a new table for LATER readers; a snapshot already
16//! taken keeps the old one. So a Vulkan kernel registered after a snapshot is invisible to whoever holds
17//! that snapshot, with no error. The rule: install before the first snapshot that a Vulkan-capable
18//! realize will use. `fuel-tensor/tests/vulkan_install_before_snapshot.rs` fails if that order breaks.
19//!
20//! # Layout
21//!
22//! - [`vulkan_dispatch`]: the Vulkan kernel wrappers and [`register_vulkan_kernels`] (moved unchanged
23//!   from `fuel-dispatch/src/vulkan_dispatch.rs`; the module keeps its name so the paths inside it and
24//!   in [`link`] did not change).
25//! - [`link`]: the FKC link registry that binds contract entry points to those wrappers.
26
27pub mod link;
28pub mod vulkan_dispatch;
29
30pub use link::{VULKAN_CAST_ENTRY_POINTS, VULKAN_ELEMENTWISE_ENTRY_POINTS, VulkanLinkRegistry};
31pub use vulkan_dispatch::register_vulkan_kernels;
32
33use std::sync::Once;
34
35/// Add the Vulkan kernels to the process-wide binding table, once per process, together with the
36/// derived `BackendCapabilities` for the Vulkan backend (the step `fuel-dispatch` used to run for every
37/// compiled-in GPU backend right after registering them). Safe to call from any number of threads and
38/// any number of times: later calls return immediately. See the crate docs for when it must run.
39pub fn install_global() {
40    static INSTALLED: Once = Once::new();
41    INSTALLED.call_once(|| {
42        fuel_dispatch::dispatch::extend_global_bindings(|table| {
43            register_vulkan_kernels(table);
44            fuel_dispatch::dispatch::register_derived_caps_for(
45                fuel_ir::probe::BackendId::Vulkan,
46                table,
47            );
48        });
49    });
50}