Maratyszcza / NNPACK

Acceleration package for neural networks on multi-core CPUs
BSD 2-Clause "Simplified" License
1.68k stars 316 forks source link

NNPack+MXNet Build Fails on Raspberry Pi 3 #135

Closed nxbyte closed 6 years ago

nxbyte commented 6 years ago

Hello! I am attempting to install NNPack on my Raspberry Pi so I can accelerate my machine learning applications with MXNet 1.0. For this installation, I installed a clean version of the latest Raspbian OS (Stretch with Desktop, Kernel 4.9).

However, when I try to build NNPack together with MXNet it fails and I receive this error.

/home/pi/NNPACK/lib//libnnpack.a(init.c.o): In function `init_hwinfo':
/home/pi/NNPACK/src/init.c:426: undefined reference to `cpuinfo_isa'
/home/pi/NNPACK/lib//libnnpack.a(init.c.o): In function `nnp_initialize':
/home/pi/NNPACK/src/init.c:574: undefined reference to `cpuinfo_initialize'
/home/pi/NNPACK/lib//libnnpack.a(init.c.o): In function `nnp_deinitialize':
/home/pi/NNPACK/src/init.c:584: undefined reference to `cpuinfo_deinitialize'
collect2: error: ld returned 1 exit status
Makefile:421: recipe for target 'bin/im2rec' failed
make: *** [bin/im2rec] Error 1

After trying the instructions in the READMEs in this repository, I looked at other instructions found here and here. However, all have led to the same error.

Am I doing something wrong, or does NNPack only support a certain build of MXNet?

Thanks!

Maratyszcza commented 6 years ago

NNPACK's migrated to CMake as the primary build system, and MXNet's adaptation to this change it still work-in-progress, see apache/incubator-mxnet#9860 and cc @dabraude and @tqchen.

The error you see arises from not linking cpuinfo library, used in NNPACK to detect ISA features and cache sizes.

Maratyszcza commented 6 years ago

@nextseto Alternatively, you may try Caffe2, which integrates the latest NNPACK.

nxbyte commented 6 years ago

@Maratyszcza Hi, thank you for the explanation.

Until the MXNet team merges the NNPack integration, what previous versions of NNPack and MXNet would still work together?

Maratyszcza commented 6 years ago

Probably, but if you want a version that doesn't depend on cpuinfo, you'd have to go to a very old NNPACK revision. f824d521126fea15d01cb1da5cb9dab94602b525 is the last that didn't depend on cpuinfo

dabraude commented 6 years ago

It wouldn't work even with an older version of nnpack as there was a rewrite of the operators, I haven't had a lot of time lately to work on it but hopefully next week I can.

nxbyte commented 6 years ago

Thanks @dabraude! As a stopgap solution, MXNet 0.11 and NNPack 3627062 does still build.

juliensimon commented 6 years ago

Hello @nextseto, I'm the author of the two posts you mentioned ;)

I ran into the same issue, this is how you can built MXNet 1.1.0 with the latest NNPACK and cpuinfo libs. Using this build, I was able to successfully predict images with a pre-trained version of Inception v3.

1) Build NNPACK as explained

2) Build cpuinfo in a similar fashion git clone https://github.com/Maratyszcza/cpuinfo.git cd cpuinfo configure cpuinfo: confu setup && python ./configure.py add -fPIC to cflags and cxxflags in build.ninja build: ninja

3) Add these to the MXNet makefile (with your own directories, of course): NNPACK = /home/pi/dev/NNPACK CPUINFO = /home/pi/dev/cpuinfo ADD_LDFLAGS = -L$(NNPACK)/lib/ -lnnpack -lpthreadpool -L$(CPUINFO)/lib/ -lcpuinfo ADD_CFLAGS = -I$(NNPACK)/include/ -I$(NNPACK)/deps/pthreadpool/include/

4) Build and install MXNet.

I hope this helps... and I guess I need an updated version of my post!

Cheers to @Maratyszcza for building such great tools.

nxbyte commented 6 years ago

Thanks soooooo much! @juliensimon I can confirm that it builds successfully. (with a few tweaks) When building with MXNet and NNPack: we had to increase our swap size to 4+ GB because we kept running out of memory when we compiled.

However, like @dabraude mentioned, since the operators were re-written everything causes Segmentation Faults...

So, from a practical stand point, NNPack + MXNet 1.1.0 isn't a viable solution.