You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/fexpa/_index.md
+5-7Lines changed: 5 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,18 @@
1
1
---
2
-
title: Accelerate the exponential function
2
+
title: Optimize exponential functions with FEXPA
3
3
4
-
draft: true
5
-
cascade:
6
-
draft: true
7
4
8
5
minutes_to_complete: 15
9
6
10
-
who_is_this_for: This is an introductory topic for developers interested in implementing the exponential function and optimizing it. The Scalable Vector Extension (SVE), introduced with the Armv8-A architecture, includes a dedicated instruction, FEXPA. Although initially not supported in SME, the FEXPA instruction has been made available in Scalable Matrix Extension (SME) version 2.2.
7
+
who_is_this_for: This is an introductory topic for developers interested in accelerating exponential function computations using Arm's Scalable Vector Extension (SVE). The FEXPA instruction provides hardware acceleration for exponential calculations on Arm Neoverse processors.
11
8
12
9
learning_objectives:
13
10
- Implement the exponential function using SVE intrinsics
14
11
- Optimize the function with FEXPA
15
12
16
13
prerequisites:
17
-
- Access to an [AWS Graviton4, Google Axion, or Azure Cobalt 100 virtual machine from a cloud service provider](/learning-paths/servers-and-cloud-computing/csp/).
18
-
- Some familiarity with SIMD programming and SVE intrinsics.
14
+
- Access to an [AWS Graviton4, Google Axion, or Azure Cobalt 100 virtual machine from a cloud service provider](/learning-paths/servers-and-cloud-computing/csp/)
15
+
- Some familiarity with SIMD programming and SVE intrinsics
19
16
20
17
author:
21
18
- Arnaud Grasset
@@ -54,3 +51,4 @@ weight: 1 # _index.md always has weight of 1 to order corr
54
51
layout: "learningpathall"# All files under learning paths have this same wrapper
55
52
learning_path_main_page: "yes"# This should be surfaced when looking for related content. Only set for _index.md of learning path content.
The SVE FEXPA instruction can speed-up the computation of the exponential functions by implementing table lookup and bit manipulation. The exponential function is the core of the Softmax function that, with the shift toward Generative AI, has become a critical component of modern neural network architectures.
9
+
## Summary
11
10
12
-
An implementation of the exponential function based on FEXPA can achieve a specified target precision using a polynomial of lower degree than that required by alternative implementations. Moreover, SME support for FEXPA lets you embed the exponential approximation directly into the matrix computation path and that translates into:
11
+
The SVE FEXPA instruction speeds up the computation of exponential functions by implementing table lookup and bit manipulation. The exponential function is the core of the Softmax function that, with the shift toward Generative AI, has become a critical component of modern neural network architectures.
12
+
13
+
An implementation of the exponential function based on FEXPA can achieve a specified target precision using a polynomial of lower degree than alternative implementations. SME support for FEXPA lets you embed the exponential approximation directly into the matrix computation path, which translates into:
13
14
- Fewer instructions (no back-and-forth to scalar/SVE code)
14
15
- Potentially higher aggregate throughput (more exponentials per cycle)
15
16
- Lower power & bandwidth (data being kept in the SME engine)
16
17
- Cleaner fusion with GEMM/GEMV workloads
17
18
18
-
All of which makes all exponentialheavy workloads significantly faster on ARM CPUs.
19
+
These improvements make exponential-heavy workloads significantly faster on Arm CPUs.
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/fexpa/fexpa.md
+16-7Lines changed: 16 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: FEXPA
2
+
title: Optimize with FEXPA instruction
3
3
weight: 4
4
4
5
5
### FIXED, DO NOT MODIFY
@@ -8,9 +8,9 @@ layout: learningpathall
8
8
9
9
## The FEXPA instruction
10
10
11
-
Arm introduced in SVE an instruction called FEXPA: the Floating Point Exponential Accelerator.
11
+
Arm introduced an instruction in SVE called FEXPA: the Floating Point Exponential Accelerator.
12
12
13
-
Let’s segment the IEEE 754 floating-point representation fraction part into several sub-fields (Index, Exp and Remaining bits) with respective length of _Idxb_, _Expb_ and _Remb_ bits.
13
+
The IEEE 754 floating-point representation fraction part can be segmented into several sub-fields (Index, Exp and Remaining bits) with respective length of _Idxb_, _Expb_ and _Remb_ bits.
14
14
15
15
| IEEE 754 precision | Idxb | Expb | Remb |
16
16
|-------------------------|------|------|------|
@@ -46,7 +46,7 @@ With a table of size 2^L, the evaluation interval for the approximation polynomi
46
46
47
47
## Exponential implementation with FEXPA
48
48
49
-
FEXPA can be used to rapidly perform the table lookup. With this instruction a degree-2 polynomial is sufficient to obtain the same accuracy as the degree-4 polynomial implementation from the previous section.
49
+
Use FEXPA to rapidly perform the table lookup. With this instruction, a degree-2 polynomial is sufficient to obtain the same accuracy as the degree-4 polynomial implementation from the previous section.
This implementation can be found in [ARM Optimized Routines](https://github.com/ARM-software/optimized-routines/blob/ba35b32/math/aarch64/sve/sv_expf_inline.h).
96
+
This implementation can be found in [Arm Optimized Routines](https://github.com/ARM-software/optimized-routines/blob/ba35b32/math/aarch64/sve/sv_expf_inline.h).
1.**SVE with degree-4 polynomial**: Provides up to 4x speedup through vectorization
150
-
2.**SVE with FEXPA and degree-2 polynomial**: Achieves an additional 1-2x improvement
149
+
-SVE with degree-4 polynomial provides up to 4x speedup through vectorization
150
+
-SVE with FEXPA and degree-2 polynomial achieves an additional 1-2x improvement
151
151
152
152
The FEXPA instruction delivers this improvement by:
153
153
- Replacing manual bit manipulation with a single hardware instruction (`svexpa()`)
154
154
- Enabling a simpler polynomial (degree-2 instead of degree-4) while maintaining accuracy
155
155
156
156
Both SVE implementations maintain comparable accuracy (errors in the 10^-9 to 10^-10 range), demonstrating that specialized hardware instructions can significantly improve performance without sacrificing precision.
157
+
158
+
## What you've accomplished and what's next
159
+
160
+
In this section, you:
161
+
- Implemented exponential function optimization using the FEXPA instruction
162
+
- Reduced polynomial degree from four to two while maintaining accuracy
163
+
- Achieved up to 6x speedup over the baseline implementation
164
+
165
+
Next, you'll review the key benefits and applications of FEXPA optimization.
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/fexpa/implementation.md
+11-4Lines changed: 11 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: First implementation
2
+
title: Implement exponential with SVE intrinsics
3
3
weight: 3
4
4
5
5
### FIXED, DO NOT MODIFY
@@ -8,11 +8,11 @@ layout: learningpathall
8
8
9
9
## Implement the exponential function
10
10
11
-
Based on the theory covered in the previous section, you can implement the exponential function using SVE intrinsics with polynomial approximation. This Learning Path was tested using a AWS Graviton4 instance type `r8g.medium`.
11
+
Based on the theory covered in the previous section, implement the exponential function using SVE intrinsics with polynomial approximation. This Learning Path was tested using an AWS Graviton4 instance type `r8g.medium`.
12
12
13
13
## Set up your environment
14
14
15
-
To run the example, you will need `gcc`.
15
+
To run the example, you need `gcc`.
16
16
17
17
```bash
18
18
sudo apt update
@@ -230,4 +230,11 @@ The benchmark demonstrates the performance benefit of using SVE intrinsics for v
230
230
231
231
The accuracy check confirms that the polynomial approximation maintains high precision, with errors typically in the range of 10^-9 to 10^-10 for single-precision floating-point values.
232
232
233
-
Continue to the next section to dive into the FEXPA intrinsic implementation, providing further performance uplifts.
233
+
## What you've accomplished and what's next
234
+
235
+
In this section, you:
236
+
- Implemented a vectorized exponential function using SVE intrinsics
237
+
- Applied range reduction and polynomial approximation techniques
238
+
- Achieved up to 4x speedup over the scalar baseline
239
+
240
+
Next, you'll optimize further using the FEXPA instruction for additional performance gains.
title: Learn exponential function optimization techniques
3
3
weight: 2
4
4
5
5
### FIXED, DO NOT MODIFY
6
6
layout: learningpathall
7
7
---
8
8
9
9
## The exponential function
10
-
The exponential function is a fundamental mathematical function used across a wide range of algorithms for signal processing, High-Performance Computing and Machine Learning. Optimizing its computation has been the subject of extensive research for decades. The precision of the computation depends both on the selected approximation method and on the inherent rounding errors associated with finite-precision arithmetic, and it is directly traded off against performance when implementing the exponential function.
10
+
The exponential function is a fundamental mathematical function used across a wide range of algorithms for signal processing, High-Performance Computing and Machine Learning. Researchers have extensively studied optimizing its computation for decades. The precision of the computation depends both on the selected approximation method and on the inherent rounding errors associated with finite-precision arithmetic, and it is directly traded off against performance when implementing the exponential function.
11
11
12
12
## Range reduction
13
-
Polynomial approximations are among the most widely used methods for software implementations of the exponential function. The accuracy of a Taylor series approximation for exponential function can be improved with the polynomial’s degree but will always deteriorate as the evaluation point moves further from the expansion point. By applying range reduction techniques, the approximation of the exponential function can however be restricted to a very narrow interval where the function is well-conditioned. This approach consists in reformulating the exponential function in the following way:
13
+
Polynomial approximations are among the most widely used methods for software implementations of the exponential function. The accuracy of a Taylor series approximation for exponential function can be improved with the polynomial's degree but deteriorates as the evaluation point moves further from the expansion point. By applying range reduction techniques, you can restrict the approximation of the exponential function to a very narrow interval where the function is well-conditioned. This approach reformulates the exponential function in the following way:
14
14
15
15
$$e^x=e^{k×ln2+r}=2^k \times e^r$$
16
16
@@ -22,16 +22,16 @@ Since k is an integer, the evaluation of 2^k can be efficiently performed using
22
22
23
23
$$e^x \approx 2^k \times p(r)$$
24
24
25
-
It is important to note that the polynomial p(r) is evaluated exclusively over the interval [-ln2/2, +ln2/2]. So, the computational complexity can be optimized by selecting the polynomial degree based on the required precision of p(r) within this narrow range. Rather than relying on a Taylor polynomial, a minimax polynomial approximation can be used to minimize the maximum approximation error over the considered interval.
25
+
The polynomial p(r) is evaluated exclusively over the interval [-ln2/2, +ln2/2]. So, the computational complexity can be optimized by selecting the polynomial degree based on the required precision of p(r) within this narrow range. Rather than relying on a Taylor polynomial, a minimax polynomial approximation can be used to minimize the maximum approximation error over the considered interval.
26
26
27
27
## Decomposition of the input
28
-
The decomposition of an input value as x = k × ln2 + r can be done in 2 steps:
28
+
Decompose an input value as x = k × ln2 + r in two steps:
29
29
- Compute k as: k = round(x⁄ln2), where round(.) is the round-to-nearest function
30
30
- Compute r as: r = x - k × ln2
31
31
32
-
Rounding of k is performed by adding an adequately chosen large number to a floating-point value and subtracting it just afterward (the original value is rounded due to the finite precision of floating-point representation). Although explicit rounding instructions are available in both SVE and SME, this method remains advantageous as the addition of the constant can be fused with the multiplication by the reciprocal of ln2. This approach assumes however that the floating-point rounding mode is set to round-to-nearest, which is the default mode in Armv9-A. By integrating the bias into the constant, 2^k can also be directly computed by shifting the intermediate value.
32
+
Rounding of k is performed by adding an adequately chosen large number to a floating-point value and subtracting it just afterward (the original value is rounded because of the finite precision of floating-point representation). Although explicit rounding instructions are available in both SVE and SME, this method remains advantageous because the addition of the constant can be fused with the multiplication by the reciprocal of ln2. This approach assumes that the floating-point rounding mode is set to round-to-nearest, which is the default mode in Armv9-A. By integrating the bias into the constant, 2^k can also be directly computed by shifting the intermediate value.
33
33
34
-
Rounding error during the second step will introduce a global error as we will have:
34
+
A rounding error during the second step introduces a global error as you have:
where s is the sign bit and 1.fraction represents the significand.
46
46
47
-
The value 2^k can be encoded by setting both the sign and fraction bits to zero and assigning the exponent field the value k + bias. If k is an 8-bits integer, 2^k can be efficiently computed by adding the bias value and positioning the result into the exponent bits of a 32-bit floating-point number using a logical shift.
47
+
The value 2^k can be encoded by setting both the sign and fraction bits to zero and assigning the exponent field the value k + bias. If k is an 8-bit integer, 2^k can be efficiently computed by adding the bias value and positioning the result into the exponent bits of a 32-bit floating-point number using a logical shift.
48
48
49
-
Taking this approach a step further, a fast approximation of exponential function can be achieved using bits manipulation techniques alone. Specifically, adding a bias to an integer k and shifting the result into the exponent field can be accomplished by computing an integer i as follows:
49
+
Taking this approach a step further, you can achieve a fast approximation of exponential function using bit manipulation techniques alone. Specifically, adding a bias to an integer k and shifting the result into the exponent field can be accomplished by computing an integer i as follows:
This formulation assumes a 23-bit significand, but the method can be generalized to other floating-point precisions.
54
54
55
-
Now, consider the case where k is a real number. The fractional part of k will propagate into the significand bits of the resulting 2^k approximation. However, this side effect is not detrimental, it effectively acts as a form of linear interpolation, thereby improving the overall accuracy of the approximation. To approximate the exponential function, the following identity can be used:
55
+
Now, consider the case where k is a real number. The fractional part of k propagates into the significand bits of the resulting 2^k approximation. However, this side effect isn't detrimental; it effectively acts as a form of linear interpolation, thereby improving the overall accuracy of the approximation. To approximate the exponential function, use the following identity:
56
56
57
57
$$e^x = 2^{x⁄ln2}$$
58
58
59
59
As previously discussed, this value can be approximated by computing a 32-bit integer:
60
60
61
61
$$i = 2^{23} \times x⁄ln2 + 2^{23} \times bias = a \times x + b $$
62
62
63
-
Continue to the next section to make a C-based implementation of the exponential function.
63
+
## What you've accomplished and what's next
64
+
65
+
In this section, you learned the mathematical foundations for optimizing exponential functions:
66
+
- Range reduction techniques that narrow the evaluation interval
67
+
- How to decompose inputs using k × ln2 + r reformulation
68
+
- Bit manipulation techniques for computing scaling factors
69
+
70
+
Next, you'll implement these concepts in C using SVE intrinsics.
0 commit comments