CNN acceleration method and accelerator
By optimizing the CNN acceleration method and simplifying the control logic and data read/write process, the complexity and scalability issues of existing CNN accelerators are resolved, achieving efficient data processing and easy scalability.
Patent Information
- Application Number
- CN202010784854.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2020-06-02
- Filing Date
- 2020-08-06
- Publication Date
- 2026-02-27
- Estimated Expiration
- 2040-08-06
AI Technical Summary
Existing CNN accelerators suffer from problems such as complex control, repetitive read/write operations, and poor scalability.
By reading the initial input data sequentially, the first feature vector group is obtained. The convolution kernel is multiplied and accumulated with the first feature vector group to obtain the second feature vector group. Then, partial sums are accumulated, and finally, classification is performed, thus optimizing the data reading and writing process and control logic.
It achieves simple control, data read/write is friendly to external DDR, there are no read/write efficiency issues, it is easy to expand, adapts to high computing power requirements, and improves the use of interface-side data read clock and multi-bank mode.
Smart Images

Figure CN111898743B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of convolutional neural network, and particularly relates to a CNN acceleration method and accelerator. BACKGROUND
[0002] The convolutional neural network (CNN) is a kind of feedforward neural network containing convolution calculation and having a deep structure, and is one of the representative algorithms of deep learning. The artificial neuron thereof can respond to surrounding units in a part of coverage, and has excellent performance for large image processing.
[0003] In the existing CNN accelerator or algorithm, there are problems such as complex control, repeated read-write operation, certain limitations, and poor expansibility. Therefore, the present application optimizes the existing technical solution. SUMMARY
[0004] One of the purposes of the present application is to provide a CNN acceleration method and accelerator, which solves the technical problems of complex control, repeated read-write, and poor expansibility of the CNN in the prior art. The preferred embodiment of the present application can achieve many beneficial effects, which are described below.
[0005] To achieve the above-mentioned purpose, the present application provides the following technical solutions:
[0006] The CNN acceleration method of the present application comprises:
[0007] initial data is inputted, and the initial data is read in order to obtain a first feature vector group; wherein the initial data is scanned in order from a channel direction, a horizontal direction and a vertical direction to obtain the first feature vector group;
[0008] The convolution kernel is multiplied and accumulated with the first feature vector group to obtain a second feature vector group; specifically comprising:
[0009]
[0010] Wherein, ofm_t represents the second feature vector group; ifm represents the first feature vector group; kernel represents the convolution kernel;
[0011] h1 represents the vertical direction index of the second feature vector group, h represents the vertical direction index of the first feature vector group, and H represents the maximum value of the vertical direction index of the first feature vector group;
[0012] w1 represents the horizontal direction index of the second feature vector group, w represents the horizontal direction index of the first feature vector group, and W represents the maximum value of the horizontal direction index of the first feature vector group;
[0013] m1 represents the channel direction index of the second feature vector group, m represents the group number index of the kernel convolution kernel, and M represents the channel direction index maximum value of the first feature vector group;
[0014] i represents the vertical direction index of the convolution kernel, H K represents the vertical direction index maximum value of the convolution kernel;
[0015] j represents the horizontal direction index of the convolution kernel, W K represents the horizontal direction index maximum value of the convolution kernel;
[0016] k represents the channel direction index of the convolution kernel, C K represents the channel direction index maximum value of the convolution kernel;
[0017] i1 represents the row index of the second feature vector group, and j1 represents the column index of the second feature vector group;
[0018] The second feature vector group is accumulated by partial sum to obtain a third feature vector group; specifically comprising:
[0019] The second feature vector group is accumulated by partial sum to obtain a third feature vector group; then the expression formula is as follows:
[0020]
[0021] ofm_F represents the third feature vector group, and ofm_t represents the second feature vector group;
[0022] h2 represents the vertical direction index of the third feature vector group, h1 represents the vertical direction index of the second feature vector group, and H1 represents the vertical direction index maximum value of the second feature vector group;
[0023] w2 represents the horizontal direction index of the third feature vector group, w1 represents the horizontal direction index of the second feature vector group, and W1 represents the horizontal direction index maximum value of the second feature vector group;
[0024] m2 represents the channel direction index of the third feature vector group, m1 represents the channel direction index of the second feature vector group, and M1 represents the channel direction index maximum value of the second feature vector group;
[0025] H K1 represents the maximum value in the row direction of the second feature vector group, W K1 represents the maximum value in the column direction of the second feature vector group;
[0026] s represents the windowing step, which is set according to actual requirements;
[0027] The accumulating of the partial sum of the second feature vector group obtains a third feature vector group, and further comprises:
[0028] The partial sum of one window in the row direction is saved in a register.
[0029] The partial sum of all windows in the row direction is saved in an on-chip RAM.
[0030] The third feature vector group is classified to obtain a classification result, and specifically comprises:
[0031] The third feature vector group is brought into a softmax() function for classification processing to obtain the classification result.
[0032] Further, the multiplying and accumulating calculation of the convolution kernel and the first feature vector group to obtain the second feature vector group comprises:
[0033] The convolution kernel is a constant vector.
[0034] Further, the multiplying and accumulating calculation of the convolution kernel and the first feature vector group to obtain the second feature vector group comprises:
[0035] The convolution kernel is a plurality of.
[0036] The application further comprises a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is executed to perform the CNN acceleration method as described above.
[0037] The application further comprises a CNN accelerator, which comprises a processor and a memory connected to the processor, and the memory stores a computer program, and when the computer program is executed by the processor, the CNN acceleration method as described above is performed.
[0038] The CNN acceleration method and the accelerator provided by the application have at least the following beneficial technical effects:
[0039] The overall control of the application is simple, and only needs to scan the initial data in the order of the channel direction, the horizontal direction and the vertical direction in the input layer, without any complex control, such as windowing (s=1, s=2, etc.); and the feature vector of the initial data is read once, and the feature vector of the output layer is output on the corresponding channel, without any redundant read-write operation. The data reading and writing of the application is very friendly to the off-chip DDR, and there is no problem of reading and writing efficiency. The application is easy to expand, and for high computing power requirements, the data reading clock on the interface side can be improved, or a multi-bank mode is adopted; and each port is completely independent of each other without any dependence. BRIEF DESCRIPTION OF DRAWINGS
[0040] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description only constitute some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor on the basis of these drawings.
[0041] Figure 1 is a flowchart of a CNN acceleration method of the present application;
[0042] Figure 2 is a structural diagram of obtaining a second feature vector group of the present application;
[0043] Figure 3 is a structural diagram of obtaining a first feature vector group of the present application;
[0044] Figure 4 is a structural diagram of a convolution kernel of the present application;
[0045] Figure 5 is a structural diagram of accumulating a part sum of the present application;
[0046] Figure 6 is a structural diagram of a CNN accelerator of the present application.
[0047] In the figure, 1 is a processor; 2 is a memory. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical solutions and advantages of the present application more clear, the various exemplary embodiments to be described below will be described with reference to the corresponding drawings, which constitute a part of the exemplary embodiments, and various exemplary embodiments that can be used to implement the present application are described, and the same numerals in different drawings represent the same or similar elements, unless otherwise indicated. The implementation described in the following exemplary embodiments does not represent all the implementations consistent with the present disclosure. It should be understood that they are only examples of devices and methods consistent with some aspects of the present disclosure as described in the appended claims, and other embodiments can also be used, or structural and functional modifications can be made to the embodiments listed herein, without departing from the scope and spirit of the present application. In other cases, detailed descriptions of well-known systems, devices, circuits and methods are omitted to avoid unnecessary details that hinder the description of the present application.
[0049] Referring to Figure 1 , the present application provides a CNN acceleration method embodiment, which comprises:
[0050] S1: input initial data, read the initial data in order to obtain a first feature vector group;
[0051] S2: multiply and accumulate the convolution kernel with the first feature vector group to obtain a second feature vector group;
[0052] S3: accumulate the second feature vector group by partial sum to obtain a third feature vector group;
[0053] S4: classify the third feature vector group to obtain a classification result.
[0054] It should be noted that the CNN itself includes three layers, which are an input layer, a convolution layer and an output layer connected in turn. The initial data is input in the input layer, the initial data is read in order to obtain the first feature vector group and sent to the convolution layer, wherein the initial data is preferably a picture. In the convolution layer, the convolution kernel is multiplied and accumulated with the first feature vector group to obtain the second feature vector group, and then the second feature vector group is accumulated by partial sum to obtain the third feature vector group and sent to the output layer; then, the third feature vector group is classified to obtain a classification result. Among them, the final classification result can distinguish various objects on the picture, such as cats, dogs, people, flowers, birds, etc.
[0055] The application proposes a CNN acceleration method based on vector-vector, and then a partial sum accumulation implementation method. The implementation process of the partial sum is to accumulate the contribution of the result obtained from each vector-vector of the input feature vector group to the final output feature vector group result on the channel, which is different from the partial sum of other schemes. Therefore, the application is optimal in read-write DDR efficiency, internal control logic, energy consumption and computing power scalability.
[0056] For details Figure 3 , S1: input initial data, read the initial data in order to obtain a first feature vector group, including:
[0057] The initial data is scanned in the channel direction, the horizontal direction and the vertical direction in turn to obtain the first feature vector group.
[0058] It should be noted that the initial data (corresponding to the feature map in the figure) is scanned in the channel direction first (corresponding to the C direction of the coordinate system in the figure), the horizontal direction second (corresponding to the W direction of the coordinate system in the figure), and the vertical direction (corresponding to the V direction of the coordinate system in the figure). Figure 3 Figure 3 Figure 3 The first feature vector group is obtained by scanning in turn according to the last order of the H direction of the middle coordinate system. That is, the feature vector of each sub-data in the initial data is scanned in turn according to the order from top to bottom and from left to right, and the feature vector of each sub-data is collected to form the first feature vector group. For example, the initial data is a picture, the information of each point on the picture is read in turn according to the order from top to bottom and from left to right, and the information of each point in all channel directions forms a feature vector, and a plurality of different feature vectors are obtained by traversing the entire picture. That is, the picture is scanned according to the direction of CWH in turn, and the first feature vector group composed of single feature vectors in different coordinates is obtained.
[0059] The feature vector is scanned from H=0 first:
[0060] Vector 0 includes the following feature vectors: H0W0C0, H0W0C1, H0W0C2,..., H0W0Cn-1.
[0061] Vector 1 includes the following feature vectors: H0W1C0, H0W1C1, H0W1C2,..., H0W1Cn-1.
[0062] Vectors 2, 3, 4,..., and n-1 are scanned in turn, and include the following feature vectors: H0Wn-1C0, H0Wn-1C1,..., H0Wn-1Cn-1.
[0063] The feature vector is scanned from H=1 again:
[0064] Vector 0 includes the following feature vectors: H1W0C0, H1W0C1, H1W0C2,..., H1W0Cn-1.
[0065] Vector 1 includes the following feature vectors: H1W1C0, H1W1C1, H1W1C2,..., H1W1Cn-1.
[0066] Vectors 2, 3, 4,..., and n-1 are scanned in turn, and include the following feature vectors: H1Wn-1C0, H1Wn-1C1,..., H1Wn-1Cn-1.
[0067] Then, the feature vector is continuously scanned according to H=2, 3,..., n-1 in turn to obtain the complete first feature vector group.
[0068] The present application only needs to scan each feature vector included in the initial data in the order of the channel direction, the horizontal direction and the vertical direction in the input layer, without any complex control, and has the characteristics of simple control.
[0069] For details, see Figure 2 andFigure 4 , S2: multiply and accumulate the convolution kernel with the first feature vector group to obtain a second feature vector group, comprising:
[0070] The convolution kernel is a constant vector; the convolution kernel is multiple.
[0071] It should be noted that the convolution kernel is a constant vector trained from public massive data. For example, the convolution kernel can be extracted from the public deep learning model Mobile-net-yolov3 trained from the public massive image library (ImageNet).
[0072] As shown in Figure 4 , a convolution kernel (taking kernel_group0 in Figure 4 as an example) itself is also a vector group, and the vectors in the convolution kernel are read in turn according to the order of channel direction (C direction) first, horizontal direction (W direction) second, and vertical direction (H direction) last.
[0073] Still taking the kernel_group0 convolution kernel in Figure 4 as an example, scanning according to the CWH direction obtains the following vector group:
[0074] When H is 0 first,
[0075] Vector 0 includes: H0W0C0, H0W0C1,..., H0W0Cn-1,
[0076] Vector 1 includes: H0W1C0, H0W1C1,..., H0W1Cn-1,...
[0077] Vectors 2, 3, 4,..., n-1 are scanned in turn, and vector group n-1 includes: H0Wn-1C0, H0Wn-1C1,..., H0Wn-1Cn-1; then H is 1, 2, 3,..., n-1 respectively, and vectors 0, 1,..., n-1 are scanned in turn, wherein vectors 0, 1,..., n-1 are scanned in the order of C from 0 to n-1, to obtain a vector group of a convolution kernel.
[0078] The convolution kernel of the application is multiple, so it is assumed that the convolution kernel in the application has M, and the convolution kernel is kernel_group0, kernel_group1, kernel_group2,..., kernel_groupM-1.
[0079] As shown in Figure 2 , after the convolution kernel is multiplied and accumulated with the first feature vector group, a second feature vector group is obtained, and is sent to a register.
[0080] S2: multiply and accumulate the convolution kernel and the first feature vector group to obtain a second feature vector group, specifically comprising:
[0081]
[0082] Simplify the expression as:
[0083]
[0084] Where ofm_t represents the second feature vector group; ifm represents the first feature vector group; kernel represents the convolution kernel;
[0085] h1 represents the vertical direction index of the second feature vector group, h represents the vertical direction index of the first feature vector group, and H represents the maximum value of the vertical direction index of the first feature vector group;
[0086] w1 represents the horizontal direction index of the second feature vector group, w represents the horizontal direction index of the first feature vector group, and W represents the maximum value of the horizontal direction index of the first feature vector group;
[0087] m1 represents the channel direction index of the second feature vector group, m represents the group number index of the kernel convolution kernel, and M represents the maximum value of the channel direction index of the first feature vector group, wherein m is equal to the group number index of the kernel convolution kernel;
[0088] i represents the vertical direction index of the convolution kernel, H K represents the maximum value of the vertical direction index of the convolution kernel;
[0089] j represents the horizontal direction index of the convolution kernel, W K represents the maximum value of the horizontal direction index of the convolution kernel;
[0090] k represents the channel direction index of the convolution kernel, C K represents the maximum value of the channel direction index of the convolution kernel; wherein the channel direction index of the convolution kernel is equal to the channel direction index of the first feature vector group;
[0091] i1 represents the row index of the second feature vector group, and j1 represents the column index of the second feature vector group.
[0092] The specific algorithm is:
[0093]
[0094]
[0095] Where, ofm_t represents the feature vector of the second feature vector group of the present invention, ifm represents the feature vector of the first feature vector group of the present invention, kernel represents the convolution kernel, h represents the vertical direction index of the second feature vector group, w represents the horizontal direction index of the second feature vector group, m represents the channel direction index of the second feature vector group, and m is equal to the group number index of the kernel convolution kernel; i represents the vertical direction index of the kernel, j represents the horizontal direction index of the kernel, k represents the channel direction index of the kernel, and k is equal to the channel direction index of the first feature vector group.
[0096] It should be noted that, compared to the standard convolution formula, ofm_t represents the partial sum of the output feature vector group (ofm). Compared to the final ofm, there are i*j additional partial sums here, which is the size of the convolution kernel w*h. From the above formula, it can also be seen that ifm here does not require skipping addresses; it only needs to be read sequentially. The standard convolution formula is as follows:
[0097]
[0098] Where ofm represents the output feature vector group, ifm represents the first feature vector group (also known as the input feature vector group); kernel represents the convolution kernel;
[0099] h0 represents the vertical index of the output feature vector group, h represents the vertical index of the input feature vector group, and H represents the maximum value of the vertical index of the input feature vector group.
[0100] w0 represents the horizontal index of the output feature vector group, w represents the horizontal index of the input feature vector group, and W represents the maximum value of the horizontal index of the input feature vector group.
[0101] m0 represents the channel direction index of the output feature vector group, m represents the group number index of the kernel convolution kernel, and M represents the maximum value of the channel direction index of the input feature vector group.
[0102] i represents the vertical index of the kernel, H K This represents the maximum vertical index value of the convolution kernel;
[0103] j represents the horizontal index of the kernel, W K This represents the maximum horizontal index of the convolution kernel;
[0104] k represents the kernel channel direction index, C K This represents the maximum value of the channel direction index of the convolution kernel; where k is the same as the channel direction index of the input feature vector group.
[0105] 's' indicates the window swiping step.
[0106] The specific algorithm is:
[0107]
[0108]
[0109] wherein ofm represents an output feature map, ifm represents an input feature map, kernel represents a convolution kernel, h represents a vertical direction index of the output feature map, w represents a horizontal direction index of the output feature map, m represents a channel direction index of the output feature map, m herein is equal to a group index of the kernel convolution kernel; i represents a vertical direction index of the kernel, j represents a horizontal direction index of the kernel, k represents a channel direction index of the kernel, k is equal to a channel direction index of the input feature map, and s represents a window step.
[0110] S3: performing partial sum accumulation on the second feature vector group to obtain a third feature vector group, comprising:
[0111] The second feature vector group is shifted and accumulated to obtain the third feature vector group; and the expression formula is as follows:
[0112]
[0113] The simplified expression is:
[0114] wherein ofm_F represents the third feature vector group, and ofm_t represents the second feature vector group.
[0115] h2 represents a vertical direction index of the third feature vector group, h1 represents a vertical direction index of the second feature vector group, and H1 represents a maximum value of the vertical direction index of the second feature vector group.
[0116] w2 represents a horizontal direction index of the third feature vector group, w1 represents a horizontal direction index of the second feature vector group, and W1 represents a maximum value of the horizontal direction index of the second feature vector group.
[0117] m2 represents a channel index of the third feature vector group, m1 represents a channel direction index of the second feature vector group, and M1 represents a maximum value of the channel direction index of the second feature vector group.
[0118] H K1 represents a maximum value in a row direction of the second feature vector group, W K1 represents a maximum value in a column direction of the second feature vector group.
[0119] s represents the window step, which is set according to actual requirements.
[0120] The specific algorithm is as follows:
[0121]
[0122] For example, s = 1, m = 0, kernel (w = h = 3), and the shift and accumulation process of step S3 is specifically shown in the following table:
[0123] ofm_F[0][0][0] = ofm_t[0][0][0][0][0] + ofm_t[0][1][0][0][1] + ofm_t[0][2][0][0][2] + ofm_t[1][0][0][1][0] + ofm_t[1][1][0][1][1] + ofm_t[1][2][0][1][2] + ofm_t[2][0][0][2][0] + ofm_t[2][1][0][2][1] + ofm_t[2][2][0][2][2]
[0124]
[0125]
[0126] The above table is a specific decomposition process of how to obtain the final result ofm_F from the partial sum ofm_t. The first column on the left represents the row index of ofm_t, the second column is the index of each point on each row (00 represents the 0th point on the 0th row, 01 represents the 1st point on the 0th row, and so on), and the third column to the eleventh column are the partial sums (that is, the results of vector * vector) obtained by multiplying and accumulating the input first feature vector group with each feature vector of the convolution kernel.
[0127] To obtain the final result ofm_F, that is, the last column, only the vector * vector results with the same background are accumulated. Obviously, the accumulation here is divided into partial sum accumulation within a row and partial sum accumulation between rows. There are 3 blocks with the same background in each row that need to be added up, and there are 3 rows in total, so a total of 9 blocks with the same background need to be added up (accumulation along the diagonal). In this way, the final ofm_F is obtained.
[0128] Therefore, as shown in the above table, in combination with Figure 5 The partial sum accumulation process of the second feature vector group also includes two steps:
[0129] S31: Save the partial sum of one window in the row direction to the register;
[0130] S32: save all windowed partial sums in the row direction to on-chip RAM.
[0131] It should be noted that if the on-chip RAM storage is not enough, all windowed partial sums in the row direction can be exported to off-chip.
[0132] The application performs multiplication and accumulation calculation and partial sum accumulation calculation based on initial data and convolution kernel, achieves friendly data read and write to off-chip DDR, and does not have read and write efficiency problems; it is easy to expand, can improve the interface side read data clock for high algorithm requirement, or adopts a multi-bank mode; each port is completely independent of each other and has no any dependence.
[0133] S4: classify the third feature vector group to obtain a classification result, and the specific implementation process is as follows:
[0134] The third feature vector group is brought into a softmax() function to classify and obtain a result.
[0135] Softmax() function: V i is an element in the i-th feature vector in the third feature vector group, V j is an element in the j-th feature vector in the third feature vector group, j represents the number of feature vectors in the third feature vector group, S i is a picture classification probability.
[0136] It should be noted that the final result S i is in the same range or the same value, and the picture is classified into one class. For example, if the probability range of a picture class is 0.3-0.5, and Si is 0.4, the picture belongs to this picture class. Therefore, the final result is to classify the input picture.
[0137] The application also provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is executed to perform the CNN acceleration method described above.
[0138] Referring to Figure 6 The application also includes a CNN accelerator, which includes a processor and a memory connected to the processor, and the memory stores a computer program, and when the computer program is executed by the processor, the CNN acceleration method described above is performed.
[0139] It should be noted that the processor itself includes a register, and the memory includes a RAM. Therefore, the application optimizes the CNN algorithm and improves the performance efficiency on the hardware.
[0140] After reading the foregoing description, those skilled in the art should understand that various features described herein can be implemented by a method, a data processing system or a computer program product. Therefore, these features can be implemented in a hardware manner, in a software manner or in a combination of hardware and software. In addition, the above features can also be in the form of a computer program product stored on one or more computer readable storage media, which contains computer readable program code segments or instructions stored in the storage medium. The readable storage medium is configured to store various types of data to support the operation of the device. The readable storage medium can be realized by any type of volatile or non-volatile storage device or their combination. Such as hard disk, static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), optical storage device, magnetic storage device, flash memory, magnetic disk or optical disk, and / or combination of the above devices.
[0141] Specific application methods of the present application are as follows:
[0142] First, the garbage classification application method of the present application:
[0143] The garbage classification result is 5 categories: plastic bottles, books, paper boxes, waste batteries and kitchen waste. A picture is input into the present application, scanned according to the CWH order direction, and a first feature vector group is obtained. Two convolution kernels of 7*7*16 and 6*6*32 are multiplied and accumulated with the first feature vector group to obtain a second feature vector group, which is the calculation of formula 1. Then the second feature vector group is partially summed (the calculation of formula 2) to obtain a third feature vector group. The third feature vector group is classified by the softmax() function to obtain a probability value, which is mapped to the corresponding garbage classification.
[0144] Second, the license plate recognition application method of the present application:
[0145] The license plate number in China involves 31 provinces of Chinese characters, 26 letters and 10 digits. After the license plate picture is obtained by the camera and other acquisition devices, it is input into the present application. The license plate picture is scanned according to the CWH order direction to obtain a first feature vector group. The first feature vector group is multiplied and accumulated with the convolution kernel to obtain a second feature vector group, which is the calculation of formula 1. Then the second feature vector group is partially summed (the calculation of formula 2) to obtain a third feature vector group. The third feature vector group is classified by the softmax() function to obtain a probability value, which is mapped to the corresponding Chinese characters, letters and numbers to form a clear license plate number, which is convenient for traffic police to perform subsequent work.
[0146] The above merely provides preferred embodiments of the present application, and those skilled in the art know that various changes or equivalent replacements can be made to the features and embodiments without departing from the spirit and scope of the present application. In addition, the features and embodiments can be modified to adapt to specific conditions and materials under the teaching of the present application without departing from the spirit and scope of the present application. Therefore, the present application is not limited to the specific embodiments disclosed herein, and all embodiments falling within the scope of the claims of the present application belong to the protection scope of the present application.
Claims
1. A CNN acceleration method, characterized in that, The CNN comprises an input layer, a convolution layer and an output layer connected in sequence; and the method comprises: The initial data is input through the input layer, and the initial data is sequentially read to obtain a first feature vector group; wherein the initial data is sequentially scanned from a channel direction, a horizontal direction and a vertical direction to obtain the first feature vector group, and the initial data is a picture; The convolution kernel is multiplied with the first feature vector group to obtain a second feature vector group through the convolution layer; specifically comprising: Wherein, ofm_t represents the second feature vector group; ifm represents the first feature vector group; kernel represents the convolution kernel; h1 represents the vertical direction index of the second feature vector group, h represents the vertical direction index of the first feature vector group, and H represents the maximum value of the vertical direction index of the first feature vector group; w1 represents the horizontal direction index of the second feature vector group, w represents the horizontal direction index of the first feature vector group, and W represents the maximum value of the horizontal direction index of the first feature vector group; m1 represents the channel direction index of the second feature vector group, m represents the group number index of the kernel convolution kernel, and M represents the maximum value of the channel direction index of the first feature vector group; i denotes a vertical direction index of the convolution kernel, H K denotes a maximum value of the vertical direction index of the convolution kernel; j denotes the horizontal direction index of the convolution kernel, W K denotes the maximum value of the horizontal direction index of the convolution kernel; k denotes a channel direction index of the convolution kernel, C K denotes a maximum value of the channel direction index of the convolution kernel; i1 represents the row index of the second feature vector group, and j1 represents the column index of the second feature vector group; The second feature vector group is accumulated in a partial sum to obtain a third feature vector group; specifically comprising: The second feature vector group is accumulated in a partial sum to obtain a third feature vector group; then the expression formula is as follows: Wherein, ofm_F represents the third feature vector group, and ofm_t represents the second feature vector group; h2 represents the vertical direction index of the third feature vector group, h1 represents the vertical direction index of the second feature vector group, and H1 represents the maximum value of the vertical direction index of the second feature vector group; w2 represents the horizontal direction index of the third feature vector group, w1 represents the horizontal direction index of the second feature vector group, and W1 represents the maximum value of the horizontal direction index of the second feature vector group; m2 represents the channel direction index of the third feature vector group, m1 represents the channel direction index of the second feature vector group, and M1 represents the maximum value of the channel direction index of the second feature vector group; H K1 denotes the maximum value in the row direction of the second eigenvector group, W K1 denotes the maximum value in the column direction of the second eigenvector group; S represents a window step, which is set according to actual requirements; The second feature vector group is accumulated in a partial sum to obtain a third feature vector group, and further comprising: The partial sum of one window in the row direction is saved in a register; The partial sum of all windows in the row direction is saved in an on-chip RAM; The third feature vector group is classified through the output layer to obtain a classification result; specifically comprising: The third feature vector group is brought into a softmax() function for classification processing to obtain the classification result.
2. The CNN acceleration method of claim 1, wherein, The convolution kernel is multiplied with the first feature vector group to obtain a second feature vector group, comprising: The convolution kernel is a constant vector.
3. The CNN acceleration method of claim 2, wherein, The convolution kernel is multiplied with the first feature vector group to obtain a second feature vector group, comprising: The convolution kernel is a plurality of.
4. A computer readable storage medium, characterized in that, The storage medium has a computer program stored thereon, and the computer program is executed to perform the CNN acceleration method according to any one of claims 1-3.
5. A CNN accelerator, comprising: Comprising: A processor, and a memory connected to the processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the CNN acceleration method according to any one of claims 1-3 is executed.
Citation Information
Patent Citations
Hardware Accelerator for Convolutional Neural Networks and Method of Operation Thereof
US20180341495A1
Processing element, apparatus and method used for implementing convolution operation
WO2020087742A1