-
Notifications
You must be signed in to change notification settings - Fork 824
SIMD vectorization of Array.sum<int>, etc #18509
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
base: main
Are you sure you want to change the base?
Changes from all commits
5c3670f
e924815
61ec211
6f17f65
70fef77
330ea57
4c62650
e55905e
116dfde
91accb1
a6979ac
cb5fc5e
20d258f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1578,8 +1578,7 @@ module Array = | |
checkNonNull "array" array | ||
Microsoft.FSharp.Primitives.Basics.Array.permute indexMap array | ||
|
||
[<CompiledName("Sum")>] | ||
let inline sum (array: ^T array) : ^T = | ||
let inline private fsharpSumImpl (array: ^T array) : ^T = | ||
checkNonNull "array" array | ||
let mutable acc = LanguagePrimitives.GenericZero< ^T> | ||
|
||
|
@@ -1588,6 +1587,32 @@ module Array = | |
|
||
acc | ||
|
||
let isNetFramework = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Framework" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this going to functionally compile to a Is this going to do the "wrong" thing on custom runtimes or scenarios where vectorization may not be available or possible? For example, there was no SIMD acceleration on 32-bit Unix for a while and there is non on Arm32 today. Likewise, acceleration can be disabled via environment variables for testing purposes. In general it's expected that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is runtime check, not compile-time check. Because nothing says the code is compiled and run on similar machines.
No, because Enumerable.Sum already checks that within its implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, which is why you should ensure it compiles down to a
The point was that you're doing a specific check for .NET Framework, which doesn't account for custom runtimes or other scenarios that may or may not be relevant. So I'm just asking if the nuance of that has been fully considered. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @tannergooding , I think you have it right - It just does not apply to desktop framework, which is still supported and can be used with latest F# and latest FSharp.Core - there the @tannergooding : There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @T-Gro I think he means that the check should be emitted such that it should be optimized away by JIT and directly use the relevant implementation depending on framework - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is one part of the concern - F#'s emit for The other part of the concern is if indeed Enumerable.Sum is not worse for any configuration |
||
|
||
[<CompiledName("Sum")>] | ||
let inline sum (array: ^T array) : ^T = | ||
fsharpSumImpl array | ||
when ^T : float = | ||
if isNetFramework then fsharpSumImpl array | ||
else | ||
let r = (System.Linq.Enumerable.Sum : IEnumerable<float> -> float) (# "" array : IEnumerable<float> #) | ||
(# "" r : 'T #) | ||
when ^T : float32 = | ||
if isNetFramework then fsharpSumImpl array | ||
else | ||
let r = (System.Linq.Enumerable.Sum : IEnumerable<float32> -> float32) (# "" array : IEnumerable<float32> #) | ||
(# "" r : 'T #) | ||
when ^T : int = | ||
if isNetFramework then fsharpSumImpl array | ||
else | ||
let r = (System.Linq.Enumerable.Sum : IEnumerable<int> -> int) (# "" array : IEnumerable<int> #) | ||
(# "" r : 'T #) | ||
when ^T : int64 = | ||
if isNetFramework then fsharpSumImpl array | ||
else | ||
let r = (System.Linq.Enumerable.Sum : IEnumerable<int64> -> int64) (# "" array : IEnumerable<int64> #) | ||
(# "" r : 'T #) | ||
|
||
[<CompiledName("SumBy")>] | ||
let inline sumBy ([<InlineIfLambda>] projection: 'T -> ^U) (array: 'T array) : ^U = | ||
checkNonNull "array" array | ||
|
Uh oh!
There was an error while loading. Please reload this page.