A data processing method and device, and a computer-readable storage medium

By classifying and extracting the weights in deep neural networks, the problem of large amount of deep neural networks in the existing technology is solved, and efficient utilization of computing resources and improved computing efficiency is achieved.

CN111079890BActive Publication Date: 2025-02-14ZTE CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN201811223953.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-10-19
Publication Date
2025-02-14
Estimated Expiration
2038-10-19

AI Technical Summary

Technical Problem

The prior art is difficult to effectively reduce the computing volume of deep neural networks, resulting in waste of computing resources and inefficient efficiency.

Method used

By obtaining at least one type of weight and corresponding feature data, classification processing is performed to obtain classification features, and using these features for calculation, reducing the amount of redundant calculation. The specific steps include obtaining historical weights, filtering and classifying weights, calculating the processing results corresponding to the weights, and further calculations and adjustments based on the processing results.

Benefits of technology

By classifying weights and extracting features, the calculation amount of neural networks can be effectively reduced, computing efficiency can be improved, and waste of computing resources can be reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111079890B_ABST
    Figure CN111079890B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a method and device for data processing, and a computer-readable storage medium. The method includes: obtaining at least one type of weight and feature data corresponding to each type of weight; obtaining classification features corresponding to each type of weight based on the at least one type of weight; performing calculations based on the at least one type of weight and the feature data to obtain a first processing result corresponding to each type of weight; and performing calculations based on the classification features and the first processing result to obtain a second processing result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence neural network technology, and in particular to a data processing method and device, and a computer-readable storage medium. Background Art

[0002] Deep Neural Network (DNN) is an artificial neural network. The essence of deep learning is to learn more useful features by building a machine learning model with many hidden layers and massive training data, thereby ultimately improving the accuracy of classification or prediction. It has a wide range of applications in speech analysis and image recognition.

[0003] With the continuous development of deep learning technology, the amount of computation required by deep neural networks is increasing. Therefore, effectively reducing the amount of computation required by deep neural networks has become an urgent problem to be solved. Summary of the invention

[0004] In order to solve the above technical problems, embodiments of the present invention hope to provide a data processing method and device, and a computer-readable storage medium, which can reduce the amount of computation of a neural network.

[0005] The technical solution of the present invention is achieved in this way:

[0006] In a first aspect, an embodiment of the present invention provides a data processing method, the method comprising:

[0007] Obtain at least one type of weight and feature data corresponding to each type of weight;

[0008] According to the at least one type of weight, obtaining classification features corresponding to each type of weight;

[0009] Calculating according to the at least one type of weight and the characteristic data to obtain a first processing result corresponding to each type of weight;

[0010] Calculation is performed based on the classification feature and the first processing result to obtain a second processing result.

[0011] In the above solution, before obtaining at least one type of weight, the method further includes:

[0012] Get historical weights;

[0013] Filter the historical weights according to the set filtering conditions to obtain filtered weights;

[0014] The filtered weights are classified according to set classification rules to obtain the at least one category of weights.

[0015] In the above solution, the calculation is performed according to the at least one type of weight and the characteristic data to obtain the first processing result corresponding to each type of weight, including:

[0016] Acquire classification data corresponding to the feature data according to the at least one type of weight and the classification feature;

[0017] The characteristic data is calculated according to the classification data to obtain a first processing result corresponding to each category weight.

[0018] In the above solution, the calculation is performed according to the classification feature and the first processing result to obtain the second processing result, including:

[0019] Arrange the first processing results corresponding to each type of weight according to the set arrangement rule to obtain the first processing results after the arrangement;

[0020] Selecting one first processing result to be processed from the arranged first processing results in sequence according to the arrangement order;

[0021] Perform calculation according to the classification feature and the first processing result to be processed to obtain a first calculation result;

[0022] Calculate the currently obtained first calculation result and the obtained first technical result to obtain a second calculation result;

[0023] When it is determined that the second calculation result is a negative number, the second calculation result is used as a second processing result.

[0024] In the above solution, after the calculation is performed according to the classification feature and the first processing result to obtain the second processing result, the method further includes:

[0025] Obtaining a first dimension of the feature data and a corresponding network dimension;

[0026] Obtaining a second dimension of the second processing result;

[0027] When it is determined that the second dimension is smaller than the first dimension, adjusting the current network dimension corresponding to the second processing result according to the network dimension and a predetermined threshold range;

[0028] Obtaining a weight corresponding to the second processing result;

[0029] Based on the current network dimension and the weight corresponding to the second processing result, the second processing result is calculated to obtain a third processing result.

[0030] In the above solution, when it is determined that the second dimension is smaller than the first dimension, adjusting the current network dimension corresponding to the second processing result according to the network dimension and a predetermined threshold range includes:

[0031] When it is determined that the second dimension is smaller than the first dimension, performing a modulo operation on the network dimension to be adjusted to obtain a modulo result;

[0032] Compare the modulo result and the network dimension to be adjusted to obtain a ratio result;

[0033] When the ratio result is within a predetermined threshold range, it is determined that the dimension to be adjusted is the current network dimension corresponding to the second processing result.

[0034] In the above solution, the characteristic data is calculated according to the classification data to obtain the first processing result corresponding to each type of weight, including:

[0035] Performing a left shift calculation on the feature data according to the classification data to obtain a first processing result corresponding to each category weight;

[0036] Correspondingly, the calculating according to the classification feature and the first processing result to obtain the second processing result includes:

[0037] A multiplication and addition calculation is performed according to the classification feature and the first processing result to obtain a second processing result.

[0038] In a second aspect, an embodiment of the present invention provides a data processing device, the device comprising:

[0039] A first acquisition module is configured to acquire at least one type of weight and feature data corresponding to each type of weight;

[0040] A second acquisition module is configured to acquire classification features corresponding to each type of weight according to the at least one type of weight;

[0041] A first obtaining module is configured to perform calculations based on the at least one type of weight and the characteristic data to obtain a first processing result corresponding to each type of weight;

[0042] The second obtaining module is configured to perform calculations based on the classification features and the first processing results to obtain a second processing result.

[0043] In a third aspect, an embodiment of the present invention provides a data processing device, wherein the data processing device includes a processor, a memory storing instructions executable by the processor, and a bus for connecting the processor and the memory, and when the instructions are executed, the processor implements the above-mentioned data processing method.

[0044] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a data processing program stored thereon, wherein the data processing program implements the above-mentioned data processing method when executed by a processor.

[0045] The embodiments of the present invention provide a method and device for operating a neural network, and a computer-readable storage medium. The method includes: obtaining at least one type of weight and feature data corresponding to each type of weight; obtaining classification features corresponding to each type of weight based on at least one type of weight; performing calculations based on at least one type of weight and feature data to obtain a first processing result corresponding to each type of weight; performing calculations based on the classification features and the first processing result to obtain a second processing result. In this way, the weights are first classified to obtain classification features, and then the feature data is calculated based on the classification features. This allows the huge weights to be analyzed and sorted into fewer situations, thereby effectively reducing the amount of calculations. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] Figure 1 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 1 ;

[0047] Figure 2 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 2 ;

[0048] Figure 3 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 3 ;

[0049] Figure 4 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 4 ;

[0050] Figure 5 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 5 ;

[0051] Figure 6 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 6 ;

[0052] Figure 7 A schematic diagram of the structure of the neural network hardware architecture provided by an embodiment of the present invention;

[0053] Figure 8 A schematic diagram of the structure of a computing unit provided in an embodiment of the present invention;

[0054] Fig. 9 A schematic diagram of the structure of a classification operation unit in a calculation unit provided in an embodiment of the present invention;

[0055] Fig.10 A schematic diagram of a structure in which one CP operation unit corresponds to one multiplication-addition operation unit in a computing unit provided in an embodiment of the present invention;

[0056] Fig.11 A schematic diagram of a structure in which one CP operation unit corresponds to multiple multiplication and addition operation units in a computing unit provided in an embodiment of the present invention;

[0057] Fig.12 A data processing method is provided for the present invention. Figure 7 ;

[0058] Fig.13 This is a schematic diagram of the dimensional matching composition of the computing unit in an embodiment of the present invention;

[0059] Fig.14 A schematic diagram of the operation structure in a computing unit provided in an embodiment of the present invention;

[0060] Fig.15 A schematic diagram of a data processing device provided by an embodiment of the present invention;

[0061] Fig.16 A schematic diagram of the structure of a data processing device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0062] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0063] Embodiment 1

[0064] The embodiment of the present invention provides a data processing method. Figure 1 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 1 ,like Figure 1 As shown, in an embodiment of the present invention, implementing the data processing method may include the following steps:

[0065] Step 101: Obtain at least one type of weight and feature data corresponding to each type of weight.

[0066] In the embodiment of the present invention, before calculating the characteristic data and the weights, it is necessary to obtain at least one type of weight and the characteristic data corresponding to each type of weight.

[0067] It should be noted that at least one type of weight obtained is a classified weight obtained after being processed in advance according to the screening conditions and classification rules, and since each weight corresponds to corresponding feature data, each type of weight indicator, the position index information corresponding to the weight, and the feature data corresponding to each type of weight are stored in advance in the storage unit, and the weight indicator is used to identify the weight, and the position index information corresponding to the weight is used to identify the storage location of the feature data, that is, the weight indicator corresponds to the weight, and the weight corresponds to the position index information, so the weight indicator and the position index information are corresponding. Here, the weight indicator and the corresponding position index information are read out sequentially from the storage unit, the weight is restored through the weight indicator, and the feature data of the corresponding position is indexed through the position index information, that is, the feature data corresponding to the weight, and the weight and the feature data are convolved, and so on, to complete all convolution operations.

[0068] Exemplarily, the above-mentioned screening condition may be to remove weights with a set threshold and retain weights without a set threshold. For example, when the threshold is 0, the screening condition is to remove weights with a value of 0 and retain weights with a value other than 0. The above-mentioned classification rule may be to group weights with the same absolute value of positive and negative numbers into one category, and then classify each type of weight according to the common factor multiplied by the power of 2; or to classify weights with negative values ​​into one category and weights with positive values ​​into another category, and then classify each type of weight according to the common factor multiplied by the power of 2; or to classify directly according to the common factor multiplied by the power of 2. For example, weights with values ​​of 1, 3, 4, and 6 may be converted into 1=1*2 according to the common factor multiplied by the power of 2. 0 ,3=3*2 0 ,4=1*2 2 ,6=3*2 1 After extracting the common factors, weights 3 and 6 with a common factor of 3 can be classified into one category, and weights 1 and 4 with a common factor of 1 can be classified into another category. The above screening conditions and classification rules are not limited in the embodiment of the present invention.

[0069] Step 102: According to at least one type of weight, obtain classification features corresponding to each type of weight.

[0070] In the embodiment of the present invention, after obtaining at least one type of weight, classification features corresponding to each type of weight may also be obtained based on the at least one type of weight.

[0071] It should be noted that by classifying the weights, the classification features corresponding to each type of weight can be obtained. For example, the weights of 1, 3, 4, and 6 can be converted into 1=1*2 by multiplying the common factor by the power of 2. 0 ,3=3*2 0 ,4=1*2 2 ,6=3*2 1In this way, the weights with a common factor of 3 can be divided into one category, and the common factor 3 corresponding to the weights 3 and 6 of this category is the classification feature corresponding to this category of weights; the weights with a common factor of 1 can be divided into another category, and the common factor 1 corresponding to the weights 1 and 4 of this category is the classification feature corresponding to this category of weights.

[0072] Step 103: Calculate based on at least one type of weight and feature data to obtain a first processing result corresponding to each type of weight.

[0073] In an embodiment of the present invention, after obtaining weights and feature data, classification features can be obtained based on the weights, and then calculations can be performed based on the classification features and weights to obtain classification data corresponding to the feature data, and then addition calculations can be performed on the feature data based on the classification data to obtain the first processing results corresponding to each type of weight.

[0074] For example, if the weight values ​​of one type of weights are 1 and 4 respectively, the feature data corresponding to weight 1 is 1, and the feature data corresponding to weight 4 is 2; the weight values ​​of another type of weights are 6 and -12 respectively, the feature data corresponding to weight 6 is 3, and the feature data corresponding to weight -12 is 4, then the weights can be converted to 1=1*2 by multiplying the common factor by the power of 2. 0 ,4=1*2 2 ,6=3*2 1 , 12 = 3*2 2 , where the classification features corresponding to weights 1 and 4, that is, the common factor is 1, and the corresponding classification data, that is, the power of 2, are 0 and 2 respectively; the classification features corresponding to weights 6 and -12, that is, the common factor is 3, and the corresponding classification data, that is, the power of 2, are 1 and 2 respectively.

[0075] From the above description, it can be seen that the first processing results corresponding to each category of weights are obtained by adding the feature data according to the classified data. Specifically, the first processing results corresponding to one category of weights 1 and 4 are (1<<0)+(2<<2)=1+8=9; the first processing results corresponding to another category of weights 6 and -12 are (3<<1)-(4<<2)=6-16=-10.

[0076] It should be noted that the calculation corresponding to the negative weight is the addition of negative numbers, that is, subtraction.

[0077] In the embodiment of the present invention, the classification features obtained in step 102 and the first processing result obtained in step 103 are used in step 104 to calculate the second processing result according to step 102 and step 103. Therefore, step 103 can also be executed before step 102. The embodiment of the present invention does not specifically limit the execution order of step 102 and step 103.

[0078] Step 104: Perform calculation based on the classification feature and the first processing result to obtain a second processing result.

[0079] In the embodiment of the present invention, after the classification feature and the first processing result are obtained, a multiplication and addition calculation is performed according to the classification feature and the first processing result to obtain the second processing result.

[0080] Exemplarily, weights 1, -12, 4, and 6 are divided into one category according to the common factor multiplied by the power of 2, and weights 1 and 4 are divided into another category. The first processing result corresponding to weights 1 and 4 is 9, and the corresponding classification feature is 1; the first processing result corresponding to weights 6 and -12 is -10, and the corresponding classification feature is 3, then the second processing result is 9*1+(-10)*3=-21.

[0081] Figure 2 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 2 ,like Figure 2 As shown, in the embodiment of the present invention, before obtaining at least one type of weight data, that is, before step 101, the data processing method may further include the following steps:

[0082] Step 101a: Obtain historical weights.

[0083] In the embodiment of the present invention, sufficient sample data is collected and trained according to a preset model such as a back propagation algorithm of an artificial neural network to obtain historical weights.

[0084] Step 101b: filter the historical weights according to the filter conditions to obtain the filtered weights.

[0085] In the embodiment of the present invention, in order to support sparse computing of a neural network, historical weights may be screened according to set screening conditions to obtain screened weights.

[0086] Exemplarily, the above-mentioned filtering condition can be to delete the weights with a value of 0 and retain the weights with a value of non-0, that is, only store the weights with a value of non-0, and do not need to store and calculate the weights with a value of 0. This can reduce both the storage bandwidth and the amount of calculation, thereby supporting sparse operations of neural networks.

[0087] Step 101c: classify the screened weights according to the set classification rules to obtain at least one category of weights.

[0088] In an embodiment of the present invention, after obtaining the filtered weights, the filtered weights can also be classified according to classification rules to obtain at least one category of weights. The classification rule can be to classify weights with the same absolute values ​​of positive and negative numbers into one category, and then further classify the classified weights according to the common factor multiplied by the power of 2.

[0089] Exemplarily, taking 8-bit fixed point as an example, there are 256 cases of weights from -128 to 127. The weights with the same absolute value of positive and negative numbers are classified into one category, and there are 128 cases of weights after classification; the classified weights are then classified into 128 cases in the manner of common factors multiplied by the power of 2, such as 1, 2, 4, 8, 16, 32, and 64 are classified into one category, and the corresponding classification feature, that is, the common factor is 1; 3, 6, 12, 24, 48, and 96 are classified into one category, and the corresponding classification feature, that is, the common factor is 3; after classification, the weights are merged into 64 cases, so that the original 256 cases can be sorted into 64 cases through classification.

[0090] Figure 3 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 3 ,like Figure 3 As shown, in the embodiment of the present invention, calculation is performed based on at least one type of weight and feature data to obtain the first processing result corresponding to each type of weight, that is, the data processing method implemented in step 103 may include the following steps:

[0091] Step 103a: Obtain classification data corresponding to the feature data according to at least one type of weight and classification feature.

[0092] In the embodiment of the present invention, after the weights and classification features are obtained, classification data corresponding to the feature data may be obtained according to at least one type of weights and classification features.

[0093] For example, if the weight values ​​of one type of weight are 1 and 4, and the corresponding feature data are 1 and 2 respectively; the weight values ​​of another type of weight are 6 and -12, and the corresponding feature data are 3 and 4 respectively, then the weights can be converted to 1=1*2 by multiplying the common factor by the power of 2. 0 ,4=1*2 2 ,6=3*2 1 , 12 = 3*2 2 Among them, the classification features of one type with weights 1 and 4, that is, the common factor is 1, and the corresponding classification data, that is, the power of 2, are 0 and 2 respectively; the classification features corresponding to the other type of weights 6 and -12, that is, the common factor is 3, and the corresponding classification data, that is, the power of 2, are 1 and 2 respectively.

[0094] Step 103b: perform left shift calculation on the feature data according to the classification data to obtain the first processing result corresponding to each category weight.

[0095] Step 104a: perform multiplication and addition calculations based on the classification feature and the first processing result to obtain a second processing result.

[0096] Exemplarily, if the weight values ​​of one type of weights are 1 and 4, the corresponding feature data are 1 and 2 respectively, the corresponding classification data, that is, the powers of 2, are 0 and 2 respectively, and the corresponding classification features, that is, the common factor is 1; the weight values ​​of another type of weights are 6 and -12, the corresponding feature data are 3 and 4 respectively, the corresponding classification data, that is, the powers of 2, are 1 and 2 respectively, and the corresponding classification features, that is, the common factor is 3, then the first processing results corresponding to weights 1 and 4 are (1<<0)+(2<<2)=1+8=9; the first processing results corresponding to weights 6 and -12 are (3<<1)-(4<<2)=6-16=-10, and then according to the classification features and the first processing results, multiplication is performed first and then accumulation is performed, that is, first multiplication 9*1 is performed to obtain 9, then 10*3 is performed to obtain 30, and then accumulation is performed to obtain the second processing result of 9+(-30)=-21.

[0097] Based on the above description, taking 8-bit fixed point as an example, there are 256 cases where the weight is -128 to 127. The prior art directly multiplies and then adds the weight and the corresponding feature data. Therefore, 256 multiplication calculations are required to obtain the second processing result. In order to reduce the amount of calculation, in the embodiment of the present invention, all weights are first classified to obtain 64 types of weights, and then the classified weights and the corresponding feature data are shifted and accumulated to obtain the first processing results corresponding to the 64 types of weights, and then the first processing result and the corresponding classification feature are multiplied and then accumulated. That is, the embodiment of the present invention only needs 64 multiplication calculations to obtain the second processing result. Therefore, the embodiment of the present invention can effectively reduce the amount of calculation.

[0098] Figure 4 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 4 ,like Figure 4 As shown, in the embodiment of the present invention, the second processing result is obtained by calculating according to the classification feature and the first processing result, that is, the data processing method implemented in step 104 may include the following steps:

[0099] Step 104a1: Arrange the first processing results corresponding to each type of weight according to the set arrangement rule to obtain the first processing results after arrangement.

[0100] In the embodiment of the present invention, after obtaining the first processing results corresponding to each type of weight, the first processing results corresponding to each type of weight can be arranged in order according to the set arrangement rule to obtain the first processing results after the arrangement order. Here, if a corresponding first processing result is obtained for each type of weight, the arrangement order of the first processing results corresponding to each type of weight is the arrangement order of each first processing result obtained, that is, the number of first processing results is the same as the number of weight classes.

[0101] It should be noted that before arranging the order of the first processing results corresponding to each type of weight according to the set arrangement rules, the embodiment of the present invention needs to pre-process the weights according to steps 101a to 101c. The specific preprocessing can be: first identify the positive and negative values ​​of the weights, and classify the weights with positive values ​​into one category, and the weights with negative values ​​into another category, that is, the screened weights can be divided into two categories according to positive and negative numbers, and then the positive and negative weights can be further classified according to the common factor multiplied by the power of 2, so as to obtain at least one type of weight and the first processing results corresponding to each type of weight; then, the first processing results corresponding to each type of weight are sorted according to the set sorting rules to obtain the first processing results after the arrangement order corresponding to each type of weight.

[0102] Here, the sorting rule can be to put the first processing result with a positive value in front of the sorting result, and to put the first processing result with a negative value in the back of the sorting result. Then, the first processing results corresponding to each type of weight are sorted according to the sorting rule to obtain the first processing result after the sorting order, including: first identifying whether the value of the first processing result is positive or negative, and dividing the first processing result into positive first processing results and negative first processing results according to the positive or negative value of the first processing result, then selecting the positive first processing result and putting it in front of the sorting result, and selecting the negative first processing result and putting it behind the sorting result, that is, behind the positive first processing result, so that when calculating the second processing result, the first processing result of the positive number is calculated first, and then the first processing result of the negative number is calculated. For the first processing result of the positive number placed in front of the sorting result, the order can be arranged by size, or the order can be arranged at will, as long as it is guaranteed to be calculated before the first processing result of the negative number; for the first processing result of the negative number placed behind the sorting result, the order can be arranged at will. In order to further reduce the amount of calculation, all the first processing results of the negative number placed behind the sorting result can be arranged in order from small to large.

[0103] Step 104b1, selecting first processing results to be processed from the first processing results after being arranged in order according to the order of arrangement;

[0104] It should be noted that the arrangement and sorting here is to put the first processing result of positive numbers in front, and the first processing results of negative numbers are all placed behind the first processing results of positive numbers. In an embodiment of the present invention, the first processing results to be processed are selected in sequence according to the arrangement order. The first processing result of the positive number arranged in the front can be selected first. After the first processing of each positive number is selected for calculation in turn, the first processing result corresponding to the negative number weight at the back is selected for calculation.

[0105] Step 104c1, performing calculation according to the first processing result to be processed and the classification feature to obtain a first calculation result.

[0106] Step 104d1, calculate the currently obtained first calculation result and the already obtained first calculation result to obtain a second calculation result.

[0107] Step 104e1: When it is determined that the second calculation result is a negative number, the second calculation result is used as the second processing result.

[0108] In an embodiment of the present invention, after selecting the first processing result to be processed, calculation is performed based on the first processing result to be processed and the classification feature to obtain the first calculation result, the currently obtained first calculation result is calculated with the first calculation result that has been obtained to obtain the second calculation result, and it is determined whether the second calculation result is a negative number. If the second calculation result is a negative number, then according to the arrangement order, it can be known that the next selected first processing result should also be a negative number. At this time, the calculation process of the next selection is stopped, and the second calculation result is directly used as the second processing result; if the second calculation result is a positive number, the next first processing result to be processed is continued to be selected and calculated to obtain the second calculation result, and it is determined again whether the second calculation result is a negative number, and so on, until it is determined that the second calculation result is a negative number or the calculation of the last first processing result in the arrangement order is completed.

[0109] For example, if the first processing results after the arrangement order are A, B, C, and D, and the corresponding classification features are A1, B1, C1, and D1 respectively, A*A1 is calculated first to determine whether A*A1 is a negative number. If the second calculation result A*A1 is a negative number, the second calculation result A*A1 is directly used as the second processing result. If the second calculation result A*A1 is a positive number, B*B1 is calculated, and then the current first calculation result B*B1 is calculated with the first calculation result A*A1 that has been obtained to obtain a second calculation result of A*A1+B*B1. It is determined whether the second calculation result A*A1+B*B1 is a negative number. If the second calculation result A*A1+B*B1 is a negative number, the second calculation result A*A1+B*B1 is used as the second processing result. If the second calculation result A*A1+B*B1 is a negative number, then the second calculation result A*A1+B*B1 is directly used as the second processing result. If the second calculation result A*A1+B*B1 is a positive number, then C*C1 is calculated, and then the current first calculation result C*C1 is calculated with the first calculation result A*A1+B*B1 that has been obtained to obtain a second calculation result of A*A1+B*B1+C*C1. It is again determined whether the second calculation result A*A1+B*B1+C*C1 is a negative number, and so on, until it is determined that the second calculation result is a negative number or the last first processing result D in the arrangement order is calculated.

[0110] It should be noted that, for deep neural network calculations, as long as the second processing result is a negative number, it will be regarded as a 0 output for the linear rectified linear unit (Rectified Linear Unit, ReLU) activation function. Based on the above description, it can be seen that the embodiment of the present invention improves the entire calculation process. First, all weights are divided into two categories according to positive numbers and negative numbers, and then the two categories of weights are reclassified according to classification rules such as common factors multiplied by the power of 2. When the weight values ​​corresponding to one type of weights are all negative numbers, the first processing result of its calculation is a negative number, and when the weight values ​​corresponding to one type of weights are all positive numbers, the first processing result of its calculation is a positive number. In this way, the first processing results corresponding to each type of weight are arranged, and the positive numbers are placed in front of the arrangement order, and the negative numbers are placed behind the positive numbers in the arrangement order, and then selected in sequence according to the arrangement order. When it is determined that the second calculation result is a negative number, the subsequent calculation process must also be a negative number, and the calculation can be terminated, which can achieve the purpose of terminating the convolution calculation in advance, thereby reducing the amount of calculation and the power consumption, and thus improving the energy efficiency ratio.

[0111] Figure 5 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 5 ,like Figure 5 As shown, in the embodiment of the present invention, after calculating according to the classification feature and the first processing result to obtain the second processing result, that is, after step 104, the data processing method may further include the following steps:

[0112] Step 105: Obtain the first dimension of the feature data and the corresponding network dimension.

[0113] In the embodiment of the present invention, the first dimension represents the network model actually required for calculation based on weights and feature data, and the network dimension represents the network model planned to be allocated to the weights and feature data for calculation.

[0114] Step 106: Obtain a second dimension of the second processing result.

[0115] In the embodiment of the present invention, in order to further ensure the computing resources corresponding to the second processing result, the embodiment of the present invention needs to obtain the first dimension corresponding to the current feature data and the second dimension corresponding to the second processing result;

[0116] Step 107: When it is determined that the second dimension is smaller than the first dimension, the current network dimension corresponding to the second processing result is adjusted according to the network dimension and a predetermined threshold range.

[0117] In an embodiment of the present invention, after obtaining the second processing result and before performing the next layer of calculation, the embodiment of the present invention needs to determine whether the second dimension is smaller than the first dimension. If the second dimension is smaller than the first dimension, it indicates that processing the next layer of calculation according to the network dimension corresponding to the current layer will obviously waste computing resources. If the second dimension is not smaller than the first dimension, it indicates that processing the next layer of calculation according to the network dimension corresponding to the current layer will not waste resources, that is, there is no need to adjust the current network dimension corresponding to the second processing result. Therefore, the embodiment of the present invention sets a predetermined threshold range, and adjusts the current network dimension corresponding to the second processing result according to the network dimension and the predetermined threshold range to avoid waste of resources.

[0118] Step 108: Obtain the weight corresponding to the second processing result.

[0119] Step 109: Based on the current network dimension and the weight corresponding to the second processing result, the second processing result is calculated to obtain a third processing result.

[0120] In an embodiment of the present invention, after obtaining the current network dimension, the second processing result is calculated according to the weight corresponding to the second processing result to obtain the third processing result. In this way, during the calculation process, once it is found that the calculated network dimension becomes smaller, the current network dimension can be adjusted in real time to achieve maximum utilization of computing resources.

[0121] Figure 6 A schematic diagram of an implementation process of a data processing method provided in an embodiment of the present invention Figure 6 ,like Figure 6 As shown, in an embodiment of the present invention, when it is determined that the second dimension is smaller than the first dimension, the current dimension corresponding to the second processing result is adjusted according to the second dimension and the predetermined threshold range, that is, the data processing method implemented in step 107 may further include the following steps:

[0122] Step 107a: When it is determined that the second dimension is smaller than the first dimension, a modulo operation is performed on the network dimension and the network dimension to be adjusted to obtain a modulo result.

[0123] In the embodiment of the present invention, when it is determined that the second dimension is smaller than the first dimension, that is, the current network dimension needs to be adjusted, the network dimension and the dimension to be adjusted are modulo-calculated to obtain a modulo result.

[0124] Exemplarily, assuming that the network dimension is 18 and the network dimension to be adjusted is 16, the two modulo operations result in a modulo result of 2.

[0125] Step 107b: perform a comparison based on the modulo result and the network dimension to be adjusted to obtain a ratio result.

[0126] In the embodiment of the present invention, after the modulo result is obtained, a ratio is performed based on the modulo result and the network dimension to be adjusted to obtain a ratio result.

[0127] Exemplarily, assuming that the network dimension is 18 and the network dimension to be adjusted is 16, the two modulo results are 2, and the ratio of the modulo result to the network dimension to be adjusted is 2 / 16=1 / 8.

[0128] Step 107c: when the ratio result is within a predetermined threshold range, determine that the dimension to be adjusted is the current network dimension corresponding to the second processing result.

[0129] In the embodiment of the present invention, assuming that the predetermined threshold range is 0 to 1 / 6, based on the above example, if the ratio result 1 / 8 is within the predetermined threshold range, it is determined that the dimension to be adjusted 16 is the current network dimension corresponding to the second processing result.

[0130] In an embodiment of the present invention, at least one type of weight and feature data corresponding to each type of weight are obtained; classification features corresponding to each type of weight are obtained based on at least one type of weight; calculations are performed based on at least one type of weight and feature data to obtain a first processing result corresponding to each type of weight; and calculations are performed based on the classification features and the first processing result to obtain a second processing result. In this way, the weights are first classified to obtain classification features, and then the feature data is calculated based on the classification features. This allows the huge weights to be analyzed and sorted into fewer situations, thereby effectively reducing the amount of calculations.

[0131] Embodiment 2

[0132] Based on the same inventive concept of the first embodiment, the above data processing method is applied to a neural network. In order to better understand the embodiment of the present invention, a convolutional neural network (CNN) is briefly described below:

[0133] DNN includes CNN and RNN, which generally includes an input layer, a hidden layer and an output layer.

[0134] CNN is a multi-layer neural network, each layer consists of multiple two-dimensional planes, and each plane consists of multiple independent neurons. CNN usually consists of convolutional layer, pooling layer and full connection layer (FC), among which,

[0135] The convolution layer generates a feature map of the input data through the convolution kernel and the nonlinear activation function. The convolution kernel repeatedly performs inner product with different regions of the input data and then outputs it through the nonlinear function.

[0136] The pooling layer is usually an average pooling layer or a maximum pooling layer, which simply finds the average or maximum value of a certain area of ​​the feature map obtained in the previous layer;

[0137] All elements of the input segment in the fully connected layer are connected to the output neurons, and each output element is the sum of all input elements multiplied by their respective weights.

[0138] Figure 7 A schematic diagram of the structure of the neural network hardware architecture provided by an embodiment of the present invention is shown in FIG. Figure 7 As shown, the neural network hardware architecture includes: a central processing unit (CPU), a storage unit, a direct memory access (DMA) controller, a command parsing unit, a control unit, an input and output cache unit and a computing unit, wherein:

[0139] CPU, used to send control instructions to the DMA controller;

[0140] A storage unit, used to store the characteristic data, weights and calculation results of the neural network, and the storage unit can be an external double data rate synchronous dynamic random access memory (Double Data Rate SDRAM, DDR) or an on-chip random access memory (Random Access Memory, RAM);

[0141] A DMA controller is used to receive a control instruction for convolution calculation from a CPU, the instruction carrying a start address and an end address, store the feature data and weights stored in the address segment identified by the start address and the end address from the storage unit to the input and output buffer unit, and send the instruction to the command parsing unit at the same time, or receive a control instruction for storing calculation results from the CPU, and store the calculation results obtained by the calculation unit from the input and output buffer unit to the storage unit;

[0142] A command parsing unit, used for receiving an instruction from the DMA controller, parsing the instruction to obtain the content of the instruction, and sending the content obtained by parsing the instruction to the control unit;

[0143] A control unit, used for receiving the content obtained from the command parsing unit, and sending instructions to the input and output buffer unit according to the content obtained by the command parsing unit;

[0144] An input-output buffer unit, used to receive instructions from the control unit, and prepare the feature data and weights to be calculated for the calculation unit according to the instructions of the control unit; or, used to store the feature data and weights to be calculated by the calculation unit and the calculation results obtained by the calculation unit, and the input-output buffer unit can be an on-chip dynamic random access memory (DRAM) or a register array;

[0145] The input and output cache unit consists of two parts: one part is used to cache weights and feature data. To reduce the cache data capacity, the cache size can be associated with the number of channels in each layer and the corresponding convolution kernel size; for example, if the convolution kernel size is 3*3, data of 64 channels can be cached; if the convolution kernel size is 7*7, data of more than 64 channels can be cached;

[0146] Another part of the cache is used to store the weights and feature data to be calculated, and output the weights and feature data to the calculation unit;

[0147] The computing unit is used to receive the feature data and weights from the input and output buffer units, and complete the convolution calculation according to the feature data and weights to obtain the second processing result. In a deep neural network, it is necessary to perform a convolution operation first, and then perform the FC multiplication and addition operation, the ReLU activation function, and the pooling process in the FC. Therefore, in addition to completing the convolution operation, the computing unit of the embodiment of the present invention can also be used to complete the FC multiplication and addition operation, the ReLU activation function, and the pooling process. Since the embodiment of the present invention is an improvement on the convolution calculation in the computing unit to reduce the amount of calculation, the process of the computing unit completing the convolution calculation will be described in detail below.

[0148] Figure 8 A schematic diagram of the structure of a computing unit provided in an embodiment of the present invention is shown in FIG. Figure 8 As shown, the computing unit includes a selector, a classification processor (CP) computing unit and a multiply-add unit (MAU), wherein:

[0149] A selector, for receiving feature data and weights outputted from the input and output buffer units, selecting corresponding weights and feature data from the feature data and weights according to the weight indicator and the corresponding position index information, and outputting the weights and feature data to the CP operation unit;

[0150] The CP operation unit is used to receive the feature data and weight output by the selector, perform shift calculation on the feature data and weight, and input the first processing result and classification feature to the MAU;

[0151] The MAU is used to receive the first processing result and the classification feature output by the CP operation unit, and perform multiplication and addition calculations on the first processing result and the classification feature to obtain a second processing result.

[0152] Fig. 9 A schematic diagram of the structure of a CP operation unit in a computing unit provided in an embodiment of the present invention, such as Fig. 9 As shown, the CP operation unit includes a classifier and an adder, wherein:

[0153] The classifier is used to receive the weights and feature data output from the selector, classify the weights to obtain classification features and classification data, and input the classification features, classification data and feature data to the adder.

[0154] The adder is used to receive the classification features, classification data and feature data output from the classifier, and then perform shift addition operations on the feature data according to the classification data to obtain a first processing result, and then input the first processing result and the classification features to the MAU. When the weight is a negative number, the adder performs the calculation corresponding to the negative weight as a negative addition calculation, that is, a subtraction calculation.

[0155] MAU is used to receive the first processing result and classification feature output from the adder, perform multiplication calculation on the first processing result and the classification feature, and then perform accumulation calculation to output the second processing result. MAU can correspond to one or more CP operation units. Fig.10 A schematic diagram of a structure in which one CP operation unit corresponds to one multiplication-addition operation unit in a computing unit provided in an embodiment of the present invention, as shown in FIG. Fig.10 As shown, the MAU includes a multiplier and an accumulator. The CP operation unit outputs the first processing results corresponding to each type of weight and the corresponding classification features to the MAU in sequence. The multiplier first multiplies the classification features corresponding to the first processing results of the first two types of weights, and outputs the corresponding two multiplication results to the accumulator. The accumulator then adds the two multiplication results. The multiplier then multiplies the classification features corresponding to the first processing results of the third type of weights, and outputs the corresponding multiplication results to the accumulator. The accumulator then performs accumulation on the basis of the previous ones, until the first processing result corresponding to the last type of weight and the corresponding classification features are multiplied first and then accumulated, and the accumulated result is used as the second processing result. Fig.11 A schematic diagram of a structure in which a plurality of CP operation units in a computing unit corresponding to one multiplication-addition operation unit is provided in an embodiment of the present invention, such as Fig.11 As shown, a multiplier queue is added before the multiplier to complete the routing selection function of multiple CP operation units to one multiplier. This design can effectively increase the frequency of multiplier use and thus reduce the number of multipliers used.

[0156] Based on the above description, Fig.12 A data processing method is provided for the present invention. Figure 7 ,like Fig.12 As shown, in order to better illustrate the data processing method provided by the embodiment of the present invention, the data processing method can be applied to the computing unit of the above neural network hardware architecture. The data processing method implemented by the embodiment of the present invention may include the following steps:

[0157] Step 201: Store weights and feature data in a storage unit in advance.

[0158] It should be noted that for classified data, positive numbers can be stored first, and then negative numbers, so that the subsequent multiplication and addition operations can be terminated early. For data with a weight of 0, since the result of the convolution operation is still 0, the data with a weight of 0 is discarded and does not participate in the calculation, that is, it does not need to be stored or read out in the storage unit, thereby saving storage resources and data read and write bandwidth, and improving resource processing efficiency, thereby achieving the effect of supporting sparse operations.

[0159] Step 202: The computing unit generates a corresponding network dimension.

[0160] It should be noted that, for the computing unit, since the network dimensions corresponding to different network models are different, such as 300*300 and 416*416; in addition, for different network models, the supported dimension sizes may also be inconsistent, such as 1*1, 3*3, 5*5, 7*7, etc. Therefore, the computing unit of the embodiment of the present invention is designed as an elastic and scalable structure, that is, when the dimensions corresponding to different network models are different, the computing unit can be matched to the dimensions corresponding to the corresponding network structure model to maximize the utilization of computing resources.

[0161] Fig.13 FIG. 1 is a schematic diagram of the dimensional matching composition of the computing unit in an embodiment of the present invention. Fig.13 As shown, if the convolution kernel is 1*1 or 3*3 or the feature image is 4*4 or less, the network dimension can become Fig.13 On the left, if the convolution kernel is larger than 3*3 or the feature image is larger than 4*4, the network dimension can become Fig.13 On the right.

[0162] In an embodiment of the present invention, when the control unit sends a dimension instruction corresponding to the current neural network model to the computing unit, the computing unit generates a corresponding hardware structure model according to the instruction, that is, the network dimension corresponding to the calculation of this layer, specifically: obtaining a first dimension of the feature data and a corresponding network dimension; obtaining a second dimension of the second processing result; when it is determined that the second dimension is smaller than the first dimension, adjusting the current network dimension corresponding to the second processing result according to the network dimension and a predetermined threshold range; obtaining a weight corresponding to the second processing result; and calculating the second processing result based on the current network dimension and the weight corresponding to the second processing result to obtain a third processing result.

[0163] Among them, the method for determining the current network dimension can be that when it is determined that the second dimension is smaller than the first dimension, the network dimension is modulo-operated with the network dimension to be adjusted to obtain a modulo result; a ratio is performed based on the modulo result and the network dimension to be adjusted to obtain a ratio result; when the ratio result is within a predetermined threshold range, it is determined that the dimension to be adjusted is the current network dimension corresponding to the second processing result.

[0164] Step 203: The DMA controller reads out the corresponding weight and feature data from the storage unit and stores them in the input and output buffer unit.

[0165] In the embodiment of the present invention, the CPU sends an instruction to the DMA controller, and the DMA controller outputs the weight and characteristic data read from the storage unit according to the sent instruction to the input-output buffer unit.

[0166] It should be noted that when running to a certain process, the CPU will be informed of the current processing progress in the form of an interrupt. The control unit sends corresponding instructions to the input and output cache unit according to the current processing progress. The input and output cache unit outputs instructions to the computing unit and prepares the weights and feature data to be calculated for the computing unit. Then the computing unit performs corresponding operations according to the instruction requirements. For example, after the convolution calculation is completed, the full connection needs to be calculated. The computing unit and the cache unit match the full connection operation according to the instruction.

[0167] Step 204: The input and output buffer units obtain weight and feature data.

[0168] In an embodiment of the present invention, the cache unit needs to obtain the position index information corresponding to the weight, and index the corresponding feature data according to the position index information corresponding to the weight. For example, assuming the weight value A1, its original position corresponding to the filter is numbered 100, then the feature data of the position can be indexed according to the position number 100 corresponding to the weight value A1.

[0169] Step 205: The CP operation unit in the calculation unit calculates the input weight and feature data to obtain a first processing result.

[0170] In the embodiment of the present invention, after acquiring the weights and feature data, the input-output cache unit outputs the weights and feature data to the calculation unit, and the CP operation unit in the calculation unit calculates the input weights and feature data to obtain a first processing result.

[0171] Here, the CP operation unit first accumulates the feature data corresponding to the same category weight according to the classification features corresponding to the weight. After the accumulation of the same classification data is completed, the accumulator is cleared and the next classification data is accumulated until all data are processed.

[0172] It should be noted that if the weight is a positive number, the CP operation unit performs addition; if it is a negative number, the CP operation unit performs subtraction.

[0173] For example, if the weight values ​​of a class of weights are 6, 12, -24, and 48, and the corresponding feature data are 2, 6, 8, and 3, respectively, then the classification feature corresponding to the weight, that is, the common factor, is 3, and the corresponding classification data, that is, the power of 2, are 1, 2, 3, and 4, respectively. Then the first processing result corresponding to this class of weights is (2<<1)+(6<<2)-(8<<3)+(3<<4)=4+24-64+48=12.

[0174] Step 206: The MAU calculates the input classification feature and the first processing result to obtain a second processing result.

[0175] In the embodiment of the present invention, after the results of multiple CP operations are output to the MAU, they are first converted into a serial data stream and sent to the multiplier module. After the multiplication operation is completed, the accumulation operation of different classification data is performed.

[0176] Fig.14 A schematic diagram of the operation structure in the computing unit provided in the embodiment of the present invention, such as Fig.14 As shown, the calculation structure in the calculation unit consists of feature data, weights, CP array and MAU array. The calculation process of the calculation unit is:

[0177] The weight and feature data are output to the corresponding CP operation unit through the selector. The CP operation unit completes the classification accumulation processing and outputs the first processing result and the classification feature to the MAU. The MAU performs multiplication and addition operations on the first processing result and the classification feature to obtain the second processing result.

[0178] According to the embodiment of the present invention, the feature data is first accumulated and calculated by the classification feature to obtain a first processing result, and then a multiplication and addition operation is performed based on the first processing result and the classification feature. This operation method of adding first and then multiplying can effectively reduce the amount of calculation.

[0179] Embodiment 3

[0180] Based on the same inventive concept of the first and second embodiments, the present invention provides a data processing device, and the computing unit in the hardware architecture of the neural network of the second embodiment can apply the data processing device. Fig.15 A schematic diagram of a data processing device provided by an embodiment of the present invention is shown in FIG. Fig.15 As shown, the data processing device includes:

[0181] A first acquisition module 301 is configured to acquire at least one type of weight and feature data corresponding to each type of weight;

[0182] A second acquisition module 302 is configured to acquire classification features corresponding to each type of weight according to the at least one type of weight;

[0183] A first obtaining module 303 is configured to perform calculations based on the at least one type of weight and the feature data to obtain a first processing result corresponding to each type of weight;

[0184] The second obtaining module 304 is configured to perform calculation according to the classification feature and the first processing result to obtain a second processing result.

[0185] In other embodiments, the first acquisition module includes:

[0186] Get historical weights;

[0187] Filter the historical weights according to the set filtering conditions to obtain filtered weights;

[0188] The filtered weights are classified according to set classification rules to obtain the at least one category of weights.

[0189] In other embodiments, the first obtaining module includes:

[0190] Acquire classification data corresponding to the feature data according to the at least one type of weight and the classification feature;

[0191] The characteristic data is calculated according to the classification data to obtain a first processing result corresponding to each category weight.

[0192] In other embodiments, the second obtaining module includes:

[0193] Arrange the first processing results corresponding to each type of weight according to the set arrangement rule to obtain the first processing results after the arrangement;

[0194] Selecting one first processing result to be processed from the arranged first processing results in sequence according to the arrangement order;

[0195] Perform calculation according to the classification feature and the first processing result to be processed to obtain a first calculation result;

[0196] Calculate the currently obtained first calculation result and the already obtained first calculation result to obtain a second calculation result;

[0197] When it is determined that the second calculation result is a negative number, the second calculation result is used as a second processing result.

[0198] In other embodiments, the data processing device further includes:

[0199] After calculating according to the classification feature and the first processing result to obtain the second processing result, obtaining the first dimension of the feature data and the corresponding network dimension;

[0200] Obtaining a second dimension of the second processing result;

[0201] When it is determined that the second dimension is smaller than the first dimension, adjusting the current network dimension corresponding to the second processing result according to the network dimension and a predetermined threshold range;

[0202] Obtaining a weight corresponding to the second processing result;

[0203] Based on the current network dimension and the weight corresponding to the second processing result, the second processing result is calculated to obtain a third processing result.

[0204] In other embodiments, the data processing device further includes:

[0205] When it is determined that the second dimension is smaller than the first dimension, performing a modulo operation on the network dimension to be adjusted to obtain a modulo result;

[0206] Compare the modulo result and the network dimension to be adjusted to obtain a ratio result;

[0207] When the ratio result is within a predetermined threshold range, it is determined that the dimension to be adjusted is the current network dimension corresponding to the second processing result.

[0208] In other embodiments, the first obtaining module further includes:

[0209] Performing a left shift calculation on the feature data according to the classification data to obtain a first processing result corresponding to each category weight;

[0210] Correspondingly, the second obtaining module further includes:

[0211] A multiplication and addition calculation is performed according to the classification feature and the first processing result to obtain a second processing result.

[0212] Through the embodiment of the present invention, the data processing device first performs accumulation calculation on the feature data using the classification feature, and then performs multiplication operation based on the accumulation calculation result and the classification feature. This operation method of adding first and then multiplying can effectively reduce the amount of calculation.

[0213] Embodiment 4

[0214] Based on the same inventive concept of the first to third embodiments, the present invention provides a data processing device. Fig.16 FIG. 1 is a schematic diagram of the structure of a data processing device according to an embodiment of the present invention. Fig.16 As shown, the data processing device at least includes a processor 01, a memory 02 storing executable instructions of the processor 01, a communication interface 03, and a bus 04 for connecting the processor, the memory, and the communication interface. When the instructions are executed, the processor implements the following steps:

[0215] Obtain at least one type of weight and feature data corresponding to each type of weight;

[0216] According to the at least one type of weight, obtaining classification features corresponding to each type of weight;

[0217] Calculating according to the at least one type of weight and the characteristic data to obtain a first processing result corresponding to each type of weight;

[0218] Calculation is performed based on the classification feature and the first processing result to obtain a second processing result.

[0219] In an optional embodiment, the first processor is further configured to execute a data processing program stored in the first memory to implement the following steps:

[0220] Get historical weights;

[0221] Filter the historical weights according to the set filtering conditions to obtain filtered weights;

[0222] The filtered weights are classified according to set classification rules to obtain the at least one category of weights.

[0223] In an optional embodiment, the first processor is used to execute the data processing program stored in the first memory to implement the following steps:

[0224] Acquire classification data corresponding to the feature data according to the at least one type of weight and the classification feature;

[0225] The characteristic data is calculated according to the classification data to obtain a first processing result corresponding to each category weight.

[0226] In an optional embodiment, the first processor is used to execute the data processing program stored in the first memory to implement the following steps:

[0227] Arrange the first processing results corresponding to each type of weight according to the set arrangement rule to obtain the first processing results after the arrangement;

[0228] Selecting one first processing result to be processed from the arranged first processing results in sequence according to the arrangement order;

[0229] Perform calculation according to the classification feature and the first processing result to be processed to obtain a first calculation result;

[0230] Calculate the currently obtained first calculation result and the already obtained first calculation result to obtain a second calculation result;

[0231] When it is determined that the second calculation result is a negative number, the second calculation result is used as a second processing result.

[0232] In an optional embodiment, the first processor is further configured to execute a data processing program stored in the first memory to implement the following steps:

[0233] After calculating according to the classification feature and the first processing result to obtain the second processing result, obtaining the first dimension of the feature data and the corresponding network dimension;

[0234] Obtaining a second dimension of the second processing result;

[0235] When it is determined that the second dimension is smaller than the first dimension, adjusting the current network dimension corresponding to the second processing result according to the network dimension and a predetermined threshold range;

[0236] Obtaining a weight corresponding to the second processing result;

[0237] Based on the current network dimension and the weight corresponding to the second processing result, the second processing result is calculated to obtain a third processing result.

[0238] In an optional embodiment, the first processor is used to execute the data processing program stored in the first memory to implement the following steps:

[0239] When it is determined that the second dimension is smaller than the first dimension, performing a modulo operation on the network dimension to be adjusted to obtain a modulo result;

[0240] Compare the modulo result and the network dimension to be adjusted to obtain a ratio result;

[0241] When the ratio result is within a predetermined threshold range, it is determined that the dimension to be adjusted is the current network dimension corresponding to the second processing result.

[0242] In an optional embodiment, the first processor is used to execute the data processing program stored in the first memory to implement the following steps:

[0243] Performing a left shift calculation on the feature data according to the classification data to obtain a first processing result corresponding to each category weight;

[0244] A multiplication and addition calculation is performed according to the classification feature and the first processing result to obtain a second processing result.

[0245] Through the embodiment of the present invention, the data processing device first performs accumulation calculation on the feature data using the classification feature, and then performs multiplication operation based on the accumulation calculation result and the classification feature. This operation method of adding first and then multiplying can effectively reduce the amount of calculation.

[0246] In practical applications, the processor may be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP), or a field programmable gate array (FPGA).

[0247] In addition, each component in this embodiment may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software function modules.

[0248] If the integrated unit is implemented in the form of a software function module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment is essentially or the part that contributes to the prior art or the whole or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform all or part of the steps of the method described in this embodiment. The aforementioned storage medium includes: ferromagnetic random access memory (FRAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory,

[0249] The present invention does not limit the mediums that can store program codes, such as EEPROM, Flash Memory, magnetic surface memory, optical disk, or Compact Disc Read-Only Memory (CD-ROM).

[0250] Based on the foregoing embodiments, an embodiment of the present invention provides a computer-readable storage medium on which a data processing program is stored. When the data processing program is executed by a processor, the data processing method in one or more of the foregoing embodiments is implemented.

[0251] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of hardware embodiments, software embodiments, or embodiments combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.

[0252] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0253] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0254] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0255] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention.

Claims

1. A data processing method in a neural network, characterized in that: The method comprises: Obtain at least one type of weight and feature data corresponding to each type of weight, wherein the feature data is data to be convolved with the at least one type of weight; the at least one type of weight is classified based on one of the following set classification rules: weights with the same absolute value of positive and negative numbers are classified into one category, and then the weights of each type are classified according to the power of 2 multiplied by the common factor; weights with negative values ​​are classified into one category and weights with positive values ​​are classified into another category, and then the weights of each type are classified according to the power of 2 multiplied by the common factor; directly classified according to the power of 2 multiplied by the common factor; According to the at least one type of weight, obtaining classification features corresponding to each type of weight, wherein the classification features are the common factors; According to the at least one type of weight and the classification feature, obtaining classification data corresponding to the feature data, calculating the feature data according to the classification data, and obtaining a first processing result corresponding to each type of weight, wherein the classification data is a power of 2; Perform multiplication and addition calculations according to the classification feature and the first processing result to obtain a second processing result as a result of a convolution operation of the at least one type of weight and the feature data; Before performing multiplication and addition calculation according to the classification feature and the first processing result, it includes: completing the routing selection of multiple CP operation units to a multiplier through a multiplier queue.

2. The method according to claim 1, characterized in that Before obtaining at least one type of weight, the method further includes: Get historical weights; Filter the historical weights according to the set filtering conditions to obtain filtered weights; The filtered weights are classified according to set classification rules to obtain the at least one category of weights.

3. The method according to claim 2, characterized in that: The step of calculating according to the classification feature and the first processing result to obtain a second processing result as a result of a convolution operation of the at least one type of weight and the feature data includes: Arrange the first processing results corresponding to each type of weight according to the set arrangement rule to obtain the first processing results after the arrangement; Selecting one first processing result to be processed from the first processing results after the arrangement order in sequence according to the arrangement order; Perform calculation according to the classification feature and the first processing result to be processed to obtain a first calculation result; Calculate the currently obtained first calculation result and the already obtained first calculation result to obtain a second calculation result; When it is determined that the second calculation result is a negative number, the second calculation result is used as a second processing result.

4. The method according to claim 1, characterized in that: After performing calculation according to the classification feature and the first processing result to obtain a second processing result as a result of the convolution operation of the at least one type of weight and the feature data, the method further includes: Obtaining a first dimension of the feature data and a corresponding network dimension; Obtaining a second dimension of the second processing result; When it is determined that the second dimension is smaller than the first dimension, adjusting the current network dimension corresponding to the second processing result according to the network dimension and a predetermined threshold range; Obtaining a weight corresponding to the second processing result; Based on the current network dimension and the weight corresponding to the second processing result, the second processing result is calculated to obtain a third processing result.

5. The method according to claim 4, characterized in that When it is determined that the second dimension is smaller than the first dimension, adjusting the current network dimension corresponding to the second processing result according to the network dimension and a predetermined threshold range includes: When it is determined that the second dimension is smaller than the first dimension, performing a modulo operation on the network dimension to be adjusted to obtain a modulo result; Compare the modulo result and the network dimension to be adjusted to obtain a ratio result; When the ratio result is within a predetermined threshold range, it is determined that the network dimension to be adjusted is the current network dimension corresponding to the second processing result.

6. The method according to claim 1, characterized in that The calculating the characteristic data according to the classification data to obtain the first processing result corresponding to each type of weight includes: Performing a left shift calculation on the feature data according to the classification data to obtain a first processing result corresponding to each category weight; Correspondingly, the calculating according to the classification feature and the first processing result to obtain the second processing result includes: A multiplication and addition calculation is performed according to the classification feature and the first processing result to obtain a second processing result as a result of a convolution operation of the at least one type of weight and the feature data.

7. A data processing device in a neural network, characterized in that: A first acquisition module is configured to acquire at least one type of weight and feature data corresponding to each type of weight, wherein the feature data is data to be convolved with the at least one type of weight; the at least one type of weight is classified based on one of the following set classification rules: weights with the same absolute value of positive and negative numbers are classified into one category, and then the weights of each type are classified according to the power of 2 multiplied by the common factor; weights with negative values ​​are classified into one category and weights with positive values ​​are classified into another category, and then the weights of each type are classified according to the power of 2 multiplied by the common factor; classification is performed directly according to the power of 2 multiplied by the common factor; A second acquisition module is configured to acquire classification features corresponding to each type of weight according to the at least one type of weight, wherein the classification feature is the common factor; According to the at least one type of weight and the classification feature, obtaining classification data corresponding to the feature data, calculating the feature data according to the classification data, and obtaining a first processing result corresponding to each type of weight, wherein the classification data is a power of 2; The second obtaining module is configured to perform multiplication and addition calculations based on the classification features and the first processing results to obtain a second processing result as a result of the convolution operation of the at least one type of weight and the feature data; wherein the second obtaining module is also used to complete the routing selection of multiple CP operation units to a multiplier through a multiplier queue.

8. A data processing device in a neural network, wherein: The data processing device includes at least a processor, a memory storing instructions executable by the processor, and a bus for connecting the processor and the memory. When the instructions are executed, the processor implements the method according to any one of claims 1 to 6.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Method and device for adapting neural network

    CN107633295A

  • Neural network model weight quantification method and device

    CN107895190A