CN114640354A - Data compression method and device, electronic equipment and computer readable storage medium - Google Patents

Data compression method and device, electronic equipment and computer readable storage medium Download PDF

Info

Publication number
CN114640354A
CN114640354A CN202210301266.4A CN202210301266A CN114640354A CN 114640354 A CN114640354 A CN 114640354A CN 202210301266 A CN202210301266 A CN 202210301266A CN 114640354 A CN114640354 A CN 114640354A
Authority
CN
China
Prior art keywords
data
memory bank
preset rule
memory
accord
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210301266.4A
Other languages
Chinese (zh)
Inventor
王平
孙洁
李智
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Denglin Technology Co ltd
Original Assignee
Shanghai Denglin Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Denglin Technology Co ltd filed Critical Shanghai Denglin Technology Co ltd
Priority to CN202210301266.4A priority Critical patent/CN114640354A/en
Publication of CN114640354A publication Critical patent/CN114640354A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H03ELECTRONIC CIRCUITRY
    • H03MCODING; DECODING; CODE CONVERSION IN GENERAL
    • H03M7/00Conversion of a code where information is represented by a given sequence or number of digits to a code where the same, similar or subset of information is represented by a different sequence or number of digits
    • H03M7/30Compression; Expansion; Suppression of unnecessary data, e.g. redundancy reduction
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures

Abstract

The application relates to a data compression method, a data compression device, electronic equipment and a computer readable storage medium, and belongs to the technical field of computers. The data compression method comprises the steps of initially compressing original data stored in each of N storage banks to obtain initial compressed data and corresponding data indexes, wherein the N storage banks jointly store the same group of data to be compressed; selecting a memory bank of which the initial compressed data does not accord with a preset rule from the N memory banks; and recompressing the original data stored in the memory bank which does not accord with the preset rule to obtain new compressed data and a corresponding new data index, wherein the new compressed data accord with the preset rule. According to the method and the device, the same group of data to be compressed is stored in N memory banks in a grouping manner, so that the decompression process among the memory banks can be processed in a parallelization manner, and the decompression rate and the decompression throughput are improved; meanwhile, the compression method enables the format of the finally compressed data to be uniform, and further simplifies decoding logic.

Description

Data compression method and device, electronic equipment and computer readable storage medium
Technical Field
The application belongs to the technical field of computers, and particularly relates to a data compression method and device, electronic equipment and a computer readable storage medium.
Background
In recent years, the development of Artificial Intelligence (AI) technology has been rapidly advanced, and remarkable results have been obtained, especially in the direction of image detection and recognition, and speech recognition, the recognition rate of AI has surpassed that of human beings. The neural network processing is an important processing technology for realizing artificial intelligence, while the convolutional neural network algorithm is one of the representative algorithms of the existing deep learning algorithm, and most of the operations of the inference prediction part are convolution operations based on a discrete number domain. The convolution operation includes two Input data types, one is an Input Feature Map (Input Feature Map) obtained in real time, and the other is a weight (weight) obtained offline. The convolution operation is to complete the multiplication and accumulation operation of the input characteristic diagram and the weight, the operation amount is huge, and the weight data has certain sparsity. Therefore, by compressing such weight data, not only the data amount of data transfer from the external storage module to the internal calculation module can be reduced, but also the data amount of internal calculation can be effectively reduced.
Currently, common compression algorithms include Run Length Encoding (Run Length Encoding) algorithm and Huffman Encoding (Huffman Encoding) algorithm. The stroke length compression algorithm is used for encoding according to continuous repeated characters of a character string, and has the defects that the compression rate is greatly dependent on the composition of the character string, and only serial decoding can be performed during decompression due to data stream encoding, so that the performance is not high. The Huffman compression coding algorithm uses a variable-length codebook to code the source symbol, and has the advantages of high compression rate, complex compression algorithm, time consumption in operation, serial decoding during decoding, complex decoding logic and low speed and decoding performance.
Disclosure of Invention
In view of the above, an object of the present application is to provide a data compression method, an apparatus, an electronic device and a computer-readable storage medium, so as to solve the problems that the conventional compression method is complicated and only serial decoding is available during decoding, which results in low decompression efficiency.
The embodiment of the application is realized as follows:
in a first aspect, an embodiment of the present application provides a data compression method, including: performing initial compression on original data stored in each of the N memory banks to obtain initial compressed data and corresponding data indexes; the N memory banks store the same group of data to be compressed together, wherein N is a positive integer greater than or equal to 2; selecting a memory bank of which the initial compressed data does not accord with a preset rule from the N memory banks; and recompressing the original data stored in the memory bank which does not accord with the preset rule to obtain new compressed data and a corresponding new data index, wherein the new compressed data accord with the preset rule.
In the embodiment of the application, the same group of data to be compressed is stored in N memory banks in a grouping manner, and each memory bank is a relatively independent memory element, so that the compression and decompression processes among the memory banks can be processed in a parallelization manner, and the compression and decompression rate and the compression and decompression throughput are improved; meanwhile, during compression, all the memory banks which are not in accordance with the preset rule after initial compression are screened out and then compressed again, so that all the memory banks which are finally compressed are in accordance with the preset rule, the formats of all the compressed data are unified, decoding logic is simplified, and the method has the characteristic of being friendly to decompression hardware.
With reference to one possible implementation manner of the embodiment of the first aspect, selecting a memory bank from the N memory banks in which the initial compressed data does not meet the preset rule includes: acquiring the number of lines occupied by the initial compressed data of each memory bank; and selecting a memory bank with the number of the initially compressed data lines not equal to the designated number of the lines from the N memory banks, wherein the memory bank with the number of the initially compressed data lines not equal to the designated number of the lines is the memory bank which does not accord with the preset rule.
In the embodiment of the application, whether the memory bank is the memory bank meeting the preset rule or not is judged by utilizing the line number occupied by the initial compressed data of the memory bank without additionally introducing other conditions, so that the method has the advantage of simple judgment logic, the memory bank not meeting the preset rule can be quickly selected, meanwhile, the specified line number can be set as required, and the applicability and the flexibility of the scheme are improved; most importantly, as the line number is used as the minimum storage granularity of the memory bank, the memory banks which occupy the same line number but have different element numbers in the line number occupy the same storage space, so that the line number is used as a judgment index, the number of the memory banks which are judged to be not in accordance with the preset rule can be reduced, the data of the memory banks which need to be recompressed can be reduced, and the compression efficiency is improved.
With reference to a possible implementation manner of the embodiment of the first aspect, the specified line number is a maximum line number, and the maximum line number is a maximum line number in line numbers occupied by initial compressed data of the N memory banks.
In the embodiment of the application, the maximum line number is selected as the designated line number, so that the line numbers occupied by the data in all the memory banks are consistent and are the maximum line numbers, and the logic of decompression of the right group can be completed only by clearly reading the data amount from the memory component during hardware decompression.
With reference to a possible implementation manner of the embodiment of the first aspect, the recompressing the original data stored in the memory bank that does not meet the preset rule includes: selecting a target memory bank which has the minimum number of data lines after initial compression from all memory banks which accord with the preset rule and is larger than the number of data lines after initial compression of the memory bank which does not accord with the preset rule aiming at each memory bank which does not accord with the preset rule; and recompressing the original data stored in the memory bank which does not accord with the preset rule by taking the number of rows of the data after the initial compression of the target memory bank as a reference, so that the number of rows of the recompressed data is consistent with the number of rows occupied by the initial compressed data of the target memory bank.
In the embodiment of the application, when the original data stored in the memory bank which does not accord with the preset rule is recompressed, the target memory bank is used as a reference for recompression, so that the number of rows of the recompressed data is consistent with the number of rows occupied by the initial compressed data of the target memory bank; meanwhile, when a target memory bank is selected, a memory bank which has the minimum number of data lines after initial compression and is larger than the number of data lines after initial compression of the memory bank which does not accord with the preset rule is selected as the target memory bank, so that the introduced data volume can be reduced during recompression, and the compression efficiency is improved, for example, assuming that the number of data lines after initial compression of the memory bank which accords with the preset rule is three, namely 2, 4 and 5, and the number of data lines after initial compression of the memory bank which does not accord with the preset rule is 3, based on the principle, the target memory bank is a memory bank which has the number of data lines after initial compression is 4, so that when the memory bank which does not accord with the preset rule is recompressed, the number of new compressed data is 4 instead of 5, and the introduced data volume can be reduced, the compression efficiency is improved.
With reference to a possible implementation manner of the embodiment of the first aspect, based on the number of data lines after the initial compression of the target memory bank, the recompression of the original data stored in the memory bank that does not meet the preset rule includes: acquiring a first quantity of zero-value data in the original data stored in the target memory bank, and acquiring a second quantity of zero-value data in the original data stored in the memory bank which does not accord with a preset rule; acquiring an absolute value of the difference between the first quantity and the second quantity, and selecting the minimum value of the absolute value and the second numerical value; and performing recompression on the zero-value data of the first minimum number from the lowest address in the original data stored in the memory bank which does not accord with the preset rule as non-zero data.
In the embodiment of the application, when the original data stored in the memory bank which does not accord with the preset rule is recompressed, zero value data of the first minimum number from the lowest address in the original data stored in the memory bank which does not accord with the preset rule is recompressed as non-zero data, so that the original data stored in the memory bank which does not accord with the preset rule can be quickly recompressed into a format which is consistent with the memory bank which accords with the preset rule; meanwhile, the number of the zero value data as the non-zero data is reduced as much as possible, so that the recompression and decompression rates are improved.
With reference to a possible implementation manner of the embodiment of the first aspect, based on the number of data lines after the initial compression of the target memory bank, the recompression of the original data stored in the memory bank that does not meet the preset rule includes: acquiring a first difference value between the quantity of original data stored in a memory bank which does not accord with a preset rule and the quantity of initial compressed data corresponding to a target memory bank; acquiring a difference value between the number of zero-value data in the original data stored in the memory bank which does not accord with the preset rule and the first difference value to obtain a second difference value; and performing recompression on zero-valued data of the first second difference number from the highest address in the original data stored in the memory bank which do not accord with the preset rule as non-zero data.
In the embodiment of the application, when the original data stored in the memory bank which does not accord with the preset rule is recompressed, the zero-value data of the first second difference number from the highest address in the original data stored in the memory bank which does not accord with the preset rule is recompressed as the non-zero data, so that the original data stored in the memory bank which does not accord with the preset rule can be quickly recompressed into the format consistent with the format of the memory bank which accords with the preset rule, meanwhile, when the data are recompressed, only part of the zero-value data are recompressed as the non-zero data, no additional data are introduced, and therefore the decompression efficiency can be improved.
With reference to a possible implementation manner of the embodiment of the first aspect, the initially compressing the original data stored in each of the N memory banks includes: removing zero-value data stored in each memory bank, and sequentially arranging and combining the rest original data; and filling up the blank spaces of the lines occupied by the arrangement combination by using the specified numerical data.
In the embodiment of the application, the blank spaces of the lines occupied by the arranged and combined data are filled by using the data with the specified numerical value, so that the compressed data are integer lines, and thus, when the data are decompressed, hardware can better distinguish different compressed data groups, and the decompression efficiency can be accelerated.
In a second aspect, an embodiment of the present application further provides a data compression apparatus, including: the device comprises an initial compression module, a selection module and a recompression module; the initial compression module is used for initially compressing the original data stored in each of the N memory banks to obtain initial compressed data and corresponding data indexes; the N memory banks store the same group of data to be compressed together, wherein N is a positive integer greater than or equal to 2; the selection module is used for selecting a memory bank of which the initial compressed data does not accord with a preset rule from the N memory banks; and the recompression module is used for recompressing the original data stored in the memory bank which does not accord with the preset rule to obtain new compressed data and a corresponding new data index, wherein the new compressed data accord with the preset rule.
In a third aspect, an embodiment of the present application further provides an electronic device, including: the processor is connected with the memory; the memorizer, is used for storing the procedure and storing the data to be compressed; a processor, configured to invoke a program stored in a memory, to perform the method according to the foregoing first aspect embodiment and/or any possible implementation manner of the first aspect embodiment.
In a fourth aspect, this embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, performs the method in the foregoing first aspect embodiment and/or any possible implementation manner of the first aspect embodiment.
Additional features and advantages of the application will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the embodiments of the application. The objectives and other advantages of the application may be realized and attained by the structure particularly pointed out in the written description and drawings.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings without creative efforts. The foregoing and other objects, features and advantages of the application will be apparent from the accompanying drawings. Like reference numerals refer to like parts throughout the drawings. The drawings are not intended to be to scale as practical, emphasis instead being placed upon illustrating the subject matter of the present application.
Fig. 1 shows a schematic flow chart of a data compression method provided in an embodiment of the present application.
Fig. 2 shows a schematic diagram of data to be compressed stored in bank0 and bank1 according to an embodiment of the present application.
Fig. 3 shows a schematic diagram of initial compressed data and corresponding data indexes obtained after initial compression is performed on original data stored in a bank0 and a bank1 according to an embodiment of the present application.
Fig. 4 shows a schematic diagram of new compressed data obtained by recompressing original data stored in the bank1 and a corresponding new data index according to an embodiment of the present application.
Fig. 5 is a schematic diagram illustrating still another new compressed data obtained by recompressing the original data stored in the bank1 and a corresponding new data index according to an embodiment of the present application.
Fig. 6 shows a block schematic diagram of a data compression apparatus according to an embodiment of the present application.
Fig. 7 shows a schematic structural diagram of an electronic device provided in an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, relational terms such as "first," "second," and the like may be used solely in the description herein to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
Further, the term "and/or" in the present application is only one kind of association relationship describing the associated object, and means that three kinds of relationships may exist, for example, a and/or B may mean: a exists alone, A and B exist simultaneously, and B exists alone.
In view of the defects of the existing data compression method, the application provides a data compression method for compressing original data, such as convolution weight (weight) data for convolution calculation, the data compression is realized by utilizing the sparse characteristic of the original data, and the data compression method has the advantages of high compression speed, high compression ratio, simple decoding logic, parallelizable decoding and friendly realization of decompression hardware. It should be noted that the data compression method shown in the present application is not limited to compression of convolution weights, and the data compression method can be applied to any data compression having a sparse characteristic.
The data compression method provided by the embodiment of the present application will be described below with reference to fig. 1.
S1: and performing initial compression on the original data stored in each of the N memory banks to obtain initial compressed data and corresponding data indexes.
Considering that data is usually stored in a storage device (buffer), such as a memory, and usually one storage device is composed of M banks (banks), in order to accelerate compression efficiency and to operate in parallel when decompressing, the present application stores a same set of data to be compressed in N banks, that is, N banks store a same set of data to be compressed together, where each bank stores a part of the set of data to be compressed, that is, the data to be compressed is divided into N parts and stored in N banks respectively. Each bank of the buffer is a relatively independent storage element, so that the parallelization of the decompression process among the banks can be realized, and the decompression rate and the decompression throughput are improved. Wherein N is a positive integer greater than or equal to 2, and M is a positive integer greater than or equal to N.
Assuming that the data bit width storable in each row of each memory bank is C, the bit range of storable data is represented by C-1:0, wherein the data bit width commonly used in the art includes, but is not limited to, 64, 128, 256 bits, and the like. The number of bits occupied by a single data is denoted by C, which should typically be a multiple of 4, then C/C data can be stored per row. The data types supported by the application comprise 4-bit integer type, 8-bit integer type, 16-bit integer type, 32-bit integer type, 16-bit floating point, 32-bit floating point, 64-bit floating point and the like.
The data compression method provided by the application is carried out based on each memory bank as a minimum unit, and during compression, initial compression is carried out on original data stored in each memory bank of N memory banks to obtain initial compressed data and corresponding data indexes.
In an alternative embodiment, the process of initially compressing the raw data stored in each memory bank may be: the zero-value data stored in each memory bank is removed, and then the rest original data are sequentially arranged and combined together, so that initial compressed data are obtained. According to the method and the device, the characteristic that the weighted data participating in the convolution operation has sparseness is considered, so that zero-value data in the original data stored in the memory bank can be removed firstly during compression, and then the rest original data are closely arranged and combined together. In addition, in order to restore the compressed data during decompression, a data index needs to be correspondingly generated so as to indicate which original data are zero-valued data and are data that are discarded.
For convenience of understanding, for example, it is assumed that the original data stored in a certain memory bank is {0, 1, 3, 0, 0, 0, 0, 0, 0, 5, 2, 5, 1, 0, 0, 1}, and the initial compressed data obtained after the initial compression is {1, 3, 5, 2, 5, 1, 1 }.
The data index used for restoring the compressed original data may have various implementations, for example, 1 and 0 may be used to form the data index, such as 1 is used to represent non-zero value data in the original data, and 0 is used to represent zero value data in the original data. Taking the above example as an example, the corresponding data index is {0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1 }. Since the data of the 0 th position in the above example is "0", the corresponding index is 0; the data of the 1 st position is 1, and the corresponding index is 1; by analogy, the data at the 14 th position is "0", and the corresponding index is 0; the data at the 15 th position is "1", and the corresponding index is 1.
Of course, in addition to the data index in the above manner, other manners may be adopted, for example, the data index corresponding to the compressed original data is determined according to the absolute position of the non-zero value data in the memory bank. Also taking the above example as an example, the corresponding data index is {1, 2, 9, 10, 11, 12, 15}, i.e. the data index represents the absolute position of the original data retained after compression in the original data. For original data '1' reserved after compression, the position sequence number of the original data is 1; for original data '3' reserved after compression, the position sequence number of the original data is 2; for original data '5' reserved after compression, the position sequence number of the original data is 9; for original data "2" reserved after compression, the position sequence number of the original data is 10; for original data "5" reserved after compression, the position sequence number of the original data is 11; for original data '1' reserved after compression, the position sequence number of the original data is 12; for the original data "1" remaining after compression, its position number in the original data is 15.
In addition, the data index corresponding to the compressed original data can be determined according to the absolute position of the zero weight in the original data. Also taking the above example as an example, the corresponding data index is {0, 3, 4, 5, 6, 7, 8, 13, 14}, where "0" in the data index indicates the 0 th position of the zero weight in the original data before compression; "3" in the data index represents the 3 rd position of the zero weight in the original data before compression; "4" in the data index represents the 4 th position of the zero weight in the original data before compression; by analogy, "14" in the data index represents the 14 th position of the zero weight in the original data before compression.
In addition, the data index corresponding to the compressed original data can be determined according to the number of zero-value data spaced between the non-zero-value data in the original data and the previous non-zero-value data. Also for the above example, the corresponding data index is {1, 0,6, 0, 0, 0, 2 }. For the original data "1" retained after compression, the number of zero-value data in the middle interval is 1 relative to the previous non-zero-value data (no non-zero-value data exists in front of the original data); for the original data "3" remaining after compression, the number of zero-value data of the middle interval is 0 relative to the previous non-zero-value data (the non-zero-value data before the original data is "1"); for the original data "5" remaining after compression, the number of zero-valued data of the middle interval is 6 with respect to the previous non-zero-valued data (the non-zero-valued data before it is "3"); for the original data "2" remaining after compression, the number of zero-value data of the middle interval is 0 with respect to the previous non-zero-value data (the non-zero-value data before the original data is "5"); for the original data "5" remaining after compression, the number of zero-value data of the middle interval is 0 with respect to the previous non-zero-value data (the non-zero-value data before the original data is "2"); for the original data "1" remaining after compression, the number of zero-value data of the middle interval is 0 relative to the previous non-zero-value data (the non-zero-value data before the original data is "5"); for the original data "1" remaining after compression, the number of zero-valued data of the middle interval is 2 with respect to the previous non-zero-valued data (the non-zero-valued data before it is "1").
Besides the above manner, the data index and the like corresponding to the compressed original data can be determined according to the number of the non-zero-value data spaced between the zero-value data in the original data and the previous zero-value data. It should be noted that, in the present application, the implementation manner of the data index is not limited, and any data index manner may be used as long as the compressed original data can be restored to the original data according to the data index.
In an alternative embodiment, the process of initially compressing the raw data stored in each of the N memory banks may be: and removing zero-value original data stored in each memory bank, sequentially arranging and combining the rest original data, and filling up spaces of lines occupied by the arranged and combined data by using designated numerical data. When the original data is initially compressed and the remaining original data are sequentially arranged and combined together, if the occupied lines still have spaces after the remaining original data are arranged and combined together, the spaces of the lines occupied after arrangement and combination can be filled (supplemented) by using a specified numerical value (such as zero-value data or useless data), and the spaces of the occupied lines are supplemented, so that hardware can better distinguish different weight groups, and the decompression efficiency can be accelerated.
For ease of understanding, for example, it is assumed that each line of each memory bank can store 8 data, and 16 initial raw data are compressed to obtain 7 non-zero data, and since there is a space in the line occupied by the 7 non-zero data, the remaining spaces can be filled with 0. For another example, after 16 original data are compressed, 9 non-zero data are obtained, and the 9 non-zero data occupy two lines, wherein the second line has only 1 data and 7 spaces remain, so that the remaining 7 spaces can be filled with 0.
The compressed data is an integer line by filling the line occupied by the compressed data with the blank space by using the data with the specified value, so that the hardware can better distinguish different compressed data groups during decompression and can accelerate the decompression efficiency. The number of the filled data is C/C x the number of the data lines after the initial compression-the number of the non-zero data in the original data, and is expressed by the following formula: C/C compressed _ entry _ for _ bank [ i ] -non _ zero _ count [ i ], wherein C/C represents the number of data storable per line, compressed _ entry _ for _ bank [ i ] represents the number of data lines of the initial compressed data of the ith memory bank, and non _ zero _ count [ i ] represents the number of non-zero data in the initial data stored in the ith memory bank. It should be noted that, when the original data stored in the memory bank is initially compressed, if the data needs to be quantized, in an embodiment, the stored original data (such as floating point data) may be quantized (that is, the floating point data is converted into fixed point data), and then the quantized fixed point data may be initially compressed. An effective data mapping relation is established through quantification, so that fixed point data and floating point data are bridged, and good benefits are obtained with low precision loss cost. The following explains the principle of quantization and dequantization:
the quantization formula from floating point data to fixed point data is Q ═ Z + R/S, and the inverse quantization formula from fixed point data to floating point data is R ═ Q-Z × S. Wherein, R represents the real floating point value, Q represents the quantized fixed point value, Z represents the quantized fixed point value corresponding to the floating point value 0, S is the minimum scale which can be represented after fixed point quantization, and the evaluation formula of S and Z is as follows:
s ═ Rmax-Rmin)/(Qmax-Qmin), Z ═ Qmax-Rmax/S. Where Rmax represents the largest floating-point value, Rmin represents the smallest floating-point value, Qmax represents the largest fixed-point value, and Qmin represents the smallest fixed-point value.
Wherein, S and Z are quantization parameters, and Q and R can be evaluated by formulas, and whether the quantized Q or the floating point value R obtained by inverse quantization, if they exceed the respective maximum representable range, the truncation processing is required (the maximum value is exceeded, and the maximum value is represented, and the minimum value is less than the maximum value, and the minimum value is represented). While the floating point value 0 has a significant meaning in the neural network, such as 0 used in padding, an accurate integer value must be provided to correspond to the floating point value 0 (i.e., zero is quantized).
The model quantization evaluation process is explained below. After model training, the weight is often distributed in a limited range, for example, the weight range is [ -2.0,6.0], if int8 (signed 8-bit integer) is used for model quantization, the fixed point quantization value range is [ -128,127], and then the evaluation process of S and Z is as follows:
Figure BDA0003562972520000121
Z=127-6.0÷0.031372549≈127-191.25≈-64.25≈-64
then the following correspondence table exists:
Figure BDA0003562972520000122
Figure BDA0003562972520000131
assuming that R is 0.28, then the corresponding Q is evaluated as follows:
Q=0.28÷0.031372549+(-64)≈8.925-64≈-55.075≈-55
thus, quantized values of all weights can be obtained one by one.
S2: and selecting a memory bank of which the initial compressed data does not accord with the preset rule from the N memory banks.
After initial compression is performed on original data stored in each of the N memory banks to obtain initial compressed data and corresponding data indexes, memory banks, of which the initial compressed data do not accord with a preset rule, are selected from the N memory banks so as to perform recompression on the original data stored in the memory banks which do not accord with the preset rule.
The process of selecting the memory bank in which the initial compressed data does not meet the preset rule from the N memory banks may be: and acquiring the line number occupied by the initial compressed data of each memory bank, and selecting the memory banks with the data line numbers not equal to the specified line number from the N memory banks, wherein the memory banks with the data line numbers not equal to the specified line number are the memory banks which do not accord with the preset rule.
B may be used to represent the number of the designated line numbers corresponding to the N memory banks, that is, the N memory banks may have a plurality of designated line numbers, where B is an integer from 1 to N, for example, the minimum value is 1, and the maximum value is N. In one embodiment, the specified number of lines is the maximum number of lines among the number of lines occupied by the original data stored in the N banks after the initial compression, where the specified number of lines is only one, i.e., B is 1. And the memory bank with the data line number smaller than the maximum line number is the memory bank which does not accord with the preset rule. For convenience of understanding, for example, it is assumed that there are 2 memory banks, namely, a memory bank0 and a memory bank1, if the number of rows occupied by the initial compressed data of the memory bank0 is 3, and the number of rows occupied by the initial compressed data of the memory bank1 is 2, since the number of rows of data after the initial compression of the original data in the memory bank1 is less than the maximum number of rows (in this case, 3), the memory bank1 is a memory bank that does not meet the preset rule. This approach can be generalized to more memory banks and is not limited to the 2 bank case of the example above.
In the implementation mode that the designated number of lines is the maximum number of lines, after the original data in the memory bank which does not conform to the preset rule is recompressed, the number of lines occupied by the new compressed data is equal to the maximum number of lines, at this time, the number of lines occupied by the data in all the memory banks is the maximum number of lines, so that the decompression logic of the weight group can be completed only by knowing how much data amount is read from the memory component during hardware decompression. For example, the decompression of the weight set can be done by only reading the data amount of the maximum number of rows C N from the storage means.
In another embodiment, the specified number of rows may include other numbers of rows in addition to the maximum number of rows. That is, the number of the designated rows may be plural, and B is an integer greater than or equal to 2 and smaller than N. For convenience of understanding, for example, it is assumed that there are 4 memory banks, namely, memory bank0, memory bank1, memory bank2, and memory bank3, if the number of lines occupied by the initial compressed data of memory bank0 is 3, the number of lines occupied by the initial compressed data of memory bank1 is 2, the number of lines occupied by the initial compressed data of memory bank2 is 1, and the number of lines occupied by the initial compressed data of memory bank3 is 2. Assuming that the designated row number B is 2, that is, the number of the designated row number is 2, and if the designated row number can be two row numbers of 3 rows and 2 rows, the bank whose row number does not match the designated row number in the above 4 banks (bank 0, bank1, bank2, bank 3) is bank 2. Thus, only the bank2 is recompressed at the time of recompression, which can improve the compression efficiency.
In an embodiment, the number B of the designated line numbers may be set in advance, and the value of B is an integer from 1 to N. If B is 1, the specified line number is the maximum line number; if B is an integer greater than or equal to 2, the specified number of rows includes B-1 other number of rows in addition to the maximum number of rows. The selection principle of other rows can be: after the other line numbers are selected, after the memory bank which does not accord with the preset rule is recompressed, the sum of all data line numbers which do not accord with the preset rule after the memory bank is recompressed and the sum of all data line numbers which accord with the preset rule after the memory bank is initially compressed needs to be minimum. For example, in the case of combining the above 4 banks, if B is 2, the number of designated lines is not less than the maximum number of lines 3, and the remaining designated line number is selected between line number 1 and line number 2, and if the remaining designated line number is selected to be line number 1, then bank1 and bank3 need to be recompressed, and then the number of recompressed lines is 3, and at this time, the total number of lines of 4 banks is 3 lines of bank0 + 3 lines of bank1 + 1 lines of bank2 + 3 lines of bank3 ═ 10 lines. If one specified number of rows remains to select row number 2, then bank2 only needs to be recompressed, and the number of rows after bank2 recompression is 2, and in this case, the total number of rows of 4 banks is 3 rows of bank0 + 2 rows of bank1 + 2 rows of bank2 + 2 rows of bank3, which is 9 rows. Therefore, one designated line number remains to select the line number 2.
S3: and recompressing the original data stored in the memory banks which do not accord with the preset rules.
After selecting a memory bank of which the initial compressed data does not accord with the preset rule from the N memory banks, recompressing the original data stored in the memory bank which does not accord with the preset rule to obtain new compressed data and a corresponding new data index, wherein the recompression process is similar to the initial compression process, and the difference is that when recompressing, part of zero-value data in the original data is required to be compressed as non-zero data so that the new compressed data obtained after recompression accords with the preset rule.
In one embodiment, the process of recompressing the original data stored in the storage volume that does not comply with the preset rule may be: and selecting a target memory bank from the memory banks which accord with the preset rule aiming at each memory bank which does not accord with the preset rule, and recompressing the original data stored in the memory banks which do not accord with the preset rule by taking the number of data lines of the target memory bank after initial compression as a reference, so that the number of data lines after recompression is consistent with the number of data lines of the target memory bank after initial compression.
When the target memory bank is selected from the memory banks conforming to the preset rule, for each memory bank not conforming to the preset rule, the target memory bank in which the number of data lines after initial compression is the smallest is selected from all the memory banks conforming to the preset rule, and the number of data lines after initial compression is greater than the number of data lines after initial compression of the memory bank not conforming to the preset rule. For ease of understanding, the description is made with reference to examples. If 4 banks are assumed, which are respectively bank0, bank1, bank2, and bank3, if the number of lines occupied by the initial compressed data of bank0 is 5, the number of lines occupied by the initial compressed data of bank1 is 4, the number of lines occupied by the initial compressed data of bank2 is 1, and the number of lines occupied by the initial compressed data of bank3 is 2. If B is 2, the number of rows is specified to be 5 and 2. The memory banks conforming to the preset rule are the memory bank0 and the memory bank3, respectively, and the memory banks not conforming to the preset rule are the memory bank1 and the memory bank2, respectively. When selecting the target memory bank for the memory bank1, it is necessary to select from the memory banks 0 and 3, and since the number of data lines after initial compression of the memory bank1 is 4, a memory bank with the smallest number of data lines after initial compression and larger than 4 is selected from the memory banks 0 and 3 as the target memory bank, and the memory bank conforming to this rule is the memory bank0, that is, the target memory bank of the memory bank1 is the memory bank 0. Similarly, when selecting the target memory bank for the memory bank2, it needs to select from the memory bank0 and the memory bank3, and since the number of rows of data after initial compression of the memory bank2 is 1, it selects the memory bank that has the smallest number of rows of data after initial compression from the memory bank0 and the memory bank3 and needs to be greater than 2 as the target memory bank, and the memory bank that meets this rule is the memory bank3, that is, for the memory bank2, the target memory bank is the memory bank 3.
It should be noted that, in addition to selecting the target memory bank by using the above rule (for each memory bank that does not conform to the preset rule, selecting the target memory bank in which the number of lines of initially compressed data is the smallest from all memory banks that conform to the preset rule, and the number of lines of initially compressed data is greater than the number of lines of initially compressed data of the memory bank that does not conform to the preset rule), a memory bank in which the number of lines of initially compressed data is greater than the number of lines of initially compressed data of the memory bank that does not conform to the preset rule may be selected from all memory banks that conform to the preset rule to serve as the target memory bank. For example, assuming that the number of lines of the initially compressed data of the memory banks that meet the preset rule is three, namely 2, 4, and 5, and the number of lines of the initially compressed data of the memory banks that do not meet the preset rule is 3, based on the above principle, the target memory bank is the memory bank whose number of lines of the initially compressed data is 4.
When the original data stored in the memory bank that does not meet the preset rule is recompressed by using the number of data lines after the initial compression of the target memory bank as a reference, in an implementation manner, the data compression method may include: the method comprises the steps of obtaining a first quantity of zero-value data in original data stored in a target memory bank, obtaining a second quantity of zero-value data in the original data stored in the memory bank which does not accord with a preset rule, then obtaining an absolute value of the difference between the first quantity and the second quantity, selecting the minimum value between the absolute value and the second value, then recompressing the original data stored in the memory bank which does not accord with the preset rule, and during recompression, recompressing the zero-value data of the front-minimum number starting from the lowest address (LSB) in the original data stored in the memory bank which does not accord with the preset rule as non-zero data. Assuming that the number of zero-valued data in the original data stored in each bank is denoted by org _ zero _ count, the number of non-zero data is denoted by non _ zero _ count, and the absolute value of the difference between the first number and the second number is denoted by delta _ non _ zero _ count, the minimum value between the absolute value and the second number may be denoted as min (delta _ non _ zero _ count, org _ zero _ count). Assuming that the minimum value is 5, since the first 5 zero-value data starting from the lowest address are regarded as non-zero data, when recompressing, the first 5 zero-value data starting from the lowest address are not removed, and only the subsequent zero-value data are removed.
It should be noted that, since the non-zero data and the zero-value data in the raw data stored in the memory bank are relative, the above process may also be: the method comprises the steps of obtaining a first quantity of non-zero data in original data stored in a target memory bank, obtaining a second quantity of the non-zero data in the original data stored in the memory bank which does not accord with a preset rule, then obtaining an absolute value of the difference between the first quantity and the second quantity, then obtaining a minimum value of an absolute value and a zero value data quantity in the original data stored in the memory bank which does not accord with the preset rule, and taking the zero value data of the first minimum value number from the lowest address in the original data stored in the memory bank which does not accord with the preset rule as the non-zero data to be recompressed.
In yet another embodiment, the recompression process shown in S3 may be: the method comprises the steps of obtaining a first difference value between the number of original data stored in a memory bank which does not accord with a preset rule and the number of initial compressed data corresponding to a target memory bank, then obtaining a difference value between the number of zero-valued data in the original data stored in the memory bank which does not accord with the preset rule and the first difference value to obtain a second difference value, then recompressing the original data stored in the memory bank which does not accord with the preset rule, and recompressing zero-valued data of the number of the second difference value from the highest address (MSB) as non-zero data in the original data stored in the memory bank which does not accord with the preset rule during recompression. Assuming that the number of initial compressed data corresponding to the target memory bank is 24 and the number of original data stored in the memory bank which does not meet the preset rule is 32, the first difference is 8, and assuming that the number of zero-value data in the original data stored in the memory bank which does not meet the preset rule is 22, the second difference is 22-8-16, that is, during recompression, the first 16 zero-value data starting from the highest address in the original data stored in the memory bank which does not meet the preset rule need to be recompressed as non-zero data, and the rest zero-value data need to be compressed normally (removed during compression).
For ease of understanding, for example, assuming that N is 2, C is 256, and C is 32, each bank may store 8 data per row, and assuming that the original data sets to be compressed stored in bank0 and bank1 are as shown in fig. 2. Wherein, bank0 includes 130 s, bank1 includes 220 s, bank0 and bank1 are initially compressed, zero data are all removed, 19 valid data remain in bank0, and 5 (8 × 3-19) zero data need to be additionally filled for completion. Similarly, bank1 contains 10 valid data, and needs to be filled with 6 (8 × 2-10) zero data for completion. Initial compressed data and corresponding data indexes obtained by performing initial compression on the original data stored in the bank0 and the bank1 are shown in fig. 3.
For the generation process of the data index, the position of the original data in the bank0 can be represented by two-dimensional coordinates, such as coordinates (0, 0) representing the first element (starting from the lower bit) of the 0 th row, which is 0; (0, 2) represents the third element of row 0, which is 1; (1, 0) represents the first data of line 1, which is 8, and so on. For a coordinate point with a value of 0, at the same index coordinate point, bit 0 is filled, and data indicating the coordinate point is zero and is eliminated. For a coordinate point with a non-zero value, at the same index coordinate point, bit 1 is filled, and data indicating the coordinate point is non-zero and is reserved. Based on the above method, the numerical value of the data at the coordinate (0, 0) position is 0, so the index at the coordinate (0, 0) position is 0, and the data at the coordinate (1, 0) and (0, 2) positions are not 0, so the index at the same coordinate position is 1. According to the method, all the bank compressed data and corresponding indexes can be obtained. It should be noted that the data indexes in the examples herein are formed by 1 and 0, for example, 1 represents non-zero value data in the original data, and 0 represents zero value data in the original data, so as to obtain corresponding data indexes. In addition to this, other means as described above may be employed.
Assuming that the number B of the specified line numbers is 1, the number of data lines after the bank0 initial compression is 3, and the number of data lines after the bank1 initial compression is 2, so the original data stored in the bank1 needs to be recompressed.
In one embodiment, when the original data stored in the bank1 is recompressed, a first amount (e.g. 13) of data in the original data stored in the bank0 is obtained, and a second amount (e.g. 22) of zero-valued data in the original data stored in the bank1 is obtained, so that an absolute value of a difference between the first amount and the second amount is 9. Then Min (9, 22) ═ 9, so when the original data stored in the bank1 is recompressed, it is necessary to recompress the first 9 zero-value data starting from the lowest address (LSB) in the original data as non-zero data, that is, 5 zeros in coordinates (0, 0) to (0, 7) and 4 zeros in coordinates (1, 0) to (1, 5) in the original data are recompressed as non-zero, and the new compressed data and the corresponding new data index obtained after the original data stored in the bank1 is recompressed are as shown in fig. 4.
In still another embodiment, still using the example shown in fig. 2, after the bank1 is recompressed, the number of data rows thereof is consistent with the number of rows occupied by the initial compressed data of the bank0, and the number of the initial compressed data corresponding to the bank0 is 24, so that for the original 32 data of the bank1, when performing recompression, 8 zeros thereof need to be compressed, so that the number of the new compressed data is 24. The number of zero-value data in the original data stored in the bank1 is 22, so that when recompressing, the first 14(22-8) zero-value data from the highest address in the original data stored in the bank1 needs to be recompressed as non-zero data, and in this embodiment, the new compressed data and the corresponding new data index obtained by recompressing the original data stored in the bank1 are shown in fig. 5.
In addition, if the number of the designated row numbers is not 1, that is, B is an integer greater than or equal to 2 and less than N, the value of B, the designated row number, and the row number occupied by each bank need to be recorded in addition to the compressed data and the corresponding data index of each bank. Taking the above-mentioned assumption that there are 4 banks, namely bank0, bank1, bank2 and bank3, if the number of rows occupied by the initial compressed data of bank0 is 3, the number of rows occupied by the initial compressed data of bank1 is 2, the number of rows occupied by the initial compressed data of bank2 is 1, and the number of rows occupied by the initial compressed data of bank3 is 2. Assume that the number of designated rows is 2, e.g., two rows of 3 and 2 are designated. Then in addition to recording the compressed data of each bank and the corresponding data index, it is also necessary to record: b is 2, the row number {3, 2} is specified, and the row number for bank0 is 3, and the row number for bank1, bank2, bank3 is 2. The number of rows occupied by each bank compressed data may be recorded as a set of binary numbers 1110, such as the number of rows occupied by bank0, bank1, bank2, bank3 compressed data, where the lowest 0 in the binary number indicates that bank0 uses the zeroth element of the {3, 2} set, the next lowest bit in the binary number indicates that bank1 uses the 1 st element of the {3, 2} set, and so on.
Based on the same inventive concept, the embodiment of the present application further provides a data compression apparatus 100, as shown in fig. 6. The data compression apparatus 100 includes an initial compression module 110, a selection module 120, and a recompression module 130.
An initial compression module 110, configured to perform initial compression on original data stored in each of the N memory banks to obtain initial compressed data and a corresponding data index; the N memory banks store the same group of data to be compressed together, and N is a positive integer greater than or equal to 2.
The selecting module 120 is configured to select a memory bank from the N memory banks, where the initial compressed data does not meet the preset rule.
The recompression module 130 is configured to recompress the original data stored in the memory bank that does not meet the preset rule to obtain new compressed data and a corresponding new data index, where the new compressed data meets the preset rule.
Optionally, the initial compression module 110, when performing initial compression on the original data stored in each of the N memory banks, is specifically configured to: removing zero-value data stored in each memory bank, and sequentially arranging and combining the rest original data; and filling up the blank spaces of the lines occupied by the permutation and combination by using the specified numerical data.
The selecting module 120, when selecting a memory bank from the N memory banks for which the initial compressed data does not meet the preset rule, is specifically configured to: acquiring the number of lines occupied by the initial compressed data of each memory bank; and selecting a memory bank with the number of the initially compressed data lines not equal to the designated number of the lines from the N memory banks, wherein the memory bank with the number of the initially compressed data lines not equal to the designated number of the lines is the memory bank which does not accord with the preset rule.
Optionally, the recompression module 130, when recompressing the original data stored in the memory bank that does not meet the preset rule, is specifically configured to: and selecting a target memory bank from the memory banks which do not accord with the preset rule aiming at each memory bank which does not accord with the preset rule, and recompressing the original data stored in the memory banks which do not accord with the preset rule by taking the number of rows of the data after the initial compression of the target memory bank as a reference, so that the number of rows of the recompressed data is consistent with the number of rows occupied by the initial compressed data of the target memory bank.
Optionally, the recompression module 130, when selecting the target bank from the banks that meet the preset rule for each bank that does not meet the preset rule, is specifically configured to: and selecting a target memory bank with the minimum number of data lines after initial compression from all memory banks which accord with the preset rule and are larger than the number of data lines after initial compression of the memory bank which does not accord with the preset rule aiming at each memory bank which does not accord with the preset rule.
Optionally, the recompression module 130, when recompressing the original data stored in the memory bank that does not conform to the preset rule with the number of data lines after the initial compression of the target memory bank as a reference, is specifically configured to: acquiring a first quantity of zero-value data in the original data stored in the target memory bank, and acquiring a second quantity of zero-value data in the original data stored in the memory bank which does not accord with a preset rule; acquiring an absolute value of the difference between the first quantity and the second quantity, and selecting the minimum value of the absolute value and the second numerical value; and taking the zero-value data of the front minimum number from the lowest address in the original data stored in the memory bank which does not accord with the preset rule as non-zero data for recompression.
Optionally, the recompression module 130, when recompressing the original data stored in the memory bank that does not conform to the preset rule with the number of data lines after the initial compression of the target memory bank as a reference, is specifically configured to: acquiring a first difference value between the quantity of original data stored in a memory bank which does not accord with a preset rule and the quantity of initial compressed data corresponding to a target memory bank; acquiring a difference value between the number of zero-value data in the original data stored in the memory bank which does not accord with the preset rule and the first difference value to obtain a second difference value; and taking zero-value data of the first second difference number from the highest address in the original data stored in the memory bank which does not accord with the preset rule as non-zero data for recompression.
The data compression apparatus 100 provided in the embodiment of the present application has the same implementation principle and the same technical effects as those of the foregoing method embodiments, and for brevity, reference may be made to the corresponding contents in the foregoing method embodiments for the parts of the apparatus embodiments that are not mentioned.
As shown in fig. 6, fig. 6 is a block diagram illustrating a structure of an electronic device 200 according to an embodiment of the present disclosure. The electronic apparatus 200 includes: a transceiver 210, a memory 220, a communication bus 230, and a processor 240.
The elements of the transceiver 210, the memory 220, and the processor 240 are electrically connected to each other, directly or indirectly, to enable data transmission or interaction. For example, these components may be electrically connected to each other via one or more communication buses 230 or signal lines. The transceiver 210 is used for transceiving data. The memory 220 is used for storing data to be compressed and storing a computer program, such as the software functional module shown in fig. 5, i.e., the data compression apparatus 100. The data compression apparatus 100 includes at least one software functional module, which may be stored in the memory 220 in the form of software or Firmware (Firmware) or solidified in an Operating System (OS) of the electronic device 200. A processor 240 for executing executable modules stored in the memory 220, such as software functional modules or computer programs included in the data compression apparatus 100. For example, the processor 240 is configured to perform initial compression on original data stored in each of the N memory banks to obtain initial compressed data and corresponding data indexes; the N memory banks store the same group of data to be compressed together, wherein N is a positive integer greater than or equal to 2; selecting a memory bank of which the initial compressed data does not accord with a preset rule from the N memory banks; and recompressing the original data stored in the memory bank which does not accord with the preset rule to obtain new compressed data and a corresponding new data index, wherein the new compressed data accord with the preset rule.
The Memory 220 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and the like.
The processor 240 may be an integrated circuit chip having signal processing capabilities. The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components. The various methods, steps, and logic blocks disclosed in the embodiments of the present application may be implemented or performed. A general purpose processor may be a microprocessor or the processor 240 may be any conventional processor or the like.
The electronic device 200 includes, but is not limited to, an AI arithmetic unit, a computer, a server, and the like.
The present embodiment also provides a non-volatile computer-readable storage medium (hereinafter, referred to as a storage medium), where the storage medium stores a computer program, and the computer program is executed by the computer, such as the electronic device 200, to execute the data compression method described above.
It should be noted that, in the present specification, the embodiments are all described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative and, for example, the flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product stored in a computer-readable storage medium, which includes several instructions for causing a computer device (which may be a personal computer, a notebook computer, a server, or an electronic device) to execute all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned computer-readable storage media comprise: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A method of data compression, comprising:
performing initial compression on original data stored in each of the N memory banks to obtain initial compressed data and corresponding data indexes; the N memory banks store the same group of data to be compressed together, and N is a positive integer greater than or equal to 2;
selecting a memory bank of which the initial compressed data does not accord with a preset rule from the N memory banks;
and recompressing the original data stored in the memory bank which does not accord with the preset rule to obtain new compressed data and a corresponding new data index, wherein the new compressed data accord with the preset rule.
2. The method of claim 1, wherein selecting the memory banks from the N memory banks for which the initial compressed data does not comply with the preset rule comprises:
acquiring the number of lines occupied by the initial compressed data of each memory bank;
and selecting a memory bank with the number of the initially compressed data lines not equal to the specified number of the lines from the N memory banks, wherein the memory bank with the number of the initially compressed data lines not equal to the specified number of the lines is the memory bank which does not accord with the preset rule.
3. The method of claim 2, wherein the maximum number of rows is a maximum number of rows among the number of rows occupied by the initial compressed data of the N banks.
4. The method of claim 1, wherein recompressing the original data stored in the memory banks that do not comply with the predetermined rule comprises:
for each memory bank which does not accord with the preset rule, selecting a target memory bank which has the minimum number of data lines after initial compression from all memory banks which accord with the preset rule and has the number of data lines after initial compression which is larger than the number of data lines after initial compression of the memory bank which does not accord with the preset rule;
and recompressing the original data stored in the memory bank which does not accord with the preset rule by taking the number of rows of the data after the initial compression of the target memory bank as a reference, so that the number of rows of the recompressed data is consistent with the number of rows occupied by the initial compressed data of the target memory bank.
5. The method of claim 4, wherein recompressing the original data stored in the memory bank that does not conform to the preset rule based on the number of data lines after the initial compression of the target memory bank comprises:
acquiring a first quantity of zero-value data in the original data stored in the target memory bank, and acquiring a second quantity of zero-value data in the original data stored in the memory bank which does not accord with the preset rule;
acquiring an absolute value of the difference between the first quantity and the second quantity, and selecting the minimum value of the absolute value and the second numerical value;
and performing recompression on the zero-value data of the minimum number from the lowest address in the original data stored in the memory bank which does not accord with the preset rule as non-zero data.
6. The method of claim 4, wherein recompressing the original data stored in the memory bank that does not conform to the preset rule based on the number of data lines after the initial compression of the target memory bank comprises:
acquiring a first difference value between the quantity of original data stored in the memory bank which does not accord with the preset rule and the quantity of initial compressed data corresponding to the target memory bank;
acquiring a difference value between the number of zero-value data in the original data stored in the memory bank which does not accord with the preset rule and the first difference value to obtain a second difference value;
and performing recompression on zero-valued data of the second difference number from the highest address in the original data stored in the memory bank which do not accord with the preset rule as non-zero data.
7. The method of claim 1, wherein initially compressing the raw data stored in each of the N memory banks comprises:
removing zero-value data stored in each memory bank, and sequentially arranging and combining the rest original data;
and filling up the blank spaces of the lines occupied by the arrangement combination by using the specified numerical data.
8. A data compression apparatus, comprising:
the initial compression module is used for initially compressing the original data stored in each of the N memory banks to obtain initial compressed data and corresponding data indexes; the N memory banks store the same group of data to be compressed together, and N is a positive integer greater than or equal to 2;
the selection module is used for selecting a memory bank of which the initial compressed data does not accord with a preset rule from the N memory banks;
and the recompression module is used for recompressing the original data stored in the memory bank which does not accord with the preset rule to obtain new compressed data and a corresponding new data index, wherein the new compressed data accord with the preset rule.
9. An electronic device, comprising:
the processor is connected with the memory;
the memory is used for storing programs and storing data to be compressed;
the processor to invoke a program stored in the memory to perform the method of any of claims 1-7.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN202210301266.4A 2022-03-24 2022-03-24 Data compression method and device, electronic equipment and computer readable storage medium Pending CN114640354A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210301266.4A CN114640354A (en) 2022-03-24 2022-03-24 Data compression method and device, electronic equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210301266.4A CN114640354A (en) 2022-03-24 2022-03-24 Data compression method and device, electronic equipment and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN114640354A true CN114640354A (en) 2022-06-17

Family

ID=81949431

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210301266.4A Pending CN114640354A (en) 2022-03-24 2022-03-24 Data compression method and device, electronic equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN114640354A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115333544A (en) * 2022-10-13 2022-11-11 上海登临科技有限公司 Data decompression circuit and method, chip and electronic equipment thereof
CN116505952A (en) * 2023-06-27 2023-07-28 厦门立林科技有限公司 Infrared code compression method and device, intelligent equipment and storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115333544A (en) * 2022-10-13 2022-11-11 上海登临科技有限公司 Data decompression circuit and method, chip and electronic equipment thereof
CN115333544B (en) * 2022-10-13 2023-01-31 上海登临科技有限公司 Data decompression circuit and method, chip and electronic equipment thereof
CN116505952A (en) * 2023-06-27 2023-07-28 厦门立林科技有限公司 Infrared code compression method and device, intelligent equipment and storage medium
CN116505952B (en) * 2023-06-27 2023-09-08 厦门立林科技有限公司 Infrared code compression method and device, intelligent equipment and storage medium

Similar Documents

Publication Publication Date Title
CN112292816B (en) Processing core data compression and storage system
US6467062B1 (en) Digital data (multi-bit) storage with discrete analog memory cells
CN114640354A (en) Data compression method and device, electronic equipment and computer readable storage medium
CN106549673B (en) Data compression method and device
CN111985632A (en) Decompression apparatus and control method thereof
CN112506880B (en) Data processing method and related equipment
CN110728350A (en) Quantification for machine learning models
EP3791331A1 (en) Efficient data encoding for deep neural network training
CN114615507A (en) Image coding method, decoding method and related device
JP2011525728A (en) How to process numeric data
US7185041B1 (en) Circuit and method for high-speed execution of modulo division
CN113630125A (en) Data compression method, data encoding method, data decompression method, data encoding device, data decompression device, electronic equipment and storage medium
US7924179B2 (en) Variable-length code determining device and variable-length code decoding method
WO2023159820A1 (en) Image compression method, image decompression method, and apparatuses
CN115862653A (en) Audio denoising method and device, computer equipment and storage medium
KR101577848B1 (en) Method for counting vectors in regular point networks
CN113298892A (en) Image coding method and device, and storage medium
CN111384974B (en) Confidence quantization method, device and decoder for multi-system LDPC code
CN112734021A (en) Neural network acceleration method based on bit sparse calculation
CN113919289A (en) Coding method of bit coin wallet address character string and address numbering table generating method
CN111384975A (en) Optimization method and device of multi-system LDPC decoding algorithm and decoder
CN115333544B (en) Data decompression circuit and method, chip and electronic equipment thereof
KR102420763B1 (en) Neural network system and processing method of filter data of neural network
US20210303975A1 (en) Compression and decompression of weight values
CN114492722A (en) Method and system for generating binary weights for neural networks

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination