TW202215275A - Convolution calculation apparatus and method - Google Patents
Convolution calculation apparatus and method Download PDFInfo
- Publication number
- TW202215275A TW202215275A TW109134986A TW109134986A TW202215275A TW 202215275 A TW202215275 A TW 202215275A TW 109134986 A TW109134986 A TW 109134986A TW 109134986 A TW109134986 A TW 109134986A TW 202215275 A TW202215275 A TW 202215275A
- Authority
- TW
- Taiwan
- Prior art keywords
- data
- convolution
- weight data
- compressed
- computing device
- Prior art date
Links
- 238000004364 calculation method Methods 0.000 title claims abstract description 46
- 238000000034 method Methods 0.000 title description 7
- 230000006837 decompression Effects 0.000 claims abstract description 30
- 238000007906 compression Methods 0.000 claims description 24
- 230000006835 compression Effects 0.000 claims description 23
- 238000006243 chemical reaction Methods 0.000 claims description 18
- 230000005540 biological transmission Effects 0.000 abstract description 3
- 230000003247 decreasing effect Effects 0.000 abstract 1
- 238000005303 weighing Methods 0.000 abstract 1
- 238000010586 diagram Methods 0.000 description 17
- 230000000295 complement effect Effects 0.000 description 13
- 238000003672 processing method Methods 0.000 description 12
- 238000013507 mapping Methods 0.000 description 5
- 238000013527 convolutional neural network Methods 0.000 description 4
- 238000013473 artificial intelligence Methods 0.000 description 2
- 238000005094 computer simulation Methods 0.000 description 2
- 238000013144 data compression Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 230000000873 masking effect Effects 0.000 description 1
- 238000003062 neural network model Methods 0.000 description 1
- 230000008521 reorganization Effects 0.000 description 1
Images
Landscapes
- Compression, Expansion, Code Conversion, And Decoders (AREA)
Abstract
Description
本發明是關於捲積計算技術,尤其是關於一種卷積計算裝置及方法。The present invention relates to convolution computing technology, in particular to a convolution computing device and method.
目前,越來越多的領域開始應用人工智慧技術。在人工智慧技術中,電子設備可以利用訓練樣本對計算模型(即神經網路模型)進行機器學習。之後,電子設備可以利用訓練好的計算模型來執行一些任務,如分類和預測等。比如,卷積神經網路(Convolutional Neural Networks;CNN)可以用於影像識別等。然而,有些卷積層中卷積核的資料龐大,導致在電子設備上進行卷積層的卷積處理時需要佔用較多的系統資源。At present, more and more fields have begun to apply artificial intelligence technology. In artificial intelligence technology, electronic devices can use training samples to perform machine learning on computational models (ie, neural network models). Afterwards, electronic devices can utilize the trained computational model to perform tasks such as classification and prediction. For example, Convolutional Neural Networks (CNN) can be used for image recognition and so on. However, the data of the convolution kernels in some convolution layers is huge, which leads to the need to occupy more system resources when performing convolution processing of the convolution layers on electronic devices.
鑑於先前技術的問題,本發明之一目的在於提供一種卷積計算裝置及方法,以改善先前技術。In view of the problems of the prior art, one object of the present invention is to provide a convolution computing device and method to improve the prior art.
本發明包含一種卷積計算裝置,應用於卷積層的卷積計算,包含:解壓縮電路、資料組合電路以及計算電路。解壓縮電路用以對卷積層的卷積核的壓縮權重資料進行解壓縮,以產生解壓後權重資料。資料組合電路用以組合解壓後資料與卷積核的未壓縮權重資料,以還原卷積核的權重資料的資料順序。計算電路根據該卷積核的權重資料及該卷積層的輸入資料進行計算。The present invention includes a convolution calculation device, which is applied to the convolution calculation of the convolution layer, and includes a decompression circuit, a data combination circuit and a calculation circuit. The decompression circuit is used for decompressing the compressed weight data of the convolution kernel of the convolution layer to generate the decompressed weight data. The data combining circuit is used for combining the decompressed data and the uncompressed weight data of the convolution kernel to restore the data order of the weight data of the convolution kernel. The calculation circuit performs calculation according to the weight data of the convolution kernel and the input data of the convolution layer.
本發明另包含一種卷積計算裝置,應用於卷積層的卷積計算,包含:解壓縮電路以及計算電路。解壓縮電路用以對卷積層的卷積核的壓縮權重資料進行解壓縮,以產生解壓後權重資料。計算電路根據解壓後權重資料及卷積層的輸入資料進行計算。其中,壓縮權重資料及輸入資料分別儲存於記憶體的不同區塊中。The present invention further includes a convolution calculation device, which is applied to the convolution calculation of the convolution layer, comprising: a decompression circuit and a calculation circuit. The decompression circuit is used for decompressing the compressed weight data of the convolution kernel of the convolution layer to generate the decompressed weight data. The calculation circuit performs calculation according to the decompressed weight data and the input data of the convolution layer. Wherein, the compression weight data and the input data are stored in different blocks of the memory respectively.
本發明更包含一種卷積計算方法,應用於卷積層的卷積計算,包含:對卷積層的卷積核的壓縮權重資料進行解壓縮,以產生解壓後權重資料;以及根據解壓後權重資料及卷積層的輸入資料進行計算;其中,壓縮權重資料及輸入資料分別儲存於記憶體的不同區塊中。The present invention further includes a convolution calculation method applied to the convolution calculation of the convolution layer, including: decompressing the compressed weight data of the convolution kernel of the convolution layer to generate the decompressed weight data; and according to the decompressed weight data and The input data of the convolution layer is calculated; wherein, the compressed weight data and the input data are respectively stored in different blocks of the memory.
有關本案的特徵、實作與功效,茲配合圖式作較佳實施例詳細說明如下。Regarding the features, implementation and effects of this case, a preferred embodiment is described in detail as follows in conjunction with the drawings.
請參照圖示,其中相同的元件符號代表相同的元件,本發明的原理是以實施在一適當的運算環境中來舉例說明。以下的說明是基於所範例性示出的本發明具體實施例,其不應被視為限制本發明未在此詳述的其它具體實施例。Please refer to the drawings, in which the same reference numerals represent the same elements, and the principles of the present invention are exemplified by being implemented in a suitable computing environment. The following description is based on specific embodiments of the present invention shown by way of example, and should not be construed as limiting other specific embodiments of the present invention not detailed herein.
本發明提出可應用於卷積計算裝置的資料處理方法及對應的卷積計算裝置,其藉由預先將卷積層中卷積核的權重資料進行壓縮,再將壓縮後權重資料輸入至對應的卷積計算裝置中。當卷積計算裝置進行運算時,再對壓縮後權重資料進行解壓縮,藉此可降低卷積核權重資料所佔用的系統資源。實施上,本發明提出的卷積計算裝置可應用於諸如智慧型手機、平板電腦、安控裝置等電子設備上。The present invention proposes a data processing method applicable to a convolution computing device and a corresponding convolution computing device, which compress the weight data of the convolution kernel in the convolution layer in advance, and then input the compressed weight data to the corresponding volume in the product calculation device. When the convolution computing device performs operations, the compressed weight data is decompressed, thereby reducing the system resources occupied by the convolution kernel weight data. In implementation, the convolution computing device proposed by the present invention can be applied to electronic devices such as smart phones, tablet computers, security control devices and the like.
請參照圖1。圖1顯示本發明一實施例中,一種資料處理方法的流程示意圖,詳細說明如下。Please refer to Figure 1. FIG. 1 shows a schematic flowchart of a data processing method according to an embodiment of the present invention, and the detailed description is as follows.
步驟101中,獲取一訓練好的計算模型的一卷積層對應的一卷積核的權重資料,上述計算模型可以為卷積神經網路。In
步驟102中,對卷積核的權重資料進行壓縮,得到壓縮後的權重資料。一實施例中,步驟101及步驟102是由一處理器執行特定程序代碼所實現,而此處理器並不在卷積計算裝置中,也就是說,步驟101及步驟102是由卷積計算裝置外部的處理器預先對卷積核的權重資料進行壓縮處理。實施上,用以壓縮卷積核的權重資料的壓縮格式可為霍夫曼(Huffman)壓縮格式。In
步驟103中,將壓縮後的權重資料傳輸到具有卷積計算裝置的電子設備上,例如,將壓縮後的權重資料傳輸到電子設備的記憶體。In
在一實施例中,將預先壓縮好的權重資料傳輸到需使用此權重資料的電子設備上,實施上,壓縮後的權重資料是儲存於電子設備中一記憶體的一第一區塊中,而與此權重資料對應的卷積層的輸入資料是儲存於此記憶體的一第二區塊中。In one embodiment, the pre-compressed weight data is transmitted to an electronic device that needs to use the weight data. In practice, the compressed weight data is stored in a first block of a memory in the electronic device, The input data of the convolution layer corresponding to the weight data is stored in a second block of the memory.
步驟104中,對壓縮後的權重資料進行解壓縮。實施上,可由卷積計算裝置中的解壓縮電路對壓縮後的權重資料進行解壓縮處理。In
請參照圖2。圖2顯示本發明一實施例中,一種卷積計算裝置的方塊示意圖。卷積計算裝置20設置於一電子設備中,此電子設備的記憶體201中儲存有一壓縮後的權重資料,其對應一卷積層的卷積核,記憶體201中亦可儲存此卷積層的輸入資料。當卷積計算裝置20進行卷積運算時,解壓縮電路202自記憶體201讀取壓縮後的權重資料,並對壓縮後的權重資料進行解壓縮。若壓縮權重資料的壓縮格式為霍夫曼壓縮格式時,解壓縮電路202可根據一霍夫曼碼表對壓縮後的權重資料進行解壓縮。Please refer to Figure 2. FIG. 2 shows a block diagram of a convolution computing device according to an embodiment of the present invention. The
步驟105中,根據解壓縮後的權重資料進行卷積計算。當卷積計算裝置20進行卷積運算時,計算電路203根據解壓縮後的權重資料及對應的卷積層的輸入資料進行卷積計算。In
由上可知,由於是將預先經過壓縮的卷積核的權重資料傳輸給電子設備,當進行卷積運算時,先對壓縮後的權重資料進行解壓縮後,電子設備上的卷積計算裝置再據以進行卷積運算,因此,可降低卷積核在電子設備中所佔用的儲存空間及傳輸時所需的頻寬,進而在進行卷積處理時節省系統資源。As can be seen from the above, since the weight data of the pre-compressed convolution kernel is transmitted to the electronic device, when the convolution operation is performed, the compressed weight data is first decompressed, and then the convolution calculation device on the electronic device is used. According to the convolution operation, the storage space occupied by the convolution kernel in the electronic device and the bandwidth required for transmission can be reduced, thereby saving system resources during the convolution processing.
請參照圖3,圖3顯示本發明一實施例中,資料處理方法的另一流程示意圖,詳細說明如下。Please refer to FIG. 3 . FIG. 3 shows another schematic flowchart of a data processing method according to an embodiment of the present invention, and the detailed description is as follows.
步驟301中,獲取一卷積神經網路的一卷積層對應的一卷積核的權重資料。In
請參照圖4。圖4顯示本發明一實施例中,卷積核的權重資料示意圖。如圖4所示,一卷積層的卷積核的權重資料為5列12行的一個二維數組,即該卷積核共包含60個權重。在其它實施方式中,卷積核可以是具有其它行數和列數的二維數組,或者卷積核可以是三維或者四維等的數組。Please refer to Figure 4. FIG. 4 shows a schematic diagram of weight data of a convolution kernel in an embodiment of the present invention. As shown in Figure 4, the weight data of the convolution kernel of a convolution layer is a two-dimensional array with 5 columns and 12 rows, that is, the convolution kernel contains 60 weights in total. In other embodiments, the convolution kernel may be a two-dimensional array with other numbers of rows and columns, or the convolution kernel may be a three-dimensional or four-dimensional array, or the like.
步驟302中,對卷積核的權重資料進行格式轉換。為進一步降低資料量,可對卷積核的權重資料進行格式轉換,例如將卷積核的各權重由補數轉換為原數。In
請參照圖5。圖5顯示本發明一實施例中,將權重資料由補數轉換為原數的示意圖。以卷積核的第1列第5行的權重為例,該權重的補數為FB(其真值為-5)。電子設備可以將該權重由補數FB轉換為原數85。需要說明的是,補數FB對應的二進位表示為11111011,其中高4位元的1111代表F(16進位),低4位元的1011代表B(16進位)。補數11111011轉換為原數是10000101。原數10000101中的高4位元1000對應的16進位數為8,低4位元0101對應的16進位數為5。因此,FB由補數轉換為原數是85。需要說明的是,正數的補數和原數相同。Please refer to Figure 5. FIG. 5 shows a schematic diagram of converting weight data from complement to original in an embodiment of the present invention. Take the weight in
另外,一般在電腦設備中卷積核的權重資料並不是以16進位的形式儲存的,而是以具有多個位元的二進位的形式儲存的。例如,圖4中卷積核的第1列第5行的權重FB在電腦設備中並不是以FB的形式儲存的,而是以具有很多位元的二進位數的形式儲存的。In addition, in general, the weight data of the convolution kernel in computer equipment is not stored in the form of hexadecimal, but is stored in the form of binary with multiple bits. For example, the weight FB in the first column and fifth row of the convolution kernel in Fig. 4 is not stored in the form of FB in the computer device, but is stored in the form of binary digits with many bits.
步驟303中,按照預設規則確定卷積核的各權重資料對應的8位元二進位數字。在對卷積核的權重資料進行格式轉換之後,可再按照一預設規則確定卷積核的各權重所對應的8位元二進位數字。在一實施方式中,預設規則可以是將卷積核的各權重所包含的兩個位元的數字分別轉換為對應的4位元二進位數字,並將得到的兩個4位元二進位數字按照位元的順序拼接成8位元二進位數字。In
例如,卷積核的第1列第5行的權重為85,其中85中的「8」對應的二進位數字為1000,「5」對應的二進位數字0101,因此權重85對應的二進位數字可以由1000和0101拼接而成,即10000101。又例如,卷積核的第3列第4行的權重為81,其中81中的「8」對應的二進位數字為1000,「1」對應的二進位數字0001,因此權重81對應的二進位數字可以由1000和0001拼接而成,即10000001。For example, the weight of the 1st column and 5th row of the convolution kernel is 85, the binary number corresponding to "8" in 85 is 1000, and the binary number corresponding to "5" is 0101, so the binary number corresponding to the
步驟304中,從卷積核的各權重對應的8位元二進位數字中提取第一部分資料和第二部分資料,該第一部分資料為8位元二進位數字中除最高位元的數字和最低的三個位元的數字外的其它數字,該第二部分資料包含8位元二進位數字中的最高位元的數字和最低的三個位元的數字。In
例如,權重85對應的8位元二進位數字為10000101,則第一部分資料為0000(即從低到高的順序中的第7位元、第6位元、第5位元和第4位元),第二部分資料1101(即從低到高的順序中的第8位元、第3位元、第2位元和第1位元)。又例如,權重81對應的8位元二進位數字為10000001,則第一部分資料為0000(即從低到高的順序中的第7位元、第6位元、第5位元和第4位元),第二部分資料為1001(即從低到高的順序中的第8位元、第3位元、第2位元和第1位元)。For example, the 8-bit binary number corresponding to the
步驟305中,對各權重對應的第一部分資料進行壓縮。在得到卷積核的各權重對應的第一部分資料和第二部分資料後,可對各權重對應的第一部分資料進行無失真壓縮,壓縮後的第一部分資料與未壓縮的第二部分資料可分開儲存,也是說,經壓縮的第一部分資料是集中儲存在一起,而未經壓縮的第二部分資料是集中儲存在一起。In
一實施例中,在對各權重對應的第一部分資料進行的壓縮可以是霍夫曼壓縮。霍夫曼壓縮是一種無失真壓縮方式,它可以用較少的位元表示出現頻率較高的字元,用較多的位元表示出現頻率較低的字元,進而達到資料壓縮的目的。In an embodiment, the compression performed on the first part of the data corresponding to each weight may be Huffman compression. Huffman compression is a distortionless compression method, which can use fewer bits to represent characters with higher frequency, and use more bits to represent characters with lower frequency, so as to achieve the purpose of data compression.
例如,所有權重的第一部分資料中「0000」出現的頻率最高,在霍夫曼編碼中「0000」用字元「1」表示,這樣卷積核的資料就可以實現壓縮目的了。For example, "0000" appears most frequently in the first part of the data of all weights, and "0000" is represented by the character "1" in Huffman coding, so that the data of the convolution kernel can be compressed.
步驟302中之所以要將卷積核中的權重由補數轉換為原數,並從卷積核中提取第一部分資料,且對第一部分資料進行壓縮,是因為正數和負數的原數的第一部分資料相同,因此可以提高卷積核對應的資料的壓縮率。In
步驟306中,將壓縮後的權重資料及未壓縮的權重資料傳輸至一需使用這些資料的電子設備。此電子設備具有一卷積計算裝置,請參照圖6。圖6顯示本發明另一實施例中,卷積計算裝置的方塊示意圖。卷積計算裝置60可利用儲存在電子設備中的壓縮後的權重資料及未壓縮的權重資料進行卷積計算。這裡的壓縮後的權重資料即前述的壓縮後的第一部分資料,而未壓縮的權重資料即前述的第二部分資料。實施上,壓縮後的權重資料及未壓縮的權重資料儲存於電子設備中一記憶體不同的區塊中,而步驟301至步驟306是由一處理器執行特定程序代碼所實現,而此處理器並不在包含卷積計算裝置60的電子設備中。In
步驟307中,對壓縮後的權重資料進行解壓縮。當卷積計算裝置進行卷積計算時,解壓縮電路自記憶體601讀取壓縮後的權重資料,並進行解壓縮處理。若壓縮權重資料的壓縮格式為霍夫曼壓縮格式時,解壓縮電路602可根據一霍夫曼碼表對壓縮後的權重資料進行解壓縮,霍夫曼碼表可儲存於一寄存器中。解壓縮電路602可將解壓後所得到的各權重對應的第一部分資料存回記憶體601中或直接輸出到資料組合電路604。In
步驟308中,組合解壓後權重資料與未壓縮權重資料,以還原卷積核的權重資料的資料順序。一實施例中,解壓後所得到的各權重對應的第一部分資料儲存於記憶體601中,資料組合電路604交錯地自記憶體601中讀取第一部分資料及第二部分資料(即未壓縮的權重資料),並重排序兩者的各權重中資料的順序,以還原權重資料原始的順序。實施上,資料組合電路604依據步驟304中取出第一部分資料及第二部分資料的規則,進行反向處理,以還原權重資料原始的順序。In
步驟309中,對已還原順序的權重資料進行格式轉換,以還原權重資料原始格式。轉換電路605依據步驟302中所進行格式轉換對順序還原好的權重資料進行格式還原處理。舉例來說,若步驟302中是將卷積核中的權重資料由補數轉換為原數,轉換電路605則會將已還原順序的權重資料中的原數轉換為補數,以將權重資料還原成原始的格式。若權重資料在壓縮前有進行其它的格式轉換,轉換電路605亦會進行反向的格式轉換,以將權重資料還原成原始的格式。實施上,轉換電路605亦可在第一部分資料與第二部分資料重組前就對解壓縮後的權重資料進行反向格式轉換。In
步驟310中,計算電路603根據已還原的權重資料及對應卷積層的輸入資料進行卷積計算。In
在一實施例中,對卷積核的權重資料進行壓縮前,可先判斷卷積核的權重資料的資料量是否大於一預設閾值,若是,則對卷積核對應的權重資料進行分塊,得到至少兩個資料區塊,再分別對這兩個資料區塊進行壓縮。需要說明的是,由於卷積計算裝置的儲存空間較小,因此當卷積核的資料量較大時,可以先對卷積核對應的資料進行分塊,再對每一區塊進行壓縮,卷積計算裝置則可以在對各資料區塊對應的壓縮資料進行解壓縮後再拼接還原成一個完整的卷積核。本實施例中,如果需要對卷積核對應的資料進行分塊,電子設備可對分塊後得到的所有資料區塊進行統一的霍夫曼壓縮編碼,即同一個卷積層的卷積核只會對應於一個霍夫曼碼表。In one embodiment, before compressing the weight data of the convolution kernel, it can be determined whether the data amount of the weight data of the convolution kernel is greater than a preset threshold, and if so, the weight data corresponding to the convolution kernel is divided into blocks. , obtain at least two data blocks, and then compress the two data blocks respectively. It should be noted that since the storage space of the convolution computing device is small, when the amount of data in the convolution kernel is large, the data corresponding to the convolution kernel can be divided into blocks first, and then each block can be compressed. The convolution computing device can decompress the compressed data corresponding to each data block, and then splicing and restoring it into a complete convolution kernel. In this embodiment, if the data corresponding to the convolution kernel needs to be divided into blocks, the electronic device can perform unified Huffman compression coding on all the data blocks obtained after the division, that is, the convolution kernel of the same convolution layer only has would correspond to a Huffman code table.
在一實施例中,對各權重對應的第一部分資料所進行的壓縮處理可包含兩階段,第一階段為先將各權重對應的第一部分資料轉換為16進位的壓縮字元。第二階段為獲取卷積核的所有權重對應的壓縮字元,並對所有壓縮字元進行編碼壓縮,得到壓縮資料和解壓縮映射關係表,所述解壓縮映射關係表中記載有各壓縮字元及其對應的壓縮編碼。實施上,亦可將各權重對應的第二部分數字轉換為16進位的目標字元。而卷積計算裝置則會進行對應的反向處理,以還原原始的權重資料。In an embodiment, the compression process performed on the first part of the data corresponding to each weight may include two stages. The first stage is to convert the first part of the data corresponding to each weight into hexadecimal compressed characters. The second stage is to obtain the compressed characters corresponding to all the weights of the convolution kernel, and to encode and compress all the compressed characters to obtain the compressed data and the decompression mapping relationship table, in which each compressed character is recorded in the decompression mapping relationship table. and its corresponding compression code. In implementation, the second part of the numbers corresponding to each weight can also be converted into hexadecimal target characters. The convolution computing device will perform corresponding reverse processing to restore the original weight data.
在一具體實施例中,經補數轉原數的轉換後,可將各權重對應的第一部分資料轉換為16進位的壓縮字元。例如,權重85對應的第一部分資料為0000,該第一部分資料0000對應的16進位的字元為0,該0即是權重85對應的第一部分資料轉換而來的壓縮字元。又例如,權重81對應的第一部分資料為0000,該第一部分資料0000對應的16進位的字元為0,該0即是權重81對應的第一部分資料轉換而來的壓縮字元。In a specific embodiment, after the conversion from the complement to the original number, the first part of the data corresponding to each weight can be converted into hexadecimal compressed characters. For example, the first part of the data corresponding to the
在獲取到卷積核中的所有權重對應的壓縮字元後,可對所有壓縮字元進行霍夫曼(Huffman)編碼壓縮,進而得到壓縮資料和解壓縮間的映射關係表,該解壓縮映射關係表中記載有各壓縮字元及其對應的霍夫曼編碼。該解壓縮映射關係表即為用於解壓縮的霍夫曼碼表。After obtaining the compressed characters corresponding to all the weights in the convolution kernel, all compressed characters can be compressed by Huffman coding, and then the mapping relationship table between compressed data and decompression can be obtained. The decompression mapping relationship Each compressed character and its corresponding Huffman code are recorded in the table. The decompression mapping table is the Huffman code table used for decompression.
例如,卷積核的所有權重對應的壓縮字元按照各權重在卷積核中的行列位置進行排列得到的二維數組如圖7所示。For example, a two-dimensional array obtained by arranging the compressed characters corresponding to all weights of the convolution kernel according to the row and column positions of the weights in the convolution kernel is shown in FIG. 7 .
圖7顯示本發明一實施例中,權重資料對應的壓縮字元的示意圖。即,圖7中的二維數組的第1列第1行的字元為第二卷積核中的第1列第1行的權重對應的壓縮字元。二維數組的第1列第2行的字元為第二卷積核中的第1列第2行的權重對應的壓縮字元,等等,依此類推。FIG. 7 shows a schematic diagram of compressed characters corresponding to weight data according to an embodiment of the present invention. That is, the characters in the first column and the first row of the two-dimensional array in FIG. 7 are the compressed characters corresponding to the weights in the first column and the first row in the second convolution kernel. The characters in the first column and the second row of the two-dimensional array are the compressed characters corresponding to the weights of the first column and the second row in the second convolution kernel, and so on, and so on.
在獲取到所有的壓縮字元後,即可對這些壓縮字元進行霍夫曼編碼壓縮,進而得到壓縮資料以及對應的用於解壓縮的霍夫曼碼表。例如,由於所有的壓縮字元中「0」出現了54次,「1」出現了5次,「3」出現了1次。因此,通過建構霍夫曼樹(Huffman Tree)可得,「0」對應的霍夫曼編碼可以為「1」,「1」對應的霍夫曼編碼可以為「01」,「3」對應的霍夫曼編碼可以為「00」。After all the compressed characters are obtained, Huffman coding and compression can be performed on these compressed characters, thereby obtaining compressed data and a corresponding Huffman code table for decompression. For example, since "0" appears 54 times in all compressed characters, "1" appears 5 times, and "3" appears 1 time. Therefore, by constructing a Huffman Tree, it can be obtained that the Huffman code corresponding to "0" can be "1", the Huffman code corresponding to "1" can be "01", and the Huffman code corresponding to "3" Huffman coding can be "00".
圖8至圖9顯示本發明之一實施例中,資料處理方法的場景示意圖。霍夫曼樹可以如圖8所示,霍夫曼碼表可以如圖9所示。8 to 9 are schematic diagrams of scenarios of a data processing method according to an embodiment of the present invention. The Huffman tree can be as shown in FIG. 8 , and the Huffman code table can be as shown in FIG. 9 .
此外,還可將卷積核的各權重對應的第二部分資料轉換為16進位的目標字元。這樣的話,當卷積計算裝置需要對壓縮後的卷積核進行解壓縮時,卷積計算裝置可將該壓縮資料解壓為各權重對應的壓縮字元,並將各權重對應的壓縮字元還原為各權重對應的第一部分資料。同時,卷積計算裝置可以將各權重對應的目標字元還原為各權重對應的第二部分資料。之後,卷積計算裝置再進行第一部分資料和第二部分資料重組及格式轉換等處理,以還原原始的權重資料。In addition, the second part of the data corresponding to each weight of the convolution kernel can also be converted into a hexadecimal target character. In this way, when the convolution computing device needs to decompress the compressed convolution kernel, the convolution computing device can decompress the compressed data into compressed characters corresponding to each weight, and restore the compressed characters corresponding to each weight. It is the first part of the data corresponding to each weight. At the same time, the convolution computing device can restore the target character corresponding to each weight to the second part of data corresponding to each weight. Afterwards, the convolution computing device performs reorganization and format conversion of the first part of the data and the second part of the data to restore the original weight data.
可以理解的是,上述將第一部分資料和第二部分資料均轉換為16進位的字元的方式可以進一步提高壓縮率進而進一步降低在傳輸壓縮後的卷積核時的頻寬。It can be understood that the above method of converting both the first part of the data and the second part of the data into hexadecimal characters can further improve the compression rate and further reduce the bandwidth when transmitting the compressed convolution kernel.
在一實施例中,為了進一步降低傳輸頻寬,可以通過如下方式對經過霍夫曼壓縮後的資料再進行壓縮。例如,卷積核的各權重的第一部分資料轉換成的壓縮字元在經過霍夫曼壓縮編碼後的數組可以如圖10所示。其中,圖10顯示本發明之一實施例中,資料處理方法的場景示意圖。比如,本實施例將壓縮後的霍夫曼資料分成兩個資料區塊,即第1行至第6行為第一資料區塊,第7行至第12行為第二資料區塊,其中,第一資料區塊和第二資料區塊均各自佔據15個位元組(Byte)。對於第一資料區塊,本實施例可以按照從左至右、從上到下的順序每4個字元截取作為一個部分、不足4個字元則進行末尾補零的方式將第一資料區塊(共33個字元)轉換為10個部分,再將每個部分的字元轉換為16進位的字元,這樣第一資料區塊就被轉換為如下字元:FBFFEEFF80,如圖11所示。圖11顯示本發明之一實施例中,資料處理方法的場景示意圖。可以理解的是,在電子設備中FBFFEEFF80一共佔據5個位元組(Byte)。同理,對於第二資料區塊,本實施例可以按照從左至右、從上到下的順序每4個字元截取作為一個部分、不足4個字元則進行末尾補零的方式將第一資料區塊(共33個字元)轉換為10個部分,再將每個部分的字元轉換為16進位的字元,這樣第一資料區塊就被轉換為如下字元:7FFFE7FE80,如圖12所示。圖12顯示本發明之一實施例中,資料處理方法的場景示意圖。可以理解的是,在電子設備中7FFFE7FE80一共佔據5個位元組(Byte)。藉由上述方式,卷積核的第一部分數字對應的壓縮資料由原來的30個位元組進一步壓縮為10個位元組,壓縮率得以提高。In an embodiment, in order to further reduce the transmission bandwidth, the data after Huffman compression can be re-compressed in the following manner. For example, the array of compressed characters converted from the first part of the data of each weight of the convolution kernel after Huffman compression encoding can be as shown in FIG. 10 . 10 shows a schematic diagram of a scene of a data processing method in an embodiment of the present invention. For example, in this embodiment, the compressed Huffman data is divided into two data blocks, that is, the first data block from the first row to the sixth row is the first data block, and the seventh row to the 12th row is the second data block. Each of the first data block and the second data block occupies 15 bytes. For the first data block, in this embodiment, every 4 characters can be intercepted as a part in the order from left to right and top to bottom, and the first data block can be filled with zeros at the end if it is less than 4 characters. The block (33 characters in total) is converted into 10 parts, and then the characters of each part are converted into hexadecimal characters, so that the first data block is converted into the following characters: FBFFEEFF80, as shown in Figure 11 Show. FIG. 11 shows a schematic diagram of a scene of a data processing method according to an embodiment of the present invention. It can be understood that FBFFEEFF80 occupies a total of 5 Bytes in the electronic device. Similarly, for the second data block, in this embodiment, every 4 characters can be intercepted as a part in the order from left to right and from top to bottom, and the end is filled with zeros when less than 4 characters. A data block (33 characters in total) is converted into 10 parts, and then the characters of each part are converted into hexadecimal characters, so that the first data block is converted into the following characters: 7FFFE7FE80, such as Figure 12. FIG. 12 shows a schematic diagram of a scene of a data processing method according to an embodiment of the present invention. It can be understood that in electronic equipment, 7FFFE7FE80 occupies a total of 5 bytes (Byte). By the above method, the compressed data corresponding to the first part of the convolution kernel is further compressed from the original 30 bytes to 10 bytes, and the compression rate is improved.
在一實施例中,如果對第一部分資料進行4位元的霍夫曼編碼壓縮,則霍夫曼編碼的最大長度為15位元(即2 4-1)。如果卷積計算裝置只有32位元作為碼表單元,其中的4位元要用於計數,14位元要用於做遮罩,那麼還有14位元可以用於做碼值。也就是說最大只有14位元表示碼值。如果遇到15位元碼值的,此時需要對霍夫曼樹進行修正,進而使修正後的霍夫曼樹的最大位元為14位,例如以通過如下方式來修正霍夫曼樹,對所有的字元中出現頻率最低的4個字元的頻率進行改變,進而使霍夫曼樹的層數減少1層,這樣的話最長的15位元的霍夫曼編碼就會降低為14位元。例如,原來的出現頻率最低的4個字元的出現頻率依此為1、2、4、8,那麼這4個字元對應的霍夫曼樹的形狀可以如圖13所示。本發明可以將這4個字元的的頻率值依此修改為3、4、4、4,這樣的話這4個字元對應的霍夫曼樹的形狀就變為如圖14所示。其中,圖13至圖14顯示本發明之一實施例中,資料處理方法的場景示意圖。通過對比圖13和圖14可知,霍夫曼樹的層數減少了一層,這樣最長的霍夫曼編碼就由15位元變為了14位元。需要說明的是,圖13和圖14中僅繪示出了關於出現頻率最低的4個字元的霍夫曼樹,而沒有繪示出其他字元對應的霍夫曼樹的節點示意圖。需要說明的是,雖然頻率值被改變了,但霍夫曼碼表中的各字元及其對應的編碼仍然是正確的,不會出錯。 In one embodiment, if 4-bit Huffman coding is performed on the first part of the data, the maximum length of the Huffman coding is 15 bits (ie, 2 4 -1). If the convolution computing device has only 32 bits as the code table unit, 4 bits of which are used for counting and 14 bits are used for masking, then there are 14 bits that can be used for code values. That is to say, there is only a maximum of 14 bits to represent the code value. If a 15-bit code value is encountered, the Huffman tree needs to be modified at this time, so that the maximum bit of the modified Huffman tree is 14 bits. For example, the Huffman tree can be modified in the following way: Change the frequency of the 4 characters with the lowest frequency among all characters, and then reduce the number of layers of the Huffman tree by 1, so that the longest 15-bit Huffman encoding will be reduced to 14 bits Yuan. For example, the original appearance frequencies of the 4 characters with the lowest frequency are 1, 2, 4, and 8, then the shape of the Huffman tree corresponding to these 4 characters can be as shown in FIG. 13 . In the present invention, the frequency values of these 4 characters can be modified to 3, 4, 4, and 4 accordingly, so that the shape of the Huffman tree corresponding to these 4 characters becomes as shown in FIG. 14 . 13 to 14 show schematic diagrams of scenarios of a data processing method according to an embodiment of the present invention. By comparing Figure 13 and Figure 14, it can be seen that the number of layers of the Huffman tree is reduced by one, so that the longest Huffman code is changed from 15 bits to 14 bits. It should be noted that, FIG. 13 and FIG. 14 only show the Huffman tree for the 4 characters with the lowest frequency, but do not show the node diagrams of the Huffman trees corresponding to other characters. It should be noted that although the frequency value has been changed, the characters in the Huffman code table and their corresponding codes are still correct and will not be wrong.
以上對本發明實施例所提供的一種資料處理方法及卷積計算裝置進行了詳細介紹,本文中應用了具體個例對本發明的原理及實施方式進行了闡述,以上實施例的說明只是用於幫助理解本發明的方法及其核心思想;同時,對於本領域的技術人員,依據本發明的思想,在具體實施方式及應用範圍上均會有改變之處,綜上所述,本說明書內容不應理解為對本發明的限制。A data processing method and a convolution computing device provided by the embodiments of the present invention have been described in detail above. The principles and implementations of the present invention are described with specific examples in this paper. The descriptions of the above embodiments are only used to help understanding The method of the present invention and its core idea; at the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation and application scope. In summary, the content of this description should not be understood to limit the present invention.
101~105:步驟
20:卷積計算裝置
201:記憶體
202:解壓縮電路
203:計算電路
301~310:步驟
60:卷積計算裝置
601:記憶體
602:解壓縮電路
603:計算電路
604:資料組合電路
605:轉換電路
101~105: Steps
20: Convolution computing device
201: Memory
202: Decompression circuit
203:
[圖1]顯示本發明之一實施例中,一種資料處理方法的流程示意圖; [圖2]顯示本發明之一實施例中,一種卷積計算裝置的方塊示意圖; [圖3]顯示本發明之一實施例中,資料處理方法的另一流程示意圖; [圖4]顯示本發明之一實施例中,卷積核的權重資料示意圖; [圖5]顯示本發明之一實施例中,將權重資料由補數轉換為原數的示意圖; [圖6]顯示本發明之另一實施例中,卷積計算裝置的方塊示意圖; [圖7]顯示本發明之一實施例中,權重資料對應的壓縮字元的示意圖;以及 [圖8]至[圖14]顯示本發明之一實施例中,資料處理方法的場景示意圖。 [FIG. 1] shows a schematic flowchart of a data processing method in an embodiment of the present invention; [ Fig. 2 ] shows a block diagram of a convolution computing device in an embodiment of the present invention; [ Fig. 3 ] shows another schematic flowchart of a data processing method in an embodiment of the present invention; [FIG. 4] A schematic diagram showing the weight data of the convolution kernel in an embodiment of the present invention; [Fig. 5] shows a schematic diagram of converting the weight data from the complement to the original number in an embodiment of the present invention; [ Fig. 6 ] shows a block diagram of a convolution computing device in another embodiment of the present invention; [ FIG. 7 ] is a schematic diagram showing compressed characters corresponding to weight data in an embodiment of the present invention; and [FIG. 8] to [FIG. 14] are schematic diagrams of scenarios showing a data processing method in an embodiment of the present invention.
101~105:步驟 101~105: Steps
Claims (14)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
TW109134986A TWI758897B (en) | 2020-10-08 | 2020-10-08 | Convolution calculation apparatus and method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
TW109134986A TWI758897B (en) | 2020-10-08 | 2020-10-08 | Convolution calculation apparatus and method |
Publications (2)
Publication Number | Publication Date |
---|---|
TWI758897B TWI758897B (en) | 2022-03-21 |
TW202215275A true TW202215275A (en) | 2022-04-16 |
Family
ID=81710743
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
TW109134986A TWI758897B (en) | 2020-10-08 | 2020-10-08 | Convolution calculation apparatus and method |
Country Status (1)
Country | Link |
---|---|
TW (1) | TWI758897B (en) |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101095284B (en) * | 2004-12-28 | 2012-04-18 | 卡西欧电子工业株式会社 | Device and data method for selective compression and decompression and data format for compressed data |
-
2020
- 2020-10-08 TW TW109134986A patent/TWI758897B/en active
Also Published As
Publication number | Publication date |
---|---|
TWI758897B (en) | 2022-03-21 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102122960B (en) | Multi-character combination lossless data compression method for binary data | |
CN101095284B (en) | Device and data method for selective compression and decompression and data format for compressed data | |
CN105207678B (en) | A kind of system for implementing hardware of modified LZ4 compression algorithms | |
US20220114454A1 (en) | Electronic apparatus for decompressing a compressed artificial intelligence model and control method therefor | |
CN108886367A (en) | Method, apparatus and system for compression and decompression data | |
CN115276666B (en) | Efficient data transmission method for equipment training simulator | |
US7111094B1 (en) | System, method and algorithm for the optimization of entropy for lossless compression | |
JP6647340B2 (en) | Improved file compression and encryption | |
CN114222129A (en) | Image compression encoding method, image compression encoding device, computer equipment and storage medium | |
US4382286A (en) | Method and apparatus for compressing and decompressing strings of electrical digital data bits | |
CN104125475A (en) | Multi-dimensional quantum data compressing and uncompressing method and apparatus | |
TWI758897B (en) | Convolution calculation apparatus and method | |
CN105409129A (en) | Encoder apparatus, decoder apparatus and method | |
CN107911570A (en) | A kind of method for being compressed and decompressing to picture feature | |
CN112200301B (en) | Convolution computing device and method | |
US20180352243A1 (en) | Techniques for compressing multiple-channel images | |
JP2022162930A (en) | Weight data compression method, weight data decompression method, weight data compression device, and weight data decompression device | |
US7020340B2 (en) | Methods for compressing and decompressing data | |
US10498358B2 (en) | Data encoder and data encoding method | |
JP3127016B2 (en) | Data compression and decompression method | |
US8754791B1 (en) | Entropy modifier and method | |
CN112800183A (en) | Content name data processing method and terminal equipment | |
CN114692077A (en) | Matrix calculation device, method, system, circuit, chip and equipment | |
JP3709381B2 (en) | Color image compression method | |
Kaur et al. | Lossless text data compression using modified Huffman Coding-A review |