Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RISC-V] Fix alignment for vector types #99589

Merged
merged 6 commits into from
Mar 15, 2024
Merged

[RISC-V] Fix alignment for vector types #99589

merged 6 commits into from
Mar 15, 2024

Conversation

clamp03
Copy link
Member

@clamp03 clamp03 commented Mar 12, 2024

Fixed the error caused by alignment mismatch for vector256 and vector 512.

Assert failure(PID 2678722 [0x0028dfc2], Thread: 2678722 [0x28dfc2]): Verify_TypeLayout 'System.Runtime.Intrinsics.Vector256`1' failed to verify type layout
     File: /home/clamp/Work/dotnet/riscv/crossgen2/src/coreclr/vm/jitinterface.cpp:13839         
     Image: /riscv/crossgen2/artifacts/tests/coreclr/linux.riscv64.Checked/Tests/Core_Root/corerun
                                                                                                  
 Type System.Runtime.Intrinsics.Vector256`1: expected alignment 0x00000010, actual 0x00000020    

This sets alignment to possible max alignment value for vector types reference on https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc

Part of #84834
cc @dotnet/samsung

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 12, 2024
@clamp03 clamp03 added the arch-riscv Related to the RISC-V architecture label Mar 12, 2024
@clamp03 clamp03 self-assigned this Mar 12, 2024
@clamp03 clamp03 marked this pull request as ready for review March 14, 2024 01:10
else if (defType.Context.Target.Architecture == TargetArchitecture.RiscV64)
{
// The alignment requirement for the fixed length vector shall be equivalent to
// the alignment requirement of its elemental type.
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by "elemental type" in this comment?

Copy link
Member

Choose a reason for hiding this comment

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

I meant - could you please share the definition of "elemental type"? I do not think "elemental type" is defined anywhere in .NET. Is "elemental type" defined in the RISCV calling convention spec somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry. Actually, I haven't developed with vector. So I don't know well. This is just what I checked.
I read https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc document and update the comments.
In the doc, it mentions vector alignment twice.
The first is for fixed length vector and the second is vector types in RISC-V vector extension intrinsic document.
Initially, I wrote the comment from the fixed length vector. As I know, elemental type is type of elements of fixed length vector according to Various compilers have support for fixed-length vector types, for example GCC and Clang both support declaring a type with attributevector_size(N, where N is a positive number larger than zero in the document.

As I know, in RISC-V, max alignment is 16. So I need to update vector alignment within 16 to avoid the asserts before intrinsic is implemented. (Maybe we can start from next year.)

Copy link
Member

Choose a reason for hiding this comment

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

The fixed length vectors mentioned in the RISCV ABI spec should be mapped to InlineArray in .NET. They should not be mapped to System.Numerics.Vector... that VectorFieldLayoutAlgorithm.cs is concerned about.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the comment. The fixed length vectors are not for Vector.... I removed the comment.

@@ -10051,6 +10051,10 @@ void MethodTableBuilder::CheckForSystemTypes()
// The Procedure Call Standard for ARM 64-bit (with SVE support) defaults to
// 16-byte alignment for __m256.

pLayout->m_ManagedLargestAlignmentRequirementOfAllMembers = 16;
#elif defined(TARGET_RISCV64)
// The alignment requirement for the fixed length vector shall be equivalent to
Copy link
Member

Choose a reason for hiding this comment

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

Same fix should be applied to comments in this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks

@jkotas jkotas merged commit 7c33626 into dotnet:main Mar 15, 2024
171 of 179 checks passed
@clamp03
Copy link
Member Author

clamp03 commented Mar 15, 2024

Thank you!

Copy link
Member

@gbalykov gbalykov left a comment

Choose a reason for hiding this comment

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

LGTM

@clamp03 clamp03 deleted the cr2fix branch March 31, 2024 23:00
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-riscv Related to the RISC-V architecture area-crossgen2-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants