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
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,11 @@ minutes_to_complete: 15
10
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.
11
11
12
12
learning_objectives:
13
-
- Implementing with SVE intrinsics the exponential function
14
-
- Optimizing it with FEXPA
13
+
- Implement the exponential function using SVE intrinsics
14
+
- Optimize the function with FEXPA
15
15
16
16
prerequisites:
17
-
- An AArch64 computer running Linux or macOS. You can use cloud instances, refer to [Get started with Arm-based cloud instances](/learning-paths/servers-and-cloud-computing/csp/) for a list of cloud service providers.
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
18
- Some familiarity with SIMD programming and SVE intrinsics.
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/fexpa/conclusion.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,12 +7,12 @@ layout: learningpathall
7
7
---
8
8
9
9
## Conclusion
10
-
The SVE2 FEXPA instruction can speed-up the computation of the exponential function by implementing Look-Up and bit manipulation.
10
+
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.
11
11
12
-
In conclusion, SME-support for FEXPA lets you embed the expensive exponential approximation directly into the matrix computation path. That translates into:
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, SMEsupport for FEXPA lets you embed the exponential approximation directly into the matrix computation path and that translates into:
13
13
- Fewer instructions (no back-and-forth to scalar/SVE code)
14
14
- Potentially higher aggregate throughput (more exponentials per cycle)
15
-
- Lower power & bandwidth (data being kept in SME engine)
15
+
- Lower power & bandwidth (data being kept in the SME engine)
16
16
- Cleaner fusion with GEMM/GEMV workloads
17
17
18
18
All of which makes all exponential heavy workloads significantly faster on ARM CPUs.
Arm introduced in SVE an instruction called FEXPA: the Floating Point Exponential Accelerator.
12
12
13
-
Let’s segment the IEEE754 floating-point representation fraction part into several sub-fields (Index, Exp and Remaining bits) with respective length of Idxb, Expb and Remb bits.
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.
With a table of size 2^L, the evaluation interval for the approximation polynomial is narrowed by a factor of 2^L. This reduction leads to improved accuracy for a given polynomial degree due to the narrower approximation range. Alternatively, for a given accuracy target, the degree of the polynomial—and hence its computational complexity—can be reduced.
46
46
47
47
## Exponential implementation with FEXPA
48
-
FEXPA can be used to rapidly perform the table lookup. With this instruction a degree-2 polynomial is sufficient to obtain the same accuracy of the implementation we have seen before:
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.
50
+
51
+
### Add the FEXPA implementation
52
+
53
+
Open your `exp_sve.c` file and add the following function after the `exp_sve()` function:
54
+
55
+
```C
56
+
// SVE exponential implementation with FEXPA (degree-2 polynomial)
svfloat32_t result = svmla_f32_x(pg, scale, poly, scale);
88
+
89
+
svst1(pg, &y[i], result);
90
+
i += svcntw();
91
+
}
92
+
}
93
+
```
94
+
95
+
{{% notice Arm Optimized Routines %}}
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).
97
+
{{% /notice %}}
98
+
99
+
100
+
Now register this new implementation in the `implementations` array in `main()`. Find this section:
101
+
102
+
```C
103
+
exp_impl_t implementations[] = {
104
+
{"Baseline (expf)", exp_baseline},
105
+
{"SVE (degree-4 poly)", exp_sve},
106
+
// Add more implementations here as you develop them
107
+
};
108
+
```
109
+
110
+
Add your FEXPA implementation to the array:
49
111
50
112
```C
51
-
svfloat32_t lane_consts = svld1rq(pg, ln2_lo); // Load only ln2_lo
113
+
exp_impl_t implementations[] = {
114
+
{"Baseline (expf)", exp_baseline},
115
+
{"SVE (degree-4 poly)", exp_sve},
116
+
{"SVE+FEXPA (degree-2)", exp_sve_fexpa},
117
+
};
118
+
```
119
+
120
+
## Compile and compare
52
121
53
-
/* Compute k as round(x/ln2) using shift = 1.5*2^(23-6) + 127 */
54
-
svfloat32_t z = svmad_x(pg, svdup_f32(inv_ln2), x, shift);
55
-
svfloat32_t k = svsub_x(pg, z, shift);
122
+
Recompile the program:
56
123
57
-
/* Compute r as x - k*ln2 with Cody and Waite */
58
-
svfloat32_t r = svmsb_x(pg, svdup_f32(ln2_hi), k, x);
svfloat32_t result = svmla_f32_x(pg, scale, poly, scale);
136
+
```output
137
+
Performance Results:
138
+
Implementation Time (sec) Speedup vs Baseline
139
+
------------- ----------- -------------------
140
+
Baseline (expf) 0.002462 1.00x
141
+
SVE (degree-4 poly) 0.000578 4.26x
142
+
SVE+FEXPA (degree-2) 0.000414 5.95x
70
143
```
144
+
145
+
## Results analysis
146
+
147
+
The benchmark shows the performance progression:
148
+
149
+
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
151
+
152
+
The FEXPA instruction delivers this improvement by:
153
+
- Replacing manual bit manipulation with a single hardware instruction (`svexpa()`)
154
+
- Enabling a simpler polynomial (degree-2 instead of degree-4) while maintaining accuracy
155
+
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.
0 commit comments