ARM-software / armnn

Arm NN ML Software. The code here is a read-only mirror of https://review.mlplatform.org/admin/repos/ml/armnn
https://developer.arm.com/products/processors/machine-learning/arm-nn
MIT License
1.17k stars 308 forks source link

Errors when building Arm NN #573

Closed HungYangChang closed 2 years ago

HungYangChang commented 3 years ago

Hello,

I follow this link to build Arm NN with TensorFlow lite. I skip "Build the Google Protocol Buffers library" and "Generate the build dependencies for ONNX" part because I only use Tensorflow Lite. I was able to follow all the steps until "Build Arm NN" part

The only steps I add into or (differ from) the original setting: I add DFLATBUFFERS_LIBRARY option to solve "Flatbuffers library located at: FLATBUFFERS_LIBRARY-NOTFOUND" errors

cmake command I am using:

cmake .. -DARMCOMPUTE_ROOT=$BASEDIR/ComputeLibrary 
-DARMCOMPUTE_BUILD_DIR=$BASEDIR/ComputeLibrary/build 
-DSHARED_BOOT=ON -DBOOST_ROOT=$BASEDIR/boost -DBUILD_TF_LITE_PARSER=1 
-DTF_LITE_GENERATED_PATH=$BASEDIR/flatbuffers-1.12.0/build/tflite 
-DFLATBUFFERS_ROOT=$$BASEDIR/flatbuffers-1.12.0
**-DFLATBUFFERS_LIBRARY=$BASEDIR/flatbuffers-1.12.0/libflatbuffers.a** 
-DFLATC_DIR=$BASEDIR/flatbuffers-1.12.0/build 
-DARMCOMPUTENEON=1 -DARMNNREF=1

cmake result:

-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Flatbuffers headers are located at: /home/shunya/hungyang/armnn-dist/flatbuffers-1.12.0/include
-- Flatbuffers library located at: /home/shunya/hungyang/armnn-dist/flatbuffers-1.12.0/libflatbuffers.a
-- Tf Lite generated header found at: /home/shunya/hungyang/armnn-dist/flatbuffers-1.12.0/build/tflite
-- Looking for valgrind/memcheck.h
-- Looking for valgrind/memcheck.h - not found
-- Armnn Serializer support is disabled
-- PyArmNN wheel package is disabled
-- PyArmNN source package is disabled
-- Including backend common library into the build: /home/shunya/hungyang/armnn-dist/armnn/src/backends/aclCommon/common.cmake
-- Including backend common library into the build: /home/shunya/hungyang/armnn-dist/armnn/src/backends/backendsCommon/common.cmake
-- Including backend into the build: /home/shunya/hungyang/armnn-dist/armnn/src/backends/cl/backend.cmake
-- CL backend is disabled
-- Including backend into the build: /home/shunya/hungyang/armnn-dist/armnn/src/backends/neon/backend.cmake
-- Including backend into the build: /home/shunya/hungyang/armnn-dist/armnn/src/backends/reference/backend.cmake
-- Adding object library dependency to armnn: armnnAclCommon
-- Adding object library dependency to armnn: armnnBackendsCommon
-- Adding object library dependency to armnn: armnnClBackend
-- Adding object library dependency to armnn: armnnNeonBackend
-- Adding object library dependency to armnn: armnnNeonBackendWorkloads
-- Adding object library dependency to armnn: armnnRefBackend
-- Adding object library dependency to armnn: armnnRefBackendWorkloads
-- Adding object library dependency to UnitTests: armnnAclCommonUnitTests
-- Adding object library dependency to UnitTests: armnnBackendsCommonUnitTests
-- Adding object library dependency to UnitTests: armnnNeonBackendUnitTests
-- Adding object library dependency to UnitTests: armnnRefBackendUnitTests
-- CMAKE_CURRENT_LIST_DIR /home/shunya/hungyang/armnn-dist/armnn
-- CMAKE_CURRENT_BINARY_DIR /home/shunya/hungyang/armnn-dist/armnn/build
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    BOOST_ROOT
    SHARED_BOOT

-- Build files have been written to: /home/shunya/hungyang/armnn-dist/armnn/build

But it always shows errors when the progress at 49% I have tried flatbuffers-1.10.0 version but I still get the same errors at 49% when using "make" command. image

More info: the platform I am using is HiKey 970 image

Thanks for your help in advance :)

FrancisMurtagh-arm commented 3 years ago

Hi @HungYangChang,

You appear to be using the incorrect DTF_LITE_GENERATED_PATH, it should be pointing to a file called schema_generated.h not what you have /home/shunya/hungyang/armnn-dist/flatbuffers-1.12.0/build/tflite

This is generated using:

/usr/bin/flatc -c --gen-object-api --reflect-types --reflect-names -o path/we/output/to path/to/tensorflow/schema.fbs

In the link you provided there seems to be a typo in schema.fbs:

$ mkdir tflite
$ cd tflite
$ cp $BASEDIR/tensorflow/tensorflow/lite/schema/schema.fbs .
$ $BASEDIR/flatbuffers-1.12.0/build/flatc -c --gen-object-api --reflect-types --reflect-names schema.fbsS   # note extra S

I'll put a request in for the document to be updated for the typo

Thanks, Francis.

HungYangChang commented 3 years ago

Hello @FrancisMurtagh-arm

Thanks for your reply. I think I have followed the setting you set, but I still face a similar problem. I will try to build again and update here.

As for the typo, ​I have noticed the typo before and fix them. Also, Could you please add -DFLATBUFFERS_LIBRARY=$BASEDIR/flatbuffers-1.12.0/libflatbuffers.a into build page? I guess the DFLATBUFFERS_LIBRARY is missing there.

HungYangChang commented 3 years ago

Hello @FrancisMurtagh-arm

I tried to follow your sugeestion

$ mkdir tflite
$ cd tflite
$ cp $BASEDIR/tensorflow/tensorflow/lite/schema/schema.fbs .
$ $BASEDIR/flatbuffers-1.12.0/build/flatc -c --gen-object-api --reflect-types --reflect-names schema.fbs

And here is the tflite path:

shunya@hikey970:~/hungyang/armnn-dist/tflite$ ls
schema.fbs  schema_generated.h

And then I use the following command

cmake .. -DARMCOMPUTE_ROOT=$BASEDIR/ComputeLibrary 
-DARMCOMPUTE_BUILD_DIR=$BASEDIR/ComputeLibrary/build 
-DSHARED_BOOT=ON 
-DBOOST_ROOT=$BASEDIR/boost 
-DBUILD_TF_LITE_PARSER=1 
-DTF_LITE_GENERATED_PATH=/home/shunya/hungyang/armnn-dist/tflite 
-DFLATBUFFERS_ROOT=$BASEDIR/flatbuffers-1.12.0 
-DFLATBUFFERS_LIBRARY=$BASEDIR/flatbuffers-1.12.0/libflatbuffers.a
-DFLATC_DIR=$BASEDIR/flatbuffers-1.12.0/build 
-DARMCOMPUTENEON=1 
-DARMNNREF=1 
-DBUILD_TESTS=1

-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Flatbuffers headers are located at: /home/shunya/hungyang/armnn-dist/flatbuffers-1.12.0/include
-- Flatbuffers library located at: /home/shunya/hungyang/armnn-dist/flatbuffers-1.12.0/libflatbuffers.a
-- Tf Lite generated header found at: /home/shunya/hungyang/armnn-dist/tflite
-- Looking for valgrind/memcheck.h
-- Looking for valgrind/memcheck.h - not found
-- Armnn Serializer support is disabled
-- PyArmNN wheel package is disabled
-- PyArmNN source package is disabled
-- Including backend common library into the build: /home/shunya/hungyang/armnn-dist/armnn/src/backends/aclCommon/common.cmake
-- Including backend common library into the build: /home/shunya/hungyang/armnn-dist/armnn/src/backends/backendsCommon/common.cmake
-- Including backend into the build: /home/shunya/hungyang/armnn-dist/armnn/src/backends/cl/backend.cmake
-- CL backend is disabled
-- Including backend into the build: /home/shunya/hungyang/armnn-dist/armnn/src/backends/neon/backend.cmake
-- Including backend into the build: /home/shunya/hungyang/armnn-dist/armnn/src/backends/reference/backend.cmake
-- Adding object library dependency to armnn: armnnAclCommon
-- Adding object library dependency to armnn: armnnBackendsCommon
-- Adding object library dependency to armnn: armnnClBackend
-- Adding object library dependency to armnn: armnnNeonBackend
-- Adding object library dependency to armnn: armnnNeonBackendWorkloads
-- Adding object library dependency to armnn: armnnRefBackend
-- Adding object library dependency to armnn: armnnRefBackendWorkloads
-- Adding object library dependency to UnitTests: armnnAclCommonUnitTests
-- Adding object library dependency to UnitTests: armnnBackendsCommonUnitTests
-- Adding object library dependency to UnitTests: armnnNeonBackendUnitTests
-- Adding object library dependency to UnitTests: armnnRefBackendUnitTests
-- CMAKE_CURRENT_LIST_DIR /home/shunya/hungyang/armnn-dist/armnn
-- CMAKE_CURRENT_BINARY_DIR /home/shunya/hungyang/armnn-dist/armnn/build
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    BOOST_ROOT
    SHARED_BOOT

-- Build files have been written to: /home/shunya/hungyang/armnn-dist/armnn/build

But I still get the same error:

Scanning dependencies of target armnnTfLiteParser
[ 46%] Building CXX object src/armnnTfLiteParser/CMakeFiles/armnnTfLiteParser.dir/TfLiteParser.cpp.o
/home/shunya/hungyang/armnn-dist/armnn/src/armnnTfLiteParser/TfLiteParser.cpp: In function 'armnn::TensorInfo armnnTfLiteParser::{anonymous}::ToTensorInfo(armnnTfLiteParser::TfLiteParserImpl::TensorRawPtr, const std::vector<unsigned int>&, bool)':
/home/shunya/hungyang/armnn-dist/armnn/src/armnnTfLiteParser/TfLiteParser.cpp:429:48: error: 'const struct tflite::TensorT' has no member named 'shape_signature'
         size_t shapeSignatureSize = tensorPtr->shape_signature.size();
                                                ^~~~~~~~~~~~~~~
/home/shunya/hungyang/armnn-dist/armnn/src/armnnTfLiteParser/TfLiteParser.cpp:441:51: error: 'const struct tflite::TensorT' has no member named 'shape_signature'
                     unsigned int dim = tensorPtr->shape_signature[i] > -1 ?
                                                   ^~~~~~~~~~~~~~~
/home/shunya/hungyang/armnn-dist/armnn/src/armnnTfLiteParser/TfLiteParser.cpp:442:77: error: 'const struct tflite::TensorT' has no member named 'shape_signature'
                                        static_cast<unsigned int>(tensorPtr->shape_signature[i]) : 0;
                                                                             ^~~~~~~~~~~~~~~
/home/shunya/hungyang/armnn-dist/armnn/src/armnnTfLiteParser/TfLiteParser.cpp:447:83: error: 'const struct tflite::TensorT' has no member named 'shape_signature'
             std::unique_ptr<bool[]> dimMask = std::make_unique<bool[]>(tensorPtr->shape_signature.size());
                                                                                   ^~~~~~~~~~~~~~~
/home/shunya/hungyang/armnn-dist/armnn/src/armnnTfLiteParser/TfLiteParser.cpp:448:53: error: 'const struct tflite::TensorT' has no member named 'shape_signature'
             for (unsigned int i = 0; i < tensorPtr->shape_signature.size(); ++i)
                                                     ^~~~~~~~~~~~~~~
/home/shunya/hungyang/armnn-dist/armnn/src/armnnTfLiteParser/TfLiteParser.cpp:450:41: error: 'const struct tflite::TensorT' has no member named 'shape_signature'
                 dimMask[i] = tensorPtr->shape_signature[i] == -1 ? false : true;
                                         ^~~~~~~~~~~~~~~
src/armnnTfLiteParser/CMakeFiles/armnnTfLiteParser.dir/build.make:62: recipe for target 'src/armnnTfLiteParser/CMakeFiles/armnnTfLiteParser.dir/TfLiteParser.cpp.o' failed
make[2]: *** [src/armnnTfLiteParser/CMakeFiles/armnnTfLiteParser.dir/TfLiteParser.cpp.o] Error 1
CMakeFiles/Makefile2:391: recipe for target 'src/armnnTfLiteParser/CMakeFiles/armnnTfLiteParser.dir/all' failed
make[1]: *** [src/armnnTfLiteParser/CMakeFiles/armnnTfLiteParser.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

I also find out link (in Mandarin) have a similar issue. Thanks for the help in advacne.

payaljindal commented 3 years ago

I am also facing the same error. @HungYangChang if you found any solution, please put it here as well. Thanks in advance.

HungYangChang commented 3 years ago

@payaljindal I still cannot figure that out. But I will update here if I get any progress. I think ARM developers might reply on Tuesday since Monday is Labor day.

FrancisMurtagh-arm commented 3 years ago

Hi @HungYangChang & @payaljindal,

Could you post your schema_generated.h and confirm your Tensorflow version?

Thanks, Francis.

payaljindal commented 3 years ago

Hi @FrancisMurtagh-arm, I used a different version of Arm NN(21.05). Now, I am able to build successfully.

Thanks, Payal

HungYangChang commented 3 years ago

Hi, @FrancisMurtagh-arm I am using the latest version of both TensorFlow (2.4.3) and armNN (21.08). I will try to use ARM NN 21.05 as @payaljindal suggest and see what I get. And the attachment is schema_generated.h file schema_generated.h.zip

HungYangChang commented 3 years ago

Hi @FrancisMurtagh-arm, I used a different version of Arm NN(21.05). Now, I am able to build successfully.

Thanks, Payal

@payaljindal May I ask which version of ARM compute library are you using? Is it 21.08 or 21.05?

payaljindal commented 3 years ago

Hi @FrancisMurtagh-arm, I used a different version of Arm NN(21.05). Now, I am able to build successfully. Thanks, Payal

@payaljindal May I ask which version of ARM compute library are you using? Is it 21.08 or 21.05?

Hi @HungYangChang I used 21.05. I have written all the steps which I followed in this article. You can refer to this if you want.

Thanks Payal

HungYangChang commented 3 years ago

@payaljindal Thanks for the nice explaining. Also, I think shape_signature in tflite parser is somehow missing or not working correctly. Could @FrancisMurtagh-arm check that?

Thanks for your help in advance :)

FrancisMurtagh-arm commented 3 years ago

Hi, @FrancisMurtagh-arm I am using the latest version of both TensorFlow (2.4.3) and armNN (21.08). I will try to use ARM NN 21.05 as @payaljindal suggest and see what I get. And the attachment is schema_generated.h file schema_generated.h.zip

Hi @HungYangChang, we support TensorFlow version 2.3.1, as mentioned in our release notes, could you try with ArmNN 21.08 and Tensorflow 2.3.1?

HungYangChang commented 3 years ago

@FrancisMurtagh-arm

I will try ArmNN 21.08 and Tensorflow 2.3.1 and update here. But for now, I was also able to build armnn on ARM V21.05 My platform: HiKey 970 ldd (Debian GLIBC 2.31-13) 2.31

I basically follow this link shared by @payaljindal. But I skipped step 1 Android NDK and step 2 Build Google’s Protobuf library in the article because I will only use Tensorflow Lite. Note: The Tensorflow (and TensorFlow lite) version I am using also follow what @payaljindal suggests

cd $HOME/armnn-devenv/google/
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow/
git checkout 590d6eef7e91a6a7392c8ffffb7b58f2e0c8bc6b

This command is how I build flatbuffers:

wget -O flatbuffers-1.12.0.tar.gz https://github.com/google/flatbuffers/archive/v1.12.0.tar.gz
tar -xf flatbuffers-1.12.0.tar.gz
mkdir build
cd build
CXXFLAGS="-fPIC"  cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_FLATC=1  -DCMAKE_INSTALL_PREFIX:PATH=$BASEDIR/flatbuffers-1.12.0 -DFLATBUFFERS_BUILD_TESTS=0

And this command is how I build ARMNN:

CXXFLAGS="-fPIC" cmake .. -DARMCOMPUTE_ROOT=$BASEDIR/ComputeLibrary -DARMCOMPUTE_BUILD_DIR=$BASEDIR/ComputeLibrary/build -DSHARED_BOOT=ON -DBOOST_ROOT=$BASEDIR/boost -DBUILD_TF_LITE_PARSER=1 -DTF_LITE_GENERATED_PATH=$BASEDIR/tensorflow/tensorflow/lite/schema -DFLATBUFFERS_ROOT=$BASEDIR/flatbuffers-1.12.0 -DFLATBUFFERS_LIBRARY=$BASEDIR/flatbuffers-1.12.0/libflatbuffers.a -DFLATBUFFERS_INCLUDE_PATH=$BASEDIR/flatbuffers-1.12.0/include -DFLATC_DIR=$BASEDIR/flatbuffers-1.12.0/build -DARMCOMPUTENEON=1 -DARMNNREF=1 -DBUILD_TESTS=1
make -j8

Hope this helps everyone. Also, please close this issue if you think it's good.

HungYangChang commented 3 years ago

Unfortunately, I tried to re-build it again ( this time I build with tflite delegate) with ARM NN 21.08 and Tflite 2.3.1. So again I use 21.05 and follow the similar setup I mention above and I was ABLE to build it.

Maybe other users are able to build (?) welcome sharing.

MatthewARM commented 2 years ago

Looking at the history of the TfLite schema (https://github.com/tensorflow/tensorflow/blob/r2.2/tensorflow/lite/schema/schema.fbs) it seems that shape_signature was added in Tensorflow 2.2, but Arm NN didn't start using it until Arm NN 21.08.

So I think the likely problem here is you have some stale build artifacts from an older build of Tensorflow, and your build of Arm NN is picking up flatbuffer headers etc. from the old build, which will not work Arm NN 21.08 and later.

Hope that helps, Matthew

catcor01 commented 2 years ago

Hi @HungYangChang ,

I am going to close this issue as your problem seems to have been resolved and it has been some time since the latest activity has occurred. If you are still experiencing problems, please do not hesitate to reopen this ticket or create a new issue.

Kind Regards, Cathal.