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

[NO REVIEW] Update the CPUID and XSAVE logics for APX #103019

Closed
wants to merge 13 commits into from

Conversation

Ruihan-Yin
Copy link
Contributor

@Ruihan-Yin Ruihan-Yin commented Jun 4, 2024

[No need to review this PR for now]

Overview on the changes:

  1. Infrastructural changes on XArchIntrinsicConstants: Compress all the Avx512 related flags into 1 - Avx512f+bw+cd+dq+vl to Avx512, this saves more space in XArchIntrinsicConstants so that we can hold more x86 ISAs, like here, APX.
  1. CPUID check updates for APX: CR4[XSAVE](existing) -> XCR0[APX_F] -> CPUID(7,1).EDX[APX_F] - the current status is that due to the missing macro definition for APX on the OS level, the second check will fail anyways, and it may break the build on CI (to be verified).
  2. APX introduced 16 EGPRs, which are XSTATE enabled, this PR provides the corresponding changes for XSAVE behaviors.

anthonycanino and others added 5 commits June 3, 2024 16:26
Update the asm code in context2.S
hard coded the memory offset with an assumption that we are using standrad form

Seems the logic in context2.S is for custom stack, we may not need to follow the standard XSAVE buffer layout. Directly adding the APX section after AVX512.

Updates in threadsuspend.cpp

script-gen changes

Extending CPUID flag from int to long to hold more ISAs.

Update the cpuid check logic, make sure CR4.OSXSAVE and XCR0.APX_F are checked.

resolve comments

improve the logics in isa_detection in gc.

add missing method definitions under unix context.

code clean up
2. merge Avx512F, BW, CD, DQ to a converged ISA flag, Avx512.
3. introduce APX cpuid detection.
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 4, 2024
@Ruihan-Yin Ruihan-Yin marked this pull request as draft June 4, 2024 01:13
@tannergooding tannergooding added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Jun 4, 2024
@tannergooding
Copy link
Member

I've gone ahead and marked this as NO-MERGE for now. If it is ready for merge prior to main opening for .NET 10 changes, we would want to go through some additional considerations as to the impact it would have on .NET 9 and whether or not we want it excluded from the .NET 9 build such as via an #if defined(FEATURE_APX) flag.

@Ruihan-Yin
Copy link
Contributor Author

I've gone ahead and marked this as NO-MERGE for now. If it is ready for merge prior to main opening for .NET 10 changes, we would want to go through some additional considerations as to the impact it would have on .NET 9 and whether or not we want it excluded from the .NET 9 build such as via an #if defined(FEATURE_APX) flag.

Yes, please mark it as NO-MERGE, thanks.

Comment on lines 1 to 3
# APX Integration in .NET

Let's keep documentation on APX integration and notes on things here. I will evolve this as necessary.
Copy link
Member

Choose a reason for hiding this comment

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

We should move this under docs/design/features/xarch-apx.md or maybe under docs/design/coreclr/jit/xarch-apx.md, just to keep it in the same general place as our other docs.

I like the idea of having a documentation covering how the feature is used and integrates with the rest of the JIT.

public const int Avx10v1 = 0x4000000;
public const int Avx10v1_v256 = 0x8000000;
public const int Avx10v1_v512 = 0x10000000;
public const int Avx512 = 0x8000;
Copy link
Member

Choose a reason for hiding this comment

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

If you would like to make these bits more compact, it would be better to submit it as separate PR. There are free bits now so you do not need it to add the Apx bit.

It may be better to avoid folding the features together at the PAL level:

            public const int Avx512f = ...;
            public const int Avx512f_vl = ...;
            public const int Avx512bw = ...;
            public const int Avx512cd = ...;
            public const int Avx512dq = ...;
            public const int Avx512Vbmi = ...;

I understand that it does not save as many bits, but it is cleaner (avoids applying JIT policy at the PAL level).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the inputs, I can work on this part soon


if (__builtin_cpu_supports("avx2"))
{
IsaFlags |= (int)SupportedISA::APX;
Copy link
Member

Choose a reason for hiding this comment

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

It is not necessary to detect APX here until the APX-specific implementation of the GC sort gets added.

Comment on lines +387 to +389
// TODO-xarch-apx: the definition of XSTATE mask value for APX is now missing on the OS level,
// we are currently using bare value to hack it through the build process, and test the implementation through CI.
// those changes will be removed when we have the OS support for APX.
Copy link
Member

Choose a reason for hiding this comment

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

Why not do this via the following so that things can still function as expected, even if built on a downlevel OS without the support?

#ifndef XSTATE_APX
#define XSTATE_APX 19
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this way locally on my own dev machine with Windows OS, the build will fail with error report saying the macros are not defined, and it seems that, at least on Windows, XSTATE_APX and XSTATE_MASK_APX shall be defined in winnt.h (I am not 100% sure about the reason, is it because we are using Windows API in the CPUID checks?), I can fix the error by adding the definition there, but it might not be the solution in CI environment.

InstructionSet_AVX10v1_X64=68,
InstructionSet_AVX10v1_V256_X64=69,
InstructionSet_AVX10v1_V512_X64=70,
InstructionSet_APX=36,
Copy link
Member

Choose a reason for hiding this comment

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

Does APX support 32bit at all?

Intel®Advanced Performance Extensions (Intel® APX) expands the Intel® 64 instruction set

or is everything just generated with both x86 and x64?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for bringing this up,

No, APX features is available only under 64-bit mode
Reference: https://www.intel.com/content/www/us/en/content-details/819797/intel-advanced-performance-extensions-intel-apx-architecture-specification.html

3.1.4 Intel® APX features are only available in IA-32e 64-bit Protected Mode, and are an XSAVE-enabled feature
which requires XCR0 enabling before using the new Intel® APX ISA, new Intel® APX prefixes (REX2) and
prefix extensions (EVEX extensions). See section 3.1.4.2 for details on XCR0-enabling for Intel® APX

Based on this fact, I understand APX could be different from existing ISAs and we are open to take suggestions on this part.

Copy link
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@Ruihan-Yin
Copy link
Contributor Author

Hi @tannergooding

Since the XArchIntrinsicConstant has been updated, I will start to work on this PR again, can we reopen this PR? Thanks!

@tannergooding
Copy link
Member

I will start to work on this PR again, can we reopen this PR? Thanks!

GitHub blocks it being reopened due to the branch having been force-pushed or recreated since the time the PR was closed
image

@Ruihan-Yin
Copy link
Contributor Author

I will start to work on this PR again, can we reopen this PR? Thanks!

GitHub blocks it being reopened due to the branch having been force-pushed or recreated since the time the PR was closed image

I updated my branch beforehand, my bad, I will create another draft PR.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2024
@BruceForstall BruceForstall added the apx Related to the Intel Advanced Performance Extensions (APX) label Sep 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
apx Related to the Intel Advanced Performance Extensions (APX) area-PAL-coreclr community-contribution Indicates that the PR has been added by a community member 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.

6 participants