Calculation method and device of polynomial and computer equipment

By splitting the polynomial into subpolynomials and using matrix operation units to perform outer product operations and compensated exponentiation operations, the problem of low polynomial computation efficiency in the prior art is solved, and efficient polynomial computation is achieved.

CN121144672APending Publication Date: 2025-12-16HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410774075.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2025-12-16

AI Technical Summary

Technical Problem

In existing technologies, polynomial computation is mainly implemented through scalar computation units or vector computation units, resulting in low computational efficiency and failing to meet the needs of high-performance computing.

Method used

The polynomial is split into multiple subpolynomials, and the outer product operation and compensated exponentiation operation are performed using the matrix operation unit. The calculation is carried out through vector registers and matrix operation units, thereby improving the computational efficiency.

Benefits of technology

By utilizing matrix operation units, the efficiency of polynomial calculations is significantly improved, computational resources are fully utilized, and computational costs are reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121144672A_ABST
    Figure CN121144672A_ABST
Patent Text Reader

Abstract

The embodiment of the invention belongs to the technical field of computers, and particularly relates to a polynomial calculation method and device and computer equipment. In the method, a first polynomial can be split into a product of a reference polynomial and a compensation exponential power, and outer product operation is performed on X first vectors corresponding to exponential powers of N input data and a second vector formed by coefficients of monomials of the same index in the reference polynomial through a matrix operation unit, and the matrix obtained by the outer product operation is accumulated to obtain the calculation result of the reference polynomial of the first polynomial corresponding to the plurality of input data, and then the calculation result is multiplied by the corresponding compensation exponent power to obtain the calculation result of the first polynomial. By the adoption of the method and device, part of the calculation process of the polynomial can be converted into matrix operation, implementation is achieved through the matrix operation unit, and the calculation efficiency of the polynomial can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, in particular to a polynomial calculation method, device and computer equipment. BACKGROUND

[0002] Transcendental functions as the main part of the basic mathematical function library, in aerospace, nuclear physics and gene sequencing, etc. various high-performance computing applications will have a wide range of applications.

[0003] At present, the transcendental function can be calculated by polynomial approximation, that is, the transcendental function is converted into a polynomial, and the calculation of the transcendental function is realized by calculating the polynomial.

[0004] However, the current polynomial calculation is realized by scalar calculation unit or vector calculation unit, and the calculation efficiency is low. SUMMARY

[0005] The embodiments of the present application provide a polynomial calculation method, device and computer equipment, which can improve the calculation efficiency of the polynomial, and the corresponding technical solutions are as follows:

[0006] In a first aspect, a polynomial calculation method is provided, which is applied to a processor including a vector register and a matrix operation unit. The calculation method includes: receiving a calculation instruction sent by an application program, the calculation instruction including the calculation of a first polynomial, the difference between the exponents of two adjacent monomials in the first polynomial being Y, the first polynomial being expressed as the sum of a plurality of sub-polynomials, each sub-polynomial including X monomials, each sub-polynomial being the product of a reference polynomial and a compensation exponent power, and the difference between the exponents of two adjacent monomials in each sub-polynomial being equal. Determining X exponents in the reference polynomial as reference exponents, and storing X first vectors corresponding to the exponent powers of N input data corresponding to the X reference exponents into the vector register. Constructing a vector for the coefficients of the monomials with the same exponent in each reference polynomial to obtain X second vectors; performing outer product operation of the X first vectors and the X second vectors by the matrix operation unit and summing to obtain a result matrix, each row or each column in the result matrix representing the calculation result of the reference polynomial in each sub-polynomial corresponding to N input data. Multiplying the calculation result of the reference polynomial of each sub-polynomial by the result of the compensation exponent power to obtain the calculation result of the first polynomial of N input data.

[0007] In the scheme shown in this application, a polynomial can be decomposed into multiple sub-polynomials. The calculation of each sub-polynomial can include the calculation of the base polynomial and the product of the base polynomial and the compensation exponent. In each sub-polynomial and the corresponding base polynomial, the exponents (orders of the monomials) of the included monomials are the same, but the coefficients of the included monomials are different. For the calculation result of the base polynomial corresponding to multiple input data, the outer product operation can be performed on the first vector and the second vector through the matrix operation unit, and the result matrix of the outer product operation is accumulated. After obtaining the calculation result of each base polynomial, the order of the monomials included in the base polynomial can be compensated by multiplying it with the corresponding compensation exponent, thereby obtaining the calculation result of each sub-polynomial. The compensation exponent is a specified power of the input data, which is equal to the difference between the order of the monomials in the base polynomial and the order of the monomials in the corresponding sub-polynomial.

[0008] As can be seen, in the embodiments of this application, the partial calculation of the polynomial is converted into matrix operations, and the corresponding matrix operations are performed using the matrix operation unit, thereby accelerating the calculation of the polynomial and improving the calculation efficiency of the polynomial.

[0009] In one feasible approach, the exponent differences of the monomials corresponding to adjacent coefficients in the second vector are all equal, and the monomials corresponding to coefficients at the same position in multiple second vectors are adjacent in the first polynomial.

[0010] In one feasible approach, the X exponents in the benchmark polynomial are the exponents corresponding to the first X monomials in the first polynomial.

[0011] In one feasible approach, the calculation result of the first polynomial for N input data is obtained by multiplying the calculation result of the base polynomial of each sub-polynomial by the compensation exponent. This includes: grouping the calculation results of the base polynomial of each sub-polynomial pairwise to obtain at least one vector group to be compensated for exponent; multiplying the third vector with the higher exponent in each vector group with the compensation vector in tandem to obtain a fourth vector for each vector group, where the exponent of each vector in the vector group is the exponent of the X monomials corresponding to the X coefficients of each vector, and the elements of the compensation vector are the powers of the first exponents corresponding to the N input data, where the first exponent is equal to the difference between the exponents of the two vectors in the vector group; adding the fifth vector with the lower exponent in each vector group with the corresponding fourth vector in tandem to obtain a result vector; when there are multiple result vectors, grouping the multiple result vectors pairwise to obtain at least one vector group to be compensated for exponent, and then proceeding to multiply the third vector with the higher exponent in each vector group with the compensation vector in tandem; when there is only one result vector, the result vector is determined as the calculation result of the first polynomial.

[0012] In this embodiment, multiple reference polynomials with the same coefficients but different input data can be treated as a vector. The multiple vectors are then grouped in pairs. The vectors in the vector group are compensated by the compensation vector and summed to obtain a new vector. The new vectors are then grouped in pairs again, and the vectors in the vector group are compensated by the compensation vector and summed. This hierarchical iterative compensation of the vectors can reduce the number of compensations and improve the compensation efficiency.

[0013] In one possible implementation, the above calculation method further includes: in response to a calculation instruction, obtaining a second polynomial indicated by the calculation instruction; if the remainder obtained by dividing the number of monomials included in the second polynomial by a first value is less than a remainder threshold, the first polynomial is the polynomial after deleting M terms from the second polynomial, wherein the first value is the ratio of the bit width corresponding to the vector register to the bit width occupied by an input data, and the value of M is equal to the value of the remainder; obtaining the calculation result corresponding to the deleted M terms in the second polynomial; and summing the calculation result corresponding to the deleted M terms with the calculation result of the first polynomial to obtain the calculation result of the second polynomial.

[0014] In this embodiment, the coefficients corresponding to the M terms fill the vector register, or even fail to fill half of it. Therefore, if the matrix operation unit performs an outer product operation on the second vector (composed of the coefficients of the M terms) and the first vector, it cannot fully utilize the performance of the matrix operation unit, resulting in reduced computational efficiency and wasted computational resources. Therefore, in this embodiment, when the remaining M terms in the second polynomial are less than the remainder threshold, the second polynomial can be split into two polynomials for separate calculation: a polynomial composed of the first M terms or the last M terms, and a first polynomial. By calculating the polynomial composed of the first M terms or the last M terms using vector computation and calculating the first polynomial using matrix computation, computational efficiency can be improved, thus improving the result of obtaining the second polynomial.

[0015] In one possible implementation, the above calculation method further includes: in response to a calculation instruction, obtaining a third polynomial indicated by the calculation instruction; if the exponent of the first term of the third polynomial is greater than 1, the first polynomial is a polynomial whose exponent of each monomial in the third polynomial is reduced by L, where the value of L is equal to the difference between the exponent of the first term of the third polynomial and 1; based on L, exponent compensation is performed on the result corresponding to each monomial in the calculation result of the first polynomial to obtain the calculation result of the third polynomial.

[0016] In this embodiment, if the exponent of the first term of the third polynomial to be calculated (the order of the first polynomial) is greater than 1, the exponent of each term of the third polynomial can be reduced by L to obtain the first polynomial, making the exponent of the first term of the first polynomial 1. Then, after obtaining the calculation result of each term of the first polynomial, the order of each term can be uniformly padded to obtain the calculation result of the third polynomial. In this way, the order of each term is relatively low during the process of the first polynomial, which reduces the steps of exponentiation of the input data and the number of times the result matrix corresponding to the first polynomial needs to be compensated, thereby improving the computational efficiency of the polynomial.

[0017] In one feasible approach, the computation instructions include the computation of multiple first polynomials; and the formation of a vector from the coefficients of monomials with the same exponent in each base polynomial to obtain X second vectors, including: forming a vector from the coefficients of monomials with the same exponent in each base polynomial corresponding to the multiple first polynomials to obtain X second vectors, wherein the coefficients corresponding to any one of the multiple first polynomials occupy the same position in the X second vectors. This allows for parallel computation of multiple polynomials, fully utilizing the computational performance of the matrix operation unit and further improving the computational efficiency of polynomials.

[0018] In one feasible approach, the first polynomial is obtained by polynomial approximation and parameter reduction of the transcendental function.

[0019] Secondly, a polynomial computing apparatus is provided, the apparatus comprising:

[0020] The instruction receiving module is used to receive calculation instructions sent by the application. The calculation instructions include the calculation of a first polynomial, in which the difference between the exponents of two adjacent monomials is Y. The first polynomial is represented as the sum of multiple sub-polynomials, each sub-polynomial including X monomials. Each sub-polynomial is the product of the base polynomial and the compensation exponent. The difference between the exponents of two adjacent polynomials in each sub-polynomial is equal.

[0021] The vector generation module is used to determine the X exponents in the benchmark polynomial as benchmark exponents, and store the X first vectors corresponding to the exponents of the N input data corresponding to the X benchmark exponents into the vector register of the processor. The coefficients of the monomials with the same exponent in each benchmark polynomial are combined into a vector to obtain X second vectors.

[0022] The matrix operation module is used to perform the outer product operation of X first vectors and X second vectors through the matrix operation unit of the processor and sum them to obtain the result matrix. In the result matrix, each row or column corresponding to the first vector represents the calculation result of the base polynomial in each sub-polynomial corresponding to N input data.

[0023] The result compensation module is used to obtain the calculation result of the first polynomial of N input data by multiplying the calculation result of the base polynomial of each sub-polynomial by the compensation exponent.

[0024] In one feasible approach, the exponent differences of the monomials corresponding to adjacent coefficients in the second vector are all equal, and the monomials corresponding to coefficients at the same position in multiple second vectors are adjacent in the first polynomial.

[0025] In one feasible approach, the X exponents in the benchmark polynomial are the exponents corresponding to the first X monomials in the first polynomial.

[0026] In one feasible implementation, the result compensation module is used to: group the calculation results of the base polynomial of each sub-polynomial pairwise to obtain at least one vector group to be compensated for exponents; multiply the third vector with the higher exponent in each vector group with the compensation vector in symmetrical order to obtain the fourth vector corresponding to each vector group, where the exponent of each vector in the vector group is the exponent of the X monomials corresponding to the X coefficients of each vector, and the elements of the compensation vector are the powers of the first exponents corresponding to the N input data, where the first exponent is equal to the difference between the exponents of the two vectors in the vector group; add the fifth vector with the lower exponent in each vector group with the corresponding fourth vector in symmetrical order to obtain the result vector; when there are multiple result vectors, group the multiple result vectors pairwise to obtain at least one vector group to be compensated for exponents, and proceed to multiply the third vector with the higher exponent in each vector group with the compensation vector in symmetrical order; when there is only one result vector, determine the result vector as the calculation result of the first polynomial.

[0027] In one possible implementation, the apparatus further includes a disassembly and merging module, configured to: in response to a calculation instruction, acquire a second polynomial indicated by the calculation instruction; if the remainder obtained by dividing the number of monomials included in the second polynomial by a first value is less than a remainder threshold, the first polynomial is the polynomial after deleting M terms from the second polynomial, wherein the first value is the ratio of the bit width corresponding to the vector register to the bit width occupied by an input data, and the value of M is equal to the value of the remainder; acquire the calculation result corresponding to the deleted M terms in the second polynomial; and sum the calculation result corresponding to the deleted M terms with the calculation result of the first polynomial to obtain the calculation result of the second polynomial.

[0028] In one possible implementation, the device further includes a disassembly and merging module for: in response to a calculation instruction, obtaining a third polynomial indicated by the calculation instruction; if the exponent of the first term of the third polynomial is greater than 1, the first polynomial is a polynomial whose exponent of each monomial in the third polynomial is reduced by L, where the value of L is equal to the difference between the exponent of the first term of the third polynomial and 1; and based on L, performing exponent compensation on the result corresponding to each monomial in the calculation result of the first polynomial to obtain the calculation result of the third polynomial.

[0029] In one possible implementation, the above calculation instructions include the calculation of multiple first polynomials, and a vector generation module is used to: construct a vector from the coefficients of monomials with the same exponent in each of the reference polynomials corresponding to the multiple first polynomials, to obtain X second vectors, wherein the coefficients corresponding to any one of the multiple first polynomials are in the same position in the X second vectors.

[0030] In one feasible approach, the first polynomial is obtained by polynomial approximation and parameter reduction of the transcendental function.

[0031] Thirdly, a computer device is provided, comprising a processor and a memory, the processor including a matrix operation unit and a vector register, and the memory storing instructions. The processor executes the instructions stored in the memory to cause the computing device to perform the computational method described in the first aspect above.

[0032] Fourthly, a computer program product is provided, the computer program product including instructions that, when executed by a processor of a computer device, cause the processor to perform the calculation method described in the first aspect.

[0033] Fifthly, a computer-readable storage medium is provided, comprising computer program instructions that, when executed by a processor of a computer device, cause the processor to perform the computation method described in the first aspect. Attached Figure Description

[0034] Figure 1 This is a schematic diagram of a matrix operation unit provided in an embodiment of this application;

[0035] Figure 2 This is a schematic diagram of a computer device structure provided in an embodiment of this application;

[0036] Figure 3 This is a schematic diagram of the structure of a processor provided in an embodiment of this application;

[0037] Figure 4 This is a flowchart of a polynomial calculation method provided in an embodiment of this application;

[0038] Figure 5 This is a schematic diagram of a polynomial calculation method provided in an embodiment of this application;

[0039] Figure 6 This is a schematic diagram of a polynomial calculation method provided in an embodiment of this application;

[0040] Figure 7 This is a schematic diagram of a polynomial calculation method provided in an embodiment of this application;

[0041] Figure 8 This is a schematic diagram of a polynomial calculation method provided in an embodiment of this application;

[0042] Figure 9 This is a flowchart of a polynomial calculation method provided in an embodiment of this application;

[0043] Figure 10 This is a schematic diagram of a polynomial computing device structure provided in an embodiment of this application. Detailed Implementation

[0044] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0045] The following is a description of the terms used in the embodiments of this application:

[0046] Transcendental functions are functions whose relationships between variables cannot be expressed by a finite number of additions, subtractions, multiplications, divisions, exponentiations, and root extractions. Examples include trigonometric functions, logarithmic functions, inverse trigonometric functions, and exponential functions.

[0047] Transcendental functions are primarily calculated using methods such as polynomial approximation, lookup tables, and shift-addition. Shift-addition is mainly used in embedded platforms lacking floating-point capabilities, and its computational accuracy is generally low. In current mainstream implementations, lookup table algorithms are generally not used alone, but rather combined with polynomial approximation-based algorithms as a component of the transcendental function algorithm (for example, in the sin / cos function, a lookup table can be used to store the approximate function value for the divided interval, and within the interval, a lower-order polynomial approximation can be used to calculate the accurate value, followed by a reconstruction step to obtain the final result, thereby reducing the polynomial order and optimizing performance).

[0048] Existing polynomial approximation-based algorithms generally consist of three steps: 1. Range Reduction, 2. Polynomial Approximation, and 3. Reconstruction. In range reduction, mathematical properties are used to transform the function into an equivalent expression, and the input interval of the function is reduced to a smaller interval, allowing the use of other easily computed functions to approximate the target function. Then, a finite-degree approximation polynomial is selected to approximate the function; the computation of the polynomial is often the most time-consuming part of the computation beyond the function itself. Finally, the approximate value is substituted into the equivalent expression to obtain an approximate value of the function, completing the reconstruction process and yielding the final function result.

[0049] The Scalable Vector Extension (SME) is a matrix operation unit that provides vector outer product addition / subtraction instructions to accelerate matrix multiplication. The SME can perform outer product operations on vectors stored in vector registers, such as the Scalable Vector Extension (SVE) register. Figure 1 As shown, SME can perform an outer product operation on vectors A[a0, a1, a2, a3, a4, a5, a6, a7] and B[b0, b1, b2, b3, b4, b5, b6, b7], and the resulting matrix AB[“a0b0, a0b1, a0b2, a0b3, a0b4, a0b5, a0b6, a0b7”, ..., “a7b0, a7b1, a7b2, a7b3, a7b4, a7b5, a7b6, a7b7”].

[0050] Currently, polynomial computation is implemented using scalar or vector computation units. For example, the Horner algorithm is implemented using scalar or vector computation units to solve polynomials. However, the computational efficiency of both scalar and vector computation units is lower than that of matrix operation units. Therefore, combining matrix operation units with polynomial computation can improve the computational efficiency of polynomials.

[0051] The fundamental mathematical function library is a basic component of computer software systems, providing support for fundamental mathematical function calculations and is widely used in various applications. Transcendental functions, as the core of the fundamental mathematical function library, have a broad impact on the performance of high-performance computing applications such as aerospace, nuclear physics, and gene sequencing, through their algorithm design and implementation.

[0052] This application provides a method for calculating polynomials, in which some calculations can be performed by a matrix operation unit, thereby improving the execution efficiency of polynomials. This calculation method can be set in a basic mathematical function library, providing a highly efficient polynomial calculation method for various parts of an application. Figure 2 This is a schematic diagram of a computer device structure illustrating a polynomial calculation method provided in an embodiment of this application. Figure 2 As shown, the computing device 100 includes a bus 102, a processor 104, a memory 106, and a communication interface 108. The processor 104, the memory 106, and the communication interface 108 communicate with each other via the bus 102. The computing device 100 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 100.

[0053] Bus 102 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, Figure 2 The bus 102 may be represented by a single line, but this does not mean that there is only one bus or one type of bus. The bus 102 may include a path for transmitting information between various components of the computing device 100 (e.g., memory 106, processor 104, communication interface 108).

[0054] The processor 104 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0055] Memory 106 may include volatile memory, such as random access memory (RAM). Memory 106 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).

[0056] The memory 106 stores executable program code, and the processor 104 executes this executable program code to implement the polynomial calculation method provided in this application embodiment. In one example, such as Figure 3 As shown, the processor 104 may include a control unit 1041, a matrix operation unit 1042 (such as SME), which can be used to perform matrix operations in the polynomial calculation method, and may also include a vector register 1043 for storing input data and coefficients in the polynomial calculation method.

[0057] The communication interface 108 uses transceiver modules such as, but not limited to, network interface cards and transceivers to enable communication between the computing device 100 and other devices or communication networks.

[0058] Figure 4 This is a flowchart of a polynomial calculation method provided in an embodiment of this application. See also: Figure 4 The calculation method includes:

[0059] Step 401: The control unit receives the calculation instructions sent by the application program. The calculation instructions include the calculation of the first polynomial. The difference between the exponents of two adjacent monomials in the first polynomial is Y. The first polynomial is represented as the sum of multiple sub-polynomials. Each sub-polynomial includes X monomials. Each sub-polynomial is the product of the base polynomial and the compensation exponent. The difference between the exponents of two adjacent polynomials in each sub-polynomial is equal.

[0060] The application can be any application involving polynomial computation, such as high-performance computing (HPC) applications or artificial intelligence applications. During operation, when the application needs to solve a transcendental function or a polynomial, it can send computation instructions to the processor's control unit. These instructions can be used to instruct the solution of the transcendental function or the polynomial. In one example, when the computation instruction instructs the solution of a transcendental function, the control unit can first perform polynomial approximation and parameter reduction on the transcendental function to be solved, obtaining the first polynomial to be computed. Then, by solving the first polynomial, the transcendental function can be solved.

[0061] In the first polynomial, the difference between the exponents of adjacent monomials is always Y, where Y is a positive integer. The exponent of a monomial is its order, that is, the exponent of the variable within the monomial. For example, the first polynomial is: y = c1x 1 +c2x 2 +c3x 3 +...+c 15 x 15 +c 16 x 16The difference between the exponents of adjacent monomials is 1. For example, the first polynomial is: y = c1x 2 +c2x 4 +c3x 6 +...+c 15 x 30 +c 16 x 32 The difference between the exponents of adjacent monomials is 2. In one example, if the difference between the exponents of adjacent monomials in the polynomial to be calculated indicated by the calculation instruction is not fixed, the polynomial to be calculated can be supplemented with terms so that the difference between the exponents of adjacent monomials in the polynomial after the supplementation (the first polynomial) is fixed, wherein the coefficient of the supplemented monomial can be set to 0.

[0062] The first polynomial can be represented as the sum of multiple sub-polynomials. In this embodiment, a matrix operation unit can be used to calculate the calculation result of each sub-polynomial corresponding to different input data, and then the calculation results of multiple sub-polynomials corresponding to different input data are summed to obtain the calculation result of the first polynomial corresponding to different input data. The number of sub-polynomials included in the first polynomial is equal to the number of coefficients included in the first polynomial that the vector register in the processor can store, which is the ratio of the bit width of the vector register to the bit width of the coefficients. The number of monomials included in each sub-polynomial is X, which is equal to the ratio of the number of monomials included in the first polynomial to the number of sub-polynomials.

[0063] In a polynomial represented by the first polynomial, the order difference between adjacent terms in each subpolynomial is the same. For example, for the first polynomial y = c1x 1 +c2x 2 +c3x 3 +...+c 15 x 15 +c 16 x 16 It can include eight sub-polynomials, namely y1 = c1x 1 +c2x 2 y2=c3x 3 +c4x 4 y3=c5x 5 +c6x 6 y4=c7x 7 +c8x 8 y5=c9x 9 +c 10 x 10 y6=c 11 x 11 +c 12 x 12 y7=c 13 x13 +c 14 x 14 y8=c 15 x 15 +c 16 x 16 Where y = y 1+ y2+y3+y4+y5+y6+y7+y8. It can be seen that the order difference between adjacent terms in each subpolynomial is 1.

[0064] Or, for example, for the first polynomial y = c1x 1 +c2x 2 +c3x 3 +...+c 15 x 15 +c 16 x 16 It can include eight sub-polynomials, namely y a =c1x 1 +c9x 9 y b =c2x 2 +c 10 x 10 y c =c3x 3 +c 11 x 11 y d =c4x 4 +c 12 x 12 y e =c5x 5 +c 13 x 13 y f =c6x 6 +c 14 x 14 y g =c7x 7 +c 15 x 15 y h =c8x 8 +c 16 x 16 Where y = y a+ y b +y c +y d +y e +y f +y g +y h It can be seen that the order difference between adjacent terms in each subpolynomial is 8.

[0065] Or, for example, for the first polynomial y = c1x1 +c2x 2 +c3x 3 +...+c 15 x 15 +c 16 x 16 It can include four sub-polynomials, namely y i =c1x 1 +c2x 2 +c3x 3 +c4x 4 y j =c5x 5 +c6x 6 +c7x 7 +c8x 8 y k =c9x 9 +c 10 x 10 +c 11 x 11 +c 12 x 12 y l =c 13 x 13 +c 14 x 14 +c 13 x 15 +c 14 x 16 Where y = y i +y j +y k +y l y i ~y l Let be the sub-polynomials included in the first polynomial. It can be seen that the order difference between adjacent terms in each sub-polynomial is 1.

[0066] In this embodiment, the calculation of each sub-polynomial includes the calculation of the base polynomial, the calculation of the compensation exponent, and the product of the base polynomial and the compensation exponent. Specifically, the base polynomials corresponding to the multiple sub-polynomials are obtained by reducing the order of each monomial in the sub-polynomial by the same amount; different base polynomials contain monomials with the same order but different coefficients. The sub-polynomial is equal to the product of the base polynomial and the compensation exponent, where the compensation exponent is the specified power of the variable in the polynomial, and this specified power is the same as the order by which the base polynomial reduces the order of each monomial in the sub-polynomial.

[0067] As shown in y1~y8 above, y1=c1x 1 +c2x 2 (x 0 ), y2=c3x 1+c4x 2 (x 2 ), y3=c5x 1 +c6x 2 (x 4 ), y4=c7x 1 +c8x 2 (x 6 ), y5=c9x 1 +c 10 x 2 (x 8 ), y6=c 11 x 1 +c 12 x 2 (x 10 ), y7=c 13 x 1 +c 14 x 2 (x 12 ), y8=c 13 x 1 +c 14 x 2 (x 14 Among them, for the subpolynomial y1, "c1x 1 +c2x 2 "for the benchmark polynomial, x 0 To compensate for the exponent; for the subpolynomial y², "c³x" 1 +c4x 2 "for the benchmark polynomial, x 2 To compensate for the exponent; for the subpolynomial y3, "c5x 1 +c6x 2 "for the benchmark polynomial, x 4 To compensate for the exponent; for the subpolynomial y4, "c7x 1 +c8x 2 "for the benchmark polynomial, x 6 To compensate for the exponent; for the subpolynomial y5, "c9x 1 +c 10 x 2 "for the benchmark polynomial, x 8 To compensate for the exponent; for the subpolynomial y6, "c 11 x 1 +c 12 x 2 "for the benchmark polynomial, x 10 To compensate for the exponent; for the subpolynomial y7, "c 13 x 1 +c 14 x 2 "for the benchmark polynomial, x 12To compensate for the exponent; for the subpolynomial y8, "c 15 x 1 +c 16 x 2 "for the benchmark polynomial, x 14 To compensate for the exponent.

[0068] As mentioned above, y a ~y h middle, y a =c1x 1 +c9x 9 (x 0 ), y b =c2x 1 +c 10 x 9 (x 1 ), y c =c3x 1 +c 11 x 9 (x 2 ), y d =c4x 1 +c 12 x 9 (x 3 ), y e =c5x 1 +c 13 x 9 (x 4 ), y f =c6x 1 +c 14 x 9 (x 5 ), y g =c7x 1 +c 15 x 9 (x 6 ), y h =c8x 1 +c 16 x 9 (x 7 ), where, for the subpolynomial y a "c1x 1 +c9x 9 "for the benchmark polynomial, x 0 To compensate for the exponent; for the subpolynomial y b "c2x" 1 +c 10 x 9 "for the benchmark polynomial, x 1 To compensate for the exponent; for the subpolynomial y c "c3x" 1 +c 11x 9 "for the benchmark polynomial, x 2 To compensate for the exponent; for the subpolynomial y d "c4x" 1 +c 12 x 9 "for the benchmark polynomial, x 3 To compensate for the exponent; for the subpolynomial y e "c5x 1 +c 13 x 9 "for the benchmark polynomial, x 4 To compensate for the exponent; for the subpolynomial y f "c6x 1 +c 14 x 9 "for the benchmark polynomial, x 5 To compensate for the exponent; for the subpolynomial y g =c7x 1 +c 15 x 9 "for the benchmark polynomial, x 6 To compensate for the exponent; for the subpolynomial y h "c8x 1 +c 16 x 9 "for the benchmark polynomial, x 7 To compensate for the exponent.

[0069] In this embodiment of the application, the calculation of the reference polynomial corresponding to different input data can be realized by the matrix operation unit, as shown in steps 402-404 below, where the input data refers to the value of the first polynomial variable.

[0070] Step 402: The control unit determines the X exponents in the reference polynomial as reference exponents, and stores the X first vectors corresponding to the exponents of the N input data corresponding to the X reference exponents into the vector register.

[0071] The calculation of the benchmark polynomial can include the product of the coefficients of each monomial in the benchmark polynomial and the powers of the corresponding benchmark exponents of the variables. The X benchmark exponents in the benchmark polynomial are the orders of the X monomials in the benchmark polynomial. For example, in y1 to y8 above, X is 2, and the corresponding benchmark exponents are "1" and "2" respectively.

[0072] After determining X baseline exponents, the power values ​​of the N input data corresponding to these X baseline exponents can be calculated, resulting in X first vectors. Each first vector is then stored in a vector register. The elements of each first vector are the power values ​​of one of the baseline exponents corresponding to the N input data. For example, with baseline exponents of "1" and "2" and input data of x0, x1, x2, x3, x4, x5, x6, x7, the two first vectors would be S1 = [x0...]. 1 x1 1 x2 1 x3 1 x4 1 x5 1 x6 1 x7 1 S2 = [x0] 2 x1 2 x2 2 x3 2 x4 2 x5 2 x6 2 x7 2 ].

[0073] Step 403: The control unit constructs a vector from the coefficients of monomials with the same exponent in each base polynomial, resulting in X second vectors.

[0074] The control unit takes the coefficients of the monomials with the same exponent in each base polynomial and forms a vector to obtain X second vectors, and stores the X second vectors in the vector register.

[0075] For the above y1~y8, the corresponding x 1 The second vector S3 = [c1, c3, c5, c7, c9, c 11 c 13 c 15 ], corresponding to x 2 The second vector S4 = [c2, c4, c6, c8, c 10 c 12 c 14 c 16 ]. For the above y a ~y h , corresponding to x 1 The second vector S5 = [c1, c2, c3, c4, c5, c6, c7, c8] corresponds to x. 9 The second vector S6 = [c9, c 10 c 11 c 12 c 13 c 14 c15 c 16 ].

[0076] Step 404: The control unit performs the outer product operation of X first vectors and X second vectors through the matrix operation unit and sums them to obtain the result matrix. In the result matrix, each row or column corresponding to the first vector represents the calculation result of the base polynomial in each sub-polynomial corresponding to N input data.

[0077] In implementation, the matrix operation unit can perform an outer product operation on each first vector and its corresponding second vector to obtain an intermediate result matrix. It can then accumulate the X intermediate result matrices to obtain the final matrix. Specifically, performing an outer product operation on the first and second vectors once yields the calculation result for one monomial in a benchmark polynomial corresponding to N input data. Accumulating the intermediate result matrices from the outer product operations on each pair of first and second vectors yields the calculation result for each benchmark polynomial corresponding to N input data.

[0078] Figure 5 This is a schematic diagram of a polynomial calculation method provided in an embodiment of this application. Figure 5 The first polynomial is y = c1x 1 +c2x 2 +c3x 3 +...+c 15 x 15 +c 16 x 16 Taking the example of the first polynomial having subpolynomials y1 to y8 and N input data x0 to x7, the method of polynomial calculation is explained. Figure 5 As shown, with the first vector as a row vector and the second vector as a column vector, an outer product operation is performed on the first vector S1 and the second vector S3, and the resulting intermediate matrix is ​​stored in a matrix register. This intermediate matrix includes the calculation result of the first monomial in each base polynomial. For example, "c1x0..." 1 “c1x1” 1 "...c 15 x6 1 “c” 15 x7 1 Then, an outer product operation can be performed on the first vector S2 and the second vector S4, and the resulting intermediate result matrix can be accumulated in the intermediate result matrix already stored in the matrix register. The resulting intermediate result matrix includes the calculation result of the second monomial in each base polynomial, such as "c2x0". 2 “c2x1” 2 "...c 16 x6 2 “c”16 x7 2 "etc." The final matrix obtained by summing the intermediate result matrices includes the calculation results of N input data corresponding to each baseline polynomial. For example, the sub-polynomial y 1~ The variable x in y8 takes x respectively 0~ The calculation result of x7.

[0079] Step 405: The control unit obtains the calculation result of the first polynomial of N input data by multiplying the calculation result of the base polynomial of each sub-polynomial by the compensation exponent.

[0080] After obtaining the calculation results of the base polynomial for each sub-polynomial, for each input data, the calculation result of the corresponding base polynomial is multiplied by the compensation exponent corresponding to the input data to obtain the calculation result of each sub-polynomial in the first polynomial. Then, the calculation results of each sub-polynomial corresponding to each input data are accumulated to obtain the calculation result of the first polynomial for each input data. The calculation result of the first polynomial can then be returned to the corresponding application.

[0081] See also Figure 5 In the final matrix obtained by summing the intermediate result matrices, each row vector contains elements representing the base polynomials of multiple sub-polynomials of the first polynomial, corresponding to the calculation results of one input data. For example, the base polynomials of the multiple sub-polynomials of the first polynomial in the first row vector correspond to the calculation results of input data x0. In the final matrix obtained by summing the intermediate result matrices, each column vector contains elements representing the base polynomials of one sub-polynomial of the first polynomial, corresponding to the calculation results of N input data. For example, the base polynomial "c3x" of the second sub-polynomial of the first polynomial in the second column vector... 1 +c4x 2 "The calculation results corresponding to the input data x0 to x7."

[0082] In other words, after the outer product operation and matrix summation in step 404, we can obtain the calculation results of the base polynomial corresponding to each input data in each sub-polynomial of the first polynomial. Then, we can multiply the calculation results of the base polynomial corresponding to each input data with the compensation exponent corresponding to each input data to obtain the calculation results of each sub-polynomial corresponding to each input data in the first polynomial.

[0083] And because Figure 5In the result matrix, each column represents the calculation result of the same base polynomial corresponding to different input data. Therefore, the compensation exponents that need to be multiplied by each column element correspond to the same exponent. Thus, in this embodiment, the calculation result of the base polynomial in each column of the result matrix can be compensated column-by-column to obtain the calculation results of the sub-polynomials in the first polynomial corresponding to the input data. In one example, for the second column element of the result matrix, that is, the sub-polynomial y² = c³x... 1 +c4x 2 (x 2 The benchmark polynomial "c3x" 1 +c4x 2 The calculation results of the corresponding N input data can be obtained by multiplying the elements of the second column with the input vector composed of the square powers of the N input data respectively, and then obtaining the subpolynomial y² = c³x. 1 +c4x 2 The calculation result corresponding to the N input data. That is, [c3x0 1 +c4x0 2 c3x1 1 +c4x1 2 c3x2 1 +c4x2 2 c3x3 1 +c4x3 2 c3x4 1 +c4x4 2 c3x5 1 +c4x5 2 c3x6 1 +c4x6 2 c3x7 1 +c4x7 2 ], and [x0] 2 x1 2 x2 2 x3 2 x4 2 x5 2 x6 2 x7 2 Multiplying by each position, we get [c3x0] 3 +c4x0 4 c3x1 3 +c4x1 4 c3x2 3 +c4x2 4 c3x3 3 +c4x3 4 c3x4 3 +c4x4 4 c3x5 3 +c4x54 c3x6 3 +c4x6 4 c3x7 3 +c4x7 4 This leads to the calculation results of the second sub-polynomial in the first polynomial corresponding to x0 to x7. The calculation results of the other sub-polynomials in the first polynomial corresponding to x0 to x7 are similar and will not be repeated in the embodiments of this application.

[0084] After obtaining the calculation results of each sub-polynomial in the first polynomial corresponding to each input data, the calculation results of each sub-polynomial corresponding to each input data can be accumulated to obtain the calculation result of the first polynomial corresponding to each input data.

[0085] Figure 6 This is a schematic diagram of another polynomial calculation method provided in the embodiments of this application. Figure 6 The first polynomial is y = c1x 1 +c2x 2 +c3x 3 +...+c 15 x 15 +c 16 x 16 The subpolynomial corresponding to the first polynomial is y a ~y h Taking N input data points from x0 to x7 as an example, the method for polynomial calculation will be explained. Figure 6 As shown, with the first vector as a row vector and the second vector as a column vector, the outer product operation is performed on the first vector S1 and the second vector S5, and the resulting intermediate result matrix is ​​stored in the matrix register. The outer product operation is performed on the first vector S2 and the second vector S6, and the resulting intermediate result matrix is ​​added to the intermediate result matrix already stored in the matrix register.

[0086] See also Figure 6 In the final matrix obtained by summing the intermediate result matrices, each row vector contains elements representing the base polynomials of the first polynomial's multiple sub-polynomials, corresponding to the calculation result of one input data. For example, the base polynomial of the first row vector, representing the multiple sub-polynomials of the first polynomial, corresponds to the calculation result of input data x0. In the final matrix obtained by summing the intermediate result matrices, each column vector contains elements representing the base polynomials of the first polynomial's one sub-polynomial, corresponding to the calculation results of N input data. For example, the base polynomial of the second column vector, representing the second sub-polynomial of the first polynomial, "c2x", corresponds to the calculation result of N input data. 1 +c 10 x 9 "The calculation results corresponding to the input data x0 to x7."

[0087] exist Figure 6 In the result matrix, each column represents the calculation result of the same base polynomial for different input data. Therefore, the compensation exponents that need to be multiplied by each column's elements correspond to the same exponent. Thus, the calculation results of the base polynomial in each column of the result matrix can be compensated column-by-column to obtain the calculation results of the sub-polynomials in the first polynomial corresponding to the input data. In one example, for the elements in the second column of the result matrix, that is, the sub-polynomial y... b =c2x 1 +c 10 x 9 (x 1 The benchmark polynomial "c2x" 1 +c 10 x 9 The calculation result of the corresponding N input data can be obtained by multiplying the elements of the second column by the input vector composed of the first power of the N input data, and then obtaining the calculation result of the N input data corresponding to the subpolynomial. That is, [c2x0 1 +c 10 x0 9 c2x1 1 +c 10 x1 9 c2x2 1 +c 10 x2 9 c2x3 1 +c 10 x3 9 c2x4 1 +c 10 x4 9 c2x5 1 +c 10 x5 9 c2x6 1 +c 10 x6 9 c2x7 1 +c 10 x7 9 ], and [x0] 1 x1 1 x2 1 x3 1 x4 1 x5 1 x6 1 x7 1 Multiplying by each position, we get [c2x0] 1 +c 10 x0 9 c2x1 2 +c 10 x1 10 c2x23 +c 10 x2 11 c2x3 4 +c 10 x3 12 c2x4 5 +c 10 x4 13 c2x5 6 +c 10 x5 14 c2x6 7 +c 10 x6 15 c2x7 8 +c 10 x7 16 This means obtaining the calculation results of the second sub-polynomial in the first polynomial corresponding to x0 to x7. The calculation results of the other sub-polynomials in the first polynomial corresponding to x0 to x7 are similar and will not be repeated in this embodiment. After obtaining the calculation results of each sub-polynomial in the first polynomial corresponding to each input data, the calculation results of each sub-polynomial corresponding to each input data can be accumulated to obtain the calculation result of the first polynomial corresponding to each input data.

[0088] It should be noted that, Figure 5 and Figure 6 This describes the polynomial calculation process using the first vector as a column vector and the second vector as a row vector. In practice, the first vector can also be a row vector and the second vector can also be a column vector. In this case, each row element represents the calculation result of the same base polynomial for different input data. Furthermore, each row element can be multiplied by its corresponding compensation exponent to obtain the calculation result of the first polynomial for each input data.

[0089] In this embodiment, the calculation of a polynomial can be broken down into the calculation of a base polynomial and the product of the base polynomial and the compensating exponent. The base polynomial can be obtained by a matrix operation unit through the outer product operation of a first vector and a second vector, and then summing the resulting matrix. In other words, in this embodiment, part of the polynomial calculation process can be converted into matrix operations and implemented through a matrix operation unit, thereby improving the computational efficiency of the polynomial.

[0090] In one feasible approach, for the X monomials included in the sub-polynomial in steps 401-405 above, the value of X is also the number of the first and second vectors. This value of X can be determined by the number of monomials in the polynomial to be solved (the second polynomial), the bit width of the coefficients, and the bit width of the vector register. For example, based on the bit width of the coefficients, the bit width of the vector register can determine the number of coefficients that each vector register can store, for example, 8. Then, the value of X can be determined based on the ratio of the number of monomials in the polynomial to be solved to the number of coefficients that the vector register can store. For example, if the number of monomials in the polynomial to be solved is 16, and the number of coefficients that the vector register can store is 8, then the value of X is 2 (16 / 8).

[0091] Furthermore, if a remainder exists when the number of monomials in the second polynomial to be solved, as indicated by the calculation instruction, is divided by the number of coefficients that the vector register can store, the value of X can be determined based on the magnitude of the remainder. For example, a remainder threshold can be set. If the remainder is greater than the threshold, the value of X can be determined by adding one to the quotient of the number of monomials in the polynomial to be solved by the number of coefficients that the vector register can store. If the remainder is less than or equal to the threshold, the value of X can be determined by adding one to the quotient of the number of monomials in the polynomial to be solved by the number of coefficients that the vector register can store. This remainder threshold can be preset by a technician. For example, it could be half the number of coefficients that the vector register can store.

[0092] If the number of monomials in the polynomial to be solved is divided by the number of coefficients that the vector register can store, and the remainder is less than or equal to a remainder threshold, the polynomial to be solved can be split into two polynomials for further solving. For example, if the remainder is M, the first M terms or the last M terms of the polynomial to be solved can be used as one polynomial to be solved, and the remaining terms can be used as another polynomial to be solved (i.e., the first polynomial).

[0093] Since the polynomial composed of the first M terms or the last M terms only includes M terms, the corresponding computational workload is relatively small. Therefore, vector computation can be used to obtain the calculation result of the M terms. For the remaining first polynomial, the corresponding settlement result can be calculated using steps 401 to 405 above. Then, the calculation result of the M terms is summed with the settlement result of the first polynomial to obtain the calculation result of the second polynomial.

[0094] Figure 7 This is a schematic diagram of a polynomial calculation method provided in an embodiment of this application. Figure 7 In the equation, the second polynomial to be calculated is y = c1x. 1 +c2x 2 +c3x3 +...+c 17 x 17 +c 18 x 18 If the vector register can store 8 coefficients, the second polynomial can be decomposed into y0 = c1x. 1 +c2x 2 And y1 = c3x 3 +c4x 4 ...+c 17 x 17 +c 18 x 18 For y1 = c3x 3 +c4x 4 ...+c 17 x 17 +c 18 x 18 The corresponding first vector S7 = [x0] can be determined respectively. 1 x1 1 x2 1 x3 1 x4 1 x5 1 x6 1 x7 1 ] and S8 = [x0 2 x1 2 x2 2 x3 2 x4 2 x5 2 x6 2 x7 2 The second vector S9 = [c3, c5, c7, c9, c] 11 c 13 c 15 c 17 ] and S 10 =[c4, c6, c8, c 10 c 12 c 14 c 16 c 18 Then, by performing the outer product operation of S7 and S9, and S8 and S... 10 The outer product operation is performed, and the intermediate result matrices obtained from the outer product operation are accumulated. Then, each column of the accumulated intermediate result matrix is ​​multiplied by the corresponding compensation exponent to obtain the calculation result of y1. For y0, c1 is multiplied by S7, c2 is multiplied by S8, and the multiplication results are added to obtain the calculation result of y0. Then, the calculation results of y0 and y1 are added to obtain the calculation result of the second polynomial y.

[0095] In one feasible approach, if the exponent of the first monomial of the third polynomial indicated by the calculation instruction is greater than 1, the exponent of each monomial in the third polynomial can be reduced by L to obtain the first polynomial. Here, L is equal to the difference between the exponent of the first term of the third polynomial and 1. Since the exponent of each term in the first polynomial is reduced by L compared to the third polynomial, after obtaining the calculation result of each monomial in the first polynomial, the calculation result of each monomial can be multiplied by the Lth power of the input data to compensate for the exponent of each monomial, thus obtaining the calculation result of the third polynomial. In this way, the order of each term in the first polynomial is lower, reducing the steps of exponentiation of the input data and the number of times the result matrix of the first polynomial is compensated, thereby improving the computational efficiency of the polynomial.

[0096] In one feasible approach, for cases where the exponent differences of adjacent coefficients in the second vector are all equal, and the monomials corresponding to coefficients at the same position in multiple second vectors are adjacent in the first polynomial, i.e., the second vectors are S3 and S4 respectively. This application embodiment further provides an accelerated compensation method for the processing in step 405 above, where the calculation result of the base polynomial of each sub-polynomial is multiplied by the compensation exponent to obtain the calculation result of the first polynomial for N input data, including:

[0097] Step 4051: Group the calculation results of the base polynomial of each subpolynomial in pairs to obtain at least one vector group to be compensated for exponent.

[0098] The computation results of the multiple input data corresponding to the base polynomial of each sub-polynomial are row vectors or column vectors in the result matrix. Specifically, the vectors representing the computation results of the base polynomial can be grouped pairwise according to their row or column order in the result matrix to obtain the vector groups to be subjected to exponent compensation. For example, in Figure 8 In the result matrix, the first and second columns are grouped together, the third and fourth columns are grouped together, the fifth and sixth columns are grouped together, and so on.

[0099] Step 4052: Multiply the third vector with the highest exponent in each vector group by the compensation vector to obtain the fourth vector corresponding to each vector group.

[0100] In this vector group, the exponent corresponding to each vector is the exponent used to calculate the X monomials corresponding to the X coefficients of each vector. For example... Figure 8In the result matrix, the vector corresponding to the first column is calculated from the coefficients c1 and c2, and the exponent corresponding to this vector is the order of the monomials containing c1 and c2. Similarly, the exponent corresponding to the vector in the second column is the order of the monomials containing c3 and c4, and the exponent corresponding to the vector in the third column is the order of the monomials containing c5 and c6, and so on.

[0101] The elements of the compensation vector are the powers of the first exponents corresponding to the N input data, where the first exponent is equal to the difference between the exponents of any two vectors in the vector group. For example, in the first vector group, if the exponents of the vectors in the first column are "1" and "2", and the exponents of the vectors in the second column are "3" and "4", then the difference between the exponents of any two vectors in this vector group is 2. Since adjacent vectors are grouped together, the difference between the exponents of any two vectors in each group is the same after each grouping. In other words, after each grouping of vectors, the compensation vector for each vector group is the same.

[0102] After obtaining the compensation vector, the third vector with the highest exponent in each vector group can be multiplied digit-wise with the compensation vector to obtain the fourth vector for each vector group. For example... Figure 8 As shown, after the first grouping of the vectors, the corresponding compensation vector is X. 2 =[x0 2 x1 2 x2 2 x3 2 x4 2 x5 2 x6 2 x7 2 Then, the vectors with the highest exponents in each vector group (Y2, Y4, Y6, Y8) can be compared with X respectively. 2 Multiplying the vectors digit by digit yields the fourth vector for each vector group.

[0103] Step 4053: Add the fifth vector with the lowest exponent in each vector group to the corresponding fourth vector, and obtain the result vector.

[0104] After compensating the third vector of each vector group, the fifth vector with the lowest corresponding exponent and the compensated fourth vector in each vector group have the same exponent value for the variable that needs compensation. For example, in Figure 8 In the first vector group, after one compensation, the fifth vector Y1 and the fourth vector Y2X... 2 No compensation is needed. In the second vector group, the fifth vector Y3 and the fourth vector Y4X 2 Each input data point needs to be compensated for to the fourth power. In the third vector group, the fifth vector Y5 and the fourth vector Y6X... 2Each input data point needs to be compensated for to the power of eight. In the fourth vector group, the fifth vector Y7 and the fourth vector Y8X... 2 Each input data point needs to be compensated to the power of 12. This allows us to add the fifth vector to the corresponding fourth vector, digit by digit, to obtain a result vector. This result vector can then be further compensated, or the result of the first polynomial can be obtained.

[0105] Step 4054: When there are multiple result vectors, group the multiple result vectors into pairs to obtain at least one vector group to be exponentially compensated, and then proceed to the processing of step 4052.

[0106] In step 4053, after adding the fifth vector to the corresponding fourth vector in each vector group, if multiple result vectors are obtained, these result vectors can be grouped pairwise to obtain at least one vector group to be subjected to exponential compensation. Then, steps 4052 and 4053 are re-executed. For example, in Figure 8 After one compensation step, four result vectors are obtained. These four result vectors can then be grouped pairwise to obtain vector groups for exponential compensation. Steps 4052 and 4053 are then re-executed, meaning that the third vector in each vector group corresponding to the highest exponent is multiplied digit-wise with the compensation vector to obtain the fourth vector for each vector group. In the second execution of step 4052, the corresponding compensation vector is X. 4 =[x0 4 x1 4 x2 4 x3 4 x4 4 x5 4 x6 4 x7 4 After the second execution of step 4053, two result vectors are obtained. These two result vectors can then be used as a vector group to undergo exponential compensation, and steps 4052 and 4053 are re-executed. Specifically, in the third execution of step 4053, the corresponding compensation vector is X. 8 =[x0 8 x1 8 x2 8 x3 8 x4 8 x5 8 x6 8 x7 8 After executing step 4053 for the third time, it can be determined that the number of result vectors is one.

[0107] Step 4055: When the number of result vectors is one, determine the result vector as the calculation result of the first polynomial.

[0108] In this embodiment, the multiplication operation between the base polynomial and the compensation exponent is achieved by grouping vectors and performing multiple positional multiplications of the compensation vector with the vectors in the vector group. Since the compensation vectors corresponding to each group of vectors are the same each time, the number of times the compensation vector is calculated can be reduced, thereby further accelerating the calculation of the polynomial. For example, in steps 4051-4055 above, only the compensation vector X needs to be calculated. 2 X 4 X 8 That's sufficient. However, if compensation is applied individually to each column or row vector, then the corresponding compensation exponent needs to be calculated for each column or row vector, such as calculating X. 1 X 2 X 3 X 4 ... X 13 X 14 .

[0109] This application also provides a method for calculating polynomials, such as... Figure 9 As shown in the embodiments of this application, multiple first polynomials can be computed in parallel. These multiple first polynomials have the same input data, the same number of terms, and the same order difference between adjacent terms.

[0110] In constructing the second vectors, the coefficients of monomials with the same exponent in the base polynomials corresponding to the multiple first polynomials can be grouped into a vector, resulting in X second vectors. The coefficients of any one of the multiple first polynomials occupy the same position in the X second vectors. In one example, these multiple first polynomials are obtained through polynomial approximation and parameter reduction of multiple transcendental functions.

[0111] like Figure 9 As shown, for the first polynomial z1 = c1x 1 +c2x 2 +c3x 3 +...+c8x 8 and z2 = d1x 1 +d2x 2 +d3x 3 +...+d8x 8 We can take S11 = [c1, c3, c5, c7, d1, d3, d5, d7] and S12 = [c2, c4, c6, c8, d2, d4, d6, d8] as the second vector, and the first vector S1 = [x0] as the second vector. 1 x1 1 x2 1 x3 1 x41 x5 1 x6 1 x7 1 ], S2=[x0 2 x1 2 x2 2 x3 2 x4 2 x5 2 x6 2 x7 2 Perform an outer product operation, accumulate the intermediate result matrices obtained from the outer product operation to obtain the first polynomial z1 and the first polynomial z2, respectively, whose corresponding benchmark polynomials correspond to the calculation results of multiple input data. Then, through... Figure 8 The method shown compensates for the exponents of the input data corresponding to each column element of the result matrix, thereby obtaining the calculation results of the first polynomial z1 and the first polynomial z2. The specific calculation process is the same as described above. Figures 3 to 8 The corresponding implementation methods are identical, and will not be repeated here.

[0112] As can be seen from the embodiments of this application, multiple polynomials can be calculated in parallel, and some calculations can be converted into matrix calculations during the calculation process, which can greatly improve the calculation efficiency of polynomials.

[0113] Based on the same inventive concept, embodiments of this application provide a polynomial calculation device, see [link to relevant documentation]. Figure 10 The device includes:

[0114] The instruction receiving module 1010 is used to receive calculation instructions sent by the application program. The calculation instructions include the calculation of a first polynomial, where the difference in exponents between two adjacent monomials in the first polynomial is Y. The first polynomial is represented as the sum of multiple sub-polynomials, each sub-polynomial including X monomials. Each sub-polynomial is the product of a base polynomial and a compensation exponent, and the difference in exponents between two adjacent polynomials in each sub-polynomial is equal. Specifically, it can be used to implement the instruction receiving function of step 401 and other implicit steps mentioned above.

[0115] The vector generation module 1020 is used to determine X exponents in the benchmark polynomial as benchmark exponents, and store X first vectors corresponding to the exponents of the N input data corresponding to the X benchmark exponents into the processor's vector register. It also constructs a vector from the coefficients of monomials with the same exponent in each benchmark polynomial to obtain X second vectors. Specifically, it can be used to implement the vector generation functions of steps 402 and 403 above, as well as other implicit steps.

[0116] The matrix operation module 1030 is used to perform the outer product operation of the X first vectors and the X second vectors through the matrix operation unit of the processor and sum them to obtain a result matrix. In the result matrix, each row or column corresponding to the first vector represents the calculation result of the base polynomial in each sub-polynomial corresponding to the N input data. Specifically, it can be used to implement the matrix operation function of step 404 and other implicit steps mentioned above.

[0117] The result compensation module 1040 is used to obtain the calculation result of the first polynomial of the N input data by multiplying the calculation result of the base polynomial of each sub-polynomial by the compensation exponent. Specifically, it can be used to implement the result compensation function of step 405 and other implicit steps.

[0118] Optionally, the exponent differences of adjacent coefficients in the second vector are all equal, and the monomials corresponding to coefficients at the same position in multiple second vectors are adjacent in the first polynomial.

[0119] Optionally, the X exponents in the benchmark polynomial are the exponents corresponding to the first X monomials in the first polynomial.

[0120] Optionally, the result compensation module 1040 is configured to: group the calculation results of the base polynomial for each sub-polynomial pairwise to obtain at least one vector group to be compensated for exponent; multiply the third vector with the higher exponent in each vector group by the compensation vector to obtain a fourth vector for each vector group, wherein the exponent of each vector in the vector group is the exponent of the X monomials corresponding to the X coefficients of each vector, and the elements of the compensation vector are the powers of the first exponents corresponding to the N input data, wherein the first exponent is equal to the difference between the exponents of the two vectors in the vector group; add the fifth vector with the lower exponent in each vector group by the corresponding fourth vector to obtain a result vector; when there are multiple result vectors, group the multiple result vectors pairwise to obtain at least one vector group to be compensated for exponent, and proceed to multiply the third vector with the higher exponent in each vector group by the compensation vector; when there is only one result vector, determine the result vector as the calculation result of the first polynomial.

[0121] Optionally, the device further includes a disassembly and merging module, configured to: in response to the calculation instruction, obtain the second polynomial indicated by the calculation instruction; if the remainder obtained by dividing the number of monomials included in the second polynomial by a first value is less than a remainder threshold, the first polynomial is the polynomial after deleting M terms from the second polynomial, wherein the first value is the ratio of the bit width corresponding to the vector register to the bit width occupied by an input data, and the value of M is equal to the value of the remainder; obtain the calculation result corresponding to the deleted M terms in the second polynomial; and sum the calculation result corresponding to the deleted M terms with the calculation result of the first polynomial to obtain the calculation result of the second polynomial.

[0122] Optionally, the device further includes a disassembly and merging module, configured to: in response to the calculation instruction, obtain the third polynomial indicated by the calculation instruction; if the exponent of the first term of the third polynomial is greater than 1, the first polynomial is a polynomial whose exponent of each monomial in the third polynomial is reduced by L, wherein the value of L is equal to the difference between the exponent of the first term of the third polynomial and 1; and according to L, perform exponent compensation on the result corresponding to each monomial in the calculation result of the first polynomial to obtain the calculation result of the third polynomial.

[0123] Optionally, the calculation instructions include the calculation of multiple first polynomials. The vector generation module 1020 is used to: construct a vector from the coefficients of monomials with the same exponent in each reference polynomial corresponding to the multiple first polynomials to obtain X second vectors, wherein the coefficients corresponding to any one of the multiple first polynomials are in the same position in the X second vectors.

[0124] Optionally, the first polynomial is obtained by polynomial approximation and parameter reduction of the transcendental function.

[0125] The polynomial calculation device provided in this application embodiment can be used to execute the polynomial calculation method provided in this application embodiment. For the specific execution process, please refer to the description of the polynomial calculation method in the above embodiments, which will not be repeated here. Using the polynomial calculation device provided in this application embodiment, the processor can convert part of the polynomial calculation into matrix operations and perform the corresponding matrix operations using the matrix operation unit, thereby accelerating polynomial calculation and improving the efficiency of polynomial calculation.

[0126] This disclosure also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions capable of running on a computing device or stored on any usable medium. When the computer program product is run on at least one computer device, it causes the processor of at least one computer device to perform a polynomial computation method.

[0127] This disclosure also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computer device can store, or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital video disk (DVD)), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that can instruct a processor of a computer device to perform a polynomial computation method.

[0128] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0129] In this application, the terms "first," "second," etc., are used to distinguish identical or similar items with substantially the same function. It should be understood that there is no logical or temporal dependency between "first" and "second," nor does it limit the quantity or order of execution. It should also be understood that although the following description uses the terms "first," "second," etc., to describe various elements, these elements should not be limited by the terms. These terms are merely used to distinguish one element from another. In this application, the term "at least one" means one or more, and the term "multiple" means two or more.

[0130] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method of calculating a polynomial, characterized by, The method is applied to a processor comprising a vector register and a matrix operation unit, and the method comprises: receiving a calculation instruction sent by an application program, the calculation instruction comprising a calculation of a first polynomial, adjacent two monomials in the first polynomial having an index difference of Y, the first polynomial being expressed as a sum of a plurality of sub-polynomials, each sub-polynomial comprising X monomials, each sub-polynomial being a product of a reference polynomial and a compensation exponent power, adjacent two monomials in each sub-polynomial having an equal index difference; determining X exponents in the reference polynomial as reference exponents, and storing X first vectors corresponding to exponent powers of N input data corresponding to the X reference exponents to the vector register; constructing a vector of coefficients of monomials of the same exponent in each reference polynomial to obtain X second vectors; performing outer product operation and summation of the X first vectors and the X second vectors by the matrix operation unit to obtain a result matrix, each row or each column in the result matrix representing a calculation result of the reference polynomial in each sub-polynomial corresponding to the N input data; multiplying the calculation result of the reference polynomial of each sub-polynomial by a result of the compensation exponent power to obtain a calculation result of the first polynomial of the N input data.

2. The method of claim 1, wherein, Adjacent coefficients in the second vector correspond to monomials having an equal index difference, and coefficients at the same position in a plurality of second vectors correspond to monomials adjacent in the first polynomial.

3. The method according to claim 1 or 2, characterized in that, The X exponents in the reference polynomial are exponents corresponding to the first X monomials in the first polynomial.

4. The method of claim 2, wherein, The multiplying the calculation result of the reference polynomial of each sub-polynomial by a result of the compensation exponent power to obtain a calculation result of the first polynomial of the N input data comprises: grouping the calculation results of the reference polynomial of each sub-polynomial two by two to obtain at least one vector group to be compensated for an exponent; multiplying a third vector corresponding to a high exponent in each vector group with a compensation vector in position to obtain a fourth vector corresponding to each vector group, the exponent corresponding to each vector in the vector group being an exponent of X monomials corresponding to X coefficients used to calculate the vector, and elements of the compensation vector being power values of a first exponent corresponding to the N input data, the first exponent being equal to a difference between exponents corresponding to two vectors in the vector group; adding a fifth vector corresponding to a low exponent in each group of vector groups with a corresponding fourth vector in position to obtain a result vector; when the number of result vectors is multiple, grouping the multiple result vectors two by two to obtain at least one vector group to be compensated for an exponent, and turning to the multiplying a third vector corresponding to a high exponent in each vector group with a compensation vector in position; when the number of result vectors is one, determining the result vector as the calculation result of the first polynomial.

5. The method according to any one of claims 1 to 4, characterized in that, The method further comprises: in response to the calculation instruction, obtaining a second polynomial indicated by the calculation instruction; In a case where a remainder obtained by dividing a number of included monomials of the second polynomial by a first value is less than a remainder threshold value, the first polynomial is a polynomial obtained by deleting M terms from the second polynomial, wherein the first value is a ratio of a bit width corresponding to the vector register to an occupied bit width of one input data, and a value of M is equal to a value of the remainder; obtaining a calculation result corresponding to the deleted M terms of the second polynomial; summing the calculation result corresponding to the deleted M terms and a calculation result of the first polynomial to obtain a calculation result of the second polynomial.

6. The method according to any one of claims 1 to 4, characterized in that, The method further comprises: in response to the calculation instruction, obtaining a third polynomial indicated by the calculation instruction; in a case where an index of a first term of the third polynomial is greater than 1, the first polynomial is a polynomial obtained by reducing an index of each monomial in the third polynomial by L, wherein a value of L is equal to a difference between the index of the first term of the third polynomial and 1; performing index compensation on a result corresponding to each monomial of the first polynomial according to the L to obtain a calculation result of the third polynomial.

7. The method according to any one of claims 1 to 6, characterized in that, The calculation instruction comprises calculation of a plurality of first polynomials. The coefficients of monomials of the same index in each reference polynomial are constituted into a vector to obtain X second vectors, comprising: the coefficients of monomials of the same index in each reference polynomial corresponding to the plurality of first polynomials are constituted into a vector to obtain X second vectors, wherein the positions of the coefficients corresponding to any first polynomial in the plurality of first polynomials in the X second vectors are the same.

8. The method according to any one of claims 1 to 7, characterized in that, The first polynomial is obtained by polynomial approximation and parameter reduction on a transcendental function.

9. An apparatus for computing a polynomial, the apparatus comprising: The apparatus comprises: an instruction receiving module configured to receive a calculation instruction sent by an application program, the calculation instruction comprising calculation of a first polynomial, an index difference between two adjacent monomials in the first polynomial being Y, the first polynomial being represented as a sum of a plurality of sub-polynomials, each sub-polynomial comprising X monomials, each sub-polynomial being a product of a reference polynomial and a compensation index power, and an index difference between two adjacent monomials in each sub-polynomial being equal; a vector generating module configured to determine X indexes in the reference polynomial as reference indexes, store X first vectors corresponding to index powers of N input data in a vector register of a processor, and constitute coefficients of monomials of the same index in each reference polynomial into a vector to obtain X second vectors; a matrix operation module configured to perform outer product operation and summation of the X first vectors and the X second vectors by a matrix operation unit of the processor to obtain a result matrix, each row or each column in the result matrix corresponding to each sub-polynomial in the N input data corresponding to the calculation result of the reference polynomial in the first polynomial; a result compensating module configured to multiply the calculation result of the reference polynomial of each sub-polynomial by a result of the compensation index power to obtain a calculation result of the first polynomial of the N input data.

10. The apparatus of claim 9, wherein, The difference between the exponents of monomials corresponding to adjacent coefficients in the second vector is equal, and the monomials corresponding to the coefficients at the same position in the plurality of second vectors are adjacent in the first polynomial.

11. The apparatus of claim 9 or 10, wherein, The X exponents in the reference polynomial are exponents of monomials corresponding to the first X monomials in the first polynomial.

12. The apparatus of claim 10, wherein, The result compensation module is configured to: group the calculation results of the reference polynomial corresponding to each sub-polynomial two by two to obtain at least one vector group to be subjected to exponent compensation; multiply the third vector corresponding to a high exponent in each vector group with a compensation vector at a corresponding position to obtain a fourth vector corresponding to each vector group, the exponent corresponding to each vector in the vector group is an exponent of X monomials corresponding to X coefficients of the vector, and elements of the compensation vector are powers of a first exponent corresponding to the N input data. add the fifth vector corresponding to a low exponent in each vector group to the corresponding fourth vector at a corresponding position to obtain a result vector. When the number of result vectors is multiple, group the multiple result vectors two by two to obtain at least one vector group to be subjected to exponent compensation, and go to the step of multiplying the third vector corresponding to a high exponent in each vector group with a compensation vector at a corresponding position. When the number of result vectors is one, determine the result vector as the calculation result of the first polynomial.

13. The apparatus of any one of claims 9 to 12, wherein, The apparatus further includes a disassembling and merging module configured to: in response to the calculation instruction, obtain a second polynomial indicated by the calculation instruction; when a remainder obtained by dividing the number of included monomials in the second polynomial by a first value is less than a remainder threshold value, the first polynomial is a polynomial obtained by deleting M terms in the second polynomial, wherein the first value is a ratio of a bit width corresponding to the vector register to a bit width occupied by one input data, and the value of M is equal to the value of the remainder; obtain a calculation result corresponding to the deleted M terms in the second polynomial; sum the calculation result corresponding to the deleted M terms and the calculation result of the first polynomial to obtain the calculation result of the second polynomial.

14. The apparatus of any one of claims 9 to 12, wherein, The apparatus further includes a disassembling and merging module configured to: in response to the calculation instruction, obtain a third polynomial indicated by the calculation instruction; when the first term of the third polynomial has an exponent greater than 1, the first polynomial is a polynomial obtained by reducing the exponent of each monomial in the third polynomial by L, and the value of L is equal to the difference between the exponent of the first term of the third polynomial and 1; perform exponent compensation on a result corresponding to each monomial in the calculation result of the first polynomial according to the L to obtain the calculation result of the third polynomial.

15. The apparatus of any one of claims 9 to 14, wherein, The calculation instruction includes calculation of a plurality of first polynomials, and the vector generation module is configured to: construct a vector by using coefficients of monomials with the same exponent in each reference polynomial corresponding to the plurality of first polynomials to obtain X second vectors, wherein the positions of coefficients corresponding to any first polynomial in the plurality of first polynomials in the X second vectors are the same.

16. The apparatus of any one of claims 9 to 15, wherein, The first polynomial is obtained by polynomial approximation and parameter reduction on the transcendental function.

17. A computer device, comprising: The computer device comprises a processor and a memory, the processor comprises a matrix operation unit and a vector register, and the memory stores instructions. The processor is configured to execute the instructions stored in the memory, so that the computer device executes the method in any one of claims 1 to 8.

18. A computer program product, characterised in that, The computer program product comprises instructions which, when executed by a processor of a computer device, cause the processor to execute the method in any one of claims 1 to 8.

19. A computer-readable storage medium, characterized in that, The computer readable storage medium comprises computer program instructions which, when executed by a processor of a computer device, cause the processor to execute the method in any one of claims 1 to 8.