Multi-Processor System-on-Chip 1. Liliana Andrade

Чтение книги онлайн.

Читать онлайн книгу Multi-Processor System-on-Chip 1 - Liliana Andrade страница 13

Multi-Processor System-on-Chip 1 - Liliana Andrade

Скачать книгу

examples that illustrate the use of the processor’s XY memory and AGUs for machine learning inference.

      1.3.3. A software library for machine learning inference

      After selecting the right processor, the next question is how to arrive at an efficient software implementation of the targeted machine learning inference application. For this purpose, we present a library of reusable software modules to show how these are implemented efficiently on the ARC EM9D processor.

      Table 1.2. Supported kernels in the embARC MLI library

Group Kernels Description
Convolution 2D convolution Depthwise 2D convolution Convolve input features with a set of trained weights
Pooling Average pooling Max pooling Pool input features with a function
Recurrent and Core Basic RNN Long-Short Term Memory (LSTM) Fully connected Recurrent and fully connected kernels
Transform (Activation) ReLU (Relu1, Relu6, Leaky ReLU, ..) Sigmoid and TanH SoftMax Transform each element of input according to a particular non-linear function
Element-wise Addition, subtraction, multiplication maximum, minimum Apply multi-operand function element-wise to several inputs
Data Manipulation Permute Concatenation Padding 2D Move or extend input data by a specified pattern

      The embARC machine learning inference (MLI) library (embARC Open Software Platform 2019) is a set of C functions and associated data structures for building neural networks. Library functions, also called kernels, implement the processing associated with a complete layer in a neural network, with multidimensional input/output maps represented as tensor structures. Thus, a neural network graph can be implemented as a series of MLI function calls. Table 1.2 lists the currently supported MLI kernels, organized into six groups. For each kernel, there can be multiple functions in the library, including functions specifically optimized to support particular data types, weight kernel sizes and strides. In addition, helper functions are provided; these include operations such as data type conversion, data pointing and other operations not directly involved in the kernel functionality.

      Data representation is an important part of the MLI definition. Despite the large variety of kernels, the data directly involved in the calculations has common properties. Deep learning frameworks therefore typically employ a unified data representation. For example, TensorFlow works with tensors, while Caffe uses similar objects called “blobs”. Such objects represent multidimensional arrays of the proper sizes and may include additional data, such as links to related objects, synchronization primitives, etc. Similarly, mli_tensor is a universal data container in MLI. It is a lightweight tensor that contains the necessary elements for describing the data: a pointer to the data buffer, its capacity, shape, rank and data format-specific values. A kernel may take multiple tensors as inputs for producing an output tensor. For example, the 2D convolution kernel has three input tensors: the input map, the weights and the biases. All kernel-specific parameters, such as stride and padding for a convolution kernel, or the new order of dimensions for a permute kernel, are grouped into configuration structures. This data representation has several advantages:

       – it provides a simple and clear interface for the functions;

       – it allows the same interface to be used for several versions of one kernel;

       – it matches well with layered neural networks, enabling ease of use and natural library extensibility.

      The embARC MLI library uses signed fixed-point data types based on the Q-notation (Q Number Format 2019). Tensor structures with 8-bit and 16-bit data types are supported, both for input/output data and weights. When building an application, we should select the data types that provide sufficiently accurate results for each layer in the neural network. In addition to supporting kernels with the same data type (either 16-bit or 8-bit) for both data and weights, the MLI library also provides kernels with 16-bit data and 8-bit weights, in order to provide more flexibility for accuracy-vs-memory trade-offs.

Schematic illustration of assembly code generated from MLI C-code for a fully connected layer with 16-bit input data and 8-bit weights.

      Figure 1.7. Assembly code generated from MLI C-code for a fully connected layer with 16-bit input data and 8-bit weights

      Similar optimizations using dual-MAC instructions are used for other kernels, including RNN kernels and some convolution kernels. However, this approach is not convenient for all cases. As an example, we consider a depthwise convolution for a channel–height–width (CHW) data layout with a 3x3 weight kernel size. This type of layer applies a 2D convolution to each input channel separately. Dual-MAC instructions cannot be used optimally

Скачать книгу