mirror of
https://github.com/storytold/craft-ai-integrations.git
synced 2026-11-02 18:06:49 +00:00
fix(ai-engine-burn): run the processor fallback on every core with SIMD (#113)
The crate turns off Burn's default features, which also dropped `rayon` and `simd`: burn-ndarray was built with `std` only, so the processor fallback ran on one core with scalar maths. Turning both on gives burn-ndarray `multi-threads` and `simd`. Measured on the InSPyReNet network (640 x 333 picture, processor, i5-12600KF, release): 22.8 s -> 6.2 s, masks identical to one pixel by one level. SAM 2.1's processor timing was not re-measured; the doc says so. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Generated
+20
@@ -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"
|
||||
|
||||
@@ -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 }
|
||||
|
||||
|
||||
+4
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user