Processing apparatus and processing method

By designing a processing device with dynamically configurable calculation bit width, and using memory, data width adjustment circuit and computing circuit, the problem of data bit width changes in neural network calculations is solved, the computing efficiency and flexibility are improved, and an efficient neural network is realized calculate.

CN118690805APending Publication Date: 2024-09-24SHANGHAI CAMBRICON INFORMATION TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202410405915.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2017-04-21
Filing Date
2018-04-17
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

Existing deep learning processors have poor dynamic requirements for data bit width in neural network calculations, resulting in low operational efficiency and inability to effectively meet the changing needs of data bit width in neural network calculations.

Method used

A processing device with dynamically configurable calculation bit width is designed, including a memory, a data width adjustment circuit, an arithmetic circuit and a control circuit. Different calculation bit widths can be realized by adjusting the data bit width through control instructions and selecting appropriate multipliers and adders. Neural network data operations.

Benefits of technology

It improves the computing speed of the neural network, meets the requirements of data bit width diversity and dynamic variability of data bit width during the operation process, and has the advantages of strong flexibility, high degree of configurability, fast operation speed, and low power consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118690805A
    Figure CN118690805A
Patent Text Reader

Abstract

A processing device with dynamically configurable calculation bit width comprises a memory used for storing data including to-be-calculated data, an intermediate calculation result, a final calculation result and to-be-cached data; the data width adjusting circuit is used for adjusting the widths of the data to be operated, the intermediate operation result, the final operation result and / or the data to be cached; the operation circuit is used for operating the to-be-operated data, and an adder circuit and a multiplier are adopted to calculate the to-be-operated data with different calculation bit widths; and a control circuit for controlling the memory, the data width adjustment circuit, and the arithmetic circuit. The device disclosed by the invention has the advantages of high flexibility, high configurable degree, high operation speed, low power consumption and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computers, and further to a processing device and a processing method in the field of artificial intelligence. Background Art

[0002] With the advent of the big data era, neural network algorithms have become a research hotspot in the field of artificial intelligence in recent years, and have been widely used in pattern recognition, image analysis, intelligent robots, and other aspects.

[0003] Deep learning is a method in machine learning based on learning to represent data. Observations (such as an image) can be represented in a variety of ways, such as a vector of intensity values ​​for each pixel, or more abstractly represented as a series of edges, regions of a specific shape, etc. Using certain specific representation methods makes it easier to learn characters from examples (for example, face recognition or facial expression recognition).

[0004] There are several deep learning architectures, such as deep neural networks, convolutional neural networks, deep belief networks, and recurrent neural networks, which have been applied to computer vision, speech recognition, natural language processing, audio recognition, and bioinformatics, and have achieved excellent results. In addition, deep learning has become a similar term, or a rebranding of neural networks.

[0005] With the popularity of deep learning (neural networks), neural network accelerators have also emerged. Through the design of special memory and computing modules, neural network accelerators can achieve dozens or even hundreds of times the acceleration ratio of general-purpose processors when performing deep learning operations, and have a smaller area and lower power consumption. Summary of the invention

[0006] The present disclosure provides a processing device with dynamically configurable computing bit width, comprising:

[0007] A memory, used to store data, wherein the data includes data to be calculated, intermediate calculation results, final calculation results and data to be cached of the neural network;

[0008] A data width adjustment circuit, used for adjusting the width of the data to be calculated, the intermediate calculation result, the final calculation result and / or the data to be cached;

[0009] An operation circuit, used for operating the data to be operated by the neural network; and

[0010] The control circuit is used to control the memory, the data width adjustment circuit and the operation circuit.

[0011] The present disclosure also provides a method for using a processing device with dynamically configurable computing bit width, comprising the steps of:

[0012] The control circuit generates a control instruction and transmits it to the memory, the data width adjustment circuit and the operation circuit;

[0013] The memory inputs the data to be calculated of the neural network into the calculation circuit according to the received control instruction;

[0014] The data width adjustment circuit adjusts the width of the data to be operated by the neural network according to the received control instruction;

[0015] The operation circuit selects corresponding types of multiplier and adder circuits in the first operation module according to the received control instruction;

[0016] The operation circuit operates on the data to be operated of the neural network with different calculation bit widths according to the input data to be operated, neural network parameters and control instructions.

[0017] The present disclosure also provides a processing device, including: a memory for storing data, wherein the data includes data to be operated on the neural network; an operation circuit for operating on the data to be operated on the neural network, including using an adder circuit and a multiplier to calculate the data to be operated on the neural network with different calculation bit widths; and a control circuit for controlling the memory and the operation circuit, including determining the types of the multiplier and adder circuits of the operation circuit according to the data to be operated for performing the operation.

[0018] The present disclosure also provides a method for using the above-mentioned processing device, comprising the steps of: a control circuit generates a control instruction and transmits it to a memory and an operation circuit; the memory inputs the data to be operated of the neural network into the operation circuit according to the received control instruction; the operation circuit selects the corresponding type of multiplier and adder circuits in the first operation module according to the received control instruction; the operation circuit operates on the data to be operated of the neural network with different calculation bit widths according to the input data to be operated, the neural network parameters and the control instruction, and sends the operation results back to the memory.

[0019] The present disclosure also provides a computing device, including: an input module, used to obtain input data, the input data includes data to be processed, a network structure and weight data, or the input data includes data to be processed and / or offline model data; a model generation module, used to build an offline model according to the input network structure and weight data; a neural network computing module, used to generate and cache computing instructions based on the offline model, and to perform computing on the data to be processed based on the computing instructions to obtain computing results; an output module, used to output the computing results; and a control module, used to detect the type of input data and control the input module, the model generation module and the neural network computing module to perform computing.

[0020] The present disclosure also proposes a computing method using the computing device, comprising the following steps:

[0021] Get input data;

[0022] Obtain an offline model, or determine an offline model based on input data, and determine operation instructions based on the offline model for subsequent calculation calls;

[0023] The operation instruction is called to operate the data to be processed to obtain the operation result for output.

[0024] The present disclosure also provides a device supporting compound scalar instructions, including a controller module, a storage module and an operator module, wherein: the storage module is used to store compound scalar instructions and data, the data has more than one type, and different types of data are stored in different addresses in the storage module; the controller module is used to read the compound scalar instructions from the storage module and decode them into control signals; the operator module is used to receive the control signal, read the data from the storage module, determine the data type according to the address of the read data, and perform operations on the data.

[0025] The present disclosure also provides a processor for executing a compound scalar instruction, wherein the compound scalar instruction includes an opcode field, an operand address field, and a destination address field; the opcode stored in the opcode field is used to distinguish different types of operations, the operand address field is used to distinguish the type of operand, and the destination address field is the address where the operation result is stored.

[0026] The present disclosure also provides a method for executing a composite scalar instruction, comprising the following steps: storing different types of data in different addresses; decoding the composite scalar instruction into a control signal;

[0027] The operation data is read according to the control signal, the type of the operation data is determined according to the address of the read operation data, and the operation data is operated; and the operation result is stored in the address of the corresponding type.

[0028] The present disclosure also provides a counting device, including: a register unit, a counting unit and a storage unit, wherein the register unit is used to store the address of the input data to be counted stored in the storage unit; the counting unit is connected to the register unit and is used to obtain a counting instruction, read the storage address of the input data in the register unit according to the counting instruction, obtain the corresponding input data to be counted in the storage unit, and perform statistical counting on the number of elements in the input data that meet given conditions to obtain a counting result; the storage unit is connected to the counting unit and is used to store the input data to be counted and to store the counting result.

[0029] The present disclosure also provides a counting method for the above-mentioned counting device, comprising the following steps: a counting unit obtains a counting instruction, obtains the corresponding input data to be counted in the storage unit according to the storage address of the input data read in the register unit according to the counting instruction, and performs statistical counting on the number of elements in the input data that meet given conditions to obtain a counting result; and transmits the statistical counting result to the storage unit. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0031] Figure 1 It is a structural diagram of a processing device with dynamically configurable computing bit width provided by an embodiment of the present disclosure.

[0032] Figure 2 It is a schematic diagram of the structure of a processing device with dynamically configurable computing bit width provided by another embodiment of the present disclosure.

[0033] Figure 3 It is a schematic diagram of a structure in which the computing bit width is dynamically configurable provided by yet another embodiment of the present disclosure.

[0034] Figure 4 It is a structural diagram of another embodiment of a processing device with dynamically configurable computing bit width provided by yet another embodiment of the present disclosure.

[0035] Figure 5 It is a schematic diagram of a bit serial addition tree device used in the device according to an embodiment of the present disclosure.

[0036] Figure 6 It is a block diagram of a bit serial operator in a processing device with dynamically configurable computing bit width disclosed in the present invention.

[0037] Figure 7 It is a structural diagram of a first basic multiplier device of an embodiment provided by the present disclosure.

[0038] Figure 8 It is a structural diagram of a second basic multiplier device of an embodiment provided by the present disclosure.

[0039] Fig. 9 It is a structural diagram of a sparse multiplier device according to an embodiment of the present disclosure.

[0040] Fig.10It is a structural diagram of a device for performing vector multiplication using a basic multiplier or a sparse multiplier according to an embodiment of the present disclosure.

[0041] Fig.11 It is a structural diagram of a device for performing vector multiplication by fusing a vector multiplier according to an embodiment provided by the present disclosure.

[0042] Fig.12 It is a structural schematic diagram of the specific implementation process of the fused vector multiplier device and other multiplier devices provided by the present disclosure.

[0043] Fig.13 It is a schematic diagram of combining a second basic multiplier and a bit serial addition tree according to an embodiment of the present disclosure.

[0044] Fig.14 It is a flow chart of a processing method for dynamically configurable calculation bit width provided by an embodiment of the present disclosure.

[0045] Fig.15 It is a structural diagram of a processing device with dynamically configurable computing bit width provided by another embodiment of the present disclosure.

[0046] Fig.16 It is a schematic diagram of the structure of a processing device with dynamically configurable computing bit width provided by another embodiment of the present disclosure.

[0047] Fig.17 It is a schematic diagram of the structure of a processing device with dynamically configurable computing bit width provided in yet another embodiment of the present disclosure.

[0048] Fig.18 It is a structural diagram of another embodiment of a processing device with dynamically configurable computing bit width provided by yet another embodiment of the present disclosure.

[0049] Fig.19 It is a structural diagram of a basic multiplier device of an embodiment provided by the present disclosure.

[0050] Fig. 20 It is a structural diagram of a sparse multiplier device according to an embodiment of the present disclosure.

[0051] Fig.21 It is a structural diagram of a device for performing vector multiplication using a basic multiplier or a sparse multiplier according to an embodiment of the present disclosure.

[0052] Fig. 22 It is a structural diagram of a device for performing vector multiplication by fusing a vector multiplier according to an embodiment provided by the present disclosure.

[0053] Fig.23 It is a structural schematic diagram of the specific implementation process of the fused vector multiplier device and other multiplier devices provided by the present disclosure.

[0054] Fig.24 It is a flow chart of a processing method for dynamically configurable calculation bit width provided by an embodiment of the present disclosure.

[0055] Fig.25 It is a typical programming framework diagram.

[0056] Fig.26 It is a calculation flow chart of a calculation method proposed in one embodiment of the present disclosure.

[0057] Fig. 27 It is a structural framework diagram of a computing device proposed in another embodiment of the present disclosure.

[0058] Fig.28 is a schematic diagram of the structure of a computing device provided by an embodiment of the present disclosure;

[0059] Fig.29A is an example diagram of a RAM organization form of a storage module provided by an embodiment of the present disclosure;

[0060] Fig.29B is an example diagram of a storage module register stack organization form provided by an embodiment of the present disclosure;

[0061] Fig. 30A is an example diagram of a composite scalar instruction provided by an embodiment of the present disclosure;

[0062] Fig. 30B is an example diagram of a compound scalar instruction when register addressing is adopted provided by an embodiment of the present disclosure;

[0063] Fig. 30C is an example diagram of a compound scalar instruction when register indirect addressing is adopted according to an embodiment of the present disclosure;

[0064] Fig.30D is an example diagram of a compound scalar instruction when using immediate addressing provided by an embodiment of the present disclosure;

[0065] Fig.30E is an example diagram of a compound scalar instruction when RAM addressing is adopted provided by an embodiment of the present disclosure;

[0066] Fig.31 It is a flow chart of an operation method supporting compound scalar instructions provided by an embodiment of the present disclosure.

[0067] Fig.32 Schematic diagram of the framework structure of the counting device according to the embodiment of the present disclosure.

[0068] Fig.33 Schematic diagram of the structure of a counting unit in a counting device according to an embodiment of the present disclosure.

[0069] Fig.34 for Fig.33Schematic diagram of the adder structure in the counting unit.

[0070] Fig.35 Schematic diagram of the instruction set format of the counting instruction in the counting device according to the embodiment of the present disclosure.

[0071] Fig.36 The figure is a flow chart of the execution process of the counting unit in the counting device according to the embodiment of the present disclosure.

[0072] Fig.37 It is a schematic diagram of the structure of the counting device according to the embodiment of the present disclosure.

[0073] Fig.38 The figure is a flow chart of the execution process of the counting device according to the embodiment of the present disclosure. DETAILED DESCRIPTION

[0074] The following is a clear and complete description of the technical solutions in the embodiments of the present disclosure in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. Based on the embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.

[0075] The "memory" described in the present disclosure can be integrated inside a processing device with dynamically configurable computing bit width, or it can be a separate device, used as an external memory to perform data transmission with the processing device with dynamically configurable computing bit width. The memory can be integrated inside a processing device with dynamically configurable computing bit width, or it can be a separate device, used as an external memory to perform data transmission with the processing device with dynamically configurable computing bit width.

[0076] Figure 1 is a schematic diagram of the structure of a processing device with dynamically configurable computing bit width provided by an embodiment of the present disclosure. Figure 1 As shown, the device includes a control circuit, a data width adjustment circuit, an operation circuit and a memory.

[0077] The control circuit is used to send control signals to the data width adjustment circuit, the operation circuit and the memory to control the operation of the three and coordinate the data transmission between the three. The memory is used to store relevant data, which may include input data (including data to be operated and control instructions), intermediate operation results, final operation results, neurons, synapses, data to be cached, etc. The specific storage data content, storage organization method and access call method can be planned differently according to different needs. Figure 1As shown, the data width adjustment circuit is used to adjust the width of data. This process may occur after the data is read from the memory, the data is adjusted by the data width adjustment circuit and then passed to the operation circuit, the operation circuit adjusts the data by the data width adjustment circuit and then passes the calculation result to the memory, and the memory adjusts the data by the data width adjustment circuit and then passes it back to the memory. Its specific operation is controlled by the control signal of the control circuit. Its specific operation includes increasing, decreasing or keeping the data bit width unchanged without losing precision; increasing, decreasing or keeping the data bit width unchanged with an acceptable degree of precision loss; increasing, decreasing or keeping the data bit width unchanged according to a certain specified transformation or operation requirement (such as specifying a "bitwise AND" operation), etc. The operation circuit may include at least one adder and at least one multiplier for data operation. At least one adder includes an adder, an addition tree, and / or a serial addition tree; at least one multiplier includes a basic multiplier, a sparse multiplier and / or a fused vector multiplier. The operation circuit may also include a comparator and / or an ALU, etc., wherein the multiplier and the adder can perform operations on data of different calculation bit widths, and operations between operation data of different bit widths can be performed according to different requirements. The multiplier may be a serial operator, which implements multiplication operations in a bit-serial manner. It should be noted that the operation circuit may also directly transmit data to the memory without passing through the data bit width adjustment circuit.

[0078] Figure 2 FIG. 1 is a schematic diagram of a structure of a processing device for dynamically configurable computing bit width according to an embodiment of the present disclosure. Figure 2As shown, the structure of the device is that the control circuit connects each module or submodule of the memory and the operation circuit, including at least one control signal register and at least one control processor, the control signal register is used to store the control signal, and optionally, the control signal register is first-in-first-out. The control processor is used to take out the control signal to be executed, analyze the control logic, and control and coordinate the memory, the data width adjustment circuit and the operation circuit. The memory includes an input storage module, an output storage module, and a synaptic storage module, wherein the output storage module can be used to store intermediate operation results and final operation results. The data width adjustment circuit can be divided into an input data processing module and an output data processing module, the input data processing module is used to adjust the data width in the input storage module and / or the synaptic storage module, and it can be set at the back end of the input storage module; the output data processing module is used to store the output data processing module after the data after the operation of the operation circuit is adjusted in width; the operation circuit is mainly used to accelerate the convolution operation of the convolution layer and the fully connected layer and the average or maximum value operation of the pooling layer. Optionally, the operation circuit may include a multiplier module, an addition tree module and a nonlinear operation module (e.g., a module that performs sigmoid function operations). The multiplier module, the addition tree module and the nonlinear operation module may be executed in parallel in a pipeline manner. The device can accelerate the operation process of the convolutional neural network, reduce data exchange between the chip and the outside, and save storage space.

[0079] Figure 3 FIG. 1 is a schematic diagram of the structure of a processing device according to another embodiment of the present disclosure. Figure 3As shown, the structure of the present device is that the control circuit connects each module of the memory and the operation circuit, including a control signal register and a control processor for storing control signals. The control processor is used to take out the control signal to be executed, and after analyzing the control logic, the memory and the operation circuit are controlled and coordinated. Optionally, the control signal register is first-in-first-out. The memory includes an input storage module, an output storage module and a synaptic storage module. In the present device, the synaptic storage module includes a plurality of synaptic storage submodules, and the operation circuit includes a plurality of operation modules. The synaptic storage submodules are connected to the operation modules respectively. One synaptic storage submodule can be connected to one operation module, or multiple synaptic storage submodules can be connected to one operation module. The data width adjustment circuit can be divided into an input data processing module and an output data processing module. The input data processing module is used to adjust the data width of the data in the input storage module and / or the synaptic storage module, and it can be set at the back end of the input storage module; the output data processing module is used to adjust the width of the data after the operation of the operation circuit and store it in the output data processing module; each time the operation is performed, the input storage module transmits the input data to all the operation modules after the input data processing module, and the synaptic storage module transmits the synaptic data to the corresponding operation module. After the operation module performs the operation, the output data processing module writes the result to the output storage module. In this way, the operation efficiency is significantly improved in large-scale operations with many parameters. This device can effectively accelerate the operation process of the convolutional neural network, and is particularly suitable for situations where the network scale is relatively large and there are many parameters.

[0080] Figure 4 FIG. 1 is a schematic diagram of the structure of a processing device according to another embodiment of the present disclosure. Figure 4As shown, the structure of the device is that the control circuit connects each module of the memory, the operation circuit and the data width adjustment circuit, including an instruction queue and a decoder. Each time a new instruction is executed, a new instruction is taken out from the instruction queue and sent to the decoder, which is decoded by the decoder and the control information is sent to each module of the memory, the operation circuit and the data width adjustment circuit. The memory includes an input storage module, an output storage module, a synaptic storage module and a cache module, wherein the output storage module can be used to store intermediate operation results and final operation results. Among them, each time the input storage module and the synaptic storage module transfer data to the operation circuit, the data is first transferred to the cache module. Then, the data in the cache is read to the data width adjustment circuit. If the control instruction requires the data to be processed, the corresponding processing is completed in the data width adjustment circuit, such as expanding the bit width of the data without losing precision, forcibly deleting the lowest bit of the data to reduce the data bit width, etc. After being processed by the data width adjustment circuit, it is sent to the corresponding operation module. If the control instruction does not need to process the data, the data can be directly transferred to the corresponding operation module through the data width adjustment circuit. Similarly, when the operation module completes the operation, the result is also first sent to the data width adjustment circuit, and according to the control instruction, after completing the data processing operation or not operating the data, it is transmitted to the cache module, and then written from the cache module to the output storage module. The operation circuit includes multiple operation modules, including a first operation module and a second operation module. The operation modules can perform related operations in parallel, or transfer data to each other, thereby reducing the reuse distance of local data and further improving the operation speed. The first operation module is mainly used to accelerate linear operations with the same or different calculation bit widths in the neural network algorithm, including: matrix multiplication, addition, multiplication mixed addition; matrix and vector; matrix and constant; between vectors; vector and constant; constant and constant, and can also be used for comparison operations, selection of maximum / minimum values, etc., and the preferred operations include dot product, matrix multiplication and / or matrix addition operations. The second operation module is used to complete the unfinished operations in the above-mentioned first operation module, including nonlinear operations, division operations, separate addition operations or separate multiplication operations. The advantage of this is that the bit width of the data can be dynamically adjusted during the calculation process according to the control instructions, thereby further improving the hardware utilization of the computing circuit and memory.

[0081] Figure 5 FIG. 1 is a schematic diagram of a bit serial addition tree device used in the device according to an embodiment of the present disclosure, which can meet the requirement of dynamically configurable calculation bit width. Figure 5As shown, there are M data to be operated, and the maximum bit width is N, where M and N are both positive integers. If the data is less than N bits, a reasonable method is used to fill its bit width to N bits without affecting the data accuracy. The methods that can be used include filling the highest / lowest bit with 0, filling the highest / lowest bit with a sign bit, shifting, performing operations, etc. The adders from the first layer to the xth layer in the bit serial addition tree can complete the addition operation of n (n≥1) bits of numbers, and the adder bits in the x+1th layer can complete the addition operation of numbers not less than N bits. First, the carry output terminal Cin in the register and each adder is initially set to 0. Take the lowest n bits of each data to be operated and input them to the a and b terminals of the adder in the first layer respectively. Each adder completes the addition operation of the lowest n bits of the data to be operated transmitted from the a and b terminals, and the result value s is transmitted to the a or b terminal of the adder in the next layer. The obtained carry value Cout is transmitted back to the carry input Cin of the adder at this layer, and the next beat and the transmitted data to be operated are added. The operation of the adder in the previous layer is similar. The incoming data is added, and then the result is passed to the next higher layer, and the carry is passed back to the adder in this layer. Until the xth layer is reached. The adder in the xth layer shifts the operation result, adds it to the original result transmitted from the register, and saves it back to the register. Then, the data to be operated selects the second lowest n bits to be transmitted to the bit serial addition tree to complete the corresponding operation. At this time, Cin in each adder is the carry result output from the Cout terminal of the adder in the previous beat. Preferably, after the operation of the first layer adder is completed, the second batch of n-bit data to be operated can be input. Through parallel operation, the utilization rate of the operator is improved, and the operation speed is further improved. When all operations are completed, the data in the register is the result. In some embodiments, the adder can also be turned off during the operation when the data to be operated (a, b terminals) and the carry input (Cin terminal) input to the adder are all 0, so as to achieve the purpose of saving power consumption.

[0082] Among them, the bit serial operator used in the embodiments of the present disclosure, such as a basic multiplier, is Figure 6As shown, it includes a computing unit, a processing unit, and a storage unit. The computing unit is used to complete multiplication and / or addition operations of one or more bits of data. The input data to be operated comes from the data of the storage unit and / or the data processed by the processing unit. The output operation result is directly transmitted to the storage unit for storage, or transmitted to the processing unit for processing. The processing unit is used to complete processing operations such as data shifting, expanding / reducing the data bit width according to a given rule, and modifying one or more bits of data according to a given rule. The data to be processed comes from the computing unit and / or the storage unit, and the processed data can be transmitted to the computing unit and / or the processing unit. The storage unit is used to store data, including data to be operated, intermediate operation results, final operation results, etc. The storage unit here can be an on-chip cache. Among them, each unit can be further subdivided into multiple units according to its different functions, such as the computing unit can be subdivided into multiplication units, addition units, etc. Specific embodiments of the multiplier in the bit serial operator may include Figure 7 The first basic multiplier of Figure 8 The second basis multiplier of Fig. 9 The sparse multiplier.

[0083] Figure 7 1 is a specific embodiment of the bit serial operator disclosed in the present invention: a schematic diagram of a first basic multiplier device, which can meet the requirement of dynamically configurable computing bit width. The first basic multiplier can be used in the device disclosed in the present invention. Figure 7 As shown, the multiplicand of M bits and the multiplier of N bits, where M and N are both positive integers. Among them, the positions of the multiplier and the multiplicand can be exchanged under the control of the control module. The lower n bits of the multiplier (n is a positive integer, and 1≤n≤N, and optionally 1<n≤N, so as to further improve the parallelism of the operation, make full use of hardware resources, and speed up the operation speed) are input into the input selection circuit, and the lower n bits of the multiplier are respectively "AND" operated with the multiplicand, that is, if the value of the multiplier bit is 1, the multiplicand itself is output, otherwise 0 is output. At the same time, the multiplier is sent to the first shift register for shifting, and the lower n bits are moved out, and the new lower n bits are input to the input selection circuit next time. The result selected by the input selection circuit is input upward to the second shift register for corresponding shifting, and then sent to the addition tree for addition operation. The addition operation here is the data after input selection and shifting and the result of the previous addition operation. After the result is obtained, it is stored in the result register as the intermediate operation result. When the multiplicand is shifted after input selection next time, the result register takes out the intermediate operation result and sends it to the addition tree (device) for addition operation. When all the multipliers are 0, the multiplication operation ends.

[0084] In order to more clearly illustrate the operation flow of the basic multiplier, we give a specific embodiment, assuming that the multiplicand is 10111011, that is, M=8, and the multiplier is 1011, that is, N=4.

[0085] When n=2, that is, each time 2 bits are shifted, the operation process is as follows: first, the lowest 2 bits of the multiplier, 11, are taken out and sent to the input selection circuit together with the multiplicand. The multiplicand itself is selected and sent to the first shift register. The multiplicand corresponding to the lowest bit does not need to be shifted, that is, 10111011, and the multiplicand corresponding to the second lowest bit is shifted left by 1 bit, that is, 101110110, and sent to the addition tree. Since no numbers were added before, the sum of 10111011 and 101110110, that is, 1000110001, is sent to the result register. Then, the multiplier is shifted right by 2 bits and its lowest 2 bits, i.e. 10, are taken and sent to the input selection circuit together with the multiplicand to obtain 0 and 10111011. Then, through the second shift register, 0 is shifted left by 2 bits and is still 0. 10111011 is shifted left by 3 bits to 10111011000, which is sent to the addition tree together with 1000110001 in the result register for operation, and 100000001001 is obtained and sent to the result register. At this time, the multiplier is shifted right by 2 bits, all of which are 0, that is, the operation is completed, and the result register is the final operation result, i.e. 100000001001.

[0086] Figure 8 FIG. 1 is a schematic diagram of a second basic multiplier device for use in the device according to another embodiment of the present disclosure, which can meet the requirement of dynamically configurable computing bit width. Figure 8As shown, the multiplicand is an M-bit multiplicand and the multiplier is an N-bit multiplier, where M and N are both positive integers. The positions of the multiplier and the multiplicand can be exchanged under the control of the control module. The m-th bit of the multiplicand (m is a positive integer, and 1≤m≤M) is input into the input selection circuit, and the lower n bits of the multiplier (n is a positive integer, and 1≤n≤N) are input into the input selection circuit, and the lower m bits of the multiplicand are multiplied with the lower n bits of the multiplier. The multiplier is sent to the first shift register for shifting, and the lower n bits are shifted out, so the new lower n bits are input to the input selection circuit next time. The result after input selection is input upward to the second shift register for corresponding shifting, and then sent to the addition tree for addition. The addition operation here is the data after input selection and shifting and the result of the previous addition operation. After the result is obtained, it is stored in the result register as an intermediate operation result. When the multiplicand is shifted after the input selection next time, the result register takes out the intermediate operation result and sends it to the adder tree (device) for addition operation. When the multipliers are all 0, the multiplicand is sent to the third shift register for shifting, the lower m bits are removed, and the multiplier is taken out from the backup register, and the above steps are repeated for operation. When the multiplicand and the multiplier are both 0, the multiplication operation ends.

[0087] Fig. 9 The figure is a schematic diagram of a sparse multiplier device used in the present device according to an embodiment of the present disclosure, which can meet the requirement of dynamically configurable computing bit width. The sparse multiplier can be used in the case of sparse operations, that is, when the 1 in the binary representation of the multiplier or multiplicand is sparse, then the position of 1 in the multiplier or multiplicand is represented in a sparse manner, which can further improve the effectiveness of the operation and speed up the operation. Fig. 9 As shown, an M-bit multiplicand and an N-bit multiplier, where M and N are both positive integers, that is, the number of bits of the multiplicand and the multiplier here may be equal or unequal. Here, the multiplier uses a sparse representation method, and the position of 1 in the multiplier is represented by an absolute or relative position. Here, the operation modules of the sparse multiplier provided in this embodiment are all configurable, so when different representation methods are used for operation, the device inside the operator can be configured according to demand. For example, when the result register does not need to be shifted when performing an addition operation, the shift register connected to the result register can be configured to be non-operating at this time, and the shift information of the multiplier may not be transmitted to the shift register at this time. It can be understood by those skilled in the art that the relevant specific details can be adjusted accordingly as needed to complete the relevant specific details such as the shift of the multiplicand and the addition operation of the result.

[0088] To more clearly illustrate the operation flow of the sparse multiplier, we give a specific embodiment. Assume that the multiplicand is 10111011, that is, M=8, and the multiplier is 00100010, that is, N=8. When the absolute representation is used to represent the multiplier, the position of 1 in the multiplier is represented by the absolute position. Assume that the rightmost bit of the number is called the 0th bit, the left bit of the 0th bit is called the 1st bit, and so on. Then, the multiplier is represented as (1, 5). At the same time, we require that the shift register connected to the result register in this embodiment does not work, and the data of the multiplier does not need to be transferred to the shift register. Then first take out the first number of the multiplier, that is, 1, indicating that there is a 1 at the 1st bit. Send the multiplicand to the shift register, and then after shifting 1 bit, it is 101110110 and sent to the adder. Since the previous numbers are added, the result sent to the result register is 101110110. Then take out the position of the next 1 of the multiplier, that is, 5, and send it to the shift register together with the multiplicand. In the shift register, the multiplicand is shifted right by 5 bits to obtain 1011101100000, which is sent to the adder. At the same time, the result 101110110 in the result register is taken out. Since the absolute representation method adopted does not require shifting, the result can be directly sent to the adder for addition operation to obtain 1100011010110. The result after the addition operation is sent to the result register again. At this time, all 1s in the multiplier have been calculated, so the operation ends. If the multiplier is represented in a relative manner, and its representation method is defined as the number of bits between each two non-zero numbers starting from the first non-zero digit in the highest bit (leftmost) to the lowest bit. For 00100010, there are 4 bits between the first non-zero digit and the next non-zero digit, and 1 bit between the second non-zero digit and the lowest bit, so it is expressed as (4, 1). Here, we require that the shift registers connected to the result register and the multiplicand in this embodiment need to work. First, take out the first digit 4 of the multiplier and send it to two shift registers. Then shift the multiplicand right by 4 bits, and the data in the result register right by 4 bits and send them to the adder for addition. At this time, the data in the result register is 0, so the addition result 101110110000 is obtained, which is sent to the result register for storage. Then, take out the second digit 1 of the multiplier, and send the value to the shift register to obtain 101110110 and 1011101100000, which are sent to the adder for addition, and the result is 1100011010110. The result is sent to the result register again. At this time, all 1s in the multiplier have been calculated, so the operation is completed. In this way, the sparsity of the data can be effectively utilized, and only valid operations, that is, operations between non-zero data, are performed. This reduces invalid operations, speeds up the operation, and improves the performance-to-power ratio.

[0089] Fig.10FIG. 1 is a schematic diagram of a structure of a device for performing vector multiplication by fusing a vector multiplier according to an embodiment of the present disclosure. Here, we assume that the vector and The inner product value of the corresponding dimension is sent to the multiplier to wait for calculation, such as Fig.11 Here, the requirement and The dimensions are the same, both (N+1), but the bit width of each dimension is not necessarily the same. At the same time, it is assumed that n bits are taken for calculation each time, where n is greater than 1 and not greater than A positive integer representing the bit width of a dimension. First, take the lower n bits of B0 and A0 and send them to an input selection circuit, perform AND operation on the lower n bits of B0 and A0 respectively, and send the selected result to the subsequent shift register for shifting. After shifting, send the result to the addition tree. In this process, each dimension performs the same operation as the first dimension. Then, through the addition tree, add the data sent in these dimensions, and send the values ​​in the result register to the addition tree, perform addition operation together, and send the result after addition operation to the result register. During the operation, B of each dimension i After the value (i=0,1,...,N) is sent to the shift register and shifted right by n bits, the above operation is repeated, that is, the shifted B is obtained. i (i=0,1,……,N) The lowest n bits of the value and the corresponding A i The (i=0,1,……,N) values ​​are sent to the input selection circuit for selection, then sent to the shift register for shifting, and then sent to the addition tree for addition. This process is repeated until each dimension B i (i=0,1,……,N) values ​​are all 0, the operation is completed, and the data in the result register is the final operation result. The multiplier can flexibly configure the bit width of the data to be operated, and there is no need to recount the number of shift bits of the multiplicand every time a group of data is multiplied. At the same time, when the number of data bits is relatively low or the number of vector bits is relatively high, the characteristics of low data bit width and high vector dimension can be greatly utilized, and the process can be executed in parallel in a pipeline manner, reducing the time required for operation, further speeding up the operation speed, and improving the performance-power ratio.

[0090] In order to more clearly illustrate the operation flow of the fused vector multiplier and the difference and advantages of the operation flow of the multiplier and other multipliers, a specific embodiment is given. Fig.10 , Fig.11 and Fig.12 First, we assume and The dimension is 8, that is, N = 7, The bit width is 8 bits, that is Each dimension of A is 8 bits. i ={a i7 …a i1 a i0}, where i = 0, 1, ..., 7; The bit width is 4 bits, that is Each dimension of B is 4 bits. i = {b i3 b i2 b i1 b i0}, where i = 0, 1, ..., 7. Then the vector inner product

[0091] In general, the operation flow when using a basic multiplier or the above-mentioned basic or sparse multiplier (assuming n is 2, that is, each time the multiplier is moved 2 bits) is divided into two stages: first, the products of each component are calculated separately, and then the sum is performed, such as Fig.10 Specifically, for a certain dimension A i and B i The calculation is performed and the shift register is cleared. The first clock cycle takes B i The lowest two digits of b i0 ,b i1 , input selection, shift, send to adder, get A i *b i0 b i1 The value of the shift register is incremented by 2; in the second clock cycle, B i Shift right 2 bits and take the lowest two bits to get the lowest bit b i2 ,b i3 , input selection, shift to get A i *b i2 b i3 , add the result to the previous sum to get the final calculation result A i *b i0 b i1 b i2 b i3 , that is, the final calculation result A of this dimension is obtained i *B i . To perform the operation in the next dimension, enter A i+1 and B i+1 , the shift register is cleared... until each dimension is calculated, and (A0*B0, A1*B1, ..., A7*B7) is obtained, and the calculation of stage 1 is completed. Then, in stage 2, the product is sent to an addition tree for addition operation to obtain the final vector inner product result, that is, In stage 1, one multiplier can be selected to calculate each dimension in turn; or multiple multipliers can be provided for parallel operation to complete the operation of one dimension in one multiplier, such as Fig.11 and 12 When multiple multipliers are used, the multiplier B for each dimension i The shift values ​​need to be re-counted. The multiplier at this stage can be the first basic multiplier, the second basic multiplier or the sparse multiplier.

[0092] The above operators can be used in any combination to complete the required operation. For example, the second basic multiplier and the bit serial addition tree are combined, such as Fig.13 Here, we assume that the vector and The inner product value of the corresponding dimension is sent to the multiplier to wait for calculation, such as Fig.11 Here, the requirement and The dimensions are the same, both (N+1), but the bit width of each dimension is not necessarily the same. At the same time, assume that A is the multiplicand and B is the multiplier. For each operation, A takes the specified m bits and B takes the specified n bits for operation, where m is not greater than A positive integer that is the bit width of one dimension of A positive integer of the bit width of a dimension. First, take the low m bits of A0 and the low n bits of B0 in the multiplier, multiply the low m bits of A0 and the low n bits of B0, and send the selected result to the bit serial addition tree for addition. And save the result in the storage unit. Then, shift B by n bits, multiply it with the low m bits of A, and send it to the bit serial addition tree for addition. At the same time, the data of the original storage unit are shifted by the third shift unit and added together, and the result is saved in the storage unit. After all the operations of B are completed, A is shifted by m bits and re-operated with the n bits of B in sequence. After all the operations are completed, the data in the storage unit at this time is the final operation result required. The multiplier can flexibly configure the bit width of the data to be operated, without the need to save intermediate data, thereby reducing storage overhead. Speed ​​up the operation. At the same time, when the number of data bits is relatively low or the number of vector bits is relatively high, the characteristics of low data width and high vector dimension can be fully utilized. The process can be executed in parallel in a pipeline manner to reduce the time required for operation, further speed up the calculation speed, and improve the performance-power ratio.

[0093] In summary, the use of this device and method can significantly improve the computing speed of the neural network, and at the same time has dynamic configurability, meeting the relevant requirements of the diversity of data bit width and the dynamic variability of data bit width during the operation process, and has the advantages of strong flexibility, high degree of configurability, fast computing speed, and low power consumption.

[0094] According to another aspect of the present disclosure, a processing method for a processing device with dynamically configurable computing bit width is provided. Fig.14 As shown, the steps include:

[0095] S1401 The control circuit generates a control instruction and transmits it to the memory, the data width adjustment circuit and the operation circuit;

[0096] S1402 The memory inputs the data to be calculated of the neural network into the calculation circuit according to the received control instruction;

[0097] S1403 The data width adjustment circuit adjusts the width of the data to be calculated, the intermediate calculation result, the final calculation result and / or the data to be cached according to actual needs;

[0098] S1404 operation circuit selects corresponding type of multiplier and adder circuit bit serial operation unit according to the received control instruction;

[0099] The S1405 operation circuit operates on the data to be operated of neural networks with different calculation bit widths according to the input data to be operated, neural network parameters and control instructions.

[0100] As described above, the data width adjustment circuit in the method of this embodiment can significantly improve the computing speed of the neural network, and at the same time has dynamic configurability to meet the relevant requirements of the diversity of data bit width and the dynamic variability of data bit width during the operation process.

[0101] Furthermore, in step S1403, the first operation module includes using an adder circuit, a basic multiplier, a sparse multiplier and / or a fused vector multiplier to operate on the data to be operated of the neural network. By dynamically selecting a specific adder circuit, a basic multiplier, a sparse multiplier and / or a fused vector multiplier, the processing method can have the characteristics of strong flexibility, high configurability, fast operation speed, low power consumption, etc.

[0102] Hereinafter, another embodiment of a processing device and a processing method for dynamically configurable calculation bit width will be introduced. The scheme introduced below will not include a data width adjustment circuit and functional units related to the data width adjustment circuit.

[0103] Fig.15 FIG. 1 is a schematic diagram of the structure of a processing device provided by another embodiment of the present disclosure. Fig.15 As shown in FIG. 1 , the device is mainly divided into three parts: control circuit, operation circuit and memory. The control circuit sends control signals to the operation circuit and memory to control the operation of the two and coordinate the data transmission between the two. Figure 1The description of each part in the illustrated embodiment will not be repeated here.

[0104] Fig.16 It is a schematic diagram of the structure of a processing device according to an embodiment of the present disclosure. Fig.16 The structure shown is Figure 2 The data width adjustment circuit is removed from the structure shown, that is, the memory is directly connected to the operation circuit, and the corresponding settings can refer to the above. The three modules can be executed in parallel in a pipeline manner. This device can accelerate the operation process of the convolutional neural network, reduce the data exchange between the chip and the outside, and save storage space.

[0105] Fig.17 It is a schematic diagram of the structure of a processing device according to another embodiment of the present disclosure. Fig.17 The structure shown is Figure 3 Similar, except that Fig.17 The data width adjustment circuit does not include the relevant structure and connection relationship. Fig.17 The connection relationships and functions implemented in Figure 3 The corresponding embodiment description is not repeated here. The processing device of this embodiment significantly improves the operation efficiency in large-scale operations with many parameters. This device can effectively accelerate the operation process of the convolutional neural network, especially for situations where the network scale is relatively large and the parameters are relatively large.

[0106] Fig.18 It is a structural diagram of a processing device according to another embodiment of the present disclosure. Fig.18 The structure shown is Figure 4 Similar, except that Fig.18 The data width adjustment circuit does not include the relevant structure and connection relationship. Fig.18 The connection relationships and functions implemented in Figure 4 The corresponding embodiment description is not repeated here.

[0107] Fig.19 FIG. 1 is a schematic diagram of a basic multiplier device used in the device according to another embodiment of the present disclosure, which can meet the requirement of dynamically configurable computing bit width. Fig.19As shown, the multiplicand of M bits and the multiplier of N bits, where M and N are both positive integers, that is, the number of bits of the multiplicand and the multiplier here can be equal or unequal. The lower n bits of the multiplier (n is a positive integer, and 1<n≤N) are input into the input selection circuit. When the lower n values ​​of the multiplier are respectively ANDed with the multiplicand, that is, the value of the multiplier bit is 1, the multiplicand itself is taken, otherwise it is taken as 0. At the same time, the multiplier is sent to the first shift register for shifting, and the lower n bits are shifted out. The next input to the input selection circuit is the new lower n bits. The result after input selection is input upward to the second shift register for corresponding shifting, and then sent to the addition tree for accumulation. What is accumulated here is the data after input selection and shifting and the result of previous accumulation. After the result is obtained, it is stored in the result register as an intermediate result. When the multiplicand is shifted after input selection next time, the result register takes out the intermediate result and sends it to the addition tree (device) for accumulation. When all multipliers are 0, the multiplication operation ends.

[0108] In order to more clearly illustrate the operation flow of the basic multiplier, we give a specific embodiment, assuming that the multiplicand is 10111011, that is, M=8, and the multiplier is 1011, that is, N=4.

[0109] When n=2, that is, each time 2 bits are shifted, the operation process is as follows: first, the lowest 2 bits of the multiplier, 11, are taken out and sent to the input selection circuit together with the multiplicand. The multiplicand itself is selected and sent to the first shift register. The multiplicand corresponding to the lowest bit does not need to be shifted, that is, 10111011, and the multiplicand corresponding to the second lowest bit is shifted left by 1 bit, that is, 101110110, and sent to the addition tree. Since no numbers were added before, the sum of 10111011 and 101110110, that is, 1000110001, is sent to the result register. Then, the multiplier is shifted right by 2 bits and its lowest 2 bits, i.e. 10, are taken and sent to the input selection circuit together with the multiplicand to obtain 0 and 10111011. Then, through the shift register, 0 is shifted left by 2 bits and is still 0. 10111011 is shifted left by 3 bits to 10111011000, which is sent to the addition tree together with 1000110001 in the result register for operation, and 100000001001 is obtained and sent to the result register. At this time, the multiplier is shifted right by 2 bits, and all are 0, that is, the operation is completed, and the result register is the final result, i.e. 100000001001.

[0110] Fig. 20 The sparse multiplier device schematic diagram of an embodiment of the present disclosure used in the present device can meet the requirement of dynamically configurable computing bit width. As the name implies, the sparse multiplier is aimed at the case of sparse operations, that is, when the multiplier or multiplicand represents the position of 1 in a sparse representation, it can further improve the effectiveness of the operation and speed up the operation. Fig. 20 As shown, there is an M-bit multiplicand and an N-bit multiplier, where M and N are both positive integers, that is, the number of bits of the multiplicand and the multiplier here can be equal or unequal. Here, the multiplier is represented by a sparse representation method, and the position of 1 in the multiplier is represented by an absolute or relative position. Here, our operation circuit is configurable, so when different representation methods are used for calculations, the device inside the operator can be configured according to requirements. For example, when the result register is accumulated without shifting, it can be stipulated that the shift register connected to the result register does not work at this time, and the shift information of the multiplier may not be passed to the shift register at this time. The relevant specific details can be adjusted accordingly as needed to complete the shift of the multiplicand and the accumulation of the results and other related specific details.

[0111] To more clearly illustrate the operation flow of the sparse multiplier, we give a specific embodiment. Assume that the multiplicand is 10111011, that is, M=8, and the multiplier is 00100010, that is, N=8. When the absolute representation is used to represent the multiplier, the position of 1 in the multiplier is represented by the absolute position. Assume that the rightmost bit of the number is called the 0th bit, the left bit of the 0th bit is called the 1st bit, and so on. Then, the multiplier is represented as (1, 5). At the same time, we require that the shift register connected to the result register in this embodiment does not work, and the data of the multiplier does not need to be transferred to the shift register. Then first take out the first number of the multiplier, that is, 1, indicating that there is a 1 at the 1st bit. Send the multiplicand to the shift register, and then after shifting 1 bit, it is 101110110 and sent to the adder. Since the previous numbers are added, the result sent to the result register is 101110110. Then take out the position of the next 1 of the multiplier, that is, 5, and send it to the shift register together with the multiplicand. In the shift register, the multiplicand is shifted right by 5 bits to obtain 1011101100000, which is sent to the adder. At the same time, the result 101110110 in the result register is taken out. Since the absolute representation method adopted does not require shifting, the result can be directly sent to the adder for accumulation to obtain 1100011010110. The accumulated result is sent to the result register again. At this time, all 1s in the multiplier have been calculated, so the operation ends. If the multiplier is represented in a relative manner, and its representation method is defined as the number of bits between each two non-zero numbers starting from the first non-zero digit in the highest bit (leftmost) to the lowest bit. For 00100010, there are 4 bits between the first non-zero digit and the next non-zero digit, and 1 bit between the second non-zero digit and the lowest bit, so it is expressed as (4, 1). Here, we require that the shift registers connected to the result register and to the multiplicand in this embodiment need to work. First, take out the first digit 4 of the multiplier and send it to two shift registers. Then shift the multiplicand right by 4 bits, and the data in the result register right by 4 bits and send them to the adder for accumulation. At this time, the data in the result register is 0, so the accumulated result 101110110000 is obtained, which is sent to the result register for storage. Then, take out the second digit 1 of the multiplier, and send the value to the shift register to obtain 101110110 and 1011101100000, which are sent to the adder for accumulation, and the result is 1100011010110. The result is sent to the result register again. At this time, all 1s in the multiplier have been calculated, so the operation is completed. In this way, the sparsity of the data can be effectively utilized, and only valid operations, that is, operations between non-zero data, are performed. This reduces invalid operations, speeds up the operation, and improves the performance-to-power ratio.

[0112] Fig. 22FIG. 1 is a schematic diagram of a structure of a device for performing vector multiplication by fusing a vector multiplier according to an embodiment of the present disclosure. Here, we assume that the vector and B2B1B0}, and send the data of the corresponding dimension to the multiplier for calculation, such as Figure 8 Here, the requirement and The dimensions are the same, both (N+1), but the bit width of each dimension is not necessarily the same. At the same time, it is assumed that n bits are taken for calculation each time, where n is greater than 1 and not greater than A positive integer representing the bit width of a dimension. First, take the lower n bits of B0 and A0 and send them to the first input selection circuit at the same time, perform AND operation on the lower n bits of B0 and A0 respectively, and send the selected result to the subsequent shift register for shifting. After shifting, send the result to the addition tree. In this process, each dimension performs the same operation as the first dimension. Then, through the addition tree, the data sent in these dimensions are accumulated, and the values ​​in the result register are sent to the addition tree, accumulated together, and the accumulated result is sent to the result register. During the operation, B of each dimension i After the value (i=0,1,...,N) is sent to the shift register and shifted right by n bits, the above operation is repeated, that is, the shifted B is obtained. i (i=0,1,……,N) The lowest n bits of the value and the corresponding A i The (i=0,1,……,N) values ​​are sent to the input selection circuit for selection, then sent to the shift register for shifting, and then sent to the addition tree for accumulation. This process is repeated until each dimension B i (i=0,1,……,N) values ​​are all 0, the operation is completed, and the data in the result register is the final result. The multiplier can flexibly configure the bit width of the data to be operated, without the need to recount the number of shift bits of the multiplicand every time a group of data is multiplied. At the same time, when the number of data bits is relatively low or the number of vector bits is relatively high, the characteristics of low data bit width and high vector dimension can be greatly utilized, and the process can be executed in parallel in a pipeline manner, reducing the time required for operation, further speeding up the operation speed, and improving the performance-power ratio.

[0113] We can use a variety of methods to complete the inner product operation of vectors, combining Fig.21 , Fig. 22 and Fig.23 First, we assume and The dimension is 8, that is, N = 7, The bit width is 8 bits, that is Each dimension of is 8 bits, that is, Ai={a i7 …a i1 a i0}, where i = 0, 1, ..., 7; The bit width is 4 bits, that is Each dimension of is 4 bits, that is, Bi = {b i3 b i2 b i1 b i0}, where i = 0, 1, ..., 7. Then the vector inner product

[0114]

[0115] The operation flow when using a basic multiplier or the above-mentioned basic or sparse multiplier (assuming n is 2, that is, each time the multiplier is moved 2 bits) is divided into two stages: first, the products of each component are calculated separately, and then the sum is performed, such as Fig.21 Specifically, for a certain dimension A i and B i The calculation is performed and the shift register is cleared. The first clock cycle takes B i The lowest two digits of b i0 ,b i1 , input selection, shift, send to adder, get A i *b i0 b i1 The value of the shift register is incremented by 2; in the second clock cycle, B i Shift right 2 bits and take the lowest two bits to get the lowest bit b i2 ,b i3 , input selection, shift to get A i *b i2 b i3 , add the result to the previous sum to get the final result A i *b i0 b i1 b i2 b i3 , that is, the final result A of this dimension is obtained i *B i . To perform the operation in the next dimension, enter A i+1 and B i+1 , the shift register is cleared... until each dimension is calculated, and (A0*B0, A1*B1, ..., A7*B7) is obtained, and the calculation of stage 1 is completed. Then, in stage 2, the product is sent to an addition tree for addition operation to obtain the final vector inner product result, that is, In stage 1, one multiplier can be selected to calculate each dimension in turn; or multiple multipliers can be provided for parallel operation to complete the operation of one dimension in one multiplier, such as Figure 7 When multiple multipliers are used, the multiplier B for each dimension i The shift values ​​need to be re-counted. The multiplier at this stage can be the basic multiplier or the sparse multiplier mentioned above.

[0116] The fused vector multiplier performs horizontal accumulation operations as a whole. Its structure is as follows: Fig. 22 As shown in the figure, after the product of a component of each dimension is completed, it is sent to the addition tree for accumulation until the operation is completed and the final result is obtained. For example, its operation process is as follows Fig.23 As shown in the oval box, in the first clock cycle, each dimension is calculated to obtain A i *b i0 The product of (i=0,1,……,7) is sent to the addition tree for accumulation, the calculation result is sent to the result register, and the shift register is incremented by 1; in the second clock cycle, each dimension is calculated according to the shift register to obtain 2*A i *b i1 The product of (i=0,1,……,7) and the data in the result register are sent to the addition tree for accumulation, and the shift register is incremented by 1; in the third clock cycle, each dimension is calculated according to the shift register to obtain 4*A i *b i2 The product of (i=0,1,……,7) and the data in the result register are sent to the addition tree for accumulation, and the shift register is incremented by 1; finally, in the fourth clock cycle, 8*A is calculated. i *b i3 The product of (i=0,1,……,7) and the data in the result register are sent to the addition tree for accumulation to get the final result. Therefore, we get the required result after 4 operation cycles. During the operation, there are 3 shifts in total. In general multipliers, each data operation requires a shift operation, that is, when there are 4 operands, a total of 4*3=12 shift operations are required. Therefore, our design, by changing the order of operations, greatly reduces the counting operation of the shift value, thereby effectively improving the performance-power ratio.

[0117] According to another aspect of the embodiment of the present disclosure, a processing method for dynamically configurable computing bit width is also provided. Fig.24 As shown, the steps include:

[0118] S2400: The control circuit generates a control instruction and transmits it to the memory and the operation circuit;

[0119] S2401: The memory inputs the data to be calculated of the neural network into the calculation circuit according to the received control instruction;

[0120] S2402: The operation circuit selects a corresponding type of multiplier and adder circuit in the first operation module according to the received control instruction;

[0121] S2403: The operation circuit operates on the data to be operated of the neural network with different calculation bit widths according to the input data to be operated, neural network parameters and control instructions.

[0122] Furthermore, in step S2403, the first operation module includes using an adder, a basic multiplier, a sparse multiplier and / or a fused vector multiplier to operate on the data to be operated of the neural network.

[0123] In summary, the use of this processing device and method can significantly improve the computing speed of the neural network, and at the same time has dynamic configurability, meeting the relevant requirements of the diversity of data bit width and the dynamic variability of data bit width during the operation process, and has the advantages of strong flexibility, high degree of configurability, fast computing speed, and low power consumption.

[0124] In addition, the present disclosure also provides a computing method and computing device including building an offline model. After the offline model is generated, the calculation can be performed directly according to the offline model, avoiding the additional overhead brought by running the entire software architecture including the deep learning framework. This will be specifically explained in conjunction with specific embodiments below.

[0125] In typical application scenarios, the neural network accelerator programming framework is usually at the top level. The programming framework can be Caffe, Tensorflow, Torch, etc. Fig.25 As shown, from the bottom layer to the top layer are the neural network processor (dedicated hardware for neural network operations), hardware driver (for software to call the neural network processor), neural network processor programming library (for providing an interface for calling the neural network processor), neural network processor programming framework and advanced applications that require neural network operations.

[0126] In one aspect of the embodiments of the present disclosure, a method for operating a neural network is provided, comprising the steps of:

[0127] Step 1: Get input data;

[0128] Step 2: Obtain or determine the offline model based on the input data, and determine the operation instructions based on the offline model for subsequent calculation calls;

[0129] Step 3: Call the operation instruction to operate the data to be processed to obtain the operation result for output.

[0130] The input data includes data to be processed, network structure and weight data, or the input data includes offline model data of the data to be processed.

[0131] The offline model in step 2 may be an existing one, or may be constructed later based on external data (such as network structure or weight data). By setting the offline model to obtain the operation instructions, the operation process can be improved.

[0132] The calling operation instruction in step 3 may be to perform network operation only according to the operation instruction when the input data only includes the data to be processed and does not include the offline model or the data used to determine the offline model.

[0133] In some embodiments, when the input data includes data to be processed, a network structure, and weight data, the following steps are performed:

[0134] Step 11, obtaining input data;

[0135] Step 12, constructing an offline model based on the network structure and weight data;

[0136] Step 13, parsing the offline model, obtaining the operation instructions and caching them for subsequent calculation calls;

[0137] Step 14: According to the operation instruction, the data to be processed is operated to obtain the operation result for output.

[0138] In the above embodiment, an offline model is first constructed according to the network structure and weight data, and then the operation instructions are obtained after the polarity of the offline model is analyzed. This enables full performance to be achieved in a low-memory, real-time application environment that does not store offline models, and the operation process is simpler and faster.

[0139] In some embodiments, when the input data includes data to be processed and an offline model, the following steps are performed:

[0140] Step 21, obtaining input data;

[0141] Step 22, parsing the offline model, obtaining the operation instructions and caching them for subsequent calculation calls;

[0142] Step 23, according to the operation instruction, the data to be processed is operated to obtain the operation result for output.

[0143] In the above embodiment, when the input data includes an offline model, after the offline model is established, the offline model is parsed during operation to obtain operation instructions, thereby avoiding the additional overhead brought by running the entire software architecture including the deep learning framework.

[0144] In some embodiments, when the input data only includes data to be processed, the following steps are performed:

[0145] Step 31, obtaining input data;

[0146] Step 32, calling the cached operation instruction, performing operation on the data to be processed to obtain the operation result for output.

[0147] In the above embodiment, when the input data only includes the data to be processed but does not include the neural network structure and weight data, the operation result is obtained by calling the operation instruction to operate on the data to be processed.

[0148] In some embodiments, a neural network processor is used to perform operations on the data to be processed according to operation instructions to obtain operation results; wherein the neural network processor is mainly used for neural network operations, and performs operations after receiving instructions, data to be processed and / or network models (such as offline models); for example, for a multi-layer neural network, the output layer data is calculated based on the input layer data, as well as data such as neurons, weights and biases.

[0149] In a further embodiment, the neural network processor has an instruction cache unit for caching received operation instructions.

[0150] In some embodiments, the neural network processor further comprises a data cache unit for caching the data to be processed. After the data to be processed is input into the neural network processor, it is temporarily stored in the data cache unit and then operated in combination with the operation instruction.

[0151] Based on the above computing method, the present disclosure further provides a computing device, including:

[0152] An input module, used to obtain input data, where the input data includes data to be processed, network structure and weight data, or the input data includes offline model data of the data to be processed;

[0153] Model generation module, used to build an offline model based on the input network structure and weight data;

[0154] A neural network operation module, used to generate and cache operation instructions based on the offline model data in the input module or the offline model constructed in the model generation module, and to operate the data to be processed based on the operation instructions to obtain operation results;

[0155] An output module, used for outputting the operation result;

[0156] The control module is used to detect the input data type and perform the following operations:

[0157] When the input data includes data to be processed, network structure and weight data, the control input module inputs the network structure and weight data into the model generation module to construct an offline model, and controls the neural network operation module to operate on the data to be processed input by the input module based on the offline model input by the model generation module;

[0158] When the input data includes the data to be processed and the offline model, the control input module inputs the data to be processed and the offline model into the neural network operation module, and controls the neural network operation module to generate and cache operation instructions based on the offline model, and to operate the data to be processed based on the operation instructions;

[0159] When the input data only includes the data to be processed, the control input module inputs the data to be processed into the neural network operation module, and controls the neural network operation module to call the cached operation instructions to operate on the data to be processed.

[0160] The neural network operation module includes a model analysis unit and a neural network processor, wherein:

[0161] A model parsing unit, used for generating operation instructions based on an offline model;

[0162] A neural network processor is used to cache operation instructions for subsequent calculation calls; or to call cached operation instructions when the input data only includes data to be processed, and to calculate the data to be processed based on the operation instructions to obtain a calculation result.

[0163] In some embodiments, the neural network processor has an instruction cache unit for caching operation instructions for subsequent calculation calls.

[0164] In some embodiments, the above-mentioned offline model can be a text file defined according to a special structure, and can be various neural network models, such as Cambricon_model, AlexNet_model, GoogleNet_model, VGG_model, R-CNN_model, GAN_model, LSTM_model, RNN_model, ResNet_model and other models, but is not limited to the models proposed in this embodiment.

[0165] The offline model may contain necessary network structure information such as the network weights of each computing node in the original network and instruction data, wherein the instruction may include information such as the computing properties of each computing node and the connection relationship between each computing node. Therefore, when the processor runs the original network again, it can directly run the offline model corresponding to the network without compiling the same network again, thereby shortening the running time of the processor when running the network and improving the processing efficiency of the processor.

[0166] Optionally, the processor may be a general-purpose processor, such as a CPU (Central Processing Unit), a GPU (Graphics Processing Unit) or an IPU (Intelligence Processing Unit), where the IPU is a processor for performing artificial neural network operations.

[0167] In some embodiments, the data to be processed is an input that can be processed by a neural network, such as at least one of a continuous single image, voice or video stream.

[0168] In some embodiments, the network structure may be various neural network structures, such as AlexNet, GoogleNet, ResNet, VGG, R-CNN, GAN, LSTM, RNN, ResNet, etc., but is not limited to these structures proposed in this embodiment. It should be noted that the network structure here corresponds to the offline model. For example, when the network structure is RNN, the offline model is RNN_model, which includes the network weights of each node in the RNN network and the necessary RNN network structure information such as instruction data, wherein the instruction may include the calculation attributes of each computing node and the connection relationship between each computing node.

[0169] Specifically, according to different input data of the input module, the computing device of the embodiment of the present disclosure can have the following three execution modes:

[0170] 1. When the data input by the input module is the network structure, weight data and data to be processed, the control module controls the input module to transmit the network structure and weight data to the model generation module, and transmits the data to be processed to the model parsing module; the control module controls the model generation module to generate an offline model according to the specific network structure and the corresponding weight data (the offline model can be a text file defined according to a preset structure, which can contain the network weights of each computing node in the neural network and necessary network structure information such as instruction data, wherein the instruction can include information such as the computing properties of each computing node and the connection relationship between each computing node, for example, the offline model can be constructed according to the corresponding network structure type and weight data), and transmit the generated offline model to the model parsing unit; the control module controls the model parsing unit to parse the received offline model to obtain the operation instructions recognizable by the neural network processor (that is, the corresponding network operation instructions are mapped out according to the text file of the above-mentioned offline model without the need for network compilation operation), and transmit the operation instructions and the data to be processed to the neural network processor; the neural network processor operates on the data to be processed according to the received operation instructions to obtain the operation results, and transmits the operation results to the output module for output.

[0171] 2. When the data input by the input module is the offline model and the data to be processed, the control module controls the input module to directly transmit the offline model and the data to be processed to the model parsing unit, and the subsequent working principle is the same as the first case.

[0172] 3. When the data input by the input module only contains data to be processed, the control module controls the input module to transmit the data to be processed to the neural network processor via the model parsing unit, and the neural network processor performs operations on the data to be processed according to the cached operation instructions to obtain operation results. The input module may include a judgment module for judging the type of input data. It is understandable that this situation usually does not occur when the neural network processor is used for the first time to ensure that there are certain operation instructions in the instruction cache.

[0173] Therefore, when the offline model of the current network operation is different from that of the previous network operation, the data input by the input module should include the network structure, weight data and data to be processed, and the subsequent network operation should be carried out after a new offline model is generated by the model generation module; when the corresponding offline model has been obtained in advance for the current network operation, the data input by the input module should include the offline model and the data to be processed; when the offline model of the current network operation is the same as that of the previous network operation, the data input by the input module only includes the data to be processed.

[0174] In some embodiments of the present disclosure, the computing device described in the present disclosure is integrated into the central processing unit module of the entire computer system as a submodule. The data to be processed and the offline model are controlled by the central processing unit to be transmitted to the computing device. The model parsing unit will parse the incoming neural network offline model and generate computing instructions. Then the computing instructions and the data to be processed will be passed into the neural network processor, and the computing results will be obtained through computing processing, and the computing results will be returned to the main memory unit. In the subsequent calculation process, the network structure will no longer change, and it is only necessary to continuously pass in the data to be processed to complete the neural network calculation and obtain the computing results.

[0175] The computing device and method proposed in the present disclosure are described in detail below through specific embodiments.

[0176] like Fig.26 As shown, this embodiment proposes a calculation method, including the following steps:

[0177] When the input data includes data to be processed, network structure and weight data, the following steps are performed:

[0178] Step 11: Get input data;

[0179] Step 12: Build an offline model based on the network structure and weight data;

[0180] Step 13: Analyze the offline model, obtain the operation instructions and cache them for subsequent calculation calls;

[0181] Step 14: According to the operation instruction, the data to be processed is operated to obtain a neural network operation result for output;

[0182] When the input data includes data to be processed and an offline model, perform the following steps:

[0183] Step 21: Obtain input data;

[0184] Step 22: parse the offline model, obtain the operation instructions and cache them for subsequent calculation calls;

[0185] Step 23: According to the operation instruction, the data to be processed is operated to obtain a neural network operation result for output;

[0186] When the input data only includes the data to be processed, perform the following steps:

[0187] Step 31, obtaining input data;

[0188] Step 32: Call the cached operation instruction to operate the data to be processed to obtain the neural network operation result for output.

[0189] Through the neural network processor, according to the operation instruction, the data to be processed is processed to obtain the operation result; the neural network processor has an instruction cache unit and a data cache unit, which are used to cache the received operation instructions and the data to be processed respectively.

[0190] The input network structure proposed in this embodiment is AlexNet, the weight data is bvlc_alexnet.caffemodel, the data to be processed is a continuous single picture, and the offline model is Cambricon_model. For the existing offline model, the offline model Cambricon_model can be parsed to generate a series of operation instructions, and then the generated operation instructions are transmitted to the instruction cache unit on the neural network processor 2707, and the input picture passed by the input module 2701 is transmitted to the data cache unit on the neural network processor 2707.

[0191] In summary, the method proposed in this embodiment can greatly simplify the process of using a neural network processor for computing, avoiding the extra memory and IO overhead of calling a traditional programming framework. The method can enable the neural network accelerator to fully exert its computing performance in a low-memory, real-time environment.

[0192] like Fig. 27 As shown, this embodiment also proposes a computing device, including: an input module 2701, a model generation module 2702, a neural network computing module 2703, an output module 2704 and a control module 2705, wherein the neural network computing module 103 includes a model parsing unit 2706 and a neural network processor 2707.

[0193] The key word of this device is offline execution, which means that after generating an offline model, the offline model is directly used to generate relevant operation instructions and pass in weight data to process the data to be processed. More specifically:

[0194] The above-mentioned input module 2701 is used to input a combination of network structure, weight data and data to be processed or a combination of offline model and data to be processed. When the input is network structure, weight data and data to be processed, the network structure and weight data are passed to the model generation module 2702 to generate an offline model for performing the following operations. When the input is an offline model and data to be processed, the offline model and data to be processed are directly passed to the model parsing unit 2706 to perform the following operations.

[0195] The output module 2704 is used to output the determined operation data generated according to the specific network structure and a set of data to be processed, wherein the output data is obtained by the neural network processor 2707.

[0196] The above-mentioned model generation module 2702 is used to generate an offline model for use by the lower layer based on the input network structure parameters and weight data.

[0197] The above-mentioned model parsing unit 2706 is used to parse the incoming offline model, generate operation instructions that can be directly passed into the neural network processor 2707, and at the same time pass the data to be processed passed into the input module 2701 to the neural network processor 2707.

[0198] The neural network processor 2707 is used to perform operations according to the input operation instructions and data to be processed, obtain a certain operation result and input it into the output module 2704, and has an instruction cache unit and a data cache unit.

[0199] The control module 2705 is used to detect the input data type and perform the following operations:

[0200] When the input data includes data to be processed, network structure and weight data, the control input module 2701 inputs the network structure and weight data into the model generation module 2702 to construct an offline model, and controls the neural network operation module 2703 to perform a neural network operation on the data to be processed input by the input module 2701 based on the offline model input by the model generation module 2702;

[0201] When the input data includes the data to be processed and the offline model, the control input module 2701 inputs the data to be processed and the offline model into the neural network operation module 2703, and controls the neural network operation module 2703 to generate and cache operation instructions based on the offline model, and perform neural network operation on the data to be processed based on the operation instructions;

[0202] When the input data only includes the data to be processed, the control input module 2701 inputs the data to be processed into the neural network operation module 2703, and controls the neural network operation module 2703 to call the cached operation instructions to perform neural network operation on the data to be processed.

[0203] The input network structure proposed in this embodiment is AlexNet, the weight data is bvlc_alexnet.caffemodel, and the data to be processed is a continuous single picture. The model generation module 102 generates a new offline model Cambricon_model based on the input network structure and weight data. The generated offline model Cambricon_model can also be used alone as the next input; the model parsing unit 2706 can parse the offline model Cambricon_model to generate a series of operation instructions. The model parsing unit 2706 transmits the generated operation instructions to the instruction cache unit on the neural network processor 2707, and transmits the input picture passed in by the input module 2701 to the data cache unit on the neural network processor 2707.

[0204] In addition, the present disclosure also provides a computing device and a computing method supporting composite scalar instructions, which unifies floating-point instructions and fixed-point instructions to a large extent by providing scalar instructions (an instruction that unifies floating-point instructions and fixed-point instructions) in the operation, does not distinguish between the types of instructions in the decoding stage, and determines whether the operand is floating-point data or fixed-point data according to the address in the operand address field during the specific calculation, simplifies the decoding logic of the instruction, and makes the instruction set more streamlined. This will be specifically explained in conjunction with specific embodiments below.

[0205] Fig.28 is a schematic diagram of the structure of a device supporting composite scalar instructions provided by an embodiment of the present disclosure, such as Fig.28 As shown, the device includes a controller module 2810 , a storage module 2820 , an operator module 2830 and an input / output module 2840 .

[0206] The controller module 2810 is used to read instructions from the storage module and store them in a local instruction queue, and then decode the instructions in the instruction queue into control signals to control the behaviors of the storage module, the operator module and the input and output module.

[0207] The storage module 2820 includes storage devices such as register files, RAM and ROM, and is used to store different data such as instructions and operands. Operands include floating-point data and fixed-point data. The memory module stores the floating-point data and the fixed-point data in spaces corresponding to different addresses, such as different RAM addresses or different register numbers, so that the read data can be judged as floating-point numbers or fixed-point numbers by the address and register number.

[0208] The operator module 2830 can perform four arithmetic operations, logical operations, shift operations, and complement operations on floating-point data and fixed-point data, wherein the four arithmetic operations include addition, subtraction, multiplication, and division; and the logical operations include AND, OR, NOT, and XOR. After receiving the control signal from the controller module, the operator module can determine whether the data read is floating-point type data or fixed-point type data by reading the address or register number of the operand. The operator module reads the operation data from the storage module and performs the corresponding operation. The intermediate result of the operation is stored in the storage module, and the final operation result is stored in the input and output module.

[0209] The input-output module 2840 can be used for the storage and transmission of input-output data. During initialization, the input-output module stores the initial input data and the compiled composite scalar instructions in the storage module. After the operation is completed, the module receives the final operation result transmitted by the operator module. In addition, the input-output module can also read the information required for compiling instructions from the memory so that the computer compiler can compile the program into various instructions.

[0210] It can be seen that the device supporting compound scalar instructions provided by the embodiments of the present disclosure provides an efficient execution environment for compound scalar instructions.

[0211] Fig.29A and Fig.29B The storage module stores floating point data and fixed point data in different address spaces, such as different addresses or different register numbers, so that the read data can be judged as floating point or fixed point by the address and register number.

[0212] In this embodiment, the present disclosure uses a storage module consisting of a RAM with a starting address of 0000H and an ending address of 3FFFH and a register stack consisting of 16 registers as an example to demonstrate how to separate the storage of floating-point numbers from the storage of fixed-point numbers. Fig.29A As shown in the figure, in RAM, fixed-point data is only stored in RAM cells with addresses from 0000H to 1FFFH, while floating-point data is only stored in RAM cells from 2000H to 3FFFH. Instructions can be stored in any RAM cell, and the unchanged information in the instruction set can also be stored in ROM. Fig.29B As shown in the figure, in the register file, fixed-point data only exists in registers 0 to 7, and floating-point data only exists in registers 8 to 15. When the value stored in the register is a RAM address, registers 0 to 7 are used to store the RAM address of the fixed-point data, and registers 8 to 15 are used to store the RAM address of the floating-point data.

[0213] Fig. 30AFIG. 1 is an example diagram of a composite scalar instruction provided by an embodiment of the present disclosure. Fig. 30A As shown, each instruction has an opcode field, an operand address field (or an immediate value), and a target address field. The opcode field includes the opcode, the operand address field includes source operand address 1 and source operand address 2, indicating the storage address of each source operand, and the target address field is the storage address of the operand operation result:

[0214] The opcode field is used to distinguish different types of operations, such as addition, subtraction, multiplication, and division, but is not used to distinguish the types of operands.

[0215] The operand address field may contain RAM addresses, register numbers, and immediate values. The RAM addresses and register numbers used to store floating-point data and fixed-point data are different, so the address field can be used to distinguish floating-point operands from fixed-point operands. When the operand address field stores immediate values, a data type flag bit that can be recognized by the operator module is required to distinguish floating-point operands from fixed-point operands.

[0216] The target address field can be a RAM address or a register number. The address field should correspond to the operand type, that is, the result of the floating-point operand operation is stored in the storage unit corresponding to the floating-point data; the result of the fixed-point operand operation is stored in the storage unit corresponding to the fixed-point data.

[0217] It can be seen that the compound scalar instruction provided by the present invention is an instruction that unifies floating-point instructions and fixed-point instructions, unifies floating-point instructions and fixed-point instructions to a large extent, does not distinguish between the types of instructions in the decoding stage, and only determines whether the operand is floating-point data or fixed-point data based on the address of the read operand in the operand address field during the specific calculation, which simplifies the decoding logic of the instruction and makes the instruction set more streamlined.

[0218] In addition, for the compound scalar instruction provided by the present disclosure, if multiple addressing modes are used, it is necessary to add a flag bit to determine the addressing mode.

[0219] For example, using Fig.29A and 29B The storage module organization structure shown in the figure, the operation code of the addition instruction is 0001, and when multiple addressing modes are used, the composition of the compound scalar instruction is as follows FIG. 30B to FIG. 30E shown.

[0220] Fig. 30B is an example diagram of a composite scalar instruction when register addressing is used according to an embodiment of the present disclosure, such as Fig. 30BAs shown, when register addressing is adopted, the addressing mode flag is 01, source operand 1 and source operand 2 are respectively stored in the registers corresponding to the source operand 1 register number and the source operand 2 register number, the registers numbered 0 to 7 store fixed-point data, and the registers numbered 8 to 15 store floating-point data;

[0221] Fig. 30C is an example diagram of a composite scalar instruction when register indirect addressing is used according to an embodiment of the present disclosure, such as Fig. 30C As shown in the figure, when register indirect addressing is used, the addressing mode flag is 10, and the addresses of source operand 1 and source operand 2 in RAM are stored in the registers corresponding to the source operand 1 register number and the source operand 2 register number, respectively. The RAM address of fixed-point data (0000H to 1FFFH) is stored in registers 0 to 7; the RAM address of floating-point data (2000H to 3FFFH) is stored in registers 8 to 15. The target address field stores the target register number or the target RAM address. Fixed-point data is stored in RAM units with addresses ranging from 0000H to 1FFFH; floating-point data is stored in RAM units with addresses ranging from 2000H to 3FFFH.

[0222] Fig.30D is an example diagram of a compound scalar instruction when using immediate addressing provided by an embodiment of the present disclosure, such as Fig.30D As shown, if the data in the operand address field is two immediate numbers, the addressing mode flag is 00, and a data type flag is set between the addressing mode flag and the operand address field. When the immediate number is a fixed-point type, the data type flag is 0; when the immediate number is a floating-point type, the data type flag is 1.

[0223] Fig.30E is an example diagram of a composite scalar instruction when RAM addressing is used, as provided in an embodiment of the present disclosure. Fig.30E As shown in the figure, if the operand address field is a RAM address, the addressing mode flag is 11. Source operand 1 and source operand 2 are stored in the RAM units corresponding to the RAM addresses. Fixed-point data is stored in the RAM units corresponding to RAM addresses 0000H to 1FFFH; floating-point data is stored in the RAM units corresponding to RAM addresses 2000H to 3FFFH.

[0224] In the relevant instructions using the above addressing modes, the target address field stores the target register number or the target RAM address. Fixed-point data is stored in registers 0 to 7 or RAM units with addresses ranging from 0000H to 1FFFH; floating-point data is stored in registers 8 to 15 or RAM units with addresses ranging from 2000H to 3FFFH.

[0225] Fig.31is a flow chart of an operation method supporting compound scalar instructions provided by an embodiment of the present disclosure, such as Figure 4 As shown, the embodiment of the present disclosure provides a computing method supporting compound scalar instructions, using the above-mentioned device supporting compound scalar instructions to perform data computing, specifically including the following steps:

[0226] S3101: Store different types of data in different addresses.

[0227] The memory module stores the floating-point data and the fixed-point data in spaces corresponding to different addresses, such as different RAM addresses or different register numbers.

[0228] S3102: Decode the compound scalar instruction into a control signal.

[0229] The controller module sends input and output (IO) instructions to the storage module, reads compound scalar instructions from the storage module, and stores them in the local instruction queue. The controller module reads compound scalar instructions from the local instruction queue and decodes them into control signals.

[0230] S3103: Read the operation data according to the control signal, determine the type of the operation data according to the address of the read operation data, and perform operations on the operation data.

[0231] After receiving the control signal from the controller module, the operator module can determine whether the data read is floating-point data or fixed-point data by reading the operand address field. If the operand is an immediate number, the operand type is determined and calculated based on the data type flag; if the operand comes from RAM or register, the operand type is determined based on the RAM address or register number, the operand is read from the storage module and the corresponding operation is performed.

[0232] S3104: Store the operation result in an address of the corresponding type.

[0233] The controller module sends IO instructions to the operator module, and the operator module transmits the calculation results to the storage module or the input and output module.

[0234] It can be seen from the above embodiments that the execution method of the compound scalar instruction provided by the present disclosure can accurately and efficiently execute the compound scalar instruction. Among them, the device supporting the compound scalar instruction provides an efficient execution environment for the compound scalar instruction; the execution method of the compound scalar instruction provided can accurately and efficiently execute the compound scalar instruction.

[0235] In addition, the present disclosure also provides a technical device and counting method that support technical instructions. By writing the algorithm for counting the number of elements in the input data (data to be counted) that meet given conditions into the form of instructions, the computing efficiency can be improved. This will be specifically explained in conjunction with specific embodiments below.

[0236] In an exemplary embodiment of the present disclosure, a counting device supporting a counting instruction is provided. Fig.32 Schematic diagram of the framework structure of the counting device according to the embodiment of the present disclosure. Fig.32 As shown, the counting device supporting counting instructions disclosed in the present invention includes: a storage unit, a counting unit, and a register unit. The storage unit is connected to the counting unit, and is used to store input data to be counted and to store the number of elements (counting results) in the input data to be counted that meet a given condition. The storage unit can be a main memory; it can also be a temporary storage memory, and further, it can be a high-speed temporary storage memory. By temporarily storing the input data to be counted in the high-speed temporary storage memory, the counting instruction can flexibly and effectively support data of different widths, thereby improving the execution performance.

[0237] In one embodiment, the storage unit is a high-speed temporary storage memory that can support input data of different bit widths and / or input data occupying storage spaces of different sizes. The input data to be counted is temporarily stored in the high-speed temporary storage memory, so that the counting process can flexibly and effectively support data of different widths. The counting unit is connected to the register unit, and the counting unit is used to obtain counting instructions, read the address of the input data in the register unit according to the counting instructions, and then obtain the corresponding input data to be counted in the storage unit according to the address of the input data, and perform statistical counting on the number of elements in the input data that meet given conditions to obtain the final counting result and store the counting result in the storage unit. The register unit is used to store the address of the input data to be counted in the storage unit. In one embodiment, the address stored in the register unit is the address of the input data to be counted on the high-speed temporary storage memory.

[0238] In some embodiments, the data type of the input data to be counted can be a 0 / 1 vector, or a numerical vector or matrix. When counting the number of elements in the input data that meet a given condition, the condition that the counted elements must meet can be the same as a given element, for example, the number of elements x contained in the statistical vector A, x can be a number n, n = 0, 1, 2..., x can also be a vector m, for example m = 00, 01, 11... The condition that the counted elements must meet can also be to satisfy a given expression, for example, the number of elements in the statistical vector B that are greater than the numerical value y, where y can be an integer n, n = 0, 1, 2... or a floating point number f, f = 0.5, 0.6...; for example, the number of elements in the statistical vector C that can divide z, where z can be an integer n, n = 0, 1, 2...

[0239] Fig.33 Schematic diagram of the structure of the counting unit in the counting device of the embodiment of the present disclosure. Fig.33As shown, the counting unit includes an input-output module, an operation module, and an accumulator module.

[0240] The input-output module is connected to the operation module. For the input data to be counted in the storage unit, a segment of data with a set length (the length can be configured according to actual needs) is taken each time and input into the operation module for operation. After the operation module completes the operation, the input-output module continues to take the next segment of data with a fixed length until all elements of the input data to be counted are taken; the input-output module outputs the counting result calculated by the accumulator module to the storage unit.

[0241] The operation module is connected to the accumulator module, and a fixed length of data is input. The adder of the operation module is used to add the number of elements of the input data that meet the given conditions, and the result is output to the accumulator module. The operation module also includes a judgment submodule, which is used to judge whether the input data meets the given conditions (the given conditions can be the same as a given element, or the value can be within a set interval). If it meets the conditions, 1 is output, if not, 0 is output, and then it is sent to the adder for accumulation.

[0242] In one embodiment, the structure of the adder may include n layers, wherein: the first layer has l full adders, the second layer has full adders, ... the mth layer has full adders; where l, m, and n are integers greater than 1, and m is an integer greater than 1 and less than n. Indicates the operation of rounding up the data x. The following describes its specific working process. Assume that the input data type is a 0 / 1 vector. Now we need to count the number of 1s in the 0 / 1 vector to be counted. Assume that the length of a fixed-length 0 / 1 vector is 3l, where l is an integer greater than 1. The first layer of the adder has l full adders; the second layer of the adder has There are full adders, each of which has 3 inputs and 2 outputs, so the first layer gets a total of 41 / 3 outputs; according to the method, each layer of full adders has 3 inputs and 2 outputs, and the adders on the same layer can be executed in parallel; during the calculation process, if the number of i-th bit data is 1, it can be used as the i-th bit output of the final result, that is, the number of 1s in this part of the 0 / 1 vector.

[0243] Fig.34 Schematic diagram of a specific full adder, where the adder structure includes 7 layers (i.e. n is 7), the first layer has 6 full adders, and the length of the fixed-length 0 / 1 vector at one end is 18 (i.e. l ​​is 6), and the full adders of each layer can be parallel, for example, the third layer has When the input data is (0, 1, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (1, 0, 0), (1, 1, 0), the result of counting by the full adder of the embodiment of the present disclosure is (001000), which is 8. The use of the above adder can increase the parallelism of the addition calculation and effectively improve the operation speed of the operation module.

[0244] The accumulator module is connected to the input and output module, and the results output by the operation module are accumulated using the accumulator until there is no new input.

[0245] The counting unit is a multi-pipeline structure, in which the vector fetching operation in the input and output module is in the first pipeline stage, the operation module is in the second pipeline stage, and the accumulator module is in the third pipeline stage. These units are in different pipeline stages, which can more efficiently implement the operations required by the counting instruction.

[0246] Fig.35 FIG. 1 is a schematic diagram of the instruction set format of the counting instruction in the counting device of the embodiment of the present disclosure. Fig.35 As shown, the counting instruction includes an operation code and one or more operation fields, wherein the operation code is used to indicate that the instruction is a counting instruction, and the counting unit can perform a counting operation by identifying the operation code, and the operation field may include: address information for indicating the input data to be counted in the counting instruction, and may also include address information of the judgment condition. The address information may be an immediate number or a register number. For example, when a vector is to be obtained, the vector starting address and the vector length may be obtained in the corresponding register according to the register number, and then the vector stored at the corresponding address may be obtained in the storage unit according to the vector starting address and the vector length. The instructions used in the embodiments of the present disclosure have a streamlined format, which makes the instruction set easy to use and supports flexible data lengths.

[0247] Fig.36 FIG. 1 is a flowchart of the execution process of the counting unit in the counting device of the embodiment of the present disclosure. Fig.36 As shown, when working, the counting unit obtains the address of the input data to be counted in the register unit according to the address information in the counting instruction operation domain, and then obtains the input data to be counted in the storage unit according to the address. The input data to be counted is stored in the high-speed temporary storage memory. Each time the counting unit obtains a fixed-length input data from the high-speed temporary storage memory, the judgment submodule judges whether the element meets the given condition, and then uses the adder to count the number of elements that meet the given condition in the part of the input data, and the number of elements that meet the given condition in each section is accumulated by the accumulator module to obtain the final counting result and store the counting result in the storage unit.

[0248] Fig.37 Detailed structural diagram of the counting device according to the embodiment of the present disclosure. Fig.37 As shown, the apparatus supporting counting instructions disclosed in the present invention may also include: an instruction memory, an instruction processing unit, an instruction cache unit, and a dependency processing unit.

[0249] As for the instruction processing unit, it is used to obtain the counting instruction from the instruction memory, and after processing the counting instruction, provide it to the instruction cache unit and the dependency processing unit. Among them, the instruction processing unit includes: an instruction fetch module and a decoding module. The instruction fetch module is connected to the instruction memory, and is used to obtain the counting instruction from the instruction memory; the decoding module is connected to the instruction fetch module, and is used to decode the obtained counting instruction. In addition, the instruction processing unit may also include an instruction queue memory, which is connected to the decoding module, and is used to sequentially store the decoded counting instructions, and sequentially send the instructions to the instruction cache unit and the dependency processing unit. Considering that the number of instructions that the instruction cache unit and the dependency processing unit can accommodate is limited, the instructions in the instruction queue memory must wait until the instruction cache unit and the dependency processing unit are free before they can continue to be sent sequentially.

[0250] The instruction cache unit can be connected to the instruction processing unit and is used to sequentially store the counting instructions to be executed. During the execution process, the counting instructions are also cached in the instruction cache unit. After an instruction is executed, the instruction execution result (counting result) is transmitted to the instruction cache unit. If the instruction is also the earliest instruction among the uncommitted instructions in the instruction cache unit, the instruction will be committed, and the instruction execution result (counting result) will be written back to the high-speed temporary storage memory. In one embodiment, the instruction cache unit can be a reordering cache.

[0251] The dependency processing unit can be connected to the instruction queue memory and the counting unit, and is used to determine whether the vector required by the counting instruction (i.e., the vector to be counted) is the latest before the counting unit obtains the counting instruction. If so, the counting instruction is directly provided to the counting unit; otherwise, the counting instruction is stored in a storage queue of the dependency processing unit, and after the required vector is updated, the counting instruction in the storage queue is provided to the counting unit. Specifically, when the counting instruction accesses the high-speed temporary storage memory, the storage space is waiting for the result of the previous instruction to be written. In order to ensure the correctness of the instruction execution result, if the current instruction is detected to have a dependency relationship with the data of the previous instruction, the instruction must wait in the storage queue until the dependency relationship is eliminated. The dependency processing unit enables instructions to be executed out of order and submitted in sequence, effectively reducing pipeline congestion, and realizing precise exceptions.

[0252] The instruction fetch module is responsible for taking out the next instruction to be executed from the instruction memory and passing the instruction to the decoding module; the decoding module is responsible for decoding the instruction and passing the decoded instruction to the instruction queue memory; the instruction queue memory is used to cache the decoded instructions, and sends the instructions to the instruction cache unit and the dependency processing unit when they are idle; in the process of the counting instruction being sent from the instruction queue memory to the dependency processing unit, the counting instruction reads the address of the input data in the storage unit from the register unit; the dependency processing unit is used to process the data dependency that may exist between the current instruction and the previous instruction. The counting instruction will access the storage unit, and other instructions executed previously may access the same storage space. In order to ensure the correctness of the instruction execution result, if the current instruction is detected to have a dependency relationship with the previous instruction data, the instruction must wait in the storage queue of the dependency processing unit until the dependency is eliminated. The counting unit obtains the counting instruction from the dependency processing unit, obtains the corresponding input data to be counted in the storage unit according to the address of the input data read by the counting instruction in the register unit, and performs statistical counting on the number of elements in the input data that meet the given conditions, and transmits the counting result to the instruction cache unit. Finally, the counting result and the counting instruction are written back to the storage unit.

[0253] Fig.38 FIG. 1 is a flowchart of the execution process of the counting device according to the embodiment of the present disclosure. Fig.38 As shown, the process of executing the counting instruction includes:

[0254] S3801, the instruction fetch module fetches the counting instruction from the instruction memory and sends the counting instruction to the decoding module.

[0255] S3802, the decoding module decodes the counting instruction and sends the counting instruction to the instruction queue memory.

[0256] S3803, the counting instruction waits in the instruction queue memory until the instruction cache unit and the dependency processing unit are idle, and then is sent to the instruction cache unit and the dependency processing unit.

[0257] S3804, when the counting instruction is sent from the instruction queue memory to the dependency processing unit, the counting instruction reads the storage address of the input data in the storage unit from the register unit, and the dependency processing unit analyzes whether there is a data dependency between the instruction and the previous instruction that has not yet been executed. The counting instruction needs to wait in the storage queue of the dependency processing unit until there is no data dependency between the instruction and the previous instruction that has not yet been executed.

[0258] S3805: After the dependency relationship does not exist, the counting instruction is sent to the counting unit. The counting unit obtains input data from the storage unit according to the storage address and counts the number of elements in the input data that meet the given condition.

[0259] S3806, after the counting is completed, the counting result is written back to the storage unit through the instruction cache unit, and the instruction cache unit submits the counting instruction to the storage unit.

[0260] So far, the present embodiment has been described in detail with reference to the accompanying drawings. Based on the above description, those skilled in the art should have a clear understanding of the counting device supporting counting instructions and the counting method thereof in the embodiment of the present disclosure.

[0261] In some embodiments, a chip is also disclosed, which includes the above-mentioned neural network processor, processing device, counting device or computing device.

[0262] In some embodiments, a chip packaging structure is also disclosed, which includes the above chip.

[0263] In some embodiments, a board is also disclosed, which includes the above chip packaging structure.

[0264] In one embodiment, an electronic device is also disclosed, which includes the above-mentioned board.

[0265] Electronic devices may include, but are not limited to, robots, computers, printers, scanners, tablet computers, smart terminals, mobile phones, driving recorders, navigators, sensors, cameras, cloud servers, cameras, camcorders, projectors, watches, headphones, mobile storage, wearable devices, transportation vehicles, household appliances, and / or medical devices.

[0266] The transportation means may include airplanes, ships and / or vehicles; the household appliances may include televisions, air conditioners, microwave ovens, refrigerators, rice cookers, humidifiers, washing machines, electric lights, gas stoves, and range hoods; the medical equipment may include magnetic resonance imaging, ultrasound machines and / or electrocardiographs.

[0267] In the embodiments provided by the present disclosure, it should be understood that the disclosed related devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, and the division of the parts or modules is only a logical function division. There may be other division methods in actual implementation, such as multiple parts or modules can be combined or integrated into one system, or some features can be ignored or not executed.

[0268] In this disclosure, the term "and / or" may have been used. As used herein, the term "and / or" means one or the other or both (eg, A and / or B means A or B or both A and B).

[0269] In the above description, for illustrative purposes, numerous specific details are set forth in order to provide a comprehensive understanding of the various embodiments of the present disclosure. However, it will be apparent to those skilled in the art that one or more other embodiments may be implemented without some of these specific details. The specific embodiments described are not intended to limit the present disclosure but to illustrate. The scope of the present disclosure is not determined by the specific examples provided above, but only by the claims below. In other cases, known circuits, structures, devices, and operations are shown in block diagram form rather than in detail so as not to obscure the understanding of the description. Where deemed appropriate, the end of a figure mark or a figure mark is repeated among the drawings to indicate corresponding or similar elements that optionally have similar properties or identical features, unless otherwise specified or apparent.

[0270] Various operations and methods have been described. Some methods have been described in a relatively basic manner in a flowchart manner, but these operations can be selectively added to these methods and / or removed from these methods. In addition, although the flowchart shows a specific order of operations according to each example embodiment, it is understood that this specific order is exemplary. Alternative embodiments can optionally perform these operations in different ways, combine certain operations, interleave certain operations, etc. The components, features, and specific optional details of the equipment described herein can also be optionally applied to the methods described herein, and in various embodiments, these methods can be performed by such equipment and / or performed in such equipment.

[0271] Each functional part / unit / sub-unit / module / sub-module / component in the present disclosure may be hardware, for example, the hardware may be a circuit, including a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to physical devices, and the physical devices include but are not limited to transistors, memristors, etc. The computing module in the computing device may be any appropriate hardware processor, such as a CPU, a GPU, an FPGA, a DSP, an ASIC, etc. The storage unit may be any appropriate magnetic storage medium or magneto-optical storage medium, such as RRAM, DRAM, SRAM, EDRAM, HBM, HMC, etc.

[0272] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0273] The specific embodiments described above further illustrate the purpose, technical solutions and beneficial effects of the present disclosure. It should be understood that the above description is only a specific embodiment of the present disclosure and is not intended to limit the present disclosure. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present disclosure should be included in the protection scope of the present disclosure.

Claims

1. A processing device with dynamically configurable computing bit width, characterized in that: include: A memory, used to store data, wherein the data includes data to be calculated, intermediate calculation results, final calculation results and data to be cached of the neural network; A data width adjustment circuit, used for adjusting the width of the data to be calculated, the intermediate calculation result, the final calculation result and / or the data to be cached; An operation circuit, used for operating the data to be operated by the neural network; as well as A control circuit, used for controlling a memory, a data width adjustment circuit and an operation circuit; The operation circuit is used to operate the data to be operated of the neural network, including: determining the types of multiplier and adder circuits of the operation circuit according to the data to be operated to perform the operation, the multiplier includes a bit serial operator, the bit serial operator includes an operation unit, a processing unit and a storage unit, wherein, The operation unit inputs the data to be operated, completes the multiplication and / or addition operation of one or more bits of data, and outputs the operation result; A storage component for inputting operation results for storage; The processing unit inputs the operation result and is used to complete data shifting, expand / reduce the data bit width according to the set rules, and operate on one or more bits of data according to a set rule.

2. The device according to claim 1, characterized in that The data width adjustment circuit comprises: An input data processing module is used to adjust the data width of the memory data; The output data processing module is used to adjust the width of the data calculated by the calculation circuit and then store it in the memory.

3. The device according to claim 1, characterized in that The memory comprises: An input storage module is used to store the data to be calculated by the neural network; An output storage module, used to store intermediate calculation results and final calculation results; and Cache module, used for buffer storage of data; Wherein, the input storage module includes: A neuron storage module, used to store neuron parameters; A synaptic storage module, used for storing synaptic parameters; The output storage module comprises: An intermediate calculation result storage submodule is used to store intermediate calculation results; The final operation result storage submodule is used to store the final operation result.

4. The device according to claim 2, characterized in that The operation circuit includes a plurality of operation modules, the synapse storage module includes a plurality of synapse storage sub-modules, and each of the operation modules is respectively connected to one or more synapse storage sub-modules.

5. The device according to any one of claims 1 to 4, characterized in that: The operation circuit comprises: The first operation module is used to perform operations on data of different bit widths; the first operation module includes an adder circuit and a multiplier to perform operations on data of different bit widths in a neural network.

6. The device according to claim 5, characterized in that The first operation module further includes a bit serial addition tree, the bit serial addition tree includes a shifter, a register and a plurality of adders, each adder includes an a terminal and a b terminal, the bit serial addition tree includes an x+1 layer structure, x is a positive integer, and the serial addition tree operates as follows: The carry output terminal Cin in each register and adder is initially 0, and the lowest n bits of each data to be operated are respectively input to the a and b terminals of the adder in the first layer. Each adder in the first layer completes the addition operation of the lowest n bits of the data to be operated transmitted from the a and b terminals, and the determined result value s is transmitted to the a or b terminal of the adder in the next layer. The carry value Cout obtained by each adder is transmitted back to the carry input Cin of the adder in this layer, and is added with the transmitted data to be operated in the next beat. The operation of the adder on the previous layer refers to the adder on the previous layer, adding the incoming data, and then passing the result to the next layer, and the carry is passed back to the adder on this layer until it reaches the x-th layer. The adder on the x-th layer shifts the result of the operation through the shifter, adds it to the original result from the register, and saves it back to the register. Then, wait for the next beat to select the second lowest n bits of the operation data and pass it into the bit serial addition tree to complete the corresponding operation.

7. The device according to claim 1, characterized in that The multiplier includes a bit-serial operator, and the bit-serial operator includes at least one of the following: A basic multiplier, used for dividing a multiplier into a plurality of low-bit width data, multiplying the multiplicands respectively, and then accumulating the data; A sparse multiplier for performing a multiplication operation when the multiplier and / or the multiplicand are represented in a sparse manner; Fused vector multiplier, used for multiplication operations between vectors.

8. The device according to claim 7, characterized in that The basic multiplier is a first basic multiplier, comprising: A multiplication storage unit, used for storing a multiplier, wherein the multiplier has a bit width of N bits; A first shift register is used for shifting out the lower n bits of the multiplier each time, and the multiplier after the shifting out operation is sent back to the multiplication storage unit, where 1<n≤N; The input selection circuit is used for inputting the lower n bits of the multiplier and the multiplicand each time, and performing an AND operation on the value of each of the lower n bits of the multiplier and the multiplier to obtain an AND operation result; A second shift register, used for inputting and shifting the result of the AND operation; An adder, used to input the shifted data for addition; The result register is used to store the addition result of the adder and re-input the addition result to the adder for the next addition.

9. The device according to claim 7, characterized in that The basic multiplier is a second basic multiplier, comprising: A multiplication storage unit, used for storing a multiplier, wherein the multiplier has a bit width of N bits; A first shift register is used for shifting out the lower n bits of the multiplier each time, and the multiplier after the shifting out operation is sent back to the multiplication storage unit, where 1<n≤N; Backup register to temporarily store the shifted multiplier; The input selection circuit is used for inputting the lower n bits of the multiplier and the multiplicand each time, and performing an AND operation on the value of each of the lower n bits of the multiplier and the multiplier to obtain an AND operation result; A second shift register, used for inputting and shifting the result of the AND operation; a third shift register, for shifting the multiplicand to remove the lower m bits of the multiplier; An adder, used to input the shifted data for addition; The result register is used to store the addition result of the adder and re-input it into the adder for the next addition.

10. The device according to claim 8 or 9, characterized in that The first basic multiplier or the second basic multiplier further includes a judgment circuit for judging whether the multiplier values ​​of the multiplication storage unit at that time are all zero.

11. The device according to claim 6, characterized in that The sparse multiplier comprises: A multiplication storage unit, used for storing a multiplier, wherein the multiplier is represented in a sparse manner and has a bit width of N bits; An input selection circuit is used for selecting a bit with a multiplier value of 1 from the lower bits each time; The first shift register is used for shifting out each low bit with a bit number below 1 each time and sending it back to the multiplication storage unit as the next multiplier; A second shift register, used for performing a shift operation according to the bit whose number of bits is 1; Adder, inputs the shifted data and adds them; A result register, storing the addition result of the adder; The third shift register shifts the result in the result register according to the bit with a value of 1 and re-inputs it into the adder for the next operation; The judging circuit is used to judge whether the multiplier values ​​of the multiplication storage unit at that time are all 0.

12. The device according to any one of claims 1 to 11, characterized in that: The data operations include: dot product, multiplication, addition, and mixed multiplication and addition between matrices; multiplication, addition, and mixed multiplication and addition between matrices and vectors; multiplication, addition, and mixed multiplication and addition between matrices and constants; multiplication, addition, and mixed multiplication and addition between vectors; multiplication, addition, and mixed multiplication and addition between vectors and constants; multiplication, addition, and mixed multiplication and addition between constants; comparison and selection of maximum / minimum values, and operations that can be split into multiplication, addition, or mixed multiplication and addition.

13. The device according to claim 7, characterized in that The multipliers and the adder tree are executed in parallel in a pipeline manner.

14. The device according to claim 9, characterized in that The first operation module includes a second basic multiplier and a bit serial addition tree, and performs operation in the following manner: Set the calculation vector and The inner product value of and The dimensions are the same, both (N+1), A is the multiplicand, B is the multiplier, and each time an operation is performed, A takes the specified m bits and B takes the specified n bits for operation, where m is not greater than A positive integer that is the bit width of one dimension of A positive integer representing the bit width of one dimension of ; Take the low m bits of A0 and the low n bits of B0 in the multiplier, perform multiplication operation on the low m bits of A0 and the low n bits of B0, send the selected result to the bit serial addition tree for addition operation, and save the result to the memory; Shift B by n bits, perform multiplication operation with the lower m bits of A, and send it to the bit serial addition tree for addition operation. At the same time, the data of the original storage unit is shifted by the third shift unit and added together, and the result is saved in the storage unit; After all operations of B are completed, A is shifted by m bits and then operated again with n bits of B in sequence; When all operations are completed, the data in the storage unit is the final operation result.

15. A chip, characterized in that: The chip comprises the device according to any one of claims 1-14.

16. An electronic device, characterized in that: The electronic device comprises the chip according to claim 14.

17. A method of using the device according to any one of claims 1 to 14, characterized in that Includes steps: The control circuit generates a control instruction and transmits it to the memory, the data width adjustment circuit and the operation circuit; The memory inputs the data to be calculated of the neural network into the calculation circuit according to the received control instruction; The data width adjustment circuit adjusts the width of the data to be operated by the neural network according to the received control instruction; The operation circuit operates the data to be operated of the neural network with different calculation bit widths according to the input data to be operated, the neural network parameters and the control instruction, and the operation result is sent back to the memory. The operation of the data to be operated of the neural network with different calculation bit widths includes: using a bit serial operator to perform the operation, including the following operations: Use the operation unit to input the data to be operated, complete the multiplication and / or addition operation of one or more bits of data, and output the operation result; Using a storage component to input the operation result for storage; The processing unit is used to input the operation result to complete data shifting, expand or reduce the data bit width according to the set rules, and operate on one or more bits of data according to a set rule.

18. The method according to claim 17, characterized in that The data width adjustment circuit comprises: an input data processing module for adjusting the data width of the data in the memory; and an output data processing module for adjusting the width of the data calculated by the calculation circuit and storing it in the memory.

19. The method according to claim 18, characterized in that Adjusting the width of the data to be operated by the neural network includes at least one of the following methods: The data bit width can be increased, decreased or kept unchanged without losing accuracy; The data bit width can be increased, decreased or kept unchanged with adjustable precision loss; The data bit width is increased, decreased, or kept unchanged according to the specified transformation or operation requirements.

20. The method according to claim 17 or 18, characterized in that The memory comprises: Input storage module: used to store the data to be calculated by the neural network; Output storage module: used to store intermediate calculation results and final calculation results; Cache module: used for data buffer storage; The input storage module comprises: Neuron storage module: used to store neuron parameters; Storage module: used to store synaptic parameters. The output storage module includes: Intermediate result Intermediate operation result storage submodule: used to store intermediate operation results; Final result Final calculation result storage submodule: used to store the final calculation result.

21. The method according to claim 17, characterized in that It also includes setting up multiple operation modules, which correspond to one or more synaptic modules respectively. During operation, the input storage module transmits input data to all operation modules, and the synaptic storage module transmits synaptic data to the corresponding operation module. After the operation module performs the operation, the result is written into the output storage module.

22. The method according to any one of claims 17 to 21, characterized in that: Also includes: The first operation module is used to perform operations on data of different bit widths, including: using an adder and a multiplier to accelerate the operations on data of different bit widths in the neural network.

23. The method according to claim 22, characterized in that The operation on the to-be-operated data of the neural network with different calculation bit widths includes using a bit serial addition tree to operate on the data with different bit widths, and the operation method is as follows: Assume that there are M data to be operated, and the maximum bit width is N, where M and N are both positive integers. If the data is less than N bits, the number of bits is padded to N bits; the bit serial addition tree includes x+1 layers, where x is a positive integer. The adders in the 1st layer to the xth layer complete the addition operation of n-bit digits, n≥1, and the adders in the x+1th layer complete the addition operation of digits not less than N bits; first, the carry output terminal Cin in the register and each adder is initialized to 0, the lowest n bits of each data to be operated are taken, and input to the a and b terminals of the adder in the first layer respectively, each adder completes the addition operation of the lowest n bits of the data to be operated transmitted from the a and b terminals, and the obtained result value s is transmitted to the a or b terminal of the adder in the next layer, and the obtained carry value Cout is transmitted back to the carry input Cin of the adder in this layer, and the next beat and the transmitted data to be operated are added; The operation of the adder on the previous layer is similar. It adds the incoming data and then passes the result to the next higher layer, with the carry bit passed back to the adder on that layer until it reaches the x-th layer. The adder on the x-th layer shifts the result of the operation, adds it to the original result from the register, and saves it back to the register. Then, the next lowest n bits of the data to be operated are selected and passed into the bit serial addition tree to complete the corresponding operation.

24. The method according to claim 23, characterized in that: When the bit serial addition tree is used to perform operations on data with different bit widths, the method further includes: after the first layer of adders completes the operations, a second batch of n-bit data to be operated is input.

25. The method according to claim 24, characterized in that: The use of the bit serial adder tree to perform operations on data of different bit widths also includes: when the a, b terminals and the carry input Cin terminal of the adder to be operated data input to the adder are all 0, the adder is closed during the operation.

26. The method according to claim 17, characterized in that The operation on the to-be-operated data of the neural network with different calculation bit widths includes: using a first basic multiplier to operate on the data with different bit widths, including the following operations: A multiplication storage unit is used to store a multiplier, wherein the multiplier has a bit width of N bits; Using a first shift register, shifting out the lower n bits of the multiplier each time, and re-sending the multiplier after the shift-out operation into the multiplication storage unit, where 1<n≤N; An input selection circuit is used to input the lower n bits of the multiplier and the multiplicand each time, and the value of each of the lower n bits of the multiplier is respectively ANDed with the multiplier to obtain the result of the AND operation; Using a second shift register, inputting the AND operation result and performing shifting; Using an adder, the shifted data is input and added; The result register is used to store the addition result of the adder and re-input the addition result into the adder for the next addition.

27. The method according to claim 17, characterized in that The operation on the to-be-operated data of the neural network with different calculation bit widths includes: using the second basic multiplier to operate on the data with different bit widths, including the following operations: A multiplication storage unit is used to store a multiplier, wherein the multiplier has a bit width of N bits; Using a first shift register, shifting out the lower n bits of the multiplier each time, and re-sending the multiplier after the shift-out operation into the multiplication storage unit, where 1<n≤N; Use a backup register to temporarily store the shifted multiplier; An input selection circuit is used to input the lower n bits of the multiplier and the multiplicand each time, and the value of each of the lower n bits of the multiplier is respectively ANDed with the multiplier to obtain the result of the AND operation; Using a second shift register, inputting the AND operation result and performing shifting; Using a third shift register, the multiplicand is shifted to remove the lower m bits; Using an adder, the shifted data is input and added; The result register is used to store the addition result of the adder and re-input the addition result into the adder for the next addition.

28. The method according to claim 17, characterized in that The operation on the to-be-operated data of the neural network with different calculation bit widths includes: using a sparse multiplier to operate on the data with different bit widths, including the following operations: A multiplication storage unit is used to store a multiplier, wherein the multiplier is represented in a sparse manner with a bit width of N bits; An input selection circuit is used to select a bit with a multiplier value of 1 from the low bit each time; Using a first shift register, each time shifting out the lower bits of the bit number below 1, and re-sending them into the multiplication storage unit as the next multiplier; Using a second shift register, performing a shift operation according to the bit number of 1s; Use an adder to input the shifted data and add them; Using a result register to store the addition result of the adder; The third shift register is used to shift the result in the result register according to the bit with a value of 1, and then re-input it into the adder for the next operation.

29. The method according to claim 17, characterized in that The operation on the to-be-operated data of the neural network with different calculation bit widths includes: using a second basic multiplier and a bit serial addition tree, and operating in the following manner: Set the calculation vector and The inner product value of and The dimensions are the same, both (N+1), A is the multiplicand, B is the multiplier, and each time an operation is performed, A takes the specified m bits and B takes the specified n bits for operation, where m is not greater than A positive integer that is the bit width of one dimension of A positive integer representing the bit width of one dimension of ; Take the low m bits of A0 and the low n bits of B0 in the multiplier, multiply the low m bits of A0 and the low n bits of B0, send the selected result to the bit serial addition tree for addition, and save the result to the storage unit; Shift B by n bits, perform multiplication operation with the lower m bits of A, and send it to the bit serial addition tree for addition operation. At the same time, the data of the original storage unit is shifted by the third shift unit and added together, and the result is saved in the storage unit; After all operations of B are completed, A is shifted by m bits and then operated again with n bits of B in sequence; When all operations are completed, the data in the storage unit is the final operation result.

30. According to the method of any one of claims 17 to 29, the computing the data to be computed of the neural network with different computing bit widths comprises: The operation circuit is used to perform operations of the fully connected layer and / or the pooling layer.

31. The method according to claim 17, characterized in that Also includes: The operation circuit selects corresponding types of multiplier and adder circuits in the first operation module according to the received control instruction.

Citation Information

Patent Citations

  • Method and system for deep learning algorithm acceleration on field-programmable gate array platform

    CN106228238A

  • Apparatus employing user-specified binary point fixed point arithmetic

    CN106484362A

  • Binary field bit-width-variable modular multiplication operator

    CN106484366A

  • Processing apparatus and processing method

    CN109121435A

  • Apparatus employing user-specified binary point fixed point arithmetic

    US20170102921A1