Skip to content

Commit 8fc0bf9

Browse files
kalwaltclaude
andcommitted
fix(bench): resolve SIMD benchmark compilation errors
- Add required-features = ["simd-x86-sse41"] to simd_bench in Cargo.toml to ensure the feature is properly enabled when running benchmarks - Make SIMD function imports conditional in simd_bench.rs using #[cfg(all(target_arch = "x86_64", target_feature = "sse4.1"))] guards to match the function definitions Fixes #107 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 052a49e commit 8fc0bf9

3 files changed

Lines changed: 59 additions & 5 deletions

File tree

crates/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ harness = false
118118
[[bench]]
119119
name = "simd_bench"
120120
harness = false
121+
required-features = ["simd-x86-sse41"]
121122

122123
[[bench]]
123124
name = "feature_map_bench"

crates/core/benches/simd_bench.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@
3535
*/
3636

3737
use criterion::{black_box, criterion_group, criterion_main, Criterion};
38-
use webarkitlib_rs::image_proc::{
39-
box_filter_h_scalar, box_filter_h_simd_x86, box_filter_v_scalar, box_filter_v_simd_x86,
40-
rgba_to_gray_scalar, rgba_to_gray_simd_x86,
41-
};
42-
use webarkitlib_rs::pattern::{dot_product_scalar, dot_product_simd_x86};
38+
use webarkitlib_rs::image_proc::{box_filter_h_scalar, box_filter_v_scalar, rgba_to_gray_scalar};
39+
use webarkitlib_rs::pattern::dot_product_scalar;
40+
41+
#[cfg(all(target_arch = "x86_64", target_feature = "sse4.1"))]
42+
use webarkitlib_rs::image_proc::{box_filter_h_simd_x86, box_filter_v_simd_x86, rgba_to_gray_simd_x86};
43+
44+
#[cfg(all(target_arch = "x86_64", target_feature = "sse4.1"))]
45+
use webarkitlib_rs::pattern::dot_product_simd_x86;
4346

4447
fn bench_rgba_to_gray(c: &mut Criterion) {
4548
let size = 640 * 480 * 4;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## Summary
2+
SIMD benchmarks fail to compile due to unconditional imports of conditionally-compiled functions and missing `required-features` declaration.
3+
4+
## Environment
5+
- **Product/Service**: WebARKitLib-rs
6+
- **Crate**: `crates/core`
7+
- **Component**: Benchmarks (`simd_bench`)
8+
9+
## Reproduction Steps
10+
1. Run `cargo bench --features simd`
11+
2. Observe compilation error in `crates/core/benches/simd_bench.rs`
12+
13+
## Expected Behavior
14+
Benchmarks compile and run successfully when `--features simd` is enabled, comparing scalar and SIMD implementations.
15+
16+
## Actual Behavior
17+
Compilation fails with `error[E0432]: unresolved imports` for SIMD functions:
18+
- `box_filter_h_simd_x86`
19+
- `box_filter_v_simd_x86`
20+
- `rgba_to_gray_simd_x86`
21+
- `dot_product_simd_x86`
22+
23+
## Error Details
24+
```
25+
error[E0432]: unresolved imports `webarkitlib_rs::image_proc::box_filter_h_simd_x86`, ...
26+
--> crates\core\benches\simd_bench.rs:39:26
27+
28+
note: found an item that was configured out
29+
--> crates\core\src\ar\image_proc.rs:576:15
30+
```
31+
32+
The functions are gated behind `#[cfg(all(feature = "simd-image", target_arch = "x86_64", target_feature = "sse4.1"))]`.
33+
34+
## Root Cause
35+
1. **Missing `required-features`**: The `simd_bench` benchmark in `Cargo.toml` didn't declare `required-features = ["simd-x86-sse41"]`, so cargo wouldn't ensure the feature is enabled when building the benchmark.
36+
2. **Unconditional imports**: The benchmark's top-level imports tried to import SIMD functions unconditionally, but they're only compiled when the `target_feature = "sse4.1"` cfg is true.
37+
38+
## Impact
39+
**Medium** - Benchmarks cannot be run with SIMD features enabled, blocking performance testing of optimized implementations.
40+
41+
## Solution
42+
1. Added `required-features = ["simd-x86-sse41"]` to the `simd_bench` configuration in `Cargo.toml`
43+
2. Made SIMD function imports conditional using `#[cfg(all(target_arch = "x86_64", target_feature = "sse4.1"))]` guards in `simd_bench.rs`
44+
45+
## Files Modified
46+
- `crates/core/Cargo.toml` — Added required-features to simd_bench
47+
- `crates/core/benches/simd_bench.rs` — Made SIMD imports conditional
48+
49+
## Additional Context
50+
The benchmark code already had conditional compilation guards around SIMD function calls (lines 54, 73, 105), but the imports at the top were unconditional, causing the mismatch.

0 commit comments

Comments
 (0)