Repository: spack/spack

Issue:
ARM compilers do not generate SVE code on a64fx
The default behavior of ARM compilers (I tested 20.3 and the latest 21.0) is **not** to generate SVE code, even on A64fx platforms. The `-march=armv8.2a+sve` flag is required in order to generate SVE code.

This is arguably an ARM bug/feature, and a manual workaround is to
```
export SPACK_CFLAGS=-march=armv8.2a+sve
```
and friends.


That being said, I believe spack can improve this and automatically set this flag (unless the `-march` flag is already set by the user/recipe) when building on a SVE capable platform such as `a64fx`.

I guess a first step would be to have spack
`export SPACK_ARCH=$(spack arch)`
or something similar, and enhance the spack compiler wrappers to set the `-march` flag when needed.


Discussion:
@ggouaillardet Are you reporting behavior about `armclang`, `armclang++` and `armflang`? In case, can you double check that the flag you suggest works with all 3 compilers?
The solution here is to add optimization flags to `archspec` so that the library also supports the ARM compilers.
@alalazo I confirm `-march=armv8.2a+sve` works for the three compilers `armclang`, `armclang++` and `armflang`
Thanks for the hint!

I tried this:
```patch
diff --git a/lib/spack/external/archspec/json/cpu/microarchitectures.json b/lib/spack/external/archspec/json/cpu/microarchitectures.json
index 0eacadfbaa..d56e83d770 100644
--- a/lib/spack/external/archspec/json/cpu/microarchitectures.json
+++ b/lib/spack/external/archspec/json/cpu/microarchitectures.json
@@ -1828,6 +1828,12 @@
             "versions": "5:",
             "flags": "-march=armv8.2-a+crc+crypto+fp16+sve"
           }
+        ],
+        "arm": [
+          {
+            "versions": "20:",
+            "flags": "-march=armv8.2-a+crc+crypto+fp16"
+          }
         ]
       }
     },
```

but it did not help (`-march=...` is **not** passed to `armclang` when using `arm@20.3.0.543`.
Did I miss something?
Just to be sure (apologies, I don't have an `armclang` to try myself) how did you verify if the flag was passed or not?
No problem, I used `strace` to confirm the flags was not passed to the `armclang` spack wrapper, nor the "real" `armclang` compiler.
Also, my test failed since it `#include <arm_sve.h>`, and can only work if `-march=armv8...+sve` is passed
Can you post the part of your compilers.yaml where you have the arm compilers registered? I'll try to use that to see if I can "fake" the behavior.
Sure, here it is

```
compilers:
- compiler:
    spec: arm@20.3.0.543
    paths:
      cc: /opt/arm/arm-linux-compiler-20.3_Generic-AArch64_RHEL-8_aarch64-linux/bin/armclang
      cxx: /opt/arm/arm-linux-compiler-20.3_Generic-AArch64_RHEL-8_aarch64-linux/bin/armclang++
      f77: /opt/arm/arm-linux-compiler-20.3_Generic-AArch64_RHEL-8_aarch64-linux/bin/armflang
      fc: /opt/arm/arm-linux-compiler-20.3_Generic-AArch64_RHEL-8_aarch64-linux/bin/armflang
    flags: {}
    operating_system: rhel8
    target: aarch64
    modules: []
    environment: {}
    extra_rpaths: []
```

fwiw, here is my recipe
```
import llnl.util.cpu


class TestArmSve(CMakePackage):
    """Test including the <arm_sve.h> header file"""

    homepage = 'https://github.com/ggouaillardet/test-arm_sve'
    url      = 'https://github.com/ggouaillardet/test-arm_sve/archive/v0.1.tar.gz'
    git      = 'https://github.com/ggouaillardet/test-arm_sve.git'
    maintainers = ['ggouaillardet']


    version('0.1', sha256='65ff94bc68823170e6ccb1ff8d44ff169497bbfe30eccddcb379b546e39930d2')
    depends_on('cmake@3.13.0:3.99.99', type='build')
    depends_on('blas')
```

@ggouaillardet Can you also try adding `arm` as a valid compiler for `aarch64` without version constraints and with a generic flag? I think that + your diff above should work.
Thanks, that did the trick!

Shall I issue a PR?

fwiw, here are my changes


```patch
diff --git a/lib/spack/external/archspec/json/cpu/microarchitectures.json b/lib/spack/external/archspec/json/cpu/microarchitectures.json
index 0eacadfbaa..e34bf9e179 100644
--- a/lib/spack/external/archspec/json/cpu/microarchitectures.json
+++ b/lib/spack/external/archspec/json/cpu/microarchitectures.json
@@ -1725,6 +1725,12 @@
             "versions": ":",
             "flags": "-march=armv8-a -mtune=generic"
           }
+        ],
+        "arm": [
+          {
+            "versions": ":",
+            "flags": "-march=armv8-a -mtune=generic"
+          }
         ]
       }
     },
@@ -1828,6 +1834,12 @@
             "versions": "5:",
             "flags": "-march=armv8.2-a+crc+crypto+fp16+sve"
           }
+        ],
+        "arm": [
+          {
+            "versions": "20:",
+            "flags": "-march=armv8.2-a+crc+crypto+fp16+sve"
+          }
         ]
       }
     },
```

> Shall I issue a PR?

Can you submit a PR against the JSON file in this repository https://github.com/archspec/archspec-json ?
To explain further, `archspec` originated from Spack but is now a standalone package. When we fix issues like this one we usually contribute the change upstream and then update the version of `archspec` we vendor in Spack.
I just issued the PR archspec/archspec-json#33

Can we extend support for the `apollo80 `system? 

```
>$spack arch

cray-centos8-aarch64
```

Seems like ``armclang`` doesn't pick up `sve` here.


Resolving patch:
diff --git a/lib/spack/external/__init__.py b/lib/spack/external/__init__.py
--- a/lib/spack/external/__init__.py
+++ b/lib/spack/external/__init__.py
@@ -11,7 +11,7 @@
 
 * Homepage: https://pypi.python.org/pypi/archspec
 * Usage: Labeling, comparison and detection of microarchitectures
-* Version: 0.1.2 (commit 130607c373fd88cd3c43da94c0d3afd3a44084b0)
+* Version: 0.1.2 (commit 26dec9d47e509daf8c970de4c89da200da52ad20)
 
 argparse
 --------


Test patch: