Skip to content

Commit 0472888

Browse files
authored
Merge pull request #560 from stephentheobald-arm/main
First draft of new SME2 Learning Path
2 parents b8d4a0a + bf02920 commit 0472888

File tree

7 files changed

+250
-0
lines changed

7 files changed

+250
-0
lines changed
9.59 KB
Loading
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Get started with the Scalable Matrix Extension (SME)
3+
4+
minutes_to_complete: 20
5+
6+
who_is_this_for: This is an introductory topic for software developers who want to learn about Scalable Matrix Extension (SME2) to optimize the processing of matrices.
7+
8+
learning_objectives:
9+
- Understand the SME architecture
10+
- Build, run, and debug an SME2 single-precision floating-point matrix multiply example
11+
12+
prerequisites:
13+
- A computer with Arm DS installed
14+
- Some understanding of the Arm Architecture
15+
16+
author_primary: Stephen Theobald
17+
18+
### Tags
19+
skilllevels: Introductory
20+
subjects: Performance and Architecture
21+
armips:
22+
- Armv9-A
23+
24+
tools_software_languages:
25+
- Coding
26+
- Arm Development Studio
27+
28+
operatingsystems:
29+
- Bare-metal
30+
31+
### Cross-platform metadata only
32+
shared_path: true
33+
shared_between:
34+
- servers-and-cloud-computing
35+
- laptops-and-desktops
36+
- embedded-systems
37+
38+
### FIXED, DO NOT MODIFY
39+
# ================================================================================
40+
weight: 1 # _index.md always has weight of 1 to order correctly
41+
layout: "learningpathall" # All files under learning paths have this same wrapper
42+
learning_path_main_page: "yes" # This should be surfaced when looking for related content. Only set for _index.md of learning path content.
43+
---
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
next_step_guidance: You now have an understanding of the Scalable Matrix Extension.
3+
4+
recommended_path: /learning-paths/servers-and-cloud-computing/sve
5+
6+
further_reading:
7+
- resource:
8+
title: Introducing the Scalable Matrix Extension for the Armv9-A Architecture
9+
link: https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/scalable-matrix-extension-armv9-a-architecture
10+
type: blog
11+
- resource:
12+
title: The Scalable Matrix Extension (SME), for Armv9-A. Arm Architecture Reference Manual Supplement
13+
link: https://developer.arm.com/documentation/ddi0616
14+
type: documentation
15+
16+
17+
# ================================================================================
18+
# FIXED, DO NOT MODIFY
19+
# ================================================================================
20+
weight: 21 # set to always be larger than the content in this path, and one more than 'review'
21+
title: "Next Steps" # Always the same
22+
layout: "learningpathall" # All files under learning paths have this same wrapper
23+
---
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
review:
3+
- questions:
4+
question: >
5+
How large is the ZA storage?
6+
answers:
7+
- (SVL/8) x (SVL/8) bits
8+
- (SVL/8) x (SVL/8) bytes
9+
- (SVL/8) x (SVL/8) floats
10+
correct_answer: 2
11+
explanation: >
12+
The ZA storage is a two-dimensional array of (SVL/8) x (SVL/8) bytes. Since SVL is a power of two in the range 128 to 2048 bits, (SVL/8) will be a power of two in the range 16 to 256 bytes.
13+
14+
- questions:
15+
question: >
16+
When is the ZA array activated at run-time?
17+
answers:
18+
- When the first FMOPA instruction is executed
19+
- When an SMSTART instruction is executed
20+
- When the processor is powered-up/reset (or the FVP model is started)
21+
correct_answer: 2
22+
explanation: >
23+
The ZA array is activated at run-time when an SMSTART instruction is executed.
24+
25+
- questions:
26+
question: >
27+
How can the contents of the ZA tiles be viewed in the Arm Debugger?
28+
answers:
29+
- The ZA array is memory mapped, so the tiles can be viewed by their address in the Memory view
30+
- The tiles reside on the stack, so can be viewed as an offset from the Stack Pointer
31+
- The Registers view can show the contents of the various tiles in a variety of formats
32+
correct_answer: 3
33+
explanation: >
34+
The ZA tiles can be viewed in the Registers view in a variety of formats. Their contents can also be viewed in the Commands view by using `output` commands.
35+
36+
37+
# ================================================================================
38+
# FIXED, DO NOT MODIFY
39+
# ================================================================================
40+
title: "Review" # Always the same title
41+
weight: 20 # Set to always be larger than the content in this path
42+
layout: "learningpathall" # All files under learning paths have this same wrapper
43+
---
335 KB
Loading
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
title: Matrix multiply example
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
A single-precision floating-point matrix multiply (vector length agnostic) bare-metal example to illustrate Scalable Matrix Extension (SME) is provided with Arm Development Studio, 2023.0 and later.
10+
11+
The example shows a reference C implementation compared to an optimized version in assembler using SME2 instructions.
12+
13+
The example builds with Arm Compiler for Embedded 6, executes on the Arm Architecture Envelope Model for A-class (AEMvA) Fixed Virtual Platform (FVP) model, and can be run/debugged with the Arm Debugger.
14+
15+
The compiler, FVP model, and debugger are all provided in Arm Development Studio.
16+
17+
## Import the example
18+
19+
Open the Arm Development Studio IDE. Navigate to `File` > `Import...` > `Arm Development Studio` > `Examples & Programming Libraries` > `Examples` > `Armv9 Bare-Metal`, and select the `sme2_matmul_fp32` example. Using the text filter at the top of the pane can help locate the example. Click `Finish` to import.
20+
21+
Alternatively extract the example on the command line from the `<install_dir>\examples\Bare-metal_examples_Armv9.zip` archive. For interactive debug (see later) using the IDE is recommended.
22+
23+
Though the project is provided pre-compiled, you can also rebuild with the `Build` icon, or the `make` command from the command line.
24+
25+
The example is compiled with `-march=armv9-a+sme2`, as set in the `makefile`.
26+
27+
See the supplied `readme.html` for more information.
28+
29+
## Load the example
30+
31+
There is a supplied `sme2_matmul_fp32.launch` debug connection which has all necessary settings configured.
32+
33+
Double-click on the `.launch` file to open.
34+
35+
The AEMvA FVP model is a generic Arm implementation, which can be configured appropriately to enable Arm architectural features.
36+
37+
The model is launched with appropriate settings to implement full SME2 support, including:
38+
39+
`-C SVE.ScalableVectorExtension.has_sme=1 -C SVE.ScalableVectorExtension.has_sme2=1 -C SVE.ScalableVectorExtension.sme_veclens_implemented=7`
40+
41+
The `has_sme=1` and `has_sme2=1` parameters enable support for SME and SME2 respectively.
42+
43+
The `sme_veclens_implemented` parameter sets which SME vector lengths are implemented in the model. This is represented as a bitfield where bit[n]==1 implies a vector length of 128*2^n bits is implemented. The default `sme_veclens_implemented=7` means vector lengths of 128, 256, and 512 are supported. You can change this to fix a particular vector length by setting, for example, `sme_veclens_implemented=2` for 256 bits.
44+
The vector length can also be read by software at run-time using the `RDSVL` instruction (see later).
45+
46+
For more information on the model parameters, launch the model with `FVP_Base_AEMvA --list-params`
47+
48+
Click `Debug` to launch the FVP and load the image.
49+
50+
Execution can be controlled by the `Debug Control` pane icon bar (eg `Step Instruction` ), the command line (`stepi`), or short-cut keys (`F5`).
51+
52+
## Understand the example
53+
54+
![example image alt-text#center](armds_sme2.png "Figure 2. Debugging the SME2 example in Arm Development Studio")
55+
56+
1. In the Registers view, expand AArch64 > System > ID > ID_AA64PFR1_EL1. Notice the SME bits are set to 2, meaning the SME2 architectural state and programmers model are implemented on this target.
57+
2. This bit can also be inspected in the Commands view, by entering `output $AArch64::$System::$ID::$ID_AA64PFR1_EL1.SME`. Other bits in other registers may be inspected similarly.
58+
3. In the Registers view, expand AArch64 > System > PSTATE > SVCR. Notice the ZA bit is currently 0, meaning the ZA array storage is invalid and not accessible. This will change to 1 later, when an SMSTART instruction is executed.
59+
4. In `main.c`, observe that `main()` initialises the sizes (M, N, K) of the matrices, prints a welcome banner, then disables SVE and SIMD traps.
60+
5. Set a breakpoint on the `disable_sve_traps` function with `break disable_sve_traps` and run to it (press F8). It is written in assembler.
61+
6. In the Registers view, expand AArch64 > System > Secure > CPTR_EL3. To avoid SME, SVE, or SIMD instructions being trapped, the ESM and EZ bits must be set to 1 and the TFP bit must be cleared to 0, respectively, in CPTR_EL3. These bits reset to an architecturally unknown value on startup.
62+
7. In the Debug Control view, select Stepping By Instruction (press F10) to switch stepping mode to instruction level.
63+
8. Single-step (press F5) over the MRS, BIC, ORR, MSR, ISB instructions, and observe those bits are set/cleared as required.
64+
9. The vector length is read at run-time using an `RDSVL` instruction. To see this, set a breakpoint on `sve_cntw()` with `break sve_cntw` and run to it (press F8). Single-step (press F5) the `RDSVL` instruction. The value returned by `RDSVL` in the specified register is SVL DIV 8.
65+
10. In the Debug Control view, select Stepping By Source (press F10) to switch stepping mode back to C source level.
66+
11. The C code then initializes the matLeft and matRight arrays with random single-precision floating-point values. The input (and result) matrices are stored in memory in a row-major memory layout. To see the input values matLeft and matRight, set a breakpoint on the call to matmul() on line 85 and run to it (press F8). Open the Memory view, select Xn (Format) > Float > 4 bytes, then enter either matLeft or matRight in the address field (top-left text entry box).
67+
12. The C code then calls two functions, `matmul()` and `matmul_opt()`, to multiply the matLeft and matRight values. `matmul()` is a generic reference C implementation. `matmul_opt()` is an optimized version in assembler using SME2 instructions.
68+
13. Set a breakpoint on `matmul()` with `break matmul` and run to it (press F8). In the Registers view, expand AArch64 > Core, and note the value of X5. Parameters are passed here in registers, so X5 (6th parameter) will contain the address where the matResult will be stored.
69+
14. In the Disassembly view, notice that the inner loop calculations are performed using FMADD instructions on the SIMD single-precision registers S0, S1, S2.
70+
15. In the Registers view, expand AArch64 > SIMD > Single.
71+
16. In the Disassembly view, set a breakpoint on the FMADD instruction and run to it (press F8), and see the SIMD single-precision registers S0, S1, S2 changing. Run again and again.
72+
17. Delete the breakpoint on the FMADD instruction, then step-out of the function (press F7) back into main().
73+
18. To see the result matResult, in the Memory view, enter the previously noted address from X5 in the address field.
74+
19. Set a breakpoint on `matmul_opt()` with `break matmul_opt` and run to it (press F8). The optimized SME2 assembler is displayed in the Editor and Disassembly views.
75+
20. In the Registers view, expand AArch64 > Core, and again note the value of X5, which will now contain the address where the matResult_opt will be stored.
76+
21. In the Registers view, expand AArch64 > System > PSTATE > SVCR. Notice the ZA and SM bits are still 0.
77+
22. Single-step (press F5) up to and over the SMSTART instruction, and see the ZA changing to 1, meaning the ZA array storage is now valid and accessible.
78+
23. Set a breakpoint on the first instruction (`fmopa za2.s ...`) in `.Loop_K` at line 124 and run to it (press F8). This instruction performs a floating-point outer product and accumulate, putting the result in tile ZA2.
79+
24. To see a full description of this instruction, or any other instruction in this example, simply hover the mouse over the instruction, in either the Editor or Disassembly views.
80+
25. In the Registers view, expand AArch64 > SME > Tiles > ZA2H_S > F32 > [0]. This shows the contents of the zeroth row ('H') of tile ZA2 as floats, initially all zero.
81+
26. In the Registers view, expand AArch64 > SME > Tiles > ZA2V_S > F32 > [0]. This shows the contents of the zeroth column ('V') of tile ZA2 as floats, also initially all zero.
82+
27. Double-click on ZA2H_S.F32[0][0], and change its value to e.g. 99. Notice that ZA2V_S.F32[0][0] changes to the same value, because the zeroth element of the zeroth column is the same as the zeroth element of the zeroth row (the top-left element of the matrix).
83+
28. In the Commands view, notice that the equivalent command is also shown, e.g. `set var $AARCH64::$SME::$Tiles::$ZA2H_S.F32[0][0] = 99`. This may be abbreviated to `set $ZA2H_S.F32[0][0] = 99`.
84+
29. Single-step (press F5) to execute the `fmopa` instruction. Notice the values in ZA2H_S.F32[0] and ZA2V_S.F32[0] have updated.
85+
30. Run again and again to see the values changing. You can do the same for ZA0, ZA1, etc.
86+
31. The contents of the tile may also be viewed in the Commands view using the CLI, for example:
87+
To view the zeroth element of the zeroth row, enter `output $ZA2H_S.F32[0][0]`.
88+
To view all elements of the zeroth row, enter `output $ZA2H_S.F32[0]`.
89+
To view all elements of the zeroth column, enter `output $ZA2V_S.F32[0]`.
90+
To view the whole tile (as rows), enter `output $ZA2H_S.F32`.
91+
To view the whole tile (as columns), enter `output $ZA2V_S.F32`.
92+
Sequences of commands such as these may be easily scripted to construct groups of automated tests.
93+
32. Delete all breakpoints, then set a breakpoint on the first instruction (`st1w {za0h.s[w13, #0]}, p4, [x10]`) in `.Ktail_end` at line 176 and run to it (press F8). This instruction stores words from ZA0, from the row in w13 to memory at the address in x10.
94+
33. In the Commands view, enter `output /x $ZA0H_S.F32[$w13]` to show the w13th row of ZA0 in hexadecimal.
95+
34. In the Commands view, enter `x /16 $x10` to show the memory at x10, or open a Memory view and enter x10 in the starting address field.
96+
35. Single-step (press F5) to execute the st1w instruction.
97+
36. In the Commands view, enter `x /16 $x10` again to show the memory at x10. Notice in the Commands view or the Memory view that the memory has been loaded with the content of the w13th row of ZA0.
98+
37. Delete all breakpoints, then step-out of the function (press F7) back into main().
99+
38. To see the result matResult_opt, in the Memory view, enter the previously noted address from X5 in the address field.
100+
39. Continue running until the example completes normally.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: Introducing Scalable Matrix Extension (SME)
3+
weight: 2
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
The [Scalable Matrix Extension](https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/scalable-matrix-extension-armv9-a-architecture) (SME) is a system solution consisting of hardware components to efficiently process matrices.
10+
11+
SME introduces:
12+
* A register array storage ("ZA") capable of holding two-dimensional matrix tiles.
13+
* A Streaming SVE processing mode, which supports execution of SVE2 instructions with a vector length that matches the tile width.
14+
* Instructions that accumulate the outer product of two vectors into a tile.
15+
* Instructions that transfer a vector to or from a tile row or column.
16+
* System registers and fields that identify the presence and capabilities of SME, and enable and control its behavior at each Exception level.
17+
18+
The ZA storage is a two-dimensional array of width SVL bits, and height equal to its width in bytes, in other words, (SVL / 8) rows.
19+
SVL (the Effective Streaming SVE Vector Length) can be configured in software, and is a power of two in the range 128 to 2048 bits inclusive.
20+
21+
The ZA storage is accessed as tiles. A ZA tile is a square, two-dimensional sub-array of elements within the ZA array, whose elements must all be the same width, which can be 8-bit, 16-bit, 32-bit, 64-bit, or 128-bit.
22+
23+
The tile width is the same as the ZA storage width, which is always SVL bits. If N = SVL/8 then the ZA storage would be N rows x N bytes in size.
24+
When accessing the tile as 16-bit halfwords, it would only be N/2 halfwords wide. Since tiles are square, it would also be N/2 rows high, and therefore there is space in the ZA storage for two such tiles.
25+
26+
Similarly, when accessing 32-bit elements, tiles would have height and width both equal to N/4, so there would be four such tiles in the ZA storage. This trend continues so that there would be 16 tiles of element width 128-bits.
27+
28+
You can read or write a ZA tile slice, which is a one-dimensional vector representing a complete row or column within a tile slice.
29+
30+
![example image alt-text#center](ZA.png "Figure 1. The ZA storage, accessed by 32-bit elements, shown for SVL = 256 bits, and showing the mapping to horizontal and vertical slices of the four ZA0-3 tiles.")
31+
32+
The Scalable Matrix Extension version 2 (SME2) extends the SME architecture to increase the number of applications that can benefit from the computational efficiency of SME, beyond its initial focus on outer products and matrix-matrix multiplication. SME2 adds:
33+
* Data processing instructions with multi-vector operands and a multi-vector predication mechanism.
34+
* A Range Prefetch hint instruction.
35+
* Compressed neural network capability using dedicated lookup table instructions and outer product instructions that support binary neural networks.
36+
* A 512-bit architectural register, ZT0, to support the lookup table feature.
37+
38+
The new instructions enable SME2 to accelerate more workloads than the original SME, including GEMV, Non-Linear Solvers, Small and Sparse Matrices, and Feature Extraction or tracking.
39+
40+
SME is represented by the architectural feature FEAT_SME. FEAT_SME is an optional extension from Armv9.2-A.
41+
SME2 is represented by the architectural feature FEAT_SME2. FEAT_SME2 is an optional extension from Armv9.2-A. FEAT_SME2 requires FEAT_SME.

0 commit comments

Comments
 (0)