Variable-length coding device and method

By designing a variable-length encoding device and using a combination of encoding module, cache module, address calculation module and splicing module, parallel encoding of multiple data is achieved, which solves the problem of low data throughput in the existing technology and improves the performance of the AI ​​system. performance.

CN118611680APending Publication Date: 2024-09-06BEIJING SUIYUAN INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410839299.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

In the existing technology, in variable-length coding, the code length of the previous code symbol needs to be known after encoding each code symbol, which results in low data throughput and limits the parallelism and coding speed of variable-length coding.

Method used

A variable-length coding device is designed, including a coding module, a cache module, an address calculation module and a splicing module. It performs coding, caching, address calculation and splicing through parallel input data to generate coding frames, realize parallel coding of multiple data, and reduce Time overhead.

Benefits of technology

It improves the throughput of data encoding, improves the performance of the AI ​​system, and achieves fast and efficient parallel encoding of multiple data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118611680A
    Figure CN118611680A
Patent Text Reader

Abstract

The embodiment of the invention discloses a variable-length coding device and method. The variable-length coding device comprises a coding module, a first cache module, a second cache module, an address calculation module and a splicing module, the coding module is used for carrying out variable-length coding on a plurality of pieces of parallel input data to be coded to obtain a plurality of code words and a code length corresponding to each code word; the first cache module is used for caching each code word to obtain a plurality of pieces of first cache data; the address calculation module is used for calculating the bit address of each code word and the total code length of all the code words according to the code length corresponding to each code word and the serial number of each code word; the second cache module is used for caching each piece of first cache data according to the bit address of each code word to obtain a plurality of pieces of second cache data; and the splicing module is used for splicing the plurality of pieces of second cache data and intercepting according to the total code length to obtain a coding frame. According to the scheme, parallel coding of multiple pieces of data can be quickly realized, so that the time overhead of data coding is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of data coding technology, and in particular to a variable-length coding device and method. Background Art

[0002] At present, in order to eliminate data redundancy to the maximum extent and improve the utilization rate of system bandwidth, it is necessary to closely splice the encoded variable-length codewords together to form a coding frame for transmission and storage. However, the encoded code length of each input data unit is different. Therefore, when storing the nth code symbol, it is necessary to know the encoded code length of the n-1th code symbol to determine the starting position of the nth code symbol storage. Figure 1 A schematic diagram of a variable length coding storage format provided by the prior art, such as Figure 1 As shown, the serial input data needs to be encoded one by one, the code length is obtained, and the codeword is stored. That is, the encoding of the nth data can only be started after the encoding and storage of the n-1th input data is completed. As a result, the data throughput is relatively low, which limits the parallelism and encoding speed of variable-length coding. Summary of the invention

[0003] The embodiments of the present invention provide a variable-length coding device and method to quickly and efficiently implement parallel coding of multiple data, thereby reducing the time overhead of data coding and improving AI system performance.

[0004] In a first aspect, an embodiment of the present invention provides a variable-length coding device, the variable-length coding device comprising a coding module, a first buffer module, a second buffer module, an address calculation module and a splicing module;

[0005] The encoding module is connected to the first buffer module and the address calculation module respectively; the encoding module is used to perform variable-length encoding on a plurality of to-be-encoded data input in parallel to obtain a plurality of code words and a code length corresponding to each code word; the first buffer module is used to cache each of the code words to obtain a plurality of first buffer data; the address calculation module is used to calculate a bit address of each of the code words and a total code length of all the code words according to the code length corresponding to each of the code words and the sequence number of each of the code words;

[0006] The first cache module and the address calculation module are both connected to the second cache module, and the second cache module is used to cache each of the first cache data according to the bit address of each of the code words to obtain a plurality of second cache data; wherein the starting address of each of the second cache data is the bit address corresponding to each of the code words;

[0007] The second cache module and the address calculation module are both connected to the splicing module, and the splicing module is used to calculate and splice a plurality of the second cache data, and intercept them according to the total code length to obtain a coded frame.

[0008] Optionally, the first cache module includes a plurality of first cache units;

[0009] The size of each of the first cache units is the same as the maximum code length generated by the variable-length encoding;

[0010] Each of the codewords is stored in one of the first buffer units.

[0011] Optionally, the bit address of the codeword whose serial number is N is: the sum of the code lengths corresponding to the codewords whose serial numbers are 1 to N-1; wherein N is a positive integer.

[0012] Optionally, the second cache module includes a plurality of second cache units;

[0013] Each of the first cache data is stored in one of the second cache units, and each of the second cache units has a different size;

[0014] The second cache unit size of the first cache data cache with sequence number N is N times the first cache unit size.

[0015] Optionally, the splicing module includes a calculation unit and a splicing unit;

[0016] The second cache module is connected to the calculation unit, and the calculation unit and the address calculation module are both connected to the splicing unit;

[0017] The calculation unit is used for performing bitwise OR calculation on the plurality of the second cache data to obtain spliced ​​data;

[0018] The splicing unit is used to use the total code length as a frame header, and intercept the effective length data of the spliced ​​data according to the frame header to form a coding frame.

[0019] Optionally, the variable-length encoding device further includes a data encapsulation module;

[0020] The splicing module is connected to the data encapsulation module, and the data encapsulation module is used to receive a plurality of the coded frames and splice the plurality of the coded frames into a data packet to be transmitted.

[0021] Optionally, the data encapsulation module includes a shift unit and a third cache unit;

[0022] The shift unit is connected to the splicing module, and the shift unit is connected to the third buffer unit;

[0023] The shift unit is used to calculate the address of each coded frame according to the frame header of each coded frame, and shift according to the address of each coded frame; the third buffer unit is used to store each shifted coded frame to obtain the data packet.

[0024] In a second aspect, an embodiment of the present invention further provides a variable length coding method, the variable length coding method comprising:

[0025] Perform variable-length coding on multiple to-be-coded data input in parallel to obtain multiple code words and a code length corresponding to each code word;

[0026] Cache each of the codewords to obtain a plurality of first cache data;

[0027] Calculating the bit address of each code word and the total code length of all the code words according to the code length corresponding to each code word and the sequence number of each code word;

[0028] According to the bit address of each codeword, each of the first cache data is cached to obtain a plurality of second cache data; wherein the starting address of each of the second cache data is the bit address corresponding to each of the codewords;

[0029] A plurality of the second cache data are spliced ​​together and intercepted according to the total code length to obtain a coded frame.

[0030] Optionally, the step of splicing a plurality of the second cache data and intercepting them according to the total code length to obtain a coded frame includes:

[0031] Performing bitwise OR calculation on the plurality of the second cache data to obtain spliced ​​data;

[0032] The total code length is used as a frame header, and the effective length of the spliced ​​data is intercepted according to the frame header to form a coding frame.

[0033] The variable-length coding device provided by the embodiment of the present invention simultaneously encodes each parallel input data to be encoded through the coding module, the first cache module simultaneously caches multiple code words, the address calculation module simultaneously calculates the bit address of each code word, the second cache module simultaneously caches each cache data, and the splicing module simultaneously splices all the second cache data, and intercepts according to the total code length, thereby obtaining a coded frame. Therefore, this solution can simultaneously perform parallel compression encoding on a number of data to be encoded, thereby reducing the time overhead of data encoding, thereby improving the data throughput of the encoding, and improving the performance of the AI ​​system. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0035] Figure 1 A schematic diagram of a variable length coding storage format provided by the prior art;

[0036] Figure 2 A schematic diagram of the structure of a variable-length coding device provided by an embodiment of the present invention;

[0037] Figure 3 A schematic diagram of the principle of variable length coding provided by an embodiment of the present invention;

[0038] Figure 4 A schematic diagram of another variable length coding principle provided by an embodiment of the present invention;

[0039] Figure 5 A schematic diagram of the structure of another variable-length coding device provided by an embodiment of the present invention;

[0040] Figure 6 A schematic diagram of the structure of another variable-length coding device provided by an embodiment of the present invention;

[0041] Figure 7 A schematic diagram of the structure of another variable-length coding device provided by an embodiment of the present invention;

[0042] Figure 8 A schematic structural diagram of a barrel shifter provided by an embodiment of the present invention;

[0043] Fig. 9 A schematic diagram of a flow chart of a variable length coding method provided by an embodiment of the present invention;

[0044] Fig.10 A schematic flow chart of steps for obtaining a coded frame provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0045] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0046] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0047] At present, the field of artificial intelligence (AI) is developing rapidly, especially the generation of large models with massive parameters has put forward higher requirements for AI chips in terms of storage, bandwidth, computing power, etc. In order to support high-performance computing (HPC) of large data sets and efficiently complete increasingly complex and large model training and reasoning tasks, the use of appropriate data encoding methods to remove redundant information in massive data before storage and communication, thereby obtaining higher system equivalent bandwidth and larger storage space, and improving performance without losing computing accuracy, has become a widely used and increasingly important technical means in the current AI field.

[0048] Since encoding itself requires a certain amount of time, if the system bandwidth loss caused by the encoding overhead itself is greater than the equivalent bandwidth improvement brought by the transmission after data encoding and compression, the use of the encoding algorithm will actually damage the system performance.

[0049] In this regard, an embodiment of the present invention proposes a variable-length coding device that can simultaneously perform parallel compression encoding on a number of data to be encoded, thereby reducing the time overhead of data encoding, thereby improving the data throughput of the encoding and improving the performance of the AI ​​system. Figure 2 A schematic diagram of the structure of a variable length coding device provided by an embodiment of the present invention is shown in FIG. Figure 2 As shown, the variable-length coding device includes a coding module 110, a first buffer module 120, a second buffer module 130, an address calculation module 140 and a splicing module 150;

[0050] The encoding module 110 is connected to the first buffer module 120 and the address calculation module 140 respectively; the encoding module 110 is used to perform variable-length encoding on a plurality of to-be-encoded data input in parallel to obtain a plurality of code words and a code length corresponding to each code word; the first buffer module 120 is used to cache each code word to obtain a plurality of first buffer data; the address calculation module 140 is used to calculate the bit address of each code word and the total code length of all code words according to the code length corresponding to each code word and the sequence number of each code word;

[0051] The first cache module 120 and the address calculation module 140 are both connected to the second cache module 130, and the second cache module 130 is used to cache each first cache data according to the bit address of each code word to obtain multiple second cache data; wherein the starting address of each second cache data cache is the bit address corresponding to each code word;

[0052] The second buffer module 130 and the address calculation module 140 are both connected to the splicing module 150. The splicing module 150 is used to splice a plurality of second buffer data and intercept them according to the total code length to obtain a coded frame.

[0053] Specifically, the coding module 110 can perform variable-length coding on multiple parallel input data to be coded at the same time, so as to obtain the codeword and the code length of each data to be coded generated after variable-length coding. Wherein, codeword refers to the coded data generated after variable-length coding of the data to be coded, and code length refers to the length (number of bits) of the coded data. Variable-length coding refers to a coding method in which the length of the codeword is different after the data to be coded is coded. Variable-length coding often represents the data with a high probability of appearing in the data to be coded with a short codeword, and the data with a low probability of appearing is represented with a long codeword, so as to obtain a coding with a shorter average code length, thereby compressing the original data to be coded to the greatest extent and removing redundant information. Variable-length coding includes but is not limited to Huffman coding, dictionary coding, LZ4 coding, LZ77 coding, Deflate coding, etc., which can arbitrarily obtain the code length while encoding the codeword. Variable-length coding has better coding efficiency, can compress the original data into shorter valid data, and improve the storage and transmission efficiency of the data to be coded.

[0054] The first cache module 120 can cache the codewords generated after encoding each data to be encoded, and obtain multiple first cache data. The first cache data refers to the codewords stored in the first cache module 120. The space size used by the first cache module 120 to cache each codeword is the same, and the size of each codeword cache space is related to the maximum number of bits that can be generated by the variable-length coding.

[0055] The address calculation module 140 can determine the bit address of each code word according to the code length corresponding to each code word and the sequence number of each code word. Wherein, the bit address refers to the starting storage address of each code word. The sequence number of each code word is determined by the order in which the encoded data is transmitted. For example, if the code length of the first code word is 5, the code length of the second code word is 2, and the code length of the third code word is 8, then the bit address of the first code word is 0, the bit address of the second code word is 5, and the bit address of the third code word is 7.

[0056] The second cache module 130 can allocate storage spaces of different sizes to each first cache data, and cache each codeword to the corresponding allocated storage space. The starting bit of each codeword cached to the corresponding allocated storage space is the bit address corresponding to the codeword, thereby obtaining a plurality of second cache data whose starting addresses are the bit addresses corresponding to each codeword. For example, if the bit address of the third codeword is 7, the starting bit of the third codeword stored in the corresponding allocated storage space is 7, thereby obtaining the second cache data with the starting address of 7.

[0057] The splicing module 150 may splice each second buffer data through calculation to obtain data after all codewords are spliced, that is, a coded frame.

[0058] The working process of the variable length coding device is as follows: the coding module 110 performs variable length coding on multiple parallel input data to be coded to obtain multiple code words and the code length corresponding to each code word. The first cache module 120 caches each coded code word to obtain multiple first cache data; the address calculation module 140 calculates the bit address of each code word in parallel according to the code length corresponding to each code word and the sequence number of each code word; the second cache module 130 caches each first cache data according to the bit address of each code word to obtain multiple second cache data; the splicing module 150 splices multiple second cache data and intercepts them according to the total code length to obtain a coded frame.

[0059] The variable-length coding device provided by the embodiment of the present invention simultaneously encodes each parallel input data to be encoded through the coding module 110, the first cache module 120 caches multiple code words at the same time, the address calculation module 140 calculates the bit address of each code word at the same time, the second cache module 130 caches each cache data at the same time, and the splicing module 150 splices all the second cache data at the same time, and intercepts according to the total code length, thereby obtaining a coded frame. Therefore, this solution can simultaneously perform parallel compression encoding on a number of data to be encoded, thereby reducing the time overhead of data encoding, thereby improving the data throughput of the encoding and improving the performance of the AI ​​system.

[0060] Based on the above embodiment, optionally, Figure 3A schematic diagram of the principle of variable length coding provided by an embodiment of the present invention, such as Figure 3 As shown, the first cache module 120 includes a plurality of first cache units; the size of each first cache unit is the same as the maximum code length generated by the variable-length coding; and each codeword is stored in a first cache unit.

[0061] Exemplarily, if the maximum code length generated by the variable-length coding is M bits, the length of each first cache unit is M bits, the code length of each codeword is between 1 bit and M bits, and when each codeword is stored in a first cache unit, the codeword is stored starting from the least significant bit (LSB) of the first cache unit. Then, each first cache unit may be filled with codewords or some high bits may be empty.

[0062] Figure 3 In the example, the maximum code length generated by the variable-length coding is 8 bits, so the length of each first cache unit is 8 bits. The first data to be encoded has a code length of 4 after encoding, and 4 high bits are empty; the second data to be encoded has a code length of 8 after encoding, and 0 high bits are empty; the third data to be encoded has a code length of 2 after encoding, and 6 high bits are empty; the fourth data to be encoded has a code length of 3 after encoding, and 5 high bits are empty; the fifth data to be encoded has a code length of 8 after encoding, and 0 high bits are empty; ..., the Nth data to be encoded has a code length of 5 after encoding, and 3 high bits are empty.

[0063] On the basis of the above embodiment, optionally, the bit address of the codeword with the codeword serial number N is: the sum of the code lengths corresponding to the codewords with the codeword serial numbers 1 to N-1; wherein N is a positive integer.

[0064] The address calculation module 140 may adopt a reduced calculation to calculate the bit address of each codeword according to the sequence number of the codeword and the code length of each codeword.

[0065]

[0066] Among them, i∈[1,N-1], m i Refers to the code length of the i-th codeword.

[0067] Figure 3 , the code length of the first code word is 4, and the bit address of the first code word is 0; the code length of the second code word is 8, and the bit address of the second code word is 4; the code length of the third code word is 2, and the bit address of the third code word is 12; the code length of the fourth code word is 3, and the bit address of the fourth code word is 14; the code length of the fifth code word is 8, and the bit address of the fifth code word is 17; ..., the code length of the Nth code word is 5, and the bit address of the Nth code word is: the sum of the code lengths corresponding to the code words numbered 1 to N-1.

[0068] In addition, the address calculation module 140 includes a plurality of adders. Figure 4 A schematic diagram of another variable length coding principle provided by an embodiment of the present invention, such as Figure 4 As shown, 8 input data to be encoded adopt log2(8)=3-level addition operation, each level of addition operation includes 8 / 2=4 adders, and outputs the bit addresses corresponding to 8 code words to the second storage module. Among them, the three dotted boxes included in the dotted box of the address calculation module 140 are respectively the first-level adder, the second-level adder and the third-level adder from left to right; the first-level adder (from top to bottom) includes a first adder for calculating the sum of the code lengths of the first code word and the second code word, a second adder for calculating the sum of the code lengths of the third code word and the fourth code word, a third adder for calculating the sum of the code lengths of the fifth code word and the sixth code word, and a fourth adder for calculating the sum of the code lengths of the seventh code word and the eighth code word. The second-level adders (from top to bottom) include a first adder for calculating the sum of the code lengths of the first code word, the second code word, and the third code word, a second adder for calculating the sum of the code lengths of the first code word, the second code word, the third code word, and the fourth code word, a third adder for calculating the sum of the code lengths of the fifth code word, the sixth code word, and the seventh code word, and a fourth adder for calculating the sum of the code lengths of the fifth code word, the sixth code word, the seventh code word, and the eighth code word. The third-level adder (from top to bottom) includes a first adder for calculating the sum of the code lengths of the first code word, the second code word, the third code word, the fourth code word, and the fifth code word, a second adder for calculating the sum of the code lengths of the first code word, the second code word, the third code word, the fourth code word, the fifth code word, and the sixth code word, a third adder for calculating the sum of the code lengths of the first code word, the second code word, the third code word, the fourth code word, the fifth code word, the sixth code word, and the seventh code word, and a fourth adder for calculating the sum of the code lengths of the first code word, the third code word, the fourth code word, the fifth code word, the sixth code word, the seventh code word, and the eighth code word. The reduced calculation can be split into any pipeline according to the addition series, so it will not have a negative impact on the data throughput under any size of parallelism. Wherein, the parallelism can be any natural number greater than or equal to 2, preferably a power of 2.

[0069] Based on the above embodiment, optionally, continue to refer to Figure 3 , the second cache module 130 includes a plurality of second cache units;

[0070] Each first cache data is stored in a second cache unit, and each second cache unit has a different size;

[0071] The size of the second cache unit of the first cache data cache with sequence number N is N times the size of the first cache unit.

[0072] The starting bit of each first cache data stored in the second cache unit is a bit address obtained by protocol calculation, and the other unused bits of the second cache unit are zero.

[0073] like Figure 3 As shown, the size of the first cache unit is 8 bits. The size of the second cache unit of the first first cache data storage is 8 bits, the code length of the first first cache data is 4, and the starting bit of the first cache data stored in the second cache unit is 0; the size of the second cache unit of the second first cache data storage is 16 bits, the code length of the second first cache data is 8, and the starting bit of the second first cache data stored in the second cache unit is 4; the size of the second cache unit of the third first cache data storage is 24 bits, the code length of the third first cache data is 2, and the starting bit of the third first cache data stored in the second cache unit is 12; the second cache unit of the fourth first cache data storage is 16 bits, the code length of the second first cache data is 8, and the starting bit of the second first cache data stored in the second cache unit is 4; The size of the cache unit is 32 bits, the code length of the fourth first cache data is 3, and the starting bit of the fourth first cache data stored in the second cache unit is 14; the size of the second cache unit where the fifth first cache data is stored is 40 bits, the code length of the fifth first cache data is 8, and the starting bit of the fifth first cache data stored in the second cache unit is 17; ..., the size of the second cache unit where the Nth first cache data is stored is 8N bits, the code length of the Nth first cache data is 5, and the starting bit of the Nth first cache data stored in the second cache unit is: the sum of the code lengths corresponding to the code words whose sequence numbers are 1 to N-1.

[0074] Based on the above embodiments, Figure 5 A schematic diagram of the structure of another variable length coding device provided by an embodiment of the present invention is shown in FIG. Figure 5 As shown, the splicing module 150 includes a calculation unit 151 and a splicing unit 152;

[0075] The second cache module 130 is connected to the calculation unit 151, and the calculation unit 151 and the address calculation module 140 are both connected to the splicing unit 152;

[0076] The calculation unit 151 is used for performing bitwise OR calculation on the plurality of second cache data to obtain spliced ​​data;

[0077] The splicing unit 152 is used to use the total code length as a frame header, and to extract effective length data of the spliced ​​data according to the frame header to form a coded frame.

[0078] The address calculation module 140 can obtain the total length of the codewords after encoding all the data to be encoded. The calculation unit 151 can perform a bitwise OR operation on the second cache data of all the second storage units in the second cache module 130 to obtain the data after all the codewords are spliced, which is the final result after the input data to be encoded is encoded in parallel. The splicing unit 152 can use the total length of all the codewords as the frame header, and intercept the effective length of the encoded data according to the total length of all the codewords to form a coding frame.

[0079] Based on the above embodiments, Figure 6 A schematic diagram of the structure of another variable length coding device provided by an embodiment of the present invention is shown in FIG. Figure 6 As shown, the variable-length coding device further includes a data encapsulation module 160;

[0080] The splicing module 150 is connected to the data encapsulation module 160 . The data encapsulation module 160 is used to receive a plurality of coded frames and splice the plurality of coded frames into a data packet to be transmitted.

[0081] The data encapsulation module 160 can receive multiple coding frames, and calculate the address of each coding frame in the data packet according to the frame header information of each coding frame, and then splice the multiple coding frames to obtain a complete data packet for output.

[0082] Specifically, based on the above embodiments, Figure 7 A schematic diagram of the structure of another variable length coding device provided by an embodiment of the present invention is shown in FIG. Figure 7 As shown, the data encapsulation module 160 includes a shift unit 161 and a third cache unit 162;

[0083] The shift unit 161 is connected to the splicing module 150 , and the shift unit 161 is connected to the third buffer unit 162 ;

[0084] The shift unit 161 is used to calculate the address of each coding frame according to the frame header of each coding frame, and to shift according to the address of each coding frame; the third buffer unit 162 is used to store each shifted coding frame to obtain a data packet.

[0085] Among them, the shift unit 161 calculates the address of the coded frame in the data packet according to the total length information of the frame header of each coded frame, and shifts the coded frame to the position to be stored in the third cache unit 162 according to the address of each coded frame, completes the splicing of multiple coded frames in the third cache unit 162, and obtains a complete data packet.

[0086] Specifically, the shift unit 161 includes a barrel shifter (composed of multiple stages of 2-to-1 data selectors). Figure 8 A schematic diagram of the structure of a barrel shifter provided by an embodiment of the present invention is shown in FIG. Figure 4 , Figure 7 as well as Figure 8 As shown, the barrel shifter is composed of multiple stages of two-to-one selectors, d0-d7 is the input data (coded frame), S2-S1 is the address of the input data (the address of the coded frame), and d0'-d7' is the output data (the shifted coded frame). Among them, the shift speed of the input data depends on the number of stages of the barrel shifter group, has nothing to do with the input data, and can be completed through the pipeline without affecting the data throughput.

[0087] Fig. 9 A flow chart of a variable length coding method provided by an embodiment of the present invention, the variable length coding method comprising:

[0088] S110 , performing variable-length coding on a plurality of to-be-coded data input in parallel to obtain a plurality of code words and a code length corresponding to each code word.

[0089] S120 , cache each codeword to obtain a plurality of first cache data.

[0090] S130. Calculate the bit address of each code word and the total code length of all code words according to the code length corresponding to each code word and the sequence number of each code word.

[0091] S140, caching each first cache data according to the bit address of each codeword to obtain a plurality of second cache data; wherein the starting address of each second cache data cache is the bit address corresponding to each codeword;

[0092] S150 , calculating and splicing the plurality of second cache data, and intercepting them according to the total code length to obtain a coded frame.

[0093] The variable-length coding method provided by the embodiment of the present invention simultaneously encodes each data to be encoded that is input in parallel, caches multiple code words, calculates the bit address and total code length of each code word, caches each cached data, splices all second cached data, and intercepts according to the total code length to obtain a coded frame. Therefore, this solution can compress and encode several data to be encoded in parallel at the same time, thereby reducing the time overhead of data encoding, thereby improving the data throughput of the encoding and improving the performance of the AI ​​system.

[0094] Based on the above embodiments, Fig.10 A flowchart of a step of obtaining a coded frame provided by an embodiment of the present invention is shown as follows: Fig.10 As shown, the steps of calculating and splicing a plurality of second cache data and intercepting them according to the total code length to obtain a coded frame are described:

[0095] S210 , performing bitwise OR calculation on the plurality of second cache data to obtain spliced ​​data.

[0096] S220: Using the total code length as a frame header, and extracting the effective length of the spliced ​​data according to the frame header to form a coding frame.

[0097] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0098] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A variable length coding device, characterized in that: It includes an encoding module, a first cache module, a second cache module, an address calculation module and a splicing module; The encoding module is connected to the first cache module and the address calculation module respectively; the encoding module is used to perform variable-length encoding on a plurality of to-be-encoded data input in parallel to obtain a plurality of code words and a code length corresponding to each code word; The first cache module is used to cache each of the codewords to obtain a plurality of first cache data; The address calculation module is used to calculate the bit address of each code word and the total code length of all the code words according to the code length corresponding to each code word and the sequence number of each code word; The first cache module and the address calculation module are both connected to the second cache module, and the second cache module is used to cache each of the first cache data according to the bit address of each of the code words to obtain a plurality of second cache data; wherein the starting address of each of the second cache data is the bit address corresponding to each of the code words; The second cache module and the address calculation module are both connected to the splicing module, and the splicing module is used to splice a plurality of the second cache data and intercept them according to the total code length to obtain a coded frame.

2. The variable length coding device according to claim 1, characterized in that: The first cache module includes a plurality of first cache units; The size of each of the first cache units is the same as the maximum code length generated by the variable-length encoding; Each of the codewords is stored in one of the first buffer units.

3. The variable length coding device according to claim 1, characterized in that: The bit address of the codeword whose serial number is N is: the sum of the code lengths corresponding to the codewords whose serial numbers are 1 to N-1; wherein N is a positive integer.

4. The variable length coding device according to claim 2, characterized in that: The second cache module includes a plurality of second cache units; Each of the first cache data is stored in one of the second cache units, and each of the second cache units has a different size; The second cache unit size of the first cache data cache with sequence number N is N times the first cache unit size.

5. The variable length coding device according to claim 1, characterized in that: The splicing module includes a calculation unit and a splicing unit; The second cache module is connected to the calculation unit, and the calculation unit and the address calculation module are both connected to the splicing unit; The calculation unit is used for performing bitwise OR calculation on the plurality of the second cache data to obtain spliced ​​data; The splicing unit is used to use the total code length as a frame header, and intercept the effective length data of the spliced ​​data according to the frame header to form a coding frame.

6. The variable length coding device according to claim 1, characterized in that: Also includes a data encapsulation module; The splicing module is connected to the data encapsulation module, and the data encapsulation module is used to receive a plurality of the coded frames and splice the plurality of the coded frames into a data packet to be transmitted.

7. The variable length coding device according to claim 6, characterized in that: The data encapsulation module includes a shift unit and a third cache unit; The shift unit is connected to the splicing module, and the shift unit is connected to the third buffer unit; The shift unit is used to calculate the address of each coded frame according to the frame header of each coded frame, and shift according to the address of each coded frame; the third buffer unit is used to store each shifted coded frame to obtain the data packet.

8. A variable length coding method, characterized in that: include: Perform variable-length coding on multiple to-be-coded data input in parallel to obtain multiple code words and a code length corresponding to each code word; Cache each of the codewords to obtain a plurality of first cache data; Calculating the bit address of each code word and the total code length of all the code words according to the code length corresponding to each code word and the sequence number of each code word; According to the bit address of each codeword, each of the first cache data is cached to obtain a plurality of second cache data; wherein the starting address of each of the second cache data is the bit address corresponding to each of the codewords; A plurality of the second cache data are spliced ​​together and intercepted according to the total code length to obtain a coded frame.

9. The variable length coding method according to claim 8, characterized in that: The step of splicing the plurality of second cache data and intercepting them according to the total code length to obtain a coded frame includes: Performing bitwise OR calculation on the plurality of the second cache data to obtain spliced ​​data; The total code length is used as a frame header, and the effective length of the spliced ​​data is intercepted according to the frame header to form a coding frame.