You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "mikemccand (via GitHub)" <gi...@apache.org> on 2023/06/27 18:11:54 UTC
[GitHub] [lucene] mikemccand opened a new issue, #12399: Would SIMD powered sort (on top of Panama) be worth it?
mikemccand opened a new issue, #12399:
URL: https://github.com/apache/lucene/issues/12399
### Description
I came across [this writeup](https://www.phoronix.com/news/Intel-x86-simd-sort-2.0) of Intel's https://github.com/intel/x86-simd-sort, and then across [this blog post](https://jbaker.io/2022/06/09/vectors-in-java/) about how to do something similar in Java on top of Panama.
We do a fair amount of sorting in Lucene, especially during indexing. Could/should we explore using this Java Panama SIMD sort algorithm for them, when the right SIMD instructions are available?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] rmuir commented on issue #12399: Would SIMD powered sort (on top of Panama) be worth it?
Posted by "rmuir (via GitHub)" <gi...@apache.org>.
rmuir commented on issue #12399:
URL: https://github.com/apache/lucene/issues/12399#issuecomment-1612510234
To give more perspective, look at this algorithm and think about the instructions used and possibly of downclocking causing performance regressions.
Think about trying to detect that all these insns are supported by hardware... We can't. We dodge these issues by limiting what we do to basic stuff like addition and multiplication which has wide general support. Someone writing a blog can "go wild" and use all this crap and as long as it works on their machine for the jmh, they get a successful blog. This is very different from trying to prevent performance regressions across any hardware.
This is why we should not be vectorizing everything and just stick with only methods that are white hot. Vectorizing everyday business logic like this is a real risk.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] uschindler commented on issue #12399: Would SIMD powered sort (on top of Panama) be worth it?
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on issue #12399:
URL: https://github.com/apache/lucene/issues/12399#issuecomment-1611699406
Instead of Valhalla we could also create MemorySegments on heap and create structs on them and then use Varhandles to access the components.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] mikemccand commented on issue #12399: Would SIMD powered sort (on top of Panama) be worth it?
Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand commented on issue #12399:
URL: https://github.com/apache/lucene/issues/12399#issuecomment-1612734709
OK thanks for all the exciting discussion. I agree we should focus on only the white-hot spots given how risking using Panama vector APIs is (trappy performance pitfalls). Let's wait for OpenJDK to vectorize things like sorting.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] uschindler commented on issue #12399: Would SIMD powered sort (on top of Panama) be worth it?
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on issue #12399:
URL: https://github.com/apache/lucene/issues/12399#issuecomment-1611696642
> Yeah, some of our custom sorts are because we want to sort one array, but use the sort key from another parallel array. Unfortunately I don't think (?) the JDK has existing APIs for this usage, yet, the way the SIMD sorting works, it would be a perfect fit (it reports the indices into the array that it then permute to, to achieve the sort ... so we'd want those sorted indices so we could permute our own (possible non-primitive) arrays).
Yes, but I doubt that vectorization can help much here. Actually the problem with parallel arrays should be solved at some time with Project Valhalla, so you can have real Java representations like array of `struct { int a, float b}` which doe snot havethe overhead and is much friendier to caches.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] mikemccand commented on issue #12399: Would SIMD powered sort (on top of Panama) be worth it?
Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand commented on issue #12399:
URL: https://github.com/apache/lucene/issues/12399#issuecomment-1612777794
> > Yeah, some of our custom sorts are because we want to sort one array, but use the sort key from another parallel array. Unfortunately I don't think (?) the JDK has existing APIs for this usage, yet, the way the SIMD sorting works, it would be a perfect fit (it reports the indices into the array that it then permute to, to achieve the sort ... so we'd want those sorted indices so we could permute our own (possible non-primitive) arrays).
>
> Yes, but I doubt that vectorization can help much here.
One correction: I think the SIMD sorting would in fact help here. The way it works is to do the hard part of the sorting to produce a "permute array" (the indices into the original array to achieve the sort). One could easily use that to sort a second parallel array.
Valhala (efficient array of structs) would be a nice option too, once it finally arrives.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [I] Would SIMD powered sort (on top of Panama) be worth it? [lucene]
Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand commented on issue #12399:
URL: https://github.com/apache/lucene/issues/12399#issuecomment-1808206348
At least OpenJDK 22 on modern-ish Intel x86-64 CPUs will [sometimes using SIMD for fast `Arrays.sort`](https://bugs.openjdk.org/browse/JDK-8309130)!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] rmuir commented on issue #12399: Would SIMD powered sort (on top of Panama) be worth it?
Posted by "rmuir (via GitHub)" <gi...@apache.org>.
rmuir commented on issue #12399:
URL: https://github.com/apache/lucene/issues/12399#issuecomment-1610090785
maybe it would be best to try to make more use out of Arrays.sort given that openjdk is doing this kind of optimization, e.g. https://bugs.openjdk.org/browse/JDK-8309130
currently, lucene has a lot of its own sorting.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] mikemccand closed issue #12399: Would SIMD powered sort (on top of Panama) be worth it?
Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand closed issue #12399: Would SIMD powered sort (on top of Panama) be worth it?
URL: https://github.com/apache/lucene/issues/12399
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [I] Would SIMD powered sort (on top of Panama) be worth it? [lucene]
Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand commented on issue #12399:
URL: https://github.com/apache/lucene/issues/12399#issuecomment-1788845861
Some exciting updates here ... Intel continues to improve this "super fast sorting using SIMD instructions" library: https://www.phoronix.com/news/Intel-x86-simd-sort-4.0
And apparently NumPy (fast Python numeric extensions) adopted it, and now also OpenJDK: https://www.phoronix.com/news/Intel-x86-simd-sort-3.0
I wonder which version of OpenJDK we will first see this released in? So, yeah, we should try to use `Arrays.sort` more in Lucene instead of our own sort impls when possible!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] mikemccand commented on issue #12399: Would SIMD powered sort (on top of Panama) be worth it?
Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand commented on issue #12399:
URL: https://github.com/apache/lucene/issues/12399#issuecomment-1611648451
> that openjdk is doing this kind of optimization, e.g. https://bugs.openjdk.org/browse/JDK-8309130
Ahh that is great news that the JDK is working to fold SIMD driven sort into the `Arrays.sort` for primitives.
> maybe it would be best to try to make more use out of Arrays.sort given that openjdk is doing this kind of optimization
+1
> currently, lucene has a lot of its own sorting.
Yeah, some of our custom sorts are because we want to sort one array, but use the sort key from another parallel array. Unfortunately I don't think (?) the JDK has existing APIs for this usage, yet, the way the SIMD sorting works, it would be a perfect fit (it reports the indices into the array that it then permute to, to achieve the sort ... so we'd want those sorted indices so we could permute our own (possible non-primitive) arrays).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] rmuir commented on issue #12399: Would SIMD powered sort (on top of Panama) be worth it?
Posted by "rmuir (via GitHub)" <gi...@apache.org>.
rmuir commented on issue #12399:
URL: https://github.com/apache/lucene/issues/12399#issuecomment-1612499383
> Yeah, some of our custom sorts are because we want to sort one array, but use the sort key from another parallel array. Unfortunately I don't think (?) the JDK has existing APIs for this usage, yet, the way the SIMD sorting works, it would be a perfect fit (it reports the indices into the array that it then permute to, to achieve the sort ... so we'd want those sorted indices so we could permute our own (possible non-primitive) arrays).
I really don't think this is a good candidate for lucene. I would actually be opposed to merging any code that does this. Here's why:
* Vector API is in incubation and has very high maintenance cost for us
* Vector API has a lot of performance landmines
* sorting is not a mega hotspot in any of our benchmarks
* algorithm is AVX 512 only
I see lots of issues being opened to vectorize this or that, and I know it's soon my time to play bad guy again, but I can and will veto performance gains that are overall a bad tradeoff. This would be one of them.
We should really focus on only the hottest of hotspots, we should really focus on the big wins where vectorization is a natural fit, and where it works on most everyone's hardware, and seek to *minimize* the surface area we touch with vector API.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org