# US 2022/0066737 A1 · Tanh and sigmoid function execution

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2022/0066737 A1
- Document ID: US20220066737A1
- Status: Published application
- Kind: A1
- Application number: 17/003,334
- Filed: 2020-08-26
- Published: 2022-03-03
- Earliest claimed: 2020-08-26
- Assignees: Intel Corporation
- Applicants: Intel Corporation
- Inventors: Shuai MU; Cristina S. ANDERSON; Subramaniam MAIYURAN
- Web page: https://patentgrep.com/patent/US20220066737A1

## CPC

- G06F 7/548: Trigonometric functions; Co-ordinate transformations
- G06N 3/063: using electronic means
- G06F 9/3001: {Arithmetic instructions}
- G06F 17/17: Function evaluation by approximation methods, e.g. inter- or extrapolation, smoothing, least mean square method ({G06F17/18 takes precedence } ; interpolation for numerical control G05B19/18)
- G06N 3/048: Activation functions
- G06F 2101/04: Trigonometric functions
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS

## Abstract

Examples described herein relate to instructions to request performance of tanh and sigmoid instructions. For example, a compiler can generate native tanh instructions to perform tanh. In some examples, a tanh function can be compiled into instructions that include an instruction to perform either tanh(input) or tanh(input)/input depending on a value of the input to generate an intermediate output; an instruction to cause a performance of generation of scale factor based on the input; and an instruction to cause performance of a multiplication operation on the intermediate result with the scale factor. For example, a sigmoid function can be compiled to cause a math pipeline to perform a range check and performs operations based on a range.

## Claims

### Claim 1

A computer-implemented method comprising:
performing a tanh function in a math pipeline and Floating Point Unit (FPU) pipeline of an execution unit (EU) of a graphics processing unit by:
based on a value range of an input x, generating an intermediate result by performing either a tanh(x) operation or tanh(x)/x operation;
based on the value range of the input x, generating a scale factor using a minimum operation; and
multiplying the intermediate result with the scale factor to generate an output of a tanh function for input x.

### Claim 2 (depends on 1)

The method of claim 1, comprising:
if a value of x is in a first range: determining tanh(x)/x to generate the intermediate result and multiplying the intermediate result by x or
if a value of x is in a second range: determining tanh(x) to generate the intermediate result and multiplying the intermediate result by a value.

### Claim 3 (depends on 2)

The method of claim 2, wherein determining tanh(x) comprises:
performing a quadratic interpolation operation or clamping to a fixed value.

### Claim 4 (depends on 3)

The method of claim 3, wherein the performing a quadratic interpolation operation comprises:
generating C0+C1*delta+C2*delta*delta, where:
C0, C1, and C2 comprise constant values selected from a look-up table based on a value of x and
delta comprises bits of x's mantissa.

### Claim 5 (depends on 4)

The method of claim 4, wherein interpolation logic performs the generating C0+C1*delta+C2*delta*delta.

### Claim 6 (depends on 1)

The method of claim 1, wherein generating a scale factor using a minimum operation comprises performing:
MIN(abs(x), 1) to selects a smaller of an absolute value of x and 1.

### Claim 7 (depends on 1)

The method of claim 1, wherein the tanh operation is generated by a compiler from a tanh application program interface (API) as a tanh instruction, a minimum instruction and one multiply instruction.

### Claim 8

A method of performing sigmoid comprising:
performing a sigmoid operation on an input value comprising: based on a range of the input value, clamping an output to fixed value or performing a piece-wise quadratic interpolation.

### Claim 9 (depends on 8)

The method of claim 8, wherein clamping an output to fixed value or performing a piece-wise quadratic interpolation comprises:
math
.
sigmoid
⁢
⁢
(
x
)
=
{
Nan
Nan
0.0
,
x
∈
[
-
INF
,
16
]
C
⁢
⁢
0
+
C
⁢
⁢
1
*
delta
+
C
⁢
⁢
2
*
delta
*
delta
,
x
∈
(
-
16
,
-
2
-
20
]
0.5
,
x
∈
(
-
2
-
20
,
-
0
]
0.5
,
x
∈
[
0
,
2
-
20
)
C
⁢
⁢
0
′
+
C
⁢
⁢
1
′
*
delta
+
C
⁢
⁢
2
′
*
delta
*
delta
x
∈
[
2
-
20
,
16
)
1.0
,
x
∈
[
16
,
+
INF
)

### Claim 10 (depends on 9)

The method of claim 9, comprising:
providing access to different look up table entries for coefficients for different ranges, wherein merely coefficients for a negative input are stored in different look up table entries and coefficients for a positive input are derived from the coefficients for a negative input.

### Claim 11

A non-transitory computer-readable medium comprising instructions stored thereon, that if executed by one or more processors, cause the one or more processors to:
execute a tanh application program interface (API) as a combination of a tanh instruction, a minimum instruction, and one multiply instruction.

### Claim 12 (depends on 11)

The non-transitory computer-readable medium of claim 11, wherein the tanh instruction comprises:
if an input x value is in a range of [0, 1), execution of the tanh instruction causes generation of a tanh(x)/x operation to generate an intermediate result and multiplication of the intermediate result by x or
if the input x value is in a range of 1 and greater, execution of the tanh instruction causes generation of a tanh(x) to generate an intermediate result and multiplication of the intermediate result by 1.0f.

### Claim 13 (depends on 12)

The non-transitory computer-readable medium of claim 12, wherein the generation of a tanh(x) comprises performance of a quadratic interpolation operation or clamping to a fixed value.

### Claim 14 (depends on 13)

The non-transitory computer-readable medium of claim 13, wherein the performance of a quadratic interpolation operation comprises:
determine C0+C1*delta+C2*delta*delta, where:
C0, C1, and C2 comprise constant values selected from a look-up table based on a value of input value x and
delta comprises bits of x's mantissa.

### Claim 15

A non-transitory computer-readable medium comprising instructions stored thereon, that if executed by one or more processors, cause the one or more processors to:
execute a sigmoid application program interface (API) as: based on a range of an input value, clamping an output to fixed value or performing a piece-wise quadratic interpolation.

### Claim 16 (depends on 15)

The non-transitory computer-readable medium of claim 15, wherein the performing a piece-wise quadratic interpolation comprises:
providing access to different look up table entries for coefficients for different ranges, wherein merely coefficients for a negative input are stored in different look up table entries and coefficients for a positive input are derived from the coefficients for a negative input.

### Claim 17

A graphics processing apparatus comprising:
a memory device; and
a graphics processing unit (GPU) comprising at least one execution unit, an execution unit configured to:
perform a tanh application operation as a combination of a tanh instruction, a minimum instruction, and one multiply instruction and
perform a sigmoid operation on an input value comprising: based on a range of the input value, clamping an output to fixed value or performing a piece-wise quadratic interpolation.

### Claim 18 (depends on 17)

The graphics processing apparatus of claim 17, wherein:
the execution unit comprises a math pipeline and Floating Point Unit (FPU) pipeline.

### Claim 19 (depends on 18)

The graphics processing apparatus of claim 18, wherein to perform a tanh application operation, the math pipeline is to:
if an x value is in a first range: determine a tanh(x)/x to generate an intermediate result and multiply the intermediate result by x or
if the x value is in a second range: determine tanh(x) to generate an intermediate result and multiply the intermediate result by a value, wherein the determine tanh(x) comprises perform a quadratic interpolation operation or clamping to a fixed value.

### Claim 20 (depends on 18)

The graphics processing apparatus of claim 18, wherein the performing a piece-wise quadratic interpolation comprises accessing different look up table entries for coefficients for different ranges, wherein merely coefficients for a negative input are stored in different look up table entries and coefficients for a positive input are derived from the coefficients for a negative input.
