In-place execution of neural network operations with scatter write and gather read across memory fragments

The proposed memory management approach for DNNs enables in-place execution and scatter/gather operations across fragmented memory, addressing bandwidth and utilization issues, enhancing efficiency and performance in DNN inference.

WO2026044571A1PCT designated stage Publication Date: 2026-03-05INTEL CORP +7
View PDF 5 Cites 0 Cited by

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-08-29
Publication Date
2026-03-05

AI Technical Summary

Technical Problem

DNNs face significant computation and memory bandwidth challenges due to high computing demands and inefficient memory utilization, leading to performance bottlenecks and increased power consumption, particularly in resource-constrained devices.

Method used

Implement a memory management approach that enables in-place execution of deep learning operations, allowing input memory to be reused for output storage, and supports scatter write and gather read across fragmented memory spaces using scatter and gather maps to optimize memory utilization.

Benefits of technology

Improves memory bandwidth efficiency, reduces on-chip memory consumption, and enhances DNN inference performance, especially for large convolutions and matrix multiplications, by effectively utilizing available memory spaces and reducing memory traffic.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024115392_05032026_PF_FP_ABST
    Figure CN2024115392_05032026_PF_FP_ABST
Patent Text Reader

Abstract

A deep neural network (DNN) accelerator may execute in-place deep learning operations. The DNN accelerator may write an input tensor of a DNN layer into a memory that includes a plurality of memory entries storing input elements in the input tensor. The DNN accelerator may compute an output tensor of the layer using the input tensor and another tensor, e.g., by performing multiply-accumulate operations on the input tensor and the other tensor. The DNN accelerator may use a scatter map to write the output tensor into the memory and generate a gather map to be used for reading the output tensor in the next layer. The DNN accelerator may remove an input element from a memory entry and store an output element in the memory entry. The position of the input element in the input tensor may be different from the position of the output element in the output tensor.
Need to check novelty before this filing date? Find Prior Art

Description

IN-PLACE EXECUTION OF NEURAL NETOWRK OPERATIONS WITH SCATTER WRITE AND GATHER READ ACROSS MEMORY FRAGMENTSTechnical Field

[0001] This disclosure relates generally to neural networks (also referred to as “deep neural networks” or “DNN” ) , and more specifically, in-place execution of operations in DNNs with scattered data write and read across memory fragments.Background

[0002] DNNs are used extensively for a variety of artificial intelligence applications ranging from computer vision to speech recognition and natural language processing due to their ability to achieve high accuracy. However, the high accuracy comes at the expense of significant computation cost. DNNs have extremely high computing demands as there can be hundreds of millions of MAC (multiply-accumulate) operations as well as a large amount of data to read and write. Therefore, techniques to improve efficiency of DNNs are needed.Brief Description of the Drawings

[0003] Embodiments will be readily understood by the following detailed description in conjunction with the accompanying drawings. To facilitate this description, like reference numerals designate like structural elements. Embodiments are illustrated by way of example, and not by way of limitation, in the figures of the accompanying drawings.

[0004] FIG. 1 illustrates an example DNN, in accordance with various embodiments.

[0005] FIG. 2 illustrates an example convolution, in accordance with various embodiments.

[0006] FIG. 3 is a block diagram of a DNN system, in accordance with various embodiments.

[0007] FIG. 4 is a block diagram of a DNN module, in accordance with various embodiments.

[0008] FIG. 5 illustrates an input tensor and an output tensor of a deep learning operation executed in place, in accordance with various embodiments.

[0009] FIG. 6 illustrates an example matrix multiplication operation, in accordance with various embodiments.

[0010] FIG. 7 illustrates output data elements overwriting input data elements during in-place execution of the matrix multiplication operation in FIG. 6, in accordance with various  embodiments.

[0011] FIG. 8 illustrates memory layout before and after the in-place execution of the matrix multiplication operation in FIG. 6, in accordance with various embodiments.

[0012] FIG. 9 illustrates memory layout before and after in-place execution of another matrix multiplication operation, in accordance with various embodiments.

[0013] FIG. 10 illustrates memory layout before and after in-place execution of a matrix multiplication operation executed by multiple compute blocks, in accordance with various embodiments.

[0014] FIG. 11 illustrates an example sparse cell, in accordance with various embodiments.

[0015] FIG. 12 illustrates an example sparse cell array, in accordance with various embodiments.

[0016] FIG. 13 is a block diagram of a drain module, in accordance with various embodiments.

[0017] FIG. 14 illustrates an example memory with scattered free memory fragments, in accordance with various embodiments.

[0018] FIG. 15 illustrates a scatter map and a gather map, in accordance with various embodiments.

[0019] FIG. 16 illustrates scatter write and gather read, in accordance with various embodiments.

[0020] FIG. 17 illustrates an example sparse encoder, in accordance with various embodiments.

[0021] FIG. 18 is a flowchart showing a method of executing a DNN layer, in accordance with various embodiments.

[0022] FIG. 19 is a block diagram of an example computing device, in accordance with various embodiments.Detailed Description

[0023] Overview

[0024] The last decade has witnessed a rapid rise in AI (artificial intelligence) based data processing, particularly based on DNNs. A DNN usually includes a sequence of layers. A DNN layer may include one or more deep learning operations (also referred to as “neural network  operations” ) , such as convolution, matrix multiplication, pooling, elementwise operation, linear operation, nonlinear operation, and so on. A deep learning operation in a DNN may be performed on one or more internal parameters of the DNNs (e.g., weights) , which are determined during the training phase, and one or more activations. An activation may be a data point (also referred to as “data elements” or “elements” ) . Activations or weights of a DNN layer may be elements of a tensor of the DNN layer. A tensor is a data structure having multiple elements across one or more dimensions. Example tensors include a vector, which is a one-dimensional tensor, and a matrix, which is a two-dimensional tensor. There can also be three-dimensional tensors and even higher dimensional tensors. A DNN layer may have an input tensor (also referred to as “input feature map (IFM) ” ) including one or more input activations (also referred to as “input elements” ) and a weight tensor including one or more weights. A weight is an element in the weight tensor. A weight tensor of a convolution may be a kernel, a filter, or a group of filters. The output data of the DNN layer may be an output tensor (also referred to as “output feature map (OFM) ” ) that includes one or more output activations (also referred to as “output elements” ) . The fundamental operation of a convolution and matrix multiplication is MAC operations on two tensors.

[0025] DNNs are widely used in the domains of computer vision, speech recognition, natural language processing, image, and video processing mainly due to their ability to achieve beyond human-level accuracy. The significant improvements in DNN model size and accuracy coupled with the rapid increase in computing power of execution platforms have led to the adoption of DNN applications even within resource constrained mobile and edge devices that have limited energy availability.

[0026] For instance, the complexity of performing inference on convolutional neural networks (CNNs) is related to the number of parameters in the model, and it directly impacts the storage size and bandwidth requirements of memory, such as off-chip memory (e.g., dynamic random-access memories (DRAM) ) and on-chip memory (e.g., static random-access memories (SRAM) ) . The number of parameters in CNNs has been increasing as larger and more complex models are developed to improve accuracy and performance of the networks. The efficiency of executing CNN layers can be limited by memory bandwidth as less operation is performed for each fetch byte of data. For such CNN layers, insufficient memory bandwidth can cause stall cycles as compute elements must wait for data fetches from the  on-chip memory. The compute capacity of DNN accelerators grow steadily across product generations due to technology process improvement as well as architectural innovations. With the increase in computation power (e.g., scaling of the numbers of compute elements, e.g., MAC units) , memory capacity and bandwidth becomes the greater bottleneck as more CNN layers are not able to reach accelerator’s peak performance. This trend is exacerbated by the scaling seen in latest process nodes where standard cells (logic) outpaces SRAM memories in density and performance improvements.

[0027] Another factor pushing CNNs into being memory bandwidth limited is that the on-chip memory of a DNN accelerator can consume a significant amount of power due to the size and number of accesses performed by the compute elements to load or store parameters. It can be advantageous to select on-chip memory with lower power consumption and to clock it using lower operating frequency than compute elements. Many currently available DNN accelerators use a clock ratio of 1: 2 or 4: 7 between the compute elements and the on-chip memory. Therefore, efficient utilization of memory capacity can be important to address the performance bottleneck due to memory bound DNN-based applications.

[0028] Many currently available approaches rely on compression and exploiting sparsity to reduce memory utilization. These approaches are usually used to reduce the memory allocation during inference workload execution. For the AI accelerators to exploit sparsity, the data needs to be compressed with a bitmap, which incurs more storage. Bitmaps are usually stored and retrieved separately, which further complicates the allocation and freeing of on-chip memory during management of workloads. One of the drawbacks to these approaches is that the memory cannot be fully utilized with regions in the memory being under-utilized due to the creation of holes. These holes can be easily tracked by the compiler, but unless the AI hardware is able to stitch these holes together, it cannot effectively utilize them during memory management of workloads. These approaches fail to support memory utilization that can exploit these holes and improve layer and network-level performance.

[0029] Embodiments of the present disclosure may improve on at least some of the challenges and issues described above by providing a memory management approach that can facilitate in-place execution of deep learning operations. During the in-place execution  of a deep learning operation by an example DNN accelerator, memory allocated for the input of the deep learning operation can be at least partially reused to store the output of the deep learning operation. The DNN accelerator can also provide support for compute elements to access fragmented memory spaces through scattered data write and read. The memory management approach can provide efficient memory utilization, particularly for large convolution and matrix multiplications.

[0030] In various embodiments of the present disclosure, a DNN accelerator may execute in-place deep learning operations, including convolutions and matrix multiplications. The DNN accelerator may write an input tensor of a DNN layer into a memory. The memory may include a plurality of memory entries that store input elements in the input tensor. The DNN accelerator may compute an output tensor of the layer using the input tensor and another tensor, e.g., by performing multiply-accumulate operations on the input tensor and the other tensor. When the deep learning operation is a convolution, the other tensor may include a kernel of the convolution. The output tensor includes one or more output elements. After the DNN accelerator computes an output element, the DNN accelerator may remove an input element from the corresponding memory entry and store an output element in the memory entry. The DNN accelerator may reserve an offset area in the memory to avoid data corruption. For instance, the DNN accelerator may maintain at least one free memory entry before the memory entries storing the input tensor. The DNN accelerator may write the first output element of the output tensor into the free memory entry as the first input element of the output tensor may be used later to compute one or more other output tensors. When or after the first input element is not needed anymore to compute any output elements, the first input element may be removed from the corresponding memory entry and a subsequent output element of the output tensor may be written into the memory entry.

[0031] The DNN accelerator may facilitate scatter write and gather read across multiple memory fragments. The memory may be partitioned into fragments. A memory fragment may include one or more memory entries. A tensor may be stored in multiple memory fragments, which may be separated by one or more other memory fragments. In an example, the memory may include four fragments arranged in a sequence. The DNN accelerator may write a portion of a first tensor into the first fragment, write a second  tensor (or a portion of the second tensor) into the second segment, write another portion of the first tensor into the third fragment, and write a third tensor (or a portion of the third tensor) into the fourth segment. The DNN accelerator may manage two data structures, such as a scatter map and a gather map, for reading data from or writing data into fragmented memory spaces. A scatter map may include information about free fragments in the memory, i.e., fragments that do not store any data. For each free memory fragment, the scatter map may include a start memory address of the free fragment, a free size (e.g., the total number of memory entries in the free fragment) , and a cumulative free size (e.g., the total number of memory entries in the free fragment plus any other free fragment (s) that are before the free fragment) . The scatter map may be generated by a DNN module associated with the DNN accelerator. The drain module in the DNN accelerator may use the scatter map to write output elements into the memory.

[0032] The drain module can also generate the corresponding gather map. The gather map is a data structure that is used by the load module to gather the different fragments populated by the drain unit scatter process. The gather map may include data indicating the memory address where each output element is stored and one or more position parameters for each output element. The one or more position parameters of an output element may indicate a position of the output element in the output tensor. The gather map may be enumerated by the drain module based on the scatter map. Each entry in the gather map may correspond to each free entry indicated in the scatter map. The gather map may be used by a load module in the DNN accelerator to load the output elements into the MAC units for executing the next DNN layer.

[0033] The approach in the present disclosure can enumerate hardware optimizations to improve the memory bandwidth and can therefore improve efficiency of DNN-based applications, including the ones that are memory bound. With the reuse of input memory as output memory, on-chip memory consumption can be reduced. Scatter data write and gather data read across multiple memory fragments can optimize utilization of available memory spaces and reduce memory traffic. Therefore, the approach in the present disclosure can improve DNN inference efficiency, particularly efficiency of large convolutions and large matrix multiplications.

[0034] For purposes of explanation, specific numbers, materials and configurations are set  forth in order to provide a thorough understanding of the illustrative implementations. However, it will be apparent to one skilled in the art that the present disclosure may be practiced without the specific details or / and that the present disclosure may be practiced with only some of the described aspects. In other instances, well known features are omitted or simplified in order not to obscure the illustrative implementations.

[0035] Further, references are made to the accompanying drawings that form a part hereof, and in which is shown, by way of illustration, embodiments that may be practiced. It is to be understood that other embodiments may be utilized, and structural or logical changes may be made without departing from the scope of the present disclosure. Therefore, the following detailed description is not to be taken in a limiting sense.

[0036] Various operations may be described as multiple discrete actions or operations in turn, in a manner that is most helpful in understanding the claimed subject matter. However, the order of description should not be construed as to imply that these operations are necessarily order dependent. In particular, these operations may not be performed in the order of presentation. Operations described may be performed in a different order from the described embodiment. Various additional operations may be performed or described operations may be omitted in additional embodiments.

[0037] For the purposes of the present disclosure, the phrase “A or B” or the phrase "A and / or B" means (A) , (B) , or (A and B) . For the purposes of the present disclosure, the phrase “A, B, or C” or the phrase "A, B, and / or C" means (A) , (B) , (C) , (A and B) , (A and C) , (B and C) , or (A, B, and C) . The term "between, " when used with reference to measurement ranges, is inclusive of the ends of the measurement ranges.

[0038] The description uses the phrases "in an embodiment" or "in embodiments, " which may each refer to one or more of the same or different embodiments. The terms "comprising, " "including, " "having, " and the like, as used with respect to embodiments of the present disclosure, are synonymous. The disclosure may use perspective-based descriptions such as "above, " "below, " "top, " "bottom, " and "side" to explain various features of the drawings, but these terms are simply for ease of discussion, and do not imply a desired or required orientation. The accompanying drawings are not necessarily drawn to scale. Unless otherwise specified, the use of the ordinal adjectives “first, ” “second, ” and “third, ” etc., to describe a common object, merely indicates that different instances of like  objects are being referred to and are not intended to imply that the objects so described must be in a given sequence, either temporally, spatially, in ranking or in any other manner.

[0039] In the following detailed description, various aspects of the illustrative implementations will be described using terms commonly employed by those skilled in the art to convey the substance of their work to others skilled in the art.

[0040] The terms “substantially, ” “close, ” “approximately, ” “near, ” and “about, ” generally refer to being within + / -20%of a target value as described herein or as known in the art. Similarly, terms indicating orientation of various elements, e.g., “coplanar, ” “perpendicular, ” “orthogonal, ” “parallel, ” or any other angle between the elements, generally refer to being within + / -5-20%of a target value as described herein or as known in the art.

[0041] In addition, the terms “comprise, ” “comprising, ” “include, ” “including, ” “have, ” “having” or any other variation thereof, are intended to cover a non-exclusive inclusion. For example, a method, process, device, or DNN accelerator that comprises a list of elements is not necessarily limited to only those elements but may include other elements not expressly listed or inherent to such method, process, device, or DNN accelerators. Also, the term “or” refers to an inclusive “or” and not to an exclusive “or. ”

[0042] The systems, methods and devices of this disclosure each have several innovative aspects, no single one of which is solely responsible for all desirable attributes disclosed herein. Details of one or more implementations of the subject matter described in this specification are set forth in the description below and the accompanying drawings.

[0043] Example DNN

[0044] FIG. 1 illustrates an example DNN 100, in accordance with various embodiments. The DNN 100 may be an example of a teacher network or an example of a student network. For the purpose of illustration, the DNN 100 in FIG. 1 is a CNN. In other embodiments, the DNN 100 may be other types of DNNs. The DNN 100 is trained to receive images and output classifications of objects in the images. In the embodiments of FIG. 1, the DNN 100 receives an input image 105 that includes objects 115, 125, and 135. The DNN 100 includes a sequence of layers comprising a plurality of convolutional layers 110 (individually referred to as “convolutional layer 110” ) , a plurality of pooling layers 120 (individually referred to as “pooling layer 120” ) , and a plurality of fully-connected layers 130 (individually referred to as “fully-connected layer 130” ) . In other embodiments, the DNN 100 may include fewer, more,  or different layers. In an inference of the DNN 100, the layers of the DNN 100 execute tensor computation that includes many tensor operations, such as convolution (e.g., multiply-accumulate (MAC) operations, etc. ) , pooling operations, elementwise operations (e.g., elementwise addition, elementwise multiplication, etc. ) , other types of tensor operations, or some combination thereof.

[0045] The convolutional layers 110 summarize the presence of features in the input image 105. The convolutional layers 110 function as feature extractors. The first layer of the DNN 100 is a convolutional layer 110. In an example, a convolutional layer 110 performs a convolution on an input tensor 140 (also referred to as IFM 140) and a filter 150. As shown in FIG. 1, the IFM 140 is represented by a 7×7×3 three-dimensional (3D) matrix. The IFM 140 includes 3 input channels, each of which is represented by a 7×7 two-dimensional (2D) matrix. The 7×7 2D matrix includes 7 input elements (also referred to as input points) in each row and 7 input elements in each column. The filter 150 is represented by a 3×3×3 3D matrix. The filter 150 includes 3 kernels, each of which may correspond to a different input channel of the IFM 140. A kernel is a 2D matrix of weights, where the weights are arranged in columns and rows. A kernel can be smaller than the IFM. In the embodiments of FIG. 1, each kernel is represented by a 3×3 2D matrix. The 3×3 kernel includes 3 weights in each row and 3 weights in each column. Weights can be initialized and updated by backpropagation using gradient descent. The magnitudes of the weights can indicate importance of the filter 150 in extracting features from the IFM 140.

[0046] The convolution includes MAC operations with the input elements in the IFM 140 and the weights in the filter 150. The convolution may be a standard convolution 163 or a depthwise convolution 183. In the standard convolution 163, the whole filter 150 slides across the IFM 140. All the input channels are combined to produce an output tensor 160 (also referred to as OFM 160) . The OFM 160 is represented by a 5×5 2D matrix. The 5×5 2D matrix includes 5 output elements (also referred to as output points) in each row and 5 output elements in each column. For the purpose of illustration, the standard convolution includes one filter in the embodiments of FIG. 1. In embodiments where there are multiple filters, the standard convolution may produce multiple output channels in the OFM 160.

[0047] The multiplication applied between a kernel-sized patch of the IFM 140 and a kernel may be a dot product. A dot product is the elementwise multiplication between the kernel- sized patch of the IFM 140 and the corresponding kernel, which is then summed, always resulting in a single value. Because it results in a single value, the operation is often referred to as the “scalar product. ” Using a kernel smaller than the IFM 140 is intentional as it allows the same kernel (set of weights) to be multiplied by the IFM 140 multiple times at different points on the IFM 140. Specifically, the kernel is applied systematically to each overlapping part or kernel-sized patch of the IFM 140, left to right, top to bottom. The result from multiplying the kernel with the IFM 140 one time is a single value. As the kernel is applied multiple times to the IFM 140, the multiplication result is a 2D matrix of output elements. As such, the 2D output matrix (i.e., the OFM 160) from the standard convolution 163 is referred to as an OFM.

[0048] In the depthwise convolution 183, the input channels are not combined. Rather, MAC operations are performed on an individual input channel and an individual kernel and produce an output channel. As shown in FIG. 1, the depthwise convolution 183 produces a depthwise output tensor 180. The depthwise output tensor 180 is represented by a 5×5×3 3D matrix. The depthwise output tensor 180 includes 3 output channels, each of which is represented by a 5×5 2D matrix. The 5×5 2D matrix includes 5 output elements in each row and 5 output elements in each column. Each output channel is a result of MAC operations of an input channel of the IFM 140 and a kernel of the filter 150. For instance, the first output channel (patterned with dots) is a result of MAC operations of the first input channel (patterned with dots) and the first kernel (patterned with dots) , the second output channel (patterned with horizontal strips) is a result of MAC operations of the second input channel (patterned with horizontal strips) and the second kernel (patterned with horizontal strips) , and the third output channel (patterned with diagonal stripes) is a result of MAC operations of the third input channel (patterned with diagonal stripes) and the third kernel (patterned with diagonal stripes) . In such a depthwise convolution, the number of input channels equals the number of output channels, and each output channel corresponds to a different input channel. The input channels and output channels are referred to collectively as depthwise channels. After the depthwise convolution, a pointwise convolution 193 is then performed on the depthwise output tensor 180 and a 1×1×3 tensor 190 to produce the OFM 160.

[0049] The OFM 160 is then passed to the next layer in the sequence. In some embodiments, the OFM 160 is passed through an activation function. An example activation  function is rectified linear unit (ReLU) . ReLU is a calculation that returns the value provided as input directly, or the value zero if the input is zero or less. The convolutional layer 110 may receive several images as input and calculate the convolution of each of them with each of the kernels. This process can be repeated several times. For instance, the OFM 160 is passed to the subsequent convolutional layer 110 (i.e., the convolutional layer 110 following the convolutional layer 110 generating the OFM 160 in the sequence) . The subsequent convolutional layers 110 perform a convolution on the OFM 160 with new kernels and generate a new feature map. The new feature map may also be normalized and resized. The new feature map can be kernelled again by a further subsequent convolutional layer 110, and so on.

[0050] In some embodiments, a convolutional layer 110 has four hyperparameters: the number of kernels, the size F kernels (e.g., a kernel is of dimensions F×F×D pixels) , the S step with which the window corresponding to the kernel is dragged on the image (e.g., a step of one means moving the window one pixel at a time) , and the zero-padding P (e.g., adding a black contour of P pixels thickness to the input image of the convolutional layer 110) . The convolutional layers 110 may perform various types of convolutions, such as 2-dimensional convolution, dilated or atrous convolution, spatial separable convolution, depthwise separable convolution, transposed convolution, and so on. The DNN 100 includes 16 convolutional layers 110. In other embodiments, the DNN 100 may include a different number of convolutional layers.

[0051] The pooling layers 120 down-sample feature maps generated by the convolutional layers, e.g., by summarizing the presence of features in the patches of the feature maps. A pooling layer 120 is placed between two convolution layers 110: a preceding convolutional layer 110 (the convolution layer 110 preceding the pooling layer 120 in the sequence of layers) and a subsequent convolutional layer 110 (the convolution layer 110 subsequent to the pooling layer 120 in the sequence of layers) . In some embodiments, a pooling layer 120 is added after a convolutional layer 110, e.g., after an activation function (e.g., ReLU, etc. ) has been applied to the OFM 160.

[0052] A pooling layer 120 receives feature maps generated by the preceding convolution layer 110 and applies a pooling operation to the feature maps. The pooling operation reduces the size of the feature maps while preserving their important characteristics.  Accordingly, the pooling operation improves the efficiency of the DNN and avoids over-learning. The pooling layers 120 may perform the pooling operation through average pooling (calculating the average value for each patch on the feature map) , max pooling (calculating the maximum value for each patch of the feature map) , or a combination of both. The size of the pooling operation is smaller than the size of the feature maps. In various embodiments, the pooling operation is 2×2 pixels applied with a stride of two pixels, so that the pooling operation reduces the size of a feature map by a factor of 2, e.g., the number of pixels or values in the feature map is reduced to one quarter the size. In an example, a pooling layer 120 applied to a feature map of 6×6 results in an output pooled feature map of 3×3. The output of the pooling layer 120 is inputted into the subsequent convolution layer 110 for further feature extraction. In some embodiments, the pooling layer 120 operates upon each feature map separately to create a new set of the same number of pooled feature maps.

[0053] The fully-connected layers 130 are the last layers of the DNN. The fully-connected layers 130 may also be referred to as linear layers. The fully-connected layers 130 may be convolutional or not. In some embodiments, a fully-connected layer 130 (e.g., the first fully-connected layer in the DNN 100) may receive an input operand. The input operand may define the output of the convolutional layers 110 and pooling layers 120 and includes the values of the last feature map generated by the last pooling layer 120 in the sequence. The fully-connected layer 130 may apply a linear transformation to the input operand through a weight matrix. The weight matrix may be a kernel of the fully-connected layer 130. The linear transformation may include a tensor multiplication between the input operand and the weight matrix. The result of the linear transformation may be an output operand. In some embodiments, the fully-connected layer may further apply a nonlinear transformation (e.g., by using a nonlinear activation function) on the result of the linear transformation to generate an output operand. The output operand may contain as many elements as there are classes: element i represents the probability that the image belongs to class i. Each element is therefore between 0 and 1, and the sum of all is worth one. These probabilities are calculated by the last fully-connected layer 130 by using a logistic function (binary classification) or a SoftMax function (multi-class classification) as an activation function.

[0054] In some embodiments, the fully-connected layers 130 classify the input image 105 and return an operand of size N, where N is the number of classes in the image classification  problem. In the embodiments of FIG. 1, N equals 3, as there are 3 objects 115, 125, and 135 in the input image. Each element of the operand indicates the probability for the input image 105 to belong to a class. To calculate the probabilities, the fully-connected layers 130 multiply each input element by weight, make the sum, and then apply an activation function (e.g., logistic if N=2, SoftMax if N>2) . This is equivalent to multiplying the input operand by the matrix containing the weights. In an example, the vector includes 3 probabilities: a first probability indicating the object 115 being a tree, a second probability indicating the object 125 being a car, and a third probability indicating the object 135 being a person. In other embodiments where the input image 105 includes different objects or a different number of objects, the individual values can be different.

[0055] Example Convolution

[0056] FIG. 2 illustrates an example convolution, in accordance with various embodiments. The convolution may be a deep learning operation in a convolutional layer of a DNN, e.g., a convolutional layer 110 in FIG. 1. The convolution can be executed on an input tensor 210 and filters 220 (individually referred to as “filter 220” ) . The result of the convolution is an output tensor 230. In some embodiments, the convolution is performed by a DNN accelerator. An example of the DNN accelerator may be the DNN accelerator 302 in FIG. 3.

[0057] In the embodiments of FIG. 2, the input tensor 210 includes activations (also referred to as “input activations, ” “elements, ” or “input elements” ) arranged in a 3D matrix. An input element is a data point in the input tensor 210. The input tensor 210 has a spatial size Hin×Win×Cin, where Hin is the height of the 3D matrix (i.e., the length along the Y axis, which indicates the number of activations in a column in the 3D matrix of each input channel) , Winis the width of the 3D matrix (i.e., the length along the X axis, which indicates the number of activations in a row in the 2D matrix of each input channel) , and Cin is the depth of the 3D matrix (i.e., the length along the Z axis, which indicates the number of input channels) . For the purpose of simplicity and illustration, the input tensor 210 has a spatial size of 7×7×3, i.e., the input tensor 210 includes three input channels and each input channel has a 7×7 2D matrix. Each input element in the input tensor 210 may be represented by a (X, Y, Z) coordinate. In other embodiments, the height, width, or depth of the input tensor 210 may be different.

[0058] Each filter 220 includes weights arranged in a 3D matrix. The values of the weights  may be determined through training the DNN. A filter 220 has a spatial size Hf×Wf×Cf, where Hf is the height of the filter (i.e., the length along the Y axis, which indicates the number of weights in a column in each kernel) , Wf is the width of the filter (i.e., the length along the X axis, which indicates the number of weights in a row in each kernel) , and Cf is the depth of the filter (i.e., the length along the Z axis, which indicates the number of channels) . In some embodiments, Cf equals Cin. For purpose of simplicity and illustration, each filter 220 in FIG. 2 has a spatial size of 2×3×3, i.e., the filter 220 includes 2 convolutional kernels with a spatial size of 2×3. In other embodiments, the height, width, or depth of the filter 220 may be different. The spatial size of the convolutional kernels is smaller than the spatial size of the 2D matrix of each input channel in the input tensor 210.

[0059] An activation or weight may take one or more bytes in a memory. The number of bytes for an activation or weight may depend on the data format. For example, when the activation or weight has an INT8 format, the activation takes one byte. When the activation or weight has a FP16 format, the activation or weight takes two bytes. Other data formats may be used for activations or weights.

[0060] In the convolution, each filter 220 slides across the input tensor 210 and generates a 2D matrix for an output channel in the output tensor 230. In the embodiments of FIG. 2, the 2D matrix has a spatial size of 5×5. The output tensor 230 includes activations (also referred to as “output activations, ” “elements, ” or “output element” ) arranged in a 3D matrix. An output activation is a data point in the output tensor 230. The output tensor 230 has a spatial size Hout×Wout×Cout, where Hout is the height of the 3D matrix (i.e., the length along the Y axis, which indicates the number of output activations in a column in the 2D matrix of each output channel) , Wout is the width of the 3D matrix (i.e., the length along the X axis, which indicates the number of output activations in a row in the 2D matrix of each output channel) , and Cout is the depth of the 3D matrix (i.e., the length along the Z axis, which indicates the number of output channels) . Cout may equal the number of filters 220 in the convolution. Hout and Wout may depend on the heights and weights of the input tensor 210 and each filter 220.

[0061] As a part of the convolution, MAC operations can be performed on a 2×3×3 subtensor 215 (which is highlighted with a dotted pattern in FIG. 2) in the input tensor 210 and each filter 220. The result of the MAC operations on the subtensor 215 and one filter  220 is an output activation. In some embodiments (e.g., embodiments where the convolution is an integral convolution) , an output activation may include 8 bits, e.g., one byte. In other embodiments (e.g., embodiments where the convolution is a floating-point convolution) , an output activation may include more than one byte. For instance, an output element may include two bytes.

[0062] After the MAC operations on the subtensor 215 and all the filters 220 are finished, a vector 235 is produced. The vector 235 is highlighted with slashes in FIG. 2. The vector 235 includes a sequence of output activations, which are arranged along the Z axis. The output activations in the vector 235 have the same (X, Y) coordinate, but the output activations correspond to different output channels and have different Z coordinates. The dimension of the vector 235 along the Z axis may equal the total number of output channels in the output tensor 230. After the vector 235 is produced, further MAC operations are performed to produce additional vectors till the output tensor 230 is produced.

[0063] In some embodiments, the MAC operations on a 2×3×3 subtensor (e.g., the subtensor 215) and a filter 220 may be performed by a plurality of MAC units. One or more MAC units may receive an input operand (e.g., an input operand 217 shown in FIG. 2) and a weight operand (e.g., the weight operand 227 shown in FIG. 2) . The input operand 217 includes a sequence of activations having the same (X, Y) coordinate but different z coordinates. The input operand 217 includes an activation from each of the input channels in the input tensor 210. The weight operand 227 includes a sequence of weights having the same (X, Y) coordinate but different z coordinates. The weight operand 227 includes a weight from each of the channels in the filter 220. Activations in the input operand 217 and weights in the weight operand 227 may be sequentially fed into a MAC unit. The MAC unit may receive an activation and a weight ( “an activation-weight pair” ) at a time and multiple the activation and the weight. The position of the activation in the input operand 217 may match the position of the weight in the weight operand 227. The activation and weight may correspond to the same channel.

[0064] Activations or weights may be floating-point numbers. Floating-point numbers may have various data formats, such as FP32, FP16, BF16, and so on. A floating-point number may be a positive or negative number with a decimal point. A floating-point number may be represented by a sequence of bits that includes one or more bits representing the sign of the  floating-point number (e.g., positive or negative) , bits representing an exponent of the floating-point number, and bits representing a mantissa of the floating-point number. The mantissa is the part of a floating-point number that represents the significant digits of that number. The mantissa is multiplied by the base raised to the exponent to give the actual value of the floating-point number.

[0065] In some embodiments, the output activations in the output tensor 230 may be further processed based on one or more activation functions before they are stored or inputted into the next layer of the DNN. The processing based on the one or more activation functions may be at least part of the post processing of the convolution. In some embodiments, the post processing may include one or more other computations, such as offset computation, bias computation, and so on. The results of the post processing may be stored in a local memory of the compute block and be used as input to the next DNN layer. In some embodiments, the input activations in the input tensor 210 may be results of post processing of the previous DNN layer.

[0066] Example DNN System

[0067] FIG. 3 is a block diagram of a DNN system 300, in accordance with various embodiments. The whole DNN system 300 or a part of the DNN system 300 may be implemented in one or more computing devices, such as the computing device 1900 in FIG. 19. The DNN system 300 can generate and execute DNNs, such as the DNN 100 in FIG. 1. As shown in FIG. 3, the DNN system 300 includes a DNN module 301 and a DNN accelerator 302. In other embodiments, alternative configurations, different or additional components may be included in the DNN system 300. For instance, the DNN system 300 may include multiple DNN modules or multiple DNN accelerators. Further, functionality attributed to a component of the DNN system 300 may be accomplished by a different component included in the DNN system 300 or a different system. In some embodiments, the DNN module 301 and DNN accelerator 302 may include different types of processing units. The DNN module 301 and DNN accelerator 302 may be implemented in the same chip or separate chips.

[0068] The DNN module 301 facilitates generation and deployment of DNNs. In some embodiments, the DNN module 301 may generate and train DNNs. For instance, the DNN module 301 can define the layered architecture of a DNN. The DNN module 301 can also determine the internal parameters of the DNN through a DNN training process. The DNN  module 301 may also determine one or more hyperparameters that define how the DNN is trained. An example hyperparameter is a sparsity ratio that defines the sparsity level of one or more deep learning tensors for the DNN. The DNN module 301 may also compress DNNs, e.g., during or after training. In some embodiments, the DNN module 301 may prune weights in one or more layers of a DNN by changing nonzero valued weight to zeros. The DNN module 301 may prune weights based on a target weight sparsity ratio. A weight sparsity ratio may be the ratio of the number of zero-valued weights to the total number of weights. In an example where the DNN module 301 prunes weight during DNN training, the DNN module 301 may prune weight of a layer to achieve a target sparsity ratio after one or more epochs. The DNN module 301 may prevent the pruned weights from changing values during the rest of the training process. Alternatively, the DNN module 301 may allow the pruned weights to change values so that a pruned, zero-valued weight may have a nonzero value after further training. The DNN module 301 may prune weights of the layer again after one or more additional epochs.

[0069] The DNN module 301 may deploy trained, compressed, or validated DNNs for use in deep learning applications. The DNN module 301 may control execution processes of trained, compressed, or validated DNNs. For instance, the DNN module 301 may configure one or more sparsity modes of the DNN accelerator 302 that performs execution of a DNN. In some embodiments, the DNN module 301 may determine sparsity modes of the DNN accelerator 302 on a layer-basis. For instance, the DNN module 301 may determine whether to activate weight sparsity-based acceleration for a DNN layer based on the weight tensor of the DNN layer or not. The DNN module 301 may generate a configuration parameter, the value of which indicates the determination. The DNN module 301 may provide the configuration parameter to the DNN accelerator 302. The DNN accelerator 302 may execute the DNN layer in accordance with the configuration parameter. The DNN module 301 may determine to activate weight sparsity-based acceleration for one layer in a DNN but determine not to activate weight sparsity-based acceleration for another layer in the DNN.

[0070] In some embodiments, the DNN module 301 may distribute trained, compressed, or validated DNNs to devices or systems which may use the DNNs to perform tasks (e.g., image classification, motion planning, etc. ) for which the DNNs were trained. In other embodiments, the DNN module 301 may facilitate deployment of the DNNs using the DNN  accelerator 302. For instance, the DNN module 301 may receive data from a device or system coupled with the DNN system 300 and input the received data (or data generated by the DNN module 301, e.g., based on the received data) into a DNN. The DNN module 301 may generate instructions (e.g., configuration files) that control the operation of the DNN accelerator 302 during the DNN execution. The DNN module 301 may receive an output of the DNN from the DNN accelerator 302. The DNN module 301 may transmit the output of the DNN (or a result of processing the output of the DNN by the DNN module 301) to the device or system.

[0071] In some embodiments, the DNN module 301 facilitates memory reuse and optimized memory utilization during execution of DNNs. The memory may be a local memory 340 in the DNN accelerator 302. For example, the DNN module 301 may facilitate in-place execution of deep learning operations. The DNN module 301 may determine a memory offset size for in-place execution of a deep learning operation, during which one or more memory entries storing input elements may be reused for storing output elements. A memory entry may be used to store a single data element at a time. The memory space for storing the output tensor of the deep learning operation may have an offset from the memory space storing the input tensor deep learning operation to avoid data corruption. The memory offset size may indicate the total number of memory entries are in the offset. The memory offset size may be used by the drain module 380 to load output elements into the local memory 340.

[0072] The DNN module 301 may also facilitate the DNN accelerator 302 to write an output tensor of a deep learning operation across multiple memory fragments. In some embodiments, the DNN module 301 generates a data structure that can be used by the DNN accelerator 302 (e.g., by the drain module 380) to write data into the local memory 340 in a scattered matter. The data structure is referred to as a scatter map or data write map. A scatter map may include data that indicates locations of free memory entries in the local memory 340. The free entries may be distributed in multiple memory fragments. These memory fragments are referred to as free memory fragments. Two adjacent free memory fragments may be separated by an allocated memory fragment, i.e., a memory fragment with allocated memory entries. The drain module 380 may use the scatter map to write output elements of the same output tensor into the local memory 340 so that different  portions of the output tensor may be separated by other data in the local memory 340. Compared with storing the output tensor in continuous memory entries, the scatter write mechanism can provide better utilization of the local memory 340. Certain aspects of the DNN module 301 are provided below in conjunction with FIG. 4.

[0073] The DNN accelerator 302 executes DNNs provided by the DNN module 301. For instance, the DNN accelerator 302 can perform DNN execution, e.g., by running deep learning operations in the DNNs, for training DNNs or for using the trained / compressed / validated DNNs to perform tasks. As shown in FIG. 3, the DNN accelerator 302 includes a memory 310, a DMA (direct memory access) engine 320, and compute blocks 330 (individually referred to as “compute block 330” ) . In other embodiments, alternative configurations, different or additional components may be included in the DNN accelerator 302. For example, the DNN accelerator 302 may include more than one memory 310 or DMA engine 320. As another example, the DNN accelerator 302 may include a single compute block 330. Further, functionality attributed to a component of the DNN accelerator 302 may be accomplished by a different component included in the DNN accelerator 302 or by a different system. A component of the DNN accelerator 302 may be implemented in hardware, software, firmware, or some combination thereof.

[0074] The memory 310 stores data associated with deep learning operations performed by the DNN accelerator. In some embodiments, the memory 310 may store data to be used by the compute blocks 330 for DNN execution. For example, the memory 310 may store weights, such as weights of convolutional layers, which are determined by training DNNs. As another example, the memory 310 may store inputs to DNNs or outputs of DNNs. The memory 310 may also store data generated by the compute blocks 330 from performing deep learning operations in DNNs. Example deep learning operations include convolutions (also referred to as “convolutional operations” ) , pooling operations, elementwise operations, activation functions, other types of deep learning operations, or some combination thereof. The memory 310 may be a main memory of the DNN accelerator 302. In some embodiments, the memory 310 includes one or more DRAMs.

[0075] The DMA engine 320 facilitates data transfer between the memory 310 and local memories of the compute blocks 330. For example, the DMA engine 320 can read data from  the memory 310 and write data into a local memory of a compute block 330. As another example, the DMA engine 320 can read data from a local memory of a compute block 330and write data into the memory 310. The DMA engine 320 provides a DMA feature that allows the compute block 330 to initiate data transfer between the memory 310 and the local memories of the compute blocks 330 and to perform other operations while the data transfer is in being conducted. In some embodiments, the DMA engine 320 may read tensors from the memory 310, modify the tensors in a way that is optimized for the compute block 330 before it writes the tensors into the local memories of the compute blocks 330.

[0076] The compute blocks 330 can perform deep learning operations in DNNs. For instance, a compute block 330 may execute a DNN layer by running one or more deep learning operations in the DNN layer. A compute block 330 may execute a layer, or a portion of a layer, at a time. The compute blocks 330 may be capable of running various types of deep learning operations, such as convolution, pooling, elementwise operation, linear operation, nonlinear operation, and so on. In an example, a compute block 330 may perform convolutions, e.g., standard convolution or depthwise convolution. In some embodiments, the compute block 330 receives an input tensor and one or more convolutional kernels and performs a convolution with the input tensor and convolutional kernels. The result of the convolution may be an output tensor, which can be further computed, e.g., by the compute block 330 or another compute block 330. In some embodiments, the operations of the DNN layers may be run by multiple compute blocks 330 in parallel. For instance, multiple compute blocks 330 may each perform a portion of a workload for a convolution. Data may be shared between the compute blocks 330. A compute block 330 may also be referred to as a compute tile. In some embodiments, each compute block 330 may be a processing unit.

[0077] In the embodiments of FIG. 3, each compute block 330 includes a local memory 340, a sparsity mode module 350, a load module 360, a sparse cell array 370, and a drain module 380. Some or all the components of the compute block 330 can be implemented on the same chip. In other embodiments, alternative configurations, different or additional components may be included in the compute block 330. Further, functionality attributed to a component of the compute block 330 may be accomplished by a different component included in the compute block 330, a different compute block 330, another component of the DNN accelerator 302, or a different system. A component of the compute block 330 may  be implemented in hardware, software, firmware, or some combination thereof.

[0078] The local memory 340 is local to the corresponding compute block 330. In the embodiments of FIG. 3, the local memory 340 is inside the compute block 330. In other embodiments, the local memory 340 may be outside the compute block 330. Data in the local memory 340 may be transferred to or from the memory 310, e.g., through the DMA engine 320. The local memory 340 may be implemented on the same chip as the other components of the compute block 330. The local memory 340 may be an on-chip memory, while the memory 310 may be an off-chip memory that is not implemented on the same chip as the compute block 330. In some embodiments, data in the local memory 340 may be transferred to or from the local memory of another compute block 330. The local memory 340 may store data received, used, or generated by the sparsity mode module 350, the load module 360, the sparse cell array 370, or the drain module 380. Examples of the data may include input elements, weights, output elements, scatter maps, gather maps, sparsity bitmaps, and so on.

[0079] In some embodiments, the local memory 340 may store dense tensors (e.g., dense activation tensors, dense weight tensors, etc. ) , sparse tensors (e.g., sparse activation tensors, sparse weight tensors, etc. ) , and so on. A dense tensor may be a tensor from which zero-valued elements (if any) are not removed. A dense tensor may be converted to a sparse tensor by removing one or more zero-valued elements in the dense tensor. A sparse tensor may also be referred to as a compressed tensor or packed tensor. The process of converting a dense tensor to a sparse tensor may be referred to as sparsity encoding. Sparsity encoding may also generate a sparsity tensor. Each element in the sparsity tensor may correspond to a different element in the dense tensor and indicate whether the element in the dense tensor is zero or not. The sparsity tensor may indicate positions of elements of the sparse tensor in the dense tensor. The sparsity tensor may be a sparsity bitmap, each element of which is a bit. A sparse tensor may be converted to a dense tensor through a densifying process, in which one or more zeros may be added to the sparse tensor based on the sparsity tensor.

[0080] In some embodiments, the local memory 340 includes one or more SRAMs. The local memory 340 may be byte-addressable, and each memory address identifies a single byte (eight bits) of storage. In some embodiments, the local memory 340 may include  memory banks. The number of data banks in the local memory 340 may be 16, 64, 128, 356, 512, 1024, 3048, or other numbers. A memory bank may include a plurality of storage units. In an example, a data bank may include 8, 16, 64, or a different number of storage units. One or more storage units may constitute a memory entry. A memory entry or a storage unit in a memory bank may have a memory address. In an example, a storage unit may store a single byte, and data larger than a single byte may be stored in storage units with consecutive memory addresses, i.e., adjacent storage units. For instance, a storage unit can store an integer number in the INT8 format, versus two storage units may be needed to store a number in the FP16 or BF16 format, which has 16 bits. In some embodiments, 16 bits can be transferred from the local memory 340 in a single read cycle. In other embodiments, 16 bits can be transferred from the local memory 340 in multiple read cycles, such as two cycles.

[0081] The sparsity mode module 350 determines sparsity modes in which the compute block 330 operates to execute DNN layers. For instance, the sparsity mode module 350 may determine whether to accelerate a layer based on weight sparsity or activation sparsity. The sparsity mode module 350 select the sparsity mode for a layer from a group of sparsity modes that includes, for example, combined sparsity mode in which the layer is accelerated based on both weight sparsity and activation sparsity, activation sparsity mode in which the layer is accelerated based on activation sparsity but not based on weight sparsity, weight sparsity mode in which the layer is accelerated based on weight sparsity but not based on activation sparsity, and a dense mode in which the layer is not accelerated based on sparsity. In some embodiments (e.g., embodiments where a layer is executed by multiple compute blocks 330) , the sparsity module 345 may determine the sparsity mode for all the compute blocks 330 that executes the layer.

[0082] To determine a sparsity mode for a layer, the sparsity mode module 350 may estimate energy (e.g., power) consumption of the compute block 330 executing the layer in various sparsity modes. For instance, the sparsity mode module 350 may estimate the energy consumption for executing the layer in the combined sparsity mode, the energy consumption for executing the layer in the weight sparsity mode, the energy consumption for executing the layer in the activation sparsity mode, and the energy consumption for executing the layer in the dense mode. The sparsity mode module 350 may also measure sparsity in the activation tensor of the layer. The activation tensor may be the input tensor  (or part of the input tensor) of the layer. The activation tensor may be computed in the previous layer and may be output from the compute block 330 by the drain module 380. The sparsity mode module 350 may determine the amount of sparsity in the activation tensor using sparsity counters in the drain module 380. The sparsity mode module 350 may further measure combined sparsity of the layer. For instance, the sparsity mode module 350 may measure sparsity in the output tensor of the layer based on the weight tensor and the activation tensor. In some embodiments, the sparsity mode module 350 may receive configuration parameters from the DNN module 301. A configuration parameter may correspond to a layer and indicate whether to accelerate the layer based on weight sparsity. The sparsity mode module 350 may determine the sparsity mode of the layer based on the configuration parameter.

[0083] The load module 360 loads data from the local memory 340 to the sparse cell array 370. The load module 360 may read tensors from the local memory 340. The tensors may include input tensors, weight tensors, sparsity tensors (e.g., sparsity bitmaps) , and so on. The load module 360 is capable of gather data read across multiple memory fragments in the local memory 340. In some embodiments, the load module 360 may receive a gather map and use the gather map to read elements of an output tensor from the local memory 340. The gather map may be generated and written into the local memory 340 by the drain module 380. The gather map may correspond to one or more output elements. For each output element, the gather map may include data indicating the memory address of the memory entry storing the output element. For instance, the gather map may include the start memory address of a memory fragment including the memory entry and a position index of the memory entry. The position index may indicate the position of the memory entry in the memory fragment. The gather map may also include a position index of the output element, which indicates the position of the output element in the output tensor. The position index may be a (X, Y) or (X, Y, Z) coordinate of the output element.

[0084] In some embodiments, the load module 360 may load data based on the sparsity mode determined by the sparsity mode module 350. The load module 360 may select different data to transmit to the sparse cell array 370 in different sparsity modes. For instance, the load module 360 may transmit an activation sparsity tensor and a weight sparsity tensor of a layer to the sparse cell array 370 in the combined sparsity mode, while  transmit the activation sparsity tensor but not the weight sparsity tensor to the sparse cell array 370 in the activation sparsity mode and transmit the weight sparsity tensor but not the activation sparsity tensor to the sparse cell array 370 in the weight sparsity mode. In the dense mode, the load module 360 does not transmit either the activation sparsity tensor or the weight sparsity tensor to the sparse cell array 370.

[0085] In some embodiments, the load module 360 may process (e.g., densify) data stored in the local memory 340 before providing the data to the sparse cell array 370. In an example, the load module 360, while operating in the weight sparsity mode, may densify sparse activation tensors to generate dense activation tensors based on corresponding activation sparsity tensors. For instance, the load module 360 may add one or more zeros into a sparse activation tensor based on an activation sparsity tensor associated with the sparse activation tensor to generate the dense activation tensor. The dense activation tensor includes one or more elements than the sparse activation tensor. The additional element (s) are zero valued. The load module 360 may identify one or more elements in the activation sparsity tensor that correspond to the zero-valued element (s) , determine the position of each of the zero-valued element (s) in the dense activation tensor, and insert the zero-valued element (s) into the sparse activation tensor based on the determined positions. After the densification, the load module 360 may transmit the dense activation tensors to the sparse cell array 370. The load module 360 may also transmit corresponding sparse weight tensors and weight sparsity tensors to the sparse cell array 370. Activation sparsity tensor of the dense activation tensors may not be loaded to the sparse cell array 370.

[0086] In another example, the load module 360, while operating in the activation sparsity mode, may densify sparse weight tensors to generate dense weight tensors based on corresponding weight sparsity tensors by inserting zeros into sparse weight tensors. The densification of sparse weight tensors may be similar to the densification of sparse activation tensors described above. After the densification, the load module 360 may transmit the dense weight tensors to the sparse cell array 370. The load module 360 may also transmit corresponding sparse activation tensors and activation sparsity tensors to the sparse cell array 370. Weight sparsity tensor of the dense weight tensors may not be loaded to the sparse cell array 370. In yet another example, the load module 360, while operating in the dense mode, may densify both sparse weight tensors and sparse activation tensors. The load  module 360 may generate the input tensor and weight tensor of the layer and transmit the tensors to the sparse cell array 370 for executing the layer without sparsity acceleration.

[0087] The sparse cell array 370 may include sparse cells arranged in columns, or columns and rows. Each sparse cell may include an array of MAC units that can perform MAC operations, such as MAC operations in convolution, matrix multiplications, or other types of deep learning operations. In some embodiments (e.g., embodiments where the compute block 330 executes a convolutional layer) , a computation in an MAC unit may be an MAC operation on an activation operand and a weight operand. The activation operand may be an activation tensor that may include one or more activations in the input tensor of the convolution. Different activations may be in different input channels. The weight operand may be a weight tensor that may include one or more weights in the filter of the convolution. The values of the weights are determined through training the DNN. The weights in the weight operand may be in different input channels.

[0088] In some embodiments, an MAC unit includes one or more multipliers for performing multiplications. An MAC unit may also include one or more accumulators ( “adders” ) for performing accumulations. A column of MAC units is referred to as an MAC column. An MAC column may be associated with one or more MAC lanes. An MAC lane is a path for loading data e.g., by the load module 360, into an MAC column. An MAC lane may be also referred to as a data transmission lane or data loading lane. An MAC column may have multiple MAC lanes. The loading bandwidth of the MAC column is an aggregation of the loading bandwidths of all the MAC lanes associated with the MAC column. With a certain number of MAC lanes, data can be fed into the same number of independent PEs simultaneously. In some embodiments where an MAC column has four MAC lanes for feeding activations or weights into the MAC column and each MAC lane may have a bandwidth of 16 bytes, the four MAC lanes can have a total loading bandwidth of 64 bytes.

[0089] In some embodiments, the sparse cell array 370 may be capable of depthwise convolution, standard convolution, or both. In a depthwise convolution, an MAC unit may perform an MAC operation that includes a sequence of multiplications for an input operand and a weight operand. Each multiplication in the sequence (also referred to as a cycle) is a multiplication of a different activation in the input operand with a different weight in the weight operand. The activation and weight in the same cycle may correspond to the same  channel. The sequence of multiplication produces a product operand that includes a sequence of products. The MAC operation may also include accumulations in which multiple product operands are accumulated to produce an output operand of the MAC unit. The sparse cell array 370 may output multiple output operands at a time, each of which is generated by a different MAC unit. In a standard convolution, MAC operations may include accumulations across the channels. For instance, as opposed to generating an output operand, a MAC unit may accumulate products across different channels to generate a single output point.

[0090] In some embodiments, the sparse cell array 370 may perform MAC operations in quantized deep learning operations, such as MAC operations in a quantized convolution. In some embodiments, an MAC unit in the sparse cell array 370 may receive quantized activation and quantized weights and compute a quantized MAC result. The quantized MAC result may be a quantized value in an integer format and may be the output of the PE. In some embodiments, the MAC unit may also include a quantization multiplier that can multiply a quantization scale with the quantized MAC result, and the output of the MAC unit may be a real value in a floating-point format. The MAC unit may include no quantization subtractors as zero-point offsetting is not needed for the MAC operations in quantized deep learning operations.

[0091] In some embodiments, the sparse cell array 370 may include sparsity acceleration logic for facilitating sparsity acceleration. For instance, each sparse cell in the sparse cell array 370 may include one or more sparsity modules. In an example, each MAC column or each MAC row may have a corresponding sparsity module that accelerates MAC operations in the MAC column or MAC row. In some embodiments, a sparsity module accelerates computations in the sparse cell array 370 based on sparsity in activations, sparsity in weights, or both. The sparsity module may include a storage unit that stores a sparsity tensor, which may be loaded to the storage unit by the load module 360. The sparsity tensor may be an activation sparsity tensor, a weight sparsity tensor, or a combined sparsity tensor.

[0092] An activation sparsity tensor may be the sparsity tensor of an activation tensor and has the same number of elements as the activation tensor. An element in the activation sparsity tensor may indicate whether the corresponding element in the activation tensor is zero or not. For instance, a zero-valued in the activation sparsity tensor may indicate that  the corresponding element in the activation tensor is zero. A one-valued in the activation sparsity tensor may indicate that the corresponding element in the activation tensor is nonzero. A weight sparsity tensor may be the sparsity tensor of a weight tensor and has the same number of elements as the weight tensor. An element in the weight sparsity tensor may indicate whether the corresponding element in the weight tensor is zero or not. For instance, a zero-valued in the weight sparsity tensor may indicate that the corresponding element in the weight tensor is zero. A one-valued in the weight sparsity tensor may indicate that the corresponding element in the weight tensor is nonzero. The sparsity module may generate a combined sparsity tensor using an activation sparsity tensor and a weight sparsity tensor. For instance, the sparsity module may multiply an element of the activation sparsity tensor with a corresponding element of the weight sparsity tensor to compute an element of the combined sparsity tensor. The positions of the three elements in their corresponding sparsity tensors may match. In some embodiments, each element in a sparsity tensor may be a bit, and the sparsity tensor may be referred to as a sparsity bitmap.

[0093] The sparsity module may use the sparsity tensor to identify activations and weights to be used in MAC operations by the MAC units. In an embodiment where the sparse cell array 370 operates in the combined sparsity mode, the sparsity module may identify activations and weights that correspond to nonzero valued elements of a combined sparsity tensor. In an embodiment where the sparse cell array 370 operates in the activation sparsity mode, the sparsity module may identify activations and weights that correspond to nonzero valued elements of an activation sparsity tensor. In an embodiment where the sparse cell array 370 operates in the weight sparsity mode, the sparsity module may identify activations and weights that correspond to nonzero valued elements of a weight sparsity tensor. The sparsity module may be bypassed in the dense mode as no sparsity acceleration would be conducted. Certain aspects of the sparse cell array 370 are provided below in conjunction with FIGS. 11 and 12.

[0094] The drain module 380 drains data computed by the sparse cell array 370 and writes the data to the local memory 340. The data may be outputs of MAC operations performed by MAC units in the sparse cell array 370, such as output elements of convolutions, matrix multiplication, or other types of deep learning operations. The drain module 380 is capable of scatter data write across multiple memory fragments in the local memory 340. In some  embodiments, the drain module 380 writes output elements into the local memory 340 with scatter maps.

[0095] In some embodiments, the drain module 380 may drain data on a sparse cell level. For each sparse cell, the drain module 380 may drain outputs of MAC units in the sparse cell based on a row index or column index of each MAC unit. For instance, the drain module 380 may use a sequence of cycles to drain data from a sparse cell. The drain module 380 may drain the output of some of the MAC units in each cycle. The sequence of the cycles may be configured based on a configuration parameter indicating the operation mode of the load module 360.

[0096] In some embodiments, the drain module 380 may determine whether to drain the output of an MAC unit based on the column index of the MAC unit when the load module operates in the activation sparsity mode versus based on the row index of the MAC unit when the load module operates in the weight sparsity mode. For instance, for MAC operations where the load module 360 operates in the activation sparsity mode, the drain module 380 may drain the output of a different MAC column in each cycle. The sequence of cycles may start with the first MAC column (e.g., the MAC column on the left side of the sparse cell) and end with the last MAC column (e.g., the MAC column on the right side of the sparse cell) . For MAC operations where the load module 360 operates in the weight sparsity mode, the drain module 380 may drain the output of a different MAC row in each cycle. The sequence of cycles may start with the first MAC row (e.g., the MAC row at the top of the sparse cell) and end with the last MAC row (e.g., the MAC column at the bottom of the sparse cell) . In other embodiments, the drain module 380 may determine whether to drain the output of an MAC unit based on the row index of the MAC unit when the load module operates in the activation sparsity mode versus based on the column index of the MAC unit when the load module operates in the weight sparsity mode.

[0097] The drain module 380 may also include sparsity encoding logic that can convert outputs of the sparse cell array 370 from a dense format to a sparse format. For instance, the drain module 380 may be implemented with one or more sparse encoders. A sparse encoder converts dense data to compressed data based on sparsity in the dense data. For instance, the sparse encoder may remove zeros in an activation tensor computed by the sparse cell array 370 to convert the activation tensor to a compressed activation tensor. The  sparse encoder may also generate sparsity tensors, including activation sparsity tensors.

[0098] In some embodiments, the data drained from the sparse cell array 370 may be at least part of an output tensor (e.g., the output tensor 230 in FIG. 2) of a deep learning operation. The sparse encoder may generate a compressed version of the output tensor. The sparse encoder may identify every zero-valued activation in the output tensor and remove these activations from the output tensor to generate a compressed activation tensor (aka “sparse activation tensor” ) . The sparse encoder may also generate one or more sparsity tensors for the output tensor. A sparsity tensor may correspond to a portion of the output tensor (e.g., the vector 235 in FIG. 2) . The sparsity tensor may include sparsity elements (e.g., bits) , each of which corresponds to a different activation in the vector and indicates whether the corresponding activation is zeroed or not.

[0099] The drain module 380 may write the compressed activation tensor and the one or more sparsity tensors into the local memory 340. The sparse activation tensor and the one or more sparsity tensors may be further loaded to the memory 310, e.g., through the DMA engine 320. Additionally or alternatively, the sparse activation tensor and the one or more sparsity tensors may be loaded by the load module 360 to the sparse cell array for further computation, e.g., for performing a deep learning operation in the next layer. Certain aspects of the drain module 380 are described below in conjunction with FIG. 13.

[0100] FIG. 4 is a block diagram of a DNN module 400, in accordance with various embodiments. The DNN module 400 may be an embodiment of the DNN module 301 in FIG. 3. As shown in FIG. 4, the DNN module 400 includes an interface module 410, a training module 420, a compressing module 430, a validating module 440, a memory management module 450, and a datastore 460. In other embodiments, alternative configurations, different or additional components may be included in the DNN module 400. Further, functionality attributed to a component of the DNN module 400 may be accomplished by a different component included in the DNN module 400 or a different module or system.

[0101] The interface module 410 facilitates communications of the DNN module 400 with other modules or systems. For example, the interface module 410 establishes communications between the DNN module 400 with an external database to receive data that can be used to train DNNs or input into DNNs to perform tasks. As another example, the interface module 410 supports the DNN module 400 to distribute DNNs to other systems,  e.g., computing devices configured to apply DNNs to perform tasks.

[0102] The training module 420 trains DNNs by using a training dataset. The training module 420 forms the training dataset. In an embodiment where the training module 420 trains an DNN to recognize objects in images, the training dataset includes training images and training labels. The training labels describe ground-truth classifications of objects in the training images. In some embodiments, each label in the training dataset corresponds to an object in a training image. In some embodiments, a part of the training dataset may be used to initially train the DNN, and the rest of the training dataset may be held back as a validation subset used by the validating module 440 to validate performance of a trained DNN. The portion of the training dataset not including the tuning subset and the validation subset may be used to train the DNN.

[0103] The training module 420 also determines hyperparameters for training the DNN. Hyperparameters are variables specifying the DNN training process. Hyperparameters are different from parameters inside the DNN (e.g., weights of filters) . In some embodiments, hyperparameters include variables determining the architecture of the DNN, such as number of hidden layers, etc. Hyperparameters also include variables which determine how the DNN is trained, such as batch size, number of epochs, etc. A batch size defines the number of training samples to work through before updating the parameters of the DNN. The batch size is the same as or smaller than the number of samples in the training dataset. The training dataset can be divided into one or more batches. The number of epochs defines how many times the entire training dataset is passed forward and backwards through the entire network. The number of epochs defines the number of times that the deep learning algorithm works through the entire training dataset. One epoch means that each training sample in the training dataset has had an opportunity to update the parameters inside the DNN. An epoch may include one or more batches. The number of epochs may be 1, 5, 10, 50, 100, 500, 1000, or even larger.

[0104] The training module 420 defines the architecture of the DNN, e.g., based on some of the hyperparameters. The architecture of the DNN includes an input layer, an output layer, and a plurality of hidden layers. The input layer of an DNN may include tensors (e.g., a multidimensional array) specifying attributes of the input image, such as the height of the input image, the width of the input image, and the depth of the input image (e.g., the  number of bits specifying the color of a pixel in the input image) . The output layer includes labels of objects in the input layer. The hidden layers are layers between the input layer and output layer. The hidden layers include one or more convolutional layers and one or more other types of layers, such as pooling layers, fully-connected layers, normalization layers, SoftMax or logistic layers, and so on. The convolutional layers of the DNN abstract the input image to a feature map that is represented by a tensor specifying the feature map height, the feature map width, and the feature map channels (e.g., red, green, blue images include 3 channels) . A pooling layer is used to reduce the spatial volume of input image after convolution. It is used between two convolution layers. A fully-connected layer involves weights, biases, and neurons. It connects neurons in one layer to neurons in another layer. It is used to classify images between different categories by training.

[0105] In the process of defining the architecture of the DNN, the training module 420 also adds an activation function to a hidden layer or the output layer. An activation function of a layer transforms the weighted sum of the input of the layer to an output of the layer. The activation function may be, for example, a ReLU activation function, a tangent activation function, or other types of activation functions.

[0106] After the training module 420 defines the architecture of the DNN, the training module 420 inputs a training dataset into the DNN. The training dataset includes a plurality of training samples. An example of a training sample includes an object in an image and a ground-truth label of the object. The training module 420 modifies the parameters inside the DNN ( “internal parameters of the DNN” ) to minimize the error between labels of the training objects that are generated by the DNN and the ground-truth labels of the objects. The internal parameters include weights of filters in the convolutional layers of the DNN. In some embodiments, the training module 420 uses a cost function to minimize the error.

[0107] The training module 420 may train the DNN for a predetermined number of epochs. The number of epochs is a hyperparameter that defines the number of times that the deep learning algorithm will work through the entire training dataset. One epoch means that each sample in the training dataset has had an opportunity to update internal parameters of the DNN. After the training module 420 finishes the predetermined number of epochs, the training module 420 may stop updating the parameters in the DNN. The DNN having the updated parameters is referred to as a trained DNN.

[0108] The compressing module 430 compresses DNNs. For instance, the compressing module 430 may add pruning operations to DNN layers to reduce computational complexity or memory usage. A pruning operation may prune weight tensors of a DNN layer by changing one or more nonzero valued weights of the layer to zeros. The modification may be done before, during, or after training. Weights may be pruned during training, during inference, or a combination of both. The compressing module 430 may determine a sparsity ratio for a DNN layer. The sparsity ratio may be a ratio of the number of zero-valued weight to the total number of weights in the layer. The compressing module 430 may perform the pruning operation till the sparsity ratio of the DNN layer meets a target sparsity ration, such as 10%, 20%, 30%, 40%, 50%, and so on.

[0109] In some embodiments, the compressing module 430 may select one or more layers in a DNN and modify each selected layer with a pruning operation. For instance, the compressing module 430 may select computationally complex layers, such as layers with large filters. For a pruning operation of a layer or of a type of layer, the compressing module 430 may determine a weight threshold that would not cause a loss of the accuracy of the DNN to exceed an accuracy loss constraint. A pruning operation may modify weights having absolute values above the weight threshold to zeros and leave the other weights unchanged. The weight pruning can reduce memory storage as zero-valued weights may not be stored. Also, the number of operations in the layer can be reduced as computations on zero-valued weights can be skipped without impacting the output of the layer. In some embodiments, the compressing module 430 may also measure energy saving, final DNN accuracy, or layer-wise sparsity caused by pruning operations.

[0110] After compressing a DNN, the compressing module 430 may fine tune the DNN, e.g., through a retraining process. The compressing module 430 may fine tunes DNNs after weights are pruned. In some embodiments, the fine-tuning process is a retraining or further training process. For instance, after weights in a DNN are pruned, the compressing module 430 may further train the DNN by inputting a training dataset into the DNN. The values of the unpruned weights in the DNN may be modified based on outputs of the DNN and ground-truth labels of the training samples in the training dataset. In some embodiments, the values of the pruned weights (i.e., zero) are not changed during the fine-tuning process. For instance, the compressing module 430 may place a mask over a pruned weight block and  the mask can prevent values in the pruned weight blocks from being changed during the fine-tuning process. In other embodiments, the values of all weights, including the pruned weights, may be changed during the fine-tuning process. After one or more cycles of retraining and weight changing by the compressing module 430, the compressing module 430 may perform a new pruning process, e.g., by selecting weight blocks and pruning the selected weight blocks. In some embodiments, the weight pruning process may be repeated multiple times before the fine-tuning process is done.

[0111] In some embodiments, the number of epochs in the fine-tuning process may be different from the number of epochs in the training process in which the pre-pruning values of the weights are determined. For instance, the fine-tuning process may have less epochs than the training process. In an example, the number of epochs in the fine-tuning process may be relatively small, such as 2, 3, 4, 5, and so on.

[0112] The validating module 440 verifies accuracy of trained or compressed DNNs. In some embodiments, the validating module 440 inputs samples in a validation dataset into a trained DNN and uses the outputs of the DNN to determine the model accuracy. In some embodiments, a validation dataset may be formed of some or all the samples in the training dataset. Additionally or alternatively, the validation dataset includes additional samples, other than those in the training sets. In some embodiments, the validating module 440 may determine an accuracy score measuring the precision, recall, or a combination of precision and recall of the DNN. The validating module 440 may use the following metrics to determine the accuracy score: Precision = TP  /  (TP + FP) and Recall = TP  /  (TP + FN) , where precision may be how many the DNN correctly predicted (TP or true positives) out of the total it predicted (TP + FP or false positives) , and recall may be how many the DNN correctly predicted (TP) out of the total number of objects that did have the property in question (TP +FN or false negatives) . The F-score (F-score = 2 *PR  /  (P + R) ) unifies precision and recall into a single measure.

[0113] The validating module 440 may compare the accuracy score with a threshold score. In an example where the validating module 440 determines that the accuracy score of the DNN is less than the threshold score, the validating module 440 instructs the training module 420 to re-train the DNN. In one embodiment, the training module 420 may iteratively re-train the DNN until the occurrence of a stopping condition, such as the  accuracy measurement indication that the DNN may be sufficiently accurate, or a number of training rounds having taken place.

[0114] The memory management module 450 may facilitate in-place execution of deep learning operations. In some embodiments, the memory management module 450 may determine a memory offset size for a deep learning operation. The deep learning operation may include MAC operations on an input tensor and another tensor, such as a weight tensor. During the execution of the deep learning operation, output elements may be stored in memory entries used for storing input elements. A memory entry may be used to store a single data element at a time. In an example, a memory entry may have a storage size of one or more bytes. In another example, a memory entry may have a storage size that is smaller than one byte. The memory space for storing the output tensor may have an offset from the memory space storing the input tensor to avoid data corruption. The offset may include one or more memory entries that are reserved for storing the first output element (s) in the output tensor. Each reserved memory entry may be a free memory entry, i.e., a memory entry that stores no data and is available for storing new data. The memory offset size may indicate how many memory entries are in the offset.

[0115] In some embodiments, the memory management module 450 may determine memory offset sizes for all deep learning operations that can be executed in place. The memory management module 450 may determine a memory offset size for a deep learning operation before the execution of the deep learning operation is started, or even before the execution of the entire DNN is started. For instance, the memory management module 450 may determine memory offset sizes offline. The memory offset sizes for different deep learning operations can be different. The larger the memory offset size, the smaller the overlap between the memory space of the input tensor and the memory space of the output tensor. The memory management module 450 may use one or more attributes of a deep learning operation to determine the memory offset size. Examples of the attributes include one or more dimensions (e.g., length, width, or depth) of the input tensor, the shape of the input tensor, one or more dimensions of the weight tensor, the shape of the weight tensor, one or more dimensions of the output tensor, the shape of the output tensor, the number of compute blocks 330 to be used for executing the deep learning operations, other attributes, or some combination thereof. The memory management module 450 may ensure that the  memory offset size is large enough to avoid data corruption, e.g., to avoid removal of an input element from the memory entry before all MAC operations using the input element are complete.

[0116] The memory management module 450 may also facilitate scatter write across multiple memory fragments. In some embodiments, the memory management module 450 generates scatter maps that can be used by the DNN accelerator 302 (e.g., by the drain module 380) to write data into the local memory 340. A scatter map may include data that indicate memory addresses of free memory entries in the local memory 340. The scatter map may be used by the drain module 380 to write output elements into the local memory 340. In an embodiment, the memory management module 450 may identify free memory fragments in the local memory 340. A free memory fragment includes one or more memory entries that are free, i.e., memory entries that do not store any data at the time and are available to store new data. Free memory fragments may be separated by allocated memory fragments. An allocated memory fragment includes one or more memory entries that are allocated with data, i.e., the memory entries store data at the time.

[0117] The memory management module 450 may generate one or more scatter maps for the local memory 340. A scatter map may indicate addresses of all the free memory entries in the local memory 340 or in a portion of the local memory 340. As the status of the local memory 340 changes (e.g., one or more allocated memory entries become free, one or more free memory entries become allocated, etc. ) , the memory management module 450 may generate one or more new scatter maps based on the changed status of the local memory 340. In some embodiments, the memory management module 450 may generate scatter maps for all deep learning operations. The memory management module 450 may generate a scatter map for a deep learning operation before the execution of the deep learning operation is started, or even before the execution of the entire DNN is started. For instance, the memory management module 450 may generate scatter maps offline. The memory management module 450 may estimate which memory entries in the local memory 340 are allocated (e.g., allocated for storing the input tensor, weight tensor, sparsity tensor, etc. ) before the output tensor is computed. Based on the estimation, the memory management module 450 may identify the free memory fragments in the local memory 340 and generate the scatter map based on the identification. Scatter maps generated by the memory  management module 450 may be stored in the local memory 340 from which the drain module 380 may retrieve the scatter maps.

[0118] The datastore 460 stores data received, generated, used, or otherwise associated with the DNN module 400. For example, the datastore 460 stores the datasets used by the training module 420 and validating module 440. The datastore 460 may also store data generated by the training module 420 and validating module 440, such as the hyperparameters for training DNNs, internal parameters of trained DNNs (e.g., weights, etc. ) , data for sparsity acceleration (e.g., sparsity bitmap, etc. ) , and so on. The datastore 460 may store configuration parameters generated by the memory management module 450. In the embodiment of FIG. 4, the datastore 460 is a component of the DNN module 400. In other embodiments, the datastore 460 may be external to the DNN module 400 and communicate with the DNN module 400 through a network.

[0119] Example In-place Execution of Deep Learning Operations

[0120] FIG. 5 illustrates an input tensor 510 and an output tensor 520 of a deep learning operation executed in place, in accordance with various embodiments. An example of the input tensor 510 may be the input tensor 210 in FIG. 2. An example of the output tensor 520 may be the output tensor 230 in FIG. 2. The input tensor 510 and output tensor 520 may be stored in a memory, an example of which is the local memory 340 in FIG. 3. As shown in FIG. 5, the input tensor 510 and the output tensor 520 have an overlap 530. The overlap 530 represents a memory space that is used to store input elements in the input tensor 510 before the computation of the output tensor 520 and is reused to store output elements in the output tensor 520 when or after the output tensor 520 is computed. The memory space may include one or more memory entries. The reuse of the memory space represented by the overlap 530 can increase efficiency and utilization of the memory and reduce the requirement on the storage capacity of the memory for executing the deep learning operation.

[0121] FIG. 5 also shows an offset 540. The offset 540 represents a memory space that is used to store output elements in the output tensor 520 but is not used to store any input elements in the input tensor 510. In an example, the output elements stored in the memory space represented by the offset 540 may be arranged in the beginning of the output tensor 520, e.g., the output elements are the first N elements of the output tensor 520, where N is  an integer. In another example, the output elements stored in the memory space represented by the offset 540 may be computed before the other output elements of the output tensor 520. The memory space represented by the offset 540 may include one or more memory entries. The size of the memory space represented by the offset 540, which may equal the number of memory entries in the memory space, may be the memory offset size of the deep learning operation.

[0122] FIG. 6 illustrates an example matrix multiplication operation, in accordance with various embodiments. The matrix multiplication operation is performed on a tensor 610 and a tensor 620 and generates a tensor 630. For the purpose of illustration and simplicity, the tensors 610, 620, and 630 are 2D tensors. In the embodiments of FIG. 6, the tensor 610 is a 3×4 matrix, the tensor 620 is a 4×2 matrix, and the tensor 630 is a 3×2 matrix. In other embodiments, the tensor 610, 620, or 630 may have a different number of dimensions, a different size, or a different shape.

[0123] Each output element in the tensor 630 may be a dot product of a subtensor (e.g., a vector) in the tensor 610 and a subtensor (e.g., a vector) in the tensor 620. For instance, c0 may be a dot product of a vector [a0, a1, a2, a3] and a vector [b0, b2, b4, b6] ; c1 may be a dot product of a vector [a0, a1, a2, a3] and a vector [b1, b3, b5, b7] ; c2 may be a dot product of a vector [a4, a5, a6, a7] and a vector [b0, b2, b4, b6] ; c3 may be a dot product of a vector [a4, a5, a6, a7] and a vector [b1, b3, b5, b7] ; c4 may be a dot product of a vector [a8, a9, a10, a11] and a vector [b0, b2, b4, b6] ; and c5 may be a dot product of a vector [a8, a9, a10, a11] and a vector [b1, b3, b5, b7] . The matrix multiplication operation may be at least part of a deep learning operation that can be executed in place to reuse memory spaces.

[0124] FIG. 7 illustrates output data elements overwriting input data elements during in-place execution of the matrix multiplication operation in FIG. 6, in accordance with various embodiments. For the purpose of illustration, FIG. 7 shows three memory layouts 710, 720, and 730 during the in-place execution of the matrix multiplication operation. The memory layouts 710, 720, and 730 may show the layouts of a portion of the local memory 340 at three different times.

[0125] The memory layout 710 includes a memory offset with two memory entries for storing the first two output elements of the tensor 630, i.e., c0 and c1. The memory offset is to avoid removal of the input element a0 from the memory as a0 is required for computing  both the first output element c0 and the second output element c1. After c1 is computed, a0 is removed from the memory entry and the memory entry is reused to store the third output element c2, as shown in the memory layout 720. Also, a1 is removed from the memory entry and the memory entry is reused to store the output element c3. In the memory layout 720, two memory entries are reused.

[0126] More memory entries are reused in the memory layout 730. As shown in FIG. 7, a2 is removed from the memory entry and the memory entry is reused to store the output element c4. Also, a3 is removed from the memory entry and the memory entry is reused to store the output element c5. A total of four memory entries are reused during the in-place operation of the matrix multiplication operation.

[0127] FIG. 8 illustrates memory layout before and after the in-place execution of the matrix multiplication operation in FIG. 6, in accordance with various embodiments. Before the in-place execution of the matrix multiplication operation, the overall memory layout is represented by a layout 810, which has 12 allocated memory entries that respectively store the 12 input elements in the tensor 610. After the in-place execution of the matrix multiplication operation, the overall memory layout is represented by a layout 820, which has 6 allocated memory entries that respectively store the 6 output elements in the tensor 630. There is an offset between the layout 810 and the layout 820 to avoid data corruption. The layout 820 is offset by two memory entries, which stores the first two output elements in the tensor 630. The offset is before all the allocated memory entries in the layout 810.

[0128] The layout 810 has an overlap with the layout 820, and the overlap has four memory entries that initially stores input elements and later reused to store output elements. The total number of memory entries required for storing all the input elements and all the output elements for executing the matrix multiplication operation is 14, which equals the total number of memory entries storing all the input elements plus the total number of memory entries in the memory offset. Compared with conventional execution of the matrix multiplication operation that requires 18 memory entries, the in-place execution of the matrix multiplication operation requires less memory space and provides better memory efficiency and utilization. The offset or overlap size may vary as the size of the tensor 610 or 620 changes.

[0129] FIG. 9 illustrates memory layout before and after in-place execution of another  matrix multiplication operation, in accordance with various embodiments. The matrix multiplication operation in FIG. 8 is different from the matrix multiplication operation in FIG. 6. The matrix multiplication operation in FIG. 8 is performed on a 3×4 matrix 910 and a 4×6 matrix 920 and generates a 3×6 matrix 930. The last row of the matrix 930 [c12-c17] cannot overwrite the last row of the matrix 910 [a8-a11] , so 10 free memory entries need to be reserved, meaning the memory offset size is 10.

[0130] Before the in-place execution of the matrix multiplication operation, the overall memory layout is represented by a layout 940, which has 12 allocated memory entries that respectively store the 12 input elements in the matrix 910. After the in-place execution of the matrix multiplication operation, the overall memory layout is represented by a layout 950, which has 18 allocated memory entries that respectively store the 18 output elements in the matrix 930. There is an offset between the layout 940 and the layout 950 to avoid data corruption. The layout 950 is offset by 10 memory entries, which stores the first 10 output elements in the matrix 930. The offset is before all the allocated memory entries in the layout 940.

[0131] The layout 940 has an overlap with the layout 950, and the overlap has eight memory entries that initially stores input elements and later reused to store output elements. The total number of memory entries required for storing all the input elements and all the output elements for executing the matrix multiplication operation is 22, which equals the total number of memory entries storing all the input elements plus the total number of memory entries in the memory offset. Compared with conventional execution of the matrix multiplication operation that requires 30 memory entries, the in-place execution of the matrix multiplication operation requires less memory space and provides better memory efficiency and utilization. Memory reuse ratio (i.e., the ratio of reused memory entries to the total number of memory entries allocated for input elements or output elements) can also vary based on the number of compute blocks used for the inference.

[0132] FIG. 10 illustrates memory layout before and after in-place execution of a matrix multiplication operation executed by multiple compute blocks, in accordance with various embodiments. For the purpose of illustration and simplicity, the matrix multiplication operation in FIG. 10 is performed on the tensors 610 and 620 in FIG. 6, which generates the tensor 630 in FIG. 6. In the embodiments of FIG. 10, the first column [c0, c2, c4] of the tensor  630 is computed by a first compute block, and the second column [c1, c3, c5] of the tensor 630 is computed by a second compute block. Example of the two compute blocks include the compute blocks 330 in FIG. 3. As the matrix multiplication operation is performed by two compute blocks, two output elements may be computed in a single cycle. As shown in FIG. 10, c0 and c1 are computed in cycle 0; c2 and c3 are computed in cycle 1; and c4 and c5 are computed in cycle 2.

[0133] In the embodiments of FIG. 10, each compute block may perform MAC operations on a row of the tensor 610 and a column of the tensor 620 to compute a single output element of the tensor 630. As shown in FIG. 10, the memory space for storing [c2, c3, c4, c5] overlaps with the memory space for storing [a0, a1, a2, a3] so that the four memory entries in the overlapped memory space can be reused. The reuse ratio of the memory may be the same as the embodiments where the matrix multiplication operation is performed by a single compute block.

[0134] In other embodiments (e.g., embodiments where each compute block performs MAC operations on the tensor 610 and a column of the tensor 620 to compute a column of the tensor 630 per cycle) , there would be no overlap between the memory space storing the tensor 610 and the memory space storing the tensor 620. The two compute blocks may need the entire tensor 610 during the whole execution process, and any overlap may corrupt the input elements.

[0135] Example Sparse Cell Array

[0136] FIG. 11 illustrates an example sparse cell 1100 in a combined sparsity mode, in accordance with various embodiments. The sparse cell 1100 may be in a sparse cell array, e.g., the sparse cell array 370 in FIG. 3. The sparse cell 1100 includes 16 MAC units 1110 (individually referred to as “MAC unit 1110” ) arranged in four rows and four columns, 16 weight register files 1120 (individually referred to as “weight register file 1120” ) , 16 activation register files 1130 (individually referred to as “activation register file 1130” ) , four row buffers 1140 (individually referred to as “row buffer 1140” ) , a transpose module 1150, and four sparsity modules 1160 (individually referred to as “sparsity module 1160” ) . In other embodiments, the sparse cell 1100 may include fewer, more, or different components. For instance, the sparse cell may include a different number of MAC units 1110, weight register files 1120, activation register files 1130, row buffers 1140, or sparsity modules 1160.

[0137] The MAC units 1110 are configured to perform MAC operations. Each MAC unit 1110 may include one or more multipliers and one or more adders. A multiplier may multiply an activation with a weight at a time to compute a product. In some embodiments (e.g., embodiments where the MAC unit 1110 includes multiple multipliers) , the multipliers may operate simultaneously to process multiple activation-weight pairs and compute multiple products in one cycle. An adder may accumulate products computed by the multipliers. Even though not shown in FIG. 11, the sparse cell may include an adder tree including a plurality of adder tiers. The first tier may receive outputs of a plurality of MAC units 1110. The number of adders in the first tier may be half of the number of the MAC units 1110, and each adder may accumulate the outputs of two MAC units 1110. The second tier may receive outputs of adders in the first tier. The number of adders in the second tier may be half of the number of adders in the first tier, and each adder in the second tier may accumulate the outputs of two adders in the first tier. The adder tree may include one or more other tiers. The last tier may include a single adder that accumulates outputs of adders in the second last tier to compute a partial sum of the sparse cell 1100.

[0138] The weight register files 1120 store weights to be processed in MAC operations. In the embodiments of FIG. 11, four weight register files 1120 are grouped into a storage set that stores data to be used by a column of MAC units 1110. There are four storage sets corresponding to the four columns of MAC units 1110. In some embodiments, a weight register file 1120 may correspond to a MAC unit 1110 and store data to be processed by the MAC unit. In some embodiments, all the 16 weight register files 1120 constitute a weight storage unit, which may be an example of the weight storage unit 545 in FIG. 5.

[0139] The activation register files 1130 stores activations to be processed in MAC operations. In the embodiments of FIG. 11, four activation register files 1130 are grouped into a storage set that stores data to be used by a row of MAC units 1110. There are four storage sets corresponding to the four rows of MAC units 1110. In some embodiments, an activation register file 1130 may correspond to a MAC unit 1110 and store data to be processed by the MAC unit. In some embodiments, all the 16 activation register files 1130 constitute an activation storage unit, which may be an example of the activation storage unit 535 in FIG. 5.

[0140] The row buffers 1140 store outputs of the MAC units 1110. Each row buffer 1140  may drain outputs of a single row of MAC units 1110. Data stored in the row buffers 1140, such as output operands, may be further transmitted to the transpose module 1150. The transpose module 1150 may operate in either an activation sparsity mode or a weight sparsity mode. In some embodiments, the transpose module 1150 may transpose the output operands in one of the two sparsity modes and keep the output operands as is in the other sparsity mode.

[0141] The sparsity module 1160 facilitates dynamic sparsity-based acceleration in the sparse cell 1100. In the embodiments of FIG. 11, each sparsity module 1160 includes a sparsity tensor storage unit 1165 and a control logic 1167. The sparsity tensor storage unit 1165 stores combined sparsity tensors. A combined sparsity tensor stored in the sparsity tensor storage unit 1165 may correspond to an activation tensor and a weight tensor. A nonzero element in the combined sparsity tensor may correspond to a nonzero activation-weight pair that includes a nonzero activation and a nonzero weight. The position of the nonzero activation in the activation tensor may match the position of the nonzero weight in the weight tensor. The product of the nonzero activation and nonzero weight would be nonzero.

[0142] The control logic 1167 may control transmission of activations and weights stored from the weight register files 1120 and the activation register files 1130 to the MAC units 1110 based on sparsity tensors. For instance, the control logic 1167 may select a subset of the weights stored in the weight register files 1120 and select a subset of activations stored in the activation register files 1130 based on a combined sparsity tensor. The selected weights and activations constitute nonzero activation-weight pairs. The control logic 1167 may transmit the selected weights and activations to the MAC units 1110 for performing MAC operations. The other weights stored in the weight register files 1120 and the other activations stored in the activation register files 1130 are skipped from computation. In the embodiments of FIG. 11, each sparsity module 1160 controls sparsity acceleration in a respective MAC unit 1110. As the sparsity acceleration is either based on both weight sparsity and activation sparsity, 16 sparsity modules 1160 are used for acceleration computations in the 16 MAC units 1110.

[0143] As shown in FIG. 11, the sparse cell 1100 is associated with multiplexers (MUXs) 1103, 1104, 1105, and 1106. In other embodiments, the sparse cell 1100 may be associated  with a different number of MUXs or other devices. The MUX 1103 facilitates loading weights, e.g., from the local memory 340, into the weight register files 1120. The MUX 1104 facilitates loading activations, e.g., from the local memory 340, into the activation register files 1130. The MUX 1105 facilitates loading sparsity tensors into the sparsity tensor storage unit 1165. An example of the MUX 1105 may be the MUX 550 in FIG. 5. The MUX 1106 may be a drain MUX that can facilitate draining outputs of the MAC units 1110, e.g., to the local memory 340.

[0144] In some embodiments, the sparse cell 1100 may operate in a one-sided sparsity mode. The one-sided sparsity mode may be an activation sparsity mode or a weight sparsity mode. The sparsity tensor storage unit 1165 of a sparsity module 1160 may store either an activation sparsity tensor or weight sparsity tensor, depending on which side the sparsity acceleration is. The control logic 1167 may control transmission of weights and activations stored from the weight register files 1120 and the activation register files 1130 to the MAC units 1110 based on the activation sparsity tensor or weight sparsity tensor.

[0145] In an example where the one-sided sparsity mode is a weight sparsity mode, the control logic 1167 may select a subset of the activations stored in the activation register files 1130 based on the weight sparsity tensor and transmits the selected activations to the MAC units 1110 for computation. The other activations stored in the activation register files 1130 are skipped from computation. The position of a selected activation in the activation tensor may match the position of a nonzero element in the weight sparsity tensor so that the weight to be multiplied with the selected activation is nonzero.

[0146] In an example where the one-sided sparsity mode is an activation sparsity mode, the control logic 1167 may select a subset of the weights stored in the weight register files 1120 based on the activation sparsity tensor and transmits the selected weights to the MAC units 1110 for computation. The other weights stored in the weight register files 1120 are skipped from computation. The position of a selected weight in the weight tensor may match the position of a nonzero element in the activation sparsity tensor so that the activation to be multiplied with the selected weight is nonzero.

[0147] In embodiments of two-sided sparsity acceleration, each sparsity module 1160 may control sparsity acceleration in a respective column of MAC units 1110. The MAC units 1110 in the column may process the same sparse tensor but different dense tensors (or the same  dense tensor but different sparse tensors) in a single computation round. In embodiments of one-sided sparsity acceleration, as the sparsity acceleration is either based on weight or activation (but not both) , four sparsity modules 1160 can be sufficient for the 16 MAC units 1110. The other 12 sparsity modules 1160 may be gated or deactivated to save power. The gating or deactivation of the other sparsity modules 1160 may be controlled by clock signals.

[0148] In the dense mode of the sparse cell 1100, no sparsity-based acceleration is performed. One sparsity module 1160 may be activated for the dense mode, while the other sparsity module 1160 may be gated or deactivated to save power. The weight register files 1120 store dense weight tensors. The activation register files 1130 store dense activation tensors. The sparsity tensor storage unit 1165 of the sparsity module 1160 may store no sparsity tensors. The sparsity tensor storage unit 1165 may be gated or deactivated to save power. The control logic 1167 may transmit the weights stored in the weight register files 1120 and the activations stored in the activation register files 1130 to the MAC units 1110 for computation. In some embodiments, all the weights stored in the weight register files 1120 and all the activations stored in the activation register files 1130 are used in MAC operations by the MAC units 1110.

[0149] FIG. 12 illustrates an example sparse cell array 1200, in accordance with various embodiments. The sparse cell array 1200 may be an example of the sparse cell array 370 in FIG. 3. In FIG. 12, the sparse cell array 1200 includes sparse cells 1210 (individually referred to as “sparse cell 1210” ) arranged in four columns and four rows, an activation memory 1220, and a weight memory 1230. In other embodiments, the sparse cell array 1200 may include fewer, more, or different components. For instance, the sparse cell array 1200 may include a different number of columns, rows, or sparse cells 1210.

[0150] Each sparse cell 1210 may perform sparsity accelerated MAC operations. The sparse cells 1210 may facilitate dynamic sparsity mode. For instance, the sparsity modes of the sparse cells 1210 may be dynamically changed between a combined sparsity mode, an activation sparsity mode, a weight sparsity mode, and a dense mode. An embodiment of a sparse cell 1210 may be the sparse cell 1100 in FIG. 11. The activation memory 1220 stores activations, such as activations in input tensors of deep learning operations. Activations may be loaded from the activation memory 1220 to sparse cells 1210. The weight memory 1230 stores weights, such as weights in filters of deep learning operations. Weights may be loaded  from the weight memory 1230 to sparse cells 1210. The activation memory 1220 or weight memory 1230 may be a buffer. In other embodiments, the sparse cell array 1200 may include a dense data memory and a sparse data memory in lieu of the activation memory 1220 and weight memory 1230. The dense data memory may store dense tensors, e.g., dense tensors generated by the load module 360. The sparse data memory may store sparse tensors.

[0151] Example Scatter Write and Gather Read

[0152] FIG. 13 is a block diagram of a drain module 1300, in accordance with various embodiments. The drain module 1300 extracts output elements computed by sparse cells (e.g., sparse cells in the sparse cell array 370, the sparse cell 1100, sparse cells in the sparse cell array 1200, etc. ) and writes the output elements into memories (e.g., the local memory 340) . The drain module 1300 may be an example of the drain module 380 in FIG. 3. As shown in FIG. 13, the drain module 1300 includes post processing engines 1310 (individually referred to as “post processing engine 1310” ) , circular buffers 1320 (individually referred to as “circular buffer 1320” ) , a drain staging buffer 1330, a global drain module 1340, drain banks 1350 (individually referred to as “drain bank 1350” ) , sparse encoders 1360 (individually referred to as “sparse encoder 1360” ) , a write module 1370, and a write buffer 1380. In other embodiments, alternative configurations, different or additional components may be included in the drain module 1300. Further, functionality attributed to a component of the drain module 1300 may be accomplished by a different component included in the drain module 1300 or a different module or system.

[0153] The post processing engines 1310 process outputs of a sparse cell array, e.g., the sparse cell array 370. In some embodiments, a post processing engine 1310 computes activation functions. The post processing engine 1310 may receive outputs of the sparse cell array 370 as inputs to the activation functions. In addition or alternative to activation functions, the post processing engine 1310 may perform other types of post processing on outputs of the sparse cell array 370. For instance, the post processing engine 1310 may apply a bias on an output of the sparse cell array 370. The post processing engine 1310 may transmit the results of the post processing to the circular buffers 1320. The output data stored in the circular buffers 1320 may be further transmitted and written into the drain staging buffer 1330.

[0154] The global drain module 1340 may select output elements stored in the drain staging buffer 1330. In some embodiments, the global drain module 1340 selects output elements in a predetermined manner, e.g., a 1×1×output channels (OC) manner. In some embodiments, the global drain module 1340 selects one of a predetermined number of entries of the drain staging buffer 1330. The predetermined number may be the number of MAC units in a column of the sparse cell. In other embodiments, the global drain module 1340 may select a predetermined amount of data, e.g., 16 bytes, 32 bytes, and so on. After the entries are selected, the global drain module 1340 may select one or more drain banks 1350 and multicast the selected entries to the selected drain bank (s) 1350. In an example, the global drain module 960 may have 16 drain banks 1350 in four groups. Each group may include 4 drain banks 1350. The global drain module 1340 may assign the right rotate value specific to each drain bank 1350 to align and concatenate the consecutive OCs in a single drain bank 1350. The global drain module 1340 may further write the correct set of bytes in the selected line of the drain staging buffer 1330 to the drain bank 1350.

[0155] In some embodiments, a single drain bank 1350 may store an output vector including output elements having the same (OX, OY) coordinate (aka “ (X, Y) coordinate” ) but different OCs. The output elements of the output vector may be arranged in sequence in accordance with their OCs. For instance, the OC coordinate of the first output element in the output vector may be in 0, the OC coordinate of the second output element may be in 1, the OC coordinate of the third output element may be in 2, and so on. Different drain banks 1350 may store different output vectors. The output elements in different drain banks 1350 may have different OX coordinates or different OY coordinates.

[0156] A sparse encoder 1360 converts dense data to compressed data based on sparsity in the dense data. In some embodiments, a sparse encoder 1360 may receive output elements (e.g., the output tensor 230 in FIG. 2) of a layer, e.g., from the global drain module 1340. The output elements may be arranged in output vectors. The sparse encoder 1360 may generate a compressed version of one or more output vectors. In some embodiments, the sparse encoder 1360 may compress an output vector based on a threshold value. The sparse encoder 1360 may compare the absolute value of each output element with the threshold value. The sparse encoder 1360 may remove any output elements whose absolute value is no greater than the threshold value from the output vector to generate a compressed  output vector. The threshold value may be zero. The removed output elements may not be stored in the write buffer 1380 or the local memory to save bandwidth and memory usage.

[0157] In some embodiments, a sparse encoder 1360 may also generate one or more sparsity tensors of the output vector. The sparsity tensor may include sparsity elements, each of which corresponds to a different output element in the output vector and indicates whether the corresponding output element is removed or not. In some embodiments, the sparsity tensor may be a sparsity bitmap, and a sparsity element in the sparsity bitmap may be a bit. A zero bit may indicate that the corresponding output element is removed and not in the compressed output vector, while a one bit may indicate that the corresponding output element is not removed and is in the compressed output vector.

[0158] In some embodiments, a sparse encoder 1360 may encode sparsity on a context level. A context may be a portion of the output tensor generated by the sparse cell array. In an example, the context may be an output vector including output elements that have the same (X, Y) coordinate but different Z coordinates. The context may be processed in the next DNN layer, e.g., by one or more MAC units. For a given context, the sparse encoder 1360 may read in multiple lines from a data bank before emitting a single line of N bytes (where N is an integer, such as 16, 32, 64, etc. ) , depending on the sparsity level. As the elements in a context stream may come over multiple rounds, the sparse encoder 1360 can save data indicating a state of the context ( “context state” ) in a buffer and retrieve the context state back later from the buffer. A context state may include the compressed context, sparsity tensor of the context, output elements in the compressed context, and line counts.

[0159] The write module 1370 determines memory addresses of output elements and writes output elements into a memory based on the memory addresses. An example of the memory may be the local memory 340. In some embodiments, the write module 1370 writes output elements with a scatter write mechanism. The write module 1370 may write output elements of the same output tensor of a deep learning operation into multiple memory fragments, and the memory fragments may be separated by one or more other memory fragments that store data elements of one or more other tensors. These other tensors may be the input tensor of the same deep learning operation, the weight tensor of the same deep learning operation, or tensors of other deep learning operations.

[0160] The write module 1370 may retrieve a scatter map from the local memory 340 and  write output elements based on the scatter map. The scatter map may be generated by the DNN module 301 and includes a sequence of entries corresponding to a sequence of free memory fragments in the local memory 340. The order of the free memory fragments in the scatter map may match the order of the locations of the free memory fragments in the local memory 340. For instance, the first free memory fragment in the scatter map may be the first free memory fragment in the local memory 340 or in a particular section of the local memory 340; and the second free memory fragment in the scatter map may be the second free memory fragment in the local memory 340 or in a particular section of the local memory 340, even though one or more allocated memory fragments may be located between the first free memory fragment and the second free memory fragment in the local memory 340. Each entry of the scatter map may include a start address of the corresponding free memory fragment and the free size of the free memory fragment. The start address may be the address of the first memory entry in the free memory fragment. The write module 1370 may compute a cumulative free size for each memory fragment in the scatter map. The cumulative free size of the first memory fragment may equal the free size of the first memory fragment. For each of the subsequent memory fragments, the cumulative free size may equal the free size of the memory fragment plus the cumulative free size of the previous memory fragment. The write module 1370 may modify the scatter map to include the cumulative free sizes of all the memory fragments.

[0161] The write module 1370 may also determine a write address for writing an output element based on an input write address of the output element and the modified scatter map. The input write address may be indicated in a configuration parameter from the DNN module 301. In some embodiments, the input write address may indicate the position index of the output element in all the elements to be written into the local memory 340. The configuration parameter may also include data indicating a write amount. The write amount may be the amount of data to be written. For instance, a write amount of 1 may indicate that a single memory entry will be allocated to the output element. The write module 1370 may compare the input write address with one or more cumulative free sizes in the modified scatter map and identify a memory fragment with a cumulative free size that is greater than the input write address. The write module 1370 may further subtract the cumulative free size of the previous memory fragment in the modified scatter map from the input write  address. The previous memory fragment may be right before the identified memory fragment in the scatter map. The write module 1370 may then compute a sum of the result of the subtraction and the start address of the identified memory fragment, and the sum may be the write address. The write module 1370 writes the output element into the memory entry at write address. The write module 1370 may determine the write addresses for writing other output elements.

[0162] The write module 1370 may generate a gather map including data indicating locations of the memory entries that store the output elements. In some embodiments, the write module 1370 generates one or more gather map for an output tensor of a deep learning operation. A gather map may include a list of entries (aka “gather map entries” ) , each of which may correspond to an output element. A gather map entry may include a start address of a memory fragment, the position index of the memory entry in the memory fragment, and a position index of the output element in the output tensor. In some embodiments (e.g., embodiments where a memory fragment including multiple memory entries storing output elements) , the gather map entries of these memory entries may share the same start address. The position index of a memory entry in a memory fragment may indicate the position of the memory entry in the memory fragment. For instance, 0 may indicate that the memory entry is the first memory entry in the memory fragment. The position index of an output element in an output tensor may indicate the position of the output element in the output tensor. The position index of an output element may include one or more parameters, each of which may correspond to a position in a different dimension of the output tensor. An example position index of an output element may be a (X, Y) coordinate. Another example position index of an output element may be a (X, Y, Z) coordinate.

[0163] In some embodiments, the write module 1370 may generate a gather map based on a scatter map. For instance, the write module 1370 may generate a gather map for an output tensor based on the scatter map used by the write module 1370 to write the output tensor into the local memory 340. Each entry in the gather map may correspond to a different entry in the scatter map. The write module 1370 may write the gather map into the local memory 340. The gather map may be later retrieved by the load module 360 to read the output elements from the local memory 340, e.g., for performing the next deep learning  operation in the DNN. To read an output element from the local memory 340, the load module 360 may identify the corresponding gather map entry and accumulate the start address and the position index of the memory entry in the gather map entry to compute a read address of the output element. The load module 360 may generate a data read request that includes the read address and read the output element from the memory entry at the read address.

[0164] In some embodiments, the write module 1370 determines memory address of output elements in the compressed output vectors. The write module 1370 may avoid the determination of memory addresses for output elements removed by the sparse encoder 1360. The write module 1370 may use the position of an activation in the output tensor of the deep learning operation to generate a memory address for the activation. For instance, the write module 1370 may compute the 3D coordinate (e.g., a (OX, OY, OC) coordinate) of the activation. The write module 1370 may identify the location of any (OX, OY, OC) coordinate of the output tensor in the memory.

[0165] In some embodiments (e.g., embodiments where the sparse encoder 1360 compresses the output tensor) , the write module 1370 may write compressed output vectors generated by the sparse encoder 1360 into the memory. The write module 1370 may skip output elements removed by the sparse encoder 1360 in the compression process. The write module 1370 may also write sparsity tensors generated by the sparse encoder 1360 into the memory or a separate memory. In some embodiments, the write module 1370 may determine memory addresses of sparsity tensors associated with the output tensor and write the sparsity tensors to the memory based on the memory addresses.

[0166] To write an output vector or sparsity tensor into the memory, the write module 1370 may generate a write request that includes the memory address (se) of the output vector or sparsity tensor and transmit the write request to the memory. The memory, after receiving the write request, may process the write request and store the output vector or sparsity tensor in one or more data write operations. The write buffer 1380 may store the output vector, sparsity tensor, or the write request while the write request or one or more previous write requests are being processed by the memory.

[0167] FIG. 14 illustrates an example memory 1400 with scattered free memory fragments 1410, in accordance with various embodiments. The free memory fragments 1410 are  individually referred to as free memory fragment 1410. The memory 1400 also includes allocated memory fragments 1420, individually referred to as allocated memory fragment 1420. For the purpose of illustration, the memory 1400 includes four free memory fragments 1410 and three allocated memory fragments 1420. In other embodiments, the memory 1400 may include a different number of free memory fragments or a different number of allocated memory fragments. The memory 1400 may be an example of the local memory 340 or an example of part of the local memory 340.

[0168] Each free memory fragment 1410 includes a group of free memory entries, e.g., memory entries that do not store any data at the time and are available to store data. Each allocated memory fragment 1420 includes a group of allocated memory entries, e.g., memory entries that are occupied by data and are not available to store new data before the currently stored data is removed. As shown in FIG. 14, free memory fragments 1410 may be separated by an allocated memory fragment 1420. Due to the presence of the allocated memory fragments 1420 between the free memory fragments 1410, the free memory fragments 1410 are scattered, as opposed to continuous.

[0169] FIG. 15 illustrates a scatter map 1510 and a gather map 1520, in accordance with various embodiments. In some embodiments, the scatter map 1510 may be generated by the write module 1370 by modifying a scatter map generated by the DNN module 301. The scatter map may be for writing data into the memory 1400 in FIG. 14. The gather map 1520 may be generated by the write module 1370 based on the scatter map 1510 and may be used to read data from the memory 1400.

[0170] The scatter map 1510 includes four entries that correspond to four free memory fragments, respectively. Each entry in the scatter map 1510 has a start address, a free size, and a cumulative free size. As shown in FIG. 15, the first free memory fragment has a start address of 0, a free size of 20 (i.e., a total of 20 free memory entries in the first free memory fragment) , and a cumulative size of 20. The second free memory fragment has a start address of 40, a free size of 30 (i.e., a total of 30 free memory entries in the second free memory fragment) , and a cumulative size of 50 (i.e., 30 plus 20) . The third free memory fragment has a start address of 90, a free size of 70 (i.e., a total of 70 free memory entries in the third free memory fragment) , and a cumulative size of 120 (i.e., 70 plus 50) . The fourth free memory fragment has a start address of 180, a free size of 30 (i.e., a total of 30 free  memory entries in the fourth free memory fragment) , and a cumulative size of 150 (i.e., 30 plus 120) .

[0171] The gather map 1520 has four entries corresponding to four output elements stored in four memory entries. In other embodiments, the gather map 1520 may include a different number of entries. The four entries in the gather map 1520 share the same start address. Each of the four entries has a position index of the free entry used for storing the output element and a (X, Y) coordinate of the output element. The (X, Y) coordinate specifies the position of the output element in the output tensor. An adder 1530 is used to compute a read address by accumulating the start address with the position index of the memory entry. The adder 1530 may be part of the load module 360. The load module 360 may use the output of the adder 1530 to read the output element from the memory 1400 so that the sparse cell array 370 may use the output element as an input element in the next deep learning operation of the DNN.

[0172] FIG. 16 illustrates scatter write and gather read, in accordance with various embodiments. For the purpose of illustration and simplicity, FIG. 16 shows a memory 1600 that stores four tensors: a first tensor 1610, a second tensor 1620, a third tensor 1630, and a fourth tensor having two segments 1640A and 1640B. With scatter maps and gather maps (e.g., the scatter map 1510 and the gather map 1520) , the memory 1600 can support scatter write and gather read across multiple memory fragments. In the example shown in FIG. 16, the segments 1640A and 1640B of the fourth tensor are written into two memory fragments that are separated by a memory fragment storing the second tensor 1620. The scatter write of the segments 1640A and 1640B into the memory 1600 may be performed based on a scatter map that indicates the addresses of the memory entries in the two memory fragments. Also, the gather read of the segments 1640A and 1640B from the memory 1600 may be performed based on a gather map that indicates the address of the memory entries in the two memory fragments and indicates which element of the fourth tensor is stored in which memory entry.

[0173] FIG. 17 illustrates an example sparse encoder 1700, in accordance with various embodiments. The sparse encoder 1700 may be an example of the sparse encoders 1360 in FIG. 13. As shown in FIG. 17, the sparse encoder 1700 includes comparators 1710 (individually referred to as “comparator 1710” ) and a compression packer 1720. For the  purpose of illustration, FIG. 17 shows 17 comparators 1710. In other embodiments, the sparse encoder 1700 may include a different number of comparators 1710.

[0174] In the embodiments of FIG. 17, the sparse encoder 1700 receives an activation tensor 1701 that includes 17 activations represented as D0-D15 in FIG. 17. The activation tensor may be an output operand computed in a sparse cell, e.g., the sparse cell 1100. Each comparator 1710 receives a different activation in the activation tensor 1701 and compresses the activation with a predetermined value. The predetermined value may be zero in some embodiments. In other embodiments, the predetermined value may be nonzero. The comparator 1710 may change the value of an activation having a value lower than the predetermined value to zero and output zero. For an activation having a value not lower than the predetermined value, the comparator 1710 may output the activation as is. The data elements output from the comparators 1710 are C0-C15. Each comparator 1710 may also output a bit indicating whether the data element output from the comparator is zero or not. In an example, when the output is zero, the bit is zero; when the output is nonzero, the bit is one. The bits are represented as B0-B15 in FIG. 17. The data elements and bits are provided to the compression packer 1720.

[0175] The compression packer 1720 may generate a compressed activation vector 1702 that includes the nonzero data elements output from the comparators 1710. All the data elements in the compressed activation vector 1702 may be nonzero. The compressed activation vector 1702 may have a smaller size (e.g., less data elements) than the activation tensor 1701. The compression packer 1720 also generates a sparsity tensor 1703 that indicates positions of the data elements of the compressed activation vector 1702 in the activation tensor 1701. In some embodiments, the compression packer 1720 generates the sparsity tensor 1703 using the bits B0-B15. The sparsity tensor 1703 may have the same size as the activation tensor 1701.

[0176] Example Method of Executing DNN Layer

[0177] FIG. 18 is a flowchart showing a method 1800 of executing a DNN layer, in accordance with various embodiments. The method 1800 may be performed by the DNN accelerator 302 in FIG. 3. Although the method 1800 is described with reference to the flowchart illustrated in FIG. 18, many other methods for accelerating DNN layer may alternatively be used. For example, the order of execution of the steps in FIG. 18 may be  changed. As another example, some of the steps may be changed, eliminated, or combined.

[0178] The DNN accelerator 302 stores 1810 an input tensor of the layer in a memory. A memory entry in the memory stores an input element in the input tensor. In some embodiments, the input tensor includes a plurality of input elements. In some embodiments, the input tensor is a vector, a matrix, or a 3D tensor.

[0179] The DNN accelerator 302 generates 1820 an output tensor of the layer by performing one or more MAC operations on the input tensor and another tensor. The output tensor comprises one or more output elements. In some embodiments, the layer is a convolutional layer. The other tensor includes a kernel of the convolutional layer.

[0180] The DNN accelerator 302 removes 1830 the input element from the memory entry. The DNN accelerator 302 writes 1840 an output element in the output tensor into the memory entry. A position index of the input element in the input tensor is different from a position index of the output element in the output tensor. In some embodiments, the DNN accelerator 302 maintains one or more free memory entries in the memory after storing the input tensor. The one or more free memory entries are before the memory entry in the memory. The DNN accelerator 302 stores one or more output elements in the output tensor in the one or more free memory entries. The one or more output elements are before the output element in the output tensor. In some embodiments, the total number of the one or more free memory entries is determined based on a total number of input elements in the input tensor or a total number of output elements in the output tensor.

[0181] In some embodiments, the DNN accelerator 302 receives a scatter map of the memory, the scatter map indicating positions of free entries in the memory. The DNN accelerator 302 determines a memory address for writing the output element based on the scatter map, wherein the memory address corresponds to the memory entry. In some embodiments, the memory comprises a plurality of free fragments. A free fragment comprises one or more free memory entries. For each free fragment, the scatter map comprises a start memory address of the free fragment and a size of the free fragment. The size of the free fragment indicates a total number of free memory entries in the free fragment of the memory.

[0182] In some embodiments, the scatter map further comprises a cumulative size of the free fragment. The cumulative size of the free fragment indicates a total number of memory  entries in the free fragment and in one or more free fragments that are before the free fragment in the memory. In some embodiments, after writing the output element into the memory entry, the DNN accelerator 302 generates a gather map for the output tensor. The gather map comprises a memory address of the memory entry and one or more parameters that indicate a position of the output element in the output tensor. In some embodiments, the DNN accelerator 302 reads the output element from the memory based on the gather map. The DNN accelerator 302 executes the next layer of the neural network using the output element.

[0183] In some embodiments, the DNN accelerator 302 stores a first segment of the output tensor in a first fragment of the memory. The DNN accelerator 302 stores a second segment of the output tensor in a second fragment of the memory. A third fragment of the memory is between the first fragment of the memory and the second fragment of the memory. The third fragment of the memory stores at least part of a different tensor.

[0184] Example Computing Device

[0185] FIG. 19 is a block diagram of an example computing device 1900, in accordance with various embodiments. In some embodiments, the computing device 1900 can be used as at least part of the DNN system 300. A number of components are illustrated in FIG. 19 as included in the computing device 1900, but any one or more of these components may be omitted or duplicated, as suitable for the application. In some embodiments, some or all of the components included in the computing device 1900 may be attached to one or more motherboards. In some embodiments, some or all of these components are fabricated onto a single system on a chip (SoC) die. Additionally, in various embodiments, the computing device 1900 may not include one or more of the components illustrated in FIG. 19, but the computing device 1900 may include interface circuitry for coupling to the one or more components. For example, the computing device 1900 may not include a display device 1906, but may include display device interface circuitry (e.g., a connector and driver circuitry) to which a display device 1906 may be coupled. In another set of examples, the computing device 1900 may not include an audio input device 1918 or an audio output device 1908, but may include audio input or output device interface circuitry (e.g., connectors and supporting circuitry) to which an audio input device 1918 or audio output device 1908 may be coupled.

[0186] The computing device 1900 may include a processing device 1902 (e.g., one or more processing devices) . The processing device 1902 processes electronic data from registers and / or memory to transform that electronic data into other electronic data that may be stored in registers and / or memory. The computing device 1900 may include a memory 1904, which may itself include one or more memory devices such as volatile memory (e.g., DRAM) , nonvolatile memory (e.g., read-only memory (ROM) ) , high bandwidth memory (HBM) , flash memory, solid state memory, and / or a hard drive. In some embodiments, the memory 1904 may include memory that shares a die with the processing device 1902. In some embodiments, the memory 1904 includes one or more non-transitory computer-readable media storing instructions executable to perform operations for executing DNN layers (e.g., the method 1800 described in conjunction with FIG. 18) or some operations performed by the DNN system 300 (e.g., by the DNN accelerator 302) . The instructions stored in the one or more non-transitory computer-readable media may be executed by the processing device 1902.

[0187] In some embodiments, the computing device 1900 may include a communication chip 1912 (e.g., one or more communication chips) . For example, the communication chip 1912 may be configured for managing wireless communications for the transfer of data to and from the computing device 1900. The term "wireless" and its derivatives may be used to describe circuits, devices, systems, methods, techniques, communications channels, etc., that may communicate data through the use of modulated electromagnetic radiation through a nonsolid medium. The term does not imply that the associated devices do not contain any wires, although in some embodiments they might not.

[0188] The communication chip 1912 may implement any of a number of wireless standards or protocols, including but not limited to Institute for Electrical and Electronic Engineers (IEEE) standards including Wi-Fi (IEEE 802.10 family) , IEEE 802.16 standards (e.g., IEEE 802.16-2005 Amendment) , Long-Term Evolution (LTE) project along with any amendments, updates, and / or revisions (e.g., advanced LTE project, ultramobile broadband (UMB) project (also referred to as "3GPP2" ) , etc. ) . IEEE 802.16 compatible Broadband Wireless Access (BWA) networks are generally referred to as WiMAX networks, an acronym that stands for worldwide interoperability for microwave access, which is a certification mark for products that pass conformity and interoperability tests for the IEEE 802.16 standards. The  communication chip 1912 may operate in accordance with a Global System for Mobile Communication (GSM) , General Packet Radio Service (GPRS) , Universal Mobile Telecommunications System (UMTS) , High Speed Packet Access (HSPA) , Evolved HSPA (E-HSPA) , or LTE network. The communication chip 1912 may operate in accordance with Enhanced Data for GSM Evolution (EDGE) , GSM EDGE Radio Access Network (GERAN) , Universal Terrestrial Radio Access Network (UTRAN) , or Evolved UTRAN (E-UTRAN) . The communication chip 1912 may operate in accordance with Code-division Multiple Access (CDMA) , Time Division Multiple Access (TDMA) , Digital Enhanced Cordless Telecommunications (DECT) , Evolution-Data Optimized (EV-DO) , and derivatives thereof, as well as any other wireless protocols that are designated as 3G, 4G, 5G, and beyond. The communication chip 1912 may operate in accordance with other wireless protocols in other embodiments. The computing device 1900 may include an antenna 1922 to facilitate wireless communications and / or to receive other wireless communications (such as AM or FM radio transmissions) .

[0189] In some embodiments, the communication chip 1912 may manage wired communications, such as electrical, optical, or any other suitable communication protocols (e.g., the Ethernet) . As noted above, the communication chip 1912 may include multiple communication chips. For instance, a first communication chip 1912 may be dedicated to shorter-range wireless communications such as Wi-Fi or Bluetooth, and a second communication chip 1912 may be dedicated to longer-range wireless communications such as global positioning system (GPS) , EDGE, GPRS, CDMA, WiMAX, LTE, EV-DO, or others. In some embodiments, a first communication chip 1912 may be dedicated to wireless communications, and a second communication chip 1912 may be dedicated to wired communications.

[0190] The computing device 1900 may include battery / power circuitry 1914. The battery / power circuitry 1914 may include one or more energy storage devices (e.g., batteries or capacitors) and / or circuitry for coupling components of the computing device 1900 to an energy source separate from the computing device 1900 (e.g., AC line power) .

[0191] The computing device 1900 may include a display device 1906 (or corresponding interface circuitry, as discussed above) . The display device 1906 may include any visual indicators, such as a heads-up display, a computer monitor, a projector, a touchscreen  display, a liquid crystal display (LCD) , a light-emitting diode display, or a flat panel display, for example.

[0192] The computing device 1900 may include an audio output device 1908 (or corresponding interface circuitry, as discussed above) . The audio output device 1908 may include any device that generates an audible indicator, such as speakers, headsets, or earbuds, for example.

[0193] The computing device 1900 may include an audio input device 1918 (or corresponding interface circuitry, as discussed above) . The audio input device 1918 may include any device that generates a signal representative of a sound, such as microphones, microphone arrays, or digital instruments (e.g., instruments having a musical instrument digital interface (MIDI) output) .

[0194] The computing device 1900 may include a GPS device 1916 (or corresponding interface circuitry, as discussed above) . The GPS device 1916 may be in communication with a satellite-based system and may receive a location of the computing device 1900, as known in the art.

[0195] The computing device 1900 may include another output device 1910 (or corresponding interface circuitry, as discussed above) . Examples of the other output device 1910 may include an audio codec, a video codec, a printer, a wired or wireless transmitter for providing information to other devices, or an additional storage device.

[0196] The computing device 1900 may include another input device 1920 (or corresponding interface circuitry, as discussed above) . Examples of the other input device 1920 may include an accelerometer, a gyroscope, a compass, an image capture device, a keyboard, a cursor control device such as a mouse, a stylus, a touchpad, a bar code reader, a Quick Response (QR) code reader, any sensor, or a radio frequency identification (RFID) reader.

[0197] The computing device 1900 may have any desired form factor, such as a handheld or mobile computer system (e.g., a cell phone, a smart phone, a mobile internet device, a music player, a tablet computer, a laptop computer, a netbook computer, an ultrabook computer, a personal digital assistant (PDA) , an ultramobile personal computer, etc. ) , a desktop computer system, a server or other networked computing component, a printer, a scanner, a monitor, a set-top box, an entertainment control unit, a vehicle control unit, a digital camera, a digital video recorder, or a wearable computer system. In some embodiments, the  computing device 1900 may be any other electronic device that processes data.

[0198] Select Examples

[0199] The following paragraphs provide various examples of the embodiments disclosed herein.

[0200] Example 1 provides a method, including storing an input tensor of a layer of a neural network in a memory, a memory entry in the memory storing an input element in the input tensor; generating an output tensor of the layer by performing one or more multiply-accumulate (MAC) operations on the input tensor and another tensor; removing the input element from the memory entry; and writing an output element in the output tensor into the memory entry, in which a position index of the input element in the input tensor is different from a position index of the output element in the output tensor.

[0201] Example 2 provides the method of example 1, further including maintaining one or more free memory entries in the memory after storing the input tensor, in which the one or more free memory entries are before the memory entry in the memory; and storing one or more output elements in the output tensor in the one or more free memory entries, in which the one or more output elements are before the output element in the output tensor.

[0202] Example 3 provides the method of example 2, in which a number of the one or more free memory entries is determined based on a total number of input elements in the input tensor or a total number of output elements in the output tensor.

[0203] Example 4 provides the method of any one of examples 1-3, in which writing an output element in the output tensor into the memory entry includes determining a memory address for writing the output element based on a scatter map, wherein the scatter map has information indicating positions of free entries in the memory, and wherein the memory address corresponds to the memory entry.

[0204] Example 5 provides the method of example 4, in which: the memory includes a plurality of free fragments, a free fragment includes one or more free memory entries, for each free fragment, the scatter map includes a start memory address of the free fragment and a size of the free fragment, and the size of the free fragment indicates a total number of free memory entries in the free fragment of the memory.

[0205] Example 6 provides the method of example 5, in which the scatter map further includes a cumulative size of the free fragment, and the cumulative size of the free fragment  indicates a total number of memory entries in the free fragment and in one or more free fragments that are before the free fragment in the memory.

[0206] Example 7 provides the method of any one of examples 1-6, further including after writing the output element into the memory entry, generating a gather map for the output tensor, the gather map including a memory address of the memory entry and one or more parameters that indicate a position of the output element in the output tensor.

[0207] Example 8 provides the method of example 7, further includes reading the output element from the memory based on the gather map; and executing a next layer of the neural network using the output element.

[0208] Example 9 provides the method of any one of examples 1-8, further including storing a first segment of the output tensor in a first fragment of the memory; and storing a second segment of the output tensor in a second fragment of the memory, in which a third fragment of the memory is between the first fragment of the memory and the second fragment of the memory, and the third fragment of the memory stores at least part of a different tensor.

[0209] Example 10 provides the method of any one of examples 1-9, in which the layer is a convolutional layer, and the another tensor includes a filter of the convolutional layer.

[0210] Example 11 provides one or more non-transitory computer-readable media storing instructions executable to perform operations, the operations including storing an input tensor of a layer of a neural network in a memory, a memory entry in the memory storing an input element in the input tensor; generating an output tensor of the layer by performing one or more multiply-accumulate (MAC) operations on the input tensor and another tensor; removing the input element from the memory entry; and writing an output element in the output tensor into the memory entry, in which a position index of the input element in the input tensor is different from a position index of the output element in the output tensor.

[0211] Example 12 provides the one or more non-transitory computer-readable media of example 11, in which the operations further include maintaining one or more free memory entries in the memory after storing the input tensor, in which the one or more free memory entries are before the memory entry in the memory; and storing one or more output elements in the output tensor in the one or more free memory entries, in which the one or more output elements are before the output element in the output tensor.

[0212] Example 13 provides the one or more non-transitory computer-readable media of example 11 or 12, in which writing an output element in the output tensor into the memory entry includes determining a memory address for writing the output element based on a scatter map, wherein the scatter map has information indicating positions of free entries in the memory, and wherein the memory address corresponds to the memory entry.

[0213] Example 14 provides the one or more non-transitory computer-readable media of example 13, in which: the memory includes a plurality of free fragments, a free fragment includes one or more free memory entries, for each free fragment, the scatter map includes a start memory address of the free fragment and a size of the free fragment, and the size of the free fragment indicates a total number of free memory entries in the free fragment of the memory.

[0214] Example 15 provides the one or more non-transitory computer-readable media of example 14, in which the scatter map further includes a cumulative size of the free fragment, and the cumulative size of the free fragment indicates a total number of memory entries in the free fragment and in one or more free fragments that are before the free fragment in the memory.

[0215] Example 16 provides the one or more non-transitory computer-readable media of any one of examples 11-15, in which the operations further include after writing the output element into the memory entry, generating a gather map for the output tensor, the gather map including a memory address of the memory entry and one or more parameters that indicate a position of the output element in the output tensor; reading the output element from the memory based on the gather map; and executing a next layer of the neural network using the output element.

[0216] Example 17 provides the one or more non-transitory computer-readable media of any one of examples 11-16, in which the operations further include storing a first segment of the output tensor in a first fragment of the memory; and storing a second segment of the output tensor in a second fragment of the memory, in which a third fragment of the memory is between the first fragment of the memory and the second fragment of the memory, and the third fragment of the memory stores at least part of a different tensor.

[0217] Example 18 provides an apparatus, including a computer processor for executing computer program instructions; and a non-transitory computer-readable memory storing  computer program instructions executable by the computer processor to perform operations including storing an input tensor of a layer of a neural network in a memory, a memory entry in the memory storing an input element in the input tensor, generating an output tensor of the layer by performing one or more multiply-accumulate (MAC) operations on the input tensor and another tensor, removing the input element from the memory entry, and writing an output element in the output tensor into the memory entry, in which a position index of the input element in the input tensor is different from a position index of the output element in the output tensor.

[0218] Example 19 provides the apparatus of example 18, in which the operations further include maintaining one or more free memory entries in the memory after storing the input tensor, in which the one or more free memory entries are before the memory entry in the memory; and storing one or more output elements in the output tensor in the one or more free memory entries, in which the one or more output elements are before the output element in the output tensor.

[0219] Example 20 provides the apparatus of example 18 or 19, in which writing an output element in the output tensor into the memory entry includes determining a memory address for writing the output element based on a scatter map, wherein the scatter map has information indicating positions of free entries in the memory, and wherein the memory address corresponds to the memory entry.

[0220] The above description of illustrated implementations of the disclosure, including what is described in the Abstract, is not intended to be exhaustive or to limit the disclosure to the precise forms disclosed. While specific implementations of, and examples for, the disclosure are described herein for illustrative purposes, various equivalent modifications are possible within the scope of the disclosure, as those skilled in the relevant art will recognize. These modifications may be made to the disclosure in light of the above detailed description.

Claims

A method, comprising:storing an input tensor of a layer of a neural network in a memory, a memory entry in the memory storing an input element in the input tensor;generating an output tensor of the layer by performing one or more multiply-accumulate (MAC) operations on the input tensor and another tensor;removing the input element from the memory entry; andwriting an output element in the output tensor into the memory entry,wherein a position index of the input element in the input tensor is different from a position index of the output element in the output tensor.The method of claim 1, further comprising:maintaining one or more free memory entries in the memory after storing the input tensor, wherein the one or more free memory entries are before the memory entry in the memory; andstoring one or more output elements in the output tensor in the one or more free memory entries, wherein the one or more output elements are before the output element in the output tensor.The method of claim 2, wherein a number of the one or more free memory entries is determined based on a total number of input elements in the input tensor or a total number of output elements in the output tensor.The method of claim 1, wherein writing an output element in the output tensor into the memory entry comprises:determining a memory address for writing the output element based on a scatter map, wherein the scatter map has information indicating positions of free entries in the memory, and wherein the memory address corresponds to the memory entry.The method of claim 4, wherein:the memory comprises a plurality of free fragments,a free fragment comprises one or more free memory entries,for each free fragment, the scatter map comprises a start memory address of the free fragment and a size of the free fragment, andthe size of the free fragment indicates a total number of free memory entries in the free fragment of the memory.The method of claim 5, wherein the scatter map further comprises a cumulative size of the free fragment, and the cumulative size of the free fragment indicates a total number of memory entries in the free fragment and in one or more free fragments that are before the free fragment in the memory.The method of claim 1, further comprising:after writing the output element into the memory entry, generating a gather map for the output tensor, the gather map comprising a memory address of the memory entry and one or more parameters that indicate a position of the output element in the output tensor.The method of claim 7, further comprises:reading the output element from the memory based on the gather map; andexecuting a next layer of the neural network using the output element.The method of claim 1, further comprising:storing a first segment of the output tensor in a first fragment of the memory; andstoring a second segment of the output tensor in a second fragment of the memory,wherein a third fragment of the memory is between the first fragment of the memory and the second fragment of the memory, and the third fragment of the memory stores at least part of a different tensor.The method of claim 1, wherein the layer is a convolutional layer, and the another tensor comprises a filter of the convolutional layer.One or more non-transitory computer-readable media storing instructions executable to perform operations, the operations comprising:storing an input tensor of a layer of a neural network in a memory, a memory entry in the memory storing an input element in the input tensor;generating an output tensor of the layer by performing one or more multiply-accumulate (MAC) operations on the input tensor and another tensor;removing the input element from the memory entry; andwriting an output element in the output tensor into the memory entry,wherein a position index of the input element in the input tensor is different from a position index of the output element in the output tensor.The one or more non-transitory computer-readable media of claim 11, wherein the operations further comprise:maintaining one or more free memory entries in the memory after storing the input tensor, wherein the one or more free memory entries are before the memory entry in the memory; andstoring one or more output elements in the output tensor in the one or more free memory entries, wherein the one or more output elements are before the output element in the output tensor.The one or more non-transitory computer-readable media of claim 11, wherein writing an output element in the output tensor into the memory entry comprises:determining a memory address for writing the output element based on a scatter map, wherein the scatter map has information indicating positions of free entries in the memory, and wherein the memory address corresponds to the memory entry.The one or more non-transitory computer-readable media of claim 13, wherein:the memory comprises a plurality of free fragments,a free fragment comprises one or more free memory entries,for each free fragment, the scatter map comprises a start memory address of the free fragment and a size of the free fragment, andthe size of the free fragment indicates a total number of free memory entries in the free fragment of the memory.The one or more non-transitory computer-readable media of claim 14, wherein the scatter map further comprises a cumulative size of the free fragment, and the cumulative size of the free fragment indicates a total number of memory entries in the free fragment and in one or more free fragments that are before the free fragment in the memory.The one or more non-transitory computer-readable media of claim 11, wherein the operations further comprise:after writing the output element into the memory entry, generating a gather map for the output tensor, the gather map comprising a memory address of the memory entry and one or more parameters that indicate a position of the output element in the output tensor;reading the output element from the memory based on the gather map; andexecuting a next layer of the neural network using the output element.The one or more non-transitory computer-readable media of claim 11, wherein the operations further comprise:storing a first segment of the output tensor in a first fragment of the memory; andstoring a second segment of the output tensor in a second fragment of the memory,wherein a third fragment of the memory is between the first fragment of the memory and the second fragment of the memory, and the third fragment of the memory stores at least part of a different tensor.An apparatus, comprising:a computer processor for executing computer program instructions; anda non-transitory computer-readable memory storing computer program instructions executable by the computer processor to perform operations comprising:storing an input tensor of a layer of a neural network in a memory, a memory entry in the memory storing an input element in the input tensor,generating an output tensor of the layer by performing one or more multiply-accumulate (MAC) operations on the input tensor and another tensor,removing the input element from the memory entry, andwriting an output element in the output tensor into the memory entry,wherein a position index of the input element in the input tensor is different from a position index of the output element in the output tensor.The apparatus of claim 18, wherein the operations further comprise:maintaining one or more free memory entries in the memory after storing the input tensor, wherein the one or more free memory entries are before the memory entry in the memory; andstoring one or more output elements in the output tensor in the one or more free memory entries, wherein the one or more output elements are before the output element in the output tensor.The apparatus of claim 18, wherein writing an output element in the output tensor into the memory entry comprises:determining a memory address for writing the output element based on a scatter map, wherein the scatter map has information indicating positions of free entries in the memory, and wherein the memory address corresponds to the memory entry.

Citation Information

Patent Citations

  • Apparatus and method for a tensor permutation engine

    CN110659068A

  • Method and system for implementing convolution transpose layer of neural network

    CN111723904A

  • Implementing dispersive functions on neural network accelerators

    CN117952156A

  • Performing operation in neural network with storage pointer and sparsity map

    US20230376765A1

  • Pruning activations and weights of neural networks with programmable thresholds

    US20230394312A1