Extracting Arm NN on your Raspberry Pi and running a sample program

To create an archive of cross-compiled libraries, binaries, and directories:

  1. Copy the following libraries, binaries, and directories from your virtual machine. To copy these libraries, binaries, and directories enter the following commands:

    #Set the versions based on /armnn/include/armnn/Version.hpp
    ARMNN_MAJOR_VERSION=<ARMNN_MAJOR_VERSION>
    ARMNN_MINOR_VERSION=<ARMNN_MINOR_VERSION>
    ARMNN_PATCH_VERSION=<ARMNN_PATCH_VERSION>
    cd $BASEDIR
    mkdir armnn-dist
    mkdir armnn-dist/armnn
    mkdir armnn-dist/armnn/lib
    cp $BASEDIR/armnn/build/libarmnn.so.$ARMNN_MAJOR_VERSION.$ARMNN_MINOR_VERSION $BASEDIR/armnn-dist/armnn/lib
    ln -s libarmnn.so.$ARMNN_MAJOR_VERSION.$ARMNN_MINOR_VERSION $BASEDIR/armnn-dist/armnn/lib/libarmnn.so.$ARMNN_MAJOR_VERSION
    ln -s libarmnn.so.$ARMNN_MAJOR_VERSION $BASEDIR/armnn-dist/armnn/lib/libarmnn.so
    cp $BASEDIR/armnn/build/libarmnnTfParser.so.$ARMNN_MAJOR_VERSION.$ARMNN_MINOR_VERSION $BASEDIR/armnn-dist/armnn/lib
    ln -s libarmnnTfParser.so.$ARMNN_MAJOR_VERSION.$ARMNN_MINOR_VERSION $BASEDIR/armnn-dist/armnn/lib/libarmnnTfParser.so.$ARMNN_MAJOR_VERSION
    ln -s libarmnnTfParser.so.$ARMNN_MAJOR_VERSION $BASEDIR/armnn-dist/armnn/lib/libarmnnTfParser.so
    cp $BASEDIR/protobuf-arm/lib/libprotobuf.so.15.0.0 $BASEDIR/armnn-dist/armnn/lib/libprotobuf.so
    cp $BASEDIR/protobuf-arm/lib/libprotobuf.so.15.0.0 $BASEDIR/armnn-dist/armnn/lib/libprotobuf.so.15
    cp -r $BASEDIR/armnn/include $BASEDIR/armnn-dist/armnn/include
    cp -r $BASEDIR/boost $BASEDIR/armnn-dist/boost
  2. To test that your build of Arm NN works correctly, you will need to run Unit Tests. To enable the running of Unit Tests, also copy the libtimelineDecoder.so, libtimelineDecoderJson.so and libarmnnBasePipeServer.so libraries from your virtual machine.

  3. Note

    If you are also building for the Open Neural Network Exchange (ONNX) format and TensorFlow Lite, you also have to copy and link the libarmnnOnnxParser.so and libarmnnTfLiteParser.so libraries.

  4. Copy the following dynamic backend related files from your virtual machine. To copy these files, enter the following commands:

    mkdir -p $BASEDIR/armnn-dist/src/backends/backendsCommon/test/
    cp -r $BASEDIR/armnn/build/src/backends/backendsCommon/test/testSharedObject $BASEDIR/armnn-dist/src/backends/backendsCommon/test/testSharedObject/
    
    cp -r $BASEDIR/armnn/build/src/backends/backendsCommon/test/testDynamicBackend/ $BASEDIR/armnn-dist/src/backends/backendsCommon/test/testDynamicBackend/
    cp -r $BASEDIR/armnn/build/src/backends/backendsCommon/test/backendsTestPath1/ $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath1/
    
    mkdir -p $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath2
    cp $BASEDIR/armnn/build/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath2/
    
    ln -s Arm_CpuAcc_backend.so $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1
    ln -s Arm_CpuAcc_backend.so.1 $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1.2
    ln -s Arm_CpuAcc_backend.so.1.2 $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1.2.3
    cp $BASEDIR/armnn/build/src/backends/backendsCommon/test/backendsTestPath2/Arm_GpuAcc_backend.so $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath2/
    ln -s nothing $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath2/Arm_no_backend.so
    
    mkdir -p $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath3
    
    cp -r $BASEDIR/armnn/build/src/backends/backendsCommon/test/backendsTestPath5/ $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath5
    cp -r $BASEDIR/armnn/build/src/backends/backendsCommon/test/backendsTestPath6/ $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath6
    
    mkdir -p $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath7
    
    cp -r $BASEDIR/armnn/build/src/backends/backendsCommon/test/backendsTestPath9/ $BASEDIR/armnn-dist/src/backends/backendsCommon/test/backendsTestPath9
    
    mkdir -p $BASEDIR/armnn-dist/src/backends/dynamic/reference
    cp $BASEDIR/armnn/build/src/backends/dynamic/reference/Arm_CpuRef_backend.so $BASEDIR/armnn-dist/src/backends/dynamic/reference/

    If you enable the standalone sample dynamic backend tests, also copy the dynamic backend file using the following commands:

    mkdir -p $BASEDIR/armnn-dist/src/dynamic/sample
    cp $BASEDIR/armnn/src/dynamic/sample/build/libArm_SampleDynamic_backend.so $BASEDIR/armnn-dist/src/dynamic/sample/
    cp $BASEDIR/armnn/samples/DynamicSample.cpp $BASEDIR/armnn-dist
  5. Copy the Unit Tests and a sample Arm NN program. To copy this test and program, enter the following commands:

    cp $BASEDIR/armnn/build/UnitTests $BASEDIR/armnn-dist
    cp $BASEDIR/armnn/samples/SimpleSample.cpp $BASEDIR/armnn-dist
  6. Create the archive for your Raspberry Pi. To create the archive, enter the following command:

    tar -czf $BASEDIR/armnn-dist.tar.gz armnn-dist

Extract the libraries, binaries, and directories to your Raspberry Pi

Extract the libraries, binaries, and directories to your Raspberry Pi. To extract the libraries, binaries and directories enter the following commands:

cd /home/pi
tar -xzf /home/pi/armnn-dist.tar.gz

Compiling and running a sample Arm NN program on your Raspberry Pi

To compile and run a sample C++ program that uses Arm NN on your Raspberry Pi:

  1. Enter the following commands:

    export LD_LIBRARY_PATH=/home/pi/armnn-dist/armnn/lib
    cd /home/pi/armnn-dist

    To compile the program, enter the following commands:

    g++ SimpleSample.cpp -I/home/pi/armnn-dist/armnn/include -I/home/pi/armnn-dist/boost/include -L/home/pi/armnn-dist/armnn/lib -larmnn -larmnnTfParser -lprotobuf -o SimpleSample
  2. To run the program, enter the following command:

    ./SimpleSample

    The console returns the following:

    Please enter a number:

    Enter your number. For example:

    345

    The console returns the following:

    Your number was 345
  3. If you enable the standalone sample dynamic backend tests, you can run a sample dynamic backend program as a test.

    To compile the program, enter the following commands:

    g++ DynamicSample.cpp -I/home/pi/armnn-dist/armnn/include -I/home/pi/armnn-dist/boost/include -L/home/pi/armnn-dist/armnn/lib -larmnn -larmnnTfParser -lprotobuf -o DynamicSample

    To run the program, enter the following commands:

    ./DynamicSample

    If the test is successful, the console returns the following:

    Addition operator result is {15,11}

    If the test fails, the console returns an error message describing the reason for failure.

Previous Next