Random circuit for synthesizing tanh function based on two-dimensional finite-state machine and synthesis method thereof

Through a random circuit based on a two-dimensional finite state machine, using random sequence generation and state transition, the problem of insufficient synthesis accuracy and convergence speed in the prior art is solved, and high-precision and low-cost nonlinear function synthesis are achieved.

CN118897665APending Publication Date: 2024-11-05HEFEI UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410922166.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-10
Publication Date
2024-11-05

AI Technical Summary

Technical Problem

The prior art cannot effectively synthesize complex nonlinear functions, especially two-dimensional finite state machines based on random calculations, in order to achieve function accuracy and convergence speed.

Method used

The random circuit based on the two-dimensional finite state machine, including a random sequence generation circuit, a comparison circuit and a multiplexer, is used to generate random bit streams and state transitions to realize the synthesis of the tanh function, and the state transition of the two-dimensional finite state machine and The self-cycle structure improves the accuracy of function and convergence speed.

Benefits of technology

High-precision synthesis of complex nonlinear functions is realized, which improves the convergence speed and stability of functions, improves tolerance for soft errors, and reduces hardware costs and delays.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118897665A_ABST
    Figure CN118897665A_ABST
Patent Text Reader

Abstract

The invention provides a random circuit for synthesizing a tanh function based on a two-dimensional finite-state machine, and belongs to the field of random computation.The random circuit comprises a random sequence generation circuit, a comparison circuit, the two-dimensional finite-state machine and a multiplexer, and the output end of the random sequence generation circuit is connected to the input end of the comparison circuit; the output end of the comparison circuit is connected to the input end of the two-dimensional finite-state machine and the input end of the multiplexer, the output end of the two-dimensional finite-state machine is connected to the selection end of the multiplexer, and the random sequence generation circuit is used for generating an n-bit random sequence, an n-bit random sequence and a binary sequence of an actual value are jointly input into a comparison circuit for comparison to generate 2n-bit random bit streams, the 2n-bit random bit streams are input into the input end of a two-dimensional finite-state machine and the input end of a multiplexer, and the state of the two-dimensional finite-state machine is transferred along with input of the 2n-bit random bit streams. The current state number is output to the selection end of the multiplexer, the multiplexer is used for outputting parameters preset at the input end in the current state, and a complex nonlinear function can be effectively synthesized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of random computing technology, in particular to a random circuit and a synthesis method thereof for synthesizing a tanh function based on a two-dimensional finite state machine. Background Art

[0002] Artificial neural networks have been well applied in many fields, but there are still many aspects worth studying. Among them, the combination of neural networks with advantages such as distributed storage, parallel processing, self-organization and nonlinear mapping with other technologies has now become a major research hotspot. Since other methods also have their own advantages, neural networks are combined with other methods to complement each other. The resulting hybrid methods and hybrid systems can achieve better application effects. Compared with deterministic computing based on binary bases, the logic computing paradigm of random bit streams has several key advantages, including fault tolerance and low hardware area cost. Previous studies have shown that sequential logic operating on random bit streams can calculate non-polynomial functions, such as tanh functions, and consume less energy than traditional implementation methods. However, the functions that can be calculated in this way are quite limited. For example, high-order polynomials and non-polynomial functions cannot be calculated using existing methods. Studies have shown that schemes based on random computing have finite state machines that can be used to solve nonlinear functions, such as tanh functions and exponentials. Finite state machines include one-dimensional finite state machines and two-dimensional finite state machines. One-dimensional finite state machines are prone to enter invalid states and have the problem of low accuracy in implementing functions. Two-dimensional finite state machines place the last four states on the second layer. By increasing the connections between states, the accuracy of implementing functions can be improved. For example, the Chinese invention patent application "A MIMO Detection System Based on MCMC" with publication number CN115733525A records a two-dimensional state machine including 8 states, but the accuracy and convergence speed of the function implemented by the loop method of the finite state machine are limited. Summary of the invention

[0003] The technical problem to be solved by the present invention is to address the deficiencies of the above-mentioned prior art and propose a random circuit for synthesizing tanh functions based on a two-dimensional finite state machine, which can effectively synthesize complex nonlinear functions.

[0004] The present invention solves the above technical problems through the following technical solutions: a random circuit based on a two-dimensional finite state machine synthesizing a tanh function, comprising a random sequence generating circuit, a comparison circuit, a two-dimensional finite state machine and a multiplexer, wherein the output end of the random sequence generating circuit is connected to the input end of the comparison circuit, the output end of the comparison circuit is respectively connected to the input end of the two-dimensional finite state machine and the input end of the multiplexer, the output end of the two-dimensional finite state machine is connected to the selection end of the multiplexer, the random sequence generating circuit is used to generate an n-bit random sequence, the n-bit random sequence and a binary sequence of an actual value are input to the comparison circuit together for comparison to generate a 2 n Random bit stream, 2 n The random bit stream is input to the input of the two-dimensional finite state machine and the multiplexer. The state of the two-dimensional finite state machine changes with the 2 n The input of the random bit stream is transferred and the current state number is output to the selection end of the multiplexer. The multiplexer is used to output the parameters preset at the input end when the current state is output.

[0005] Preferably, the random sequence generation circuit includes n registers, which are arranged in a row to form an n-bit linear feedback shift register, each register stores a binary number, and after the binary number of the rightmost register is output, the binary numbers in the n registers are shifted one bit to the right as a whole, and at the same time, the binary numbers in the n registers are XORed according to the feedback coefficient, and the result is stored in the leftmost register.

[0006] Preferably, the random sequence generation circuit is a 10-bit linear feedback shift register consisting of 10 registers, and the primitive polynomial used is f(x)=x 10 +x 7 +x 3 +x+1.

[0007] Preferably, the comparison circuit includes n comparators, each of which includes two input terminals and one output terminal. The n-bit random sequence generated by the random sequence generation circuit is input to the input terminal L of the comparator, the binary sequence of the actual value is input to the input terminal X of the comparator, and the output terminal outputs 2 n The output ends of two comparators among the n comparators are respectively connected to the input end X and the input end K of the two-dimensional finite state machine, and the output ends of the remaining comparators are respectively connected to the input ends of the multiplexer.

[0008] Preferably, the structural state transition of the two-dimensional finite state machine is: S0 self-loops when the value of X, K is 00, S0 jumps to S1 when the value of X, K is 11, S0 self-loops when the value of X, K is 01, S0 jumps to S4 when the value of X, K is 10; S1 self-loops when the value of X, K is 01, S1 jumps to S2 when the value of X, K is 11, S1 jumps to S5 when the value of X, K is 10, S1 When the value of X, K is 00, it jumps to S0; when the value of X, K is 01, S2 self-loops; when the value of X, K is 11, S2 jumps to S3; when the value of X, K is 10, S2 jumps to S6; when the value of X, K is 00, S2 jumps to S1; when the value of X, K is 11, S3 jumps to S4; when the value of X, K is 10, S3 jumps to S7; when the value of X, K is 01, S3 self-loops; when the value of X, K is When the value is 00, it jumps to S2; S4 self-loops when the value of X, K is 10, S4 jumps to S5 when the value of X, K is 11, S4 jumps to S3 when the value of X, K is 00, S4 jumps to S0 when the value of X, K is 01; S5 self-loops when the value of X, K is 10, S5 jumps to S6 when the value of X, K is 11, S5 jumps to S1 when the value of X, K is 00 When the value of X, K is 10, S6 jumps to S4; when the value of X, K is 10, S6 self-loops, when the value of X, K is 11, S6 jumps to S2 when the value of X, K is 01, and S6 jumps to S5 when the value of X, K is 00; when the value of X, K is 11, S7 self-loops, when the value of X, K is 10, S7 jumps to S3 when the value of X, K is 01, and S7 jumps to S6 when the value of X, K is 00.

[0009] Preferably, the comparison circuit includes 10 comparators, the output end of the first comparator is connected to the input end X of the two-dimensional finite state machine, the output end of the second comparator is connected to the input end K of the two-dimensional finite state machine, and the output ends of the third to tenth comparators are respectively connected to the input ends of the multiplexer.

[0010] Preferably, the multiplexer is an eight-to-one multiplexer, including a selection terminal t, eight parameter input terminals w0, w1, ..., w7, and an output terminal Y, the selection terminal t is connected to the output terminal s of the two-dimensional state machine, and the eight parameter input terminals w0, w1, ..., w7 are respectively connected to the output terminals of the third comparator to the tenth comparator in sequence.

[0011] The present invention also provides a method for synthesizing a random circuit using the two-dimensional finite state machine-based tanh function, comprising the following steps:

[0012] Step 1: The random sequence generation circuit generates an n-bit random sequence. The n-bit random sequence and the binary sequence of the actual value are input into the comparison circuit for comparison to generate 2n The output terminals of the two comparators in the comparison circuit are connected to the input terminals X and K of the two-dimensional finite state machine respectively. When the random state transfer of the two-dimensional finite state machine reaches the equilibrium state, the mathematical expression of the two-dimensional finite state machine is established:

[0013] in, Among them, P t is the probability that the current state of the two-dimensional finite state machine is St, PX is the probability that the bit in the input terminal X of the two-dimensional finite state machine is equal to 1, PK is the probability that the bit in the input terminal K of the two-dimensional finite state machine is equal to 1, P i The current state of the two-dimensional finite state machine in equilibrium is S i The probability of, N is 4, i = 0, 1; j = 0, 1, 2, 3;

[0014] Step 2, 2 n The random bit stream is input to the input port w of the two-dimensional finite state machine and the multiplexer. t , the state of the two-dimensional finite state machine increases with 2 n The input of the random bit stream is transferred and the current state number is output to the selection terminal t of the multiplexer to obtain the state function PY:

[0015] Among them, P t is the probability that the current state of the two-dimensional finite state machine is St, which is equal to the input terminal w of the multiplexer t The probability of being selected as output, P wt is the probability that a bit in the input of the multiplexer is equal to 1;

[0016] Step 3: Calculate the probability PK that the bit in the input terminal K of the two-dimensional finite state machine is equal to 1 and the probability P that the bit in the input terminal of the multiplexer is equal to 1. wt The optimal value of minimizes the error between the state function PY and the objective function tanh;

[0017] Step 4: Based on the optimal value in step 3, the generated probabilities are PK and P respectively. wt Random bit streams K and wt, synthesizing the tanh function.

[0018] Preferably, the two-dimensional finite state machine in step 1 conforms to the Markov chain property and satisfies the following relationship:

[0019] P i×N+j ·(1-PX)·(1-PK)=P i×N+j-1 ·PX·PK;

[0020] P i×N+j ·(1-PX)·PK=P(i-1)×N+j ·PX·(1-PK).

[0021] Preferably, step 3 comprises:

[0022] 3.1. Definition The approximate error between the state function PY and the objective function tanh(PX) is defined as:

[0023]

[0024] In the formula, is a constant, and we only need to minimize the values ​​of the last two terms, and γ is simplified to

[0025]

[0026] 3.2、 Rewritten in matrix format: in,

[0027] vector Vector b = [P w0 ,P w1 ,…,P w7 ] T ,matrix

[0028] 3.3. Set PK to 0.001, 0.002, ..., 0.999, and 1 respectively, and calculate the corresponding P one by one wt and Among 1000 results, when PK is set to 0.5, The value of P is the smallest, and wt The solution is:

[0029] P w0 =0,P w1 =0,P w2 =0,P w3 =0,P w4 =1,P w5 =1,P w6 =1,P w7 =1.

[0030] The advantages provided by the present invention are:

[0031] 1. The present invention is based on a random circuit for synthesizing a tanh function based on a two-dimensional finite state machine. The random sequence generation circuit is used to generate an n-bit random sequence. The comparison circuit is used to convert a binary number into a random bit stream required by the circuit. The state of the two-dimensional finite state machine changes with the 2 nThe input of the random bit stream undergoes a state transfer, and the current state number is input into the selection end of the multiplexer. Since the probability that the current state of the two-dimensional finite state machine is St is the same as the probability that the input end of the multiplexer is selected to output, the multiplexer outputs pre-set parameters according to the current state of the two-dimensional finite state machine, thereby being able to effectively synthesize complex nonlinear functions, with higher tolerance to soft errors and lower area-delay product.

[0032] 2. In the random circuit of the tanh function synthesized based on the two-dimensional finite state machine of the present invention, the two-dimensional finite state machine places the last four states on the second layer, increases the connection between states, and increases effective jumps. Compared with the one-dimensional finite state machine, the two-dimensional finite state machine of the present invention realizes the function with higher accuracy and faster convergence speed. The jump from S3 to S4 is added, and the connection between states is further increased. The convergence speed is faster than that of the existing two-dimensional finite state machine. By adding self-loops of each state, while ensuring that the jumps between different states are reasonable, setting the state self-loop can effectively utilize the input value, which is beneficial to improving the stability of the state machine system and the accuracy of the tanh function.

[0033] 3. The additional input K in the two-dimensional finite state machine of the present invention provides greater design freedom for synthesizing the tanh function, and reasonable state transition and self-loop settings realize the stable and balanced operation of the state machine. The tanh function synthesis method can calculate the optimal solution for setting parameters, improve the accuracy of parameter settings, achieve the purpose of improving function accuracy, and can randomly synthesize more complex functions. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 A schematic diagram of a random circuit for synthesizing a tanh function based on a two-dimensional finite state machine provided in Example 1 of the present invention;

[0035] Figure 2 A schematic diagram of a random sequence generation circuit in a random circuit based on a two-dimensional finite state machine synthesizing a tanh function provided in Example 1 of the present invention;

[0036] Figure 3 A schematic diagram of a comparison circuit in a random circuit based on a two-dimensional finite state machine synthesizing a tanh function provided in Example 1 of the present invention;

[0037] Figure 4 A schematic diagram of the structural state transition of a two-dimensional finite state machine in a random circuit based on a two-dimensional finite state machine synthesizing a tanh function provided in Example 1 of the present invention;

[0038] Figure 5 A schematic diagram of a multiplexer in a random circuit based on a two-dimensional finite state machine synthesizing a tanh function provided in Embodiment 1 of the present invention;

[0039] Figure 6 This is a simulation diagram of the two-dimensional finite state machine synthesizing the tanh function in the present invention. DETAILED DESCRIPTION

[0040] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the technical solution of the present invention is clearly and completely described below in combination with specific embodiments and with reference to the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0041] Example 1

[0042] like Figure 1 As shown, this embodiment provides a random circuit based on a two-dimensional finite state machine to synthesize a tanh function, including a random sequence generation circuit, a comparison circuit, a two-dimensional finite state machine and a multiplexer, the output end of the random sequence generation circuit is connected to the input end of the comparison circuit, the output end of the comparison circuit is respectively connected to the input end of the two-dimensional finite state machine and the input end of the multiplexer, the output end of the two-dimensional finite state machine is connected to the selection end of the multiplexer, the random sequence generation circuit is used to generate an n-bit random sequence, the n-bit random sequence and the binary sequence of the actual value are input to the comparison circuit together for comparison to generate a 2 n Random bit stream, 2 n The random bit stream is input to the input of the two-dimensional finite state machine and the multiplexer. The state of the two-dimensional finite state machine changes with the 2 n The input of the random bit stream is transferred and the current state number is output to the selection end of the multiplexer. The multiplexer is used to output the parameters preset at the input end when the current state is output.

[0043] like Figure 2 As shown, the random sequence generation circuit includes n registers, which are arranged in a row to form an n-bit linear feedback shift register. Each register stores a binary number (0 or 1). After the binary number of the rightmost register is output, the binary numbers in the n registers are shifted right by one position as a whole. At the same time, the binary numbers in the n registers are XORed according to the feedback coefficient, and the result is stored in the leftmost register. Feedback coefficient g n The value can only be 0 or 1. n When the value is 0, it indicates that the feedback branch does not exist, and the feedback coefficient g n When the value is 1, it indicates that the feedback branch exists, and the feedback coefficient g n Determines the different algorithms for generating n-bit random sequences.

[0044] The bits that affect the next state of the linear feedback shift register are called taps, and the sequence of selected "certain bits" is called a tap sequence. Theory shows that in order to make the linear feedback shift register have the longest period, the polynomial formed by this tap sequence plus 1 must be a primitive polynomial (a polynomial whose greatest common divisor of all coefficients is 1), that is, this polynomial is irreducible, for example, f(x) = x 4 +x+1, this embodiment is described with n being 10. When n is 10, the random sequence generation circuit is a 10-bit linear feedback shift register composed of 10 registers, and the primitive polynomial used is f(x)=x 10 +x 7 +x 3 +x+1, which is 2 10 The input of the 10-bit linear feedback shift register is the codeword polynomial M(x), for example, M(x) = x 4 +x+1, indicating that the input sequence of the random sequence generation circuit input is 11001, and the outputs of the 10 registers from the leftmost to the rightmost are Q1, Q2, Q3, ... Q 10 .

[0045] like Figure 3 As shown, the comparison circuit includes n comparators, which are used to convert binary numbers into random bit streams required by the circuit. The comparator includes two input terminals and one output terminal. The n-bit random sequence generated by the random sequence generation circuit is input to the input terminal L of the comparator, and the binary sequence of the actual value is input to the input terminal X of the comparator. After the n-bit random sequence and the binary sequence of the actual value are compared by the comparator, a 2 n The output ends of two of the n comparators are respectively connected to the input ends X and K of the two-dimensional finite state machine, and the output ends of the remaining n-2 comparators are respectively connected to the input ends of the multiplexer.

[0046] The binary sequence of the actual value is the actual value multiplied by 2 to the power of n. The actual value ranges between 0 and 1. n The probability of 1 appearing in a random bit stream is the actual value, for example 2 n If a 1s appear in a random bit stream, the value represented by the random bit stream is a / 2 n The random sequence generation circuit of this embodiment is composed of 10 registers, the comparison circuit includes 10 comparators, and the binary sequence of the actual value is the actual value multiplied by 2 to the power of 10. The output end of the first comparator is connected to the input end X of the two-dimensional finite state machine, the output end of the second comparator is connected to the input end K of the two-dimensional finite state machine, and the output ends of the third comparator to the tenth comparator are respectively connected to the input ends of the multiplexer.

[0047] like Figure 4 As shown, the state of the two-dimensional finite state machine changes with 2 n The input of the random bit stream is transferred, and the structural state transfer is: S0 self-loops when the value of X, K is 00, S0 jumps to S1 when the value of X, K is 11, S0 self-loops when the value of X, K is 01, S0 jumps to S4 when the value of X, K is 10; S1 self-loops when the value of X, K is 01, S1 jumps to S2 when the value of X, K is 11, S1 jumps to S5 when the value of X, K is 10, S1 When the value of X, K is 00, it jumps to S0; when the value of X, K is 01, S2 self-loops; when the value of X, K is 11, S2 jumps to S3; when the value of X, K is 10, S2 jumps to S6; when the value of X, K is 00, S2 jumps to S1; when the value of X, K is 11, S3 jumps to S4; when the value of X, K is 10, S3 jumps to S7; when the value of X, K is 01, S3 self-loops; when the value of X, K is When the value is 00, it jumps to S2; S4 self-loops when the value of X, K is 10, S4 jumps to S5 when the value of X, K is 11, S4 jumps to S3 when the value of X, K is 00, S4 jumps to S0 when the value of X, K is 01; S5 self-loops when the value of X, K is 10, S5 jumps to S6 when the value of X, K is 11, S5 jumps to S1 when the value of X, K is 00 When the value of X, K is 10, S6 jumps to S4; when the value of X, K is 10, S6 self-loops, when the value of X, K is 11, S6 jumps to S2 when the value of X, K is 01, and S6 jumps to S5 when the value of X, K is 00; when the value of X, K is 11, S7 self-loops, when the value of X, K is 10, S7 jumps to S3 when the value of X, K is 01, and S7 jumps to S6 when the value of X, K is 00.

[0048] The two-dimensional finite state machine of the present invention places the last four states in the second layer, increases the connection between states, i.e., S0 to S4, S1 to S5, S2 to S6, S3 to S7, increases effective jumps, increases the jump from S3 to S4, further increases the connection between states, can increase the precision and convergence speed of the function, by adding the self-loop of each state, while ensuring that the jump between different states is reasonable, the self-loop of the state is set to effectively utilize the input value. If the self-loop is not set, taking state S1 as an example, when the state machine receives the input of 01, the state machine cannot jump normally or jump to the wrong state, which will increase the error rate and affect the final result. The jump direction of the state machine in all input situations is clarified, which is conducive to improving the stability of the state machine system and the accuracy of the tanh function.

[0049] like Figure 5As shown, the multiplexer of the present invention is an eight-to-one multiplexer, which includes a selection terminal t, eight parameter input terminals w0, w1, ..., w7, and an output terminal Y. The selection terminal t is connected to the output terminal s of the two-dimensional state machine, and the eight parameter input terminals w0, w1, ..., w7 are respectively connected to the output terminals of the third comparator to the tenth comparator in sequence, which is specifically described as follows: the output terminal of the third comparator is connected to the parameter input terminal w0, the output terminal of the fourth comparator is connected to the parameter input terminal w1, the output terminal of the fifth comparator is connected to w2, the output terminal of the sixth comparator is connected to the parameter input terminal w3, the output terminal of the seventh comparator is connected to the parameter input terminal w4, the output terminal of the eighth comparator is connected to the parameter input terminal w5, the output terminal of the ninth comparator is connected to the parameter input terminal w6, the output terminal of the tenth comparator is connected to the parameter input terminal w7, and the output terminal Y outputs the current function value, that is, the parameter preset at the input terminal when the current state is output.

[0050] Example 2

[0051] This embodiment provides a method for synthesizing a random circuit of a tanh function based on a two-dimensional finite state machine, comprising the following steps:

[0052] Step 1: The random sequence generation circuit generates an n-bit random sequence. The n-bit random sequence and the binary sequence of the actual value are input into the comparison circuit for comparison to generate 2 n The output ends of the two comparators in the comparison circuit are connected to the input ends X and K of the two-dimensional finite state machine respectively, PX and PK are the probabilities that the bits in the input ends X and K are equal to 1 respectively, then the random state transition of the two-dimensional finite state machine will eventually reach an equilibrium state, and a mathematical expression that can describe the structure of the two-dimensional finite state machine is established. The two-dimensional structure proposed by the present invention conforms to the properties of the Markov chain, and therefore, the following two formulas can be obtained:

[0053] P i×N+j ·(1-PX)·(1-PK)=P i×N+j-1 ·PX·PK

[0054] P i×N+j ·(1-PX)·PK=P (i-1)×N+j ·PX·(1-PK)

[0055] Where N is 4, i = 0, 1; j = 0, 1, 2, 3; P i The current state of the two-dimensional finite state machine in equilibrium is S i Since the sum of all individual state probabilities must equal 1,

[0056] Combining the above formula, when the system reaches a stable state, we have:

[0057] in,

[0058] Step 2, 2 n The random bit stream is input to the input port w of the two-dimensional finite state machine and the multiplexer. t , t=0,1,...,7, the state of the two-dimensional finite state machine increases with 2 n The input of the random bit stream is transferred and the current state number is output to the selection terminal t of the multiplexer. Define P wt The input terminal w t The probability of winning 1, P Y is the probability of 1 in the output terminal Y of the multiplexer. According to the circuit setting "MUX", the input wt is selected as its probability output is P t , because this probability is the same as the probability that the current state of the two-dimensional finite state machine is St. The output expression of the multiplexer can be obtained as:

[0059] PY Because P t is a function of PX and PK, so PY is the sum of PX, PK and P wt It can be seen that the above formula is a closed-form expression of PY.

[0060] Step 3: The output expression PY of the multiplexer is the state function. The error between the state function PY and the objective function tanh is calculated and minimized.

[0061] Calculating the approximate error is to calculate the error between the state function and the target function. The smaller the error value, the more appropriate the function is. Calculate P wt and the value of PK to minimize.

[0062] 3.1. Define the approximate error. The approximate error between the state function and the objective function tanh(PX) is defined as:

[0063]

[0064] In the formula, is a constant, and we only need to minimize the values ​​of the last two terms, so γ can be simplified to

[0065] 3.2 Rewrite It can be rewritten in matrix format:

[0066] in,

[0067] vector Vector b = [Pw0 ,P w1 ,…,P w7 ] T ,matrix

[0068] 3.3 Calculation and P wt , because P t is a function of PX and PK. If PK is a constant, P t The integral over PX is also a constant, so calculate P wt , to minimize This is a typical constrained quadratic programming problem. First, set PK to 0.001 and calculate the corresponding P wt and Next, we set PK to 0.002 and calculate the corresponding P wt and After calculating one by one, finally we set PK to 1 and calculate the corresponding P wt and

[0069] In this example, among all the 1000 results, when PK is set to 0.5, The value of is the smallest. We can get P wt (i.e. vector b) solution P w0 =0,P w1 =0,P w2 =0,P w3 =0,P w4 =1,P w5 =1,P w6 =1,P w7 =1;

[0070] Step 4: Synthesis of output value Y, PK = 0.5 is the probability value of inputting PK when synthesizing the current objective function tanh (PX). At this time, P wt It is the value of the preset probability of the linear shift register at the input end of the eight-to-one multiplexer when synthesizing the current target function; py is the ratio of the number of 1s in the output Y to all output Ys; according to the polarity of y, the tanh function is bipolar, and the bipolar function value y=2*py-1, thereby synthesizing the tanh function.

[0071] When PK and P are obtained wt After the optimal value of wtRandom bit streams K and wt are used to stochastically implement the target function T(PX). For example, this method can be used in combination with the proposed finite state machine topology to synthesize the tanh function or other nonlinear functions in this example. Intuitively, the additional input K and balanced state transformations provide the proposed two-dimensional finite state machine with greater design freedom to synthesize more complex functions.

[0072] The invention is based on a random circuit for synthesizing a tanh function based on a two-dimensional finite state machine. The random sequence generation circuit is used to generate an n-bit random sequence. The comparison circuit is used to convert a binary number into a random bit stream required by the circuit. The state of the two-dimensional finite state machine changes with the 2 n The input of the random bit stream undergoes a state transfer, and the current state number is input into the selection end of the multiplexer. Since the probability that the current state of the two-dimensional finite state machine is St is the same as the probability that the input end of the multiplexer is selected to output, the multiplexer outputs preset parameters according to the current state of the two-dimensional finite state machine, thereby being able to effectively synthesize complex nonlinear functions. Table 1 can reflect that the present invention has a higher tolerance to soft errors, and Table 2 can reflect that the area-delay product of the present invention is lower.

[0073] Table 1 Comparison of soft error tolerance between the present invention and the traditional method

[0074]

[0075] Table 2 Comparison of the area delay product of the present invention and the traditional method

[0076]

[0077] The present invention can synthesize nonlinear functions used in artificial neural networks. Systems using nonlinear functions based on finite state machines (FSMs) generally have better performance in terms of energy consumption, hardware cost, and fault tolerance. The functions that can be realized by the previously proposed finite state machine structure are very limited. The function synthesis method proposed in the present invention increases the design freedom, so that more complex functions can be randomly synthesized. Figure 6 It can be seen that the tanh function implemented by the present invention is closer to the original function and has higher accuracy.

[0078] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A random circuit based on a two-dimensional finite state machine synthesizing a tanh function, characterized in that: The invention comprises a random sequence generating circuit, a comparison circuit, a two-dimensional finite state machine and a multiplexer, wherein the output end of the random sequence generating circuit is connected to the input end of the comparison circuit, the output end of the comparison circuit is respectively connected to the input end of the two-dimensional finite state machine and the input end of the multiplexer, the output end of the two-dimensional finite state machine is connected to the selection end of the multiplexer, the random sequence generating circuit is used to generate an n-bit random sequence, the n-bit random sequence and the binary sequence of the actual value are input to the comparison circuit for comparison, and then a 2-bit random sequence is generated. n Random bit stream, 2 n The random bit stream is input to the input of the two-dimensional finite state machine and the multiplexer. The state of the two-dimensional finite state machine changes with the 2 n The input of the random bit stream is transferred and the current state number is output to the selection end of the multiplexer. The multiplexer is used to output the parameters preset at the input end when the current state is output.

2. The random circuit based on the two-dimensional finite state machine synthesizing tanh function according to claim 1, characterized in that: The random sequence generation circuit includes n registers, which are arranged in a row to form an n-bit linear feedback shift register. Each register stores a binary number. After the binary number of the rightmost register is output, the binary numbers in the n registers are shifted rightward by one position as a whole. At the same time, the binary numbers in the n registers are XORed according to the feedback coefficient, and the result is stored in the leftmost register.

3. The random circuit based on the two-dimensional finite state machine synthesizing tanh function according to claim 2, characterized in that: The random sequence generation circuit is composed of 10 registers and a 10-bit linear feedback shift register. The primitive polynomial used is f(x)=x 10 +x 7 +x 3 +x+1.

4. The random circuit based on the two-dimensional finite state machine synthesizing tanh function according to claim 1, characterized in that: The comparison circuit includes n comparators, each of which includes two input terminals and one output terminal. The n-bit random sequence generated by the random sequence generation circuit is input to the input terminal L of the comparator, the binary sequence of the actual value is input to the input terminal X of the comparator, and the output terminal outputs 2 n The output ends of two comparators among the n comparators are respectively connected to the input end X and the input end K of the two-dimensional finite state machine, and the output ends of the remaining comparators are respectively connected to the input ends of the multiplexer.

5. The random circuit based on the two-dimensional finite state machine synthesizing tanh function according to claim 1, characterized in that: The structural state transition of the two-dimensional finite state machine is: S0 self-loops when the value of X, K is 00, S0 jumps to S1 when the value of X, K is 11, S0 self-loops when the value of X, K is 01, S0 jumps to S4 when the value of X, K is 10; S1 self-loops when the value of X, K is 01, S1 jumps to S2 when the value of X, K is 11, S1 jumps to S5 when the value of X, K is 10, S1 self-loops when the value of X, K is 01, S1 jumps to S2 when the value of X, K is 11, S1 jumps to S5 when the value of X, K is 10, S1 self-loops when the value of X, K is 01, S1 jumps to S6 when the value of X, K is 10, S1 self-loops when the value of X, K is 01, S1 jumps to S7 when the value of X, K is 10, S1 self-loops when the value of X, K is 01, S1 jumps to S8 when the value of X, K is 10, S1 self-loops when the value of X, K is 01, S1 self-loops when the value of X, K is 01, S1 self-loops when the value of X, K is 1 ... When the value of K is 00, it jumps to S0; when the value of X and K is 01, S2 self-loops; when the value of X and K is 11, S2 jumps to S3; when the value of X and K is 10, S2 jumps to S6; when the value of X and K is 00, S2 jumps to S1; when the value of X and K is 11, S3 jumps to S4; when the value of X and K is 10, S3 jumps to S7; when the value of X and K is 01, S3 self-loops; when the value of X and K is When the value of X, K is 00, it jumps to S2; when the value of X, K is 10, S4 self-circulates, when the value of X, K is 11, S4 jumps to S5, when the value of X, K is 00, S4 jumps to S3, when the value of X, K is 01, S4 jumps to S0; when the value of X, K is 10, S5 self-circulates, when the value of X, K is 11, S5 jumps to S6, when the value of X, K is 01, S5 jumps to S1, when the value of X, K is 00 Jump to S4; S6 self-loops when the value of X, K is 10, S6 jumps to S7 when the value of X, K is 11, S6 jumps to S2 when the value of X, K is 01, S6 jumps to S5 when the value of X, K is 00; S7 self-loops when the value of X, K is 11, S7 self-loops when the value of X, K is 10, S7 jumps to S3 when the value of X, K is 01, S7 jumps to S6 when the value of X, K is 00.

6. The random circuit based on synthesizing tanh function of two-dimensional finite state machine according to claim 4, characterized in that: The comparison circuit includes 10 comparators, the output end of the first comparator is connected to the input end X of the two-dimensional finite state machine, the output end of the second comparator is connected to the input end K of the two-dimensional finite state machine, and the output ends of the third to tenth comparators are respectively connected to the input ends of the multiplexer.

7. The random circuit based on the two-dimensional finite state machine synthesizing tanh function according to claim 6, characterized in that: The multiplexer is an eight-to-one multiplexer, including a selection terminal t, eight parameter input terminals w0, w1, ..., w7, and an output terminal Y. The selection terminal t is connected to the output terminal s of the two-dimensional state machine, and the eight parameter input terminals w0, w1, ..., w7 are respectively connected to the output terminals of the third comparator to the tenth comparator in sequence.

8. The method for synthesizing a random circuit based on a two-dimensional finite state machine synthesizing a tanh function according to any one of claims 1 to 7 is characterized in that: The following steps are involved: Step 1: The random sequence generation circuit generates an n-bit random sequence. The n-bit random sequence and the binary sequence of the actual value are input into the comparison circuit for comparison to generate 2 n The output terminals of the two comparators in the comparison circuit are connected to the input terminals X and K of the two-dimensional finite state machine respectively. When the random state transfer of the two-dimensional finite state machine reaches the equilibrium state, the mathematical expression of the two-dimensional finite state machine is established: in, Among them, P t is the probability that the current state of the two-dimensional finite state machine is St, PX is the probability that the bit in the input terminal X of the two-dimensional finite state machine is equal to 1, PK is the probability that the bit in the input terminal K of the two-dimensional finite state machine is equal to 1, P i The current state of the two-dimensional finite state machine in equilibrium is S i The probability of, N is 4, i = 0, 1; j = 0, 1, 2, 3; Step 2, 2 n The random bit stream is input to the input port w of the two-dimensional finite state machine and the multiplexer. t , the state of the two-dimensional finite state machine increases with 2 n The input of the random bit stream is transferred and the current state number is output to the selection terminal t of the multiplexer to obtain the state function PY: Among them, P t is the probability that the current state of the two-dimensional finite state machine is St, which is equal to the input terminal w of the multiplexer t The probability of being selected as output, P wt is the probability that a bit in the input of the multiplexer is equal to 1; Step 3: Calculate the probability PK that the bit in the input terminal K of the two-dimensional finite state machine is equal to 1 and the probability P that the bit in the input terminal of the multiplexer is equal to 1. wt The optimal value of minimizes the error between the state function PY and the objective function tanh; Step 4: Based on the optimal value in step 3, the generated probabilities are PK and P respectively. wt Random bit streams K and wt, synthesizing the tanh function.

9. The method for synthesizing a random circuit based on synthesizing a tanh function using a two-dimensional finite state machine according to claim 8, characterized in that: The two-dimensional finite state machine in step 1 conforms to the Markov chain property and satisfies the following relationship: P i×N+j ·(1-PX)·(1-PK)=P i×N+j-1 ·PX·PK; P i×N+j ·(1-PX)·PK=P (i-1)×N+j ·PX·(1-PK)。 10. The method for synthesizing a random circuit based on synthesizing a tanh function using a two-dimensional finite state machine according to claim 8, characterized in that: The step 3 comprises: 3.

1. Definition The approximate error between the state function PY and the objective function tanh(PX) is defined as: In the formula, is a constant, and we only need to minimize the values ​​of the last two terms, and γ is simplified to 3.2、 Rewritten in matrix format: in, vector Vector b = [P w0 ,P w1 ,…,P w7 ] T ,matrix 3.

3. Set PK to 0.001, 0.002, ..., 0.999, and 1 respectively, and calculate the corresponding P one by one wt and Among 1000 results, when PK is set to 0.5, The value of P is the smallest, and wt The solution is: P w0 =0,P w1 =0,P w2 =0,P w3 =0,P w4 =1,P w5 =1,P w6 =1,P w7 =1。