Skip to content

Post-2.1 plan of Intel hardware intrinsic #10260

Closed

Description

@fiigii
  1. Refine the API design of Intel hardware intrinsic
  2. Implement remaining AVX2 intrinsic [rely on (1)]
  3. Implement remaining SSE4.2 intrinsic [rely on (1)]
  4. Enable containment analysis on more hardware intrinsic forms (e.g., imm, 1-arg, 3-arg, etc.)
  5. Implement FMA intrinsic [rely on (4)]
    • FMA intrinsic codegen is different from other ISAs whose instruction selection depends on the operator's position (e.g., in registers or memory?)
  6. Implement other ISA classes (Bmi1, Bmi2, Aes, and Pclmulqdq)
    • fully support all the Intel hardware intrinsic of existing APIs
  7. Create non-trivial benchmarks for Intel hardware intrinsic
  8. Improve the CQ of Intel hardware intrinsic base-on key scenarios [partially rely on (7)]
  9. Investigate the JIT throughput impact from hardware intrinsic recognition [rely on (7)]
  10. Identify candidates that can be optimized using HW intrinsics and implement them using intrinsics (CoreFX, mscorlib, HPC, ML, etc.)
  11. more...

category:cq
theme:intrinsics
skill-level:intermediate
cost:extra-large

Activity

  1. fiigii commented on Apr 27, 2018

    @fiigii
    ContributorAuthor

    cc @CarolEidt @AndyAyersMS @jkotas @tannergooding @mikedn @redknightlois

    Please feel free to improve the above list.

  2. AndyAyersMS commented on Apr 30, 2018

    @AndyAyersMS
    Member

    The goal should be to have HW intrinsics be in shape to be fully supported.

    Seems like the overall priorities are good:

    • finish off current implementations
    • get mileage on the existing APIs to evaluate usability
    • start looking at CQ, especially when intrinsics are used in combination or with things like Vectors, and identify areas that need work.

    IIRC there were some not fully resolved design aspects; they should be on the list too.

  3. redknightlois commented on Apr 30, 2018

    @redknightlois

    There are a few pain points in the interface to deal with HW intrinsics, mostly on the StaticCast<T> front that probably could be handled through library implicit conversions and overloads.

  4. fiigii commented on Apr 30, 2018

    @fiigii
    ContributorAuthor

    @AndyAyersMS Thank you so much for the suggestions, updated the list.

  5. fiigii commented on Apr 30, 2018

    @fiigii
    ContributorAuthor

    mostly on the StaticCast front that probably could be handled through library implicit conversions and overloads.

    Good point. But I am afraid and not sure that "implicit conversions" may confuse the front-end compiler (Roslyn) and IDE to determine which overload users actually want.
    Moveover, StaticCast<T, U> is important to let HW intrinsic work with generic code (i.e., StaticCast<T, float>(Sse.Add(...)) to return a generic Vector128<T>). Does implicit conversion help to this case?

  6. redknightlois commented on Apr 30, 2018

    @redknightlois

    They will have to be done with care, that is either implicit and/or overloads could be the way to go. Currently StaticCast<T,U> clutters the code a bit too much. There must be some non-obvious compromise that could work.

  7. CarolEidt commented on May 1, 2018

    @CarolEidt
    Contributor

    Although the first item captures the broad issue of API design and usability, it would be worth calling out that, beyond getting CQ data, we also want to use scenarios to drive usability. @redknightlois points out one concern, but we should also seek usability feedback more broadly.

  8. tannergooding commented on May 23, 2018

    @tannergooding
    Member

    The PR adding support for the x86 FMA intrinsics is up: dotnet/coreclr#18105

  9. 4creators commented on May 24, 2018

    @4creators
    Contributor

    They will have to be done with care, that is either implicit and/or overloads could be the way to go. Currently StaticCast<T,U> clutters the code a bit too much. There must be some non-obvious compromise that could work.

    One of the proposals to handle this is in https://github.com/dotnet/corefx/issues/27911#issuecomment-372684004

    There are many other possible solutions which could be based on VectorNNN<T> as well.

  10. 4creators commented on May 24, 2018

    @4creators
    Contributor

    @fiigii @tannergooding Whis ISA I could start working on now as I have some free cycles?

  11. fiigii commented on May 24, 2018

    @fiigii
    ContributorAuthor

    IIRC, SSE2 still has a few issues (e.g. CQ, tests, etc.), it would be better to refine SSE2 code at first.

  12. zpodlovics commented on May 28, 2018

    @zpodlovics

    @fiigii Could you please also add PAUSE as intrinsics? The PAUSE instruction target is high performance / low latency intra-thread communication, lot's of energy could be saved with a small latency increase if these communicating tight loops could use a single PAUSE instruction instead of busy spinning. This is critical as we have more and more cores and multiple numa nodes within a server.

    Could you please also check the explicit cache control intrinsics (CLFLUSH, CLFLUSHOPT, CLWB, CLZERO(?), SFENCE) as persistent memory become mainstream.

    Original issue:
    https://github.com/dotnet/coreclr/issues/916#issuecomment-366562117

  13. svick commented on May 28, 2018

    @svick
    Member

    @zpodlovics

    Could you please also add PAUSE as intrinsics?

    As far as I can tell, calling Thread.SpinWait(1) on x64 will invoke pause enough times to wait 1 ns. Is that not good enough for you?

  14. zpodlovics commented on May 28, 2018

    @zpodlovics

    @svick Unfortunately not. Thread.SpinWait(1) still still doing lot's of unwanted calculation, branches and calls instead of a single (or a few, but still fully controlled) PAUSE instruction within in tight loop. The cpu micro-op cache also plays a critical role here. I have benchmarked / tested every wait method available, in almost every possible way. If you do non-blocking intra-thread communications every call, every branch and every instruction counts, and I am talking about > 100M msg/sec rate between threads. I would like to improve the energy consumption a bit by using a single (or a few but still fully controlled) PAUSE instruction as intrinsics within a loop, instead of doing full busy loop.

    And almost every other intrinsics are available, why PAUSE is not?

  15. redknightlois commented on May 28, 2018

    @redknightlois

    @svick For very high throughput low latency operations nothing beats calling PAUSE. Not on that level yet, but it is important to have it when dealing with that kind of stuff.

  16. 18 remaining items

  17. saucecontrol commented on Jun 9, 2018

    @saucecontrol
    Member

    it would probably be useful to benchmark just how much pinning is actually costing you (as it may actually be saving you some instead)

    I actually did do some benchmarking, and you're absolutely correct. I always pin in the outer loop and pass pointers around today. I was hoping I could use Span<T> to tidy things up and eliminate some of the pinning I do, but even doing questionable pin-less Unsafe.AsPointer(), perf is still worse than what I get with pinning and pointers.

    That said, I think there will be cases where at least for Load/Store, ref arguments would be useful. That would be lower on my wish list than having a complete pointer-based set of APIs, though.

  18. tannergooding commented on Jun 9, 2018

    @tannergooding
    Member

    @Jorenkv, it is on the list of things to discuss :) (whenever we have the next design meeting).

    But, like with everything, unsafe doesn't necessarily mean bad and Span or arrays doesn't necessarily mean good.

    If it is a hot path, benchmark and profile to find out what works best for your app.

  19. jkotas commented on Jun 9, 2018

    @jkotas
    Member

    even doing questionable pin-less Unsafe.AsPointer()

    The example you have posted above will lead to intermittent crashes and data corruptions unless the memory is pinned in some other way.

  20. Jorenkv commented on Jun 9, 2018

    @Jorenkv

    One more question, to get an aligned buffer and avoid having to deal with pinning I was thinking I would Marshal.AllocHGlobal a block of memory, skip a few bytes at the start to get to a 32-byte boundary, and work with that. Any particular reason why this would be a bad idea? (Assuming we're doing this in moderation.)

  21. saucecontrol commented on Jun 9, 2018

    @saucecontrol
    Member

    The example you have posted above will lead to intermittent crashes and data corruptions unless the memory is pinned in some other way.

    That was meant to be an example where the ref argument would have been useful. I thought the 'oops' comment next to the Unsafe.AsPointer() call made it clear it wasn't good code, but yes, I agree nobody should use that.

    I did find it interesting, though, that the JIT always marks that particular method Partially Interruptible in my testing. If there were some way to guarantee that behavior, that could also reduce the need for pinning in short-running methods.

  22. pentp commented on Jun 22, 2018

    @pentp
    Contributor

    Does point 4 (containment for imm, 1-arg, 3-arg forms) cover VEX encoded SSE2?

    vmovaps  xmm0, xmm1
    vpsrldq  xmm0, xmm0, 8
    
  23. fiigii commented on Jun 22, 2018

    @fiigii
    ContributorAuthor

    cover VEX encoded SSE2?

    Yes, it does.

  24. Porges commented on Jul 13, 2018

    @Porges

    Slightly an aside, but it's been discussed earlier here: Given that, even with unmanaged, Vector128 is not going to be pinnable, what's the best way to avoid bounds checks on arrays of Vector128? Array of raw bytes and Sse2.LoadVector128 from that?

    Edit: to be clear, that does work, but I'm not sure if there's a better way 🙂

  25. Zhentar commented on Jul 17, 2018

    @Zhentar

    @Porges I've been using this (with my input starting out as a byte buffer)

    				Span<Vector128<uint>> vecBuff = MemoryMarshal.Cast<byte, Vector128<uint>>(byteSpan);
    				for (int i = 0; i < vecBuff.Length; i++)
    				{
    					Vector128<uint> input = vecBuff[i];

    The read from the Span is compiling down to

    	movsxd  rcx,eax
    	shl     rcx,4
    	vmovupd xmm3,xmmword ptr [r10+rcx]

    Not a whole lot of room for improvement there.

    Although... This shaves off two whole instructions:

    				var uintBuff = MemoryMarshal.Cast<Vector128<uint>, uint>(vecBuff);
    				fixed (uint* buffPos = uintBuff)
    				{
    					uint* currPos = buffPos;
    					uint* end = (uint*)Unsafe.Add<uint>(currPos, uintBuff.Length);
    
    					while(currPos < end)
    					{
    						var input = Sse2.LoadVector128(currPos);
    						currPos = (uint*)Unsafe.Add<uint>(currPos, 4);

    I looking forward to finding out how both approaches are wrong 😁

    my buffer is unmanaged, GC ain't moving it anywhere! Check. Mate.

    Edit: benchmarks say shaving off those two instructions doesn't matter (which isn't too surprising since it should be a pretty pipeline/speculative execution friendly pattern)

  26. voinokin commented on Sep 14, 2018

    @voinokin

    @tannergooding @eerhardt
    Since .NET Core 2.2-pre was recently made public, I wonder whether there were any changes included with it, the ones related to HW intrinsics handling by JIT ? (would like to test some :-) )

  27. eerhardt commented on Sep 14, 2018

    @eerhardt
    Member

    From my understanding, there have been minimal changes in coreclr for .NET Core 2.2. You can see the changes here:

    dotnet/coreclr@release/2.1...release/2.2

    It doesn't look like any of them are HW intrinsics related.

  28. transferred this issue fromdotnet/coreclron Jan 31, 2020
  29. added this to the 3.0 milestone on Jan 31, 2020
  30. ghost locked as resolved and limited conversation to collaborators on Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrdesign-discussion

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions