ermig1979 / Synet

A small framework to infer neural network
MIT License
140 stars 26 forks source link

Infinite loop in SynetConvolution32fNhwcDirect::OldReorderWeight() #17

Closed edward9112 closed 3 years ago

edward9112 commented 3 years ago

When I try to load any model on Intel Celeron J4125 (x64) the function SynetConvolution32fNhwcDirect::OldReorderWeight() hangs on an infinite loop (looks like a.macroD parameter always equals to 0).

ermig1979 commented 3 years ago

Oh, the processor does not have cache L3. Thank you for bug report!

ermig1979 commented 3 years ago

It seems that I fixed the problem. Can you verify this (I can't get access to such type of CPU)?

edward9112 commented 3 years ago

Thanks! Now there is a different error:


Unhandled exception 0xC000001D: Illegal Instruction.

Simd.dll!Simd::Runtime<Simd::GemmFunc,Simd::GemmArgs>::Candidate::Candidate(const Simd::GemmFunc & f) Line 112
    at \3rd\Simd\src\Simd\SimdRuntime.h(112)

originated from

Simd.dll!Simd::Base::SynetConvolution32fWinograd::SynetConvolution32fWinograd(const Simd::ConvParam32f & p) Line 718
    at \3rd\Simd\src\Simd\SimdBaseSynetConvolution32f.cpp(718)
ermig1979 commented 3 years ago

I tried to fixed the second bug. Can you check it?

edward9112 commented 3 years ago

That part worked, but there is another error now:


0xC000001D: Illegal Instruction
Simd.dll!Simd::GemmNNcb<float,unsigned __int64>::GemmNNcb<float,unsigned __int64>(...) Line 304
    at C:\Users\pacha\Desktop\Upload\syn mas\3rd\Simd\src\Simd\SimdGemm.h(304)

originated from


Simd.dll!Simd::Sse::CreateGemm32fNNcb(unsigned __int64 M, unsigned __int64 N, unsigned __int64 K, Simd::GemmKernelType type, bool compatibility) Line 858
    at \3rd\Simd\src\Simd\SimdSse1Gemm32f.cpp(858)
ermig1979 commented 3 years ago

I fixed the last one bug. I've never tested Simd and Synet on such hardware, so there are too many errors.

edward9112 commented 3 years ago

No problem! I am sure we can make it work together. Here are the new ones:

0xC000001D: Illegal Instruction

Simd.dll!sqrt<unsigned __int64,0>(unsigned __int64 _Left) Line 620
    at C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\include\cmath(620)

originated from

Simd.dll!Simd::GemmNNcb<float,4,unsigned __int64>::GemmNNcb<float,4,unsigned __int64>() Line 305
    at \3rd\Simd\src\Simd\SimdGemm.h(305)
ermig1979 commented 3 years ago

Can you go to disassembly and show me this 'illegal instruction'?

edward9112 commented 3 years ago

Here you go https://prnt.sc/vm7myp

ermig1979 commented 3 years ago

And could you show me 'call stack' please.

edward9112 commented 3 years ago

https://prnt.sc/vm7y74

ermig1979 commented 3 years ago

Can you change line 305 in file SimdGemm.h:

        L2 = Simd::RestrictRange(size_t(::sqrt(L1 * L3)), L2/4, L2);

to

        L2 = Simd::RestrictRange(size_t(::sqrt(double(L1 * L3))), L2/4, L2);

and verify existance of the error?

edward9112 commented 3 years ago

It worked!

Now it fails on Simd::Resize (Illegal Instruction) https://prnt.sc/vmack2

Simd.dll!Simd::Max<float>(float a, float b) Line 46
    at \3rd\Simd\src\Simd\SimdMath.h(46)
Simd.dll!Simd::Base::ResizerByteArea::ResizerByteArea(const Simd::ResParam & param) Line 135
    at \3rd\Simd\src\Simd\SimdBaseResizer.cpp(135)
ermig1979 commented 3 years ago

You can delete the 135 line in file SimdBaseResizer.cpp - it's not needed.

And if you build solution in Debug mode can you also check in Release?

edward9112 commented 3 years ago

Still fails on Simd::Resize

https://prnt.sc/vmpkqx

Simd.dll!floor(float _Xx) Line 102
    at C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\include\cmath(102)

Simd.dll!Simd::Base::ResizerByteArea::EstimateParams(unsigned __int64 srcSize, unsigned __int64 dstSize, unsigned __int64 range, int * alpha, int * index) Line 153
    at \3rd\Simd\src\Simd\SimdBaseResizer.cpp(153)
ermig1979 commented 3 years ago

Is this error is reproduced in Release mode?

edward9112 commented 3 years ago

Just checked, it does work properly in release.

ermig1979 commented 3 years ago

OK. The past error, current and following errors are caused by Visual Studio linker error in debug mode. It links body of inline function which compiled with using of AVX and outer code which compiled without of AVX. Therу is no simple way to solve this problem in common case. But you can build Simd without of AVX and linker will not entangle implementation of inline functions. To do this you have to just uncomment macro SIMD_AVX_DISABLE in file SimdConfig.h.

edward9112 commented 3 years ago

Got it, I don't really need the Debug mode to be honest. Thank you so much for assistance!

I will be reporting if I encounter something else.

edward9112 commented 3 years ago

The only negative I observe is performance: 86ms with 256x256 model. On my Intel i7 it shows 19ms.

ermig1979 commented 3 years ago

It seems to be truth. AVX gives boost x2. Also FMA gives boost x2.

edward9112 commented 3 years ago

So basically lack of AVX and FMA makes the processor useless for real-time inference… Is there a method in Simd library that returns AVX and FMA compatibility?

ermig1979 commented 3 years ago

See SimdCpuInfo: http://ermig1979.github.io/Simd/help/group__info.html#ga9bfd6c53c168b66dbf73b966bcfb2e37

FMA <-> AVX2

edward9112 commented 3 years ago

Ok, thank you!