Compute Library
17.10
|
The Computer Vision and Machine Learning library is a set of functions optimised for both ARM CPUs and GPUs using SIMD technologies.Several builds of the library are available using various configurations:
Please email devel oper @arm. com
In order to facilitate the work of the support team please provide the build information of the library you are using. To get the version of the library you are using simply run:
$ strings android-armv7a-cl-asserts/libarm_compute.so | grep arm_compute_version arm_compute_version=v16.12 Build options: {'embed_kernels': '1', 'opencl': '1', 'arch': 'armv7a', 'neon': '0', 'asserts': '1', 'debug': '0', 'os': 'android', 'Werror': '1'} Git hash=f51a545d4ea12a9059fe4e598a092f1fd06dc858
This archive contains:
You should have the following file organisation:
. ├── arm_compute --> All the arm_compute headers │ ├── core │ │ ├── CL │ │ │ ├── CLKernelLibrary.h --> Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context. │ │ │ ├── CLKernels.h --> Includes all the OpenCL kernels at once │ │ │ ├── CL specialisation of all the generic objects interfaces (ICLTensor, ICLImage, etc.) │ │ │ ├── kernels --> Folder containing all the OpenCL kernels │ │ │ │ └── CL*Kernel.h │ │ │ └── OpenCL.h --> Wrapper to configure the Khronos OpenCL C++ header │ │ ├── CPP │ │ │ ├── CPPKernels.h --> Includes all the CPP kernels at once │ │ │ └── kernels --> Folder containing all the CPP kernels │ │ │ └── CPP*Kernel.h │ │ ├── NEON │ │ │ ├── kernels --> Folder containing all the NEON kernels │ │ │ │ ├── arm64 --> Folder containing the interfaces for the assembly arm64 NEON kernels │ │ │ │ ├── arm32 --> Folder containing the interfaces for the assembly arm32 NEON kernels │ │ │ │ ├── assembly --> Folder containing the NEON assembly routines. │ │ │ │ └── NE*Kernel.h │ │ │ └── NEKernels.h --> Includes all the NEON kernels at once │ │ ├── All common basic types (Types.h, Window, Coordinates, Iterator, etc.) │ │ ├── All generic objects interfaces (ITensor, IImage, etc.) │ │ └── Objects metadata classes (ImageInfo, TensorInfo, MultiImageInfo) │ ├── graph │ │ ├── CL --> OpenCL specific operations │ │ │ └── CLMap.h / CLUnmap.h │ │ ├── nodes │ │ │ └── The various nodes supported by the graph API │ │ ├── Nodes.h --> Includes all the Graph nodes at once. │ │ └── Graph objects ( INode, ITensorAccessor, Graph, etc.) │ └── runtime │ ├── CL │ │ ├── CL objects & allocators (CLArray, CLImage, CLTensor, etc.) │ │ ├── functions --> Folder containing all the OpenCL functions │ │ │ └── CL*.h │ │ ├── CLScheduler.h --> Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner. │ │ └── CLFunctions.h --> Includes all the OpenCL functions at once │ ├── CPP │ │ ├── CPPKernels.h --> Includes all the CPP functions at once. │ │ └── CPPScheduler.h --> Basic pool of threads to execute CPP/NEON code on several cores in parallel │ ├── NEON │ │ ├── functions --> Folder containing all the NEON functions │ │ │ └── NE*.h │ │ └── NEFunctions.h --> Includes all the NEON functions at once │ ├── OMP │ │ └── OMPScheduler.h --> OpenMP scheduler (Alternative to the CPPScheduler) │ ├── Memory manager files (LifetimeManager, PoolManager, etc.) │ └── Basic implementations of the generic object interfaces (Array, Image, Tensor, etc.) ├── documentation │ ├── index.xhtml │ └── ... ├── documentation.xhtml -> documentation/index.xhtml ├── examples │ ├── cl_convolution.cpp │ ├── cl_events.cpp │ ├── graph_lenet.cpp │ ├── neoncl_scale_median_gaussian.cpp │ ├── neon_cnn.cpp │ ├── neon_copy_objects.cpp │ ├── neon_convolution.cpp │ └── neon_scale.cpp ├── include │ ├── CL │ │ └── Khronos OpenCL C headers and C++ wrapper │ ├── half --> FP16 library available from http://half.sourceforge.net │ └── libnpy --> Library to load / write npy buffers, available from https://github.com/llohse/libnpy ├── opencl-1.2-stubs │ └── opencl_stubs.c ├── scripts │ ├── caffe_data_extractor.py --> Basic script to export weights from Caffe to npy files │ └── tensorflow_data_extractor.py --> Basic script to export weights from Tensor Flow to npy files ├── src │ ├── core │ │ └── ... (Same structure as headers) │ │ └── CL │ │ └── cl_kernels --> All the OpenCL kernels │ ├── graph │ │ └── ... (Same structure as headers) │ └── runtime │ └── ... (Same structure as headers) ├── support │ └── Various headers to work around toolchains / platform issues. ├── tests │ ├── All test related files shared between validation and benchmark │ ├── CL --> OpenCL accessors │ ├── NEON --> NEON accessors │ ├── benchmark --> Sources for benchmarking │ │ ├── Benchmark specific files │ │ ├── CL --> OpenCL benchmarking tests │ │ └── NEON --> NEON benchmarking tests │ ├── datasets │ │ └── Datasets for all the validation / benchmark tests, layer configurations for various networks, etc. │ ├── framework │ │ └── Boiler plate code for both validation and benchmark test suites (Command line parsers, instruments, output loggers, etc.) │ ├── networks │ │ └── Examples of how to instantiate networks. │ ├── validation --> Sources for validation │ │ ├── Validation specific files │ │ ├── CL --> OpenCL validation tests │ │ ├── CPP --> C++ reference implementations │ │ ├── fixtures │ │ │ └── Fixtures to initialise and run the runtime Functions. │ │ └── NEON --> NEON validation tests │ └── dataset --> Datasets defining common sets of input parameters └── utils --> Boiler plate code used by examples └── Utils.h
All releases are numbered vYY.MM Where YY are the last two digits of the year, and MM the month number. If there is more than one release in a month then an extra sequential number is appended at the end:
v17.03 (First release of March 2017) v17.03.1 (Second release of March 2017) v17.04 (First release of April 2017)
v17.10 Public maintenance release
v17.09 Public major release
v17.06 Public major release
v17.05 Public bug fixes release
v17.04 Public bug fixes release
The following functions have been ported to use the new accurate padding:
v17.03.1 First Major public release of the sources
v17.03 Sources preview
v17.02.1 Sources preview
v17.02 Sources preview
v16.12 Binary preview release
scons 2.3 or above is required to build the library. To see the build options available simply run scons -h
:
debug: Debug (yes|no) default: False actual: False asserts: Enable asserts (this flag is forced to 1 for debug=1) (yes|no) default: False actual: False arch: Target Architecture (armv7a|arm64-v8a|arm64-v8.2-a|x86_32|x86_64) default: armv7a actual: armv7a os: Target OS (linux|android|bare_metal) default: linux actual: linux build: Build type (native|cross_compile) default: cross_compile actual: cross_compile examples: Build example programs (yes|no) default: True actual: True Werror: Enable/disable the -Werror compilation flag (yes|no) default: True actual: True opencl: Enable OpenCL support (yes|no) default: True actual: True neon: Enable Neon support (yes|no) default: False actual: False embed_kernels: Embed OpenCL kernels in library binary (yes|no) default: False actual: False set_soname: Set the library's soname and shlibversion (requires SCons 2.4 or above) (yes|no) default: False actual: False openmp: Enable OpenMP backend (yes|no) default: False actual: False cppthreads: Enable C++11 threads backend (yes|no) default: True actual: True build_dir: Specify sub-folder for the build ( /path/to/build_dir ) default: . actual: . extra_cxx_flags: Extra CXX flags to be appended to the build command default: actual: pmu: Enable PMU counters (yes|no) default: False actual: False mali: Enable Mali hardware counters (yes|no) default: False actual: False validation_tests: Build validation test programs (yes|no) default: False actual: False benchmark_tests: Build benchmark test programs (yes|no) default: False actual: False
debug / asserts:
arch: The x86_32 and x86_64 targets can only be used with neon=0 and opencl=1.
os: Choose the operating system you are targeting: Linux, Android or bare metal.
build: you can either build directly on your device (native) or cross compile from your desktop machine (cross-compile). In both cases make sure the compiler is available in your path.
Werror: If you are compiling using the same toolchains as the ones used in this guide then there shouldn't be any warning and therefore you should be able to keep Werror=1. If with a different compiler version the library fails to build because of warnings interpreted as errors then, if you are sure the warnings are not important, you might want to try to build with Werror=0 (But please do report the issue either on Github or by an email to devel so that the issue can be addressed). oper @arm. com
opencl / neon: Choose which SIMD technology you want to target. (NEON for ARM Cortex-A CPUs or OpenCL for ARM Mali GPUs)
embed_kernels: For OpenCL only: set embed_kernels=1 if you want the OpenCL kernels to be built in the library's binaries instead of being read from separate ".cl" files. If embed_kernels is set to 0 then the application can set the path to the folder containing the OpenCL kernel files by calling CLKernelLibrary::init(). By default the path is set to "./cl_kernels".
set_soname: Do you want to build the versioned version of the library ?
If enabled the library will contain a SONAME and SHLIBVERSION and some symlinks will automatically be created between the objects. Example: libarm_compute_core.so -> libarm_compute_core.so.1.0.0 libarm_compute_core.so.1 -> libarm_compute_core.so.1.0.0 libarm_compute_core.so.1.0.0
extra_cxx_flags: Custom CXX flags which will be appended to the end of the build command.
build_dir: Build the library in a subfolder of the "build" folder. (Allows to build several configurations in parallel).
examples: Build or not the examples
validation_tests: Enable the build of the validation suite.
benchmark_tests: Enable the build of the benchmark tests
pmu: Enable the PMU cycle counter to measure execution time in benchmark tests. (Your device needs to support it)
mali: Enable the collection of Mali hardware counters to measure execution time in benchmark tests. (Your device needs to have a Mali driver that supports it)
openmp Build in the OpenMP scheduler for NEON.
cppthreads Build in the C++11 scheduler for NEON.
For Linux, the library was successfully built and tested using the following Linaro GCC toolchain:
To cross-compile the library in debug mode, with NEON only support, for Linux 32bit:
scons Werror=1 -j8 debug=1 neon=1 opencl=0 os=linux arch=armv7a
To cross-compile the library in asserts mode, with OpenCL only support, for Linux 64bit:
scons Werror=1 -j8 debug=0 asserts=1 neon=0 opencl=1 embed_kernels=1 os=linux arch=arm64-v8a
You can also compile the library natively on an ARM device by using build=native:
scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=arm64-v8a build=native scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a build=native
For example on a 64bit Debian based system you would have to install g++-arm-linux-gnueabihf
apt-get install g++-arm-linux-gnueabihf
Then run
scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a build=cross_compile
or simply remove the build parameter as build=cross_compile is the default value:
scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=linux arch=armv7a
The examples get automatically built by scons as part of the build process of the library described above. This section just describes how you can build and link your own application against our library.
To cross compile a NEON example for Linux 32bit:
arm-linux-gnueabihf-g++ examples/neon_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -mfpu=neon -L. -larm_compute -larm_compute_core -o neon_convolution
To cross compile a NEON example for Linux 64bit:
aarch64-linux-gnu-g++ examples/neon_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -L. -larm_compute -larm_compute_core -o neon_convolution
(notice the only difference with the 32 bit command is that we don't need the -mfpu option and the compiler's name is different)
To cross compile an OpenCL example for Linux 32bit:
arm-linux-gnueabihf-g++ examples/cl_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -mfpu=neon -L. -larm_compute -larm_compute_core -lOpenCL -o cl_convolution -DARM_COMPUTE_CL
To cross compile an OpenCL example for Linux 64bit:
aarch64-linux-gnu-g++ examples/cl_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -L. -larm_compute -larm_compute_core -lOpenCL -o cl_convolution -DARM_COMPUTE_CL
(notice the only difference with the 32 bit command is that we don't need the -mfpu option and the compiler's name is different)
To cross compile the examples with the Graph API, such as graph_lenet.cpp, you need to link the library arm_compute_graph.so also. (notice the compute library has to be built with both neon and opencl enabled - neon=1 and opencl=1)
i.e. to cross compile the "graph_lenet" example for Linux 32bit:
arm-linux-gnueabihf-g++ examples/graph_lenet.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -mfpu=neon -L. -larm_compute_graph -larm_compute -larm_compute_core -lOpenCL -o graph_lenet -DARM_COMPUTE_CL
i.e. to cross compile the "graph_lenet" example for Linux 64bit:
aarch64-linux-gnu-g++ examples/graph_lenet.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -L. -larm_compute_graph -larm_compute -larm_compute_core -lOpenCL -o graph_lenet -DARM_COMPUTE_CL
(notice the only difference with the 32 bit command is that we don't need the -mfpu option and the compiler's name is different)
To compile natively (i.e directly on an ARM device) for NEON for Linux 32bit:
g++ examples/neon_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -mfpu=neon -larm_compute -larm_compute_core -o neon_convolution
To compile natively (i.e directly on an ARM device) for NEON for Linux 64bit:
g++ examples/neon_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute -larm_compute_core -o neon_convolution
(notice the only difference with the 32 bit command is that we don't need the -mfpu option)
To compile natively (i.e directly on an ARM device) for OpenCL for Linux 32bit or Linux 64bit:
g++ examples/cl_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute -larm_compute_core -lOpenCL -o cl_convolution -DARM_COMPUTE_CL
To compile natively (i.e directly on an ARM device) the examples with the Graph API, such as graph_lenet.cpp, you need to link the library arm_compute_graph.so also. (notice the compute library has to be built with both neon and opencl enabled - neon=1 and opencl=1)
i.e. to cross compile the "graph_lenet" example for Linux 32bit:
g++ examples/graph_lenet.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -mfpu=neon -L. -larm_compute_graph -larm_compute -larm_compute_core -lOpenCL -o graph_lenet -DARM_COMPUTE_CL
i.e. to cross compile the "graph_lenet" example for Linux 64bit:
g++ examples/graph_lenet.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 L. -larm_compute_graph -larm_compute -larm_compute_core -lOpenCL -o graph_lenet -DARM_COMPUTE_CL
(notice the only difference with the 32 bit command is that we don't need the -mfpu option)
To run the built executable simply run:
LD_LIBRARY_PATH=build ./neon_convolution
or
LD_LIBRARY_PATH=build ./cl_convolution
For Android, the library was successfully built and tested using Google's standalone toolchains:
Here is a guide to create your Android standalone toolchains from the NDK
$NDK/build/tools/make_standalone_toolchain.py --arch arm64 --install-dir $MY_TOOLCHAINS/aarch64-linux-android-4.9 --stl gnustl $NDK/build/tools/make_standalone_toolchain.py --arch arm --install-dir $MY_TOOLCHAINS/arm-linux-androideabi-4.9 --stl gnustl
To cross-compile the library in debug mode, with NEON only support, for Android 32bit:
CXX=clang++ CC=clang scons Werror=1 -j8 debug=1 neon=1 opencl=0 os=android arch=armv7a
To cross-compile the library in asserts mode, with OpenCL only support, for Android 64bit:
scons Werror=1 -j8 debug=0 asserts=1 neon=0 opencl=1 embed_kernels=1 os=android arch=arm64-v8a
The examples get automatically built by scons as part of the build process of the library described above. This section just describes how you can build and link your own application against our library.
Once you've got your Android standalone toolchain built and added to your path you can do the following:
To cross compile a NEON example:
#32 bit: arm-linux-androideabi-clang++ examples/neon_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute-static -larm_compute_core-static -L. -o neon_convolution_arm -static-libstdc++ -pie #64 bit: aarch64-linux-android-g++ examples/neon_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute-static -larm_compute_core-static -L. -o neon_convolution_aarch64 -static-libstdc++ -pie
To cross compile an OpenCL example:
#32 bit: arm-linux-androideabi-clang++ examples/cl_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute-static -larm_compute_core-static -L. -o cl_convolution_arm -static-libstdc++ -pie -lOpenCL -DARM_COMPUTE_CL #64 bit: aarch64-linux-android-g++ examples/cl_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute-static -larm_compute_core-static -L. -o cl_convolution_aarch64 -static-libstdc++ -pie -lOpenCL -DARM_COMPUTE_CL
To cross compile the examples with the Graph API, such as graph_lenet.cpp, you need to link the library arm_compute_graph also. (notice the compute library has to be built with both neon and opencl enabled - neon=1 and opencl=1)
#32 bit: arm-linux-androideabi-clang++ examples/graph_lenet.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute_graph-static -larm_compute-static -larm_compute_core-static -L. -o graph_lenet_arm -static-libstdc++ -pie -lOpenCL -DARM_COMPUTE_CL #64 bit: aarch64-linux-android-g++ examples/graph_lenet.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -larm_compute_graph-static -larm_compute-static -larm_compute_core-static -L. -o graph_lenet_aarch64 -static-libstdc++ -pie -lOpenCL -DARM_COMPUTE_CL
Then you need to do is upload the executable and the shared library to the device using ADB:
adb push neon_convolution_arm /data/local/tmp/ adb push cl_convolution_arm /data/local/tmp/ adb shell chmod 777 -R /data/local/tmp/
And finally to run the example:
adb shell /data/local/tmp/neon_convolution_arm adb shell /data/local/tmp/cl_convolution_arm
For 64bit:
adb push neon_convolution_aarch64 /data/local/tmp/ adb push cl_convolution_aarch64 /data/local/tmp/ adb shell chmod 777 -R /data/local/tmp/
And finally to run the example:
adb shell /data/local/tmp/neon_convolution_aarch64 adb shell /data/local/tmp/cl_convolution_aarch64
For bare metal, the library was successfully built using linaros's latest (gcc-linaro-6.3.1-2017.05) bare metal toolchains:
Download linaro for armv7a and arm64-v8a.
To cross-compile the library with NEON support for baremetal arm64-v8a:
scons Werror=1 -j8 debug=0 neon=1 opencl=0 os=bare_metal arch=arm64-v8a build=cross_compile cppthreads=0 openmp=0 standalone=1
Examples are disabled when building for bare metal. If you want to build the examples you need to provide a custom bootcode depending on the target architecture and link against the compute library. More information about bare metal bootcode can be found here.
Using scons
directly from the Windows command line is known to cause problems. The reason seems to be that if scons
is setup for cross-compilation it gets confused about Windows style paths (using backslashes). Thus it is recommended to follow one of the options outlined below.
The best and easiest option is to use Ubuntu on Windows. This feature is still marked as beta and thus might not be available. However, if it is building the library is as simple as opening a Bash on Ubuntu on Windows shell and following the general guidelines given above.
If the Windows subsystem for Linux is not available Cygwin can be used to install and run scons
. In addition to the default packages installed by Cygwin scons
has to be selected in the installer. (git
might also be useful but is not strictly required if you already have got the source code of the library.) Linaro provides pre-built versions of GCC cross-compilers that can be used from the Cygwin terminal. When building for Android the compiler is included in the Android standalone toolchain. After everything has been set up in the Cygwin terminal the general guide on building the library can be followed.
In the opencl-1.2-stubs folder you will find the sources to build a stub OpenCL library which then can be used to link your application or arm_compute against.
If you preferred you could retrieve the OpenCL library from your device and link against this one but often this library will have dependencies on a range of system libraries forcing you to link your application against those too even though it is not using them.
To cross-compile the stub OpenCL library simply run:
<target-prefix>-gcc -o libOpenCL.so -Iinclude opencl-1.2-stubs/opencl_stubs.c -fPIC -shared
For example:
<target-prefix>-gcc -o libOpenCL.so -Iinclude opencl-1.2-stubs/opencl_stubs.c -fPIC -shared #Linux 32bit arm-linux-gnueabihf-gcc -o libOpenCL.so -Iinclude opencl-1.2-stubs/opencl_stubs.c -fPIC -shared #Linux 64bit aarch64-linux-gnu-gcc -o libOpenCL.so -Iinclude -shared opencl-1.2-stubs/opencl_stubs.c -fPIC #Android 32bit arm-linux-androideabi-clang -o libOpenCL.so -Iinclude -shared opencl-1.2-stubs/opencl_stubs.c -fPIC -shared #Android 64bit aarch64-linux-android-gcc -o libOpenCL.so -Iinclude -shared opencl-1.2-stubs/opencl_stubs.c -fPIC -shared