Tensor processing unit

The universal sparse tensor computation processor addresses inefficiencies in handling sparse data by supporting multiple sparsity dimensions, optimizing resource usage and computational flexibility for diverse machine learning tasks.

WO2026081069A1PCT designated stage Publication Date: 2026-04-23MOFFETT TECH CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
MOFFETT TECH CO LTD
Filing Date
2024-10-15
Publication Date
2026-04-23

AI Technical Summary

Technical Problem

Current hardware solutions for machine learning are limited in handling varying degrees of sparsity in input activations, output activations, and weight or filter tensors, leading to inefficiencies and resource waste when processing sparse data.

Method used

A universal sparse tensor computation processor that supports tensor computations in multiple sparsity dimensions and modes, utilizing a tensor cache, gather and scatter circuits, and multiplier circuits to efficiently handle both dense and sparse tensors.

Benefits of technology

The processor optimizes resource usage and enhances computational flexibility, enabling efficient processing of both dense and sparse tensors across different stages of machine learning workflows, reducing computational delays and resource waste.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024124911_23042026_PF_FP_ABST
    Figure CN2024124911_23042026_PF_FP_ABST
Patent Text Reader

Abstract

A tensor processing circuit optimized for neural network computations is disclosed. The circuit comprises a tensor cache for storing weight and activation tensors, a tensor mask cache for tensor masks, and an accumulation cache. A gather circuit transforms dense tensors into condensed tensors based on the tensor masks. A scatter circuit reconstructs uncondensed tensors from condensed tensors. A control circuit manages the transformation of weight and activation tensors into condensed forms via the gather circuit. A multiplier circuit processes these condensed tensors to generate an intermediate tensor. An accumulating circuit produces an output tensor by combining the intermediate tensor with another tensor from the accumulation cache and writes it back. If the cached tensor is uncondensed, the intermediate tensor is converted back to an uncondensed form using the scatter circuit before generating the output tensor.
Need to check novelty before this filing date? Find Prior Art

Description

Tensor Processing UnitTECHNICAL FIELD

[0001] The present invention relates to the field of computer processors and machine learning, specifically to a universal tensor computing unit designed for efficient and flexible processing of tensor computations.BACKGROUND

[0002] In recent years, machine learning has become a cornerstone of technological advancement, driving innovations across various industries. The computational demands of training and deploying large-scale machine learning models have spurred the development of specialized hardware accelerators. While these accelerators offer substantial performance benefits, they primarily rely on dense computation, which often leads to inefficiencies when processing inherently sparse data.

[0003] Sparse computation, which focuses on optimizing operations that involve a significant number of zero or redundant elements, has emerged as a promising alternative to dense computation. By capitalizing on the natural sparsity found in many machine learning models, sparse computation can significantly reduce the computational resources required, resulting in faster processing times and lower power consumption.

[0004] Despite the advantages, current hardware solutions that support sparse computation are limited in functionality and performance, particularly in practical, real-world applications. Existing processors often struggle to efficiently handle the varying degrees of sparsity present in input activations, output activations, and weight or filter tensors.

[0005] The present disclosure addresses these challenges by introducing a universal sparse tensor computation processor that supports tensor computations in multiple sparsity dimensions and modes. This innovative processor is designed to provide greater computational flexibility, allowing it to efficiently handle tensor processing across different stages of machine learning workflows.SUMMARY

[0006] Various embodiments of the present specification may include processors and systems for support dual-sparse tensor computations in neural networks. A system composed of one or more computers can be configured to perform specific operations or actions by installing software, firmware, hardware, or a combination of these elements. This configuration enables the system to carry out the designated actions. Similarly, computer programs can be designed to perform particular operations by including instructions that, when executed by data processing apparatus, prompt the apparatus to execute these actions.

[0007] In one general aspect, a dual-sparse tensor processing circuit is described. The tensor processing circuit may include a tensor cache configured to cache a weight tensor and an activation tensor for neural network computation; a tensor mask cache configured to cache tensor masks; a gather circuit configured to transform a given dense tensor into a condensed tensor based on the tensor masks; a scatter circuit configured to scatter a given condensed tensor into an uncondensed tensor based on the tensor masks; a control circuit configured to transform the weight tensor and the activation tensor into condensed tensors using the gather circuit; a multiplier circuit configured to generate an intermediate tensor based on the condensed tensors, an accumulating circuit configured to generate an output tensor based on the intermediate tensor and another cached tensor from an accumulation cache, and write the output tensor back to the accumulation cache, wherein: in response to the other cached tensor from the accumulation cache being uncondensed, the intermediate tensor is transformed into an uncondensed tensor using the scatter circuit before generating the output tensor.

[0008] In some embodiments, to transform a condensed tensor into the uncondensed based on a given tensor mask, the scatter circuit is configured to: construct a tensor based on the given tensor mask, wherein the given tensor mask comprises a bitmask representing positions of non-zero values and zero values; and distribute data values in the condensed tensor into the constructed tensor according to the positions of the non-zero values.

[0009] In some embodiments, to transform the given dense tensor into the condensed tensor based on the given tensor mask, the gather circuit is configured to: identify effective non-zero values in the dense tensor based on positions of effective non-zero values in the given tensor mask, wherein the effective non-zero values are to be used in the subsequent neural network computation with a second tensor, and the given tensor mask is associated with the second tensor and comprises a bitmask representing the positions of non-zero values and zero values  in the second tensor; and construct the condensed tensor comprising only the effective non-zero values.

[0010] In some embodiments, the tensor cache comprises a first tensor cache and a second tensor cache, and the tensor mask cache comprises a first tensor mask cache and a second tensor mask cache, and the first tensor cache is configured to cache the activation tensor and the second tensor cache is configured to cache the weight tensor.

[0011] In some embodiments, the first tensor mask cache is configured to store an activation tensor bitmask when the activation tensor is sparse, and the second tensor mask cache is configured to store a weight tensor bitmask when the weight tensor is sparse.

[0012] In some embodiments, in response to that the weight tensor is pruned in an input channel direction and has a corresponding weight tensor mask, the control circuit is configured to: input the activation tensor and the weight tensor mask to the gather circuit to transform the activation tensor into a condensed activation tensor based on the weight tensor mask, wherein: the weight tensor comprises a condensed weight tensor that only stores non-zero weights, and the condensed weight tensor and the condensed activation tensor have a same shape.

[0013] In some embodiments, in response to that the weight tensor is pruned in an output channel direction and is stored as a condensed weight tensor, the control circuit is further configured to: transform the activation tensor into a condensed activation tensor using the broadcast function of the gather circuit, wherein the condensed activation tensor has a same shape as the condensed weight tensor, wherein the condensed weight tensor only stores non-zero weights; input the condensed activation tensor and the condensed weight tensor into the multiplier circuit to generate the intermediate tensor; and input the intermediate tensor and a weight tensor mask of the weight tensor to the scatter circuit to transform the intermediate tensor into the uncondensed tensor based on the weight tensor mask.

[0014] In some embodiments, in response to that the weight tensor is pruned in an input channel direction and has a weight tensor mask and a destination vector mask, the control circuit is configured to: input the activation tensor and the weight tensor mask (only non-zero positions in destination vector mask are activated in the weight tensor mask) into the gather circuit to transform the activation tensor into a condensed activation tensor; input the weight tensor and the destination vector mask into the gather circuit to transform the weight tensor into the condensed weight tensor, wherein the condensed activation tensor and the condensed weight tensor have a same shape; and distribute the condensed activation tensor and the condensed weight tensor into the multiplier circuit to generate the intermediate tensor.

[0015] In some embodiments, the weight tensor mask comprises a bitmask representing positions of non-zero values and zero values in the weight tensor, and the destination vector mask is a predicted mask that comprises a bitmask representing of positions non-zero values and zero values in the output tensor.

[0016] In some embodiments, in response to that the weight tensor is pruned in an output channel direction, the activation tensor has an activation tensor mask, the control circuit is configured to: transform the activation tensor into a condensed activation tensor; input the weight tensor and the weight tensor mask into the gather circuit to transform the weight tensor into a condensed weight tensor, wherein the condensed activation tensor and the condensed weight tensor have a same shape; distribute the condensed activation tensor and the condensed weight tensor into the multiplier circuit to generate the intermediate tensor; input the intermediate tensor and a destination vector mask into the scatter circuit to transform the intermediate tensor into the uncondensed format, wherein the destination vector mask is a predicted mask that comprises a bitmask representing of positions non-zero values and zero values in the output tensor; and input the uncondensed format of the intermediate tensor into the accumulating circuit to generate the output tensor.

[0017] In some embodiments, in response to that the activation tensor is sparse and has an activation tensor mask, the control circuit is configured to: transform the activation tensor into a condensed activation tensor; input the weight tensor, the activation tensor mask, and a destination vector mask into the gather circuit to transform the weight tensor into a condensed weight tensor, wherein the condensed activation tensor and the condensed weight tensor have a same shape, and the destination vector mask is a predicted mask that comprises a bitmask representing of positions non-zero values and zero values in the output tensor; and distribute the condensed activation tensor and the condensed weight tensor into the multiplier circuit to generate the intermediate tensor.

[0018] In some embodiments, in response to the activation tensor being condensed, the control circuit is configured to: scatter the activation tensor by inputting the activation tensor and a corresponding activation tensor mask into the scatter circuit to transform the activation tensor into an uncondensed format; scatter the weight tensor by inputting the weight tensor and a corresponding weight tensor mask into the scatter circuit to transform the weight tensor into the uncondensed format; and perform tensor computation based on the uncondensed format of the activation tensor and the uncondensed format of the weight tensor to generate the output tensor.

[0019] In some embodiments, the activation tensor is stored as a condensed activation tensor along with a corresponding activation tensor mask, thereby minimizing a memory footprint for caching the activation tensor.

[0020] In some embodiments, the weight tensor is stored as a condensed weight tensor along with a corresponding weight tensor mask, thereby minimizing a memory footprint for caching the weight tensor.

[0021] In some embodiments, the accumulating circuit comprises an adder tree to reduce the intermediate tensor to a format ready for accumulation with the other tensor from the accumulation cache.

[0022] In some embodiments, the accumulating circuit further comprises an accumulation adder configured to accumulate the reduced intermediate tensor with the other tensor from the accumulation cache.

[0023] In some embodiments, the output tensor is written from the accumulation cache back to a shared memory.

[0024] In some embodiments, the activation tensor is a condensed tensor and bypasses the gather circuit, but is replicated multiple times in the condensed tensor.

[0025] In some embodiments, the tensor processing circuit supports computation based on dense activation tensors, condensed activation tensors, dense weight tensors, and condensed weight tensors.

[0026] In another aspect, a method for dual-sparse tensor computation implemented by a tensor processing circuit is described. The method may include fetching an activation tensor and a weight tensor from a memory; in response to the weight tensor being sparse, obtaining a weight tensor mask of the weight tensor that indicates positions of non-zero weights; transforming the activation tensor to a condensed activation tensor using the weight tensor mask; transforming weight tensor into the condensed weight tensor having a same shape as the condensed the activation tensor; generating an intermediate tensor by distributing the condensed weight tensor and the condensed activation tensor to a plurality of the plurality to perform parallel computation; and inputting the intermediate tensor into an accumulating circuit to generate an output tensor.

[0027] In yet another aspect, a method for dual-sparse tensor computation implemented by a tensor processing circuit is described. The method may include fetching an activation tensor and a weight tensor from a memory; in response to the activation tensor being sparse, obtaining an activation tensor mask of the activation tensor; transforming the weight tensor into a condensed weight tensor using the activation tensor mask; transforming the activation  tensor into the condensed activation tensor having a same shape as the condensed weight tensor; distributing the condensed weight tensor and the condensed activation tensor to a plurality of the plurality to perform parallel computation, thereby generating an intermediate tensor; and inputting the intermediate tensor into an accumulating circuit to generate an output tensor.

[0028] Other embodiments of this method may include corresponding computer systems, apparatus, and computer programs recorded on one or more storage devices, each configured to perform these methods.

[0029] These and other features of the systems, methods, and non-transitory computer-readable media disclosed herein, as well as the methods of operation and functions of the related elements of structure and the combination of parts and economies of manufacture, will become more apparent upon consideration of the following description and the appended claims with reference to the accompanying drawings, all of which form a part of this specification, wherein like reference numerals designate corresponding parts in the various figures. It is to be expressly understood, however, that the drawings are for purposes of illustration and description only and are not intended as a definition of the limits of the invention.BRIEF DESCRIPTION OF THE DRAWINGS

[0030] FIG. 1 illustrates an exemplary system diagram of a neural network processing unit.

[0031] FIG. 2 illustrates an example Processing Entity (PE) in the neural network processing unit.

[0032] FIG. 3A illustrates an exemplary architectural diagram of a universal tensor computation processor supporting dual-sparse tensor operations, in accordance with various embodiments.

[0033] FIG. 3B illustrates a system diagram involving the universal tensor computation processor, in accordance with various embodiments.

[0034] FIG. 4 illustrates an exemplary data flow of a universal tensor computation processor, in accordance with various embodiments.

[0035] FIGs. 5-13 illustrate exemplary tensor processing using universal tensor computation processor, in accordance with various embodiments.

[0036] FIG. 14 illustrate a data preprocessing module of the universal tensor computation processor, in accordance with various embodiments.

[0037] FIG. 15 illustrate an example method of using the universal tensor computation processor for tensor computation, in accordance with various embodiments.

[0038] FIG. 16 illustrate another example method of using the universal tensor computation processor for tensor computation, in accordance with various embodiments.

[0039] FIG. 17 illustrates a table showing different sparse modes that are handled by the above-described universal tensor computation processor.

[0040] DETAIL DESCRIPTION OF THE EMBODIMENTS

[0041] Embodiments described herein provide methods, systems, apparatus for supporting both tensor computation using dense format and condensed format using a tensor computation processor.

[0042] This disclosure uses distinct types of tensors to help describe the invention, such as dense tensors, sparse tensors, condensed tensors, and sparse uncondensed tensors.

[0043] A dense tensor refers to a tensor in its original size, characterized by the number of elements and the bit-depth (precision) of these elements as received from upstream or downstream processing engines. The dense tensor may include high-magnitude data and low-magnitude data. When a dense tensor contains a large number of zero-valued data, it is called a sparse tensor.

[0044] The sparse tensor may be represented and stored in different data formats using a combination of a condensed tensor, a bitmask, and optional quantization information. A condensed tensor represents a compressed version of a given tensor, the bitmask maps the data in the condensed tensor with the original tensor, and the quantization information includes quantization parameters used when generating the condensed tensor from the original tensor.

[0045] In a narrow-sense sparse representation, the sparse representation of a sparse tensor may include a condensed tensor and a bitmask. The condensed tensor only stores non-zero elements from a sparse tensor, and the bitmask uses binary values to indicate the original positions of the non-zero elements in the given tensor. The condensed tensor in combination of the bitmask can be used to restore the given tensor. The restoration may be necessary for certain tensor operations (e.g., max or average pooling) or hardware processing units.

[0046] In a more general-sense sparse representation, the sparse representation of a sparse tensor may include a condensed tensor and a bitmask. The condensed tensor stores high-magnitude elements in the original tensor (e.g., a dense tensor) . The bitmask uses multi-bits  values to indicate not only the original positions of the high-magnitude elements in the original tensor, but also encoded value information of the low-magnitude elements in the original tensor. The “high-magnitude elements” refer to elements that exceed a value threshold, indicating significance of these elements for the tensor computation. The condensed tensor in combination of the multi-bit bitmask can be used to restore the given tensor.

[0047] In some embodiments, if quantization is performed when converting the given tensor into the corresponding condensed tensor, the quantization parameters (e.g., scale and bias) may be stored as part of the sparse representation in addition to the condensed tensor and the bitmask. While quantization reduces the data precision, the quantization parameters may be used to reverse (to some extent) the data precision when converting the condensed tensor back to its dense format.

[0048] The sparse uncondensed tensor is an expanded version of the condensed tensor. Elements from the condensed tensor are scattered and distributed into this larger tensor, which contains more positions or “spots” than the condensed tensor. Since the elements from the condensed tensor occupy only a subset of these spots, the remaining positions are filled with zero-valued elements, rendering the uncondensed tensor sparse.

[0049] In some scenarios, the dense tensor and the sparse uncondensed tensor share the same size and dimensions, while the condensed tensor has a smaller size. The bit-depth of the dense tensor is equal or higher than that of the condensed tensor. The bit-depth of the sparse uncondensed tensor may remain the same as that of the dense tensor.

[0050] In the current landscape of neural network processing, tensor computation plays a crucial role at various stages or layers, with each stage potentially requiring different formats or handling requirements for tensors. Sparsification is a commonly employed technique that compresses the input tensors to a condensed format, effectively reducing computation costs in terms of both time and resources while maintaining acceptable levels of accuracy. However, the diverse needs of neural network layers introduce complexity, as tensors can switch between the dense format and the sparse format as they pass through different stages of processing. For example, not all neural network operations or upstream hardware / accelerators are designed to handle sparse data natively. Many standard operations, such as max pooling and average pooling, as well as interactions with dense layers, require tensors in their original dense format.

[0051] Currently, tensor computation engines are typically optimized for one specific type of tensor format (either sparse or dense, but not both) . For example, engines designed to  efficiently process dense tensors excel in handling sparsity but may encounter difficulties when dealing with condensed tensors, leading to inefficiencies. In such cases, real-time sparsification processes may be required to convert condensed tensors into a dense format, which can introduce additional delays during training and inference, ultimately impacting performance. Conversely, engines optimized for condensed tensors can process such tensors swiftly but may waste significant resources and computational power when working with dense tensors, as they continue to process zero values that do not contribute to the final output.

[0052] Given these challenges, there is a clear need for a universal tensor computation processor that can efficiently handle both dense and sparse tensors across various stages of neural network processing, including the cases where the input tensors include one or more sparse tensors (e.g., dual-sparse) . Such a processor would optimize resource usage, ensuring that both dense and condensed tensors are processed with equal efficiency using the same piece of hardware, regardless of their format. This universal approach would significantly enhance the flexibility and performance of tensor computation systems, making them more suitable for the diverse and evolving requirements of modern neural networks.

[0053] The following description begins with FIG. 1 and FIG. 2, which provide background information on tensor computation and the associated hardware components, setting the stage for a comprehensive understanding of the universal tensor computation processor architecture illustrated in FIG. 3A. Additionally, the system diagram depicted in FIG. 4 further elucidates the overall design and functionality of the processor.

[0054] FIG. 1 illustrates an exemplary system diagram of a neural network (NN) processing unit 100. The neural network processing unit 100 in FIG. 1 may refer to a neural network accelerator or an NPU, e.g., a specialized microprocessor designed to accelerate machine learning and artificial intelligence (AI) tasks. Unlike traditional CPUs (Central Processing Units) and GPUs (Graphics Processing Units) , accelerators or NPUs are optimized specifically for the neural network operations such as convolution computations and vector operations..

[0055] The NN processing unit 100 illustrated in FIG. 1 includes a plurality of Processing Entities (PEs) that are designed to provide maximum parallelism to accelerate neural network operations. These PEs are organized in a 2D mesh network and interconnected via a network of routers (denoted as “R” in FIG. 1) . Additionally, the NN processing unit 100 incorporates double data rate (DDR) memory modules and caches, such as the last-level cache (LLC) , to support efficient data storage and retrieval. The NN processing unit 100 in FIG. 1 is merely  illustrative, and may comprise more, fewer, or alternative components. The accelerator 100 may be designed as a reconfigurable device such as a field-programmable gate array (FPGA) , or an application-specific integrated circuit (ASIC) . The dual-sparse SPU introduced in this disclosure may be implemented in a PE.

[0056] In some embodiments, to optimize resource utilization and enhance the parallel processing capabilities of the NN processing unit 100, the PEs within the 2D mesh network may be divided into multiple sections, with each section referred to as a core. As illustrated in FIG. 1, every group of 16 PEs (arranged in a 4x4 grid) constitutes a core, resulting in a total of four cores across the 64 PEs in the NN processing unit 100. Each core is equipped with dedicated DDR memory, LLC, and control circuits, including a RISC-V Vector Unit (RVV) , responsible for vector processing, Core-Level Scheduler (CoLS) , which manages the execution and synchronization of multiple PEs, and an Instruction Dispatch Unit (IDU) , which allocates instructions to various execution units within the accelerator. This architecture enables all four cores 110 (i.e., the four PE groups) to operate concurrently, ensuring efficient parallel processing.

[0057] In some embodiments, these cores 110 are further organized into a Network-on-Chip (NoC) for inter-core communication. For instance, in FIG. 1, the four groups of PEs are arranged as a ring NoC, facilitating seamless communication between cores and enhancing overall computational throughput. The ring NoC architecture includes a circular arrangement of cores 110, where data packets travel along a unidirectional or bidirectional ring, passing through each core 110 until they reach their destination. The ring NoC may be used for data communication between DDRs and PCIe or for PEs to read data from DDR belonging to other cores. In addition to the ring NoC, the PEs may be arranged as a 2D mesh NoC, managing the data communication between PEs.

[0058] Furthermore, the ring NoC architecture in FIG. 1 is scalable, allowing additional cores or PEs to be easily added to the ring without significantly increasing the complexity of the network. This flexibility supports the expansion of the NN processing unit to accommodate larger neural network models or additional computational tasks as needed.

[0059] The NN processing unit 100 illustrated in FIG. 1 may interact with an external (host) CPU through a peripheral component interconnect express (PCIe) . The NN processing unit 100 illustrated in FIG. 1 may further include an internal CPU to orchestra the cores with instructions, and a chip-level scheduler (ChLS) .

[0060] FIG. 2 illustrates an example Processing Entity (PE) 140 in the neural network processing unit. The PE 140 is an example of a PE within core 110 from FIG. 1. The internal  components of PE 140 depicted in FIG. 2 are for illustrative purposes, and the actual implementation may include additional, fewer, or alternative components depending on the specific design requirements.

[0061] In some embodiments, the PE 140 includes two NoC switches: a Data NoC Switch and a Cfg NoC Switch, both used to facilitate communication with other cores on the NoC. The Data NoC Switch is responsible for transmitting high-bandwidth data and instructions, ensuring efficient communication of tensor data and processing commands across the network. The Cfg NoC Switch is dedicated to handling configuration data, including parameters and setup information for the core and its functional modules. The wired connections to the Data NoC Switch are typically of higher bandwidth compared to those of the Cfg NoC Switch, reflecting the heavier data traffic load on the data path.

[0062] Additionally, PE 140 may include a scheduler that manages instruction issuance through an instruction interface, triggering various functional modules. These modules include the DMA (Direct Memory Access) module, which facilitates high-speed data transfer between memory and processing units without burdening the central processing core. The Sparse Processing Unit (SPU) performs tensor multiplication. The Vector Processing Unit (VPU) handles vectorized operations. The Activation Engine (AE) applies activation functions, including ReLU, sigmoid, or softmax, introducing non-linearity into the neural networks. The Transpose Engine (TE) performs tensor transposition, often required in matrix multiplications and other tasks that involve reordering data dimensions. The Sorting Engine (SE) is responsible for sorting tensor elements.

[0063] Furthermore, PE 140 incorporates a local RISC-V Vector (RVV) processing unit, such as a single-core RVV, which is optimized for executing vectorized instructions for neural network tasks. The RVV is coupled with TCM (Tightly Coupled Memory) , a high-speed, low-latency memory directly connected to the PE. This TCM allows the PE to store critical data and intermediate results for rapid access, minimizing latency and ensuring efficient execution of compute-intensive tasks such as matrix operations, convolutions, and tensor manipulations.

[0064] The universal tensor computation processor described below in this disclosure may be implemented as (or as a part of) the SPU in FIG. 2.

[0065] FIG. 3A illustrates an exemplary architectural diagram of a universal tensor computation processor supporting dual-sparse tensor operations, in accordance with various embodiments. For clarity of the description, the universal tensor computation processor is logically divided into two primary modules: a control module 300 and a computation module  270. In essence, the control module 300 is responsible for initializing, configuring, and managing the data flow within the computation module 270, while the computation module 270 executes the data processing tasks as directed by the control module 300.

[0066] In some embodiments, the control module 300 includes various components designed to manage and direct neural network computations. These components may include an instruction queue configured to receive computation instructions, such as memory addresses for input tensors, the type of computation to be performed, and the destination memory address for storing the output tensor. The control module 300 also comprises local (engine) registers, which serve as the interface for configuring the computation module 270, and an instruction parser for interpreting the instructions within the instruction queue. Additionally, the control module 300 includes a read / write controller that is used to get necessary data flow read / write control information from control / status registers (CSR) or instructions, a pipeline instruction buffer that acts as a staging area for buffering instructions, local registers that materialize the configurations specified by the engine, and pipeline controller responsible for executing the instructions fetched from the pipeline instruction buffer.

[0067] In some embodiments, the computation module 270 includes a plurality of components implementing distinct functionalities. As shown in FIG. 3A, a shared memory 322 may be configured to store tensors, including the input tensors (also called source tensors) entering the computation workflow and output tensors resulted from the computation workflow.

[0068] In some embodiments, multiple source tensor L1 caches are configured to fetch source tensors from the shared memory 322 for computation. As depicted in FIG. 3A, the source tensor 0 L1 cache 323 (denoted as Src Tensor 0 L1 Cache) and the Src Tensor 1 L1 cache are designed to cache the activation tensor (e.g., input feature maps (IFMs) ) and the filters (e.g., weight tensors) , respectively. These source tensor caches are complemented by corresponding source tensor mask caches, such as the source mask 0 L1 cache 324 and the source mask 1 L1 cache, which are configured to store the tensor masks for input tensors.

[0069] In practice, source tensors may be stored in either dense or sparse formats. When a source tensor is in a dense format, the data-whether activations or weights-is stored contiguously in the shared memory 322 for easy access.

[0070] Conversely, when a source tensor is in sparse format-by compressing the non-zero elements into a condensed tensor and using a tensor mask to indicate the positions of the non-zero and zero-valued elements-the storage scheme in shared memory 322 differs. The non- zero data elements of the condensed tensor are stored contiguously in shared memory 322 as a single data structure (also called a condensed tensor) , while the positional information of these elements is stored separately as a corresponding tensor mask.

[0071] In some embodiments, this tensor mask is implemented as a bitmask, using 1s and 0s to indicate the positions of the non-zero elements as well as the zero-valued elements. For instance, an 8x8 tensor containing 64-bit values would typically require 4096 bits (or 512 bytes) of memory, while the bitmask would only need 64 bits to represent the positions of the non-zero elements in the tensor.

[0072] In some embodiments, the computation module 270 may further include a scatter circuit 325 and a gather circuit 326. The scatter circuit 325 is configured to receive a tensor in its condensed format and a tensor mask from the first tensor mask cache 324 or the second tensor mask cache (denoted as Src mask 1 L1 Cache in FIG. 3A) , and transform the condensed tensor to an uncondensed tensor based on the tensor mask. The data in the condensed tensor are distributed in the uncondensed tensor based on the position information in the tensor mask, and the remaining spots in the uncondensed tensor are filled with zero-valued elements.

[0073] The gather circuit 326 is configured to receive a tensor-either dense or sparse-and a tensor mask from the first or second tensor mask cache, transforming the tensor into a condensed format. Specifically, the gather circuit identifies the "effective non-zero data" within the tensor based on the tensor mask, either along the input dimension (e.g., rows in a 2D tensor) or the output dimension (e.g., columns in a 2D tensor) , and constructs a condensed tensor that stores these data elements. In some embodiments, the gather circuit 326 may replicate, or "broadcast, " an effective non-zero data element multiple times in the condensed format if the tensor mask indicates it will be involved multiple times in the computation. Thus, the gather circuit sometimes performs not only "gathering" operations of the effective non-zero data but also "broadcasting" to generate the condensed tensor in the required shape. Examples in FIGs. 5-13 provide various use cases of the scatter circuit 325 and the gather circuit 326.

[0074] In some embodiments, the computation module 270 may further include a dual-scatter circuit 327 and a dual-gather circuit 328. The difference between the scatter circuit 325 and the dual-scatter circuit 327 is that the scatter circuit 325 performs the scattering operation based on a single tensor mask, whereas the dual-scatter circuit 327 works with two tensor masks at the same time. The same analogy applies to the gather circuit 326 and the dual-gather circuit 328.

[0075] The two tensor masks used in the dual-scatter circuit 327 and the dual-gather circuit 328 may include one native tensor mask (e.g., the mask comes with the input tensor) and a predicted tensor mask (also called destination vector mask) . In some cases, the predicted tensor mask represents the positions of non-zero data values in the expected output tensor.

[0076] In FIG. 3A, the computation module 270 may include an additional scatter circuit 330 such that the two input tensors may have their dedicate scatter circuit 330, allowing the scattering operations to be carried out in parallel. In some embodiments, the scatter circuit 325 and the scatter circuit 330 may refer to the same circuit.

[0077] In some embodiments, the computation module 270 may further include the hardware circuits for carrying out the actual computation, including the multiplier array 329, an adder tree 332, a scaling multiplier, a scaling factor L1 cache, and an accumulation L1 cache 334 for caching the intermediate tensors generated during the computation as well as the final output tensor.

[0078] The inclusion of the scatter circuit 325 and gather circuit 326, along with the potential dual-scatter circuit 327 and dual-gather circuit 328, enables the computation module 270 to handle input tensors with varying levels of sparsity and storage formats. These circuits also facilitate the generation of output tensors in specific formats tailored to subsequent operations, such as computations in the next layer of a neural network or as input tensors for another computation engine that requires a particular format.

[0079] By applying various combinations of these circuits to both the input and output tensors, the universal tensor computation processor depicted in FIG. 3A is capable of interfacing seamlessly with any upstream and downstream engines, effectively managing tensors in dense and condensed formats. This capability is further illustrated in FIG. 3B, where the tensor computation processor 360 is shown to accept any combination of input tensors from upstream engines 350 and generate output specified by downstream engines 380. This compatibility is made possible by the inclusion of these essential circuits, such as the scatter circuit 325, gather circuit 326, a MAC circuit 370 (Multiply-Accumulate Operation circuit) , and potentially the dual-scatter circuit 327 and dual-gather circuit 328.

[0080] FIG. 4 illustrates an exemplary data flow of a universal tensor computation processor, in accordance with various embodiments. The exemplary data flow in FIG. 4 includes several data paths that are optional, depending on the actual input tensors and corresponding masks. The data flow may be implemented by the universal tensor computation processor illustrated in FIG. 3A.

[0081] In FIG. 4, three major data paths are illustrated: (1) transforming the activation tensor into its condensed format (Condensed Data 0 in FIG. 4) ; (2) transforming the weight tensor into its condensed format (Condensed Data 1 in FIG. 4) ; and (3) transforming the intermediate tensor generated by the Multiplier Array (MUL array) into its uncondensed format, if necessary.

[0082] It is important to note that the universal tensor computation processor may require both input tensors to be transformed into their condensed formats before performing parallel computations using the MUL array. This transformation is essential for minimizing cache accesses, allowing the processor to directly compute on the effective activation data and weights, thereby maximizing computational efficiency.

[0083] The condensed formats of the activation tensor and the weight tensor share the same shape. The MUL array performs element-wise computations on these two condensed tensors, significantly reducing complexity by eliminating the need for cache accesses due to the prior tensor transformation.

[0084] Data Path (1) : transforming the activation tensor to its condensed format (i.e., Condensed Data 0 in FIG. 4)

[0085] The end-result of this data path is to obtain the condensed format of the activation tensor.

[0086] If (1) the activation tensor is in its condensed format when received and (2) the activation tensor mask is same as the weight tensor mask, it is already the condensed tensor in the required shape for computation, thus it can be directly input into the MUL array. Here, the activation tensor is in its condensed format when it is sparse and represented using the “condensed tensor and tensor mask” combination. When the activation tensor mask is same as the weight tensor mask, the effective activations of the activation tensor do not need to be broadcasted (because the condensed activation tensor and the condensed weight tensor will be in the same shape) . That is, when the two masks are the same, the activation data in the condensed format will be all effective and contribute to the computation.

[0087] If the activation tensor is in its condensed format but the activation tensor mask is different from the weight tensor mask the activation tensor, it may go through the scatter circuit first to revert back to its uncondensed format using its activation tensor mask (i.e., A-Tensor Mask) , and then go through the gather circuit to identify the effective tensor data for the computation using the weight tensor mask (i.e., W-Tensor Mask) .

[0088] If the activation tensor is in its dense format, it may skip the scatter step and directly go into the gather and broadcast step to form its condensed representation.

[0089] Data Path (2) : transforming the weight tensor to its condensed format (i.e., Condensed Data 1 in FIG. 4)

[0090] The end-result of this data path (2) is to obtain the condensed format of the weight tensor.

[0091] If the weight tensor is in its condensed format when received, it can be directly input into the MUL array. Here, the weight tensor is in its condensed format when its effective weights are already identified according to the corresponding non-zero activations in the activation tensor.

[0092] If the weight tensor is in its dense format it may go through the gather circuit to identify the effective weights for the computation using the activation tensor mask (i.e., A-Tensor Mask) .

[0093] In some embodiments, the gathering step and the subsequent broadcasting step on the weight tensor may rely on both the activation tensor mask (A-Tensor Mask) and a predicted destination vector mask (Dst Vector Mask) . The two masks work collectively to predict the “effective” weights and gather them into the condensed format of the weight tensor. This process may use the dual-gather circuit described in FIG. 3A. More details on these scenarios are described in FIG. 12 and FIG. 13.

[0094] Based on the above description, it is clear that the tensor masks, including the A-Tensor Mask, the W-Tensor Mask, and the Dst Vector Mask may work together in the process of scattering, gathering, and broadcasting. For simplicity, FIG. 4 uses an “intersection Mask” to represent the combination of one or more of the above-listed tensor masks.

[0095] Data Path (3) : transforming the intermediate tensor generated by the MUL array (i.e., Multiplier Array) to its dense format if needed

[0096] After the condensed activation tensor and the condensed weight tensor go through the multiplier array, the generated intermediate tensor may be in a condensed format that has the same shape as the condensed activation tensor and the condensed weight tensor. This intermediate tensor will need to be accumulated with another intermediate tensor (previous computed and / or stored in the accumulation cache) through the Adder Tree. In some cases, the other intermediate tensor may be in an uncondensed format (e.g., a dense tensor) , which makes it necessary to convert the condensed intermediate tensor to its uncondensed format in order to perform the element-wise accumulation. The scatter circuit may be used in this case to perform the transformation from the condensed format to the uncondensed format using the Intersection Mask, i.e., the combination of one or more of the A-Tensor Mask, W-Tensor Mask, and the Dst Vector Mask.

[0097] Once the accumulation is performed, the generated tensor may be stored in the accumulation cache for the next round of computation (as “the other” intermediate tensor in the next round) , or output to the shared memory as the output tensor.

[0098] Note that data path (3) may be optional if the intermediate tensor can be directly used for accumulation. For example, if the intermediate tensor has the same shape as “the other” intermediate tensor from the accumulation cache, the accumulation can be executed directly.

[0099] FIGs. 5-13 illustrate exemplary tensor processing using universal tensor computation processor, in accordance with various embodiments. The universal tensor processing circuit supports computation based on dense activation tensors, condensed activation tensors, dense weight tensors, and condensed weight tensors. In actual computations, tensor multiplication is performed on tensors, but because the outer dimensions are serially processed and multiple computing units work in parallel, the processing of each vector is identical. The diagrams in the following description use activation vector (representing the activation tensor) multiplied by weight tensor as an example. In these figures, the dark-colored grid cells refer to non-zero values (or 1s in masks) , and white grid cells refer to zeros.

[0100] FIG. 5 illustrates a case where both the activation vector and the weight tensor are dense with all effective tensor data (e.g., all elements are non-zero) . Since the weight tensor is not sparse, all the non-zero data in the activation tensor are effective activations for computation. In this case, the activation tensor may go through a broadcast step to replicate itself to a tensor of the same shape as the weight tensor. As shown in FIG. 5, the weight tensor is already in its condensed format, and the activation tensor is broadcasted and transformed into its condensed format of the same shape. Both condensed tensors are input into the MUL array for generating the intermediate tensor. The intermediate tensor also has the same shape as the condensed activation and weight tensors. The intermediate tensor may then go through the accumulation process with another tensor (e.g., from the previous round of computation or from another parallel computation) to obtain the output tensor.

[0101] FIG. 6 illustrates a case where the activation vector is non-sparse, and the weight tensor is sparsified by input channels and represented in a condensed format (using a condensed tensor and a corresponding tensor mask) . In this particular case, the weight tensor is pruned by its input channels (e.g., the row directions) such that each row of the weight tensor contains the same number of non-zero weights. This is called balanced-sparsification, which balances the computation workloads on the plurality of multipliers (MULs) when the computation is distributed. As shown in FIG. 2, the weight tensor is already in its condensed  format (Condensed Data 1) by compressing the non-zero weights in the input channels. On the other hand, the activation vector is transformed using the gather circuit based on the weight tensor mask. The weight tensor mask indicates the positions of the non-zero weights, and the gather circuit identifies the “effective activations” in the activation vector that correspond to the non-zero weights. The result of the gathering step is the condensed activation data (Condensed Data 0) . Note that the Condensed Data 0 and Condensed Data 1 have the same shape. Subsequently, the condensed data is fed in to the MUL Array and the Adder Tree for computation.

[0102] FIG. 7 illustrates a case where the weight tensor is pruned in its output channel directions (each column in the weight tensor has the same number of non-zero weights) and is already represented in a condensed format, and the activation vector is non-sparse. As shown in FIG. 7, all the non-zero weights in the weight tensor are compressed in the output channel direction into the condensed data 1, and the activation vector goes through the broadcast process to duplicate the non-zero activations into the condensed data 0, which has the same shape as the condensed data 1. The “broadcast” function may be implemented as part of the gather circuit or a standard along logic outside of the gather circuit.

[0103] Subsequently, the two condensed data are fed into the MUL Array for tensor multiplication. The intermediate tensor generated by the MUL Array is in its condensed format having the same shape as the condensed data 0 and condensed data 1. In this particular case, the intermediate tensor goes through the scatter circuit to be converted into the uncondensed format using the weight tensor mask (i.e., the bitmask) . This is because the non-zero data in the intermediate tensor are compressed in the output channel direction, but the accumulation process needs to the non-zero data to be restored to their proper positions in the input channel direction (i.e., to be placed in the proper position in each row, so that the non-zero data in the same input channel can be accumulated) . After the scattering process, the condensed intermediate tensor is transformed back to the dense format having the same shape as the dense format of the weight tensor. The uncondensed intermediate tensor enters the Adder Tree to generate the reduced vector by adding up the non-zero data in each input channel (row) . The reduced vector and another accumulate vector from the cache then enter the accumulation adder to generate the output tensor.

[0104] FIG. 8 illustrates a weight and activation mixed sparse scenario in which two masks are involved. In particular, FIG. 8 shows the weight tensor being sparse (represented in a condensed format) . A person skilled in the art would understand the process and apply it to the cases where the activation tensor is sparse (and represented in a condensed format) .

[0105] In FIG. 8, the first mask is the weight tensor mask indicating the positions of non-zero weights in the weight tensor. The other mask is the predicted destination vector mask indicating possible positions of non-zero data in the output tensor. This prediction can be performed using neural network trained based on historical tensor computations. In FIG. 8, the activation tensor is transformed into its condensed format (condensed data 0) using the gather circuit based on the selected weight tensor mask (based on the non-zero positions in destination vector mask) , and the weight tensor (the non-zero weights are compressed in the input channel direction, i.e., by rows) is transformed into its condensed format (condensed data 1) using the gather circuit based on the predicted destination vector mask. The condensed data 0 and condensed data 1 have the same shape. After the MUL Array generates the intermediate tensor (condensed) based on the condensed data 0 and condensed data 1, the destination vector mask is used to convert the condensed intermediate tensor to its dense format, thereby restoring the position information of the non-zero data in the output channel direction (by columns) . The rest of the accumulation process is similar to previous embodiments.

[0106] FIG. 9 illustrates a similar scenario as FIG. 8. The difference is that in FIG. 9, the accumulate vector from the cache is also in its condensed format, and the output tensor is also required to be in its condensed format. In this case, the condensed intermediate tensor generated by the MUL Array may be directly used in the accumulation and skip the scattering process.

[0107] FIG. 10 illustrates a scenario in which the activation vector is sparse (e.g., represented in an uncondensed format) and has its corresponding activation vector mask, and the weight tensor is pruned in its output channel direction (each column has the same number of non-zero weights) . The activation vector goes through the gather circuit with the activation vector mask and is converted into condensed data 0. In particular, the “gather” circuit in FIG. 10 performs both gathering step (gathering the effective activations indicated by the mask) and broadcasting step (broadcasting the gathered activations such that the resultant condensed data 0 is the same shape as the condensed data 1) . The weight tensor goes through the gather circuit with the activation vector mask and is converted into condensed data 1. The condensed data 0 and 1 enter the MUL Array to generate the condensed intermediate tensor, which is then scattered using the scatter circuit based on the predicted destination vector mask. The scattering process restores the non-zero data in the condensed intermediate tensor to the corresponding positions in each output channel (column) . The resultant dense intermediate tensor enters the accumulation process similar to the previous embodiments.

[0108] FIG. 11 illustrates a scenario similar to FIG. 10. The difference is that the activation vector in FIG. 11 is in its condensed format. However, the condensed format of the activation vector is different from the condensed format of the weight tensor (condensed data 1 in FIG. 11) , the activation vector needs to go through another transformation, i.e., broadcast (by replicating itself multiple times) , in order to make the pair of tensors in the same shape. Therefore, the activation vector is broadcasted into its condensed data 0 in FIG. 11, rather than going through the gathering circuit to generate the condensed data 0. The rest of the process is similar to FIG. 10.

[0109] FIG. 12 illustrates a scenario in which the activation vector is in its condensed format and has its corresponding activation vector mask, and transformed into its condensed format (condensed data 0) via broadcasting. The weight tensor in this case is not sparse, and is transformed into its condensed format (condensed data 1) using the dual-gather circuit based on the activation vector mask and the predicted destination vector mask. That is, only part of the non-zero data in the weight tensor are the “effective weights” according to the masks. The rest of the process is similar to the previous embodiments (no scattering is performed on the intermediate tensor because the output tensor is required to be in its condensed format) .

[0110] FIG. 13 illustrates a scenario in which the activation vector is sparse and represented using an uncondensed tensor. The activation vector has a corresponding bitmask as its activation vector mask. The activation vector goes through the gather circuit with the predicted destination vector mask to generate the condensed data 0. Here, the gather circuit gathers the effective activations based on the activation mask, and broadcasts the gathered activations for n times, wherein n is the non-zero number in the destination mask. The weight tensor goes through the dual gather circuit with the activation vector mask and the predicted destination vector mask to generate the condensed data 1. The result of the process is similar to FIG. 10.

[0111] FIG. 14 illustrate a data preprocessing module of the universal tensor computation processor, in accordance with various embodiments. The preprocessing module is configured to transform the condensed activation vector and the condensed weight tensor into their uncondensed format using their respective masks. This preprocessing unifies the format of the input tensors to the subsequent pipelines, which simplifies the control logic for the MUL Array and the accumulation circuits.

[0112] In the current design, the input channels of the weight tensor and the activation vector cannot both be in a sparse format simultaneously to achieve computational  acceleration. Simultaneous sparsity in both tensors complicates the computation process and prevents acceleration benefits. However, when both tensors are in sparse formats, the preprocessing module can restore one of them to its uncondensed format. By converting one tensor back to its uncondensed format, the processor can perform sparse computation acceleration on the other tensor as originally intended. This approach not only maintains the computational acceleration from sparsity in one tensor but also leverages the I / O transmission acceleration gained from the sparsity of both input tensors. Consequently, even though one tensor is uncondensed, the system benefits from reduced data transmission requirements and improved overall efficiency.

[0113] FIG. 15 is a flowchart of an example process 1500. In some implementations, one or more process blocks of FIG. 15 may be performed by a device (such as the device illustrated in FIG. 3A) .

[0114] As shown in FIG. 15, process 1500 may include fetching an activation tensor and a weight tensor from a memory (block 1510) . For example, the device may fetch an activation tensor and a weight tensor from a memory, as described above.

[0115] As also shown in FIG. 15, process 1500 may include in response to the weight tensor being sparse, obtaining a weight tensor mask of the weight tensor that indicates positions of non-zero weights (block 1520) . For example, the device may, in response to the weight tensor being sparse, obtain a weight tensor mask of the weight tensor that indicates positions of non-zero weights, as described above.

[0116] As further shown in FIG. 15, process 1500 may include transforming the activation tensor to a condensed format using the weight tensor mask (block 1530) . For example, the device may transform the activation tensor to a condensed format using the weight tensor mask, as described above.

[0117] As also shown in FIG. 15, process 1500 may include transforming weight tensor into the condensed format having a same shape as the condensed format of the activation tensor (block 1540) . For example, the device may transform weight tensor into the condensed format having a same shape as the condensed format of the activation tensor, as described above.

[0118] As further shown in FIG. 15, process 1500 may include generating an intermediate tensor by distributing the condensed format of the weight tensor and the condensed format of the activation tensor to a plurality of the plurality to perform parallel computation (block 1550) . For example, the device may generate an intermediate tensor by distributing the  condensed format of the weight tensor and the condensed format of the activation tensor to a plurality of the plurality to perform parallel computation, as described above.

[0119] As also shown in FIG. 15, process 1500 may include inputting the intermediate tensor into an accumulating circuit to generate an output tensor (block 1560) . For example, the device may input the intermediate tensor into an accumulating circuit to generate an output tensor, as described above.

[0120] Although FIG. 15 shows example blocks of process 1500, in some implementations, process 1500 may include additional blocks, fewer blocks, different blocks, or differently arranged blocks than those depicted in FIG. 15. Additionally, or alternatively, two or more of the blocks of process 1500 may be performed in parallel.

[0121] FIG. 16 is a flowchart of an example process 1600. In some implementations, one or more process blocks of FIG. 16 may be performed by a device (such as the device illustrated in FIG. 3A) .

[0122] As shown in FIG. 16, process 1600 may include fetching an activation tensor and a weight tensor from a memory (block 1610) . For example, the device may fetch an activation tensor and a weight tensor from a memory, as described above.

[0123] As also shown in FIG. 16, process 1600 may include determining the activation tensor being sparse, (block 1620) . For example, the device may determine that the activation tensor is sparse, as described above.

[0124] As further shown in FIG. 16, process 1600 may include obtaining an activation tensor mask of the activation tensor (block 1630) . For example, the device may obtain an activation tensor mask of the activation tensor, as described above.

[0125] As also shown in FIG. 16, process 1600 may include transforming the weight tensor into a condensed format using the activation tensor mask (block 1640) . For example, the device may transform the weight tensor into a condensed format using the activation tensor mask, as described above.

[0126] As further shown in FIG. 16, process 1600 may include transforming the activation tensor into the condensed format having a same shape as the condensed format of the weight tensor (block 1650) . For example, the device may transform the activation tensor into the condensed format having a same shape as the condensed format of the weight tensor, as described above.

[0127] As also shown in FIG. 16, process 1600 may include distributing the condensed format of the weight tensor and the condensed format of the activation tensor to a plurality of the plurality to perform parallel computation, thereby generating an intermediate tensor  (block 1660) . For example, the device may distribute the condensed format of the weight tensor and the condensed format of the activation tensor to a plurality of the plurality to perform parallel computation, thereby generating an intermediate tensor, as described above.

[0128] As further shown in FIG. 16, process 1600 may include inputting the intermediate tensor into an accumulating circuit to generate an output tensor (block 1670) . For example, the device may input the intermediate tensor into an accumulating circuit to generate an output tensor, as described above.

[0129] Although FIG. 16 shows example blocks of process 1600, in some implementations, process 1600 may include additional blocks, fewer blocks, different blocks, or differently arranged blocks than those depicted in FIG. 16. Additionally, or alternatively, two or more of the blocks of process 1600 may be performed in parallel.

[0130] FIG. 17 illustrates a table showing different sparse modes that are handled by the above-described universal tensor computation processor. The diagram illustrates various modes of sparsity configurations supported by a processor for neural network computations. It categorizes these configurations based on how sparsity is applied to both input and output channels, which can affect the efficiency and performance of the processor when handling neural network operations.

[0131] The matrix is divided into four main categories: Dense, Weight Sparse, Activation Sparse, and Mixed Sparse. The Dense mode is the standard configuration where neither the weights nor the activations are sparse, meaning the processor uses the full set of weights and activations for computations without any zero values or omissions. This mode is straightforward but does not offer the benefits of reduced computational complexity that come with sparse configurations.

[0132] The Weight Sparse mode, on the other hand, indicates that the weights in the neural network are sparse, implying that certain weights are set to zero or ignored. This reduces the number of operations required during computation, saving processing time and power. Similarly, the Activation Sparse mode means that some activations are zero, allowing the processor to skip over these values, which also improves efficiency.

[0133] The Mixed Sparse category represents a hybrid mode where both weights and activations are sparse, but it is further divided based on whether the sparsity is applied to the input or output channels. This category includes configurations where sparsity is considered either for the input channels or the output channels, allowing for nuanced control over how sparsity is managed during computation.

[0134] The matrix also shows an Undefined entry, which indicates that a specific configuration-where a weight output channel interacts with a weight input channel-is not supported by this processor. This could be due to the lack of a clear definition or practical implementation for this particular interaction.

[0135] The performance of certain of the operations may be distributed among the processors, not only residing within a single machine, but deployed across a number of machines. In some example embodiments, the processors or processor-implemented engines may be located in a single geographic position (e.g., within a home environment, an office environment, or a server farm) . In other example embodiments, the processors or processor-implemented engines may be distributed across a number of geographic positions.

[0136] Each of the processes, methods, and algorithms described in the preceding sections may be embodied in, and fully or partially automated by, code modules executed by one or more computer systems or computer processors comprising computer hardware. The processes and algorithms may be implemented partially or wholly in application-specific circuit.

[0137] When the functions disclosed herein are implemented in the form of software functional units and sold or used as independent products, they can be stored in a processor executable non-volatile computer-readable storage medium. Particular technical solutions disclosed herein (in whole or in part) or aspects that contributes to current technologies may be embodied in the form of a software product. The software product may be stored in a storage medium, comprising a number of instructions to cause a computing device (which may be a personal computer, a server, a network device, and the like) to execute all or some steps of the methods of the embodiments of the present application. The storage medium may comprise a flash drive, a portable hard drive, ROM, RAM, a magnetic disk, an optical disc, another medium operable to store program code, or any combination thereof.

[0138] Particular embodiments further provide a system comprising a processor and a non-transitory computer-readable storage medium storing instructions executable by the processor to cause the system to perform operations corresponding to steps in any method of the embodiments disclosed above. Particular embodiments further provide a non-transitory computer-readable storage medium configured with instructions executable by one or more processors to cause the one or more processors to perform operations corresponding to steps in any method of the embodiments disclosed above.

[0139] Embodiments disclosed herein may be implemented through a cloud platform, a server or a server group (hereinafter collectively the “service system” ) that interacts with a  client. The client may be a terminal device, or a client registered by a user at a platform, wherein the terminal device may be a mobile terminal, a personal computer (PC) , and any device that may be installed with a platform application program.

[0140] The various features and processes described above may be used independently of one another or may be combined in various ways. All possible combinations and sub-combinations are intended to fall within the scope of this disclosure. In addition, certain method or process blocks may be omitted in some implementations. The methods and processes described herein are also not limited to any particular sequence, and the blocks or states relating thereto can be performed in other sequences that are appropriate. For example, described blocks or states may be performed in an order other than that specifically disclosed, or multiple blocks or states may be combined in a single block or state. The example blocks or states may be performed in serial, in parallel, or in some other manner. Blocks or states may be added to or removed from the disclosed example embodiments. The exemplary systems and components described herein may be configured differently than described. For example, elements may be added to, removed from, or rearranged compared to the disclosed example embodiments.

[0141] The various operations of exemplary methods described herein may be performed, at least partially, by an algorithm. The algorithm may be comprised in program codes or instructions stored in a memory (e.g., a non-transitory computer-readable storage medium described above) . Such algorithm may comprise a machine learning algorithm. In some embodiments, a machine learning algorithm may not explicitly program computers to perform a function but can learn from training samples to make a prediction model that performs the function.

[0142] The various operations of exemplary methods described herein may be performed, at least partially, by one or more processors that are temporarily configured (e.g., by software) or permanently configured to perform the relevant operations. Whether temporarily or permanently configured, such processors may constitute processor-implemented engines that operate to perform one or more operations or functions described herein.

[0143] Similarly, the methods described herein may be at least partially processor-implemented, with a particular processor or processors being an example of hardware. For example, at least some of the operations of a method may be performed by one or more processors or processor-implemented engines. Moreover, the one or more processors may also operate to support performance of the relevant operations in a “cloud computing” environment or as a “software as a service” (SaaS) . For example, at least some of the  operations may be performed by a group of computers (as examples of machines including processors) , with these operations being accessible via a network (e.g., the Internet) and via one or more appropriate interfaces (e.g., an Application Program Interface (API) ) .

[0144] The performance of certain of the operations may be distributed among the processors, not only residing within a single machine, but deployed across a number of machines. In some example embodiments, the processors or processor-implemented engines may be located in a single geographic position (e.g., within a home environment, an office environment, or a server farm) . In other example embodiments, the processors or processor-implemented engines may be distributed across a number of geographic positions.

[0145] Throughout this specification, plural instances may implement components, operations, or structures described as a single instance. Although individual operations of one or more methods are illustrated and described as separate operations, one or more of the individual operations may be performed concurrently, and nothing requires that the operations be performed in the order illustrated. Structures and functionality presented as separate components in example configurations may be implemented as a combined structure or component. Similarly, structures and functionality presented as a single component may be implemented as separate components. These and other variations, modifications, additions, and improvements fall within the scope of the subject matter herein.

[0146] As used herein, “or” is inclusive and not exclusive, unless expressly indicated otherwise or indicated otherwise by context. Therefore, herein, “A, B, or C” means “A, B, A and B, A and C, B and C, or A, B, and C, ” unless expressly indicated otherwise or indicated otherwise by context. Moreover, “and” is both joint and several, unless expressly indicated otherwise or indicated otherwise by context. Therefore, herein, “Aand B” means “Aand B, jointly or severally, ” unless expressly indicated otherwise or indicated otherwise by context. Moreover, plural instances may be provided for resources, operations, or structures described herein as a single instance. Additionally, boundaries between various resources, operations, engines, and data stores are somewhat arbitrary, and particular operations are illustrated in a context of specific illustrative configurations. Other allocations of functionality are envisioned and may fall within a scope of various embodiments of the present disclosure. In general, structures and functionality presented as separate resources in the example configurations may be implemented as a combined structure or resource. Similarly, structures and functionality presented as a single resource may be implemented as separate resources. These and other variations, modifications, additions, and improvements fall within a scope of embodiments of the present disclosure as represented by the appended claims. The  specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense.

[0147] The term “include” or “comprise” is used to indicate the existence of the subsequently declared features, but it does not exclude the addition of other features. Conditional language, such as, among others, “can, ” “could, ” “might, ” or “may, ” unless specifically stated otherwise, or otherwise understood within the context as used, is generally intended to convey that certain embodiments include, while other embodiments do not include, certain features, elements and / or steps. Thus, such conditional language is not generally intended to imply that features, elements and / or steps are in any way required for one or more embodiments or that one or more embodiments necessarily include logic for deciding, with or without user input or prompting, whether these features, elements and / or steps are included or are to be performed in any particular embodiment.

[0148] Although an overview of the subject matter has been described with reference to specific example embodiments, various modifications and changes may be made to these embodiments without departing from the broader scope of embodiments of the present disclosure. Such embodiments of the subject matter may be referred to herein, individually or collectively, by the term “invention” merely for convenience and without intending to voluntarily limit the scope of this application to any single disclosure or concept if more than one is, in fact, disclosed.

[0149] The embodiments illustrated herein are described in sufficient detail to enable those skilled in the art to practice the teachings disclosed. Other embodiments may be used and derived therefrom, such that structural and logical substitutions and changes may be made without departing from the scope of this disclosure. The Detailed Description, therefore, is not to be taken in a limiting sense, and the scope of various embodiments is defined only by the appended claims, along with the full range of equivalents to which such claims are entitled.

Claims

1.A tensor processing circuit, comprising:a tensor cache configured to cache a weight tensor and an activation tensor for neural network computation;a tensor mask cache configured to cache tensor masks;a gather circuit configured to transform a given dense tensor into a condensed tensor based on the tensor masks;a scatter circuit configured to scatter a given condensed tensor into an uncondensed tensor based on the tensor masks;a control circuit configured to transform the weight tensor and the activation tensor into condensed tensors using the gather circuit;a multiplier circuit configured to generate an intermediate tensor based on the condensed tensors,an accumulating circuit configured to generate an output tensor based on the intermediate tensor and another cached tensor from an accumulation cache, and write the output tensor back to the accumulation cache, wherein:in response to the other cached tensor from the accumulation cache being uncondensed, the intermediate tensor is transformed into an uncondensed tensor using the scatter circuit before generating the output tensor.2.The tensor processing circuit of claim 1, wherein to transform a condensed tensor into the uncondensed based on a given tensor mask, the scatter circuit is configured to:construct a tensor based on the given tensor mask, wherein the given tensor mask comprises a bitmask representing positions of non-zero values and zero values; anddistribute data values in the condensed tensor into the constructed tensor according to the positions of the non-zero values.3.The tensor processing circuit of claim 1, wherein to transform the given dense tensor into the condensed tensor based on the given tensor mask, the gather circuit is configured to:identify effective non-zero values in the dense tensor based on positions of effective non-zero values in the given tensor mask, wherein the effective non-zero values are to be used in the subsequent neural network computation with a second tensor, and the given tensor mask is associated with the second tensor and comprises a bitmask representing the positions of non-zero values and zero values in the second tensor; andconstruct the condensed tensor comprising only the effective non-zero values.4.The tensor processing circuit of claim 1, wherein the tensor cache comprises a first tensor cache and a second tensor cache, and the tensor mask cache comprises a first tensor mask cache and a second tensor mask cache, andthe first tensor cache is configured to cache the activation tensor and the second tensor cache is configured to cache the weight tensor.5.The tensor processing circuit of claim 4, wherein:the first tensor mask cache is configured to store an activation tensor bitmask when the activation tensor is sparse, andthe second tensor mask cache is configured to store a weight tensor bitmask when the weight tensor is sparse.6.The tensor processing circuit of claim 1, wherein in response to that the weight tensor is pruned in an input channel direction and has a corresponding weight tensor mask, the control circuit is configured to:input the activation tensor and the weight tensor mask to the gather circuit to transform the activation tensor into a condensed activation tensor based on the weight tensor mask, wherein:the weight tensor comprises a condensed weight tensor that only stores non-zero weights, andthe condensed weight tensor and the condensed activation tensor have a same shape.7.The tensor processing circuit of claim 1, wherein in response to that the weight tensor is pruned in an output channel direction and is stored as a condensed weight tensor, the control circuit is further configured to:transform the activation tensor into a condensed activation tensor using the broadcast circuit, wherein the condensed activation tensor has a same shape as the condensed weight tensor, wherein the condensed weight tensor only stores non-zero weights;input the condensed activation tensor and the condensed weight tensor into the multiplier circuit to generate the intermediate tensor; andinput the intermediate tensor and a weight tensor mask of the weight tensor to the scatter circuit to transform the intermediate tensor into the uncondensed tensor based on the weight tensor mask.8.The tensor processing circuit of claim 1, wherein in response to that the weight tensor is pruned in an input channel direction and has a weight tensor mask and a destination vector mask, the control circuit is configured to:input the activation tensor and the weight tensor mask into the gather circuit to transform the activation tensor into a condensed activation tensor;input the weight tensor and the destination vector mask into the gather circuit to transform the weight tensor into a condensed weight tensor, wherein the condensed activation tensor and the condensed weight tensor have a same shape; anddistribute the condensed activation tensor and the condensed weight tensor into the multiplier circuit to generate the intermediate tensor.9.The tensor processing circuit of claim 8, wherein:the weight tensor mask comprises a bitmask representing positions of non-zero values and zero values in the weight tensor, andthe destination vector mask is a predicted mask that comprises a bitmask representing of positions non-zero values and zero values in the output tensor.10.The tensor processing circuit of claim 1, wherein in response to that the weight tensor is pruned in an output channel direction, the activation tensor has an activation tensor mask, the control circuit is configured to:transform the activation tensor into a condensed activation tensor;input the weight tensor and the weight tensor mask into the gather circuit to transform the weight tensor into a condensed weight tensor, wherein the condensed activation tensor and the condensed weight tensor have a same shape;distribute the condensed activation tensor and the condensed weight tensor into the multiplier circuit to generate the intermediate tensor;input the intermediate tensor and a destination vector mask into the scatter circuit to transform the intermediate tensor into the uncondensed format, wherein the destination vector mask is a predicted mask that comprises a bitmask representing of positions non-zero values and zero values in the output tensor; andinput the uncondensed format of the intermediate tensor into the accumulating circuit to generate the output tensor.11.The tensor processing circuit of claim 1, wherein in response to that the activation tensor is sparse and has an activation tensor mask, the control circuit is configured to:transform the activation tensor into a condensed activation tensor;input the weight tensor, the activation tensor mask, and a destination vector mask into the gather circuit to transform the weight tensor into a condensed weight tensor, wherein the condensed activation tensor and the condensed weight tensor have a same shape, and the destination vector mask is a predicted mask that comprises a bitmask representing of positions non-zero values and zero values in the output tensor; anddistribute the condensed activation tensor and the condensed weight tensor into the multiplier circuit to generate the intermediate tensor.12.The tensor processing circuit of claim 1, wherein in response to the activation tensor and the weight tensor being condensed, the control circuit is configured to:scatter the activation tensor by inputting the activation tensor and a corresponding activation tensor mask into the scatter circuit to transform the activation tensor into an uncondensed format;scatter the weight tensor by inputting the weight tensor and a corresponding weight tensor mask into the scatter circuit to transform the weight tensor into the uncondensed format; andperform tensor computation based on the uncondensed format of the activation tensor or the uncondensed format of the weight tensor to generate the output tensor.13.The tensor processing circuit of claim 1, wherein:the activation tensor is stored as a condensed activation tensor along with a corresponding activation tensor mask, thereby minimizing a memory footprint for caching the activation tensor, andthe weight tensor is stored as a condensed weight tensor along with a corresponding weight tensor mask, thereby minimizing a memory footprint for caching the weight tensor.14.The tensor processing circuit of claim 1, wherein the accumulating circuit comprises an adder tree to reduce the intermediate tensor to a format ready for accumulation with the other tensor from the accumulation cache.15.The tensor processing circuit of claim 14, wherein the accumulating circuit further comprises an accumulation adder configured to accumulate the reduced intermediate tensor with the other tensor from the accumulation cache.16.The tensor processing circuit of claim 1, wherein the output tensor is written from the accumulation cache back to a shared memory.17.The tensor processing circuit of claim 1, wherein the activation tensor is a condensed tensor and bypasses the gather circuit, but is replicated multiple times in the condensed tensor.18.The tensor processing circuit of claim 1, wherein the tensor processing circuit supports computation based on dense activation tensors, condensed activation tensors, dense weight tensors, and condensed weight tensors.19.A method implemented by a tensor processing circuit, comprising:fetching an activation tensor and a weight tensor from a memory;in response to the weight tensor being sparse:obtaining a weight tensor mask of the weight tensor that indicates positions of non-zero weights;transforming the activation tensor to a condensed activation tensor using the weight tensor mask;transforming weight tensor into the condensed weight tensor having a same shape as the condensed the activation tensor;generating an intermediate tensor by distributing the condensed weight tensor and the condensed activation tensor to a plurality of the plurality to perform parallel computation; andinputting the intermediate tensor into an accumulating circuit to generate an output tensor.20.A method implemented by a tensor processing circuit, comprising:fetching an activation tensor and a weight tensor from a memory;in response to the activation tensor being sparse:obtaining an activation tensor mask of the activation tensor;transforming the weight tensor into a condensed weight tensor using the activation tensor mask;transforming the activation tensor into the condensed activation tensor having a same shape as the condensed weight tensor;distributing the condensed weight tensor and the condensed activation tensor to a plurality of the plurality to perform parallel computation, thereby generating an intermediate tensor; andinputting the intermediate tensor into an accumulating circuit to generate an output tensor.

Citation Information

Patent Citations

  • Exploiting activation sparsity in deep neural networks

    CN112740236A

  • Accelerator for sparse matrix multiplication in neural network

    CN116108914A

  • Methods, systems, articles of manufacture, and apparatus to decode zero-value-compression data vectors

    US20200228137A1

  • Dynamic uncompression for channel-separable operation in neural network

    US20230221994A1

  • Structured sparse memory hierarchy for deep learning

    US20240095518A1