In-memory computing unit design method and system for mixed-precision neural networks
Through dual-mode reconfigurable multiplication unit and lightweight interface design, the mixed-precision vector multiply-accumulate calculation method is improved, which solves the problem of high energy consumption of data communication in hardware accelerators and realizes a low-power, high-efficiency mixed-precision neural network. Computing, adapting to multiple storage technologies.
Patent Information
- Application Number
- CN202410376716.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-29
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-03-29
AI Technical Summary
In the existing technology, in hardware accelerators, mixed-precision multiply-accumulate calculations have high energy and time consumption caused by frequent data communication, and the design of in-memory calculation precision reconfigurable computing accelerators has high complexity and low adaptability, and cannot meet the needs of diversification. Model accuracy requirements.
It adopts dual-mode reconfigurable multiplication unit and lightweight interface design, and uses an improved mixed-precision vector multiplication-accumulation calculation method, combined with zero-padding operations and splicing multiplication, to filter the product results, solve the problem of large bit-width multipliers, and reduce data Transmission energy consumption.
It achieves low power consumption and high computing efficiency of hardware unit design under the 28nm process, adapts to a variety of storage technologies, reduces energy consumption and time delays caused by data transmission, and meets diverse model accuracy requirements.
Smart Images

Figure CN118278477B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of in-memory computing units, and in particular to a method and system for designing an in-memory computing unit for a mixed-precision neural network. Background Art
[0002] There are two main ways to accelerate neural networks on common hardware, namely accelerators and in-memory computing. The following lists the advantages and disadvantages of these two hardware acceleration methods.
[0003] First, the implementation method of the accelerator. The prior art uses a binary segmentation algorithm as the basis for mixed-precision multiplication and accumulation calculation acceleration, but its acceleration unit also needs to frequently communicate data with the storage module, which brings about a large amount of additional energy consumption and time consumption. The prior art also proposes a module for accelerating the multiplication and accumulation of floating-point numbers of different precisions, but there is also a problem of data communication between the acceleration unit and the storage module, which fails to reduce energy consumption to a greater extent.
[0004] The existing technology also proposes a computing accelerator with reconfigurable computing accuracy that uses in-memory computing technology. Although this part of the work provides better energy efficiency, it has high design complexity and low adaptability to different storage technologies. For example, it is only applicable to static random access memory composed of six transistors. Although additional changes have been made to traditional static random access memory, the supported reconfigurable computing accuracy is limited and cannot meet the increasingly diverse model accuracy requirements.
[0005] Patent document CN113610222A discloses a method for calculating convolution operation of a neural network, the method comprising: a processor is configured to perform a preset calculation accuracy; obtaining at least one pair of multipliers and multiplicands, and the mantissas of the multipliers and multiplicands are respectively encoded as multiple fixed-point basic precision data, and performing fixed-point multiplication operations according to program instructions, the multiplier is convolution kernel weight data, and the multiplicand is input data; when the processor is configured for basic calculation accuracy multiplication, the multiplier and multiplicand are correspondingly multiplied with the basic precision data as a unit, and the current precision multiplication result is calculated, and / or, when the processor is configured for first calculation accuracy multiplication, the multiplier and multiplicand are divided into high-bit and low-bit data represented by low-precision digits, and calculated according to preset variable precision multiplication instructions, and the high-bit and low-bit of the multiplier and multiplicand can be divided into at least one basic precision data representation. However, this patent cannot completely solve the existing technical problems, nor can it meet the needs of the present invention. Summary of the invention
[0006] In view of the defects in the prior art, the object of the present invention is to provide a method and system for designing an in-memory computing unit for a mixed-precision neural network.
[0007] The method for designing an in-memory computing unit for a mixed-precision neural network provided by the present invention includes:
[0008] Step 1: Adapt the mixed precision multiplication and accumulation calculation on hardware to the existing binary segmentation algorithm to obtain an improved mixed precision vector multiplication and accumulation calculation method;
[0009] Step 2: Using a dual-mode reconfigurable multiplication unit to solve the problem of large bit-width multipliers required by the improved mixed-precision vector multiplication-accumulation calculation method, and obtaining the hardware unit design of the improved mixed-precision vector multiplication-accumulation calculation method;
[0010] Step 3: Use lightweight interface design in combination with a dual-mode reconfigurable multiplication unit, and based on the improved mixed-precision vector multiplication accumulation calculation method, improve the hardware design of pre-processing of operands before multiplication and post-processing of results after multiplication.
[0011] Preferably, the step 1 comprises:
[0012] Step 1.1: Use the data with a width of 2 to 8 bits in mixed precision quantization as operands. For single operand bit widths of 2 to 7 bits, calculate the bit width of each element of the vector operand after the zero-padding operation according to the formula: single operand bit width after zero-padding operation = 2*longest single operand bit width + batch calculation size. For single operand bit widths of 8 bits, no zero-padding operation is required.
[0013] Step 1.2: concatenate each element of the zero-filled vector operands, concatenate one of the vector operands in the original order, and reverse all the zero-filled elements of the other vector operand, and finally obtain two long bit strings;
[0014] Step 1.3: Multiply the two long bit strings to get a product;
[0015] Step 1.4: Filter out some bit strings in the product, the filtering range is: [batch calculation size * single operand bit width after zero padding operation - 1: (batch calculation size - 1) * single operand bit width after zero padding operation], and obtain the true product accumulation result of the concatenated vector operands;
[0016] Step 1.5: For the convolutional layers in the neural network model whose size exceeds the preset range, repeat steps 1.1 to 1.4, and accumulate the results of multiple steps 1.4 to obtain the final result.
[0017] Preferably, the step 2 comprises:
[0018] The dual-mode reconfigurable multiplication unit performs a 32*32-bit multiplication operation, and the dual-mode reconfigurable multiplication unit is composed of four sub-multiplication units connected into four stages, each sub-multiplication unit performs an 8*32-bit multiplication operation, and each sub-multiplication unit receives a partial product result calculated in the previous stage and outputs the product result of the stage;
[0019] The sub-multiplication unit is composed of three multiplexers, a multiplier, an adder and a register. The multiplier and multiplicand inputs of the sub-multiplication unit are selected by two multiplexers respectively. The internal / external data is determined according to the level of the mode control signal is_pipe currently applied to the multiplication unit. If is_pipe is at a high level, the internal multiplier and the internal multiplicand are used, multiplied in the multiplier, and then added to the internal product stored in the register input from the previous stage in the adder, and finally the single-stage product of the current sub-multiplication unit is obtained, which is selected and output by the last multiplexer by is_pipe; if is_pipe is at a low level, the external multiplier and the external multiplicand are used, multiplied, and each sub-multiplication unit works independently without using the internal product input from the previous stage in the register, and the current stage product is output independently and is selected and output by is_pipe via the last multiplexer.
[0020] Preferably, the control signal for mode switching is is_pipe. When is_pipe is at a high level, the current mode is pipeline mode, and the four sub-multipliers jointly calculate a 32*32-bit multiplication, and each sub-multiplier undertakes a partial multiplication of 8*32 bits; when is_pipe is at a low level, the current mode is parallel mode, and the four sub-multipliers work independently, each undertaking an independent 8*32-bit multiplication.
[0021] Preferably, step 3 comprises: when the operand to be calculated enters the data buffer, the hardware unit of the improved mixed precision vector multiplication and accumulation calculation method reads the idle data in the buffer and starts calculation in advance, completes the zero padding operation and puts the processed operand bit string into the operand register, and the dual-mode reconfigurable multiplication unit reads the operand bit string to be calculated from the operand register for multiplication calculation, and the calculation mode here is controlled by the is_pipe signal sent by the controller, and then the selector screens the result obtained in the dual-mode reconfigurable multiplication unit, if the current is_pipe When the pe signal is high, the selector result will directly enter the reconfigurable accumulator. If the size of the currently calculated convolution layer exceeds the preset range and requires multiple calculations, the reconfigurable accumulator will be started for accumulation until the final product accumulation result is obtained. If the is_pipe signal is currently low, the result of the selector will be ignored. At this time, the product of each sub-multiplication unit in the dual-mode reconfigurable multiplication unit will be added in pairs and finally enter the reconfigurable accumulator for the last addition. If the size of the currently calculated convolution layer exceeds the preset range, the reconfigurable accumulator will be started for accumulation until the final result is obtained.
[0022] The in-memory computing unit design system for mixed-precision neural networks provided by the present invention includes:
[0023] Module M1: Adapt the mixed precision multiplication and accumulation calculation on hardware to the existing binary segmentation algorithm, and obtain an improved mixed precision vector multiplication and accumulation calculation method;
[0024] Module M2: A dual-mode reconfigurable multiplication unit is used to solve the problem of large bit-width multipliers required by the improved mixed-precision vector multiplication-accumulation calculation method, and the hardware unit design of the improved mixed-precision vector multiplication-accumulation calculation method is obtained;
[0025] Module M3: Using lightweight interface design, combined with dual-mode reconfigurable multiplication unit, based on the improved mixed-precision vector multiplication accumulation calculation method, improve the pre-processing of the operator before multiplication and the post-processing hardware design of the result after multiplication.
[0026] Preferably, the module M1 comprises:
[0027] Module M1.1: Use the data with a width of 2 to 8 bits in mixed precision quantization as operands. For single operand bit widths of 2 to 7 bits, calculate the bit width of each element of the vector operand after the zero-padding operation according to the formula: single operand bit width after zero-padding operation = 2*longest single operand bit width + batch calculation size. For single operand bit widths of 8 bits, no zero-padding operation is required.
[0028] Module M1.2: concatenate each element of the zero-filled vector operands, concatenate one of the vector operands in the original order, and reverse all the zero-filled elements of the other vector operand, and finally obtain two long bit strings;
[0029] Module M1.3: Multiply two long bit strings to obtain a product;
[0030] Module M1.4: Filter out some bit strings in the product, the filtering range is: [batch calculation size * single operand bit width after zero padding operation - 1: (batch calculation size - 1) * single operand bit width after zero padding operation], and obtain the true product accumulation result of the concatenated vector operands;
[0031] Module M1.5: For convolutional layers in the neural network model whose size exceeds the preset range, repeatedly trigger modules M1.1 to M1.4, and accumulate the results of multiple modules M1.4 to obtain the final result.
[0032] Preferably, the module M2 comprises:
[0033] The dual-mode reconfigurable multiplication unit performs a 32*32-bit multiplication operation, and the dual-mode reconfigurable multiplication unit is composed of four sub-multiplication units connected into four stages, each sub-multiplication unit performs an 8*32-bit multiplication operation, and each sub-multiplication unit receives a partial product result calculated in the previous stage and outputs the product result of the stage;
[0034] The sub-multiplication unit is composed of three multiplexers, a multiplier, an adder and a register. The multiplier and multiplicand inputs of the sub-multiplication unit are selected by two multiplexers respectively. The internal / external data is determined according to the level of the mode control signal is_pipe currently applied to the multiplication unit. If is_pipe is at a high level, the internal multiplier and the internal multiplicand are used, multiplied in the multiplier, and then added to the internal product stored in the register input from the previous stage in the adder, and finally the single-stage product of the current sub-multiplication unit is obtained, which is selected and output by the last multiplexer by is_pipe; if is_pipe is at a low level, the external multiplier and the external multiplicand are used, multiplied, and each sub-multiplication unit works independently without using the internal product input from the previous stage in the register, and the current stage product is output independently and is selected and output by is_pipe via the last multiplexer.
[0035] Preferably, the control signal for mode switching is is_pipe. When is_pipe is at a high level, the current mode is pipeline mode, and the four sub-multipliers jointly calculate a 32*32-bit multiplication, and each sub-multiplier undertakes a partial multiplication of 8*32 bits; when is_pipe is at a low level, the current mode is parallel mode, and the four sub-multipliers work independently, each undertaking an independent 8*32-bit multiplication.
[0036] Preferably, the module M3 comprises: when the operand to be calculated enters the data buffer, the hardware unit of the improved mixed precision vector multiplication accumulation calculation method reads the idle data in the buffer and starts calculation in advance, completes the zero padding operation and puts the processed operand bit string into the operand register, and the dual-mode reconfigurable multiplication unit reads the operand bit string to be calculated from the operand register for multiplication calculation. The calculation mode here is controlled by the is_pipe signal sent by the controller, and then the selector screens the results obtained in the dual-mode reconfigurable multiplication unit. If the current is_pipe When the pe signal is high, the selector result will directly enter the reconfigurable accumulator. If the size of the currently calculated convolution layer exceeds the preset range and requires multiple calculations, the reconfigurable accumulator will be started for accumulation until the final product accumulation result is obtained. If the is_pipe signal is currently low, the result of the selector will be ignored. At this time, the product of each sub-multiplication unit in the dual-mode reconfigurable multiplication unit will be added in pairs and finally enter the reconfigurable accumulator for the last addition. If the size of the currently calculated convolution layer exceeds the preset range, the reconfigurable accumulator will be started for accumulation until the final result is obtained.
[0037] Compared with the prior art, the present invention has the following beneficial effects:
[0038] (1) After logic synthesis and simulation tests on the above design under 28nm process technology, the hardware unit design proposed in the present invention achieved an area of 1778μm2 and a power consumption of 1.82mW at a clock frequency of 500MHz, a throughput of 4-16GOPS during calculation, and an energy efficiency of 2.14-8.56TOPS / W;
[0039] (2) By adopting the vector multiplication and accumulation calculation method based on the binary segmentation algorithm, the effect of adaptive mixed precision convolution calculation is achieved;
[0040] (3) The problem of large bit-width multipliers required for the improved mixed-precision vector multiplication-accumulation calculation method is solved by adopting the design of dual-mode reconfigurable multipliers.
[0041] (4) By adopting a lightweight interface design to directly connect the designed hardware unit with the data storage module, the energy consumption and time delay caused by data transmission are reduced, and adaptability to multiple storage technologies is also achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0043] Figure 1 This is a schematic diagram of the mixed precision vector multiplication and accumulation calculation process based on binary segmentation;
[0044] Figure 2 This is a conceptual diagram of a dual-mode reconfigurable multiplication unit;
[0045] Figure 3 The figure is the internal structure diagram of the sub-multiplication unit in the dual-mode reconfigurable multiplication unit;
[0046] Figure 4 The execution principle diagram of the dual-mode reconfigurable multiplication unit (left: pipeline mode execution; right: parallel mode execution);
[0047] Figure 5 A structural diagram is used for a mixed-precision multiply-accumulate acceleration unit that can adapt to different storage technologies. DETAILED DESCRIPTION
[0048] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.
[0049] Example 1
[0050] The present invention provides an in-memory computing unit design for a mixed-precision neural network, comprising the following steps:
[0051] Step 1, adapting the mixed precision multiplication and accumulation calculation on hardware to the existing binary segmentation algorithm to obtain an improved mixed precision vector multiplication and accumulation calculation method;
[0052] Step 2, proposing a dual-mode reconfigurable multiplication unit to solve the problem of large bit-width multipliers required by the improved mixed-precision vector multiplication accumulation calculation method;
[0053] Step three, obtain the hardware unit implementation of the improved mixed-precision vector multiplication and accumulation calculation method, use lightweight interface design, combine with the dual-mode reconfigurable multiplication unit, and according to the improved mixed-precision vector multiplication and accumulation calculation method, improve the hardware design of pre-processing of operands before multiplication and post-processing of results after multiplication.
[0054] In step 1, the binary segmentation algorithm is an existing algorithm, and the present invention mainly refers to the method for calculating the vector inner product. The vector inner product calculation is to multiply the elements of the corresponding positions in two vector operands of the same length by two, and finally add all the multiplication results. The existing binary segmentation algorithm is used to calculate the vector inner product. First, the order of the elements of one of the vector operands is reversed. For example, the original vector operand is [v0, v1, ..., v n-1 ], then becomes [v n-1 ,...,v1,v0]. Then, fill each element in the two vector operands with zeros, and then concatenate them sequentially. The formula for zero filling is "bit width of a single operand after zero filling = 2*bit width of the longest single operand + vector length". For example, the original vector operand is [2,3], which becomes [000010,000011] after zero filling, and becomes the bit string 000010000011 after sequential concatenation. Multiply the two bit strings, and finally filter the obtained product. The selection range is [vector length*bit width of a single element after zero filling-1:(vector length-1)*bit width of a single element after zero filling] to get the final result;
[0055] In step 1, the present invention improves the existing binary segmentation algorithm to adapt to mixed precision multiplication and accumulation calculations. The improvement process is mainly to optimize hardware and energy consumption. It is impossible to complete the inner product calculation of each element in a vector of any length at the same time. It is necessary to segment and batch calculate some single operands with large bit widths and vector operands that are too long. In addition, the present invention only focuses on the two to eight bit width data commonly used in mixed precision quantization as operands;
[0056] In step 1, the specific measures of the improved mixed precision vector multiplication and accumulation calculation method can be referred to in the provided drawing. Figure 1 , the whole can be further divided into five steps:
[0057] Step 1, for a single operand bit width of 2 to 7 bits, the bit width of each element of the vector operand after the zero-padding operation is calculated according to the formula "single operand bit width after zero-padding operation = 2*longest single operand bit width + batch calculation size". For a single operand bit width of 8 bits, no zero-padding operation is required in consideration of the additional calculation cost;
[0058] Step 2, concatenate each element of the vector operands after the zero padding. For one of the vector operands, it is sufficient to concatenate them in the original arrangement order, and for the other vector operand, all its zero-padded elements need to be reversed, and finally two long bit strings are obtained;
[0059] Step 3, multiplying the two long bit strings obtained in step 2 to obtain a product;
[0060] Step 4, filter out some bit strings in the product obtained in step 3, and the range of the filter is "[batch calculation size * single operand bit width after zero padding operation - 1: (batch calculation size - 1) * single operand bit width after zero padding operation]", and obtain the true product accumulation result of the vector operands obtained by splicing in step 2;
[0061] Step 5 is an optional step. For a smaller convolutional layer in the neural network model, the result obtained in step 4 is the final result. For a larger convolutional layer in the neural network model, steps 1 to 4 need to be repeated, and the results of multiple steps 4 are accumulated to obtain the final result.
[0062] In step 2, the concept of the dual-mode reconfigurable multiplication unit can be referred to in the provided drawings. Figure 2 , the unit can perform 32*32 bit multiplication operations. The unit is composed of four sub-multiplication units connected into four stages. Each sub-multiplication unit can perform 8*32 bit multiplication operations, and each sub-multiplication unit can receive the partial product result calculated in the previous stage and output the product result of this stage;
[0063] In step 2, the internal structure of the sub-multiplication unit can refer to the provided drawing. Figure 3 , the unit is composed of three multiplexers, a multiplier, an adder and a register. The multiplier and multiplicand inputs of the unit are selected by two multiplexers respectively. The internal / external data is determined according to the level of the mode control signal "is_pipe" currently applied to the multiplication unit. If "is_pipe" is high, the internal multiplier and the internal multiplicand are used, multiplied in the multiplier, and then added to the internal product stored in the register input from the previous stage in the adder, and finally the single-stage product of the current sub-multiplication unit is obtained, which is selected and output by the last multiplexer by "is_pipe"; if "is_pipe" is low, the external multiplier and the external multiplicand are used, multiplied, and each sub-multiplication unit works independently, without using the internal product input from the previous stage in the register, and the current stage product is output independently, and is selected and output by the last multiplexer by "is_pipe";
[0064] In step 2, how to switch the mode of the dual-mode reconfigurable multiplication unit and how each mode operates can be referred to Figure 4 , the control signal for mode switching is "is_pipe". When "is_pipe" is high, the current mode is pipeline mode, and the four sub-multipliers jointly calculate a 32*32-bit multiplication, and each sub-multiplier undertakes a partial multiplication of 8*32 bits. When "is_pipe" is low, the current mode is parallel mode, and the four sub-multipliers work independently, each undertaking an independent 8*32-bit multiplication;
[0065] In step 3, the hardware unit design of the improved mixed precision vector multiplication and accumulation calculation method and its connection with the storage array can be referred to in the provided drawings. Figure 5 , wherein the storage array can be any existing storage technology. When the operands to be calculated enter the data buffer, the hardware unit of the improved mixed precision vector multiplication and accumulation calculation method is Figure 5 The acceleration module can read the idle data in the buffer and start the calculation in advance. In the acceleration module, the zero-filling unit completes the logic of step 1 and step 2 in step one and puts the processed operand bit string into the operand register. The dual-mode reconfigurable multiplication unit in step two will read the operand bit string to be calculated from the operand register for multiplication calculation. The calculation mode here is also controlled by the "is_pipe" signal sent by the controller. Then the selector will filter the results obtained in the dual-mode reconfigurable multiplication unit according to the steps, and proceed according to the method of step 4 in step one. Finally, if the current When the "is_pipe" signal is high, the selector result will directly enter the reconfigurable accumulator. If the convolution layer currently being calculated is large and requires multiple calculations, the reconfigurable accumulator will be started for accumulation operations until the final product accumulation result is obtained. If the current "is_pipe" signal is low, the result of the selector will be ignored. At this time, the product of each sub-multiplication unit in the dual-mode reconfigurable multiplication unit will be added in pairs and finally enter the reconfigurable accumulator for the last addition. Similarly, if the convolution layer being calculated this time is large, the reconfigurable accumulator will be started for accumulation operations until the final result is obtained.
[0066] Example 2
[0067] The present invention also provides an in-memory computing unit design system for mixed-precision neural networks. The in-memory computing unit design system for mixed-precision neural networks can be implemented by executing the process steps of the in-memory computing unit design method for mixed-precision neural networks, that is, those skilled in the art can understand the in-memory computing unit design method for mixed-precision neural networks as a preferred implementation of the in-memory computing unit design system for mixed-precision neural networks.
[0068] The in-memory computing unit design system for mixed-precision neural networks provided by the present invention includes: module M1: performing hardware adaptation of the mixed-precision multiplication and accumulation calculation on the existing binary segmentation algorithm to obtain an improved mixed-precision vector multiplication and accumulation calculation method; module M2: adopting a dual-mode reconfigurable multiplication unit to solve the problem of large-bit-width multipliers required for the improved mixed-precision vector multiplication and accumulation calculation method, and obtaining the hardware unit design of the improved mixed-precision vector multiplication and accumulation calculation method; module M3: using a lightweight interface design, combined with a dual-mode reconfigurable multiplication unit, according to the improved mixed-precision vector multiplication and accumulation calculation method, to improve the hardware design of pre-processing of operands before multiplication and post-processing of results after multiplication.
[0069] The module M1 includes: module M1.1: using data with a width of two to eight bits in mixed precision quantization as operands, for a single operand bit width of two to seven bits, according to the formula: single operand bit width after zero padding = 2*longest single operand bit width + batch calculation size, the bit width of each element of the vector operand after the zero padding operation is calculated, and for a single operand bit width of eight bits, no zero padding operation is required; module M1.2: splicing each element of the vector operand after zero padding, splicing one of the vector operands in the original arrangement order, and splicing all the zero-padded elements of the other vector operand Reverse and finally get two long bit strings; module M1.3: multiply the two long bit strings to get a product; module M1.4: filter out some bit strings in the product, and the screening range is: [batch calculation size * single operand bit width after zero padding operation-1: (batch calculation size-1) * single operand bit width after zero padding operation], and get the true product accumulation result of the concatenated vector operands; module M1.5: for the convolution layer in the neural network model whose size exceeds the preset range, repeatedly trigger module M1.1 to module M1.4, and accumulate the results of multiple modules M1.4 to get the final result.
[0070] The module M2 includes: the dual-mode reconfigurable multiplication unit performs a 32*32-bit multiplication operation, the dual-mode reconfigurable multiplication unit is composed of four sub-multiplication units connected into four stages, each sub-multiplication unit performs an 8*32-bit multiplication operation, and each sub-multiplication unit receives the partial product result calculated in the previous stage and outputs the product result of the stage; the sub-multiplication unit is composed of three multiplexers, a multiplier, an adder and a register, the multiplier and multiplicand inputs of the sub-multiplication unit are selected by two multiplexers respectively, and the mode control signal is_pipe currently applied to the multiplication unit is judged according to its level. Using internal / external data, if is_pipe is high, the internal multiplier and the internal multiplicand are used, multiplied in the multiplier, and then added to the internal product stored in the register input from the previous stage in the adder, and finally the single-stage product of the current sub-multiplication unit is obtained, which is selected and output by the last multiplexer by is_pipe; if is_pipe is low, the external multiplier and the external multiplicand are used, multiplied, and each sub-multiplication unit works independently, without using the internal product of the previous stage input in the register, and the current stage product is output independently, and is selected and output by is_pipe through the last multiplexer.
[0071] The control signal for mode switching is is_pipe. When is_pipe is high, the current mode is pipeline mode. The four sub-multipliers jointly calculate a 32*32-bit multiplication, and each sub-multiplier undertakes a partial multiplication of 8*32 bits. When is_pipe is low, the current mode is parallel mode. The four sub-multipliers work independently and each undertakes an independent 8*32-bit multiplication.
[0072] The module M3 includes: when the operand to be calculated enters the data buffer, the hardware unit of the improved mixed precision vector multiplication and accumulation calculation method reads the idle data in the buffer and starts calculation in advance, completes the zero padding operation and puts the processed operand bit string into the operand register, and the dual-mode reconfigurable multiplication unit reads the operand bit string to be calculated from the operand register for multiplication calculation. The calculation mode here is controlled by the is_pipe signal sent by the controller, and then the selector screens the results obtained in the dual-mode reconfigurable multiplication unit. If the current is_pipe is The signal is high, the selector result will directly enter the reconfigurable accumulator. If the size of the convolution layer currently calculated exceeds the preset range and requires multiple calculations, the reconfigurable accumulator will be started for accumulation until the final product accumulation result is obtained; if the current is_pipe signal is low, the result of the selector will be ignored. At this time, the product of each sub-multiplication unit in the dual-mode reconfigurable multiplication unit will be added in pairs and finally enter the reconfigurable accumulator for the last addition. If the size of the convolution layer currently calculated exceeds the preset range, the reconfigurable accumulator will be started for accumulation until the final result is obtained.
[0073] Those skilled in the art know that, in addition to implementing the system, device and its various modules provided by the present invention in a purely computer-readable program code, it is entirely possible to implement the same program in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers and embedded microcontrollers by logically programming the method steps. Therefore, the system, device and its various modules provided by the present invention can be considered as a hardware component, and the modules included therein for implementing various programs can also be considered as structures within the hardware component; the modules for implementing various functions can also be considered as both software programs for implementing the method and structures within the hardware component.
[0074] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. A design method for in-memory computing units for mixed-precision neural networks. It is characterized in that include: Step 1: Adapt the mixed precision multiplication and accumulation calculation on hardware to the existing binary segmentation algorithm to obtain an improved mixed precision vector multiplication and accumulation calculation method; Step 2: Using a dual-mode reconfigurable multiplication unit to solve the problem of large bit-width multipliers required by the improved mixed-precision vector multiplication-accumulation calculation method, and obtaining the hardware unit design of the improved mixed-precision vector multiplication-accumulation calculation method; Step 3: Using lightweight interface design, combined with dual-mode reconfigurable multiplication units, and based on the improved mixed-precision vector multiplication accumulation calculation method, improve the hardware design of pre-processing of operators before multiplication and post-processing of results after multiplication; The step 1 comprises: Step 1.1: Use the data with a width of 2 to 8 bits in mixed precision quantization as operands. For single operand bit widths of 2 to 7 bits, calculate the bit width of each element of the vector operand after the zero-padding operation according to the formula: single operand bit width after zero-padding operation = 2*longest single operand bit width + batch calculation size. For single operand bit widths of 8 bits, no zero-padding operation is required. Step 1.2: concatenate each element of the zero-filled vector operands, concatenate one of the vector operands in the original order, and reverse all the zero-filled elements of the other vector operand, and finally obtain two long bit strings; Step 1.3: Multiply the two long bit strings to get a product; Step 1.4: Filter out some bit strings in the product, the filtering range is: [batch calculation size * single operand bit width after zero padding operation - 1: (batch calculation size - 1) * single operand bit width after zero padding operation], and obtain the true product accumulation result of the concatenated vector operands; Step 1.5: For the convolutional layers in the neural network model whose size exceeds the preset range, repeat steps 1.1 to 1.4, and accumulate the results of multiple steps 1.4 to obtain the final result; The step 2 comprises: The dual-mode reconfigurable multiplication unit performs a 32*32-bit multiplication operation, and the dual-mode reconfigurable multiplication unit is composed of four sub-multiplication units connected into four stages, each sub-multiplication unit performs an 8*32-bit multiplication operation, and each sub-multiplication unit receives a partial product result calculated in the previous stage and outputs the product result of the stage; The sub-multiplication unit is composed of three multiplexers, a multiplier, an adder and a register. The multiplier and multiplicand inputs of the sub-multiplication unit are selected by two multiplexers respectively. The internal / external data is determined according to the level of the mode control signal is_pipe currently applied to the multiplication unit. If is_pipe is at a high level, the internal multiplier and the internal multiplicand are used, multiplied in the multiplier, and then added to the internal product stored in the register input from the previous stage in the adder, and finally the single-stage product of the current sub-multiplication unit is obtained, which is selected and output by the last multiplexer by is_pipe; if is_pipe is at a low level, the external multiplier and the external multiplicand are used, multiplied, and each sub-multiplication unit works independently without using the internal product input from the previous stage in the register, and the current stage product is output independently and is selected and output by is_pipe via the last multiplexer.
2. The method for designing an in-memory computing unit for a mixed-precision neural network according to claim 1, It is characterized in that The control signal for mode switching is is_pipe. When is_pipe is high, the current mode is pipeline mode. The four sub-multipliers jointly calculate a 32*32-bit multiplication, and each sub-multiplier undertakes a partial multiplication of 8*32 bits. When is_pipe is low, the current mode is parallel mode. The four sub-multipliers work independently and each undertakes an independent 8*32-bit multiplication.
3. The method for designing an in-memory computing unit for a mixed-precision neural network according to claim 1, It is characterized in that The step 3 comprises: when the operand to be calculated enters the data buffer, the hardware unit of the improved mixed precision vector multiplication and accumulation calculation method reads the idle data in the buffer and starts calculation in advance, completes the zero padding operation and puts the processed operand bit string into the operand register, and the dual-mode reconfigurable multiplication unit reads the operand bit string to be calculated from the operand register for multiplication calculation, and the calculation mode here is controlled by the is_pipe signal sent by the controller, and then the selector screens the result obtained in the dual-mode reconfigurable multiplication unit, if the current is_pipe is The signal is high, the selector result will directly enter the reconfigurable accumulator. If the size of the convolution layer currently calculated exceeds the preset range and requires multiple calculations, the reconfigurable accumulator will be started for accumulation until the final product accumulation result is obtained; if the current is_pipe signal is low, the result of the selector will be ignored. At this time, the product of each sub-multiplication unit in the dual-mode reconfigurable multiplication unit will be added in pairs and finally enter the reconfigurable accumulator for the last addition. If the size of the convolution layer currently calculated exceeds the preset range, the reconfigurable accumulator will be started for accumulation until the final result is obtained.
4. A system for designing in-memory computing units for mixed-precision neural networks. It is characterized in that include: Module M1: Adapt the mixed precision multiplication and accumulation calculation on hardware to the existing binary segmentation algorithm, and obtain an improved mixed precision vector multiplication and accumulation calculation method; Module M2: A dual-mode reconfigurable multiplication unit is used to solve the problem of large bit-width multipliers required by the improved mixed-precision vector multiplication-accumulation calculation method, and the hardware unit design of the improved mixed-precision vector multiplication-accumulation calculation method is obtained; Module M3: Using lightweight interface design, combined with dual-mode reconfigurable multiplication unit, based on the improved mixed-precision vector multiplication accumulation calculation method, improve the pre-processing of the operator before multiplication and the post-processing hardware design of the result after multiplication; The module M1 comprises: Module M1.1: Use the data with a width of 2 to 8 bits in mixed precision quantization as operands. For single operand bit widths of 2 to 7 bits, calculate the bit width of each element of the vector operand after the zero-padding operation according to the formula: single operand bit width after zero-padding operation = 2*longest single operand bit width + batch calculation size. For single operand bit widths of 8 bits, no zero-padding operation is required. Module M1.2: concatenate each element of the zero-filled vector operands, concatenate one of the vector operands in the original order, and reverse all the zero-filled elements of the other vector operand, and finally obtain two long bit strings; Module M1.3: Multiply two long bit strings to obtain a product; Module M1.4: Filter out some bit strings in the product, the filtering range is: [batch calculation size * single operand bit width after zero padding operation - 1: (batch calculation size - 1) * single operand bit width after zero padding operation], and obtain the true product accumulation result of the concatenated vector operands; Module M1.5: For convolutional layers in the neural network model whose size exceeds the preset range, repeatedly trigger modules M1.1 to M1.4, and accumulate the results of multiple modules M1.4 to obtain the final result; The module M2 comprises: The dual-mode reconfigurable multiplication unit performs a 32*32-bit multiplication operation, and the dual-mode reconfigurable multiplication unit is composed of four sub-multiplication units connected into four stages, each sub-multiplication unit performs an 8*32-bit multiplication operation, and each sub-multiplication unit receives a partial product result calculated in the previous stage and outputs the product result of the stage; The sub-multiplication unit is composed of three multiplexers, a multiplier, an adder and a register. The multiplier and multiplicand inputs of the sub-multiplication unit are selected by two multiplexers respectively. The internal / external data is determined according to the level of the mode control signal is_pipe currently applied to the multiplication unit. If is_pipe is at a high level, the internal multiplier and the internal multiplicand are used, multiplied in the multiplier, and then added to the internal product stored in the register input from the previous stage in the adder, and finally the single-stage product of the current sub-multiplication unit is obtained, which is selected and output by the last multiplexer by is_pipe; if is_pipe is at a low level, the external multiplier and the external multiplicand are used, multiplied, and each sub-multiplication unit works independently without using the internal product input from the previous stage in the register, and the current stage product is output independently and is selected and output by is_pipe via the last multiplexer.
5. The system for designing an in-memory computing unit for a mixed-precision neural network according to claim 4, It is characterized in that The control signal for mode switching is is_pipe. When is_pipe is high, the current mode is pipeline mode. The four sub-multipliers jointly calculate a 32*32-bit multiplication, and each sub-multiplier undertakes a partial multiplication of 8*32 bits. When is_pipe is low, the current mode is parallel mode. The four sub-multipliers work independently and each undertakes an independent 8*32-bit multiplication.
6. The system for designing an in-memory computing unit for a mixed-precision neural network according to claim 4, It is characterized in that The module M3 includes: when the operand to be calculated enters the data buffer, the hardware unit of the improved mixed precision vector multiplication and accumulation calculation method reads the idle data in the buffer and starts calculation in advance, completes the zero padding operation and puts the processed operand bit string into the operand register, and the dual-mode reconfigurable multiplication unit reads the operand bit string to be calculated from the operand register for multiplication calculation. The calculation mode here is controlled by the is_pipe signal sent by the controller, and then the selector screens the results obtained in the dual-mode reconfigurable multiplication unit. If the current is_pipe is The signal is high, the selector result will directly enter the reconfigurable accumulator. If the size of the convolution layer currently calculated exceeds the preset range and requires multiple calculations, the reconfigurable accumulator will be started for accumulation until the final product accumulation result is obtained; if the current is_pipe signal is low, the result of the selector will be ignored. At this time, the product of each sub-multiplication unit in the dual-mode reconfigurable multiplication unit will be added in pairs and finally enter the reconfigurable accumulator for the last addition. If the size of the convolution layer currently calculated exceeds the preset range, the reconfigurable accumulator will be started for accumulation until the final result is obtained.
Citation Information
Patent Citations
Method and system for calculating neural network convolution operation, and hardware device
CN113610222A
CGRA-oriented multi-precision small-area SIMD operation system and method, medium and equipment
CN115904507A
