ermig1979 / Simd

C++ image processing and machine learning library with using of SIMD: SSE, AVX, AVX-512, AMX for x86/x64, NEON for ARM.
http://ermig1979.github.io/Simd
MIT License
2.06k stars 413 forks source link

test app crashes - Illegal Instruction (version 4.6.89) #125

Closed us-er-name closed 4 years ago

us-er-name commented 4 years ago

I searched today for motion detection software and found this site. I downloaded simd.4.6.89, found the vs2019 directory and opened Simd.sln I let msvc update it to the sdk version I am using: MSVC Version 16.5.5 Platform Toolset: Visual Studio 2019 (v142)

My machine: Windows 10 Home, Version 1903 (64 bit OS) Intel I7-2600K, 16 Gig RAM

I am assuming this is the correct way to build everything. This project built clean (very pleasantly surprised) with no errors or warnings. (Nice job!)

I ran the test app (debug) and it crashed:

in SimdDetection.h line 340: sum += leaves[subset[c >> 5] & (1 << (c & 31)) ? leafOffset : leafOffset + 1]; Unhandled exception at 0x0883639E in Test.exe: 0xC000001D: Illegal Instruction.

The console window's last few lines were: ..... [17152] INFO: DetectionHaarDetect32fiAutoTest is finished successfully.

[17152] INFO: DetectionLbpDetect32fpAutoTest is started : [17152] INFO: Test Simd::Base::DetectionLbpDetect32fp & SimdDetectionLbpDetect32fp for size [128,96].

Additional info (if it helps): I actually googled and found the sourceforge site first. It looked active, with 38 downloads this week. So I downloaded it. Took me a while to update it (simd.4.2.74.zip) but I got it built and ran the tests - those tests were successful. It was only when digging around for documentation I found the link to this github site. Unfortunately I deleted it when I found out I was working with an old version, so I do not know if the test that crashed was also in the old version - and passed running that old version.

With my limited experience in with this, I would figure an illegal instruction on a line of code like that... well, it makes me think of memory corruption. With such complicated code (and being a newbie to image processing) I wouldn't know where to begin to debug this. Any ideas?

PS: You should place a note about moving to github on the sourceforge summary page instead of the support page!

ermig1979 commented 4 years ago

Hello. I think that main reason of the crash is a fact that your CPU is not supports AVX2 extension. Of course Simd must not have crash. But I can't reproduce this error because I don't have access to CPU without AVX2. Nevertheless you can fix locally the crash: you have to uncomment macro //#define SIMD_AVX2_DISABLE in file SimdConfig.h. I hope that this helps you.

ermig1979 commented 4 years ago

P.S. I want to note that Simd::Detection use outdated algorithms. The modern algorithm based on neural network is more accurate and more fast. There is my another project which implements it: https://github.com/ermig1979/Synet

us-er-name commented 4 years ago

Unfortunately that does not work. This causes references to Avx2 which is now undefined.

I uncommented that line in SimdConfig.h and that results in lots of compile errors.

Example: SimdMath.h uses references to Avx2 SIMD_INLINE m512i UnpackHalfU8(m256i a, __m256i b = Avx2::K_ZERO)

Example: SimdSynetConvolution32f.h: class SynetConvolution32fGemmNN : public Avx2::SynetConvolution32fGemmNN

SimdResizer.h has similar issue I aborted the compile. Many files include the SimdMath.h so the most errors listed were duplicates.

Thanks for your time.

ermig1979 commented 4 years ago

Thank you for bug report. Compiler error when defined SIMD_AVX2_DISABLE is fixed. Could you update and try again?

us-er-name commented 4 years ago

I deleted the old code i had, downloaded from git and recompiled:

1>------ Build started: Project: Ssse3, Configuration: Debug Win32 ------ 1>SimdSsse3BgrToBgra.cpp 1>D:\data\c\simd\src\Simd\SimdSsse3BgrToBgra.cpp(84,17): error C2065: 'bgrStride': undeclared identifier 1>D:\data\c\simd\src\Simd\SimdSsse3BgrToBgra.cpp(105): message : see reference to function template instantiation 'void Simd::Ssse3::RgbToBgra(const uint8_t ,size_t,size_t,size_t,uint8_t ,size_t,uint8_t)' being compiled 1>SimdSsse3BgrToGray.cpp 1>SimdSsse3Reorder.cpp 1>SimdSsse3YuvToBgr.cpp 1>Generating Code... 1>Done building project "Ssse3.vcxproj" -- FAILED. 2>------ Build started: Project: Simd, Configuration: Debug Win32 ------ 2>Extract project version: 2>Current version: 4.6.89 2>Last version: 4.6.89 2>Skip updating of file ""D:\data\c\simd\prj\vs2019...."\src\Simd\SimdVersion.h" because there are not any changes. 2>LINK : fatal error LNK1104: cannot open file 'D:\data\c\simd\bin\v142\Win32\Debug\Ssse3.lib' 2>Done building project "Simd.vcxproj" -- FAILED. 3>------ Build started: Project: Test, Configuration: Debug Win32 ------ 3>LINK : fatal error LNK1104: cannot open file 'D:\data\c\simd\bin\v142\Win32\Debug\Ssse3.lib' 3>Done building project "Test.vcxproj" -- FAILED. ========== Build: 0 succeeded, 3 failed, 15 up-to-date, 0 skipped ==========

ermig1979 commented 4 years ago

I'm sorry. I checked build only in Release mode. The bug has been fixed.

us-er-name commented 4 years ago

Thanks for all of your efforts. It compiles now. Naturally I have to define SIMD_AVX2_DISABLE (for my machine) as you have mentioned.

I ran the test app and it reports some errors and halts. I do not know if this is from disabling avx2 or it is something not related and is simply code you are working on.

I will paste it here just in case it is useful to you. I realise you don't have access to a non-avx2 machine. If this is not related to the cpu type, I can close this thread topic off or I can continue to help. Please let me know what you prefer.

Console output:

[22164] INFO: SynetConvolution8iForwardAutoTest is started : [22164] INFO: Test Simd::Base::SynetConvolution8iInit[1x3x1000x1000-32x1x1-1-0-1-1-o] & SimdSynetConvolution8iInit[1x3x1000x1000-32x1x1-1-0-1-1-o]]. [22164] ERROR: Fail comparison: Error at [0, 13, 778, 28] : 171 != 172; (difference = 1)! Error at [0, 33, 659, 28] : 171 != 172; (difference = 1)! Error at [0, 54, 291, 1] : 33 != 34; (difference = 1)! Error at [0, 77, 840, 1] : 33 != 34; (difference = 1)! Error at [0, 112, 930, 28] : 171 != 172; (difference = 1)! Error at [0, 123, 416, 1] : 33 != 34; (difference = 1)! Error at [0, 140, 953, 1] : 33 != 34; (difference = 1)! Error at [0, 142, 700, 1] : 33 != 34; (difference = 1)! Error at [0, 159, 948, 1] : 33 != 34; (difference = 1)! Error at [0, 192, 126, 1] : 33 != 34; (difference = 1)! Error at [0, 214, 998, 1] : 33 != 34; (difference = 1)! Error at [0, 256, 393, 1] : 33 != 34; (difference = 1)! Error at [0, 290, 354, 1] : 33 != 34; (difference = 1)! Error at [0, 294, 871, 1] : 33 != 34; (difference = 1)! Error at [0, 297, 759, 1] : 33 != 34; (difference = 1)! Error at [0, 332, 194, 28] : 171 != 172; (difference = 1)! Error at [0, 361, 606, 1] : 33 != 34; (difference = 1)! Error at [0, 378, 392, 1] : 33 != 34; (difference = 1)! Error at [0, 387, 697, 28] : 171 != 172; (difference = 1)! Error at [0, 410, 10, 1] : 33 != 34; (difference = 1)! Error at [0, 414, 527, 1] : 33 != 34; (difference = 1)! Error at [0, 432, 902, 1] : 33 != 34; (difference = 1)! Error at [0, 447, 220, 1] : 33 != 34; (difference = 1)! Error at [0, 448, 214, 28] : 171 != 172; (difference = 1)! Error at [0, 463, 845, 28] : 171 != 172; (difference = 1)! Error at [0, 477, 27, 1] : 33 != 34; (difference = 1)! Error at [0, 481, 362, 1] : 33 != 34; (difference = 1)! Error at [0, 508, 183, 1] : 33 != 34; (difference = 1)! Error at [0, 525, 80, 28] : 171 != 172; (difference = 1)! Error at [0, 548, 401, 1] : 33 != 34; (difference = 1)! Error at [0, 576, 217, 1] : 33 != 34; (difference = 1)! Error at [0, 612, 335, 1] : 33 != 34; (difference = 1)! Error at [0, 628, 290, 1] : 33 != 34; (difference = 1)! Error at [0, 632, 807, 1] : 33 != 34; (difference = 1)! Error at [0, 675, 505, 1] : 33 != 34; (difference = 1)! Error at [0, 681, 664, 1] : 33 != 34; (difference = 1)! Error at [0, 689, 603, 28] : 171 != 172; (difference = 1)! Error at [0, 701, 142, 1] : 33 != 34; (difference = 1)! Error at [0, 711, 625, 1] : 33 != 34; (difference = 1)! Error at [0, 727, 647, 1] : 33 != 34; (difference = 1)! Error at [0, 759, 580, 1] : 33 != 34; (difference = 1)! Error at [0, 764, 97, 1] : 33 != 34; (difference = 1)! Error at [0, 775, 299, 1] : 33 != 34; (difference = 1)! Error at [0, 775, 768, 1] : 33 != 34; (difference = 1)! Error at [0, 805, 98, 1] : 33 != 34; (difference = 1)! Error at [0, 815, 396, 1] : 33 != 34; (difference = 1)! Error at [0, 868, 238, 1] : 33 != 34; (difference = 1)! Error at [0, 885, 363, 1] : 33 != 34; (difference = 1)! Error at [0, 910, 690, 1] : 33 != 34; (difference = 1)! Error at [0, 925, 658, 1] : 33 != 34; (difference = 1)! Error at [0, 932, 173, 1] : 33 != 34; (difference = 1)! Error at [0, 941, 372, 1] : 33 != 34; (difference = 1)! Error at [0, 958, 502, 1] : 33 != 34; (difference = 1)! Error at [0, 982, 23, 1] : 33 != 34; (difference = 1)! Error at [0, 984, 300, 1] : 33 != 34; (difference = 1)!

[22164] INFO: SynetConvolution8iForwardAutoTest is finished with errors!

[22164] ERROR: ERROR! TEST EXECUTION IS TERMINATED !

ermig1979 commented 4 years ago

I ran this test on my CPU. And the bug is not reproduced. I think this bug is specific for your CPU (without support of AVX2 and FMA). Later I will try to fix it when get access to corresponding machine.

P.S. The error is caused by rounding error after 8-bit integer convolution (eg 45.499999 and 45.500000 are very close but give significant difference after rounding). You may exclude specific test with using options -fe=SynetConvolution8i .

us-er-name commented 4 years ago

As the illegal instruction error has been fixed, I will close this thread. The rounding is obviously a different issue.

Thank you for all your hard work. I am impressed with your efforts.