An adaptive multi-granularity sparse processing method, device, chip and medium

By using an adaptive multi-granularity sparse processing method to dynamically select the sparse coding mode, the problem that existing sparse acceleration schemes cannot adapt to dynamic sparse distribution is solved, thereby improving the acceleration efficiency and performance stability of AI chips and reducing design complexity.

CN123138562APending Publication Date: 2026-11-20ZHONGCHENG HUALONG COMPUTER TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611646192.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-23
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

Existing sparse acceleration solutions, due to their fixed-granularity sparse coding mode, cannot adapt to the dynamic sparse distribution changes under different network layers and batch inputs. This leads to invalid computation or increased indexing overhead when sparsity is mismatched, and even performance is lower than dense computation in low-sparse scenarios.

Method used

An adaptive multi-granularity sparse processing method is adopted. By obtaining the feature map of the output of the convolutional neural network layer, the sparsity and spatial dispersion are analyzed, and four candidate processing modes, namely element-level, block-level, channel-level or dense pass-through, are dynamically selected to generate data output with a unified hybrid encoding format.

Benefits of technology

It improves acceleration efficiency across the entire sparsity range, takes into account the encoding requirements of highly sparse and dispersed data as well as low sparse and clustered data, reduces chip design complexity and software stack development costs, and enables efficient deployment of heterogeneous AI models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123138562A_ABST
    Figure CN123138562A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of artificial intelligence chips, and provides a self-adaptive multi-granularity sparse processing method and device, a chip and a medium, which comprise the following steps: acquiring an input tensor and analyzing dimension information, a sparsity, a spatial dispersion degree and a total number of non-zero elements of the input tensor; determining a target processing mode from a plurality of candidate processing modes according to the sparsity and the spatial dispersion degree according to a preset threshold rule; and processing the input tensor according to the target mode and packaging the input tensor into uniform format data output containing a granularity identifier. The application selects an optimal coding granularity adaptively in runtime, solves the problem that a static sparse strategy cannot adapt to dynamic data distribution, and improves acceleration efficiency in a full sparsity range.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence chip technology, specifically to an adaptive multi-granularity sparse processing method, device, chip, and medium. Background Technology

[0002] In related technologies, sparse computing is a key technique for reducing the computational load and memory access overhead of AI chips. Existing sparse acceleration solutions typically employ fixed-granularity sparse coding patterns, such as 2:4 structured sparse or element-level unstructured sparse, or statically determine the sparse format at compile time. However, in real-world inference scenarios, the sparse distribution of data varies significantly across different network layers and even within the same layer under different batches of input. Furthermore, runtime operations such as dynamic pruning cause the sparse pattern to change in real time. The fundamental flaw of existing solutions lies in their reliance on static presets or single-granularity coding strategies. When the actual data distribution does not match the preset pattern, either excessively coarse granularity leads to increased invalid computation, or excessively fine granularity causes indexing overhead to offset computational gains. In low-sparse scenarios, the lack of a fallback mechanism can even result in performance lower than dense computing.

[0003] Therefore, it is evident that how to break free from the static preset framework and seek a better acceleration efficiency solution across the entire sparsity range has become a technical challenge that urgently needs to be overcome in this field. Summary of the Invention

[0004] This invention provides an adaptive multi-granularity sparse processing method, apparatus, chip, and medium, which can solve the problem of decreased sparse acceleration efficiency caused by static sparse coding strategies in the prior art. The technical solution is as follows: On the one hand, an adaptive multi-granularity sparse processing method is provided, the method comprising: During the inference process of the AI ​​chip, the feature map output of any layer in the convolutional neural network is obtained as the input tensor. The input tensor is a multi-dimensional tensor that includes the channel dimension. The input tensor is analyzed to determine its dimensionality and sparsity. Spatial dispersion and the total number of non-zero elements in the input tensor. The sparsity The ratio of the number of zero elements in the input tensor to the total number of elements determined based on the dimensionality information; the spatial dispersion. Obtained through the following methods: The input tensor is divided into multiple The number of non-zero blocks containing at least one non-zero element is counted. The spatial dispersion is calculated according to the following formula:

[0005] in, and The spatial dispersion is a preset positive integer, used to characterize the degree of spatial dispersion of the non-zero elements in the input tensor; Multiple candidate processing modes are set; based on the sparsity... The spatial dispersion The target processing mode is determined from the multiple candidate processing modes according to preset rules; The input tensor is processed according to the target processing mode and encapsulated into data output in the corresponding format.

[0006] On the other hand, an adaptive multi-granularity sparse processing apparatus is provided, the apparatus comprising: The data input port is used to receive an input tensor, which is a feature map of the output of any layer in the convolutional neural network obtained during the inference process of the AI ​​chip, and the input tensor is a multidimensional tensor containing the channel dimension. A sparsity-aware analyzer, whose input is connected to the data input port, is used to analyze the input tensor during runtime to determine the dimension information and sparsity rate of the input tensor. Spatial dispersion and the total number of non-zero elements in the input tensor. The sparsity rate is the ratio of the number of zero elements in the input tensor to the total number of elements determined based on the dimension information. The spatial dispersion is obtained by dividing the input tensor into multiple... The number of non-zero blocks containing at least one non-zero element is counted. The spatial dispersion is calculated according to the following formula:

[0007] in, and The spatial dispersion is a preset positive integer, used to characterize the degree of spatial dispersion of the non-zero elements in the input tensor; The granular decision engine, whose input is connected to the output of the sparse sensing analyzer, is used to set multiple candidate processing modes; based on the sparsity rate... and the spatial dispersion The target processing mode is determined from the multiple candidate processing modes according to preset rules; The encoding package formatting module is used to process the input tensor according to the target processing mode and encapsulate it into data output in the corresponding format.

[0008] On the other hand, an artificial intelligence (AI) chip is provided, including: The adaptive multi-granularity sparse processing device described above; The computing unit array includes multiple computing circuits. The input terminal of the computing unit array is connected to the output terminal of the adaptive multi-granularity sparse processing device, and is used to receive data in a unified hybrid encoding format or a unified dense data format output by the adaptive multi-granularity sparse processing device, and to perform calculations on the received data.

[0009] On the other hand, a computer-readable storage medium is provided, wherein a computer program is stored therein, and when the computer program is executed by a processor, it implements the steps of the adaptive multi-granularity sparse processing method described above.

[0010] The technical solution provided by this invention can bring at least the following beneficial effects: By embedding a runtime sparsity awareness and adaptive decision-making mechanism into the AI ​​chip inference path, this application effectively improves the average acceleration efficiency across the entire sparsity range. Simultaneously, by introducing spatial dispersion as a secondary decision dimension and combining it with multi-level thresholds to dynamically determine the target processing mode from multiple candidate processing modes, it breaks the contradiction between the difficulty in matching single granularity and dynamic data distribution in traditional solutions, thus balancing the encoding requirements of highly sparse and dispersed data and low-sparse and clustered data. Furthermore, based on a unified hybrid encoding format and a zero-overhead dense backoff mechanism, this application further provides automated adaptation capabilities without manual tuning for the efficient deployment of heterogeneous AI models on the same hardware IP core, significantly reducing chip design complexity and software stack development costs. Attached Figure Description

[0011] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0012] Figure 1 This is a flowchart of an adaptive multi-granularity sparse processing method provided in an embodiment of the present invention; Figure 2 This is a detailed flowchart of L2 block-level encoding and decoding provided in one embodiment of the present invention; Figure 3 This is a structural diagram of an adaptive multi-granularity sparse processing device provided in an embodiment of the present invention; Figure 4 This is an architecture diagram of an artificial intelligence (AI) chip provided in an embodiment of the present invention. Detailed Implementation

[0013] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are some embodiments of the present invention, but not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.

[0014] As mentioned earlier, in related technologies, sparse acceleration solutions for AI chips generally adopt a fixed-granularity sparse coding strategy that is statically determined at compile time, which cannot dynamically adapt to the actual sparsity characteristics of the data at runtime. When the actual data distribution does not match the preset pattern, coarse granularity leads to an increase in invalid computation, while fine granularity causes indexing overhead to offset computational gains. Furthermore, in low-sparseness scenarios, there is a lack of a mechanism to fall back to dense computation, resulting in performance that is actually lower than that without sparse processing. In addition, a single sparsity rate metric cannot distinguish whether non-zero elements are spatially concentrated or dispersed, further limiting the accuracy of coding granularity selection. This application introduces a dual-dimensional runtime awareness mechanism of sparsity rate and spatial dispersion, and combines multi-level threshold decision rules to adaptively determine the target processing mode from four candidate processing modes: element-level, block-level, channel-level, and dense pass-through, and encapsulates the output in a unified format. This solves the technical problems mentioned above, such as the inability of static coding strategies to adapt to dynamic data distribution, insufficient accuracy of single-metric decision-making, and lack of a full-sparseness range fallback mechanism. The specific implementation of the above concept is described below.

[0015] Example 1 Please refer to Figure 1 This invention provides an adaptive multi-granularity sparse processing method that can automatically select the optimal encoding granularity based on runtime data characteristics. The method includes: Step S100, during the inference process of an AI chip, obtaining the feature map output of any layer in a convolutional neural network as an input tensor. This input tensor is a multi-dimensional tensor containing channel dimensions. Specifically, this input tensor typically originates from the output of the previous layer's computational unit in the AI ​​chip's internal pipeline, or from intermediate feature data loaded from off-chip memory. In practical applications, this input tensor is generally a three-dimensional tensor (H×W×C) or a four-dimensional tensor (N×H×W×C), where the channel dimension forms the basis for subsequent channel-level sparse processing. It should be understood that although this embodiment uses a convolutional neural network as an example, this method is also applicable to other neural network models such as Transformer and MLP that include multi-dimensional tensor operations, as long as their output data has a divisible spatial or channel structure.

[0016] Step S102: Analyze the input tensor to determine its dimensionality and sparsity. Spatial dispersion and the total number of non-zero elements in the input tensor. Among them, sparsity Spatial dispersion is the ratio of the number of zero elements in the input tensor to the total number of elements determined based on dimensionality information, used to macroscopically characterize the sparsity of the data. This is obtained by partitioning the input tensor into multiple... The number of non-zero blocks containing at least one non-zero element is counted. Spatial dispersion is calculated using the following formula:

[0017] in, and This is a preset positive integer, such as 4, 8, or 16. The specific value can be configured according to the memory access granularity or vector processing width of the AI ​​chip's computing unit. Spatial dispersion This formula is used to characterize the spatial dispersion of non-zero elements in an input tensor. Specifically, its physical meaning is "the average block area occupied by a unit of non-zero element." When non-zero elements are highly clustered, a smaller number of non-zero blocks can accommodate a large number of non-zero elements. Approaching 1; conversely, when non-zero elements are extremely dispersed, each non-zero element may occupy an entire block, in which case... Approaching block size This definition avoids the numerical instability of traditional clustering indices under extreme distributions, providing a linear and monotonic criterion for subsequent granularity decisions. In terms of hardware implementation, this analysis process can be completed in real-time by a dedicated sparse-aware analyzer as data flows, without the need for additional caching or preprocessing cycles.

[0018] Step S104: Set multiple candidate processing modes; based on sparsity... and spatial dispersion The target processing mode is determined from the multiple candidate processing modes according to preset rules. The candidate processing modes include L1 element-level sparse coding mode, L2 block-level sparse coding mode, L3 channel-level sparse coding mode, and dense pass-through mode.

[0019] Furthermore, the multiple candidate processing modes include L1 element-level sparse coding mode, L2 block-level sparse coding mode, L3 channel-level sparse coding mode, and dense pass-through mode; the target processing mode is determined from the multiple candidate processing modes according to preset rules, including: Among them, settings , , and The preset threshold is satisfied. The size relationship. The specific decision-making logic is as follows: when and At this point, the L1 element-level sparse coding mode is determined as the target processing mode. This indicates that the data is not only extremely sparse, but also highly spatially dispersed. In this case, using an element-level coordinate list format can minimize the storage of invalid zero values ​​and redundant block index information.

[0020] when and When the data is extremely sparse, the L2 block-level sparse coding mode is determined as the target processing mode. This indicates that although the data is extremely sparse, non-zero elements still exhibit some clustering within local regions. In this case, using the block-level bitmap format has lower indexing overhead than the element-level coordinate format.

[0021] when At this point, the L2 block-level sparse coding mode is determined as the target processing mode. Within this medium sparsity range, regardless of spatial dispersion, block-level coding is usually the optimal balance between compression efficiency and decoding performance. Therefore, there is no need to further determine the dispersion condition, which simplifies the decision-making logic and reduces the power consumption of the hardware comparator.

[0022] when At this point, the L3 channel-level sparse coding mode is determined as the target processing mode. The data sparsity is low at this stage, making it suitable only for skipping the entire all-zero channel, and not for fine-grained element-level or block-level compression.

[0023] when At this point, the dense pass-through mode is determined as the target processing mode. Because the data is too dense, the metadata overhead introduced by any sparse encoding may outweigh the data transmission savings; therefore, directly passing through the original data is the optimal choice.

[0024] It should be noted that in the above decision-making logic, spatial dispersion... With threshold The comparison only occurs when the sparsity reaches the highest threshold. It is only triggered at certain times. This hierarchical conditional branching design conforms to the technical principle that fine differentiation of dispersion is only required in highly sparse scenarios, and avoids unnecessary dispersion calculations and comparisons in medium- and low-sparse scenarios, effectively saving hardware resources and decision latency.

[0025] Step S106: Process the input tensor according to the target processing mode and encapsulate it into data output in the corresponding format.

[0026] Specifically, the input tensor is processed according to the target processing mode to generate corresponding processing data, and the processing data and the granularity identifier field indicating the target processing mode are encapsulated together into data output in the corresponding format; The input tensor is processed according to the target processing mode to generate corresponding processed data, including: When the target processing mode is L1 element-level sparse coding mode, L1 element-level sparse coding is performed on the input tensor to generate first processing data containing the position information and values ​​of each non-zero element, and the first processing data and the granularity identifier field are encapsulated together into a unified hybrid coding format. When the target processing mode is L2 block-level sparse coding mode, L2 block-level sparse coding is performed on the input tensor to generate second processing data containing bitmaps of each block and values ​​of each non-zero element, and the second processing data and the granularity identifier field are encapsulated together into the unified hybrid coding format. When the target processing mode is L3 channel-level sparse coding mode, L3 channel-level sparse coding is performed on the input tensor to generate third processing data containing channel mask and data of each non-zero channel, and the third processing data and the granularity identifier field are encapsulated together into the unified hybrid coding format. When the target processing mode is dense pass-through mode, the original dense data of the input tensor is used as the fourth processing data, and the fourth processing data and the granularity identifier field are encapsulated together into a unified dense data format. By introducing a unified granularity identifier field, downstream computing units or decoders do not need to know the sparsity characteristics of the upstream data in advance, and only need to read the packet header identifier to dynamically configure the decoding path, realizing seamless switching of heterogeneous sparse formats in the same data stream.

[0027] In this embodiment, by embedding a runtime sparsity awareness and multi-level adaptive decision-making mechanism into the AI ​​chip inference path, the problem that static sparse coding strategies in the prior art cannot adapt to dynamic data distribution is effectively solved. Compared with fixed-granularity schemes at compile time, this method can select the optimal solution from four modes—L1, L2, L3, or dense—in real time based on the actual sparsity and spatial dispersion of each layer or even each batch of data. More importantly, by introducing spatial dispersion as a secondary decision dimension for high-sparse intervals, the limitation of a single sparsity index being unable to distinguish between "dispersed sparsity" and "clustered sparsity" is overcome, ensuring that maximum compression benefits and computational speedup can be obtained under different data formats. In addition, the output mechanism based on a unified format encapsulation eliminates the protocol conversion overhead caused by mode switching, providing a solid foundation for the AI ​​chip to maintain stable and optimal performance across the entire sparsity range.

[0028] Example 2 The following is combined with Figure 1 The steps shown below provide a detailed description of the specific execution method of the adaptive multi-granularity sparse processing method provided in the embodiments of this application.

[0029] In step S100, during the inference process of the AI ​​chip, the feature map output of any layer in the convolutional neural network is obtained as an input tensor. This input tensor is a multi-dimensional tensor containing channel dimensions. Specifically, this input tensor usually originates from the output of the previous layer's computation unit in the AI ​​chip's internal pipeline, or from intermediate feature data loaded from off-chip memory. In practical applications, this input tensor is generally a three-dimensional tensor (H×W×C) or a four-dimensional tensor (N×H×W×C), where the channel dimension is the basis for subsequent channel-level sparsity processing. It should be understood that although this embodiment uses a convolutional neural network as an example, this method is also applicable to other neural network models such as Transformer and MLP that contain multi-dimensional tensor operations, as long as their output data has a divisible spatial or channel structure.

[0030] In step S102, the input tensor is analyzed to determine its dimensionality and sparsity. Spatial dispersion and the total number of non-zero elements in the input tensor. Among them, sparsity Spatial dispersion is the ratio of the number of zero elements in the input tensor to the total number of elements determined based on dimensionality information, used to macroscopically characterize the sparsity of the data. This is obtained by partitioning the input tensor into multiple... The number of non-zero blocks containing at least one non-zero element is counted. Spatial dispersion is calculated using the following formula:

[0031] in, and This is a preset positive integer, such as 4, 8, or 16. The specific value can be configured according to the memory access granularity or vector processing width of the AI ​​chip's computing unit. Spatial dispersion This formula is used to characterize the spatial dispersion of non-zero elements in an input tensor. Its physical meaning is "the average block area occupied by a unit of non-zero element." When non-zero elements are highly clustered, a smaller number of non-zero blocks can accommodate a large number of non-zero elements. Approaching 1; conversely, when non-zero elements are extremely dispersed, each non-zero element may occupy an entire block, in which case... Approaching block size This definition avoids the numerical instability of traditional clustering indices under extreme distributions, providing a linear and monotonic criterion for subsequent granularity decisions. In terms of hardware implementation, this analysis process can be completed in real-time by a dedicated sparse-aware analyzer as data flows, without the need for additional caching or preprocessing cycles.

[0032] In step S104, multiple candidate processing modes are set; based on the sparsity... and spatial dispersion The target processing mode is determined from the multiple candidate processing modes according to preset rules; In step S106, the input tensor is processed according to the target processing mode and encapsulated into data output in the corresponding format.

[0033] Specifically, the input tensor is processed according to the target processing mode to generate corresponding processing data, and the processing data and the granularity identifier field indicating the target processing mode are encapsulated together into data output in the corresponding format; The step of processing the input tensor according to the target processing mode to generate corresponding processing data includes: When the target processing mode is L1 element-level sparse coding mode, L1 element-level sparse coding is performed on the input tensor to generate first processing data containing the position information and values ​​of each non-zero element, and the first processing data and the granularity identifier field are encapsulated together into a unified hybrid coding format. When the target processing mode is L2 block-level sparse coding mode, L2 block-level sparse coding is performed on the input tensor to generate second processing data containing bitmaps of each block and values ​​of each non-zero element, and the second processing data and the granularity identifier field are encapsulated together into the unified hybrid coding format. When the target processing mode is L3 channel-level sparse coding mode, L3 channel-level sparse coding is performed on the input tensor to generate third processing data containing channel mask and data of each non-zero channel, and the third processing data and the granularity identifier field are encapsulated together into the unified hybrid coding format. When the target processing mode is dense pass-through mode, the original dense data of the input tensor is used as the fourth processing data, and the fourth processing data and the granularity identifier field are encapsulated together into a unified dense data format.

[0034] By introducing a unified granularity identifier field, downstream computing units or decoders do not need to know the sparsity characteristics of upstream data. They only need to read the packet header identifier to dynamically configure the decoding path, thus achieving seamless switching between heterogeneous sparse formats in the same data stream.

[0035] The specific encoding implementation methods of each candidate processing mode involved in step S104 and the encapsulation format involved in step S106 will be described in detail below.

[0036] Furthermore, in step S104, the multiple candidate processing modes include L1 element-level sparse coding mode, L2 block-level sparse coding mode, L3 channel-level sparse coding mode, and dense pass-through mode.

[0037] The target processing mode is determined from the multiple candidate processing modes according to preset rules, including: set up , , and The preset threshold is satisfied. , The size relationship. The specific decision-making logic is as follows: when and When this is determined, the L1 element-level sparse coding mode is selected as the target processing mode. The L1 element-level sparse coding mode uses a single element as the encoding unit and records the position and value of each non-zero element using a coordinate list format. The position of each non-zero element in the coordinate list format is determined by its channel, row coordinate, and column coordinate. This indicates that the data is not only extremely sparse but also highly spatially dispersed. Using an element-level coordinate list format in this case can minimize the storage of invalid zero values ​​and redundant block index information.

[0038] when and At that time, the L2 block-level sparse coding mode is determined as the target processing mode. The L2 block-level sparse coding mode uses... A block consisting of elements is used as an encoding unit to generate a block bitmap for marking the positions of non-zero elements within each block, and the values ​​of the non-zero elements are extracted. This shows that although the data is extremely sparse, non-zero elements still have a certain degree of clustering in local areas. In this case, the block-level bitmap format has a lower indexing overhead than the element-level coordinate format.

[0039] when At this point, the L2 block-level sparse coding mode is determined as the target processing mode. Within this medium sparsity range, regardless of spatial dispersion, block-level coding is usually the optimal balance between compression efficiency and decoding performance. Therefore, there is no need to further determine the dispersion condition, which simplifies the decision-making logic and reduces the power consumption of the hardware comparator.

[0040] when At this time, the L3 channel-level sparse coding mode is determined as the target processing mode. The L3 channel-level sparse coding mode uses the entire channel of the input tensor as the coding unit to generate a channel mask for marking non-zero channels and extract the data of the non-zero channels; at this time, the data sparsity is low, which is only suitable for skipping the entire all-zero channel, and not suitable for fine-grained element-level or block-level compression.

[0041] when At this point, the dense pass-through mode is determined as the target processing mode. Because the data is too dense, the metadata overhead introduced by any sparse encoding may outweigh the data transmission savings; therefore, directly passing through the original data is the optimal choice.

[0042] It should be noted that in the above decision-making logic, spatial dispersion... With threshold The comparison only occurs when the sparsity reaches the highest threshold. It is only triggered at certain times. This hierarchical conditional branching design, on the one hand, conforms to the technical principle that fine differentiation of dispersion is only needed in highly sparse scenarios, and on the other hand, avoids unnecessary dispersion calculations and comparisons in medium- and low-sparse scenarios, effectively saving hardware resources and decision latency. For the L1 element-level sparse coding mode, the coordinate list format in the first processed data is represented as follows: ,in For the first The channel index containing the non-zero elements For the first The row coordinates of the non-zero elements. For the first The column coordinates of the non-zero elements. For the first The numerical values ​​of each non-zero element. Specifically, in scenarios with extremely high sparsity and highly dispersed spatial distribution, there is a lack of local correlation between non-zero elements. In such cases, block-level or channel-level encoding would result in a large amount of invalid zero-value padding or redundant index header information. This embodiment explicitly records the three-dimensional spatial coordinates of each non-zero element. This allows the decoding end to directly write values ​​to the target storage location based on the coordinates, completely avoiding the overhead of transmitting zero values ​​to maintain the data structure. Compared to a two-dimensional coordinate format that only records rows and columns, adding channel dimensions... This is to adapt to the multi-channel parallel computing architecture commonly found in AI chips, ensuring that no additional channel switching instructions are needed when processing across channels. In this embodiment, by accurately recording the three-dimensional coordinates of each non-zero element, a large number of zero values ​​can be avoided in scenarios with extremely high sparsity and spatial dispersion, thereby maximizing the compression ratio.

[0043] Please refer to Figure 2 For L2 block-level sparse coding mode, Each element is processed as a block, generating a second set of processed data containing a bitmap of each block and the values ​​of each non-zero element.

[0044] like Figure 2 As shown on the left, at the encoding end, the current process to be processed is first... The data block is used as "input 4×4 block (16 data)"; then, it is checked whether each element in the block is zero, and a 16-bit bitmap is generated accordingly. Each bit in the bitmap corresponds one-to-one with an element in the block, with the bit corresponding to a non-zero element set to 1 and the bit corresponding to a zero element set to 0; after generating the bitmap, the number of non-zero elements is counted, that is, the number of "1"s in the bitmap is counted to obtain the number of non-zero elements in the block; then, the original values ​​of each non-zero element are taken out in sequence and tightly concatenated to form a compact sequence of non-zero values; finally, the bitmap, the sequence of non-zero values, and the count of non-zero elements are used as output for the decoder.

[0045] like Figure 2 As shown on the right, at the decoding end, firstly, the "input bitmap and non-zero value sequence" are entered; then, the "output is initialized to all zeros" to prepare an output buffer of all zeros for the current block; next, the "bitmap is scanned to find non-zero bits" to find all positions of "1" in the same order as at the encoding end; each time a non-zero bit is found, the "non-zero value is filled in order" to take a value from the non-zero value sequence and fill it into the element position corresponding to that bit in the buffer; after scanning and filling all non-zero bits, the "4×4 block of original data" can be restored.

[0046] For example, when the preset block size =4, When the value is 4, each block corresponds to a 16-bit bitmap. Assuming that only positions 0, 3, and 7 in a block contain non-zero values, the bitmap generated by the encoder is the binary sequence "1001000100000000", with a non-zero count of 3. The sequence of non-zero values ​​is the original value of these three positions. After receiving the bitmap, the decoder first initializes the all-zero block, then scans the bitmap and fills in these three values ​​in sequence at positions 0, 3, and 7 to restore the original block.

[0047] The key to this design lies in the fact that the order in which "1"s appear in the bitmap of the second processed data has a strict implicit mapping relationship with the order in which non-zero values ​​are arranged in the payload area. The decoder only needs to scan the bitmap to determine the write offset of each value, without needing to store an index separately for each value. Compared to L1 mode recording coordinates one by one, L2 mode utilizes local spatial clustering to compress the positioning information of multiple elements into a single bitmap, significantly reducing the average number of index bits per non-zero element. In this embodiment, by marking non-zero positions within a block with a bitmap and arranging values ​​in a compact order, local spatial structure information is preserved while avoiding the high overhead of recording coordinates element by element, achieving the best balance between index overhead and computational efficiency under moderate sparsity.

[0048] For L3 channel-level sparse coding, a third-processed data set containing channel masks and data for each non-zero channel is generated. Specifically, this includes: checking channel by channel whether all channels in the input tensor consist entirely of zero elements; if all elements in a channel are zero, the channel is designated as a zero channel; otherwise, it is designated as a non-zero channel; generating a mask of the same length as the number of channels in the input tensor, where each bit corresponds to a channel (1 indicates a non-zero channel, 0 indicates a zero channel); compactly arranging the data for each non-zero channel; using this mask as the channel mask in the third-processed data, and using the data for each non-zero channel as the non-zero channel data in the third-processed data. Specifically, in the attention layer or channel-pruned convolutional layers of the Transformer model, it is common for entire channels to be set to zero. In this case, the length of the channel mask in the third-processed data is fixed equal to the total number of channels in the input tensor. Each bit directly represents the validity of the corresponding channel. For channels marked as 0 in the mask, the encoder skips all data reading and transmission; for channels marked as 1, it fully transmits the data. Each data point is compactly arranged as a whole, serving as the non-zero channel data in the third processed data. While this coarse-grained encoding method is less refined than element-level or block-level encoding, it has extremely low indexing overhead (only 1 bit / channel) and enables continuous memory access of entire blocks of data when processing structured sparse data, significantly improving storage bandwidth utilization. In this embodiment, the entire zero channel is skipped using a channel-level mask in the third processed data, eliminating the indexing requirement for all elements within the channel. This is particularly suitable for structured sparse scenarios such as channel pruning, achieving a significant reduction in metadata overhead under low sparsity conditions.

[0049] Regarding the encapsulation process in step S106, in each of the above modes, the first processing data, the second processing data, and the third processing data all include index data and payload data, while the fourth processing data only includes payload data.

[0050] Specifically: when the target processing mode is L1 element-level sparse coding mode, the index data is the position information of each non-zero element, and the payload data in the first processing data is the value of each non-zero element; when the target processing mode is L2 block-level sparse coding mode, the index data is a bitmap of each block arranged in block order, and the payload data in the second processing data is the value of each non-zero element arranged in the order corresponding to the non-zero bits in the bitmap; when the target processing mode is L3 channel-level sparse coding mode, the index data is a channel mask, and the payload data in the third processing data is the data of each non-zero channel. This unified index and payload binary structure design enables encoded data of different granularities to have a consistent abstract interface in logic. The hardware decoder can first parse the index part to determine the data layout, and then move the payload data in batches according to the index guidance, thereby achieving decoupling of control flow and data flow. For example, the bitmap in L2 mode is both an index and a mask for data validity, while the channel mask in L3 mode directly determines the starting address offset of subsequent payload data. For dense pass-through mode, since the fourth processing data only contains payload data and not index data, the decoder does not need to perform index parsing operations and can directly process the payload data as raw tensor data. This avoids the additional overhead of index parsing in extremely low sparsity scenarios. This differentiated yet structurally unified definition avoids the complexity of designing independent parsing logic for each format. In this embodiment, by defining an index-payload structure that matches the semantics of each granularity, the decoder can efficiently recover the original data based on unified parsing logic, thereby improving the throughput of the hardware pipeline.

[0051] Furthermore, during the encapsulation process in step S106, both the unified hybrid encoding format and the unified dense data format include a shape information field to record the number of rows, columns, and channels of the input tensor; and a non-zero element count field to record the total number of non-zero elements in the input tensor. Specifically, the shape information field is typically assigned a fixed bit width (e.g., 46 bits, allocated to rows, columns, and channels respectively), while the non-zero element count field (e.g., 8 bits or 16 bits) provides a quick verification basis for the payload length within the data packet. The existence of these two fields enables each output data packet to possess complete self-descriptive capabilities. In actual chip systems, this means that downstream computing units or DMA controllers can obtain the current tensor's geometric dimensions and data volume without querying an external global configuration table or waiting for a software interrupt notification when receiving data, thereby supporting dynamic data stream processing in multi-task concurrent scenarios. Even if the output dimension of the upstream network layer changes, the data packet itself still carries the correct parsing metadata, preventing decoding misalignment or out-of-bounds access. In this embodiment, by carrying shape and counter information in the packet header, the decoder can autonomously complete data reconstruction without external configuration, thereby enhancing the self-describing capability and system robustness of data packets transmitted between different computing units.

[0052] Example 3 Please refer to Figure 3 This application provides an adaptive multi-granularity sparse processing device 30, which serves as a dedicated hardware acceleration unit within an AI chip, used to execute the aforementioned adaptive sparse processing method in real time during inference. Figure 3 As shown, the device includes a data input port 31, a sparse sensing analyzer 32, a granular decision engine 33, a granular router 34, an L1 encoder 35, an L2 encoder 36, an L3 encoder 37, a dense pass-through module 38, and an encoding packet formatting module 39.

[0053] Data input port 31 is used to receive input tensors, which are feature maps output from any layer of the convolutional neural network acquired during the inference process of the AI ​​chip, and are multi-dimensional tensors including channel dimensions. Specifically, the data input port typically adopts high-speed streaming interface protocols such as AXI-Stream, supporting backpressure handshake mechanisms to ensure data transmission synchronization with upstream computing units or off-chip memory controllers. This port not only transmits the tensor data itself, but may also carry valid signals representing tensor boundaries (such as tensor_last) to trigger statistical resets and result outputs in downstream modules.

[0054] The input of the sparse-aware analyzer 32 is connected to the data input port and is used to analyze the input tensor at runtime to determine the dimension information and sparsity of the input tensor. Spatial dispersion and the total number of non-zero elements in the input tensor The sparsity rate is the ratio of the number of zero elements to the total number of elements determined based on the dimensionality information. Spatial dispersion is obtained by partitioning the input tensor into multiple... The number of non-zero blocks containing at least one non-zero element is counted. Spatial dispersion is calculated using the following formula:

[0055] in, and The spatial dispersion is a preset positive integer used to characterize the spatial dispersion of non-zero elements in the input tensor. Specifically, the sparse-aware analyzer is the hardware embodiment of step S102 in the method embodiment. It integrates a zero-value detection circuit, a counter array, and a divider circuit, enabling it to perform statistics step-by-step as data flows through, without needing to cache the complete tensor in on-chip SRAM, thus achieving real-time analysis with zero additional memory access overhead. This hardware-level parallel statistical capability is the physical basis for supporting the low-latency characteristics of runtime adaptive decision-making.

[0056] The input of the granular decision engine 33 is connected to the output of the sparse sensing analyzer to set multiple candidate processing modes; based on the sparsity... and spatial dispersion The target processing mode is determined from the multiple candidate processing modes according to preset rules; Furthermore, multiple candidate processing modes include L1 element-level sparse coding mode, L2 block-level sparse coding mode, L3 channel-level sparse coding mode, and dense pass-through mode. The granular decision engine 33 is specifically used to determine the target processing mode from multiple candidate processing modes and output the target processing mode, wherein... , , and For a preset threshold, and , .

[0057] The target processing mode is determined from the multiple candidate processing modes according to preset rules, including: when and When, the L1 element-level sparse coding pattern is determined as the target processing pattern; when and When, the L2 block-level sparse coding mode is determined as the target processing mode; when When, the L2 block-level sparse coding mode is determined as the target processing mode; when When, the L3 channel-level sparse coding mode is determined as the target processing mode; when At that time, the dense pass-through mode is determined as the target processing mode. Specifically, the granular decision engine can be implemented in hardware using combinational logic circuits composed of multi-stage comparators and multiplexers, or using a lightweight state machine. Its output target processing mode is usually encoded as a 2-bit control signal (e.g., 00 represents L1, 01 represents L2, 10 represents L3, and 11 represents dense), which directly drives the subsequent router and formatting module. This hardwired decision mechanism ensures that the delay from the completion of statistical analysis to mode determination is controlled in the nanosecond range, which is much faster than software polling or table lookup methods.

[0058] The granular router 34 has its data input terminal connected to the data input port, and its control input terminal connected to the output terminal of the granular decision engine. The granular router has dense DC path output terminals, L1 encoded path output terminals, L2 encoded path output terminals, and L3 encoded path output terminals, and is used to receive the target processing mode and perform data routing according to the target processing mode: when the target processing mode is dense pass-through mode, the input tensor is routed to the dense DC path output terminal; when the target processing mode is L1 element-level sparse coding mode, the input tensor is routed to the L1 encoded path output terminal; when the target processing mode is L2 block-level sparse coding mode, the input tensor is routed to the L2 encoded path output terminal; and when the target processing mode is L3 channel-level sparse coding mode, the input tensor is routed to the L3 encoded path output terminal. Specifically, the granular router is essentially a 1-to-4 data distributor (Demultiplexer). In a preferred hardware implementation, the router employs a pure combinational logic design and does not contain any pipelined registers, thereby achieving zero-clock-cycle data distribution latency. This means that data can be directed to the correct processing path the moment it arrives at the router, eliminating pipeline bubbles caused by mode switching. Simultaneously, the valid signals of the three unselected output ports remain low, and the corresponding encoders are in a gated clock off or idle state, avoiding dynamic power consumption waste caused by invalid flips.

[0059] The input of the L1 encoder 35 is connected to the output of the L1 encoding path of the granular router. When the target processing mode is L1 element-level sparse coding mode, it performs L1 element-level sparse coding on the input tensor to generate the first processing data containing the position information and values ​​of each non-zero element. The L1 element-level sparse coding mode uses a single element as the encoding unit and records the position and value of each non-zero element in a coordinate list format. The position of each non-zero element in the coordinate list format is determined by its channel, row coordinate, and column coordinate.

[0060] The input of the L2 encoder 36 is connected to the output of the L2 encoding path of the granular router. When the target processing mode is L2 block-level sparse coding mode, it performs L2 block-level sparse coding on the input tensor to generate bitmaps of each block and the values ​​of each non-zero element as second processing data. The L2 block-level sparse coding mode uses... A block consisting of 10 elements is used as an encoding unit. A block bitmap is generated to mark the positions of non-zero elements in each block, and the values ​​of non-zero elements are extracted.

[0061] The input of the L3 encoder 37 is connected to the output of the L3 encoding path of the granular router. When the target processing mode is L3 channel-level sparse coding mode, it performs L3 channel-level sparse coding on the input tensor to generate a channel mask and third-processed data for each non-zero channel. The L3 channel-level sparse coding mode uses the entire channel of the input tensor as the encoding unit, generates a channel mask to mark the non-zero channels, and extracts the data from the non-zero channels.

[0062] The input of dense pass-through module 38 is connected to the output of the dense pass-through path of the granular router, providing the original dense data of the input tensor as the fourth processing data when the target processing mode is dense pass-through mode. Specifically, these four processing modules exist physically in parallel but operate mutually exclusively logically. Each encoder contains compression logic optimized for a specific granularity; for example, the L2 encoder has a built-in bitmap generator and compact arrangement buffer, and the L3 encoder has a built-in channel mask generator. This dedicated hardware design offers orders of magnitude advantages in throughput and energy efficiency compared to general-purpose processors executing software compression algorithms.

[0063] The output of the granularity decision engine 33 is connected to the control input of the encoding packet formatting module, and the outputs of the L1 encoder, the L2 encoder, the L3 encoder, and the dense pass-through module are respectively connected to the data input of the encoding packet formatting module. The granular decision engine 33 is also used to output the target processing mode to the encoding packet formatting module, so that the encoding packet formatting module selects to receive corresponding processing data from the L1 encoder, the L2 encoder, the L3 encoder and the dense pass-through module according to the target processing mode, and encapsulates the received processing data into the corresponding format and outputs it.

[0064] The encoding package formatting module 39 is used to process the input tensor according to the target processing mode and encapsulate it into data output in the corresponding format.

[0065] Specifically, this module is responsible for packaging the encoding results of different granularities into a unified package, adding a header containing granularity identifiers, shape information, and non-zero counts to form a standardized output data stream. This allows downstream computing units to determine the data format simply by parsing the header, without needing to know what sparsity strategy was used upstream, thus decoupling the data processing chain.

[0066] In some embodiments of this application, the L1 element-level sparse coding mode uses a single element as the coding unit and records the position and value of each non-zero element in a coordinate list format. The position of each non-zero element in the coordinate list format is determined by its channel, row coordinate, and column coordinate. The L2 block-level sparse coding mode uses... The L3 channel-level sparse coding mode uses the entire channel of the input tensor as the coding unit, generates a channel mask to mark the positions of non-zero channels, and extracts the data of the non-zero channels. Specifically, the L1 encoder operates in scenarios with extremely high sparsity and spatial dispersion by explicitly recording the three-dimensional coordinates of each non-zero element. This allows the decoding end to directly write values ​​to the target storage location based on coordinates, completely avoiding the overhead of transmitting zero values ​​to maintain the data structure. The L2 encoder operates at a medium sparsity rate, utilizing local spatial clustering to compress the location information of multiple elements into a single bitmap, significantly reducing the average number of index bits per non-zero element. The L3 encoder operates at a low sparsity rate, skipping the entire zero channel through channel-level masking, eliminating the indexing requirements for all elements within a channel, making it particularly suitable for structured sparse scenarios such as channel pruning. In this embodiment, by defining encoding granularities matching the data sparsity characteristics for each of the three encoders, the device can automatically select the optimal encoding strategy based on runtime decision results, achieving full granularity coverage from the element level to the channel level, and achieving optimal compression efficiency across different sparsity ranges.

[0067] In some embodiments of this application, the sparse sensing analyzer includes a zero-value detection circuit, a successive approximation divider circuit, and a block statistics circuit. Specifically, the zero-value detection circuit is used to count the number of zero elements and non-zero elements in the input tensor. This circuit is typically composed of multiple parallel comparators, capable of simultaneously determining the zero value of all elements on the input data bus in each clock cycle and outputting the corresponding non-zero mask signal in real time. This parallel processing ensures that statistical analysis does not become a bottleneck in the data path. The block statistics circuit is used to divide the input tensor into multiple... The number of non-zero blocks containing at least one non-zero element is counted. And based on the number of non-zero blocks 1. Input the total number of non-zero elements in the tensor and preset block size and Calculate the spatial dispersion. In hardware implementation, the block statistics circuit internally maintains a block counter, which increments by 1 when at least one non-zero element is detected in the current block; specifically, the circuit is configured to immediately latch the current block upon receiving the tensor_last signal representing the tensor boundary. The value is automatically reset to ensure that statistical data between different tensors are isolated from each other, avoiding statistical contamination caused by pipeline overlap. The successive approximation divider circuit is used to calculate the sparsity rate based on the number of zero elements and the total number of elements determined by the dimension information. Considering the stringent limitations of AI chips in terms of area and power consumption, this embodiment abandons the general-purpose hardware divider that consumes a large amount of logic resources, and instead adopts a successive approximation algorithm based on shift and addition / subtraction operations. For example, this divider uses the Q8.8 fixed-point format to represent the sparsity rate, and converges to an accurate result through 16 clock cycles of iteration. At an operating frequency of 200MHz, the entire calculation process can be completed in only 80ns, and it saves logic gate area compared to traditional dividers. In this embodiment, real-time perception of sparsity characteristics is achieved through dedicated hardware sub-circuits. In particular, the successive approximation divider significantly reduces hardware overhead while ensuring computational accuracy, achieving nanosecond-level decision response and extremely low chip area occupancy.

[0068] In other embodiments of this application, the encoding packet formatting module is specifically used for encapsulation according to the target processing mode. Specifically, When the target processing mode is L1 element-level sparse coding mode, the first processing data is received from the L1 encoder, a granularity identifier field is generated, the position information of each non-zero element in the first processing data is encapsulated as index data, the value of each non-zero element is encapsulated as payload data, and the index data, the payload data and the granularity identifier field are encapsulated together into a unified hybrid coding format and output. When the target processing mode is L2 block-level sparse coding mode, the second processing data is received from the L2 encoder, a granularity identifier field is generated, the bitmap of each block arranged in block order in the second processing data is used as index data, the values ​​of each non-zero element arranged in the order corresponding to the non-zero bits in the bitmap are used as payload data, and the index data, the payload data and the granularity identifier field are encapsulated together into a unified hybrid coding format and output. When the target processing mode is L3 channel-level sparse coding mode, the third processing data is received from the L3 encoder, a granularity identifier field is generated, the channel mask in the third processing data is used as index data, the data of each non-zero channel is used as payload data, and the index data, the payload data and the granularity identifier field are encapsulated together into a unified hybrid coding format and output. When the target processing mode is dense pass-through mode, the fourth processing data is received from the dense pass-through module, a granularity identifier field is generated, the original dense data in the fourth processing data is used as payload data, and together with the granularity identifier field, they are encapsulated into a unified dense data format and output. The granularity identifier field is 2 bits, used to indicate whether the target processing mode is L1 element-level sparse coding mode, L2 block-level sparse coding mode, L3 channel-level sparse coding mode, or dense pass-through mode; the unified hybrid coding format and the unified dense data format both include: a shape information field, used to record the number of rows, columns, and channels of the input tensor; and a non-zero element count field, used to record the total number of non-zero elements in the input tensor.

[0069] For example, "00" can represent L1 mode, "01" L2 mode, "10" L3 mode, and "11" dense pass-through mode. This 2-bit identifier is placed at the very beginning of the data packet header, allowing the downstream decoder to immediately start the corresponding parsing state machine by reading only the first two bits, without waiting for the complete packet header to be received, thus achieving bubble-free switching in the decoding pipeline. Both the unified hybrid coding format and the unified dense data format also include a shape information field to record the number of rows, columns, and channels of the input tensor; and a non-zero element count field to record the total number of non-zero elements in the input tensor. In specific implementations, the shape information field can be allocated a fixed length of 46 bits, for example, divided into 16 bits for the row dimension, 16 bits for the column dimension, and 14 bits for the channel dimension, which is sufficient to cover the tensor size of most mainstream AI models. The non-zero element count field can be 8 bits wide, with a theoretical upper limit of 255. When the actual number of non-zero elements exceeds this threshold, the hardware automatically performs a saturation counting operation (i.e., locks to 255), and combines shape information for boundary verification during subsequent decoding to prevent data parsing misalignment due to counter overflow. In this embodiment, through standardized 2-bit granularity identifiers and a self-describing header field design, heterogeneous sparse data can flow seamlessly under the same transmission protocol, achieving zero-configuration adaptive decoding and robust system-level data transmission.

[0070] It should be noted that the adaptive multi-granularity sparse processing device provided in the above embodiments is only an example of the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the adaptive multi-granularity sparse processing device and the adaptive multi-granularity sparse processing method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.

[0071] Example 4 This application also provides an artificial intelligence (AI) chip 50, which includes an adaptive multi-granularity sparse processing device 30 as described in any of the foregoing embodiments and a computing unit array 40. The computing unit array 40 includes multiple arithmetic circuits, and its input is connected to the output of the adaptive multi-granularity sparse processing device 30. The input receives data in a unified mixed encoding format or a unified dense data format output by the adaptive multi-granularity sparse processing device 30 and performs calculations on the received data. Specifically, this connection is typically implemented at the physical level through a network-on-chip (NoC) or a high-performance AXI bus, allowing the adaptive multi-granularity sparse processing device 30 to be directly embedded as a dedicated hardware acceleration IP core into the data path of the AI ​​chip, rather than existing as an external software module. The computing unit array 40 can be any form of AI computing unit, such as a systolic array, a vector processing unit, or a tensor computation core. In this embodiment, the 2-bit granularity identifier field carried in the header of the data packet output by the adaptive multi-granularity sparse processing device 30 is directly read and parsed by the computing unit array. The decoding logic inside the computing unit array 40 is dynamically configured in real time according to the identifier field, thereby directly converting the uniform format data into the dense matrix or sparse index format required for internal calculation. The entire process does not require intervention from the central processing unit or secondary read / write operations to external memory. For example, when the AI ​​chip is performing the inference task of the Transformer model, for the channel-level sparse data generated by the attention mechanism layer, the adaptive multi-granularity sparse processing device 30 automatically encapsulates it into the L3 channel-level sparse coding format. After the computing unit array recognizes that the packet header identifier is in L3 mode, it immediately activates the channel mask decoding path and skips the zero-channel data for calculation. Then, when processing the block-level sparse data generated by the multilayer perceptron (MLP) layer, the device automatically switches to output the L2 block-level sparse coding format, and the computing unit array seamlessly switches to the bitmap decoding path. Throughout the model inference process, despite the significant differences in data sparsity characteristics across different levels, the chip hardware requires no reconfiguration or downtime, consistently transmitting and computing at the optimal granularity for the current data format. In this embodiment, by deeply integrating the adaptive sparse processing device and the computing unit array at the chip level, and utilizing a unified hybrid encoding format as the standardized interaction protocol between the two, not only are pipeline bubbles and additional memory access overhead caused by heterogeneous data format conversion eliminated, achieving optimal performance across the entire sparsity range, but the adaptive sparse processing device can also be reused as a general-purpose independent IP core to support the acceleration of various AI models with different architectures such as CNN, Transformer, and LLM without modifying the hardware design, significantly reducing chip development costs and iteration cycles.

[0072] Embodiments of this application also provide a computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, at least one program, code set, or instruction set is loaded and executed by a processor to implement the adaptive multi-granularity sparse processing method provided in the above-described method embodiments.

[0073] For ease of description, the above systems or devices are described separately as various modules or units based on their functions. Of course, in implementing this application, the functions of each unit can be implemented in one or more software and / or hardware components.

[0074] As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in various embodiments or some parts of the embodiments of this application.

[0075] Finally, it should be noted that in this document, relational terms such as first, second, third, and fourth are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0076] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.

Claims

1. An adaptive multi-granularity sparse processing method, characterized in that, include: During the inference process of the AI ​​chip, the feature map output of any layer in the convolutional neural network is obtained as the input tensor, and the input tensor is a multidimensional tensor containing the channel dimension. The input tensor is analyzed to determine its dimensionality and sparsity. Spatial dispersion and the total number of non-zero elements in the input tensor. ; The sparsity It is the ratio of the number of zero elements in the input tensor to the total number of elements determined based on the dimension information; The spatial dispersion This is obtained by dividing the input tensor into multiple... The number of non-zero blocks containing at least one non-zero element is counted. The spatial dispersion is calculated according to the following formula: in, and The spatial dispersion is a preset positive integer, used to characterize the degree of spatial dispersion of the non-zero elements in the input tensor; Multiple candidate processing modes are set; based on the sparsity... The spatial dispersion The target processing mode is determined from the multiple candidate processing modes according to preset rules; The input tensor is processed according to the target processing mode and encapsulated into data output in the corresponding format.

2. The method according to claim 1, characterized in that, The input tensor is processed according to the target processing mode to generate corresponding processing data, and the processing data and the granularity identifier field indicating the target processing mode are encapsulated together into data output in the corresponding format. The step of processing the input tensor according to the target processing mode to generate corresponding processing data includes: When the target processing mode is L1 element-level sparse coding mode, L1 element-level sparse coding is performed on the input tensor to generate first processing data containing the position information and values ​​of each non-zero element, and the first processing data and the granularity identifier field are encapsulated together into a unified hybrid coding format. When the target processing mode is L2 block-level sparse coding mode, L2 block-level sparse coding is performed on the input tensor to generate second processing data containing bitmaps of each block and values ​​of each non-zero element, and the second processing data and the granularity identifier field are encapsulated together into the unified hybrid coding format. When the target processing mode is L3 channel-level sparse coding mode, L3 channel-level sparse coding is performed on the input tensor to generate third processing data containing channel mask and data of each non-zero channel, and the third processing data and the granularity identifier field are encapsulated together into the unified hybrid coding format. When the target processing mode is dense pass-through mode, the original dense data of the input tensor is used as the fourth processing data, and the fourth processing data and the granularity identifier field are encapsulated together into a unified dense data format.

3. The method according to claim 2, characterized in that, The multiple candidate processing modes include L1 element-level sparse coding mode, L2 block-level sparse coding mode, L3 channel-level sparse coding mode, and dense pass-through mode. The step of determining the target processing mode from the multiple candidate processing modes according to preset rules includes: setting... , , and For a preset threshold, and , ; when and When the target processing mode is determined, the L1 element-level sparse coding mode is determined. The L1 element-level sparse coding mode uses a single element as the coding unit and records the position and value of each non-zero element in the coordinate list format. The position of each non-zero element in the coordinate list format is determined by its channel, row coordinate and column coordinate. when and When the target processing mode is determined, the L2 block-level sparse coding mode is defined as the L2 block-level sparse coding mode. A block consisting of 10 elements is used as an encoding unit. A block bitmap is generated to mark the position of non-zero elements in each block, and the values ​​of the non-zero elements are extracted. when When the target processing mode is determined, the L2 block-level sparse coding mode is identified. when When the target processing mode is determined, the L3 channel-level sparse coding mode is determined. The L3 channel-level sparse coding mode uses the entire channel of the input tensor as the coding unit to generate a channel mask for marking non-zero channels and extracts the data of the non-zero channels. when At that time, the dense pass-through mode is determined as the target processing mode.

4. The method according to claim 2, characterized in that, In the L1 element-level sparse coding mode, the coordinate list format in the first processed data is represented as follows: in, For the first The channel index containing the non-zero elements For the first The row coordinates of the non-zero elements. For the first The column coordinates of the non-zero elements. For the first The value of a non-zero element.

5. The method according to claim 2, characterized in that, In the L2 block-level sparse coding mode, the generation of second-processed data, which includes bitmaps of each block and the values ​​of each non-zero element, specifically includes: by Each element is a block, and the function checks whether the value of each element in each block is zero. For each block, generate a A bitmap of bits, wherein each bit in the bitmap corresponds one-to-one with an element in the block. If the element is non-zero, the bit in the bitmap corresponding to that element is set to 1; if the element is zero, the bit in the bitmap corresponding to that element is set to 0. The values ​​of each non-zero element are arranged in a compact manner according to the order of the non-zero bits in the bitmap described in each block, so as to generate second processed data containing the bitmap of each block and the values ​​of each non-zero element.

6. The method according to claim 2, characterized in that, In the L3 channel-level sparse coding mode, third-processed data is generated, which includes channel masks and data for each non-zero channel. Specifically, this includes: Detect channel by channel whether each channel of the input tensor consists entirely of zero elements; If all elements of a channel are zero, then the channel is defined as a zero channel; otherwise, the channel is defined as a non-zero channel. Generate a mask of the same length as the number of channels of the input tensor. Each bit in the mask corresponds to a channel. A bit of 1 indicates that the corresponding channel is a non-zero channel, and a bit of 0 indicates that the corresponding channel is a zero channel. The data from each non-zero channel is compactly arranged to generate third-processed data that includes the channel mask and the data from each non-zero channel.

7. The method according to claim 2, characterized in that, The first processed data, the second processed data, and the third processed data all include index data and payload data, while the fourth processed data only includes payload data, wherein: When the target processing mode is L1 element-level sparse coding mode, the index data is the position information of each non-zero element, and the payload data in the first processing data is the value of each non-zero element. When the target processing mode is L2 block-level sparse coding mode, the index data is a bitmap of each block arranged in block order, and the payload data in the second processing data is the value of each non-zero element arranged in the order corresponding to the non-zero bits in the bitmap. When the target processing mode is L3 channel-level sparse coding mode, the index data is a channel mask, and the payload data in the third processing data is the data of each non-zero channel; when the target processing mode is dense pass-through mode, the fourth processing data only contains payload data, and the payload data is the original dense data of the input tensor.

8. The method according to claim 2, characterized in that, Both the unified hybrid encoding format and the unified dense data format include: The shape information field is used to record the number of rows, columns, and channels of the input tensor; and The non-zero element count field is used to record the total number of non-zero elements in the input tensor.

9. An adaptive multi-granularity sparse processing device, characterized in that, include: The data input port is used to receive an input tensor, which is a feature map of the output of any layer in the convolutional neural network obtained during the inference process of the AI ​​chip, and the input tensor is a multidimensional tensor containing the channel dimension. A sparsity-aware analyzer, whose input is connected to the data input port, is used to analyze the input tensor during runtime to determine the dimension information and sparsity rate of the input tensor. Spatial dispersion and the total number of non-zero elements in the input tensor. ; The sparsity rate is the ratio of the number of zero elements in the input tensor to the total number of elements determined based on the dimension information; The spatial dispersion is obtained by dividing the input tensor into multiple... The number of non-zero blocks containing at least one non-zero element is counted. The spatial dispersion is calculated according to the following formula: in, and The spatial dispersion is a preset positive integer, used to characterize the degree of spatial dispersion of the non-zero elements in the input tensor; The granular decision engine, whose input is connected to the output of the sparse sensing analyzer, is used to set multiple candidate processing modes; based on the sparsity rate... and the spatial dispersion The target processing mode is determined from the multiple candidate processing modes according to preset rules; The encoding package formatting module is used to process the input tensor according to the target processing mode and encapsulate it into data output in the corresponding format.

10. The apparatus according to claim 9, characterized in that, The multiple candidate processing modes include L1 element-level sparse coding mode, L2 block-level sparse coding mode, L3 channel-level sparse coding mode, and dense pass-through mode. The granular decision engine is specifically used to determine the target processing mode from multiple candidate processing modes and output the target processing mode, wherein... , , and For a preset threshold, and , : when and When the target processing mode is determined, the L1 element-level sparse coding mode is determined; when and When the target processing mode is determined, the L2 block-level sparse coding mode is identified. when When the target processing mode is determined, the L2 block-level sparse coding mode is identified. when At that time, the L3 channel-level sparse coding mode is determined as the target processing mode; when At that time, the dense pass-through mode is determined as the target processing mode.

11. The apparatus according to claim 10, characterized in that, The device further includes: A granular router, whose data input terminal is connected to the data input port and whose control input terminal is connected to the output terminal of the granular decision engine, is equipped with a dense direct current path output terminal, an L1 encoding path output terminal, an L2 encoding path output terminal, and an L3 encoding path output terminal. It is used to receive the target processing mode and perform data routing according to the target processing mode: when the target processing mode is a dense direct current mode, the input tensor is routed to the dense direct current path output terminal; when the target processing mode is an L1 element-level sparse coding mode, the input tensor is routed to the L1 encoding path output terminal; when the target processing mode is an L2 block-level sparse coding mode, the input tensor is routed to the L2 encoding path output terminal; when the target processing mode is an L3 channel-level sparse coding mode, the input tensor is routed to the L3 encoding path output terminal. An L1 encoder, whose input is connected to the output of the L1 encoding path of the granular router, is used to perform L1 element-level sparse encoding on the input tensor when the target processing mode is L1 element-level sparse encoding mode, so as to generate the first processing data of the position information and value of each non-zero element. An L2 encoder, whose input is connected to the L2 encoding path output of the granular router, is used to perform L2 block-level sparse encoding on the input tensor when the target processing mode is L2 block-level sparse encoding mode, so as to generate bitmaps of each block and the values ​​of each non-zero element as second processing data. An L3 encoder, whose input is connected to the L3 encoding path output of the granular router, is used to perform L3 channel-level sparse encoding on the input tensor when the target processing mode is L3 channel-level sparse encoding mode, so as to generate channel mask and third processing data of each non-zero channel. The dense pass-through module, whose input is connected to the dense DC path output of the granular router, is used to provide the original dense data of the input tensor as the fourth processing data when the target processing mode is dense pass-through mode. The output of the granular decision engine is connected to the control input of the encoding packet formatting module, and the outputs of the L1 encoder, the L2 encoder, the L3 encoder, and the dense pass-through module are respectively connected to the data input of the encoding packet formatting module. The granular decision engine is also used to output the target processing mode to the encoding packet formatting module, so that the encoding packet formatting module selects to receive corresponding processing data from the L1 encoder, the L2 encoder, the L3 encoder and the dense pass-through module according to the target processing mode, and encapsulates the received processing data into the corresponding format and outputs it.

12. The apparatus according to claim 10, characterized in that: The L1 element-level sparse coding mode uses a single element as the coding unit and uses a coordinate list format to record the position and value of each non-zero element. The position of each non-zero element in the coordinate list format is determined by its channel, row coordinate, and column coordinate. The L2 block-level sparse coding mode is based on A block consisting of 10 elements is used as an encoding unit. A block bitmap is generated to mark the position of non-zero elements in each block, and the values ​​of the non-zero elements are extracted. The L3 channel-level sparse coding mode uses the entire channel of the input tensor as the coding unit to generate a channel mask for marking non-zero channels and extract the data of the non-zero channels.

13. The apparatus according to claim 9, characterized in that, The sparse sensing analyzer includes: A zero-value detection circuit is used to count the number of zero elements and non-zero elements in the input tensor. A successive approximation divider circuit is used to calculate the sparsity based on the number of zero elements and the total number of elements determined based on the dimension information. ; Block statistical circuitry is used to divide the input tensor into multiple... The number of non-zero blocks containing at least one non-zero element is counted. And based on the number of non-zero blocks The total number of non-zero elements in the input tensor and preset block size and Calculate the spatial dispersion.

14. The apparatus according to claim 11, characterized in that, The encoding packet formatting module is specifically used for encapsulation according to the target processing mode, including: When the target processing mode is L1 element-level sparse coding mode, the first processing data is received from the L1 encoder, a granularity identifier field is generated, the position information of each non-zero element in the first processing data is encapsulated as index data, the value of each non-zero element is encapsulated as payload data, and the index data, the payload data and the granularity identifier field are encapsulated together into a unified hybrid coding format and output. When the target processing mode is L2 block-level sparse coding mode, the second processing data is received from the L2 encoder, a granularity identifier field is generated, the bitmap of each block arranged in block order in the second processing data is used as index data, the values ​​of each non-zero element arranged in the order corresponding to the non-zero bits in the bitmap are used as payload data, and the index data, the payload data and the granularity identifier field are encapsulated together into a unified hybrid coding format and output. When the target processing mode is L3 channel-level sparse coding mode, the third processing data is received from the L3 encoder, a granularity identifier field is generated, the channel mask in the third processing data is used as index data, the data of each non-zero channel is used as payload data, and the index data, the payload data and the granularity identifier field are encapsulated together into a unified hybrid coding format and output. When the target processing mode is dense pass-through mode, the fourth processing data is received from the dense pass-through module, a granularity identifier field is generated, the original dense data in the fourth processing data is used as payload data, and together with the granularity identifier field, they are encapsulated into a unified dense data format and output. The granularity identifier field is 2 bits, used to indicate whether the target processing mode is L1 element-level sparse coding mode, L2 block-level sparse coding mode, L3 channel-level sparse coding mode, or dense pass-through mode; the unified hybrid coding format and the unified dense data format both include: a shape information field, used to record the number of rows, columns, and channels of the input tensor; and a non-zero element count field, used to record the total number of non-zero elements in the input tensor.

15. An artificial intelligence (AI) chip, characterized in that, include: The adaptive multi-granularity sparse processing apparatus as described in any one of claims 9 to 14; The computing unit array includes multiple computing circuits. The input terminal of the computing unit array is connected to the output terminal of the adaptive multi-granularity sparse processing device, and is used to receive data in a unified hybrid encoding format or a unified dense data format output by the adaptive multi-granularity sparse processing device, and to perform calculations on the received data.

16. A non-volatile computer-readable storage medium, characterized in that, The system stores computer program instructions that, when executed by a processor, cause the processor to perform the adaptive multi-granularity sparse processing method as described in any one of claims 1 to 8.