Repository navigation
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIdesign-discussionOngoing discussion about design without consensus
Milestone
Description
- Refine the API design of Intel hardware intrinsic
- Implement remaining AVX2 intrinsic [rely on (1)]
- Implement remaining SSE4.2 intrinsic [rely on (1)]
- Enable containment analysis on more hardware intrinsic forms (e.g., imm, 1-arg, 3-arg, etc.)
- 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?)
- Implement other ISA classes (
Bmi1,Bmi2,Aes, andPclmulqdq)- fully support all the Intel hardware intrinsic of existing APIs
- Create non-trivial benchmarks for Intel hardware intrinsic
- Improve the CQ of Intel hardware intrinsic base-on key scenarios [partially rely on (7)]
- especially when intrinsics are used in combination or with things like Vectors, and identify areas that need work.
- related issues/PRs: https://github.com/dotnet/coreclr/issues/17073, https://github.com/dotnet/coreclr/issues/17108
- Investigate the JIT throughput impact from hardware intrinsic recognition [rely on (7)]
- Identify candidates that can be optimized using HW intrinsics and implement them using intrinsics (CoreFX, mscorlib, HPC, ML, etc.)
- more...
category:cq
theme:intrinsics
skill-level:intermediate
cost:extra-large
Reacted by itsamelambda, Jason Nelson, Egor Bogatov, hypeartist, Pent Ploompuu, Maximilian Haru Raditya and Joannes Vermorel
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIdesign-discussionOngoing discussion about design without consensus
Activity
fiigii commentedon Apr 27, 2018
cc @CarolEidt @AndyAyersMS @jkotas @tannergooding @mikedn @redknightlois
Please feel free to improve the above list.
AndyAyersMS commentedon Apr 30, 2018
The goal should be to have HW intrinsics be in shape to be fully supported.
Seems like the overall priorities are good:
IIRC there were some not fully resolved design aspects; they should be on the list too.
redknightlois commentedon Apr 30, 2018
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.fiigii commentedon Apr 30, 2018
@AndyAyersMS Thank you so much for the suggestions, updated the list.
fiigii commentedon Apr 30, 2018
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 genericVector128<T>). Does implicit conversion help to this case?redknightlois commentedon Apr 30, 2018
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.CarolEidt commentedon May 1, 2018
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.
tannergooding commentedon May 23, 2018
The PR adding support for the x86 FMA intrinsics is up: dotnet/coreclr#18105
4creators commentedon May 24, 2018
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.4creators commentedon May 24, 2018
@fiigii @tannergooding Whis ISA I could start working on now as I have some free cycles?
fiigii commentedon May 24, 2018
IIRC, SSE2 still has a few issues (e.g. CQ, tests, etc.), it would be better to refine SSE2 code at first.
zpodlovics commentedon May 28, 2018
@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
svick commentedon May 28, 2018
@zpodlovics
As far as I can tell, calling
Thread.SpinWait(1)on x64 will invokepauseenough times to wait 1 ns. Is that not good enough for you?zpodlovics commentedon May 28, 2018
@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?
redknightlois commentedon May 28, 2018
@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.
18 remaining items
saucecontrol commentedon Jun 9, 2018
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-lessUnsafe.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,
refarguments would be useful. That would be lower on my wish list than having a complete pointer-based set of APIs, though.tannergooding commentedon Jun 9, 2018
@Jorenkv, it is on the list of things to discuss :) (whenever we have the next design meeting).
But, like with everything,
unsafedoesn't necessarily mean bad andSpanorarraysdoesn't necessarily mean good.If it is a hot path, benchmark and profile to find out what works best for your app.
jkotas commentedon Jun 9, 2018
The example you have posted above will lead to intermittent crashes and data corruptions unless the memory is pinned in some other way.
Jorenkv commentedon Jun 9, 2018
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.)
saucecontrol commentedon Jun 9, 2018
That was meant to be an example where the
refargument would have been useful. I thought the 'oops' comment next to theUnsafe.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.
pentp commentedon Jun 22, 2018
Does point 4 (containment for imm, 1-arg, 3-arg forms) cover VEX encoded SSE2?
fiigii commentedon Jun 22, 2018
Yes, it does.
Porges commentedon Jul 13, 2018
Slightly an aside, but it's been discussed earlier here: Given that, even with
unmanaged,Vector128is not going to be pinnable, what's the best way to avoid bounds checks on arrays ofVector128? Array of raw bytes andSse2.LoadVector128from that?Edit: to be clear, that does work, but I'm not sure if there's a better way 🙂
Zhentar commentedon Jul 17, 2018
@Porges I've been using this (with my input starting out as a byte buffer)
The read from the Span is compiling down to
Not a whole lot of room for improvement there.
Although... This shaves off two whole instructions:
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)
voinokin commentedon Sep 14, 2018
@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 :-) )
eerhardt commentedon Sep 14, 2018
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.