Skip to content

Add empty SVE API for Arm64#94791

Closed
a74nh wants to merge 4 commits intodotnet:mainfrom
a74nh:empty_api_github
Closed

Add empty SVE API for Arm64#94791
a74nh wants to merge 4 commits intodotnet:mainfrom
a74nh:empty_api_github

Conversation

@a74nh
Copy link
Contributor

@a74nh a74nh commented Nov 15, 2023

Adds empty System/Runtime/Intrinsics/Arm/Sve.cs and hwintrinsiclistarm64sve.h.
Plus all connecting code.
Many of the files touched here are autogenerated via InstructionSetDesc.txt.

@ghost ghost added community-contribution Indicates that the PR has been added by a community member area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI new-api-needs-documentation labels Nov 15, 2023
@ghost
Copy link

ghost commented Nov 15, 2023

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Nov 15, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

Adds empty System/Runtime/Intrinsics/Arm/Sve.cs and hwintrinsiclistarm64sve.h.
Plus all connecting code.
Many of the files touched here are autogenerated via InstructionSetDesc.txt.

Author: a74nh
Assignees: -
Labels:

area-CodeGen-coreclr, new-api-needs-documentation, community-contribution

Milestone: -

@a74nh
Copy link
Contributor Author

a74nh commented Nov 15, 2023

Extracted from #94765
Currently includes all of @kunalspathak's #94529

Not sure if the Arm64_Sve parts are required or if it should only be Sve. I think we want the readytorun/crossgen changes too (but it should be disabled for them?)

When run on a Arm64 Neoverse V1, the test program correctly outputs "SVE is supported."

@a74nh
Copy link
Contributor Author

a74nh commented Nov 15, 2023

@a74nh
Copy link
Contributor Author

a74nh commented Nov 15, 2023

Rebased off head as Kunal's work isn't dependant on this work.

Copy link
Contributor

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Early version looks good. Added some questions.

/// </summary>
[Intrinsic]
[CLSCompliant(false)]
public abstract class Sve : AdvSimd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is an example of APIs that goes in Sve vs. Sve.Arm64? I thought we wanted something like System.Runtime.Instrinsics.Arm.Sve and System.Runtime.Instrinsics.Arm.Sve2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general setup is that Isa exists to hold APIs that work on any arm platform

Isa.Arm32 exists to hold APIs that only work on Arm32
Isa.Arm64 exists to hold APIs that only work on Arm64 (we then have Isa.X64 for xarch)

SVE is interesting because there are many APIs that "could" work on Arm32, but there are currently no plans (based on a prior discussion on one of the proposals) to expose that support there.

This means Arm64 may be empty, but it must exist for usability reasons since Sve inherits from AdvSimd and otherwise Sve.Arm64.IsSupported would resolve to AdvSimd.Arm64.IsSupported and would lead users into a pit of failure, thinking it meant Sve.IsSupported would also be true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I didn't pay attention to : AdvSimd portion actually. I am wondering why Sve and Sve.Arm64 do not inherit from ArmBase and ArmBase.Arm64 respectively? I assume there will be a separate class for Sve2 next to Sve class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SVE inherits from AdvSimd because it requires AdvSimd support to exist and so it makes it overall more convenient for the user

AdvSimd then inherits from ArmBase itself

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense.

AddInstructionSet(InstructionSet_Sha1_Arm64);
if (HasInstructionSet(InstructionSet_Sha256))
AddInstructionSet(InstructionSet_Sha256_Arm64);
if (HasInstructionSet(InstructionSet_Sve))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, want to understand difference between InstructionSet_Sve vs. InstructionSet_Sve_Arm64 instead of InstructionSet_Sve and InstructionSet_Sve2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like this PR is adding Sve2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, what I was trying to get is that since we have generated boiler plate code for encodings, etc. of both SVE and SVE2 instructions and we should define SVE2 as well (instead of doing it in future PR).

Copy link
Member

@tannergooding tannergooding Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a ton of work to do and we should really focus on finishing SVE before we start on Sve2, IMO

We don’t want to be in a scenario where we leave Sve2 incomplete and half done because we didn’t have enough time for everything

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative suggestion: We should focus first on the the instructions that give extra functionality that are not in NEON and will be useful for the existing SDK libraries. That may include some SVE2 instructions. Doing that would ensure some performance uplift for .NET9.

On my TODO list is to rewrite some of the SDK routines in SVE and see if I can find any performance improvements. Then use that to prioritise the SVE work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would definitely be helpful to know what that list is.

Having an incomplete ISA is generally something we try to avoid as it can lead to issues when exposing APIs later, missed functionality, etc.


if (test.IsSupported)
{
Console.WriteLine("SVE is supported.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you verify on SVE hardware if the CPU flags are returned and set correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - both with and without:

Graviton 3:

❯ $CORE_ROOT/corerun /home/alahay01/dotnet/runtime_sve/artifacts/tests/coreclr/linux.arm64.Release/JIT/HardwareIntrinsics/Arm/Sve/Sve/Sve.dll
SVE is supported.

Altra:

❯ $CORE_ROOT/corerun /home/alahay01/dotnet/runtime_sve/artifacts/tests/coreclr/linux.arm64.Release/JIT/HardwareIntrinsics/Arm/Sve/Sve/Sve.dll
SVE is not supported.

@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Nov 15, 2023
@a74nh
Copy link
Contributor Author

a74nh commented Nov 15, 2023

2023-11-15T18:21:52.2206448Z /__w/1/s/src/native/minipal/cpufeatures.c:359:17: error: use of undeclared identifier 'HWCAP_SVE'

What OS and version are the builds run on? Surprised this does not exist.

@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Nov 15, 2023
Copy link
Member

@tannergooding tannergooding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but we can't merge until after API review has happened.

@tannergooding tannergooding added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Nov 15, 2023
@BruceForstall
Copy link
Contributor

What OS and version are the builds run on? Surprised this does not exist.

All .NET Linux builds are done inside a CBL-Mariner docker container. You can see the details if you look at the "Initializing containers" step of the build, e.g.: https://dev.azure.com/dnceng-public/public/_build/results?buildId=471209&view=logs&jobId=3f327aea-bfb2-5154-7b3c-2691dcdd6bb2&j=3f327aea-bfb2-5154-7b3c-2691dcdd6bb2&t=aa810107-5ca4-4707-8689-54adfbc0a8ea. In this case, it looks like the container is mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-cross-biarch-amd64-arm64.

@sbomer is the expert on these: @sbomer or @a74nh do you know why Mariner might be missing the HWCAP_SVE declaration?

@BruceForstall
Copy link
Contributor

BruceForstall commented Nov 15, 2023

Looks like maybe SVE support should have shown up in Linux kernels from 5.15 in around 2017? https://www.kernel.org/doc/html/v5.15/arm64/sve.html

(also, https://docs.kernel.org/next/arm64/elf_hwcaps.html)

@a74nh
Copy link
Contributor Author

a74nh commented Nov 16, 2023

Looks like maybe SVE support should have shown up in Linux kernels from 5.15 in around 2017? https://www.kernel.org/doc/html/v5.15/arm64/sve.html

(also, https://docs.kernel.org/next/arm64/elf_hwcaps.html)

Mariner is used for WSL. It's possible this has been disabled due to Windows not yet supporting SVE.

I'll add the following:

#ifndef HWCAP_SVE
#define HWCAP_SVE	(1 << 22)
#endif

That's safe as the kernel is never going to return that value on Mariner.

It's also what we did in gdb and also one of the utilities in the Linux kernel is doing is too.

@a74nh
Copy link
Contributor Author

a74nh commented Nov 16, 2023

LGTM, but we can't merge until after API review has happened.

To get this merged, we only need to get one piece of the API reviewed?

@kunalspathak
Copy link
Contributor

With InstructionSet changes in a separate PR #95021 , this PR just adds the empty hwintrinsiclistarm64sve.h then?

@a74nh
Copy link
Contributor Author

a74nh commented Nov 22, 2023

With InstructionSet changes in a separate PR #95021 , this PR just adds the empty hwintrinsiclistarm64sve.h then?

Done!

@a74nh
Copy link
Contributor Author

a74nh commented Nov 22, 2023

After discussion with @kunalspathak, this PR is mostly pointless now. Closing.

@a74nh a74nh closed this Nov 22, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants