diff --git a/Cargo.lock b/Cargo.lock index 77631b1..408308b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1103,6 +1103,7 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e05d08ef48d738fadf13f8689b634f8b396d5a8cbb27d0a87f61e163d241846" dependencies = [ + "aligned-vec", "burn-backend", "burn-ir", "burn-std", @@ -1110,9 +1111,11 @@ dependencies = [ "gemm 0.19.0", "half", "libm", + "macerator", "num-traits", "once_cell", "portable-atomic", + "rayon", ] [[package]] @@ -1167,7 +1170,9 @@ dependencies = [ "burn-backend", "burn-ir", "burn-std", + "bytemuck", "const-random", + "itertools 0.15.0", "libm", "macerator", "matrixmultiply", @@ -1175,6 +1180,8 @@ dependencies = [ "num-traits", "paste", "rand 0.10.3", + "rayon", + "seq-macro", ] [[package]] @@ -5445,7 +5452,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f607c237553f086e7043417a51df26b2eb899d3caff94e6a67592ff992fedc7" dependencies = [ "autocfg", + "num_cpus", + "once_cell", "rawpointer", + "thread-tree", ] [[package]] @@ -5649,6 +5659,7 @@ dependencies = [ "portable-atomic", "portable-atomic-util", "rawpointer", + "rayon", ] [[package]] @@ -8388,6 +8399,15 @@ dependencies = [ "syn 3.0.7", ] +[[package]] +name = "thread-tree" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbd370cb847953a25954d9f63e14824a36113f8c72eecf6eccef5dc4b45d630" +dependencies = [ + "crossbeam-channel", +] + [[package]] name = "thread_local" version = "1.1.10" diff --git a/crates/ai-engine-burn/Cargo.toml b/crates/ai-engine-burn/Cargo.toml index 4f1496e..c8e07d8 100644 --- a/crates/ai-engine-burn/Cargo.toml +++ b/crates/ai-engine-burn/Cargo.toml @@ -22,8 +22,10 @@ craft-ai-features = { path = "../ai-features", package = "craft-ai-features" } # The request handling (clicks, box, the picture kept between requests, the empty-mask answer), # picture decoding and resampling are engine-neutral and live there once. craft-ai-engine-rten = { path = "../ai-engine-rten", package = "craft-ai-engine-rten" } -# `wgpu` reaches Vulkan, Metal and DirectX 12 cards; `ndarray` is the processor fallback. -burn = { version = "=0.22.1", default-features = false, features = ["std", "ndarray", "wgpu"] } +# `wgpu` reaches Vulkan, Metal and DirectX 12 cards; `ndarray` is the processor fallback. Without +# `rayon` and `simd` (off with the default features) the processor fallback runs on one core with +# scalar maths. +burn = { version = "=0.22.1", default-features = false, features = ["std", "ndarray", "wgpu", "rayon", "simd"] } burn-store = "=0.22.1" craft-ai-burn-setup = { path = "../ai-burn-setup", package = "craft-ai-burn-setup", features = ["conversion"], optional = true } diff --git a/docs/BURN-ENGINE.md b/docs/BURN-ENGINE.md index 5a4711f..a3e5c27 100644 --- a/docs/BURN-ENGINE.md +++ b/docs/BURN-ENGINE.md @@ -79,7 +79,10 @@ python tools/mutation/mutation_check.py be - SAM 2.1 tiny only. A different architecture needs its own generated code and runner. - Click and box prompts. A description stays on the ComfyUI route. - The processor fallback uses Burn's `ndarray` backend, which Burn has marked deprecated in favour - of `burn-flex`. Swap it once flex is measured. + of `burn-flex`. Swap it once flex is measured. It is built with Burn's `rayon` and `simd` + features: the crate turns Burn's default features off, and without these two the processor runs + on one core with scalar maths (3.7 times slower on the one network measured, see the pull request + that turned them on). The SAM 2.1 timings below were taken before that change. - `CRAFT_AI_BURN_DEVICE=cpu` forces the processor even when a graphics card answers. Run on the test PC (release, astronaut sample): one click and one box both gave IoU 1.0000 against rten (22.5 % selected by both). Timings on the processor: first run 8.70 s (rten 0.71 s), second