Method for constructing function processing circuit, function processing circuit and hardware accelerator
By performing continuous second-order function conversion and interpolation processing on the objective function, a function processing circuit with parallel calculation is constructed, which solves the problem of large number of iterations when traditional hardware circuits deal with cosine functions, and improves convergence speed and throughput.
Patent Information
- Application Number
- CN202410866938.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-01
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2044-07-01
AI Technical Summary
Traditional hardware circuits have large iterations when processing cosine functions, resulting in long convergence periods and limited throughput.
By performing continuous second-order function conversion and interpolation processing on the objective function, the first subfunction and the second subfunction are obtained, and a function processing circuit is constructed using the connection multiplier, so that the first subfunction and the second subfunction are calculated in parallel, and the processing is improved efficiency.
The convergence speed and throughput of the function processing circuit are significantly improved, and the precise processing of the cosine function is realized.
Smart Images

Figure CN118394301B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method for constructing a function processing circuit, a function processing circuit and a hardware accelerator. Background Art
[0002] Transcendental functions are the basis of mathematical calculations and the prerequisite for computers to perform complex calculations. As the most basic transcendental function, sine and cosine functions are widely used in digital signal processing, image processing, coordinate axis conversion, and scientific computing. Therefore, the sine and cosine function calculation method based on hardware circuits has developed rapidly and has been widely used in processor design, hardware acceleration and other fields.
[0003] Traditionally, a hardware circuit is generally constructed using CORDIC (Coordinate Rotation Digital Computer) to process (i.e., calculate) sine and cosine functions; however, this method has the disadvantage of a large number of iterations, which in turn causes the constructed hardware circuit to have the disadvantages of a long convergence period and limited throughput when processing sine and cosine functions. Summary of the invention
[0004] Based on this, it is necessary to provide a method for constructing a function processing circuit, a function processing circuit and a hardware accelerator that can improve the convergence speed and throughput of the constructed function processing circuit in response to the above technical problems.
[0005] In a first aspect, the present application provides a method for constructing a function processing circuit, comprising:
[0006] Performing a continuous second-order function conversion process on the objective function to obtain a first sub-function of the objective function; wherein the objective function is a sine function or a cosine function;
[0007] Performing interpolation processing on the objective function to obtain a second sub-function of the objective function; wherein the product of the first sub-function and the second sub-function represents the objective function;
[0008] A function processing circuit corresponding to the target function is constructed according to the first sub-function, the second sub-function, and the connected multipliers corresponding to the product of the first sub-function and the second sub-function.
[0009] In one embodiment, the first sub-function includes a first linear function and a first quadratic function;
[0010] Accordingly, the target function is subjected to continuous second-order function conversion processing to obtain the first sub-function of the target function, including:
[0011] Performing a continuous second-order function conversion process on the objective function to obtain a first linear term coefficient and a first quadratic term coefficient;
[0012] The product of the first linear term coefficient and the angle variable in the objective function is used as the first linear term function;
[0013] The product of the first quadratic term coefficient and the square of the angle variable in the objective function is used as the first quadratic term function;
[0014] The difference between the first linear function and the first quadratic function is used as the first sub-function.
[0015] In one embodiment, the interpolation processing of the objective function to obtain the second sub-function of the objective function includes:
[0016] Using a preset number of interpolation intervals, within the definition domain of the objective function, the objective function is subjected to piecewise interpolation processing to obtain interpolation information corresponding to each interpolation interval; wherein the interpolation information includes an interpolation variable, a starting value, and an end value corresponding to the interpolation interval;
[0017] According to the interpolation information corresponding to each interpolation interval, a second sub-function of the objective function corresponding to each interpolation interval is constructed.
[0018] In one embodiment, the second sub-function includes a zero-order term coefficient, a second first-order term function, and a second second-order term function;
[0019] Correspondingly, constructing the second sub-function of the objective function corresponding to each interpolation interval according to the interpolation information corresponding to each interpolation interval includes:
[0020] For each interpolation interval, the ratio between the objective function and the first sub-function is used as an intermediate function;
[0021] Determine, according to the intermediate function and the interpolation information corresponding to the interpolation interval, the zero-order term coefficient, the second linear term function, and the second quadratic term function corresponding to the interpolation interval;
[0022] The second sub-function of the objective function corresponding to the interpolation interval is obtained by subtracting the sum of the second first-order term function and the zero-order term coefficient from the second second quadratic term function.
[0023] In one embodiment, determining the zero-order term coefficient, the second first-order term function, and the second second-order term function corresponding to the interpolation interval according to the intermediate function and the interpolation information corresponding to the interpolation interval includes:
[0024] Determining a zero-order term coefficient according to the intermediate function and a starting point value of the interpolation interval;
[0025] Determining an intermediate coefficient according to the starting point value, the end point value and the intermediate function;
[0026] Determining a second quadratic term coefficient according to the intermediate coefficient, the zero-order term coefficient, the starting point value, the end point value and the intermediate function;
[0027] Taking the sum of the intermediate coefficient and the coefficient of the second quadratic term as the coefficient of the second linear term;
[0028] The product of the second linear term coefficient and the interpolation variable is used as the second linear term function;
[0029] The sum of the coefficient of the second quadratic term and the square of the interpolation variable is taken as the function of the second quadratic term.
[0030] In one embodiment, constructing a function processing circuit corresponding to the target function according to the first sub-function, the second sub-function, and the connected multipliers corresponding to the product of the first sub-function and the second sub-function includes:
[0031] According to the first sub-function, construct a first sub-function circuit;
[0032] According to the second sub-function, construct a second sub-function circuit;
[0033] The output end of the first sub-function circuit is connected to the first input end of the connection multiplier, and the output end of the second sub-function circuit is connected to the second input end of the connection multiplier to obtain a function processing circuit corresponding to the target function; wherein the input end of the function processing circuit is the input end of the first sub-function circuit and the second sub-function circuit, and the output end of the function processing circuit is the output end of the connection multiplier.
[0034] In one embodiment, constructing a first sub-function circuit according to the first sub-function includes:
[0035] According to the first sub-function, determining a first processing device for constructing the first sub-function circuit; wherein the first processing device includes a first squarer, a first subtractor and a shifter;
[0036] Connecting the output ends of the first squarer and the translator to the input ends of the first subtractor respectively to obtain the first sub-function circuit;
[0037] The input end of the first sub-function circuit is the input end of the first squarer and the translator, and the output end of the first sub-function circuit is the output end of the first subtractor.
[0038] In one embodiment, constructing a second sub-function circuit according to the second sub-function includes:
[0039] According to the second sub-function, determining a second processing device for constructing the second sub-function circuit; wherein the second processing device includes a first memory, a second memory, a third memory, a first multiplier, an adder, a second subtractor, a second multiplier and a second squarer;
[0040] The second input terminal of the first multiplier is connected to the output terminal of the second memory, the output terminal of the first multiplier is connected to the first input terminal of the adder, the second input terminal of the adder is connected to the output terminal of the first memory, the output terminal of the adder is connected to the first input terminal of the second subtractor, the second input terminal of the second subtractor is connected to the output terminal of the second multiplier, the first input terminal of the second multiplier is connected to the output terminal of the third memory, and the second input terminal of the second multiplier is connected to the output terminal of the second squarer, to obtain the second sub-function circuit;
[0041] Among them, the input end of the second sub-function circuit is the input end of the first memory, the second memory, the third memory, the second squarer, and the first input end of the first multiplier; the output end of the second sub-function circuit is the output end of the second subtractor.
[0042] In one embodiment, the method further comprises:
[0043] Get the original function;
[0044] The angle variable in the original function is compressed to obtain the objective function; wherein the domain and range of the objective function are both between [0,1).
[0045] In a second aspect, the present application further provides a function processing circuit, which is constructed by the method for constructing the function processing circuit described in the first aspect.
[0046] In a third aspect, the present application also provides a hardware accelerator, comprising the function processing circuit described in the second aspect.
[0047] In a fourth aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method of the first aspect when executing the computer program.
[0048] In a fifth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when a processor executes the computer program, the steps of the method in the first aspect are implemented.
[0049] In a sixth aspect, the present application further provides a computer program product, including a computer program, and when a processor executes the computer program, the steps of the method of the first aspect are implemented.
[0050] The construction method, function processing circuit and hardware accelerator of the function processing circuit mentioned above obtain the first sub-function of the target function by performing continuous second-order function conversion processing on the target function (i.e., sine function or cosine function); and perform interpolation processing on the target function to obtain the second sub-function of the target function; since the product of the first sub-function and the second sub-function can accurately represent the target function, the function processing circuit corresponding to the constructed target function according to the connected multipliers corresponding to the first sub-function, the second sub-function, and the product of the first sub-function and the second sub-function can accurately process the target function. In addition, since the first sub-function and the second sub-function are connected by the connected multiplier, the first sub-function and the second sub-function belong to parallel calculation in the function processing circuit, which reduces the execution time of the function processing circuit, thereby improving the convergence speed and throughput of the constructed function processing circuit. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0052] FIG1 is a schematic flow chart of a method for constructing a function processing circuit in one embodiment;
[0053] FIG2 is a schematic diagram of a process for constructing a first sub-function of an objective function in one embodiment;
[0054] FIG3 is a schematic diagram of a flow chart of constructing a second sub-function of an objective function in one embodiment;
[0055] FIG4 is a schematic diagram of a flow chart of constructing a second sub-function corresponding to each interpolation interval in one embodiment;
[0056] FIG5 is a schematic diagram of a flow chart for determining a zero-order term coefficient, a second first-order term function, and a second second-order term function in one embodiment;
[0057] FIG6 is a schematic diagram of a flow chart of constructing a function processing circuit corresponding to an objective function in one embodiment;
[0058] FIG7 is a schematic diagram of a flow chart of constructing a first sub-function circuit in one embodiment;
[0059] FIG8 is a schematic diagram of a function processing circuit in one embodiment;
[0060] FIG9 is a schematic diagram of a flow chart of constructing a second sub-function circuit in one embodiment;
[0061] FIG10 is a flow chart of a method for constructing a function processing circuit in another embodiment;
[0062] FIG. 11 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0064] The method for constructing a function processing circuit provided in an embodiment of the present application can be applied to an application environment for constructing a function processing circuit, especially an application environment for constructing a function processing circuit for a sine function and a cosine function. The method can be executed by a computer device, which can be a server or a terminal with powerful computing power. In one embodiment, as shown in FIG1 , a method for constructing a function processing circuit is provided, which is described by taking the application of the method to a server as an example, and specifically includes the following steps:
[0065] S101, performing continuous second-order function conversion processing on the objective function to obtain the first sub-function of the objective function.
[0066] Among them, the objective function is a sine function or a cosine function; the first sub-function is a second-order function. In an embodiment of the present application, the first sub-function includes a first linear function and a first quadratic function.
[0067] Optionally, since the function curves of the sine function and the cosine function are similar to a parabola, the sine function and the cosine function can be accurately calculated by multiplying two sub-functions based on the coordinated parabola synthesis theory.
[0068] Optionally, based on the coordinated parabola synthesis theory, the objective function may be converted into a continuous second-order function to obtain a first sub-function including a first linear function and a first quadratic function.
[0069] S102, performing interpolation processing on the objective function to obtain a second sub-function of the objective function.
[0070] The product of the first sub-function and the second sub-function represents the target function. The second sub-function is a second-order function of nonlinear interpolation.
[0071] Optionally, based on the coordinated parabola synthesis theory, the objective function may be subjected to piecewise interpolation processing, that is, the objective function may be processed into a piecewise second-order function by interpolating the objective function.
[0072] Optionally, the first sub-function can perform an initial approximate calculation on the objective function, and the second sub-function can perform an accurate calculation on the objective function. The first sub-function and the second sub-function can be multiplied to achieve an accurate calculation of the objective function. Specifically, the objective function can be represented by the following formula (1):
[0073] (1)
[0074] in, is the objective function; is the first subfunction; is the second sub-function.
[0075] S103, constructing a function processing circuit corresponding to the target function according to the first sub-function, the second sub-function, and the connected multipliers corresponding to the product of the first sub-function and the second sub-function.
[0076] The connection multiplier is a multiplier that connects the first sub-function and the second sub-function in the function processing circuit.
[0077] Optionally, corresponding processing devices, such as adder, subtractor, and multiplier processing devices, can be selected according to the functional formula of the first sub-function and the second sub-function, and the implementation circuits corresponding to the first sub-function and the second sub-function can be connected by connecting the multiplier to serve as the function processing circuit corresponding to the target function.
[0078] In the method for constructing the function processing circuit, the first sub-function of the target function (i.e., sine function or cosine function) is converted to a continuous second-order function to obtain the first sub-function of the target function; and the target function is interpolated to obtain the second sub-function of the target function; since the product of the first sub-function and the second sub-function can accurately represent the target function, the function processing circuit corresponding to the target function constructed according to the first sub-function, the second sub-function, and the connected multipliers corresponding to the product of the first sub-function and the second sub-function can accurately process the target function. In addition, since the first sub-function and the second sub-function are connected by the connected multiplier, the first sub-function and the second sub-function belong to parallel calculation in the function processing circuit, which reduces the execution time of the function processing circuit, thereby improving the convergence speed and throughput of the constructed function processing circuit.
[0079] It should be noted that the prerequisite for the continuous second-order function conversion and interpolation processing of the objective function is that the domain and range of the objective function must be within a preset range. In the embodiment of the present application, the preset range is [0,1). However, in general, the sine function or cosine function to be processed does not meet this requirement. Therefore, if the domain and range of the sine function or cosine function to be processed do not meet the requirements, the objective function needs to be converted. Specifically, the original function is obtained; the angle variable in the original function is compressed to obtain the objective function; wherein the original function is a sine function or a cosine function; the domain and range of the objective function are both between [0,1).
[0080] For example, if the original function is a sine function, and the original function is as shown in formula (2), the angle variable in the original function can be compressed, as shown in the following formulas (3) and (4). After the processing, the objective function shown in formula (5) can be obtained. After the processing, the domain and range of the objective function are both between [0,1).
[0081] (2)
[0082] (3)
[0083] (4)
[0084] (5)
[0085] in, is the original function; is the angle variable in the original function; is the objective function; is the angle variable, that is, the angle variable in the objective function.
[0086] For example, if the original function is a cosine function, and the original function is as shown in formula (6), the angle variable in the original function can be compressed, as shown in the following formulas (7) and (8). After the processing, the objective function shown in formula (9) can be obtained. After the processing, the domain and range of the objective function are both between [0,1).
[0087] (6)
[0088] (7)
[0089] (8)
[0090] (9)
[0091] Optionally, the first sub-function is a second-order function, so the first sub-function includes a first linear function and a first quadratic function; therefore, in order to ensure the accuracy of the constructed first sub-function, in one embodiment, as shown in FIG2 , a method for constructing a first sub-function of an objective function is provided, specifically comprising the following steps:
[0092] S201, performing continuous second-order function conversion processing on the target function to obtain the first linear term coefficient and the first quadratic term coefficient.
[0093] Among them, the first linear term coefficient is the coefficient of the first linear term function; the first quadratic term coefficient is the coefficient of the first quadratic term function.
[0094] Optionally, the objective function may be converted into a continuous second-order function to obtain the first linear term coefficient and the first quadratic term coefficient in the first sub-function of the approximate objective function. In the embodiment of the present application, the first linear term coefficient is determined to be 2, and the first quadratic term coefficient is determined to be 1.
[0095] S202, taking the product of the first linear term coefficient and the angle variable in the objective function as the first linear term function.
[0096] Optionally, the first linear term coefficient is multiplied by the angle variable in the objective function to obtain the first linear term function. Specifically, the first linear term function can be expressed by the following formula (10):
[0097] (10)
[0098] in, is the first linear function in the first subfunction; 2 is the first linear coefficient; is the angle variable in the objective function.
[0099] S203: The product of the coefficient of the first quadratic term and the square of the angle variable in the objective function is taken as the first quadratic term function.
[0100] Optionally, the first quadratic term coefficient is multiplied by the square of the angle variable in the objective function to obtain the first quadratic term function. Specifically, the first quadratic term function can be expressed by the following formula (11):
[0101] (11)
[0102] in, is the first quadratic function in the first subfunction.
[0103] S204: taking the difference between the first linear term function and the first quadratic term function as the first sub-function.
[0104] Optionally, the first linear function and the first quadratic function are subtracted to obtain a first sub-function. Specifically, the first sub-function can be expressed by the following formula (12):
[0105] (12)
[0106] in, is the first sub-function.
[0107] In this embodiment, by introducing the first linear term coefficient and the first quadratic term coefficient, and constructing the first sub-function by the first linear term coefficient and the first quadratic term coefficient, the accuracy of the constructed first sub-function is ensured.
[0108] Optionally, in order to ensure the accuracy of the second sub-function of the constructed objective function, in one embodiment, as shown in FIG3 , a method for constructing the second sub-function of the objective function is provided, which specifically includes the following steps:
[0109] S301, using a preset number of interpolation intervals, within the definition domain of the objective function, performing piecewise interpolation processing on the objective function to obtain interpolation information corresponding to each interpolation interval.
[0110] The preset number is the number of pre-set interpolation intervals. In the embodiment of the present application, the preset number is ; The interpolation information includes the interpolation variable, starting value and end value corresponding to the interpolation interval.
[0111] Optionally, within the definition domain of the objective function, that is, within the range of [0,1), a preset number of interpolation intervals are divided to perform piecewise interpolation processing on the objective function. Further, the interpolation variable, starting value and end value corresponding to each interpolation interval are determined.
[0112] Specifically, the interpolation variable can be expressed by the following formula (13):
[0113] (13)
[0114] in, is the interpolation variable; The preset number of interpolation intervals.
[0115] S302: construct a second sub-function of the objective function corresponding to each interpolation interval according to the interpolation information corresponding to each interpolation interval.
[0116] Optionally, the second sub-function corresponding to each interpolation interval of the objective function may be constructed according to the interpolation variable, the starting value and the ending value corresponding to each interpolation interval and based on the construction rule of the second sub-function.
[0117] In this embodiment, by performing piecewise interpolation processing on the target function and introducing interpolation information corresponding to each interpolation interval, the accuracy of the second sub-function corresponding to each interpolation interval is ensured.
[0118] Optionally, since the second sub-function is also a second-order function, the second sub-function includes a zero-order term coefficient, a second first-order term function, and a second second-order term function; in order to ensure the accuracy of the constructed second sub-function, in one embodiment, as shown in FIG. 4, a method for constructing a second sub-function corresponding to each interpolation interval is provided, which specifically includes the following steps:
[0119] S401 : For each interpolation interval, use the ratio between the target function and the first sub-function as an intermediate function.
[0120] Optionally, for each interpolation interval, the ratio between the objective function and the first sub-function can be used as an intermediate function. Specifically, the intermediate function can be determined by the following formula (14):
[0121] (14)
[0122] in, is an intermediate function.
[0123] S402, determining the zero-order term coefficient, the second linear term function and the second quadratic term function corresponding to the interpolation interval according to the intermediate function and the interpolation information corresponding to the interpolation interval.
[0124] The zero-order term coefficient is the coefficient of the zero-order term in the second subfunction.
[0125] Optionally, based on the construction rules of the zero-order coefficient, the second linear function and the second quadratic function, the zero-order coefficient, the second linear function and the second quadratic function corresponding to the interpolation interval can be constructed respectively according to the interpolation information corresponding to the intermediate function and the interpolation interval.
[0126] S403, subtracting the sum of the second linear term function and the zero-order term coefficient from the second quadratic term function to obtain a second sub-function corresponding to the objective function at the interpolation interval.
[0127] Optionally, after obtaining the zero-order coefficient, the second linear function and the second quadratic function, the second linear function and the zero-order coefficient can be added, and then the sum is subtracted from the second quadratic function to obtain the second sub-function of the objective function corresponding to the interpolation interval.
[0128] In this embodiment, a method for quickly and accurately constructing a second sub-function is provided by introducing an intermediate function, a zero-order term coefficient, a second first-order term function, and a second second-order term function.
[0129] Optionally, in order to ensure the accuracy of the determined zero-order coefficient, the second linear function and the second quadratic function, in one embodiment, as shown in FIG5 , a method for determining the zero-order coefficient, the second linear function and the second quadratic function is provided, which specifically includes the following steps:
[0130] S501, determining the coefficient of the zero-order term according to the intermediate function and the starting value of the interpolation interval.
[0131] Optionally, the value of the intermediate function at the starting point of the interpolation interval is used as the zero-order term coefficient. Specifically, the zero-order term coefficient can be determined by the following formula (15):
[0132] (15)
[0133] in, For the The starting value of the interpolation interval; For the The zero-order coefficient of the interpolation interval.
[0134] S502, determining an intermediate coefficient according to the starting value, the end value and the intermediate function.
[0135] Optionally, the difference between the value of the intermediate function at the starting point and the value of the intermediate function at the end point is used as the intermediate coefficient. Specifically, the intermediate coefficient can be expressed by the following formula (16):
[0136] (16)
[0137] in, For the The intermediate coefficients of the interpolation intervals; For the The end point value of the interpolation interval.
[0138] S503, determining the second quadratic term coefficient according to the intermediate coefficient, the zero-order term coefficient, the starting point value, the end point value and the intermediate function.
[0139] Optionally, the coefficient of the second quadratic term may be constructed according to the relationship between the coefficient of the second quadratic term and the intermediate coefficient, the coefficient of the zero-order term, the starting value, the end value, and the intermediate function. Specifically, the coefficient of the second quadratic term may be determined by the following formula (17):
[0140] (17)
[0141] in, For the The coefficient of the second quadratic term for the interpolation intervals.
[0142] S504, taking the sum of the intermediate coefficient and the coefficient of the second quadratic term as the coefficient of the second linear term.
[0143] Optionally, the intermediate coefficient and the coefficient of the second quadratic term are added, and the sum is used as the coefficient of the second linear term. Specifically, the coefficient of the second linear term can be expressed by the following formula (18):
[0144] (18)
[0145] in, For the The coefficient of the second linear term for the interpolation intervals.
[0146] S505: taking the product of the second linear term coefficient and the interpolation variable as the second linear term function.
[0147] Optionally, the second linear term coefficient and the interpolation variable are multiplied, and the product obtained is used as the second linear term function. Specifically, the second linear term function can be expressed by the following formula (19):
[0148] (19)
[0149] in, is the second linear function in the second subfunction.
[0150] S506: The sum of the second quadratic term coefficient and the square of the interpolation variable is used as the second quadratic term function.
[0151] Optionally, the second quadratic term coefficient and the square of the interpolation variable are added, and the sum obtained is used as the second quadratic term function. Specifically, the second quadratic term function can be determined by the following formula (20):
[0152] (20)
[0153] in, is the second linear function.
[0154] It should be noted that after obtaining the zero-order term coefficient, the second first-order term function and the second first-order term function, the second sub-function can be expressed by the following formula (21):
[0155] (twenty one)
[0156] In this embodiment, by introducing intermediate coefficients, a method for constructing zero-order coefficients, second linear functions and second quadratic functions is provided, thereby ensuring the accuracy of the constructed zero-order coefficients, second linear functions and second quadratic functions.
[0157] Optionally, in order to ensure the accuracy of the constructed function processing circuit, in one embodiment, as shown in FIG6 , a method for constructing a function processing circuit corresponding to a target function is provided, which specifically includes the following steps:
[0158] S601: construct a first sub-function circuit according to the first sub-function.
[0159] Optionally, the first sub-function circuit may be constructed according to the expression of the first sub-function, such as formula (12) in the above embodiment, by using a processing device, such as an adder, a multiplier, etc.
[0160] S602: construct a second sub-function circuit according to the second sub-function.
[0161] Optionally, the second sub-function circuit can be constructed according to the expression of the second sub-function, such as formula (21) in the above embodiment, by using a processing device, such as an adder, a multiplier, etc.
[0162] S603, connecting the output end of the first sub-function circuit to the first input end of the multiplier, and connecting the output end of the second sub-function circuit to the second input end of the multiplier, to obtain a function processing circuit corresponding to the target function.
[0163] The input end of the function processing circuit is the input end of the first sub-function circuit and the second sub-function circuit, and the output end of the function processing circuit is the output end connected to the multiplier.
[0164] Optionally, the first sub-function circuit and the second sub-function circuit can be connected by connecting a multiplier. Specifically, the output end of the first sub-function circuit is connected to the first input end of the multiplier, and the output end of the second sub-function circuit is connected to the second input end of the multiplier, so as to obtain the second sub-function circuit.
[0165] Further, the input end of the first sub-function and the input end of the second sub-function are used as the input end of the function processing circuit, and the output end of the multiplier is used as the output end of the function processing circuit.
[0166] In this embodiment, by introducing the first sub-function circuit and the second sub-function circuit, the constructed function processing circuit is more intuitive and more in line with the requirements of the objective function.
[0167] Optionally, in one embodiment, as shown in FIG7 , a method for constructing a first sub-function circuit is provided, which specifically includes the following steps:
[0168] S701: Determine, according to a first sub-function, a first processing device for constructing a first sub-function circuit.
[0169] The first processing device includes a first squarer, a first subtractor and a translator.
[0170] Optionally, according to the first sub-function, such as formula (12) in the above embodiment, it can be determined that the first processing device for constructing the first sub-function circuit includes a first squarer, a first subtractor and a shifter.
[0171] As shown in FIG8 , it is a schematic diagram of a function processing circuit, wherein 810 is a first sub-function circuit part, in which 811 is a first squarer, 812 is a first subtractor, 813 is a shifter, and 830 is a connection multiplier.
[0172] S702, connecting the output ends of the first squarer and the shifter to the input ends of the first subtractor respectively to obtain a first sub-function circuit.
[0173] The input end of the first sub-function circuit is the input end of the first squarer and the shifter, and the output end of the first sub-function circuit is the output end of the first subtractor.
[0174] Optionally, as shown in Figure 8, the input end of the first squarer 811 is connected to the input circuit of the function processing circuit; the input end of the shifter 813 is connected to the input circuit of the function processing circuit; and the output end of the first squarer 811 is connected to the first input end of the first subtractor 812; further, the output end of the shifter 813 is connected to the second input end of the first subtractor 812, so as to obtain the first sub-function circuit.
[0175] Further, the input ends of the first squarer 811 and the shifter 813 are used as the input ends of the first sub-function circuit, and the output end of the first subtractor 812 is used as the output end of the first sub-function circuit.
[0176] In this embodiment, by determining the first processing device according to the first sub-function and connecting the first processing devices, a method for constructing a first sub-function circuit is provided, and the accuracy of the constructed first sub-function circuit is ensured.
[0177] Optionally, in one embodiment, as shown in FIG9 , a method for constructing a second sub-function circuit is provided, which specifically includes the following steps:
[0178] S901: Determine, according to a second sub-function, a second processing device for constructing a second sub-function circuit.
[0179] The second processing device includes a first memory, a second memory, a third memory, a first multiplier, an adder, a second subtractor, a second multiplier and a second squarer.
[0180] It should be noted that, although each interpolation interval has a second sub-function, the constitutive expressions of the second sub-functions corresponding to each difference interval are the same, except that the coefficient of the zero-order term, the coefficient of the second first-order term, and the coefficient of the second second-order term are different. Therefore, it is only necessary to construct a second sub-function circuit, and store the coefficient of the zero-order term, the coefficient of the second first-order term, and the coefficient of the second second-order term of each interpolation interval through a memory.
[0181] Optionally, according to the expression of the second sub-function, such as formula (21) in the above embodiment, it can be determined that the second processing device required to construct the second sub-function circuit includes a first memory, a second memory, a third memory, a first multiplier, an adder, a second subtractor, a second multiplier and a second squarer. Among them, the first storage area is used to store the zero-order coefficient of the second sub-function corresponding to each interpolation interval; the second storage area is used to store the second first-order coefficient of the second sub-function corresponding to each interpolation interval; the third storage area is used to store the second second-order coefficient in the second sub-function corresponding to each interpolation interval.
[0182] Optionally, 820 in Figure 8 in the above embodiment is a second sub-function circuit, in which 821 is a first memory, 822 is a second memory, 823 is a third memory, 824 is a first multiplier, 825 is an adder, 826 is a second subtractor, 827 is a second multiplier and 828 is a second squarer.
[0183] S902, connect the second input of the first multiplier to the output of the second memory, connect the output of the first multiplier to the first input of the adder, connect the second input of the adder to the output of the first memory, connect the output of the adder to the first input of the second subtractor, connect the second input of the second subtractor to the output of the second multiplier, connect the first input of the second multiplier to the output of the third memory, and connect the second input of the second multiplier to the output of the second squarer to obtain a second sub-function circuit.
[0184] The input end of the second sub-function circuit is the input end of the first memory, the second memory, the third memory, the second squarer, and the first input end of the first multiplier; the output end of the second sub-function circuit is the output end of the second subtractor.
[0185] Optionally, as shown in Figure 8, the second input terminal of the first multiplier 824 is connected to the output terminal of the second memory 822, the output terminal of the first multiplier 824 is connected to the first input terminal of the adder 825, the second input terminal of the adder 825 is connected to the output terminal of the first memory 821, the output terminal of the adder 825 is connected to the first input terminal of the second subtractor 826, the second input terminal of the second subtractor 826 is connected to the output terminal of the second multiplier 827, the first input terminal of the second multiplier 827 is connected to the output terminal of the third memory 823, and the second input terminal of the second multiplier 827 is connected to the output terminal of the second squarer 828, so as to obtain a second sub-function circuit.
[0186] Furthermore, the input ends of the first memory, the second memory, the third memory and the second squarer are connected to the input end of the function processing circuit; and the first input end of the first multiplier is used as the input end of the second sub-function circuit, and the output end of the second subtractor is used as the output end of the second sub-function circuit.
[0187] In this embodiment, by determining the second processing device according to the second sub-function and connecting the second processing devices, a method for constructing a second sub-function circuit is provided, and the accuracy of the constructed second sub-function circuit is ensured.
[0188] FIG10 is a flow chart of a method for constructing a function processing circuit in another embodiment. Based on the above embodiment, this embodiment provides an optional example of a method for constructing a function processing circuit. In conjunction with FIG10 , the specific implementation process is as follows:
[0189] S1001, obtaining an original function, and compressing the angle variables in the original function to obtain a target function.
[0190] The objective function is a sine function or a cosine function, and the domain and range of the objective function are both between [0,1).
[0191] S1002, performing continuous second-order function conversion processing on the target function to obtain the first linear term coefficient and the first quadratic term coefficient.
[0192] S1003, taking the product of the first linear term coefficient and the angle variable in the objective function as the first linear term function.
[0193] S1004: The product of the first quadratic term coefficient and the square of the angle variable in the objective function is taken as the first quadratic term function.
[0194] S1005: Taking the difference between the first linear term function and the first quadratic term function as the first sub-function of the objective function.
[0195] S1006, using a preset number of interpolation intervals, within the definition domain of the objective function, performing piecewise interpolation processing on the objective function to obtain interpolation information corresponding to each interpolation interval.
[0196] The interpolation information includes the interpolation variable, the starting value and the ending value corresponding to the interpolation interval.
[0197] S1007: Use the ratio between the target function and the first sub-function as the intermediate function.
[0198] S1008, determining the zero-order term coefficient, the second linear term function and the second quadratic term function corresponding to each interpolation interval according to the intermediate function and the interpolation information corresponding to each interpolation interval.
[0199] Optionally, determine the zero-order coefficient based on the intermediate function and the starting value of the interpolation interval; determine the intermediate coefficient based on the starting value, the end value and the intermediate function; determine the second quadratic coefficient based on the intermediate coefficient, the zero-order coefficient, the starting value, the end value and the intermediate function; take the sum of the intermediate coefficient and the second quadratic coefficient as the second first-order coefficient; take the product of the second first-order coefficient and the interpolation variable as the second first-order function; take the sum of the second quadratic coefficient and the square of the interpolation variable as the second quadratic function.
[0200] S1009: Subtract the sum of the second first-order term function and the zero-order term coefficient corresponding to each interpolation interval from the second quadratic term function to obtain a second sub-function of the objective function corresponding to each interpolation interval.
[0201] S1010: construct a first sub-function circuit according to the first sub-function.
[0202] Optionally, according to the first sub-function, a first processing device for constructing a first sub-function circuit is determined; wherein the first processing device includes a first squarer, a first subtractor and a translator; the output ends of the first squarer and the translator are respectively connected to the input ends of the first subtractor to obtain a first sub-function circuit; wherein the input end of the first sub-function circuit is the input end of the first squarer and the translator, and the output end of the first sub-function circuit is the output end of the first subtractor.
[0203] S1011, construct a second sub-function circuit according to the second sub-function.
[0204] Optionally, according to the second sub-function, a second processing device for constructing a second sub-function circuit is determined; wherein the second processing device includes a first memory, a second memory, a third memory, a first multiplier, an adder, a second subtractor, a second multiplier and a second squarer; the second input end of the first multiplier is connected to the output end of the second memory, the output end of the first multiplier is connected to the first input end of the adder, the second input end of the adder is connected to the output end of the first memory, the output end of the adder is connected to the first input end of the second subtractor, the second input end of the second subtractor is connected to the output end of the second multiplier, the first input end of the second multiplier is connected to the output end of the third memory, and the second input end of the second multiplier is connected to the output end of the second squarer to obtain a second sub-function circuit; wherein the input end of the second sub-function circuit is the input end of the first memory, the second memory, the third memory, the second squarer, and the first input end of the first multiplier; the output end of the second sub-function circuit is the output end of the second subtractor.
[0205] S1012, connecting the output end of the first sub-function circuit to the first input end of the multiplier, and connecting the output end of the second sub-function circuit to the second input end of the multiplier, to obtain a function processing circuit corresponding to the target function.
[0206] The specific process of the above S1001-S1012 can be found in the description of the above method embodiment. The implementation principle and technical effect are similar and will not be repeated here.
[0207] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0208] Optionally, an embodiment of the present application further provides a function processing circuit, as shown in FIG8 in the above embodiment, and the function processing circuit is constructed based on the function processing circuit construction method provided in the above embodiment.
[0209] Optionally, an embodiment of the present application further provides a hardware accelerator, which integrates a function processing circuit.
[0210] It should be noted that the function processing circuit constructed in the above embodiment can also be integrated into chips of various processors.
[0211] Each module in the construction device of the above function processing circuit can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.
[0212] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be shown in FIG11. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a method for constructing a function processing circuit is implemented.
[0213] Those skilled in the art will understand that the structure shown in FIG. 11 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0214] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps of the method for constructing the function processing circuit are implemented.
[0215] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for constructing the function processing circuit are implemented.
[0216] In one embodiment, a computer program product is provided, including a computer program, which, when executed by a processor, implements the steps of the method for constructing the function processing circuit.
[0217] It should be noted that the data involved in this application (including but not limited to data used for analysis, storage, display, etc.) are all information and data fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0218] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0219] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0220] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for constructing a function processing circuit, characterized in that: The method comprises: Performing a continuous second-order function conversion process on the objective function to obtain a first first-order term coefficient and a first second-order term coefficient; wherein the objective function is a sine function or a cosine function; The product of the first linear term coefficient and the angle variable in the objective function is used as the first linear term function; The product of the first quadratic term coefficient and the square of the angle variable in the objective function is used as the first quadratic term function; Taking the difference between the first linear term function and the first quadratic term function as a first sub-function; Performing interpolation processing on the objective function to obtain a second sub-function of the objective function; wherein the product of the first sub-function and the second sub-function represents the objective function; constructing a first sub-function circuit according to the first sub-function, and constructing a second sub-function circuit according to the second sub-function; Connecting the output end of the first sub-function circuit to the first input end of the multiplier, and connecting the output end of the second sub-function circuit to the second input end of the multiplier, to obtain a function processing circuit corresponding to the target function; The input end of the function processing circuit is the input end of the first sub-function circuit and the second sub-function circuit, and the output end of the function processing circuit is the output end of the connected multiplier.
2. The method according to claim 1, characterized in that The interpolation processing is performed on the objective function to obtain a second sub-function of the objective function, including: Using a preset number of interpolation intervals, within the definition domain of the objective function, the objective function is subjected to piecewise interpolation processing to obtain interpolation information corresponding to each interpolation interval; wherein the interpolation information includes an interpolation variable, a starting value, and an end value corresponding to the interpolation interval; According to the interpolation information corresponding to each interpolation interval, a second sub-function of the objective function corresponding to each interpolation interval is constructed.
3. The method according to claim 2, characterized in that The second sub-function includes a zero-order term coefficient, a second first-order term function, and a second second-order term function; Correspondingly, constructing the second sub-function of the objective function corresponding to each interpolation interval according to the interpolation information corresponding to each interpolation interval includes: For each interpolation interval, the ratio between the objective function and the first sub-function is used as an intermediate function; Determine, according to the intermediate function and the interpolation information corresponding to the interpolation interval, the zero-order term coefficient, the second linear term function, and the second quadratic term function corresponding to the interpolation interval; The second sub-function of the objective function corresponding to the interpolation interval is obtained by subtracting the sum of the second first-order term function and the zero-order term coefficient from the second second quadratic term function.
4. The method according to claim 3, characterized in that The step of determining the zero-order term coefficient, the second first-order term function, and the second second-order term function corresponding to the interpolation interval according to the intermediate function and the interpolation information corresponding to the interpolation interval includes: Determining a zero-order term coefficient according to the intermediate function and a starting point value of the interpolation interval; Determining an intermediate coefficient according to the starting point value, the end point value and the intermediate function; Determining a second quadratic term coefficient according to the intermediate coefficient, the zero-order term coefficient, the starting point value, the end point value and the intermediate function; Taking the sum of the intermediate coefficient and the coefficient of the second quadratic term as the coefficient of the second linear term; The product of the second linear term coefficient and the interpolation variable is used as the second linear term function; The sum of the coefficient of the second quadratic term and the square of the interpolation variable is taken as the function of the second quadratic term.
5. The method according to claim 1, characterized in that The step of constructing a first sub-function circuit according to the first sub-function comprises: According to the first sub-function, determining a first processing device for constructing the first sub-function circuit; wherein the first processing device includes a first squarer, a first subtractor and a shifter; Connecting the output ends of the first squarer and the translator to the input ends of the first subtractor respectively to obtain the first sub-function circuit; The input end of the first sub-function circuit is the input end of the first squarer and the translator, and the output end of the first sub-function circuit is the output end of the first subtractor.
6. The method according to claim 1, characterized in that The step of constructing a second sub-function circuit according to the second sub-function comprises: According to the second sub-function, determining a second processing device for constructing the second sub-function circuit; wherein the second processing device includes a first memory, a second memory, a third memory, a first multiplier, an adder, a second subtractor, a second multiplier and a second squarer; The second input terminal of the first multiplier is connected to the output terminal of the second memory, the output terminal of the first multiplier is connected to the first input terminal of the adder, the second input terminal of the adder is connected to the output terminal of the first memory, the output terminal of the adder is connected to the first input terminal of the second subtractor, the second input terminal of the second subtractor is connected to the output terminal of the second multiplier, the first input terminal of the second multiplier is connected to the output terminal of the third memory, and the second input terminal of the second multiplier is connected to the output terminal of the second squarer, to obtain the second sub-function circuit; Among them, the input end of the second sub-function circuit is the input end of the first memory, the second memory, the third memory, the second squarer, and the first input end of the first multiplier; the output end of the second sub-function circuit is the output end of the second subtractor.
7. The method according to claim 1, characterized in that The method further comprises: Get the original function; The angle variable in the original function is compressed to obtain the objective function; wherein the domain and range of the objective function are both between [0,1).
8. A function processing circuit, characterized in that: The function processing circuit is constructed based on the construction method of the function processing circuit according to any one of claims 1 to 7.
9. A hardware accelerator, characterized in that: The hardware accelerator is integrated with the function processing circuit described in claim 8.
