Repository navigation
Closed as not planned
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Runtime.Intrinsics
Description
Background and motivation
This is a follow up on #109083.
This proposal adds the VPDPB[SU,UIU,SS]D[,S] to other already approved AVX10v2 API
Avx10.2 spec. Section10 in this spec goes over these intrinsics
API Proposal
namespace System.Runtime.Intrinsics.X86
{
/// <summary>Provides access to X86 AVX10.1 hardware instructions via intrinsics</summary>
[Intrinsic]
[CLSCompliant(false)]
public abstract class Avx10v2 : Avx10v1
{
// VPDPBSSD xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAdd(vector128<sbyte> left, Vector128<sbyte> right) => MultiplyWideningAndAdd(left, right,);
// VPDPBSUD xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAdd(vector128<sbyte> left, Vector128<byte> right) => MultiplyWideningAndAdd(left, right,);
// VPDPBUUD xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAdd(vector128<byte> left, Vector128<byte> right) => MultiplyWideningAndAdd(left, right);
// VPDPBSSD ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAdd(Vector256<sbyte> left, Vector256<sbyte> right) => MultiplyWideningAndAdd(left, right);
// VPDPBSUD ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAdd(Vector256<sbyte> left, Vector256<byte> right) => MultiplyWideningAndAdd(left, right);
// VPDPBUUD ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAdd(Vector256<byte> left, Vector256<byte> right) => MultiplyWideningAndAdd(left, right);
// VPDPBSSDS xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAddSaturate(vector128<sbyte> left, Vector128<sbyte> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPBSUDS xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAddSaturate(vector128<sbyte> left, Vector128<byte> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPBUUDS xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAddSaturate(vector128<byte> left, Vector128<byte> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPBSSDS ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAddSaturate(Vector256<sbyte> left, Vector256<sbyte> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPBSUDS ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAddSaturate(Vector256<sbyte> left, Vector256<byte> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPBUUDS ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAddSaturate(Vector256<byte> left, Vector256<byte> right) => MultiplyWideningAndAddSaturate(left, right, acc);
// VPDPWSUD xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAdd(vector128<short> left, Vector128<ushort> right) => MultiplyWideningAndAdd(left, right, acc);
// VPDPWUSD xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAdd(vector128<ushort> left, Vector128<short> right) => MultiplyWideningAndAdd(left, right);
// VPDPWUUD xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAdd(vector128<ushort> left, Vector128<ushort> right) => MultiplyWideningAndAdd(left, right);
// VPDPWSUD ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAdd(Vector256<short> left, Vector256<ushort> right) => MultiplyWideningAndAdd(left, right);
// VPDPWUSD ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAdd(Vector256<ushort> left, Vector256<short> right) => MultiplyWideningAndAdd(left, right);
// VPDPWUUD ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAdd(Vector256<ushort> left, Vector256<ushort> right) => MultiplyWideningAndAdd(left, right);
// VPDPWSUDS xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAddSaturate(vector128<short> left, Vector128<ushort> right) => MultiplyWideningAndAddSaturate(left, right, acc);
// VPDPWUSDS xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAddSaturate(vector128<ushort> left, Vector128<short> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPWUUDS xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector128<int> MultiplyWideningAndAddSaturate(vector128<ushort> left, Vector128<ushort> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPWSUDS ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAddSaturate(Vector256<short> left, Vector256<ushort> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPWUSDS ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAddSaturate(Vector256<ushort> left, Vector256<short> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPWUUDS ymm1{k1}{z}, ymm2, ymm3/m256/m32bcst
public static Vector256<int> MultiplyWideningAndAddSaturate(Vector256<ushort> left, Vector256<ushort> right) => MultiplyWideningAndAddSaturate(left, right);
[Intrinsic]
public abstract class V512 : Avx10v1.V512
{
// VPDPWSUD xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector512<int> MultiplyWideningAndAdd(Vector512<short> left, Vector512<ushort> right) => MultiplyWideningAndAdd(left, right);
// VPDPWUSD xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector512<int> MultiplyWideningAndAdd(Vector512<ushort> left, Vector512<short> right) => MultiplyWideningAndAdd(left, right);
// VPDPWUUD xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector512<int> MultiplyWideningAndAdd(Vector512<ushort> left, Vector512<ushort> right) => MultiplyWideningAndAdd(left, right);
// VPDPWSUDS xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector512<int> MultiplyWideningAndAddSaturate(Vector512<short> left, Vector512<short> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPWUSDS xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector512<int> MultiplyWideningAndAddSaturate(Vector512<short> left, Vector512<ushort> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPWUUDS xmm1{k1}{z}, xmm2, xmm3/m128/m32bcst
public static Vector512<int> MultiplyWideningAndAddSaturate(Vector512<ushort> left, Vector512<ushort> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPBSSD zmm1{k1}{z}, zmm2, zmm3/m512/m32bcst
public static Vector512<int> MultiplyWideningAndAdd(Vector512<sbyte> left, Vector512<sbyte> right) => MultiplyWideningAndAdd(left, right);
// VPDPBSUD zmm1{k1}{z}, zmm2, zmm3/m512/m32bcst
public static Vector512<int> MultiplyWideningAndAdd(Vector512<sbyte> left, Vector512<byte> right) => MultiplyWideningAndAdd(left, right);
// VPDPBUUD zmm1{k1}{z}, zmm2, zmm3/m512/m32bcst
public static Vector512<int> MultiplyWideningAndAdd(Vector512<byte> left, Vector512<byte> right) => MultiplyWideningAndAdd(left, right);
// VPDPBSSDS zmm1{k1}{z}, zmm2, zmm3/m512/m32bcst
public static Vector512<int> MultiplyWideningAndAddSaturate(Vector512<sbyte> left, Vector512<sbyte> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPBSUDS zmm1{k1}{z}, zmm2, zmm3/m512/m32bcst
public static Vector512<int> MultiplyWideningAndAddSaturate(Vector512<sbyte> left, Vector512<byte> right) => MultiplyWideningAndAddSaturate(left, right);
// VPDPBUUDS zmm1{k1}{z}, zmm2, zmm3/m512/m32bcst
public static Vector512<int> MultiplyWideningAndAddSaturate(Vector512<byte> left, Vector512<byte> right) => MultiplyWideningAndAddSaturate(left, right);
}
}
}API Usage
// Fancy the value
Vector128<byte> v1 = Vector512.Create((byte)someParam1);
Vector128<byte> v2 = Vector512.Create((byte)someParam2);
if (Avx10v2.IsSupported()) {
Vector128<int> v3 = Avx10v2.MultiplyWideningAndAdd(v1, v2, 0b00000000);
// etc
}Alternative Designs
No response
Risks
No response
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Runtime.Intrinsics
Activity
dotnet-policy-service commentedon Nov 20, 2024
Tagging subscribers to this area: @dotnet/area-system-runtime-intrinsics
See info in area-owners.md if you want to be subscribed.
khushal1996 commentedon Nov 23, 2024
I will also like to discuss the following API again here. @tannergooding @DeepakRajendrakumaran
and would like to change them to
saucecontrol commentedon Dec 8, 2024
These dot product instructions are also exposed independent of AVX10.2 under AVX-VNNI-INT8 (vpdpb*) and AVX-VNNI-INT16 (vpdpw*), both of which are present in Lunar Lake, Arrow Lake, and Sierra Forest. Should they be exposed under those ISAs with light-up for future AVX10.2 instead?
jeffhandley commentedon Jan 16, 2025
Assigned to @tannergooding for triage. (I assume this is 10.0.0, but want to be sure).
tannergooding commentedon Jan 23, 2025
Probably, for consistency with how we expose other ISAs.
CC. @khushal1996 for input.
khushal1996 commentedon Jan 24, 2025
@saucecontrol can you explain your comment in more detail? So do you mean the same set of dot product instructions are available on AVX-VNNI_INT8/16 or that these are similar?
What are you suggesting?
Note: the new dot product instructions in AVX10.2 are different from what has been introduced in AVX-VNNI. AVx-vnni has
VPDPWSSD
VPDPWSSDS
Where as Avx10.2 introduces the new remaining instructions VPDPB[SU,UIU,SS]D[,S]
saucecontrol commentedon Jan 25, 2025
AVX-VNNI-INT8 and AVX-VNNI-INT16 are new ISAs, starting with Lunar Lake. They cover the same DP instructions as AVX10.2. From the Oct 2024 SDM 5-500, for example:
saucecontrol commentedon Jan 25, 2025
It wouldn't make sense to duplicate those between
Avx10v2andAvxVnniInt16managed classes, so they should be included under the dedicated ISA and then work if either AVX-VNNI-INT16 or AVX10.2 is present.I would propose
And
(edited to fix typos and omissions in the top post)
Base class should probably be
Avx2. I can't imagine these existing without the original AVX-VNNI (they fill in gaps left in the original ISA), but they are technically independent flags, so we should probably model that way.On the other hand, making the base class
AvxVnniwould help with discoverability, since e.g.AvxVnniInt16.MultiplyWideningAndAddwould show all 4 int16 overloads (SS, SU, US, UU) together.anthonycanino commentedon Jan 29, 2025
Hi all,
We are ok with separating the duplicated APIs out into their own class, with
Avx2as the base class. So long as the following code works without triggering any kind of compiler warning.We are currently working on getting the proposal together.
tannergooding commentedon Jan 29, 2025
This matches what I would expect to work/be safe. The main consideration @saucecontrol was raising is that we don't want to block use of these instructions on hardware they are supported.
We may want to consider duplicating the API surface, as we did for some APIs on AVX10v1.V512 since the inheritance hierarchy couldn't inherit from all of
Avx512BW/CD/DQ, for discoverability. But we can document the relationship/guarantee otherwise.anthonycanino commentedon Feb 10, 2025
One thing to note as we are finishing up our internal proposal:
The 512-bit registers are not present for
AVX-VNNI-INT{8,16}so I think it looks a little odd to have aV512class inAVX-VNNI-INT{8,16}.Perhaps its worth to lift those into
Avx10v2.V512, as they are not duplicated amongAVX-VNNI-INT{8,16}and then we can leave the remaining underAVX-VNNI-INT{8,16}but make sure they light up withAvx10v2?saucecontrol commentedon Feb 10, 2025
V512being its own nested class means that it gets its ownIsSupportedimplementation, which means it can check additional cpuid bits (in this case AVX10v2/512).This would be similar to the way VPCLMULQDQ was modeled, where the base ISA gives 128-bit support but AVX-512 or AVX10v1/512 is required in addition to VPCLMULQDQ to light up the nested
V512class.anthonycanino commentedon Feb 11, 2025
Understood. I was commenting that I think the API surface looks a little odd to reach to
AvxVnniInt8.V512instead ofAvx10v2.V512, but I see that there is precedent withVPCLMULQDQ.We will formalize this proposal and we can mention both as an alternative design, but I am generally on board with either.
anthonycanino commentedon Feb 13, 2025
@tannergooding should we close this issue and open a new one for AvxVnniInt8 and AvxVnniInt16?
tannergooding commentedon Jul 6, 2025
This has been replaced by #112586, closing in favor of it