WO2020103653A1 - 一种全连接层的实现方法、装置、电子设备及计算机可读存储介质 - Google Patents

一种全连接层的实现方法、装置、电子设备及计算机可读存储介质

Info

Publication number
WO2020103653A1
WO2020103653A1 PCT/CN2019/114085 CN2019114085W WO2020103653A1 WO 2020103653 A1 WO2020103653 A1 WO 2020103653A1 CN 2019114085 W CN2019114085 W CN 2019114085W WO 2020103653 A1 WO2020103653 A1 WO 2020103653A1
Authority
WO
WIPO (PCT)
Prior art keywords
feature
input
components
data processing
output
Prior art date
Application number
PCT/CN2019/114085
Other languages
English (en)
French (fr)
Other versions
WO2020103653A9 (zh
Inventor
李炜
曹庆新
Original Assignee
深圳云天励飞技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳云天励飞技术有限公司 filed Critical 深圳云天励飞技术有限公司
Publication of WO2020103653A1 publication Critical patent/WO2020103653A1/zh
Publication of WO2020103653A9 publication Critical patent/WO2020103653A9/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • This application relates to the field of neural networks, and in particular, to a method, device, electronic device, and computer-readable storage medium for implementing a fully connected layer.
  • CNN convolutional neural networks
  • FC Fully connected
  • Embodiments of the present application provide a method, an apparatus, a device, and a computer-readable storage medium for implementing a fully connected layer, which can implement multiplexing of FC layer weight coefficients and improve MAC utilization in a neural network.
  • the first aspect of the present application provides a method for implementing a fully connected layer, including:
  • each input feature of the plurality of input features including a plurality of first feature components
  • the output features corresponding to each input feature are determined in parallel .
  • a second aspect of the present application provides a device for implementing a fully connected layer, including:
  • an acquisition module configured to acquire multiple input features for a fully connected layer, each of the multiple input features including multiple first feature components
  • a transmission module configured to simultaneously input the plurality of input features to a plurality of data processing units corresponding to the fully connected layer when the total number of the acquired plurality of input features reaches a first preset threshold ;
  • the acquiring module is further configured to acquire a weight coefficient of each first feature component of the plurality of first feature components in the output feature of the fully connected layer;
  • a processing module includes a plurality of data processing units corresponding to the fully connected layer, for the plurality of first feature components and the weighting coefficients corresponding to the plurality of first feature components to be determined in parallel The output feature corresponding to each input feature.
  • a third aspect of the embodiments of the present application provides an electronic device, including: a processor, a memory, a communication interface, and a bus;
  • the processor, the memory, and the communication interface are connected through the bus and communicate with each other;
  • the memory stores executable program code
  • the processor runs the program corresponding to the executable program code by reading the executable program code stored in the memory, for performing a full connection disclosed in the first aspect of the embodiments of the present application Layer implementation method.
  • a fourth aspect of the present application provides a storage medium, wherein the storage medium is used to store an application program
  • the application program is used to execute a method for implementing a fully connected layer disclosed in the first aspect of the embodiments of the present application at runtime.
  • the output features corresponding to multiple input features can be determined in parallel in multiple data processing units, and the calculation of the FC layer of multiple input features can be completed under the premise of reading the weight coefficient only once, compared with the existing In the technology, the method of reading the weight coefficient is required for each calculation of an input feature in the FC layer.
  • the method provided in the embodiment of the present application implements multiplexing of the weight coefficient.
  • the selection of the first preset threshold corresponding to the total number of input features may be based on the number of data processing units corresponding to the FC layer, so that each data processing unit undertakes calculation of at least one input feature of the FC layer to avoid data
  • the fact that the processing unit is idle increases the utilization rate of the MAC.
  • FIG. 1 is a schematic structural diagram of a neural network processor provided by an embodiment of the present application.
  • FIG. 2 is a schematic flowchart of a method for implementing a fully connected layer according to an embodiment of the present application
  • FIG. 3 is a schematic diagram of an input feature provided by an embodiment of the present application.
  • FIG. 4 is a schematic diagram of writing input features to a PE provided by an embodiment of the present application.
  • FIG. 5 is a schematic diagram of an output feature provided by an embodiment of the present application.
  • FIG. 6 is a schematic flowchart of another method for implementing a fully connected layer according to an embodiment of the present application.
  • FIG. 7 is a schematic diagram of writing input features to a PE provided by an embodiment of the present application.
  • FIG. 8 is a schematic diagram of another output feature provided by an embodiment of the present application.
  • FIG. 9 is a schematic structural diagram of a device for implementing a fully connected layer according to an embodiment of the present application.
  • FIG. 10 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
  • FIG. 1 is a schematic structural diagram of a neural network processor according to an embodiment of the present application.
  • the neural network processor in the embodiment of the present application includes a data memory, a data reading unit, a weight memory, a data return unit, and multiple data processing units (Processing Element, PE).
  • each PE may include an input data buffer, a convolution operation unit, and an output data buffer.
  • the data memory is used to store the input feature map generated by each layer in the neural network calculation process, thereby integrating the input features into the output feature map;
  • the data reading unit is used to read the data feature in the data memory Input features, and send the input features into the input data cache of the corresponding PE;
  • the weight storage is used to store the weight coefficients required by each layer in the calculation process of the neural network, or it can be a weight matrix; Store the output features in the output data buffer into the data memory.
  • PE is used to complete the calculation of the FC layer, where the convolution operation unit is used to read the input features in the input data cache, and perform the FC layer operation or other convolution operations, and the output data cache is used to store the convolution operation unit calculation Output characteristics.
  • FIG. 2 is a schematic flowchart of an implementation method of a fully connected layer provided by an embodiment of the present application. As shown in the figure, the method in the embodiment of the present application includes:
  • S201 Acquire multiple input features for a fully connected layer, where each input feature of the multiple input features includes multiple first feature components.
  • the CNN includes a convolutional layer, a pooling layer, and a fully connected layer.
  • the fully connected layer can integrate a large number of image features obtained after the processing of the convolutional layer and the pooling layer to facilitate subsequent classification or other processing of the image. Therefore, the input features for the FC layer generated in the CNN can be acquired in real time, and the acquired input features can be stored in the data memory, where multiple first feature components of each input feature can be batch processed, so Will each The input feature can be stored in a batch, and each first feature component occupies an input channel (input channel, ci) in the batch, and each first feature component can be a number, a vector, or a matrix. Based on this, for convenience of description, the x-th feature component of the input feature is denoted as cix below.
  • each input feature includes 6 feature components, respectively corresponding to ciO, cil, and ci5.
  • S202 When the total number of the acquired multiple input features reaches a first preset threshold, simultaneously input the multiple input features to multiple data processing units corresponding to the fully connected layer.
  • multiple data processing units corresponding to the FC layer may be used to perform FC layer calculations on input features in multiple batches, for example: PE0 performs FC layer calculations on input features in batchO, and PE 1 targets The input features in batchl are used for FC layer calculation, ..., PE15 performs FC layer calculations for the input features in batchl5.
  • the first preset threshold may be determined according to the number of data processing units corresponding to FC and / or the storage capacity of the data memory. For example: if there are 16 data processing units corresponding to FC, the first preset threshold may be 16.
  • one of the acquired multiple input features may be simultaneously input to each data processing unit of the multiple data units.
  • the input feature may be read from the data storage first, and then the input feature may be input to one of the data processing units corresponding to the FC layer, where the input feature may be stored in The input data buffer of the data processing unit.
  • each data processing unit also has only one input feature, and in order to improve the utilization rate of the multiply accumulator, the input feature in each data processing unit is different.
  • a total of 16 input features are obtained, including TO, T1, ..., T15, which are stored in batchO, batch1, ..., batch15, respectively.
  • the feature components of each input feature can be read from each batch in the following order and stored in the input data cache of the corresponding PE ("batcha-cib" indicates the b-th ci in batcha): [0041] batchO-ciO, batch 1-ciO, batch 15-ciO,
  • batchO-cil batch 1-cil, batch 15-cil,
  • S203 Obtain a weight coefficient of each second feature component in the output features of the fully connected layer among the multiple feature components.
  • the weight coefficients required for the FC layer may be read from the double-rate synchronous dynamic random access memory (Double Data Rate, DDR) and stored in the weight memory.
  • DDR Double Data Rate
  • the output feature includes multiple second feature components, and each first feature component contributes to each second feature component. Therefore, the obtained weight coefficient includes the weight coefficient of each first feature component in each second feature component.
  • each second feature component included in the output feature may also be stored in batches in the output data cache of the corresponding data processing unit, each second The characteristic component occupies an output channel (output channel, CO). Based on this, for convenience of the following description, the x-th second feature component of the output feature is denoted as cox.
  • S204 in the plurality of data processing units, according to the plurality of first feature components and the weight coefficients corresponding to the plurality of first feature components, determine the output feature corresponding to each input feature in parallel .
  • the weight coefficients of the first feature component in each second feature component may be broadcast to the data processing unit one by one, when the weight coefficients of the first feature components are all equal After the broadcast is completed, another first feature component is switched to broadcast the weight coefficient. After the parameters of CN N are determined, the weight coefficients required for calculating each input feature in the FC layer are the same, so the weight coefficients required in each data processing unit are also the same.
  • each input feature includes six first feature components ciO, cil, ..., ci5, and each output feature includes 128 second feature components co0, col, ..., col27.
  • the weight coefficients can be broadcast to each PE in the following order.
  • cix-coy represents the weight coefficient of the x-th first feature component in the y-th second feature component.
  • each first feature component in an input feature input to the data processing unit may be determined according to a weighting factor
  • the contribution value of each second feature component in the two feature components, where the contribution value may be the product of the first feature component and the weight coefficient. It should be noted that operations in multiple data units are performed in parallel.
  • the input feature T0 includes ciO, cil, and ci2, which are 0, 6, and 5, respectively, and ciO-coO, cil-co 0, ci2-co0, and ci3-co0 are 0.12, 0.15, and 0.2, respectively.
  • the contribution value of one of the first feature components to each second feature component in the output feature may be calculated first, and then the first feature component is deleted from the data processing unit; Then switch to another first feature component for calculation. In other words, after applying one of the first feature components to each second feature component, the first feature component is switched for calculation.
  • PE can first calculate the contribution value of ciO to coO, col, ..., col27, and ciO is deleted from the input data cache; then after inputting cil to PE, broadcast cil-coO, cil-col, cil-col27 to PE, then PE can calculate the contribution value of cil to coO, col, ..., col27 , And delete the cil from the input data cache ... and so on, and the contribution value of each d to each CO can be obtained, thereby obtaining each second feature component.
  • the output feature is determined according to the contribution value, where the sum of the contribution values of each first feature component may be used as the corresponding second feature component, and the plurality of second feature components together constitute the output feature.
  • the output data cache of each PE stores the output characteristics corresponding to the input characteristics input to the PE, where co0, col, ..., col27 constitute the output characteristics .
  • each data processing unit calculates the output characteristics, it is necessary to store the output characteristics in the output data cache, and then read and store the output characteristics to the data memory through the data return unit. Therefore, if the storage capacity of the output data cache is smaller than the storage space occupied by the output features Small, you need to group multiple second feature components in the output features.
  • PE0 can store 128 cos in the output data cache, and the output feature P0 corresponding to the input feature TO contains 148 second feature components, then 148 is decomposed into 128 + 20.
  • the 128 second feature components can be stored in the output data buffer of PE0, and then when the 128 second feature components are read from the output data buffer of PE0, then Calculate the remaining 20 second feature components.
  • the core idea of the implementation method of the fully connected layer in the embodiments of the present application is to broadcast the weight coefficients to multiple data processing units at the same time, wherein each data processing unit is responsible for calculating the acquired one Input features, so that multiple PEs can simultaneously calculate the FC layer of multiple input features to achieve the purpose of multiplexing weight coefficients.
  • each input feature includes six first feature components ciO, cil, and ci5 (as shown in FIG. 3).
  • the output features corresponding to TO, T1, and T15 are P0, P1 ' P15, and each output feature contains 128 second feature components co0, col, ..., col27.
  • the specific implementation process is as follows:
  • the TO, T1, and T15 are read out from batch0, batch1, and batch15 in the following order, and stored in the input data buffers of PE0, PE1, ..., PE15, respectively.
  • the ciO of each input feature can be read first, then the cil, ... of each input feature can be read, and put into the corresponding PE.
  • it is equivalent to ciO, cil, ..., ci5 input to T0 in PE0.
  • batchO-ciO batch 1-ciO, batch 15-ci0,
  • batchO-cil batch 1-cil, batch 15-cil,
  • the weight coefficient of each ci to each co may be broadcast to PE0, PEI, ..., PE15 in the following order
  • the broadcasting order of the weighting coefficients shown below allows each PE to multiplex each d to the greatest extent. And minimize the input data cache, because when the contribution value of cix to each of coO, col, ..., col27 is calculated at once, the cix can be deleted from the input data cache.
  • a plurality of input features for a fully connected layer are acquired, each input feature of the plurality of input features includes a plurality of first feature components, and when the plurality of inputs are acquired When the total number of features reaches a preset threshold, first input the multiple input features to multiple data processing units corresponding to the fully connected layer at the same time; then acquire each first feature in the multiple first feature components Weight coefficients of components in the output features of the fully connected layer; then in the multiple data processing units, according to the multiple first feature components and the weight coefficients corresponding to the multiple first feature components, parallel The output feature corresponding to each input feature is determined.
  • the method described in the embodiment of the present application first accumulates the input feature, and after accumulating a certain number, then uses multiple data processing units
  • the parallel determination of multiple input features achieves the calculation of the FC layer of multiple input features under the premise of reading the weight coefficient only once, thereby achieving the purpose of multiplexing the FC layer weight coefficients, greatly reducing Reading the bandwidth of the weight coefficient improves the utilization rate of the neural network MAC.
  • the invalid data after the calculation is deleted in time, which effectively reduces the data cache pressure in the data processing unit.
  • FIG. 6 is a schematic flowchart of another method for implementing a fully connected layer according to an embodiment of the present application. As shown in the figure, the method in the embodiment of the present application includes:
  • S601 Acquire multiple input features for a fully connected layer, where each input feature of the multiple input features includes multiple first feature components.
  • the CNN includes a convolution layer, a pooling layer, and a fully connected layer.
  • the fully connected layer can process a large number of images after processing by the convolutional layer and the pooling layer. Image features are integrated for subsequent classification or other processing of images. Therefore, the input features for the FC layer generated in the CNN can be acquired in real time, and the acquired input features can be stored in the data memory, where multiple first feature components of each input feature can be batch processed, so Each input feature may be stored in a batch, and each first feature component occupies a ci in the batch, and each first feature component may be a number, a vector, a matrix, or the like.
  • S602 When the total number of acquired multiple input features reaches a preset threshold, simultaneously input the multiple input features to each of the multiple data processing unit inputs corresponding to the fully connected layer.
  • the preset threshold may be determined according to the number of data processing units corresponding to the FC and / or the storage capacity of the data memory, such as 16, 10, and so on. For each input feature obtained, the input feature can be read from the data memory first, and then the input feature can be input to each of the multiple data processing units corresponding to the FC layer, where The input features are stored in the input data cache of the data processing unit. Therefore, each data processing unit has all the acquired input characteristics.
  • a total of 16 input features generated by the system are obtained, including TO, T1, ..., T15, which are stored in batch0, batch1, ..., batch15, respectively.
  • the characteristic components of each TO, T1, ..., T15 may be read from the data memory in the following order and stored in the input data buffer of each PE.
  • batch 1-ciO batch 1-cil
  • batch l-ci5 batch l-ci5
  • batch 15-ci0 batch 15-cil, batch 15-ci5.
  • S603 Obtain a weight coefficient of each second feature component of the plurality of feature components in the output feature of the fully connected layer.
  • the weight coefficients required for the FC layer may be read from the DDR and stored in the weight memory.
  • the output feature includes multiple second feature components, and each first feature component contributes to each second feature component. Therefore, the obtained weight coefficient is each first feature component The weight coefficient in each second feature component.
  • each data processing unit determine, according to the multiple first feature components in each input feature and the weight coefficients corresponding to the multiple first feature components, how many output features corresponding to each input feature contain At least one second feature component of the second feature components.
  • a plurality of second feature components may be numbered, and the second feature components may be assigned to each data processing unit for processing in order from the smallest number to the largest number. Among them, the number of second feature components included in each output feature is the same.
  • a plurality of weight coefficients required by the data processing unit can be broadcast to each data processing unit one by one, wherein, each data processing unit requires The weighting factors are different.
  • each data processing unit according to the weight coefficient, it is determined that each second feature component of the at least one second feature component that the data processing unit is responsible for processing, wherein the operations in the multiple data processing units It is done simultaneously.
  • the output feature includes a total of 128 second feature components coO, col, ..., col27.
  • the total number of PEs is 16, including PEO, PEI, ..., PE15.
  • the corresponding weight coefficients can be input to each PE in the following order, where “cix-coy (PEZ)” means that the weight coefficient of cix in coy is input to the PEz.
  • Ci5-col l2 (PE0), ci5-col l3 (PEl), ci5-col27 (PE15) [0103]
  • the first feature component is switched for calculation.
  • S605 Combine at least one first feature component determined by each data processing unit to obtain an output feature corresponding to each input feature.
  • the co0, col6, co32, and col l2 of the output feature P0 corresponding to the feature T0 may be input from the output data cache of PE0, and the col, col7, co33 of P0 may be obtained from PE1 , ..., col 13; and obtaining col5, co31, co47, ..., col27 from P0 in PE15. Then, according to the sequence number, co is combined into co0, col, co2, ..., col27 as P0.
  • the weight memory can only store the weight coefficients of ciO, cil, ..., ci5 in coO, col, ..., colOO, then you can first calculate coO, col, ..., co 100,
  • the core idea of the implementation method of the fully connected layer in the embodiments of the present application is: for each output feature, split the multiple second feature components included in the output feature into multiple groups Each of the multiple PEs corresponding to the FC layer is responsible for calculating one of them. Therefore, not only can multiple PEs simultaneously calculate the FC of multiple input features, but also multiple PEs can be combined to calculate an output feature, which achieves the purpose of multiplexing the weight coefficient.
  • each input feature includes six first feature components ciO, cil, ..., ci5 (as shown in FIG. 3).
  • the output features corresponding to TO, T1, ..., T15 are P0, P1, ..., P15, and each output feature contains 128 second feature components coO, col, ..., col27.
  • the specific implementation process is as follows:
  • batch 1-ciO batch 1-cil
  • batch l-ci5 batch l-ci5
  • batch 15-ci0 batch 15-cil, batch 15-ci5.
  • Ci5-col l2 (PE0), ci5-col l3 (PEi), ci5-col27 (PE15)
  • each of the multiple input features includes multiple first feature components, and when the multiple inputs are acquired When the total number of features reaches a preset threshold, first input the multiple input features to each of the multiple data processing units corresponding to the fully connected layer simultaneously; then obtain the multiple first feature components The weight coefficient of each first feature component in the output feature of the fully connected layer; and then in each data processing unit, according to the multiple first feature components and the multiple first features Weight coefficients corresponding to the components, to determine in parallel at least one second feature component of a plurality of second feature components contained in the output feature corresponding to each input feature, and finally to determine at least one determined second feature component determined by each data unit The two feature components are combined into the input features.
  • an output feature is split into multiple feature component groups, and each data processing unit calculates one of the groups, so that multiple data processing units jointly calculate an output feature, and operations in multiple data processing units They are all performed in parallel to achieve the purpose of multiplexing the FC layer weight coefficients, reducing the bandwidth of the read weight coefficients, and improving the neural network MAC utilization.
  • FIG. 9 is a schematic structural diagram of a device for implementing a fully connected layer according to an embodiment of the present application
  • the device in the embodiment of the present application includes:
  • an acquisition module 901 configured to acquire multiple input features for a fully connected layer, each of the multiple input features including multiple first feature components.
  • the CNN includes a convolution layer, a pooling layer, and a fully connected layer.
  • the fully connected layer can integrate a large number of image features obtained after the processing of the convolutional layer and the pooling layer to facilitate subsequent classification or other processing of the image. Therefore, the input features of the FC layer generated in the CNN can be acquired in real time, and the acquired input features can be stored in the data memory, where multiple first feature components of each input feature can be batch processed, so Each input feature may be stored in a batch, and each first feature component occupies one ci, and each first feature component may be a number, a vector, or a matrix, and so on.
  • the transmission module 902 is configured to simultaneously input the plurality of inputs to the plurality of data processing units corresponding to the fully connected layer when the total number of the acquired input features reaches a first preset threshold feature.
  • multiple data processing units corresponding to the FC layer may be used to input features in multiple batches. Sign the FC layer separately.
  • the first preset threshold may be determined according to the number of data processing units corresponding to the FC and / or the storage capacity of the data storage. For example: if there are 16 data processing units corresponding to FC, the first preset threshold may be 16
  • one of the acquired multiple input features may be simultaneously input to each data processing unit of the multiple data units.
  • the input feature may be read from the data storage first, and then the input feature may be input to one of the data processing units corresponding to the FC layer, where the input feature may be stored in The input data buffer of the data processing unit.
  • each data processing unit also has only one input feature, and in order to improve the utilization rate of the multiply accumulator, the input feature in each data processing unit is different.
  • multiple acquired inputs may be simultaneously input to each data processing unit of the multiple data units.
  • the input feature For each input feature acquired, the input feature may be read from the data memory first, and then the input feature may be input to each of the plurality of data processing units corresponding to the FC layer, where the input feature may be Stored in the input data buffer of the data processing unit. Therefore, each data processing unit possesses all the acquired input features.
  • the obtaining module 901 is further configured to obtain a weight coefficient of each second feature component in the output features of the fully connected layer among the plurality of feature components.
  • the weight coefficients required for the FC layer can be read from the DDR and stored in the weight memory.
  • the output feature contains multiple second feature components, and each first feature component contributes to each second feature component. Therefore, the obtained weight coefficient includes the weight coefficient of each first feature component in each second feature component.
  • the processing module 903 is configured to determine output features corresponding to each input feature in parallel according to the weight coefficient and the plurality of first feature components, where the processing module 903 includes multiple data processing corresponding to the fully connected layer unit.
  • the weight coefficient of each first feature component in each second feature component may be broadcast to the data processing unit one by one. Among them, after the parameters of CNN are determined, the weight coefficients required to calculate each input feature in the F C layer are the same.
  • the input to the data processing unit may be determined according to the weight coefficient
  • the product of weight coefficients may be the first feature component The product of weight coefficients.
  • the contribution value of one of the first feature components to each second feature component in the output feature may be calculated first, and then the first feature component is deleted from the data processing unit; Then switch to another first feature component for calculation. In other words, after applying one of the first feature components to each second feature component, the first feature component is switched for calculation.
  • the output feature is determined according to the contribution value, where the sum of the contribution values of each first feature component may be used as the corresponding second feature component, and the plurality of second feature components together constitute the output feature.
  • each data processing unit may first determine the output corresponding to each input feature according to multiple first feature components in each input feature and weight coefficients corresponding to the multiple first feature components At least one second feature component of the plurality of second feature components included in the feature. Then, at least one first feature component determined by each data processing unit is combined to obtain an output feature.
  • a plurality of second feature components may be numbered, and the second feature components may be assigned to each data processing unit one by one in order from small to large. Among them, the number of second feature components included in each output feature is the same.
  • a corresponding weight coefficient may be input to each data processing unit according to the second feature component processed in each data processing unit. Then, in each data processing unit, according to the weight coefficient, each second feature component of at least one second feature component that the data processing unit is responsible for processing is determined.
  • each input feature of the multiple input features includes multiple first feature components, and the acquired multiple inputs
  • the total number of features reaches a preset threshold
  • first input the multiple input features to the data processing unit corresponding to the fully connected layer at the same time acquire each first feature component of the multiple first feature components in The whole Weight coefficients in the output features of the connection layer; and then in the multiple data processing units, determine each in parallel according to the multiple first feature components and the weight coefficients corresponding to the multiple first feature components Output features corresponding to input features.
  • the method described in the embodiment of the present application first accumulates the input feature, and after accumulating a certain number, then uses multiple data processing units A way to perform parallel calculation on multiple input features. Realize the calculation of the FC layer of multiple input features under the premise of reading the weight coefficient only once, thereby achieving the purpose of multiplexing the FC layer weight coefficient, greatly reducing the bandwidth of reading the weight coefficient, and improving the nerve Network MAC utilization.
  • the invalid data that has been calculated is deleted in time, which effectively reduces the data cache pressure in the data processing unit.
  • FIG. 10 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
  • the electronic device may include: at least one processor 1001, such as a CPU, at least one communication interface 1002, at least one memory 1003, and at least one bus 1004.
  • the bus 1004 is used to implement connection and communication between these components.
  • the communication interface 1002 of the electronic device is a wired transmission port, and may also be a wireless device, for example, including an antenna device, and used for signaling or data communication with other node devices.
  • the memory 1003 may be a high-speed RAM memory or a non-volatile memory (non-volatile memory), for example, at least one disk memory.
  • the memory 1003 may optionally be at least one storage device located away from the foregoing processor 1001.
  • a group of program codes is stored in the memory 1003, and the processor 1001 is used to call the program codes stored in the memory to perform the following operations:
  • each of the multiple input features including multiple first feature components
  • the output features corresponding to each input feature are determined in parallel according to the plurality of first feature components and the weight coefficients corresponding to the plurality of first feature components.
  • the processor 1001 is further configured to perform the following operation steps:
  • the processor 1001 is further configured to perform the following operation steps:
  • each data processing unit according to the plurality of first feature components in the one input feature and the weight coefficients corresponding to the plurality of first feature components, determine that the one input feature corresponds to Output characteristics.
  • the processor 1001 is further configured to perform the following operation steps:
  • the plurality of input features are simultaneously input to each of the plurality of data processing units.
  • the processor 1001 is further configured to perform the following operation steps:
  • each of the data processing units according to the plurality of first feature components in each input feature and the weight coefficients corresponding to the plurality of first feature components, determine the At least one second feature component of the plurality of second feature components contained in the output feature corresponding to the input feature;
  • the output feature corresponding to the one input feature includes multiple second feature components
  • the processor 1001 is further configured to perform the following operation steps:
  • the processor 1001 is further configured to perform the following operation steps:
  • the first feature component for which the contribution value has been determined is deleted from each data processing unit.
  • the processor 1001 is further configured to perform the following operation steps:
  • the at least one second feature component is determined.
  • the processor 1001 is further configured to perform the following operation steps: [0173] determine the storage space required to store the weight coefficient;
  • an embodiment of the present application also provides a storage medium, the storage medium is used to store an application program, the application program is used to execute a full-time shown in Figure 2 and Figure 6 when running The operation performed by the electronic device in the implementation method of the connection layer.
  • the embodiments of the present application also provide an application program, which is used to execute an implementation method of the fully connected layer shown in FIG. 2 and FIG. 6 during runtime by an electronic device. Operation.

Abstract

本申请公开了一种全连接层的实现方法、装置、电子设备及计算机可读存储介质,包括:获取针对全连接层的多个输入特征,所述多个输入特征中的每个输入特征包括多个第一特征分量,当获取到的所述多个输入特征的总数量达到第一预设阈值时,同时向所述全连接层对应的多个数据处理单元输入所述多个输入特征;接着获取所述多个第一特征分量中的每个第一特征分量在所述全连接层的输出特征中的权重系数;然后在所述多个数据处理单元中,根据所述多个第一特征分量和所述多个第一特征分量对应的权重系数,并行确定所述每个输入特征对应的输出特征。采用本申请实施例,可以实现全连接层权重系数的复用、提高神经网络中乘法累加器的利用率。

Description

一种全连接层的实现方法、 装置、 电子设备及计算机可 读存储介质 技术领域
[0001] 本申请涉及神经网络领域, 尤其涉及一种全连接层的实现方法、 装置、 电子设 备及计算机可读存储介质。
[0002] 本申请要求于 2018年 11月 19日提交中国专利局, 申请号为 201811375742.7、 发 明名称为“一种全连接层的实现方法、 装置、 电子设备及计算机可读存储介质”的 中国专利申请的优先权, 其全部内容通过引用结合在本申请中。
背景技术
[0003] 目前, 卷积神经网络 (Convolution Neural Network, CNN) 被广泛地应用于人 工智能的各个领域。 CNN是一种深度前馈人工神经网络, 包括卷积层、 池化层 和全连接 (Fully connect, FC) 层。 相比于其他神经网络算法, CNN可以处理更 大的图像, 具有计算量大、 带宽需求大以及操作相对固定的特点。 其中, 在 FC 层中需将处理对象的局部特征整合为全局特征。 尽管 FC层的计算量比较小, 但 需要的权重系数 (weight) 的量却很大。 多数情况下, FC层所需的 weight占整个 神经网络 weight的 70%以上。 在现有的 FC层的实现方案中, 一旦系统生成局部特 征立即读取 weight对该局部特征进行转化, 这种做法不仅无法实现 Fdl weight的 复用、 而且导致整个神经网络中乘法累加器 (Multiply Accumulate, MAC) 的利 用率低。
发明概述
技术问题
问题的解决方案
技术解决方案
[0004] 本申请实施例提供一种全连接层的实现方法、 装置、 设备及计算机可读存储介 质, 可以实现 FC层权重系数的复用、 提高神经网络中 MAC的利用率。 [0005] 本申请第一方面提供了一种全连接层的实现方法, 包括:
[0006] 获取针对全连接层的多个输入特征, 所述多个输入特征中的每个输入特征包括 多个第一特征分量;
[0007] 当获取到的所述多个输入特征的总数量达到第一预设阈值时, 同时向所述全连 接层对应的多个数据处理单元输入所述多个输入特征;
[0008] 获取所述多个第一特征分量中的每个第一特征分量在所述全连接层的输出特征 中的权重系数;
[0009] 在所述多个数据处理单元中, 根据所述多个第一特征分量和所述多个第一特征 分量对应的所述权重系数, 并行确定所述每个输入特征对应的输出特征。
[0010] 本申请第二方面提供了一种全连接层的实现装置, 包括:
[0011] 获取模块, 用于获取针对全连接层的多个输入特征, 所述多个输入特征中的每 个输入特征包括多个第一特征分量;
[0012] 传输模块, 用于当获取到的所述多个输入特征的总数量达到第一预设阈值时, 同时向所述全连接层对应的多个数据处理单元输入所述多个输入特征;
[0013] 所述获取模块, 还用于获取所述多个第一特征分量中的每个第一特征分量在所 述全连接层的输出特征中的权重系数;
[0014] 处理模块, 所述处理模块包括所述全连接层对应的多个数据处理单元, 用于所 述多个第一特征分量和所述多个第一特征分量对应的权重系数, 并行确定所述 每个输入特征对应的输出特征。
[0015] 本申请实施例第三方面提供了一种电子设备, 包括: 处理器、 存储器、 通信接 口和总线;
[0016] 所述处理器、 所述存储器和所述通信接口通过所述总线连接并完成相互间的通 信;
[0017] 所述存储器存储可执行程序代码;
[0018] 所述处理器通过读取所述存储器中存储的可执行程序代码来运行与所述可执行 程序代码对应的程序, 以用于执行本申请实施例第一方面公开的一种全连接层 的实现方法。
[0019] 本申请第四方面提供了一种存储介质, 其中, 所述存储介质用于存储应用程序 , 所述应用程序用于在运行时执行本申请实施例第一方面公开的一种全连接层 的实现方法。
[0020] 实施本申请实施例, 获取针对全连接层的多个输入特征, 所述多个输入特征中 的每个输入特征包括多个第一特征分量, 当获取到的所述多个输入特征的总数 量达到第一预设阈值时, 首先同时向所述全连接层对应的多个数据处理单元输 入所述多个输入特征; 接着获取所述多个第一特征分量中的每个第一特征分量 在所述全连接层的输出特征中的权重系数; 然后在所述多个数据处理单元中, 根据所述多个第一特征分量和所述多个第一特征分量对应的权重系数, 并行确 定所述每个输入特征对应的输出特征。 可以在多个数据处理单元中对多个输入 特征对应的输出特征进行并行确定, 实现了在仅读取一次权重系数的前提下完 成对多个输入特征的 FC层的计算, 相比于现有技术中每对一个输入特征进行 FC 层的计算都要读取一次权重系数的方法, 本申请实施例提供的方法实现了权重 系数的复用。 此外, 输入特征的总数量对应的第一预设阈值的选取可以以 FC层 对应的数据处理单元的数量为依据, 以使每个数据处理单元至少承担一个输入 特征的 FC层的计算, 避免数据处理单元闲置的情况, 提高了 MAC的利用率。 发明的有益效果
对附图的简要说明
附图说明
[0021] 为了更清楚地说明本申请实施例的技术方案, 下面将对实施例描述中所需要使 用的附图作简单地介绍, 显而易见地, 下面描述中的附图是本申请的一些实施 例, 对于本领域普通技术人员来讲, 在不付出创造性劳动的前提下, 还可以根 据这些附图获得其他的附图。
[0022] 图 1是本申请实施例提供的神经网络处理器的结构示意图;
[0023] 图 2是本申请实施例提供的一种全连接层的实现方法的流程示意图;
[0024] 图 3是本申请实施例提供的一种输入特征的示意图;
[0025] 图 4是本申请实施例提供的一种向 PE写入输入特征的示意图;
[0026] 图 5是本申请实施例提供的一种输出特征的示意图;
[0027] 图 6是本申请实施例提供的另一种全连接层的实现方法的流程示意图; [0028] 图 7是本申请实施例提供的一种向 PE写入输入特征的示意图;
[0029] 图 8是本申请实施例提供的另一种输出特征的示意图;
[0030] 图 9是本申请实施例提供的一种全连接层的实现装置的结构示意图;
[0031] 图 10是本申请实施例提供的一种电子设备的结构示意图。
发明实施例
本发明的实施方式
[0032] 请参考图 1, 图 1是本申请实施例提供的一种神经网络处理器的结构示意图。 如 图所示, 本申请实施例中神经网络处理器包括数据存储器、 数据读取单元、 权 重存储器、 数据回存单元、 以及多个数据处理单元 (Processing Element, PE) 。 其中, 每个 PE可以包括输入数据缓存、 卷积运算单元和输出数据缓存。 其中, 数据存储器用于存储神经网络计算过程中每层产生的输入特征 (input feature map) , 从而将输入特征整合成输出特征 (output feature map) ; 数据读取单元 用于读取数据存储器中的输入特征, 并将输入特征送入对应 PE的输入数据缓存 中; 权重存储器用于存储神经网络计算过程中每层所需的权重系数 (weight) , 也可以是权重矩阵; 数据回存单元用于将输出数据缓存中的输出特征存入数据 存储器中。 PE用于完成 FC层的计算, 其中, 卷积运算单元用于读取输入数据缓 存中的输入特征, 并执行 FC层的运算或其他卷积运算, 输出数据缓存用于存储 卷积运算单元计算出来的输出特征。 基于以上神经网络处理器, 本申请实施例 提供以下全连接层的实现方法。
[0033] 请参考图 2, 图 2是本申请实施例提供的一种全连接层的实现方法的流程示意图 。 如图所示, 本申请实施例中的方法包括:
[0034] S201 , 获取针对全连接层的多个输入特征, 所述多个输入特征中的每个输入特 征包括多个第一特征分量。
[0035] 具体实现中, CNN中包括卷积层、 池化层和全连接层。 在利用卷积神经网络图 像处理的过程中, 全连接层可以将经过卷积层和池化层的处理后得到的大量图 像特征进行整合, 以便对图像进行后续分类或其他处理。 因此, 可以实时获取 C NN中生成的针对 FC层的输入特征, 并将获取到的输入特征存储在数据存储器中 , 其中, 可以将每个输入特征的多个第一特征分量进行批量处理, 因此将每个 输入特征可以存储在一个 batch中, 并且每个第一特征分量占用 batch中的一个输 入通道 (input channel, ci) , 每个第一特征分量可以为一个数、 一个向量、 或 者一个矩阵等等。 基于此, 为了方便叙述, 以下将输入特征的第 x个特征分量记 为 cix。
[0036] 例如: 如图 3所示, 输入特征 TO、 Tl、 T2、 ...、 T 15分别存储在数据存储器的 b atchO、 batchl、 ...、 batchl5中。 其中, 每个输入特征包括 6个特征分量, 分别对 应 ciO、 cil、 、 ci5。
[0037] S202, 当获取到的所述多个输入特征的总数量达到第一预设阈值时, 同时向所 述全连接层对应的多个数据处理单元输入所述多个输入特征。
[0038] 具体实现中, FC层对应的多个数据处理单元可以用于针对多个 batch中的输入 特征分别进行 FC层计算, 例如: PE0针对 batchO中的输入特征进行 FC层计算、 PE 1针对 batchl中的输入特征进行 FC层计算、 ...、 PE15针对 batchl5中的输入特征进 行 FC层计算。 第一预设阈值可以根据 FC对应的数据处理单元的数量和 /或数据存 储器的存储容量来确定。 比如: FC对应的数据处理单元为 16个, 则第一预设阈 值可以为 16。
[0039] 当获取到的多个输入特征的总数量达到第一预设阈值时, 可以同时向多个数据 单元中的每个数据处理单元输入获取到的多个输入特征中的一个输入特征。 针 对获取到的每个输入特征, 可以首先从数据存储读取该输入特征, 然后向 FC层 对应的多个数据处理单元中的一个数据处理单元输入该输入特征, 其中, 可以 将输入特征存储在数据处理单元的输入数据缓存中。 相应地, 每个数据处理单 元中也仅拥有一个输入特征, 并且为了提高乘法累加器的利用率, 每个数据处 理单元中的输入特征均不相同。
[0040] 例如: 如图 3所示, 总共获取到 16个输入特征, 包括 TO、 T1、 ...、 T15 , 它们 分别存储在 batchO、 batchl、 ...、 batchl5中。 FC层对应的数据处理单元有 16个, 包括 PE0、 PE1、 ...、 PE15。 因此, 如图 4所示, 可以将 T0输入 PE0、 T1输入 PE1 、 ...、 T15输入 PE15。 其中, 可以按照如下顺序从每个 batch中读取每个输入特征 的特征分量, 并存入对应的 PE的输入数据缓存中 (“batcha-cib”表示 batcha中的第 b个 ci) : [0041] batchO-ciO, batch 1-ciO, batch 15-ciO,
[0042] batchO-cil , batch 1-cil , batch 15-cil,
[0043] .
[0044] batchO-ci5 , batch l-ci5 , …, batch 15-ci5。
[0045] S203 , 获取所述多个特征分量中每个第二特征分量在所述全连接层的输出特中 的权重系数。
[0046] 具体实现中, 在 CNN中, 可以从双倍速率同步动态随机存储器 (Double Data Rate, DDR) 中读取 FC层所需的权重系数, 并存储到权重存储器中。 其中, 输出 特征中包含多个第二特征分量, 每个第一特征分量对每个第二特征分量均有贡 献。 因此, 获取到的权重系数包括每个第一特征分量在每个第二特征分量中的 权重系数。
[0047] 其中, 如图 5所示, 与输入特征的存储方式相同, 输出特征所包含的多个第二 特征分量也可以被批量存储在对应数据处理单元的输出数据缓存中, 每个第二 特征分量占用一个输出通道 (output channel, CO) 。 基于此, 为了便于叙述以下 将输出特征的第 x个第二特征分量记为 cox。
[0048] S204, 在所述多个数据处理单元中, 根据所述多个第一特征分量和所述多个第 一特征分量对应的权重系数, 并行确定所述每个输入特征对应的输出特征。
[0049] 具体实现中, 可以首先针对每个第一特征分量, 向数据处理单元逐个广播该第 一特征分量在每个第二特征分量中的权重系数, 当该第一特征分量的权重系数 均广播完成后, 再切换另一个第一特征分量进行权重系数的广播。 其中, 当 CN N的各项参数确定后, 将每个输入特征在 FC层的计算中所需的权重系数是相同的 , 因此每个数据处理单元中所需的权重系数也相同。
[0050] 例如: 每个输入特征包括 6个第一特征分量 ciO、 cil、 ...、 ci5, 每个输出特征包 括 128个第二特征分量 co0、 col、 ...、 col27。 则可以按照如下顺序向每个 PE广 播权重系数。 其中, cix-coy表示第 x个第一特征分量在第 y个第二特征分量中的 权重系数。
[0051] ci0-co0, ciO-col, , ci0-col27 ,
[0052] cil-coO, cil-col, , cil-col27 , [0053] .
[0054] ci5-co0, ci5-col, , ci5-col27
[0055] 接着, 在每个数据处理单元中, 可以根据权重系数, 确定输入该数据处理单元 的一个输入特征中的每个第一特征分量对该输入特征对应的输出特征所包含的 多个第二特征分量中的每个第二特征分量的贡献值, 其中, 贡献值可以为第一 特征分量与权重系数的乘积。 需要说明的是, 多个数据单元中的操作是并行执 行的。
[0056] 例如, 输入特征 T0包括 ciO、 cil和 ci2, 它们分别为 0、 6和 5, 且 ciO-coO、 cil-co 0、 ci2-co0和 ci3-co0分别为 0.12、 0.15和 0.2, 则 ciO、 cil和 ci2对 co0的贡献值分别 为 0*0.12=0 6*0.15=0.9、 5*0.2=1。
[0057] 其中, 为了最大程度的复用输入特征中的每个第一特征分量, 以及最小化数据 处理单元的数据缓存。 针对输入特征中的多个第一特征分量, 可以首先计算其 中一个第一特征分量对输出特征中的每个第二特征分量的贡献值, 接着将该第 一特征分量从数据处理单元中删除; 然后切换到另一个第一特征分量进行计算 。 也就是说, 在将其中一个第一特征分量应用于每个第二特征分量之后, 再切 换第一特征分量进行计算。
[0058] 例如: 在向 PE输入 ciO后, 向 PE广播 ci0-co0, ciO-col , ci0-col27 , 则 PE可 以首先计算出 ciO对 coO, col, ..., col27的贡献值, 并将 ciO从输入数据缓存中删 除; 接着在向 PE输入 cil后, 向 PE广播 cil-coO, cil-col , cil-col27 , 则 PE可 以计算出 cil对 coO, col, ..., col27的贡献值, 并将 cil从输入数据缓存中删除 ... 依次类推, 可以得到每个 d对每个 CO的贡献值, 从而得到每个第二特征分量。
[0059] 然后, 根据贡献值, 确定输出特征, 其中, 可以将每个第一特征分量的贡献值 的和作为对应的第二特征分量, 而多个第二特征分量共同构成了输出特征。
[0060] 例如, 如图 5所示, 每个 PE的输出数据缓存中存储着输入该 PE中的输入特征所 对应的输出特征, 其中, co0、 col、 ...、 col27构成了该输出特征。
[0061] 需要说明的是, 在每个数据处理单元计算出输出特征之后, 需要将输出特征存 储到输出数据缓存中, 然后再通过数据回存单元将输出特征读取并存储到数据 存储器。 因此, 若输出数据缓存的存储容量小于输出特征所占的存储空间的大 小, 则需要将输出特征中的多个第二特征分量进行分组。
[0062] 例如: PE0的输出数据缓存中可以存储 128个 co, 而输入特征 TO对应的输出特征 P0包含 148个第二特征分量, 则将 148分解为 128+20。 首先在 PE0计算其中的 128 个第二特征分量, 这 128个第二特征分量可以存储在 PE0的输出数据缓存中, 然 后当 128个第二特征分量从 PE0的输出数据缓存被读走后, 再计算剩下的 20个第 二特征分量。
[0063] 综上所述, 本申请实施例中的全连接层的实现方法的核心思想是: 将权重系数 同时广播给多个数据处理单元, 其中, 每个数据处理单元负责计算获取到的一 个输入特征, 从而可以实现多个 PE同步进行多个输入特征的 FC层的计算, 达到 复用权重系数的目的。
[0064] 以下通过一个例子来说明本申请实施例中全连接层的实现方法的完整实施流程
[0065] 假设供获取到 16个输入特征 TO、 T1、 ...、 T15。 它们分别存储在数据存储器的 batchO、 batchl、 ...、 batchl5中, 每个输入特征中分别包括 6个第一特征分量 ciO 、 cil、 、 ci5 (如图 3所示) 。 TO、 T1、 、 T15对应的输出特征分别为 P0、 P1 ' ' P15 , 每个输出特征包含 128个第二特征分量 co0、 col、 ...、 col27。 则具 体实施流程如下:
[0066] 1) 将 TO、 T1、 、 T15按照如下顺序从 batchO、 batchl、 、 batchl5中读出, 并分别存入 PE0、 PE1、 ...、 PE15的输入数据缓存中。 其中, 可以首先读取每个 输入特征的 ciO, 再读取每个输入特征的 cil, ..., 并放入对应的 PE中。 如图 4所 示, 相当于 PE0中被输入 T0的 ciO、 cil、 ...、 ci5。 PE1中被输入 T1的 ciO、 cil、 ...
、 ci5。 ....., PE15中被输入 T15的 ciO、 cil、 、 ci5。
[0067] batchO-ciO, batch 1-ciO, batch 15-ci0,
[0068] batchO-cil , batch 1-cil , batch 15-cil,
[0069] .
[0070] batch0-ci5 , batch l-ci5 , …, batch 15-ci5。
[0071] 2) 可以按照如下顺序向 PE0、 PEI、 ...、 PE15广播每个 ci对每个 co的权重系数
。 其中, 以下所示的权重系数的广播顺序使得每个 PE可以最大程度的复用每个 d 并最小化输入数据缓存, 因为当一次性将 cix对 coO、 col、 ...、 col27中每个的贡 献值都计算出来后, 就可以将 cix从输入数据缓存中删除。
[0072] ciO-coO, ciO-col, , ci0-col27 ,
[0073] cil-coO, cil-col, , cil-col27 ,
[0074] .
[0075] ci5-co0, ci5-col, , ci5-col27
[0076] 3) 如图 5所示, 在每个 PE中依次计算对应输出特征的 co0、 col、 ...、 col27并 存储输出数据缓存中, 从而得到 P0、 P1、 ...、 P15。
[0077] 在本申请实施例中, 获取针对全连接层的多个输入特征, 所述多个输入特征中 的每个输入特征包括多个第一特征分量, 当获取到的所述多个输入特征的总数 量达到预设阈值时, 首先同时向所述全连接层对应的多个数据处理单元输入所 述多个输入特征; 接着获取所述多个第一特征分量中的每个第一特征分量在所 述全连接层的输出特征中的权重系数; 然后在所述多个数据处理单元中, 根据 所述多个第一特征分量和所述多个第一特征分量对应的权重系数, 并行确定所 述每个输入特征对应的输出特征。 相比于现有技术中每生成一个输入特征就进 行 FC层计算的方法, 本申请实施例所述的方法中先将输入特征进行累积, 当累 积到一定数量之后, 再利用多个数据处理单元对多个输入特征进行并行确定的 方式, 实现了在仅读取一次权重系数的前提下完成对多个输入特征的 FC层的计 算, 从而达到了复用 FC层权重系数的目的, 大大减少了读取权重系数的带宽, 提高了神经网络 MAC的利用率。 此外, 通过输入特征分量的读取顺序与权重系 数的广播顺序的配合, 将完成计算的无效数据及时删除, 有效减少了的数据处 理单元中的数据缓存压力。
[0078] 请参考图 6 , 图 6是本申请实施例提供的另一种全连接层的实现方法的流程示意 图。 如图所示, 本申请实施例中的方法包括:
[0079] S601 , 获取针对全连接层的多个输入特征, 所述多个输入特征中的每个输入特 征包括多个第一特征分量。
[0080] 具体实现中, CNN中包括卷积层、 池化层和全连接层。 在利用卷积神经网络图 像处理的过程中, 全连接层可以将经过卷积层和池化层的处理后得到的大量图 像特征进行整合, 以便对图像进行后续分类或其他处理。 因此, 可以实时获取 C NN中生成的针对 FC层的输入特征, 并将获取到的输入特征存储在数据存储器中 , 其中, 可以将每个输入特征的多个第一特征分量进行批量处理, 因此将每个 输入特征可以存储在一个 batch中, 并且每个第一特征分量占用 batch中的一个 ci , 每个第一特征分量可以为一个数、 一个向量、 或者一个矩阵等等。
[0081] S602, 当获取到的多个输入特征的总数量达到预设阈值时, 同时向全连接层对 应的多个数据处理单元输入中的每个数据处理单元输入所述多个输入特征。
[0082] 具体实现中, 预设阈值可以根据用于 FC对应的数据处理单元的数量和 /或数据 存储器的存储容量来确定, 如 16、 10等。 其中, 针对获取到的每个输入特征, 可以首先从数据存储器中读取该输入特征, 然后向 FC层对应的多个数据处理单 元中的每个数据处理单元输入该输入特征, 其中, 可以将输入特征存储在数据 处理单元的输入数据缓存中。 因此, 每个数据处理单元拥有获取到的所有的输 入特征。
[0083] 例如: 总共获取到系统生成的 16个输入特征, 包括 TO、 T1、 ...、 T15 , 它们分 别存储在 batchO、 batchl、 ...、 batchl5中。 FC层对应的数据处理单元有 16个, 包 括 PEO、 PE1、 ...、 PE15。 因此, 如图 7所示, 可以先将 T0输入 PEO、 PE1、 ...、 PE15; 再将 T1输入 PEO、 PE1、 、 PE15; ...; 最后再将 T15输入 PEO、 PE1、 ... 、 PE15。 具体地, 可以按照如下顺序从数据存储器中读取每个 TO、 T1、 ...、 T1 5的特征分量, 并存入每个 PE的输入数据缓存中。
[0084] batch0-ci0, batchO-cil , ... ,batch0-ci5,
[0085] batch 1-ciO, batch 1-cil , batch l-ci5,
[0086] .
[0087] batch 15-ci0, batch 15-cil , batch 15-ci5。
[0088] S603 , 获取所述多个特征分量中每个第二特征分量在所述全连接层的输出特中 的权重系数。
[0089] 具体实现中, 在 CNN中, 可以从 DDR中读取 FC层所需的权重系数, 并存储到 权重存储器中。 其中, 输出特征中包含多个第二特征分量, 每个第一特征分量 对每个第二特征分量均有贡献。 因此, 获取到的权重系数为每个第一特征分量 在每个第二特征分量中的权重系数。
[0090] S604, 在每个数据处理单元中, 根据每个输入特征中的多个第一特征分量和多 个第一特征分量对应的权重系数, 确定每个输入特征对应的输出特征包含的多 个第二特征分量中的至少一个第二特征分量。
[0091] 具体实现中, 可以将多个第二特征分量进行编号, 并按照编号从小到大的顺序 将第二特征分量逐一分配给每个数据处理单元进行处理。 其中, 每个输出特征 所包含的第二特征分量的数量相同。 相应地, 可以根据在每个数据处理单元中 进行处理的第二特征分量, 向每个数据处理单元逐个广播该数据处理单元所需 的多个权重系数, 其中, 每个数据处理单元所需的权重系数不同。
[0092] 然后, 在每个数据处理单元中, 根据权重系数, 确定该数据处理单元负责处理 的至少一个第二特征分量中的每个第二特征分量, 其中, 多个数据处理单元中 的操作是同时进行的。
[0093] 例如: 如图 8所示, 输出特征总共包含 128个第二特征分量 coO、 col、 ...、 col2 7。 PE的总数量为 16, 包括 PEO、 PEI、 ...、 PE15。 则可以首先将 co0分配给 PE0 、 col分配给 PEI、 co2分配给 PE2、 ...、 以及 col5分配给 PE15 ; 接着将 col6分配 给 PE0、 将 col7分配给 PE1、 ...。 依次类推, 得到在 PEi中进行计算的第二特征分 量包括 co (i+j*16) , 其中, i=0、 1,2,...,15 , j=0,l ...,7 , 在得到 co (i+j*16) 后 , 可以将其存储在输出数据缓存中。
[0094] 相应地, 可以按照如下顺序向每个 PE输入对应的权重系数, 其中, “cix-coy (P Ez) ”表示向 PEz输入 cix在 coy中的权重系数。
[0095] ci0-co0 (PE0) , ciO-col (PEI) , , ci0-col5 (PE15) ,
[0096] ci0-col6 (PE0) , ci0-col7 (PEI) , , ci0-co31 (PE15) ,
[0097] .
[0098] ci0-col l2 (PE0) , ci0-col l3 (PEI) , , ci0-col27 (PE15) ,
[0099] cil-coO (PE0) , cil-col (PEI) , , cil-col5 (PE15) ,
[0100] cil-col6 (PE0) , cil-col7 (PEI) , , cil-co31 (PE15) ,
[0101] .
[0102] ci5-col l2 (PE0) , ci5-col l3 (PEl) , ci5-col27 (PE15) [0103] 为了最大程度的复用输入特征中的每个第一特征分量, 以及最小化数据处理单 元的数据缓存。 在将其中一个第一特征分量应用于每个第二特征分量之后, 再 切换第一特征分量进行计算。
[0104] 例如: 需要在 PE0中计算 coO、 col6、 co32、 、 col l2。 则针对 ciO、 cil、 、 ci5 , 可以先计算 ciO对 coO、 col6、 co32、 ...、 col 12的贡献值, 再从 PE0中删除 ci 0; 接着计算 cil对 co0、 col6、 co32、 ...、 col 12的贡献值, 再从 PE0中删除 cil ; …
[0105] S605 , 将每个数据处理单元所确定的至少一个第一特征分量进行组合得到每个 输入特征对应的输出特征。
[0106] 例如, 如图 8所示, 可以从 PE0的输出数据缓存中输入特征 T0对应的输出特征 P 0的 co0、 col6、 co32、 、 col l2, 从 PE1中获取 P0的 col、 col7、 co33、 …、 col 13; 以及从 PE15中 P0的获取 col5、 co31、 co47、 ...、 col27。 然后将 co按照 序号从小到大组合成 co0、 col、 co2、 ...、 col27作为 P0。
[0107] 可选的, 为了避免在对多个输入特征进行 FC层的计算过程中多次从 DDR中读 取权重系数, 造成带宽消耗。 可以首先确定完成所有输入特征在 FC层的计算所 需的权重系数所占的存储空间的大小, 并保证该存储空间小于权重存储器的存 储容量, 从而可以将所需的权重系数一次性从 DDR中全部读出, 并存放在权重 存储器中。
[0108] 而当权重存储器无法存储所有的权重系数时, 则需要将输出特征中的多个第二 特征分量进行分组处理。 例如: 权重存储器中仅能存储 ciO、 cil、 ...、 ci5在 coO 、 col、 ...、 colOO中的权重系数, 则可以先计算 coO、 col、 ...、 co 100,
[0109] 然后再进行 colOl、 col02、 、 col27的计算。
[0110] 综上所述, 本申请实施例中的全连接层的实现方法的核心思想是: 针对每个输 出特征, 将该输出特征所包含的多个第二特征分量拆分成多个组, FC层对应的 多个 PE中每个 PE负责计算其中的一组。 从而不仅可以实现多个 PE同步进行多个 输入特征的 FC的计算, 还可以联合多个 PE对一个输出特征进行计算, 达到了复 用权重系数的目的。
[0111] 以下通过一个例子来说明本申请实施例中的全连接层的实现方法的完整实施流 程。
[0112] 假设供获取到 16个输入特征 TO、 Tl、 ...、 T15。 它们分别存储在数据存储器的 batchO、 batchl、 ...、 batchl5中, 每个输入特征中分别包括 6个第一特征分量 ciO 、 cil、 …、 ci5 (如图 3所示) 。 TO、 T1、 …、 T15对应的输出特征分别为 P0、 P1 、 ...、 P15 , 每个输出特征包含 128个第二特征分量 coO、 col、 ...、 col27。 则具 体实施流程如下:
[0113] 1) 将 TO、 T1、 …、 T15按照如下顺序从 batchO、 batchl、 …、 batchl5中读出, 并向 PE0、 PE1、 ...、 PE15进行广播中。 如图 7所示, 相当于将 TO、 T1、 ...、 T15 输入每个 PE中;
[0114] batch0-ci0, batchO-cil , ...,batch0-ci5,
[0115] batch 1-ciO, batch 1-cil , batch l-ci5,
[0116] .
[0117] batch 15-ci0, batch 15-cil , batch 15-ci5。
[0118] 2) 将每个输出特征的 co0、 col、 …、 col27分为 16组 ( 16个 PE) , 其中, 第 i 组中包括 CO (i+j*16) , i=0、 1,2, ...,15 , j=0,l ...,7。 则 PEi可以用于计算每个输出 特征的 co (i+j*16) ;
[0119] 3) 根据 PEi对应的 co (i+j*16) , 按照如下方案向 PEi输入对应的权重系数。
[0120] ci0-co0 (PE0) , ciO-col (PEi) , ci0-col5 (PE15) ,
[0121] ci0-col6 (PE0) , ci0-col7 (PEi) , ci0-co31 (PE15) ,
[0122] .
[0123] ci0-col l2 (PE0) , ci0-col l3 (PEI) , …, ci0-col27 (PE15) ,
[0124] cil-coO (PE0) , cil-col (PEi) , cil-col5 (PE15) ,
[0125] cil-col6 (PE0) , cil-col7 (PEI) , …, cil-co31 (PE15) ,
[0126] .
[0127] ci5-col l2 (PE0) , ci5-col l3 (PEi) , ci5-col27 (PE15)
[0128] 4) 如图 8所示, 在 PEi中根据权重系数以及 TO、 Tl、 ...、 T15 , 计算得到 P0、 P
1、 …、 P15中每个输出特征的 co (i+j*16) ;
[0129] 5) 从每个 PE中取出同一个输出特征的 co (i+j*16) 并进行组合从而得到 P0、 P 1、 、 P15。
[0130] 在本申请实施例中, 获取针对全连接层的多个输入特征, 所述多个输入特征中 的每个输入特征包括多个第一特征分量, 当获取到的所述多个输入特征的总数 量达到预设阈值时, 首先同时向所述全连接层对应的多个数据处理单元中的每 个数据处理单元输入所述多个输入特征; 接着获取所述多个第一特征分量中的 每个第一特征分量在所述全连接层的输出特征中的权重系数; 然后在所述每个 数据处理单元中, 根据所述多个第一特征分量和所述多个第一特征分量对应的 权重系数, 并行确定所述每个输入特征对应的输出特征所包含的多个第二特征 分量的至少一个第二特征分量, 最后将每个数据单元所确定的所确定的至少一 个第二特征分量进行组合到输入特征。 本申请实施例中将一个输出特征拆分成 多个特征分量组, 每个数据处理单元计算其中一个组, 实现了多个数据处理单 元联合计算一个输出特征, 并且多个数据处理单元中的操作均是并行进行的, 达到了复用 FC层权重系数、 减少读取权重系数的带宽、 以及提高神经网络 MAC 利用率的目的。
[0131] 请参考图 9 , 图 9是本申请实施例提供的一种全连接层的实现装置的结构示意图
。 如图所示, 本申请实施例中的装置包括:
[0132] 获取模块 901, 用于获取针对全连接层的多个输入特征, 所述多个输入特征中 的每个输入特征包括多个第一特征分量。
[0133] 具体实现中, CNN中包括卷积层、 池化层和全连接层。 在利用卷积神经网络图 像处理的过程中, 全连接层可以将经过卷积层和池化层的处理后得到的大量图 像特征进行整合, 以便对图像进行后续分类或其他处理。 因此, 可以实时获取 C NN中生成针对的 FC层的输入特征, 并将获取到的输入特征存储在数据存储器中 , 其中, 可以将每个输入特征的多个第一特征分量进行批量处理, 因此将每个 输入特征可以存储在一个 batch中, 并且每个第一特征分量占用一个 ci, 每个第一 特征分量可以为一个数、 一个向量、 或者一个矩阵等等。
[0134] 传输模块 902, 用于当获取到的所述多个输入特征的总数量达到第一预设阈值 时, 同时向所述全连接层对应的多个数据处理单元输入所述多个输入特征。
[0135] 具体实现中, FC层对应的多个数据处理单元可以用于对多个 batch中的输入特 征分别进行 FC层的计算。 第一预设阈值可以根据 FC对应的数据处理单元的数量 和 /或数据存储器的存储容量来确定。 比如: FC对应的数据处理单元为 16个, 则 第一预设阈值可以为 16
[0136] 当获取到的多个输入特征的总数量达到第一预设阈值时, 可以同时向多个数据 单元中的每个数据处理单元输入获取到的多个输入特征中的一个输入特征。 针 对获取到的每个输入特征, 可以首先从数据存储读取该输入特征, 然后向 FC层 对应的多个数据处理单元中的一个数据处理单元输入该输入特征, 其中, 可以 将输入特征存储在数据处理单元的输入数据缓存中。 相应地, 每个数据处理单 元中也仅拥有一个输入特征, 并且为了提高乘法累加器的利用率, 每个数据处 理单元中的输入特征均不相同。
[0137] 可选的, 可以同时向多个数据单元中的每个数据处理单元输入获取到的多个输 入。 针对获取到的每个输入特征, 可以首先从数据存储器中读取该输入特征, 然后向 FC层对应的多个数据处理单元中的每个数据处理单元输入该输入特征, 其中, 可以将输入特征存储在数据处理单元的输入数据缓存中。 因此, 每个数 据处理单元拥有获取到的所有的输入特征。
[0138] 获取模块 901 还用于获取所述多个特征分量中每个第二特征分量在所述全连 接层的输出特中的权重系数。
[0139] 具体实现中, 在 CNN中, 可以从 DDR中读取 FC层所需的权重系数, 并存储到 权重存储器中。 其中, 输出特征中包含多个第二特征分量, 每个第一特征分量 对每个第二特征分量均有贡献。 因此, 获取到的权重系数包括每个第一特征分 量在每个第二特征分量中的权重系数。
[0140] 处理模块 903 用于根据所述权重系数和所述多个第一特征分量, 并行确定每 个输入特征对应的输出特征, 其中, 处理模块 903中包括全连接层对应的多个数 据处理单元。
[0141] 具体实现中, 可以首先向数据处理单元逐个广播每个第一特征分量在每个第二 特征分量中的权重系数。 其中, 当 CNN的各项参数确定后, 将每个输入特征在 F C层的计算中所需的权重系数是相同的。
[0142] 接着, 在每个数据处理单元中, 可以根据权重系数, 确定输入该数据处理单元 的一个输入特征中的每个第一特征分量对该输入特征对应的输出特征包含的多 个第二特征分量中的每个第二特征分量的贡献值, 其中, 贡献值可以为第一特 征分量与权重系数的乘积。
[0143] 其中, 为了最大程度的复用输入特征中的每个第一特征分量, 以及最小化数据 处理单元的数据缓存。 针对输入特征中的多个第一特征分量, 可以首先计算其 中一个第一特征分量对输出特征中的每个第二特征分量的贡献值, 接着将该第 一特征分量从数据处理单元中删除; 然后切换到另一个第一特征分量进行计算 。 也就是说, 在将其中一个第一特征分量应用于每个第二特征分量之后, 再切 换第一特征分量进行计算。
[0144] 然后, 根据贡献值, 确定输出特征, 其中, 可以将每个第一特征分量的贡献值 的和作为对应的第二特征分量, 而多个第二特征分量共同构成了输出特征。
[0145] 可选的, 可以首先在每个数据处理单元中, 根据每个输入特征中的多个第一特 征分量和多个第一特征分量对应的权重系数, 确定每个输入特征对应的输出特 征所包含的多个第二特征分量中的至少一个第二特征分量。 然后将每个数据处 理单元所确定的至少一个第一特征分量进行组合得到输出特征。
[0146] 具体地, 可以将多个第二特征分量进行编号, 并按照编号从小到大的顺序将第 二特征分量逐一分配给每个数据处理单元进行处理。 其中, 每个输出特征所包 含的第二特征分量的数量相同。 相应地, 可以根据在每个数据处理单元中进行 处理的第二特征分量, 向每个数据处理单元输入对应的权重系数。 然后, 在每 个数据处理单元中, 根据权重系数, 确定该数据处理单元负责处理的至少一个 第二特征分量中的每个第二特征分量。
[0147] 其中, 为了最大程度的复用输入特征中的每个第一特征分量, 以及最小化数据 处理单元的数据缓存。 在将其中一个第一特征分量应用于每个第二特征分量之 后, 再切换第一特征分量进行计算。
[0148] 在本申请实施例中, 获取针对全连接层的多个输入特征, 所述多个输入特征中 的每个输入特征包括多个第一特征分量, 当获取到的所述多个输入特征的总数 量达到预设阈值时, 首先同时向所述全连接层对应的数据处理单元输入所述多 个输入特征; 接着获取所述多个第一特征分量中的每个第一特征分量在所述全 连接层的输出特征中的权重系数; 然后在所述多个数据处理单元中, 根据所述 多个第一特征分量和所述多个第一特征分量对应的权重系数, 并行确定所述每 个输入特征对应的输出特征。 相比于现有技术中每生成一个输入特征就进行 FC 层计算的方法, 本申请实施例所述的方法中先将输入特征进行累积, 当累积到 一定数量之后, 再利用多个数据处理单元对多个输入特征进行并向计算的方式 。 实现了在仅读取一次权重系数的前提下完成对多个输入特征的 FC层的计算, 从而达到了复用 FC层权重系数的目的, 大大减少了读取权重系数的带宽、 以及 提高了神经网络 MAC的利用率。 此外通过输入特征分量的读取顺序与权重系数 的广播顺序的配合, 将完成计算的无效数据及时删除, 有效减少的数据处理单 元中的数据缓存压力。
[0149] 请参考图 10, 图 10是本申请实施例提供的一种电子设备的结构示意图。 如图所 示, 该电子设备可以包括: 至少一个处理器 1001, 例如 CPU, 至少一个通信接口 1002, 至少一个存储器 1003, 至少一个总线 1004。 其中, 总线 1004用于实现这 些组件之间的连接通信。 其中, 本申请实施例中电子设备的通信接口 1002是有 线发送端口, 也可以为无线设备, 例如包括天线装置, 用于与其他节点设备进 行信令或数据的通信。 存储器 1003可以是高速 RAM存储器, 也可以是非不稳定 的存储器 (non-volatile memory) , 例如至少一个磁盘存储器。 存储器 1003可选 的还可以是至少一个位于远离前述处理器 1001的存储装置。 存储器 1003中存储 一组程序代码, 且处理器 1001用于调用存储器中存储的程序代码, 用于执行以 下操作:
[0150] 获取针对全连接层的多个输入特征, 所述多个输入特征中的每个输入特征包括 多个第一特征分量;
[0151] 当获取到的所述多个输入特征的总数量达到第一预设阈值时, 同时向所述全连 接层对应的多个数据处理单元输入所述多个输入特征;
[0152] 获取所述多个第一特征分量中的每个第一特征分量在所述全连接层的输出特征 中的权重系数;
[0153] 在所述多个数据处理单元中, 根据所述多个第一特征分量和所述多个第一特征 分量对应的权重系数, 并行确定所述每个输入特征对应的输出特征。 。 [0154] 其中, 处理器 1001还用于执行如下操作步骤:
[0155] 同时向所述多个数据处理单元中的每个数据处理单元输入所述多个输入特征中 的一个输入特征;
[0156] 其中, 处理器 1001还用于执行如下操作步骤:
[0157] 在所述每个数据处理单元中, 根据所述一个输入特征中的所述多个第一特征分 量和所述多个第一特征分量对应的权重系数, 确定所述一个输入特征对应的输 出特征。
[0158] 其中, 处理器 1001还用于执行如下操作步骤:
[0159] 同时向所述多个数据处理单元中的每个数据处理单元输入所述多个输入特征。
[0160] 其中, 处理器 1001还用于执行如下操作步骤:
[0161] 在所述每个数据处理单元中, 根据所述每个输入特征中的所述多个第一特征分 量和所述多个第一特征分量对应的所述权重系数, 确定所述每个输入特征对应 的输出特征所包含的多个第二特征分量中的至少一个第二特征分量;
[0162] 将所述每个数据处理单元所确定的所述至少一个第二特征分量进行组合得到所 述每个输入特征对应的输出特征。
[0163] 其中, 所述一个输入特征对应的输出特征包括多个第二特征分量;
[0164] 处理器 1001还用于执行如下操作步骤:
[0165] 根据所述多个第一特征分量对应的权重系数, 确定所述一个输入特征中的所述 每个第一特征分量对所述多个第二特征分量中的每个第二特征分量的贡献值;
[0166] 根据所述贡献值, 确定所述一个输入特征对应的输出特征。
[0167] 其中, 处理器 1001还用于执行如下操作步骤:
[0168] 从所述每个数据处理单元中删除已确定所述贡献值的第一特征分量。
[0169] 其中, 处理器 1001还用于执行如下操作步骤:
[0170] 根据所述多个第一特征分量对应的权重系数, 确定所述每个输入特征中的所述 每个第一特征分量对所述至少一个第二特征分量中的每个第二特征分量的贡献 值;
[0171] 根据所述贡献值, 确定所述至少一个第二特征分量。
[0172] 其中, 处理器 1001还用于执行如下操作步骤: [0173] 确定存储所述权重系数所需的存储空间;
[0174] 当所述存储空间小于第二预设阈值时, 执行所述获取所述多个第一特征分量中 的每个第一特征分量在所述全连接层的输出特征中的权重系数的操作。
[0175] 需要说明的是, 本申请实施例同时也提供了一种存储介质, 该存储介质用于存 储应用程序, 该应用程序用于在运行时执行图 2和图 6所示的一种全连接层的实 现方法中电子设备执行的操作。
[0176] 需要说明的是, 本申请实施例同时也提供了一种应用程序, 该应用程序用于在 运行时执行图 2和图 6所示的一种全连接层的实现方法中电子设备执行的操作。

Claims

权利要求书
[权利要求 i] 一种全连接层的实现方法, 其特征在于, 所述方法包括:
获取针对全连接层的多个输入特征, 所述多个输入特征中的每个输入 特征包括多个第一特征分量;
当获取到的所述多个输入特征的总数量达到第一预设阈值时, 同时向 所述全连接层对应的多个数据处理单元输入所述多个输入特征; 获取所述多个第一特征分量中的每个第一特征分量在所述全连接层的 输出特征中的权重系数;
在所述多个数据处理单元中, 根据所述多个第一特征分量和所述多个 第一特征分量对应的权重系数, 并行确定所述每个输入特征对应的输 出特征。
[权利要求 2] 如权利要求 1所述的方法, 其特征在于, 所述同时向所述全连接层对 应的多个数据处理单元输入所述多个输入特征包括:
同时向所述多个数据处理单元中的每个数据处理单元输入所述多个输 入特征中的一个输入特征;
所述在所述多个数据处理单元中, 根据所述多个第一特征分量和所述 多个第一特征分量对应的权重系数, 并行确定所述每个输入特征对应 的输出特征包括:
在所述每个数据处理单元中, 根据所述一个输入特征中的所述多个第 一特征分量和所述多个第一特征分量对应的权重系数确定所述一个输 入特征对应的输出特征。
[权利要求 3] 如权利要求 1所述的方法, 其特征在于, 所述同时向所述全连接层对 应的多个数据处理单元输入所述多个输入特征包括:
同时向所述多个数据处理单元中的每个数据处理单元输入所述多个输 入特征;
所述在所述多个数据处理单元中, 根据所述多个第一特征分量和所述 多个第一特征分量对应的所述权重系数, 并行确定所述每个输入特征 对应的输出特征包括: 在所述每个数据处理单元中, 根据所述每个输入特征中的所述多个第 一特征分量和所述多个第一特征分量对应的权重系数, 确定所述每个 输入特征对应的输出特征所包含的多个第二特征分量中的至少一个第 二特征分量;
将所述每个数据处理单元所确定的所述至少一个第二特征分量进行组 合得到所述每个输入特征对应的输出特征。
[权利要求 4] 如权利要求 2所述的方法, 其特征在于, 所述一个输入特征对应的输 出特征包括多个第二特征分量;
所述根据所述一个输入特征中的所述多个第一特征分量和所述多个第 一特征分量对应的权重系数, 确定所述一个输入特征对应的输出特征 包括:
根据所述多个第一特征分量对应的权重系数, 确定所述一个输入特征 中的所述每个第一特征分量对所述多个第二特征分量中的每个第二特 征分量的贡献值;
根据所述贡献值, 确定所述一个输入特征对应的输出特征。
[权利要求 5] 如权利要求 4所述的方法, 其特征在于, 所述根据所述多个第一特征 分量对应的权重系数, 确定所述一个输入特征中的所述每个第一特征 分量对所述多个第二特征分量中的每个第二特征分量的贡献值之后, 还包括:
从所述每个数据处理单元中删除已确定所述贡献值的第一特征分量。
[权利要求 6] 如权利要求 3所述的方法, 其特征在于, 所述根据所述每个输入特征 中的所述多个第一特征分量和所述多个第一特征分量对应的权重系数 , 确定所述每个输入特征对应的输出特征所包含的多个第二特征分量 中的至少一个第二特征分量包括:
根据所述多个第一特征分量对应的权重系数, 确定所述每个输入特征 中的所述每个第一特征分量对所述至少一个第二特征分量中的每个第 二特征分量的贡献值;
根据所述贡献值, 确定所述至少一个第二特征分量。
[权利要求 7] 如权利要求 1-6任一项所述的方法, 其特征在于, 所述获取所述多个 第一特征分量中的每个第一特征分量在所述全连接层的输出特征中的 权重系数之前, 还包括:
确定存储所述权重系数所需的存储空间;
当所述存储空间小于第二预设阈值时, 执行所述获取所述多个第一特 征分量中的每个第一特征分量在所述全连接层的输出特征中的权重系 数的操作。
[权利要求 8] 一种全连接层的实现装置, 其特征在于, 所述装置包括:
获取模块, 用于获取针对全连接层的多个输入特征, 所述多个输入特 征中的每个输入特征包括多个第一特征分量;
传输模块, 用于当获取到的所述多个输入特征的总数量达到第一预设 阈值时, 同时向所述全连接层对应的多个数据处理单元输入所述多个 输入特征;
所述获取模块, 还用于获取所述多个第一特征分量中的每个第一特征 分量在所述全连接层的输出特征中的权重系数; 处理模块, 所述处理模块中包括所述全连接层对应的多个数据处理单 元, 用于根据所述权重系数和所述多个第一特征分量, 并行确定所述 每个输入特征对应的输出特征。
[权利要求 9] 一种电子设备, 其特征在于, 包括: 处理器、 存储器、 通信接口和总 线;
所述处理器、 所述存储器和所述通信接口通过所述总线连接并完成相 互间的通信;
所述存储器存储可执行程序代码;
所述处理器通过读取所述存储器中存储的可执行程序代码来运行与所 述可执行程序代码对应的程序, 以用于执行如权利要求 1-7任一项所 述的全连接层的实现方法。
[权利要求 10] 一种计算机可读存储介质, 其特征在于, 所述计算机可读存储介质存 储有多条指令, 所述指令适于由处理器加载并执行如权利要求 1-7任 一项所述的全连接层的实现方法。
PCT/CN2019/114085 2018-11-19 2019-10-29 一种全连接层的实现方法、装置、电子设备及计算机可读存储介质 WO2020103653A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201811375742.7 2018-11-19
CN201811375742.7A CN111199268B (zh) 2018-11-19 2018-11-19 一种全连接层的实现方法、装置、电子设备及计算机可读存储介质

Publications (2)

Publication Number Publication Date
WO2020103653A1 true WO2020103653A1 (zh) 2020-05-28
WO2020103653A9 WO2020103653A9 (zh) 2020-07-02

Family

ID=70745912

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/114085 WO2020103653A1 (zh) 2018-11-19 2019-10-29 一种全连接层的实现方法、装置、电子设备及计算机可读存储介质

Country Status (2)

Country Link
CN (1) CN111199268B (zh)
WO (1) WO2020103653A1 (zh)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107766935A (zh) * 2016-08-22 2018-03-06 耐能有限公司 多层人造神经网络
US20180096249A1 (en) * 2016-10-04 2018-04-05 Electronics And Telecommunications Research Institute Convolutional neural network system using adaptive pruning and weight sharing and operation method thereof
CN108122030A (zh) * 2016-11-30 2018-06-05 华为技术有限公司 一种卷积神经网络的运算方法、装置和服务器
CN108805267A (zh) * 2018-05-28 2018-11-13 重庆大学 用于卷积神经网络硬件加速的数据处理方法

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107239824A (zh) * 2016-12-05 2017-10-10 北京深鉴智能科技有限公司 用于实现稀疏卷积神经网络加速器的装置和方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107766935A (zh) * 2016-08-22 2018-03-06 耐能有限公司 多层人造神经网络
US20180096249A1 (en) * 2016-10-04 2018-04-05 Electronics And Telecommunications Research Institute Convolutional neural network system using adaptive pruning and weight sharing and operation method thereof
CN108122030A (zh) * 2016-11-30 2018-06-05 华为技术有限公司 一种卷积神经网络的运算方法、装置和服务器
CN108805267A (zh) * 2018-05-28 2018-11-13 重庆大学 用于卷积神经网络硬件加速的数据处理方法

Also Published As

Publication number Publication date
CN111199268B (zh) 2023-04-07
WO2020103653A9 (zh) 2020-07-02
CN111199268A (zh) 2020-05-26

Similar Documents

Publication Publication Date Title
WO2018196863A1 (zh) 卷积加速和计算处理方法、装置、电子设备及存储介质
CN109948774B (zh) 基于网络层捆绑运算的神经网络加速器及其实现方法
CN112449009B (zh) 一种基于svd的联邦学习推荐系统通信压缩方法及装置
CN111178491A (zh) 神经网络模型的训练和应用方法、装置、系统及存储介质
WO2019084788A1 (zh) 用于神经网络的运算装置、电路及相关方法
CN110351780B (zh) 一种基于编码缓存的通信方法、系统及存储介质
US20180139137A1 (en) Arranging media access control protocol data units in a wireless transmission
WO2022027917A1 (zh) 图像处理方法、装置、系统、电子设备及可读存储介质
CN109995467B (zh) 一种资源映射方法及装置、设备
WO2021147276A1 (zh) 数据处理方法、装置及芯片、电子设备、存储介质
WO2024016659A1 (zh) 工作量证明芯片及其处理方法
CN112532665A (zh) 一种服务器负载均衡的方法、装置及cdn节点
WO2020103653A1 (zh) 一种全连接层的实现方法、装置、电子设备及计算机可读存储介质
CN116934573A (zh) 数据读写方法、存储介质及电子设备
CN101566933B (zh) 一种配置缓存的方法、装置和电子设备及数据读写装置
WO2020107319A1 (zh) 图像处理方法和设备,以及视频处理器
CN116129501A (zh) 人脸位姿估计方法及装置
CN113316159B (zh) 基于异构物理层的5g网络系统
CN111432384B (zh) 用于具有录音功能设备的大数据量音频蓝牙实时传输方法
CN111915492B (zh) 一种基于动态重建的多分支视频超分辨率方法及系统
CN113627587A (zh) 一种多通道式卷积神经网络加速方法及装置
WO2020134550A1 (zh) 数据压缩方法及相关装置
CN114625891A (zh) 多媒体数据处理方法、装置和系统
CN105681112A (zh) 一种实现多级承诺访问速率控制的方法及相关设备
WO2020134548A1 (zh) 人脸抓拍方法及相关装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19888170

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19888170

Country of ref document: EP

Kind code of ref document: A1