|
| 1 | +--- |
| 2 | +title: Test your environment |
| 3 | +weight: 4 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | +In this section, you will check that your environment is all set up and ready to develop with SME2. This will be your first hands-on experience with the environment. |
| 10 | + |
| 11 | +## Compile the examples |
| 12 | + |
| 13 | +First, compile the example code with Clang: |
| 14 | + |
| 15 | +```BASH { output_lines="2-19" } |
| 16 | +docker run --rm -v "$PWD:/work" -w /work armswdev/sme2-learning-path:sme2-environment-v1 make |
| 17 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -nostartfiles -lcrt0-semihost -lsemihost -Wl,--defsym=__boot_flash=0x80000000 -Wl,--defsym=__flash=0x80001000 -Wl,--defsym=__ram=0x81000000 -T picolibc.ld -o hello hello.c |
| 18 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -c -o sme2_check.o sme2_check.c |
| 19 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -c -o misc.o misc.c |
| 20 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -nostartfiles -lcrt0-semihost -lsemihost -Wl,--defsym=__boot_flash=0x80000000 -Wl,--defsym=__flash=0x80001000 -Wl,--defsym=__ram=0x81000000 -T picolibc.ld -o sme2_check sme2_check.o misc.o |
| 21 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -DIMPL=asm -c -o main_asm.o main.c |
| 22 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -c -o matmul_asm.o matmul_asm.c |
| 23 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -c -o matmul_asm_impl.o matmul_asm_impl.S |
| 24 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -c -o preprocess_l_asm.o preprocess_l_asm.S |
| 25 | +clang --target=aarch64-none-elf -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -c -o matmul_vanilla.o matmul_vanilla.c |
| 26 | +clang --target=aarch64-none-elf -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -c -o preprocess_vanilla.o preprocess_vanilla.c |
| 27 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -nostartfiles -lcrt0-semihost -lsemihost -Wl,--defsym=__boot_flash=0x80000000 -Wl,--defsym=__flash=0x80001000 -Wl,--defsym=__ram=0x81000000 -T picolibc.ld -o sme2_matmul_asm main_asm.o matmul_asm.o matmul_asm_impl.o preprocess_l_asm.o matmul_vanilla.o preprocess_vanilla.o misc.o |
| 28 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -DIMPL=intr -c -o main_intr.o main.c |
| 29 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -c -o matmul_intr.o matmul_intr.c |
| 30 | +clang --target=aarch64-none-elf -march=armv9.4-a+sme2 -fno-exceptions -fno-rtti -mno-unaligned-access -O2 -Wall -std=c99 -nostartfiles -lcrt0-semihost -lsemihost -Wl,--defsym=__boot_flash=0x80000000 -Wl,--defsym=__flash=0x80001000 -Wl,--defsym=__ram=0x81000000 -T picolibc.ld -o sme2_matmul_intr main_intr.o matmul_intr.o matmul_vanilla.o preprocess_vanilla.o misc.o |
| 31 | +llvm-objdump --demangle -d hello > hello.lst |
| 32 | +llvm-objdump --demangle -d sme2_check > sme2_check.lst |
| 33 | +llvm-objdump --demangle -d sme2_matmul_asm > sme2_matmul_asm.lst |
| 34 | +llvm-objdump --demangle -d sme2_matmul_intr > sme2_matmul_intr.lst |
| 35 | +``` |
| 36 | + |
| 37 | + Executed within the docker ``armswdev/sme2-learning-path:sme2-environment-v1`` environment, the ``make`` command performs the following tasks: |
| 38 | + |
| 39 | +- It builds four executables: ``hello``, ``sme2_check``, ``sme2_matmul_asm``, and ``sme2_matmul_intr``. |
| 40 | +- It creates the assembly listings for the four executables: ``hello.lst``, ``sme2_check.lst``, ``sme2_matmul_asm.lst``, and ``sme2_matmul_intr.lst``. |
| 41 | + |
| 42 | +{{% notice Note %}} |
| 43 | +At any point, you can clean the directory of all the files that have been built by invoking the ``make clean`` target: |
| 44 | + |
| 45 | +```BASH |
| 46 | +$ docker run --rm -v "$PWD:/work" -w /work armswdev/sme2-learning-path:sme2-environment-v1 make clean |
| 47 | +``` |
| 48 | +{{% /notice %}} |
| 49 | + |
| 50 | +## Basic checks |
| 51 | + |
| 52 | +The very first program that you should run is the famous "Hello, world !" example that |
| 53 | +will tell you if your environment is set up correctly. |
| 54 | + |
| 55 | +The source code is contained in ``hello.c`` and looks like this: |
| 56 | + |
| 57 | +```C |
| 58 | +#include <stdio.h> |
| 59 | +#include <stdlib.h> |
| 60 | + |
| 61 | +int main(int argc, char *argv[]) { |
| 62 | + printf("Hello, world !\n"); |
| 63 | + return EXIT_SUCCESS; |
| 64 | +} |
| 65 | +``` |
| 66 | +
|
| 67 | +Run the FVP simulation of the ``hello`` program with: |
| 68 | +
|
| 69 | +```BASH { output_lines="2-4" } |
| 70 | +docker run --rm -v "$PWD:/work" -w /work armswdev/sme2-learning-path:sme2-environment-v1 ./run-fvp.sh hello |
| 71 | +Hello, world ! |
| 72 | +
|
| 73 | +Info: /OSCI/SystemC: Simulation stopped by user. |
| 74 | +``` |
| 75 | + |
| 76 | +The important line here is "``Hello, world !``" as it demonstrates that the generic code |
| 77 | +can be compiled and run on the FVP. |
| 78 | + |
| 79 | +## SME2 checks |
| 80 | + |
| 81 | +You will now run the ``sme2_check`` program, which checks that SME2 works as |
| 82 | +expected, in both the compiler and in the FVP. |
| 83 | + |
| 84 | +The source code is found in |
| 85 | +``sme2_check.c``: |
| 86 | + |
| 87 | +```C |
| 88 | +#include <stdio.h> |
| 89 | +#include <stdlib.h> |
| 90 | + |
| 91 | +#include "misc.h" |
| 92 | + |
| 93 | +#ifdef __ARM_FEATURE_SME2 |
| 94 | +#include <arm_sme.h> |
| 95 | +#else |
| 96 | +#error __ARM_FEATURE_SME2 is not defined |
| 97 | +#endif |
| 98 | + |
| 99 | +#define get_cpu_ftr(regId, feat, msb, lsb) \ |
| 100 | + ({ \ |
| 101 | + unsigned long __val; \ |
| 102 | + __asm__("mrs %0, " #regId : "=r"(__val)); \ |
| 103 | + printf("%-20s: 0x%016lx\n", #regId, __val); \ |
| 104 | + printf(" - %-10s: 0x%08lx\n", #feat, \ |
| 105 | + (__val >> lsb) & ((1 << (msb - lsb)) - 1)); \ |
| 106 | + }) |
| 107 | + |
| 108 | +int main(int argc, char *argv[]) { |
| 109 | + get_cpu_ftr(ID_AA64PFR0_EL1, SVE, 35, 32); |
| 110 | + get_cpu_ftr(ID_AA64PFR1_EL1, SME, 27, 24); |
| 111 | + |
| 112 | + int n = 0; |
| 113 | +#ifdef __ARM_FEATURE_SME2 |
| 114 | + setup_sme(); |
| 115 | + n = svcntb() * 8; |
| 116 | +#endif |
| 117 | + if (n) { |
| 118 | + printf("SVE is available with length %d\n", n); |
| 119 | + } else { |
| 120 | + printf("SVE is unavailable.\n"); |
| 121 | + exit(EXIT_FAILURE); |
| 122 | + } |
| 123 | + |
| 124 | + printf("Checking has_sme: %d\n", __arm_has_sme()); |
| 125 | + printf("Checking in_streaming_mode: %d\n", __arm_in_streaming_mode()); |
| 126 | + |
| 127 | + printf("Starting streaming mode...\n"); |
| 128 | + __asm__("smstart"); |
| 129 | + |
| 130 | + printf("Checking in_streaming_mode: %d\n", __arm_in_streaming_mode()); |
| 131 | + |
| 132 | + printf("Stopping streaming mode...\n"); |
| 133 | + __asm__("smstop"); |
| 134 | + |
| 135 | + printf("Checking in_streaming_mode: %d\n", __arm_in_streaming_mode()); |
| 136 | + |
| 137 | + return EXIT_SUCCESS; |
| 138 | +} |
| 139 | +``` |
| 140 | + |
| 141 | +The ``sme2_check`` program displays the SVE field of the ``ID_AA64PFR0_EL1`` system register and the SME field of the ``ID_AA64PFR1_EL1`` system register. It will then check if SVE and SME are available, then finally will switch into streaming mode and back from streaming mode. |
| 142 | + |
| 143 | +The ``__ARM_FEATURE_SME2`` macro is provided by the compiler when it targets an SME-capable target, which is specified with the ``-march=armv9.4-a+sme2`` command line option to ``clang`` in |
| 144 | +file ``Makefile``. |
| 145 | + |
| 146 | +The ``arm_sme.h`` include file is part of the Arm C Library |
| 147 | +Extension ([ACLE](https://arm-software.github.io/acle/main/)). |
| 148 | + |
| 149 | +The ACLE provides types and function declarations to enable C/C++ programmers to make the best possible use of the Arm architecture. You can use the SME-related part of the library, but it does also provide support for Neon or other Arm architectural extensions. |
| 150 | + |
| 151 | +```BASH |
| 152 | +docker run --rm -v "$PWD:/work" -w /work armswdev/sme2-learning-path:sme2-environment-v1 ./run-fvp.sh sme2_check |
| 153 | +``` |
| 154 | + |
| 155 | +The output should be similar to: |
| 156 | + |
| 157 | +```TXT |
| 158 | +ID_AA64PFR0_EL1 : 0x1101101131111112 |
| 159 | + - SVE : 0x00000001 |
| 160 | +ID_AA64PFR1_EL1 : 0x0000101002000001 |
| 161 | + - SME : 0x00000002 |
| 162 | +SVE is available with length 512 |
| 163 | +Checking has_sme: 1 |
| 164 | +Checking in_streaming_mode: 0 |
| 165 | +Starting streaming mode... |
| 166 | +Checking in_streaming_mode: 1 |
| 167 | +Stopping streaming mode... |
| 168 | +Checking in_streaming_mode: 0 |
| 169 | +
|
| 170 | +Info: /OSCI/SystemC: Simulation stopped by user. |
| 171 | +``` |
| 172 | + |
| 173 | +You have now checked that the code can be compiled and run with full SME2 support, and are all set to move to the next section. |
0 commit comments