arduano / simdeez

easy simd
MIT License
331 stars 25 forks source link

Consistency test fails #10

Open jdeeny opened 5 years ago

jdeeny commented 5 years ago

When I run the test suite on an AMD Phenom 9850 (tested inside a virtual machine only), the consistency test fails:

cargo test -- --test-threads=1 --nocapture
    Finished dev [unoptimized + debuginfo] target(s) in 0.32s
     Running deps/simdeez-5e719a562e36306e

running 10 tests
test libm::math::atan2::sanity_check ... ok
test libm::math::atan::tests::infinity ... ok
test libm::math::atan::tests::minus_infinity ... ok
test libm::math::atan::tests::nan ... ok
test libm::math::atan::tests::sanity_check ... ok
test libm::math::atan::tests::zero ... ok
test libm::math::ceil::tests::sanity_check ... ok
test libm::math::expm1::tests::sanity_check ... ok
test libm::math::trunc::tests::sanity_check ... ok
test libm::math::truncf::tests::sanity_check ... ok

test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running deps/tests-9fbaba33bf838c7c

running 2 tests
test tests::consistency ... error: process didn't exit successfully: `/home/jdeeny/github/simdeez/target/debug/deps/tests-9fbaba33bf838c7c --test-threads=1 --nocapture` (signal: 4, SIGILL: illegal instruction)

If I run in gdb I get this information about the crash:

running 2 tests
test tests::consistency ... 
Program received signal SIGILL, Illegal instruction.
0x00005555555634d4 in core::core_arch::x86::avx::_mm256_setr_epi32 (e0=3, e1=3, e2=3, e3=3, e4=3, e5=3, 
    e6=3, e7=3)
    at /rustc/e68bf8ae15ee6c052d0bcc9252386c5c5ee86de2/src/libcore/../stdsimd/crates/core_arch/src/x86/avx.rs:2653

I am using code from the github repo, commit 604d9e55fb036c6108ea0624c9c887bc28dbb1b6

jackmott commented 5 years ago

So I think what is happening is that CPU doesn't have AVX2 instructions, and the way the tests are structured right now, assumes they are being run on a cpu that supports all of the instruction sets. Definitely worth fixing. I welcome PRs to address it if you want to have a go, otherwise I'll get to it probably in a few days.

jdeeny commented 5 years ago

I was looking at this, thinking I could add a fn is_supported() -> bool to the Simd trait and put is_x86_feature_detected!("xxx") in each one. Then make a consistency test that tries every type that is supported against every other type.

With nostd, I can't use that macro. Should I always send true? false? Should the return be something other than a bool.

Or maybe I've headed off in the wrong direction. Let me know what you think.

lovasoa commented 4 years ago

The tests are failing for me too. Anything new ?

test output

``` cargo test warning: unused import: `simdeez::*` --> tests/unit_tests.rs:10:9 | 10 | use simdeez::*; | ^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused import: `std::f32::*` --> tests/unit_tests.rs:11:9 | 11 | use std::f32::*; | ^^^^^^^^^^^ warning: unused import: `std::f64::*` --> tests/unit_tests.rs:12:9 | 12 | use std::f64::*; | ^^^^^^^^^^^ warning: unused variable: `ints` --> tests/unit_tests.rs:137:13 | 137 | let ints = &vec![-1, 1, 0, 10, -10, i32::max_value(), i32::min_value()]; | ^^^^ help: consider prefixing with an underscore: `_ints` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `floats` --> tests/unit_tests.rs:138:13 | 138 | let floats = &vec![ | ^^^^^^ help: consider prefixing with an underscore: `_floats` warning: unnecessary `unsafe` block --> tests/unit_tests.rs:160:9 | 160 | unsafe { | ^^^^^^ unnecessary `unsafe` block | = note: `#[warn(unused_unsafe)]` on by default warning: function is never used: `setlanetest_avx` --> tests/unit_tests.rs:473:15 | 473 | unsafe fn setlanetest_avx() -> f32 { | ^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: unused import: `simdeez::*` --> tests/quickcheck.rs:15:9 | 15 | use simdeez::*; | ^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused import: `F32Ext` --> src/scalar/scalar.rs:4:12 | 4 | use libm::{F32Ext, F64Ext}; | ^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused import: `F64Ext` --> src/scalar/scalar.rs:4:20 | 4 | use libm::{F32Ext, F64Ext}; | ^^^^^^ warning: unused import: `simdeez::*` --> tests/tests.rs:10:9 | 10 | use simdeez::*; | ^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default Finished test [unoptimized + debuginfo] target(s) in 0.06s Running target/debug/deps/simdeez-9af787cb401b2478 running 10 tests test libm::math::atan2::sanity_check ... ok test libm::math::atan::tests::infinity ... ok test libm::math::atan::tests::minus_infinity ... ok test libm::math::atan::tests::sanity_check ... ok test libm::math::atan::tests::zero ... ok test libm::math::atan::tests::nan ... ok test libm::math::ceil::tests::sanity_check ... ok test libm::math::expm1::tests::sanity_check ... ok test libm::math::trunc::tests::sanity_check ... ok test libm::math::truncf::tests::sanity_check ... ok test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out Running target/debug/deps/quickcheck-19222ad07a862ed2 running 74 tests test tests::test_abs_f32 ... ok test tests::test_abs_f64 ... ok test tests::test_add_i32 ... ok test tests::test_bitand_i32 ... ok test tests::test_andnot_i32 ... ok test tests::test_bitand_i64 ... ok test tests::test_add_f64 ... ok test tests::test_add_i64 ... ok test tests::test_andnot_f32 ... ok test tests::test_andnot_i64 ... ok test tests::test_andnot_f64 ... ok test tests::test_ceil_f64 ... FAILED test tests::test_add_f32 ... ok test tests::test_bitor_i32 ... ok test tests::test_bitxor_i32 ... ok test tests::test_ceil_f32 ... ok test tests::test_bitor_i64 ... ok test tests::test_cmpeq_i32 ... ok test tests::test_bitxor_i64 ... ok test tests::test_cmpeq_f64 ... ok test tests::test_cmpeq_f32 ... ok test tests::test_cmpeq_i64 ... ok test tests::test_cmpge_f32 ... ok test tests::test_cmpge_i32 ... ok test tests::test_cmpge_f64 ... ok test tests::test_cmpgt_f32 ... ok test tests::test_cmpge_i64 ... ok test tests::test_cmpgt_f64 ... ok test tests::test_cmple_f32 ... ok test tests::test_cmpgt_i32 ... ok test tests::test_cmple_f64 ... ok test tests::test_cmple_i32 ... ok test tests::test_cmpgt_i64 ... ok test tests::test_cmple_i64 ... ok test tests::test_cmplt_f32 ... ok test tests::test_cmplt_f64 ... ok test tests::test_cmplt_i32 ... ok test tests::test_cmpneq_f32 ... ok test tests::test_cmpneq_i32 ... ok test tests::test_cmplt_i64 ... ok test tests::test_cmpneq_f64 ... ok test tests::test_div_f32 ... ok test tests::test_fast_ceil_f32 ... ok test tests::test_floor_f64 ... FAILED test tests::test_fast_floor_f32 ... ok test tests::test_cmpneq_i64 ... ok test tests::test_div_f64 ... ok test tests::test_fmadd_f32 ... FAILED test tests::test_fmsub_f32 ... FAILED test tests::test_fast_round_f32 ... ok test tests::test_fnmadd_f32 ... FAILED test tests::test_floor_f32 ... ok test tests::test_fnmsub_f32 ... FAILED test tests::test_fmadd_f64 ... ok test tests::test_fmsub_f64 ... ok test tests::test_max_f32 ... ok test tests::test_fnmadd_f64 ... ok test tests::test_max_f64 ... ok test tests::test_round_f64 ... FAILED test tests::test_fnmsub_f64 ... ok test tests::test_max_i32 ... ok test tests::test_min_f64 ... ok test tests::test_min_f32 ... ok test tests::test_min_i32 ... ok test tests::test_mul_f32 ... ok test tests::test_mul_f64 ... ok test tests::test_mul_i32 ... ok test tests::test_round_f32 ... ok test tests::test_sub_f32 ... ok test tests::test_sqrt_f32 ... ok test tests::test_sub_i32 ... ok test tests::test_sub_f64 ... ok test tests::test_sub_i64 ... ok test tests::test_sqrt_f64 ... ok failures: ---- tests::test_ceil_f64 stdout ---- Results didn't match (sse2). Reference: 89.0; Simdeez: F64x2(__m128d(88.09108394160965, 88.09108394160965)) thread 'tests::test_ceil_f64' panicked at '[quickcheck] TEST FAILED. Arguments: (88.09108394160964)', <::std::macros::panic macros>:2:4 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ---- tests::test_floor_f64 stdout ---- Results didn't match (sse2). Reference: 4.0; Simdeez: F64x2(__m128d(4.684617061337717, 4.684617061337717)) thread 'tests::test_floor_f64' panicked at '[quickcheck] TEST FAILED. Arguments: (4.684617061337718)', <::std::macros::panic macros>:2:4 ---- tests::test_fmadd_f32 stdout ---- Results didn't match (avx2). Reference: 2370.817; Simdeez: F32x8(__m256(2370.8167, 2370.8167, 2370.8167, 2370.8167, 2370.8167, 2370.8167, 2370.8167, 2370.8167)) Results didn't match (avx2). Reference: 2370.817; Simdeez: F32x8(__m256(2370.8167, 2370.8167, 2370.8167, 2370.8167, 2370.8167, 2370.8167, 2370.8167, 2370.8167)) thread 'tests::test_fmadd_f32' panicked at '[quickcheck] TEST FAILED. Arguments: ((52.662827, 44.17987, 0.0))', <::std::macros::panic macros>:2:4 ---- tests::test_fmsub_f32 stdout ---- Results didn't match (avx2). Reference: 4419.2427; Simdeez: F32x8(__m256(4419.243, 4419.243, 4419.243, 4419.243, 4419.243, 4419.243, 4419.243, 4419.243)) Results didn't match (avx2). Reference: -4145.1357; Simdeez: F32x8(__m256(-4145.1353, -4145.1353, -4145.1353, -4145.1353, -4145.1353, -4145.1353, -4145.1353, -4145.1353)) Results didn't match (avx2). Reference: -2024.3687; Simdeez: F32x8(__m256(-2024.3684, -2024.3684, -2024.3684, -2024.3684, -2024.3684, -2024.3684, -2024.3684, -2024.3684)) Results didn't match (avx2). Reference: -963.98505; Simdeez: F32x8(__m256(-963.985, -963.985, -963.985, -963.985, -963.985, -963.985, -963.985, -963.985)) Results didn't match (avx2). Reference: -963.98505; Simdeez: F32x8(__m256(-963.985, -963.985, -963.985, -963.985, -963.985, -963.985, -963.985, -963.985)) thread 'tests::test_fmsub_f32' panicked at '[quickcheck] TEST FAILED. Arguments: ((11.0, -96.3985, 0.0))', <::std::macros::panic macros>:2:4 ---- tests::test_fnmadd_f32 stdout ---- Results didn't match (avx2). Reference: 4415.753; Simdeez: F32x8(__m256(4415.7534, 4415.7534, 4415.7534, 4415.7534, 4415.7534, 4415.7534, 4415.7534, 4415.7534)) Results didn't match (avx2). Reference: 4122.6357; Simdeez: F32x8(__m256(4122.636, 4122.636, 4122.636, 4122.636, 4122.636, 4122.636, 4122.636, 4122.636)) Results didn't match (avx2). Reference: -3987.4675; Simdeez: F32x8(__m256(-3987.4678, -3987.4678, -3987.4678, -3987.4678, -3987.4678, -3987.4678, -3987.4678, -3987.4678)) Results didn't match (avx2). Reference: -1959.9417; Simdeez: F32x8(__m256(-1959.9418, -1959.9418, -1959.9418, -1959.9418, -1959.9418, -1959.9418, -1959.9418, -1959.9418)) Results didn't match (avx2). Reference: -946.1787; Simdeez: F32x8(__m256(-946.1788, -946.1788, -946.1788, -946.1788, -946.1788, -946.1788, -946.1788, -946.1788)) Results didn't match (avx2). Reference: -946.1787; Simdeez: F32x8(__m256(-946.1788, -946.1788, -946.1788, -946.1788, -946.1788, -946.1788, -946.1788, -946.1788)) thread 'tests::test_fnmadd_f32' panicked at '[quickcheck] TEST FAILED. Arguments: ((15.0, 67.5842, 0.0))', <::std::macros::panic macros>:2:4 ---- tests::test_fnmsub_f32 stdout ---- Results didn't match (avx2). Reference: 1564.4261; Simdeez: F32x8(__m256(1564.426, 1564.426, 1564.426, 1564.426, 1564.426, 1564.426, 1564.426, 1564.426)) Results didn't match (avx2). Reference: 1388.5083; Simdeez: F32x8(__m256(1388.5082, 1388.5082, 1388.5082, 1388.5082, 1388.5082, 1388.5082, 1388.5082, 1388.5082)) Results didn't match (avx2). Reference: 1055.2664; Simdeez: F32x8(__m256(1055.2662, 1055.2662, 1055.2662, 1055.2662, 1055.2662, 1055.2662, 1055.2662, 1055.2662)) Results didn't match (avx2). Reference: 999.7259; Simdeez: F32x8(__m256(999.72595, 999.72595, 999.72595, 999.72595, 999.72595, 999.72595, 999.72595, 999.72595)) Results didn't match (avx2). Reference: -1110.8065; Simdeez: F32x8(__m256(-1110.8066, -1110.8066, -1110.8066, -1110.8066, -1110.8066, -1110.8066, -1110.8066, -1110.8066)) Results didn't match (avx2). Reference: -610.94366; Simdeez: F32x8(__m256(-610.9436, -610.9436, -610.9436, -610.9436, -610.9436, -610.9436, -610.9436, -610.9436)) Results didn't match (avx2). Reference: -333.242; Simdeez: F32x8(__m256(-333.24197, -333.24197, -333.24197, -333.24197, -333.24197, -333.24197, -333.24197, -333.24197)) Results didn't match (avx2). Reference: -333.242; Simdeez: F32x8(__m256(-333.24197, -333.24197, -333.24197, -333.24197, -333.24197, -333.24197, -333.24197, -333.24197)) thread 'tests::test_fnmsub_f32' panicked at '[quickcheck] TEST FAILED. Arguments: ((5.0, 55.54033, 0.0))', <::std::macros::panic macros>:2:4 ---- tests::test_round_f64 stdout ---- Results didn't match (sse2). Reference: -2.0; Simdeez: F64x2(__m128d(-1.9302866993726724, -1.9302866993726724)) thread 'tests::test_round_f64' panicked at '[quickcheck] TEST FAILED. Arguments: (-1.9302866993726724)', <::std::macros::panic macros>:2:4 failures: tests::test_ceil_f64 tests::test_floor_f64 tests::test_fmadd_f32 tests::test_fmsub_f32 tests::test_fnmadd_f32 tests::test_fnmsub_f32 tests::test_round_f64 test result: FAILED. 67 passed; 7 failed; 0 ignored; 0 measured; 0 filtered out error: test failed, to rerun pass '--test quickcheck' ```

cpu

``` machdep.cpu.brand_string: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz machdep.cpu.family: 6 machdep.cpu.model: 158 machdep.cpu.extmodel: 9 machdep.cpu.extfamily: 0 machdep.cpu.stepping: 10 machdep.cpu.feature_bits: 9221959987971750911 machdep.cpu.leaf7_feature_bits: 43804591 1073741824 machdep.cpu.leaf7_feature_bits_edx: 2617254912 machdep.cpu.extfeature_bits: 1241984796928 machdep.cpu.signature: 591594 machdep.cpu.brand: 0 machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTES64 MON DSCPL VMX EST TM2 SSSE3 FMA CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC MOVBE POPCNT AES PCID XSAVE OSXSAVE SEGLIM64 TSCTMR AVX1.0 RDRAND F16C machdep.cpu.leaf7_features: RDWRFSGS TSC_THREAD_OFFSET SGX BMI1 AVX2 SMEP BMI2 ERMS INVPCID FPU_CSDS MPX RDSEED ADX SMAP CLFSOPT IPT SGXLC MDCLEAR TSXFA IBRS STIBP L1DF SSBD ```
verpeteren commented 1 year ago

@jdeeny : can you check if this PR / branch solves your issue. If it does, can you do an approval?