Search

CN-121996202-A - Floating point exponent operation method, tensor processor, device, and storage medium

CN121996202ACN 121996202 ACN121996202 ACN 121996202ACN-121996202-A

Abstract

The invention provides a floating point index operation method, a tensor processor, equipment and a storage medium, which comprise the steps of converting a first operation formula into a second operation formula taking 2 as a base and taking the inverse of a target floating point number multiplied by ln2 as an index, obtaining an integer item of the index of the second operation formula, obtaining a first decimal item of the index of the second operation formula, splitting the first decimal item into a fixed point number item and a first floating point number item, obtaining a first index operation result corresponding to the fixed point number item from a preset table, calculating the second index operation result of the integer item, multiplying the first index operation result and the second index operation result to obtain an initial natural index operation result of the target floating point number, performing Taylor expansion calculation on the first floating point number item to obtain a third index operation result, and multiplying the initial natural index operation result of the target floating point number and the third index operation result. The embodiment of the invention can improve the efficiency of floating point exponent operation on the premise of ensuring the precision of floating point exponent operation.

Inventors

  • GUO YUBIN
  • TIAN CHAOWEN
  • SUN YANAN
  • LI SHENGLIN
  • JIANG JIANG
  • YUAN JIZHONG

Assignees

  • 北京算能科技有限公司

Dates

Publication Date
20260508
Application Date
20251231

Claims (10)

  1. 1. A floating point exponent operation method applied to a tensor processor, the tensor processor including a control unit and a plurality of calculation units, the method comprising: Controlling the calculation unit to convert a first arithmetic expression based on a real number e and an index of a target floating point number into a second arithmetic expression based on 2 and an inverse of the target floating point number multiplied by ln2 as an index, and obtaining integer items of the index of the second arithmetic expression; the calculation unit is controlled to obtain a first decimal term of the index of the second arithmetic formula, split the first decimal term into a fixed point number term and a first floating point number term, and obtain a first index operation result corresponding to the fixed point number term from a preset table; Controlling the calculation unit to calculate a second exponent operation result of the integer item and multiplying the first exponent operation result and the second exponent operation result to obtain an initial natural exponent operation result of the target floating point number; And controlling the computing unit to perform Taylor expansion computation on the first floating point number item to obtain a third index operation result, and multiplying the initial natural index operation result of the target floating point number by the third index operation result to obtain a target natural index operation result of the target floating point number.
  2. 2. The floating point exponent operating method of claim 1 wherein splitting the first fraction term into a fixed point number term and a first floating point number term includes: and converting the first decimal term into a decimal term in a fixed point number format, and splitting the decimal term in the fixed point number format into a fixed point number term and a first floating point number term.
  3. 3. The floating-point exponent arithmetic of claim 2, wherein the converting the first fractional term to a fixed-point format fractional term splits the fixed-point format fractional term into a fixed-point term and a first floating-point term comprises: Acquiring an index value represented by a step code of the target floating point number; In response to the index value represented by the step code of the target floating point number being greater than or equal to a preset index value and less than zero, supplementing the first decimal term with an implicit preamble 1 to obtain a second decimal term; Right shifting the first number of bits of the second decimal place to obtain a third decimal place, taking a mantissa item corresponding to the high n bits in the third decimal place as a fixed point number item, wherein the first number is equal to the inverse number of the exponent value minus 1; And shifting left the mantissa items except the fixed-point number item in the third mantissa item by a second number of bits to obtain a residual mantissa item, and determining the first floating-point number item according to the step code of the target floating-point number and the residual mantissa item.
  4. 4. The floating point exponent operating method of claim 3 wherein after the obtaining the exponent value of the step code representation of the target floating point number further comprises: and determining the first decimal term as the first floating point term and the fixed point term as zero in response to the exponent value of the step code representation of the target floating point number being less than a preset exponent value.
  5. 5. A floating point exponent operation method applied to a tensor processor, the tensor processor including a control unit and a plurality of calculation units, the method comprising: Controlling the computing unit to execute a first instruction based on an input target floating point number to convert a first expression based on a real number e and an exponent of the target floating point number into a second expression based on 2 and an exponent of the second expression multiplied by an inverse of ln2, wherein the computing unit used to execute each of a plurality of computing instructions included in the first instruction is different; Controlling the calculation unit to execute a second instruction based on the index of the second arithmetic expression and the integer term to obtain a first decimal term of the index of the second arithmetic expression, splitting the first decimal term into a fixed point number term and a first floating point number term, obtaining a first index operation result corresponding to the fixed point number term from a preset table, calculating a second index operation result of the integer term, multiplying the first index operation result and the second index operation result to obtain an initial natural index operation result of a target floating point number, wherein the calculation unit used for executing each operation instruction in a plurality of operation instructions included in the second instruction is different; And controlling the computing unit to execute a third instruction based on the first floating point number item and the initial natural exponent operation result of the target floating point number so as to perform taylor expansion computation on the first floating point number item to obtain a third exponent operation result, and multiplying the initial natural exponent operation result of the target floating point number and the third exponent operation result to obtain a target natural exponent operation result of the target floating point number, wherein the computing unit used for executing each of a plurality of operation instructions included in the third instruction is different.
  6. 6. The floating point exponent operating method of claim 5 wherein splitting the first fraction term into a fixed point number term and a first floating point number term includes: and converting the first decimal term into a decimal term in a fixed point number format, and splitting the decimal term in the fixed point number format into a fixed point number term and a first floating point number term.
  7. 7. The floating-point exponent arithmetic of claim 6, wherein the converting the first fractional term to a fixed-point format fractional term splits the fixed-point format fractional term into a fixed-point term and a first floating-point term comprises: Acquiring an index value represented by a step code of the target floating point number; In response to the index value represented by the step code of the target floating point number being greater than or equal to a preset index value and less than zero, supplementing the first decimal term with an implicit preamble 1 to obtain a second decimal term; Right shifting the first number of bits of the second decimal place to obtain a third decimal place, taking a mantissa item corresponding to the high n bits in the third decimal place as a fixed point number item, wherein the first number is equal to the inverse number of the exponent value minus 1; And shifting left the mantissa items except the fixed-point number item in the third mantissa item by a second number of bits to obtain a residual mantissa item, and determining the first floating-point number item according to the step code of the target floating-point number and the residual mantissa item.
  8. 8. A tensor processor, characterized in that it comprises a control unit and a plurality of calculation units, said control unit being connected to said plurality of calculation units, said control unit being adapted to implement the floating point exponent operation method according to any one of claims 1 to 8.
  9. 9. A computer device comprising one or more tensor processors, one or more memories, a computer program stored on the memories and executable by the tensor processors, and a data bus for enabling a connection communication between the tensor processors and the memories, wherein the computer program, when executed by the tensor processors, implements the floating point exponent operation method of any of claims 1 to 7.
  10. 10. A storage medium for computer readable storage, wherein the storage medium stores one or more programs executable by one or more tensor processors to implement the floating point exponent operation method of any one of claims 1 to 7.

Description

Floating point exponent operation method, tensor processor, device, and storage medium Technical Field The present invention relates to the field of data processing technologies, and in particular, to a floating point exponent operation method, a tensor processor, a device, and a storage medium. Background The tensor processor (Tensor Processing Unit, TPU) is a processor customized for machine learning, has higher efficiency after training in special deep machine learning, and can run the neural network model more quickly, and the operation of the neural network model involves the calculation of functions such as Softmax, etc., which involves a large number of floating point exponent operations (operations based on real number e and floating point number as exponents) EXP (x). At present, a tensor processor generally converts an arithmetic expression based on a real number e and an exponent with a floating point number into an arithmetic expression based on 2 and an exponent with a floating point number, then decomposes the arithmetic expression based on 2 and an exponent with a floating point number into an integer term and a decimal term, the power corresponding to the integer term is realized through a shift operation, and the power corresponding to the decimal term is required to be iteratively calculated through a taylor series expansion. However, to achieve the target accuracy, the taylor expansion calculation needs to perform multiple polynomial iterative calculations, which takes longer time and has lower efficiency of floating point exponent operation. Therefore, how to improve the efficiency of floating point exponent operation under the premise of ensuring the precision of floating point exponent operation is a current urgent problem to be solved. Disclosure of Invention The embodiment of the invention provides a floating point exponent operation method, a tensor processor, equipment and a storage medium, aiming at improving the efficiency of floating point exponent operation on the premise of ensuring the precision of floating point exponent operation. In a first aspect, an embodiment of the present invention provides a floating point exponent operation method applied to a tensor processor, where the tensor processor includes a control unit and a plurality of computing units, the method includes: Controlling the calculation unit to convert a first arithmetic expression based on a real number e and an index of a target floating point number into a second arithmetic expression based on 2 and an inverse of the target floating point number multiplied by ln2 as an index, and obtaining integer items of the index of the second arithmetic expression; the calculation unit is controlled to obtain a first decimal term of the index of the second arithmetic formula, split the first decimal term into a fixed point number term and a first floating point number term, and obtain a first index operation result corresponding to the fixed point number term from a preset table; Controlling the calculation unit to calculate a second exponent operation result of the integer item and multiplying the first exponent operation result and the second exponent operation result to obtain an initial natural exponent operation result of the target floating point number; And controlling the computing unit to perform Taylor expansion computation on the first floating point number item to obtain a third index operation result, and multiplying the initial natural index operation result of the target floating point number by the third index operation result to obtain a target natural index operation result of the target floating point number. According to the floating point index operation method provided by the first aspect, a first operation formula based on a real number e and based on a target floating point number as an index is converted into a second operation formula based on 2 and based on the inverse of the target floating point number multiplied by ln2, an integer item of the index of the second operation formula is obtained, then the first decimal item of the second operation formula is split into a fixed point item and a first floating point item, a first index operation result corresponding to the fixed point item is obtained from a preset table, the second index operation result of the integer item is calculated, the first floating point item is subjected to Taylor expansion calculation to obtain a third index operation result, and finally the first index operation result, the second index operation result and the third index operation result are multiplied to obtain a target natural index operation result of the target floating point number, so that the number of times of iterative calculation of the Taylor expansion polynomial is reduced, and the efficiency of floating point index operation can be improved on the premise that the floating point index operation accuracy is ensured. In a second aspect, an embodiment o