You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/03/15 03:52:23 UTC

[GitHub] [lucene] rmuir opened a new pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

rmuir opened a new pull request #18:
URL: https://github.com/apache/lucene/pull/18


   See https://issues.apache.org/jira/browse/LUCENE-9838 for benchmarks and details.
   
   I'm not sure practically what we can/should do with this PR, but the performance improvement is large enough for someone using vectors that maybe we should explore options?
   
   For now the PR is just a hack, make it easier for people to try out and play with at least. I borrowed @uschindler build logic from one of his pull requests: https://github.com/apache/lucene-solr/pull/2176
   
   


----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594293841



##########
File path: gradle/defaults-java.gradle
##########
@@ -60,3 +60,14 @@ allprojects {
     }
   }
 }
+
+configure(project(":lucene:core")) {
+  plugins.withType(JavaPlugin) {

Review comment:
       I think: for this use case, we should not use MR-JARs at all. Just use a MethodHandle. It's just a single method and a few classes. Maybe you can construct this using a single MethodHandle using those combiners (MethodHandles.adapt.... and MH.guard, and all other methods).... Another MethodHandle would go to our slow version.




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r595068893



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"

Review comment:
       start with changing it to use `byte[]` instead of `float[]`. For the case of vector 256 this replaces 64 calls each to bytebuffer position, readInt, bswap, etc etc with a single `readBytes()` call. And it is easiest next step as there will be no alignment issues.
   
   going from bytebuffer is harder.




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594822712



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"

Review comment:
       refs:
    https://download.java.net/java/early_access/jdk16/docs/api/jdk.incubator.vector/jdk/incubator/vector/FloatVector.html#fromByteArray(jdk.incubator.vector.VectorSpecies,byte%5B%5D,int,java.nio.ByteOrder)
   
   https://download.java.net/java/early_access/jdk16/docs/api/jdk.incubator.vector/jdk/incubator/vector/FloatVector.html#fromByteBuffer(jdk.incubator.vector.VectorSpecies,java.nio.ByteBuffer,int,java.nio.ByteOrder)




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594293841



##########
File path: gradle/defaults-java.gradle
##########
@@ -60,3 +60,14 @@ allprojects {
     }
   }
 }
+
+configure(project(":lucene:core")) {
+  plugins.withType(JavaPlugin) {

Review comment:
       I think: for this use case, we should not use MR-JARs at all. Just use a MethodHandle. It's just a single method and a few classes. Maybe you can construct this using a single MethodHandle. Another MethodHandle would go to our slow version.




----------------------------------------------------------------
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.

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 edited a comment on pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler edited a comment on pull request #18:
URL: https://github.com/apache/lucene/pull/18#issuecomment-800065901


   Another idea: We can remove the Methodhandles with the crazy try-catch block, if we'd define a static functional interface in this class, that is implemented by VectorUtil itsself, but also by the base64-encoded class. I am not sure if it's woth the trouble, as it makes regenerating the base64 harder, but then we only need the Loader and use `.asSubClass(DotProductInterface.class)`.


----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594941232



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"

Review comment:
       I think we should have the source code of this class file available for regeneration. So anybody can compile with Java 11, but regeneration is only possible with exact Java 16 version.
   As it currently looks like I would not be sure if we can release this.
   
   If we don't add the original source code as a java file for regeneration, we should add source code here (as comment).




----------------------------------------------------------------
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.

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 closed pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
rmuir closed pull request #18:
URL: https://github.com/apache/lucene/pull/18


   


-- 
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.

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 pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
rmuir commented on pull request #18:
URL: https://github.com/apache/lucene/pull/18#issuecomment-799867289


   OK i added a version that has no mr-jar and no build-system changes, but still allows the user to opt-in to the new `jdk.incubator.vector` api... yeah it is pretty evil, but at least I didn't leave 6x performance for this thing on the table, so I'm happy regardless.


----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594205187



##########
File path: gradle/defaults-java.gradle
##########
@@ -60,3 +60,14 @@ allprojects {
     }
   }
 }
+
+configure(project(":lucene:core")) {
+  plugins.withType(JavaPlugin) {

Review comment:
       I feel the same for MMapDirectory v2: "it should really go into Lucene Core", with some trick, but at the moment I have to wait. Netty has something similar at moment, you have to download a separate JAR and add it to your classpath.
   
   So one way to implement this: Add a separate lucene module that's optional and use some "plug in" mechanism (e.g., SPI). People who want to use it must use the exact correct version for their JDK version and must add some command line flag to use it (enable it in their JDK).




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594287749



##########
File path: gradle/defaults-java.gradle
##########
@@ -60,3 +60,14 @@ allprojects {
     }
   }
 }
+
+configure(project(":lucene:core")) {
+  plugins.withType(JavaPlugin) {

Review comment:
       Is it really impossible though? Wit MR-JAR could we define a class version for 16+, but define slow version for 17+? Effectively, we define a version of the code for only exactly version 16?
   
   Furthermore, couldn't we check with static initializer and if the incubator module isn't available, link methodhandle to a slow version?




----------------------------------------------------------------
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.

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 pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on pull request #18:
URL: https://github.com/apache/lucene/pull/18#issuecomment-800070555


   We should add a small test that verifies the following: If JDK version is exactly 16 (not 15, not 17 - as we don't know if this works later anymore when incubator releases theclass), then the boolean should be true.
   
   Of course we then have to add the module-option to the test classpath (which we really should do). Currenty we have no testing at all.


----------------------------------------------------------------
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.

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] dweiss commented on a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
dweiss commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594143087



##########
File path: gradle/defaults-java.gradle
##########
@@ -60,3 +60,14 @@ allprojects {
     }
   }
 }
+
+configure(project(":lucene:core")) {
+  plugins.withType(JavaPlugin) {

Review comment:
       If this is MR-jar code then it'd be cleaner to create separate sourcesets for different jdk levels required and then apply these compiler options to each sourceset. This makes it possible to work with multiple "levels" of compatibility on the same source data.
   
   You could also (conditionally) disable compilation of these extra sourcesets if the compiler version is lower than the sourceset's required version... this would enable people to work with the code without installing all the (alpha) JDKs.
   
   I can take care of this if needed - let me know.




----------------------------------------------------------------
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.

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] dweiss commented on a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
dweiss commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594923342



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"
+          + "BwAIAQAiamF2YS9sYW5nL0lsbGVnYWxBcmd1bWVudEV4Y2VwdGlvbhIAAAAKDAALAAwBABdtYWtl\n"
+          + "Q29uY2F0V2l0aENvbnN0YW50cwEAFihJSSlMamF2YS9sYW5nL1N0cmluZzsKAAcADgwABQAPAQAV\n"
+          + "KExqYXZhL2xhbmcvU3RyaW5nOylWCQARABIHABMMABQAFQEAJW9yZy9hcGFjaGUvbHVjZW5lL3V0\n"
+          + "aWwvVmVjdG9yVXRpbFNJTUQBAAdTUEVDSUVTAQAkTGpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rv\n"
+          + "clNwZWNpZXM7CwAXABgHABkMABoAGwEAImpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3RvclNwZWNp\n"
+          + "ZXMBAAZsZW5ndGgBAAMoKUkKAB0AHgcAHwwAIAAhAQAgamRrL2luY3ViYXRvci92ZWN0b3IvRmxv\n"
+          + "YXRWZWN0b3IBAAR6ZXJvAQBIKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0b3JTcGVjaWVzOylM\n"
+          + "amRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CwAXACMMACQAJQEACWxvb3BCb3VuZAEA\n"
+          + "BChJKUkKAB0AJwwAKAApAQAJZnJvbUFycmF5AQBLKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0\n"
+          + "b3JTcGVjaWVzO1tGSSlMamRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CgAdACsMACwA\n"
+          + "LQEAA211bAEAQShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yOylMamRrL2luY3ViYXRvci92\n"
+          + "ZWN0b3IvRmxvYXRWZWN0b3I7CgAdAC8MADAALQEAA2FkZAkAMgAzBwA0DAA1ADYBACRqZGsvaW5j\n"
+          + "dWJhdG9yL3ZlY3Rvci9WZWN0b3JPcGVyYXRvcnMBAANBREQBADJMamRrL2luY3ViYXRvci92ZWN0\n"
+          + "b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOwoAHQA4DAA5ADoBAAtyZWR1Y2VMYW5lcwEA\n"
+          + "NShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOylGCQAd\n"
+          + "ADwMAD0AFQEAEVNQRUNJRVNfUFJFRkVSUkVEAQAJU2lnbmF0dXJlAQA3TGpkay9pbmN1YmF0b3Iv\n"
+          + "dmVjdG9yL1ZlY3RvclNwZWNpZXM8TGphdmEvbGFuZy9GbG9hdDs+OwEABENvZGUBAA9MaW5lTnVt\n"
+          + "YmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aGlzAQAnTG9yZy9hcGFjaGUvbHVjZW5l\n"
+          + "L3V0aWwvVmVjdG9yVXRpbFNJTUQ7AQAKZG90UHJvZHVjdAEAByhbRltGKUYBAAJ2YQEAIkxqZGsv\n"
+          + "aW5jdWJhdG9yL3ZlY3Rvci9GbG9hdFZlY3RvcjsBAAJ2YgEAAnZjAQACdmQBAARhY2MxAQAEYWNj\n"
+          + "MgEACnVwcGVyQm91bmQBAAFJAQABYQEAAltGAQABYgEAAWkBAANyZXMBAAFGAQANU3RhY2tNYXBU\n"
+          + "YWJsZQcAUQEACDxjbGluaXQ+AQAKU291cmNlRmlsZQEAE1ZlY3RvclV0aWxTSU1ELmphdmEBABBC\n"
+          + "b290c3RyYXBNZXRob2RzDwYAXQoAXgBfBwBgDAALAGEBACRqYXZhL2xhbmcvaW52b2tlL1N0cmlu\n"
+          + "Z0NvbmNhdEZhY3RvcnkBAJgoTGphdmEvbGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcyRMb29rdXA7\n"
+          + "TGphdmEvbGFuZy9TdHJpbmc7TGphdmEvbGFuZy9pbnZva2UvTWV0aG9kVHlwZTtMamF2YS9sYW5n\n"
+          + "L1N0cmluZztbTGphdmEvbGFuZy9PYmplY3Q7KUxqYXZhL2xhbmcvaW52b2tlL0NhbGxTaXRlOwgA\n"
+          + "YwEAHnZlY3RvciBkaW1lbnNpb25zIGRpZmZlcjogASE9AQEADElubmVyQ2xhc3NlcwcAZgEAMGpk\n"
+          + "ay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rvck9wZXJhdG9ycyRBc3NvY2lhdGl2ZQEAC0Fzc29jaWF0\n"
+          + "aXZlBwBpAQAlamF2YS9sYW5nL2ludm9rZS9NZXRob2RIYW5kbGVzJExvb2t1cAcAawEAHmphdmEv\n"
+          + "bGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcwEABkxvb2t1cAAhABEAAgAAAAEAGgAUABUAAQA+AAAA\n"
+          + "AgA/AAMAAQAFAAYAAQBAAAAALwABAAEAAAAFKrcAAbEAAAACAEEAAAAGAAEAAAAZAEIAAAAMAAEA\n"
+          + "AAAFAEMARAAAAAkARQBGAAEAQAAAAewABAALAAAA6Cq+K76fABS7AAdZKr4rvroACQAAtwANvwM9\n"
+          + "C0YqvgWyABC5ABYBAGihAKiyABC4ABw6BLIAELgAHDoFsgAQKr6yABC5ABYBAGS5ACICADYGHBUG\n"
+          + "ogBpsgAQKhy4ACY6B7IAECscuAAmOggZBBkHGQi2ACq2AC46BLIAECocsgAQuQAWAQBguAAmOgmy\n"
+          + "ABArHLIAELkAFgEAYLgAJjoKGQUZCRkKtgAqtgAuOgUcBbIAELkAFgEAaGA9p/+XJRkEsgAxtgA3\n"
+          + "GQWyADG2ADdiYkYcKr6iABMlKxwwKhwwamJGhAIBp//tJa4AAAADAEEAAABWABUAAAAhAAcAIgAY\n"
+          + "ACQAGgAlABwAKAArACkAMwAqADsAKwBQACwAVgAtAGAALgBqAC8AeAAwAIsAMQCeADIArAAsALwA\n"
+          + "NADQADYA1gA3AOAANgDmADkAQgAAAHAACwBgAEwARwBIAAcAagBCAEkASAAIAIsAIQBKAEgACQCe\n"
+          + "AA4ASwBIAAoAMwCdAEwASAAEADsAlQBNAEgABQBQAIAATgBPAAYAAADoAFAAUQAAAAAA6ABSAFEA\n"
+          + "AQAaAM4AUwBPAAIAHADMAFQAVQADAFYAAAAgAAUY/wA3AAcHAFcHAFcBAgcAHQcAHQEAAPsAa/gA\n"
+          + "ExUACABYAAYAAQBAAAAAHwABAAAAAAAHsgA7swAQsQAAAAEAQQAAAAYAAQAAABoAAwBZAAAAAgBa\n"
+          + "AFsAAAAIAAEAXAABAGIAZAAAABIAAgBlADIAZwYJAGgAagBsABk=";
+
+  private static final MethodHandle DOTPRODUCT;
+  private static final MethodType DOTPRODUCT_TYPE =
+      MethodType.methodType(float.class, float[].class, float[].class);
+
+  static final class Loader extends ClassLoader {
+    Loader(ClassLoader parent) {
+      super(parent);
+    }
+
+    public Class<?> define(byte[] code) {
+      return defineClass("org.apache.lucene.util.VectorUtilSIMD", code, 0, code.length);
+    }
+  }
+
+  /**
+   * True if vectorized dot product is supported.
+   *
+   * <p>For this to work, you need java 16, and you need to opt-in by passing {@code --add-modules
+   * jdk.incubator.vector} to the java command line.
+   */
+  public static final boolean DOTPRODUCT_VECTORIZATION_SUPPORTED;
+
+  static {
+    MethodHandle impl = null;
+    boolean vectorSupported = false;
+
+    try {
+      impl =
+          MethodHandles.lookup().findStatic(VectorUtil.class, "dotProductScalar", DOTPRODUCT_TYPE);
+    } catch (NoSuchMethodException | IllegalAccessException e) {
+      throw new RuntimeException(e);
+    }
+
+    try {
+      Class<?> clazz =

Review comment:
       This doesn't require additional permissions (custom class loader definition)?




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594202442



##########
File path: gradle/defaults-java.gradle
##########
@@ -60,3 +60,14 @@ allprojects {
     }
   }
 }
+
+configure(project(":lucene:core")) {
+  plugins.withType(JavaPlugin) {

Review comment:
       The problem is currently: it is incubating API, so it will break with JDK17 again.
   
   We have to wait that the incubating module get's into java.base / java.whatever, so it can be used and API is stable. The problem with MR-JARs is the following:
   - it does not handle module system, so you would get ClassNotFound if you dont start with correct command line flag
   - You can't say: "use this only is Java version exactly 16"
   
   Like with my own Pull Request for MMAP: We should test this, e.g. on Jenkins, but not add to productive code.




----------------------------------------------------------------
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.

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 pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on pull request #18:
URL: https://github.com/apache/lucene/pull/18#issuecomment-802762574


   > Looks like openjdk is just teasing us here. Incubating API is not really intended to transition to a real API anytime soon: https://openjdk.java.net/jeps/8261663
   > 
   > So we may expect java 21 or java 24 before we can use this stuff :(
   
   Actually, this is good news in the second incubator JEP (but unrelated to that issue): "On condition that the Foreign-Memory Access API exits incubation, loading and storing vectors from and to a MemorySegment." -> so it looks like the Foreign Memory Access API is planned to leave incubation in java 17. So at least: I AM HAPPY!


-- 
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594943346



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"
+          + "BwAIAQAiamF2YS9sYW5nL0lsbGVnYWxBcmd1bWVudEV4Y2VwdGlvbhIAAAAKDAALAAwBABdtYWtl\n"
+          + "Q29uY2F0V2l0aENvbnN0YW50cwEAFihJSSlMamF2YS9sYW5nL1N0cmluZzsKAAcADgwABQAPAQAV\n"
+          + "KExqYXZhL2xhbmcvU3RyaW5nOylWCQARABIHABMMABQAFQEAJW9yZy9hcGFjaGUvbHVjZW5lL3V0\n"
+          + "aWwvVmVjdG9yVXRpbFNJTUQBAAdTUEVDSUVTAQAkTGpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rv\n"
+          + "clNwZWNpZXM7CwAXABgHABkMABoAGwEAImpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3RvclNwZWNp\n"
+          + "ZXMBAAZsZW5ndGgBAAMoKUkKAB0AHgcAHwwAIAAhAQAgamRrL2luY3ViYXRvci92ZWN0b3IvRmxv\n"
+          + "YXRWZWN0b3IBAAR6ZXJvAQBIKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0b3JTcGVjaWVzOylM\n"
+          + "amRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CwAXACMMACQAJQEACWxvb3BCb3VuZAEA\n"
+          + "BChJKUkKAB0AJwwAKAApAQAJZnJvbUFycmF5AQBLKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0\n"
+          + "b3JTcGVjaWVzO1tGSSlMamRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CgAdACsMACwA\n"
+          + "LQEAA211bAEAQShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yOylMamRrL2luY3ViYXRvci92\n"
+          + "ZWN0b3IvRmxvYXRWZWN0b3I7CgAdAC8MADAALQEAA2FkZAkAMgAzBwA0DAA1ADYBACRqZGsvaW5j\n"
+          + "dWJhdG9yL3ZlY3Rvci9WZWN0b3JPcGVyYXRvcnMBAANBREQBADJMamRrL2luY3ViYXRvci92ZWN0\n"
+          + "b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOwoAHQA4DAA5ADoBAAtyZWR1Y2VMYW5lcwEA\n"
+          + "NShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOylGCQAd\n"
+          + "ADwMAD0AFQEAEVNQRUNJRVNfUFJFRkVSUkVEAQAJU2lnbmF0dXJlAQA3TGpkay9pbmN1YmF0b3Iv\n"
+          + "dmVjdG9yL1ZlY3RvclNwZWNpZXM8TGphdmEvbGFuZy9GbG9hdDs+OwEABENvZGUBAA9MaW5lTnVt\n"
+          + "YmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aGlzAQAnTG9yZy9hcGFjaGUvbHVjZW5l\n"
+          + "L3V0aWwvVmVjdG9yVXRpbFNJTUQ7AQAKZG90UHJvZHVjdAEAByhbRltGKUYBAAJ2YQEAIkxqZGsv\n"
+          + "aW5jdWJhdG9yL3ZlY3Rvci9GbG9hdFZlY3RvcjsBAAJ2YgEAAnZjAQACdmQBAARhY2MxAQAEYWNj\n"
+          + "MgEACnVwcGVyQm91bmQBAAFJAQABYQEAAltGAQABYgEAAWkBAANyZXMBAAFGAQANU3RhY2tNYXBU\n"
+          + "YWJsZQcAUQEACDxjbGluaXQ+AQAKU291cmNlRmlsZQEAE1ZlY3RvclV0aWxTSU1ELmphdmEBABBC\n"
+          + "b290c3RyYXBNZXRob2RzDwYAXQoAXgBfBwBgDAALAGEBACRqYXZhL2xhbmcvaW52b2tlL1N0cmlu\n"
+          + "Z0NvbmNhdEZhY3RvcnkBAJgoTGphdmEvbGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcyRMb29rdXA7\n"
+          + "TGphdmEvbGFuZy9TdHJpbmc7TGphdmEvbGFuZy9pbnZva2UvTWV0aG9kVHlwZTtMamF2YS9sYW5n\n"
+          + "L1N0cmluZztbTGphdmEvbGFuZy9PYmplY3Q7KUxqYXZhL2xhbmcvaW52b2tlL0NhbGxTaXRlOwgA\n"
+          + "YwEAHnZlY3RvciBkaW1lbnNpb25zIGRpZmZlcjogASE9AQEADElubmVyQ2xhc3NlcwcAZgEAMGpk\n"
+          + "ay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rvck9wZXJhdG9ycyRBc3NvY2lhdGl2ZQEAC0Fzc29jaWF0\n"
+          + "aXZlBwBpAQAlamF2YS9sYW5nL2ludm9rZS9NZXRob2RIYW5kbGVzJExvb2t1cAcAawEAHmphdmEv\n"
+          + "bGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcwEABkxvb2t1cAAhABEAAgAAAAEAGgAUABUAAQA+AAAA\n"
+          + "AgA/AAMAAQAFAAYAAQBAAAAALwABAAEAAAAFKrcAAbEAAAACAEEAAAAGAAEAAAAZAEIAAAAMAAEA\n"
+          + "AAAFAEMARAAAAAkARQBGAAEAQAAAAewABAALAAAA6Cq+K76fABS7AAdZKr4rvroACQAAtwANvwM9\n"
+          + "C0YqvgWyABC5ABYBAGihAKiyABC4ABw6BLIAELgAHDoFsgAQKr6yABC5ABYBAGS5ACICADYGHBUG\n"
+          + "ogBpsgAQKhy4ACY6B7IAECscuAAmOggZBBkHGQi2ACq2AC46BLIAECocsgAQuQAWAQBguAAmOgmy\n"
+          + "ABArHLIAELkAFgEAYLgAJjoKGQUZCRkKtgAqtgAuOgUcBbIAELkAFgEAaGA9p/+XJRkEsgAxtgA3\n"
+          + "GQWyADG2ADdiYkYcKr6iABMlKxwwKhwwamJGhAIBp//tJa4AAAADAEEAAABWABUAAAAhAAcAIgAY\n"
+          + "ACQAGgAlABwAKAArACkAMwAqADsAKwBQACwAVgAtAGAALgBqAC8AeAAwAIsAMQCeADIArAAsALwA\n"
+          + "NADQADYA1gA3AOAANgDmADkAQgAAAHAACwBgAEwARwBIAAcAagBCAEkASAAIAIsAIQBKAEgACQCe\n"
+          + "AA4ASwBIAAoAMwCdAEwASAAEADsAlQBNAEgABQBQAIAATgBPAAYAAADoAFAAUQAAAAAA6ABSAFEA\n"
+          + "AQAaAM4AUwBPAAIAHADMAFQAVQADAFYAAAAgAAUY/wA3AAcHAFcHAFcBAgcAHQcAHQEAAPsAa/gA\n"
+          + "ExUACABYAAYAAQBAAAAAHwABAAAAAAAHsgA7swAQsQAAAAEAQQAAAAYAAQAAABoAAwBZAAAAAgBa\n"
+          + "AFsAAAAIAAEAXAABAGIAZAAAABIAAgBlADIAZwYJAGgAagBsABk=";
+
+  private static final MethodHandle DOTPRODUCT;
+  private static final MethodType DOTPRODUCT_TYPE =
+      MethodType.methodType(float.class, float[].class, float[].class);
+
+  static final class Loader extends ClassLoader {
+    Loader(ClassLoader parent) {
+      super(parent);
+    }
+
+    public Class<?> define(byte[] code) {

Review comment:
       this signature is strange as it takes the bytes, but not the class name. Either take class name, too, or alternatively decode pass the base64 directly here: `Base64.getMimeDecoder().decode(SIMD_BASE64)`, so method gets parameterless.
   
   Ideally (as we are on Java 16), we could have used the new anonymous classes. But this code is also not visible, damn!

##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"
+          + "BwAIAQAiamF2YS9sYW5nL0lsbGVnYWxBcmd1bWVudEV4Y2VwdGlvbhIAAAAKDAALAAwBABdtYWtl\n"
+          + "Q29uY2F0V2l0aENvbnN0YW50cwEAFihJSSlMamF2YS9sYW5nL1N0cmluZzsKAAcADgwABQAPAQAV\n"
+          + "KExqYXZhL2xhbmcvU3RyaW5nOylWCQARABIHABMMABQAFQEAJW9yZy9hcGFjaGUvbHVjZW5lL3V0\n"
+          + "aWwvVmVjdG9yVXRpbFNJTUQBAAdTUEVDSUVTAQAkTGpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rv\n"
+          + "clNwZWNpZXM7CwAXABgHABkMABoAGwEAImpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3RvclNwZWNp\n"
+          + "ZXMBAAZsZW5ndGgBAAMoKUkKAB0AHgcAHwwAIAAhAQAgamRrL2luY3ViYXRvci92ZWN0b3IvRmxv\n"
+          + "YXRWZWN0b3IBAAR6ZXJvAQBIKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0b3JTcGVjaWVzOylM\n"
+          + "amRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CwAXACMMACQAJQEACWxvb3BCb3VuZAEA\n"
+          + "BChJKUkKAB0AJwwAKAApAQAJZnJvbUFycmF5AQBLKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0\n"
+          + "b3JTcGVjaWVzO1tGSSlMamRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CgAdACsMACwA\n"
+          + "LQEAA211bAEAQShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yOylMamRrL2luY3ViYXRvci92\n"
+          + "ZWN0b3IvRmxvYXRWZWN0b3I7CgAdAC8MADAALQEAA2FkZAkAMgAzBwA0DAA1ADYBACRqZGsvaW5j\n"
+          + "dWJhdG9yL3ZlY3Rvci9WZWN0b3JPcGVyYXRvcnMBAANBREQBADJMamRrL2luY3ViYXRvci92ZWN0\n"
+          + "b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOwoAHQA4DAA5ADoBAAtyZWR1Y2VMYW5lcwEA\n"
+          + "NShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOylGCQAd\n"
+          + "ADwMAD0AFQEAEVNQRUNJRVNfUFJFRkVSUkVEAQAJU2lnbmF0dXJlAQA3TGpkay9pbmN1YmF0b3Iv\n"
+          + "dmVjdG9yL1ZlY3RvclNwZWNpZXM8TGphdmEvbGFuZy9GbG9hdDs+OwEABENvZGUBAA9MaW5lTnVt\n"
+          + "YmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aGlzAQAnTG9yZy9hcGFjaGUvbHVjZW5l\n"
+          + "L3V0aWwvVmVjdG9yVXRpbFNJTUQ7AQAKZG90UHJvZHVjdAEAByhbRltGKUYBAAJ2YQEAIkxqZGsv\n"
+          + "aW5jdWJhdG9yL3ZlY3Rvci9GbG9hdFZlY3RvcjsBAAJ2YgEAAnZjAQACdmQBAARhY2MxAQAEYWNj\n"
+          + "MgEACnVwcGVyQm91bmQBAAFJAQABYQEAAltGAQABYgEAAWkBAANyZXMBAAFGAQANU3RhY2tNYXBU\n"
+          + "YWJsZQcAUQEACDxjbGluaXQ+AQAKU291cmNlRmlsZQEAE1ZlY3RvclV0aWxTSU1ELmphdmEBABBC\n"
+          + "b290c3RyYXBNZXRob2RzDwYAXQoAXgBfBwBgDAALAGEBACRqYXZhL2xhbmcvaW52b2tlL1N0cmlu\n"
+          + "Z0NvbmNhdEZhY3RvcnkBAJgoTGphdmEvbGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcyRMb29rdXA7\n"
+          + "TGphdmEvbGFuZy9TdHJpbmc7TGphdmEvbGFuZy9pbnZva2UvTWV0aG9kVHlwZTtMamF2YS9sYW5n\n"
+          + "L1N0cmluZztbTGphdmEvbGFuZy9PYmplY3Q7KUxqYXZhL2xhbmcvaW52b2tlL0NhbGxTaXRlOwgA\n"
+          + "YwEAHnZlY3RvciBkaW1lbnNpb25zIGRpZmZlcjogASE9AQEADElubmVyQ2xhc3NlcwcAZgEAMGpk\n"
+          + "ay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rvck9wZXJhdG9ycyRBc3NvY2lhdGl2ZQEAC0Fzc29jaWF0\n"
+          + "aXZlBwBpAQAlamF2YS9sYW5nL2ludm9rZS9NZXRob2RIYW5kbGVzJExvb2t1cAcAawEAHmphdmEv\n"
+          + "bGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcwEABkxvb2t1cAAhABEAAgAAAAEAGgAUABUAAQA+AAAA\n"
+          + "AgA/AAMAAQAFAAYAAQBAAAAALwABAAEAAAAFKrcAAbEAAAACAEEAAAAGAAEAAAAZAEIAAAAMAAEA\n"
+          + "AAAFAEMARAAAAAkARQBGAAEAQAAAAewABAALAAAA6Cq+K76fABS7AAdZKr4rvroACQAAtwANvwM9\n"
+          + "C0YqvgWyABC5ABYBAGihAKiyABC4ABw6BLIAELgAHDoFsgAQKr6yABC5ABYBAGS5ACICADYGHBUG\n"
+          + "ogBpsgAQKhy4ACY6B7IAECscuAAmOggZBBkHGQi2ACq2AC46BLIAECocsgAQuQAWAQBguAAmOgmy\n"
+          + "ABArHLIAELkAFgEAYLgAJjoKGQUZCRkKtgAqtgAuOgUcBbIAELkAFgEAaGA9p/+XJRkEsgAxtgA3\n"
+          + "GQWyADG2ADdiYkYcKr6iABMlKxwwKhwwamJGhAIBp//tJa4AAAADAEEAAABWABUAAAAhAAcAIgAY\n"
+          + "ACQAGgAlABwAKAArACkAMwAqADsAKwBQACwAVgAtAGAALgBqAC8AeAAwAIsAMQCeADIArAAsALwA\n"
+          + "NADQADYA1gA3AOAANgDmADkAQgAAAHAACwBgAEwARwBIAAcAagBCAEkASAAIAIsAIQBKAEgACQCe\n"
+          + "AA4ASwBIAAoAMwCdAEwASAAEADsAlQBNAEgABQBQAIAATgBPAAYAAADoAFAAUQAAAAAA6ABSAFEA\n"
+          + "AQAaAM4AUwBPAAIAHADMAFQAVQADAFYAAAAgAAUY/wA3AAcHAFcHAFcBAgcAHQcAHQEAAPsAa/gA\n"
+          + "ExUACABYAAYAAQBAAAAAHwABAAAAAAAHsgA7swAQsQAAAAEAQQAAAAYAAQAAABoAAwBZAAAAAgBa\n"
+          + "AFsAAAAIAAEAXAABAGIAZAAAABIAAgBlADIAZwYJAGgAagBsABk=";
+
+  private static final MethodHandle DOTPRODUCT;
+  private static final MethodType DOTPRODUCT_TYPE =
+      MethodType.methodType(float.class, float[].class, float[].class);
+
+  static final class Loader extends ClassLoader {
+    Loader(ClassLoader parent) {
+      super(parent);
+    }
+
+    public Class<?> define(byte[] code) {
+      return defineClass("org.apache.lucene.util.VectorUtilSIMD", code, 0, code.length);
+    }
+  }
+
+  /**
+   * True if vectorized dot product is supported.
+   *
+   * <p>For this to work, you need java 16, and you need to opt-in by passing {@code --add-modules
+   * jdk.incubator.vector} to the java command line.
+   */
+  public static final boolean DOTPRODUCT_VECTORIZATION_SUPPORTED;
+
+  static {
+    MethodHandle impl = null;
+    boolean vectorSupported = false;
+
+    try {
+      impl =
+          MethodHandles.lookup().findStatic(VectorUtil.class, "dotProductScalar", DOTPRODUCT_TYPE);
+    } catch (NoSuchMethodException | IllegalAccessException e) {
+      throw new RuntimeException(e);
+    }
+
+    try {
+      Class<?> clazz =
+          new Loader(VectorUtil.class.getClassLoader())
+              .define(Base64.getMimeDecoder().decode(SIMD_BASE64));
+      impl = MethodHandles.lookup().findStatic(clazz, "dotProduct", DOTPRODUCT_TYPE);
+      vectorSupported = true;
+    } catch (Throwable e) {
+    }
+
+    DOTPRODUCT = impl;
+    DOTPRODUCT_VECTORIZATION_SUPPORTED = vectorSupported;
+  }
+
   /**
    * Returns the vector dot product of the two vectors. IllegalArgumentException is thrown if the
    * vectors' dimensions differ.
    */
   public static float dotProduct(float[] a, float[] b) {
+    try {
+      return (float) DOTPRODUCT.invokeExact(a, b);
+    } catch (RuntimeException e) {
+      throw e;
+    } catch (Throwable e) {

Review comment:
       I'd add another catch with `Error`.

##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"
+          + "BwAIAQAiamF2YS9sYW5nL0lsbGVnYWxBcmd1bWVudEV4Y2VwdGlvbhIAAAAKDAALAAwBABdtYWtl\n"
+          + "Q29uY2F0V2l0aENvbnN0YW50cwEAFihJSSlMamF2YS9sYW5nL1N0cmluZzsKAAcADgwABQAPAQAV\n"
+          + "KExqYXZhL2xhbmcvU3RyaW5nOylWCQARABIHABMMABQAFQEAJW9yZy9hcGFjaGUvbHVjZW5lL3V0\n"
+          + "aWwvVmVjdG9yVXRpbFNJTUQBAAdTUEVDSUVTAQAkTGpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rv\n"
+          + "clNwZWNpZXM7CwAXABgHABkMABoAGwEAImpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3RvclNwZWNp\n"
+          + "ZXMBAAZsZW5ndGgBAAMoKUkKAB0AHgcAHwwAIAAhAQAgamRrL2luY3ViYXRvci92ZWN0b3IvRmxv\n"
+          + "YXRWZWN0b3IBAAR6ZXJvAQBIKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0b3JTcGVjaWVzOylM\n"
+          + "amRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CwAXACMMACQAJQEACWxvb3BCb3VuZAEA\n"
+          + "BChJKUkKAB0AJwwAKAApAQAJZnJvbUFycmF5AQBLKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0\n"
+          + "b3JTcGVjaWVzO1tGSSlMamRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CgAdACsMACwA\n"
+          + "LQEAA211bAEAQShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yOylMamRrL2luY3ViYXRvci92\n"
+          + "ZWN0b3IvRmxvYXRWZWN0b3I7CgAdAC8MADAALQEAA2FkZAkAMgAzBwA0DAA1ADYBACRqZGsvaW5j\n"
+          + "dWJhdG9yL3ZlY3Rvci9WZWN0b3JPcGVyYXRvcnMBAANBREQBADJMamRrL2luY3ViYXRvci92ZWN0\n"
+          + "b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOwoAHQA4DAA5ADoBAAtyZWR1Y2VMYW5lcwEA\n"
+          + "NShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOylGCQAd\n"
+          + "ADwMAD0AFQEAEVNQRUNJRVNfUFJFRkVSUkVEAQAJU2lnbmF0dXJlAQA3TGpkay9pbmN1YmF0b3Iv\n"
+          + "dmVjdG9yL1ZlY3RvclNwZWNpZXM8TGphdmEvbGFuZy9GbG9hdDs+OwEABENvZGUBAA9MaW5lTnVt\n"
+          + "YmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aGlzAQAnTG9yZy9hcGFjaGUvbHVjZW5l\n"
+          + "L3V0aWwvVmVjdG9yVXRpbFNJTUQ7AQAKZG90UHJvZHVjdAEAByhbRltGKUYBAAJ2YQEAIkxqZGsv\n"
+          + "aW5jdWJhdG9yL3ZlY3Rvci9GbG9hdFZlY3RvcjsBAAJ2YgEAAnZjAQACdmQBAARhY2MxAQAEYWNj\n"
+          + "MgEACnVwcGVyQm91bmQBAAFJAQABYQEAAltGAQABYgEAAWkBAANyZXMBAAFGAQANU3RhY2tNYXBU\n"
+          + "YWJsZQcAUQEACDxjbGluaXQ+AQAKU291cmNlRmlsZQEAE1ZlY3RvclV0aWxTSU1ELmphdmEBABBC\n"
+          + "b290c3RyYXBNZXRob2RzDwYAXQoAXgBfBwBgDAALAGEBACRqYXZhL2xhbmcvaW52b2tlL1N0cmlu\n"
+          + "Z0NvbmNhdEZhY3RvcnkBAJgoTGphdmEvbGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcyRMb29rdXA7\n"
+          + "TGphdmEvbGFuZy9TdHJpbmc7TGphdmEvbGFuZy9pbnZva2UvTWV0aG9kVHlwZTtMamF2YS9sYW5n\n"
+          + "L1N0cmluZztbTGphdmEvbGFuZy9PYmplY3Q7KUxqYXZhL2xhbmcvaW52b2tlL0NhbGxTaXRlOwgA\n"
+          + "YwEAHnZlY3RvciBkaW1lbnNpb25zIGRpZmZlcjogASE9AQEADElubmVyQ2xhc3NlcwcAZgEAMGpk\n"
+          + "ay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rvck9wZXJhdG9ycyRBc3NvY2lhdGl2ZQEAC0Fzc29jaWF0\n"
+          + "aXZlBwBpAQAlamF2YS9sYW5nL2ludm9rZS9NZXRob2RIYW5kbGVzJExvb2t1cAcAawEAHmphdmEv\n"
+          + "bGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcwEABkxvb2t1cAAhABEAAgAAAAEAGgAUABUAAQA+AAAA\n"
+          + "AgA/AAMAAQAFAAYAAQBAAAAALwABAAEAAAAFKrcAAbEAAAACAEEAAAAGAAEAAAAZAEIAAAAMAAEA\n"
+          + "AAAFAEMARAAAAAkARQBGAAEAQAAAAewABAALAAAA6Cq+K76fABS7AAdZKr4rvroACQAAtwANvwM9\n"
+          + "C0YqvgWyABC5ABYBAGihAKiyABC4ABw6BLIAELgAHDoFsgAQKr6yABC5ABYBAGS5ACICADYGHBUG\n"
+          + "ogBpsgAQKhy4ACY6B7IAECscuAAmOggZBBkHGQi2ACq2AC46BLIAECocsgAQuQAWAQBguAAmOgmy\n"
+          + "ABArHLIAELkAFgEAYLgAJjoKGQUZCRkKtgAqtgAuOgUcBbIAELkAFgEAaGA9p/+XJRkEsgAxtgA3\n"
+          + "GQWyADG2ADdiYkYcKr6iABMlKxwwKhwwamJGhAIBp//tJa4AAAADAEEAAABWABUAAAAhAAcAIgAY\n"
+          + "ACQAGgAlABwAKAArACkAMwAqADsAKwBQACwAVgAtAGAALgBqAC8AeAAwAIsAMQCeADIArAAsALwA\n"
+          + "NADQADYA1gA3AOAANgDmADkAQgAAAHAACwBgAEwARwBIAAcAagBCAEkASAAIAIsAIQBKAEgACQCe\n"
+          + "AA4ASwBIAAoAMwCdAEwASAAEADsAlQBNAEgABQBQAIAATgBPAAYAAADoAFAAUQAAAAAA6ABSAFEA\n"
+          + "AQAaAM4AUwBPAAIAHADMAFQAVQADAFYAAAAgAAUY/wA3AAcHAFcHAFcBAgcAHQcAHQEAAPsAa/gA\n"
+          + "ExUACABYAAYAAQBAAAAAHwABAAAAAAAHsgA7swAQsQAAAAEAQQAAAAYAAQAAABoAAwBZAAAAAgBa\n"
+          + "AFsAAAAIAAEAXAABAGIAZAAAABIAAgBlADIAZwYJAGgAagBsABk=";
+
+  private static final MethodHandle DOTPRODUCT;
+  private static final MethodType DOTPRODUCT_TYPE =
+      MethodType.methodType(float.class, float[].class, float[].class);
+
+  static final class Loader extends ClassLoader {
+    Loader(ClassLoader parent) {
+      super(parent);
+    }
+
+    public Class<?> define(byte[] code) {
+      return defineClass("org.apache.lucene.util.VectorUtilSIMD", code, 0, code.length);
+    }
+  }
+
+  /**
+   * True if vectorized dot product is supported.
+   *
+   * <p>For this to work, you need java 16, and you need to opt-in by passing {@code --add-modules
+   * jdk.incubator.vector} to the java command line.
+   */
+  public static final boolean DOTPRODUCT_VECTORIZATION_SUPPORTED;
+
+  static {
+    MethodHandle impl = null;
+    boolean vectorSupported = false;
+
+    try {
+      impl =
+          MethodHandles.lookup().findStatic(VectorUtil.class, "dotProductScalar", DOTPRODUCT_TYPE);
+    } catch (NoSuchMethodException | IllegalAccessException e) {
+      throw new RuntimeException(e);
+    }
+
+    try {
+      Class<?> clazz =
+          new Loader(VectorUtil.class.getClassLoader())
+              .define(Base64.getMimeDecoder().decode(SIMD_BASE64));
+      impl = MethodHandles.lookup().findStatic(clazz, "dotProduct", DOTPRODUCT_TYPE);

Review comment:
       Move `MethodHandles.lookup()` to top of static block, as we need it multiple times.

##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"
+          + "BwAIAQAiamF2YS9sYW5nL0lsbGVnYWxBcmd1bWVudEV4Y2VwdGlvbhIAAAAKDAALAAwBABdtYWtl\n"
+          + "Q29uY2F0V2l0aENvbnN0YW50cwEAFihJSSlMamF2YS9sYW5nL1N0cmluZzsKAAcADgwABQAPAQAV\n"
+          + "KExqYXZhL2xhbmcvU3RyaW5nOylWCQARABIHABMMABQAFQEAJW9yZy9hcGFjaGUvbHVjZW5lL3V0\n"
+          + "aWwvVmVjdG9yVXRpbFNJTUQBAAdTUEVDSUVTAQAkTGpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rv\n"
+          + "clNwZWNpZXM7CwAXABgHABkMABoAGwEAImpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3RvclNwZWNp\n"
+          + "ZXMBAAZsZW5ndGgBAAMoKUkKAB0AHgcAHwwAIAAhAQAgamRrL2luY3ViYXRvci92ZWN0b3IvRmxv\n"
+          + "YXRWZWN0b3IBAAR6ZXJvAQBIKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0b3JTcGVjaWVzOylM\n"
+          + "amRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CwAXACMMACQAJQEACWxvb3BCb3VuZAEA\n"
+          + "BChJKUkKAB0AJwwAKAApAQAJZnJvbUFycmF5AQBLKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0\n"
+          + "b3JTcGVjaWVzO1tGSSlMamRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CgAdACsMACwA\n"
+          + "LQEAA211bAEAQShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yOylMamRrL2luY3ViYXRvci92\n"
+          + "ZWN0b3IvRmxvYXRWZWN0b3I7CgAdAC8MADAALQEAA2FkZAkAMgAzBwA0DAA1ADYBACRqZGsvaW5j\n"
+          + "dWJhdG9yL3ZlY3Rvci9WZWN0b3JPcGVyYXRvcnMBAANBREQBADJMamRrL2luY3ViYXRvci92ZWN0\n"
+          + "b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOwoAHQA4DAA5ADoBAAtyZWR1Y2VMYW5lcwEA\n"
+          + "NShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOylGCQAd\n"
+          + "ADwMAD0AFQEAEVNQRUNJRVNfUFJFRkVSUkVEAQAJU2lnbmF0dXJlAQA3TGpkay9pbmN1YmF0b3Iv\n"
+          + "dmVjdG9yL1ZlY3RvclNwZWNpZXM8TGphdmEvbGFuZy9GbG9hdDs+OwEABENvZGUBAA9MaW5lTnVt\n"
+          + "YmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aGlzAQAnTG9yZy9hcGFjaGUvbHVjZW5l\n"
+          + "L3V0aWwvVmVjdG9yVXRpbFNJTUQ7AQAKZG90UHJvZHVjdAEAByhbRltGKUYBAAJ2YQEAIkxqZGsv\n"
+          + "aW5jdWJhdG9yL3ZlY3Rvci9GbG9hdFZlY3RvcjsBAAJ2YgEAAnZjAQACdmQBAARhY2MxAQAEYWNj\n"
+          + "MgEACnVwcGVyQm91bmQBAAFJAQABYQEAAltGAQABYgEAAWkBAANyZXMBAAFGAQANU3RhY2tNYXBU\n"
+          + "YWJsZQcAUQEACDxjbGluaXQ+AQAKU291cmNlRmlsZQEAE1ZlY3RvclV0aWxTSU1ELmphdmEBABBC\n"
+          + "b290c3RyYXBNZXRob2RzDwYAXQoAXgBfBwBgDAALAGEBACRqYXZhL2xhbmcvaW52b2tlL1N0cmlu\n"
+          + "Z0NvbmNhdEZhY3RvcnkBAJgoTGphdmEvbGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcyRMb29rdXA7\n"
+          + "TGphdmEvbGFuZy9TdHJpbmc7TGphdmEvbGFuZy9pbnZva2UvTWV0aG9kVHlwZTtMamF2YS9sYW5n\n"
+          + "L1N0cmluZztbTGphdmEvbGFuZy9PYmplY3Q7KUxqYXZhL2xhbmcvaW52b2tlL0NhbGxTaXRlOwgA\n"
+          + "YwEAHnZlY3RvciBkaW1lbnNpb25zIGRpZmZlcjogASE9AQEADElubmVyQ2xhc3NlcwcAZgEAMGpk\n"
+          + "ay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rvck9wZXJhdG9ycyRBc3NvY2lhdGl2ZQEAC0Fzc29jaWF0\n"
+          + "aXZlBwBpAQAlamF2YS9sYW5nL2ludm9rZS9NZXRob2RIYW5kbGVzJExvb2t1cAcAawEAHmphdmEv\n"
+          + "bGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcwEABkxvb2t1cAAhABEAAgAAAAEAGgAUABUAAQA+AAAA\n"
+          + "AgA/AAMAAQAFAAYAAQBAAAAALwABAAEAAAAFKrcAAbEAAAACAEEAAAAGAAEAAAAZAEIAAAAMAAEA\n"
+          + "AAAFAEMARAAAAAkARQBGAAEAQAAAAewABAALAAAA6Cq+K76fABS7AAdZKr4rvroACQAAtwANvwM9\n"
+          + "C0YqvgWyABC5ABYBAGihAKiyABC4ABw6BLIAELgAHDoFsgAQKr6yABC5ABYBAGS5ACICADYGHBUG\n"
+          + "ogBpsgAQKhy4ACY6B7IAECscuAAmOggZBBkHGQi2ACq2AC46BLIAECocsgAQuQAWAQBguAAmOgmy\n"
+          + "ABArHLIAELkAFgEAYLgAJjoKGQUZCRkKtgAqtgAuOgUcBbIAELkAFgEAaGA9p/+XJRkEsgAxtgA3\n"
+          + "GQWyADG2ADdiYkYcKr6iABMlKxwwKhwwamJGhAIBp//tJa4AAAADAEEAAABWABUAAAAhAAcAIgAY\n"
+          + "ACQAGgAlABwAKAArACkAMwAqADsAKwBQACwAVgAtAGAALgBqAC8AeAAwAIsAMQCeADIArAAsALwA\n"
+          + "NADQADYA1gA3AOAANgDmADkAQgAAAHAACwBgAEwARwBIAAcAagBCAEkASAAIAIsAIQBKAEgACQCe\n"
+          + "AA4ASwBIAAoAMwCdAEwASAAEADsAlQBNAEgABQBQAIAATgBPAAYAAADoAFAAUQAAAAAA6ABSAFEA\n"
+          + "AQAaAM4AUwBPAAIAHADMAFQAVQADAFYAAAAgAAUY/wA3AAcHAFcHAFcBAgcAHQcAHQEAAPsAa/gA\n"
+          + "ExUACABYAAYAAQBAAAAAHwABAAAAAAAHsgA7swAQsQAAAAEAQQAAAAYAAQAAABoAAwBZAAAAAgBa\n"
+          + "AFsAAAAIAAEAXAABAGIAZAAAABIAAgBlADIAZwYJAGgAagBsABk=";
+
+  private static final MethodHandle DOTPRODUCT;
+  private static final MethodType DOTPRODUCT_TYPE =
+      MethodType.methodType(float.class, float[].class, float[].class);
+
+  static final class Loader extends ClassLoader {
+    Loader(ClassLoader parent) {
+      super(parent);
+    }
+
+    public Class<?> define(byte[] code) {
+      return defineClass("org.apache.lucene.util.VectorUtilSIMD", code, 0, code.length);
+    }
+  }
+
+  /**
+   * True if vectorized dot product is supported.
+   *
+   * <p>For this to work, you need java 16, and you need to opt-in by passing {@code --add-modules
+   * jdk.incubator.vector} to the java command line.
+   */
+  public static final boolean DOTPRODUCT_VECTORIZATION_SUPPORTED;
+
+  static {
+    MethodHandle impl = null;
+    boolean vectorSupported = false;
+
+    try {
+      impl =
+          MethodHandles.lookup().findStatic(VectorUtil.class, "dotProductScalar", DOTPRODUCT_TYPE);
+    } catch (NoSuchMethodException | IllegalAccessException e) {
+      throw new RuntimeException(e);
+    }
+
+    try {
+      Class<?> clazz =

Review comment:
       It's safe, because we catch Throwable. To be safe, maybe add AccessController around it. But the necessity for this requires more investigation, I am sure Robert checked this. :-)
   
   I think, we don't need extra permissions, as we only work in same java package. The code here is copypasted from Expressions module.

##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"

Review comment:
       I think we should have the source code of this class file available for regeneration. So anybody can compile with Java 11, but regeneration is only possible with exact Java 16 version.
   As it currently looks like I would not be sure if we can release this.
   
   If we don't add the original source code as a java file for regeneration, we should add source code here.




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594207200



##########
File path: gradle/defaults-java.gradle
##########
@@ -60,3 +60,14 @@ allprojects {
     }
   }
 }
+
+configure(project(":lucene:core")) {
+  plugins.withType(JavaPlugin) {

Review comment:
       For MMapDirectory my plan would be to have a separate lucene-mmap-foreign-jdk16.jar that compiled against JDK 16 that provides another directory. Code that wants to use it knows:
   - you have to add the JAR file
   - you have to hardcode new JDK16MMapDirectory() instead of FSDircetory.open()
   - add command line flags




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594200332



##########
File path: gradle/validation/error-prone.gradle
##########
@@ -22,10 +22,12 @@ if (!includeErrorProne) {
 
 allprojects { prj ->
   plugins.withType(JavaPlugin) {
-    prj.apply plugin: 'net.ltgt.errorprone'

Review comment:
       I think the problem is that the errorprone plugin has some META-INF/service, so as soon as it appears on classpath it is hooked into javac.
   
   So you latest fix seem to work around it (keep the dependency, but remove it from config, so it is not added to classpath). I did not fully understand you patch, but this looks fine.




----------------------------------------------------------------
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.

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 edited a comment on pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler edited a comment on pull request #18:
URL: https://github.com/apache/lucene/pull/18#issuecomment-800065901


   Another idea: We can remove the Methodhandles with the crazy try-catch block, if we'd define a static functional interface in this class, that is implemented by VectorUtil itsself, but also by the base64-encoded class. I am not sure if it's worth the trouble, as it makes regenerating the base64 harder, but then we only need the Loader and use `.asSubClass(DotProductInterface.class)`.


----------------------------------------------------------------
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.

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] dweiss commented on a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
dweiss commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594167422



##########
File path: gradle/validation/error-prone.gradle
##########
@@ -22,10 +22,12 @@ if (!includeErrorProne) {
 
 allprojects { prj ->
   plugins.withType(JavaPlugin) {
-    prj.apply plugin: 'net.ltgt.errorprone'

Review comment:
       I committed a different variant of jdk16 workaround and ran check, worked for me.




----------------------------------------------------------------
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.

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 pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on pull request #18:
URL: https://github.com/apache/lucene/pull/18#issuecomment-800065901


   Another idea: We can remove the Methodhandles with the crazy try-catch block, if we'd define a static functional interface in this class, that is implemented by VectorUtil and also by the base64-encoded class. I am not sure if it's woth the trouble, as it makes regenerating the base64 harder, but then we only need the Loader and use `.asSubClass(DotProductInterface.class)`.


----------------------------------------------------------------
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.

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] dweiss commented on a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
dweiss commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594143556



##########
File path: gradle/validation/error-prone.gradle
##########
@@ -22,10 +22,12 @@ if (!includeErrorProne) {
 
 allprojects { prj ->
   plugins.withType(JavaPlugin) {
-    prj.apply plugin: 'net.ltgt.errorprone'

Review comment:
       Does it fails with JDK16, even if it's not used?




----------------------------------------------------------------
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.

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] msokolov commented on a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
msokolov commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594820508



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"

Review comment:
       So I ran my usual HNSW benchmark using KnnGraphTester, which is 1M 256-dim vectors. This was run on my 2-core i7 laptop . Indexing performance improved from 412 sec to 292 sec, and search times improved somewhat less (latency column in table below). These benchmarks are kind of noisy, but they are predictive of what performance we'd expect in an application. Probably we aren't able to pump vectors through the L2 cache fast enough to keep up with the CPU at this point. We might be able to restructure the search code to try to do some pipelining?
   
   ## JDK16 --add-modules jdk.incubator.vector
   recall	latency	nDoc	fanout	maxConn	beamWidth	visited	index ms
   0.881	 0.49	1000000	10	20	50	1154	291684
   0.897	 0.60	1000000	25	20	50	1262	0
   0.913	 0.63	1000000	50	20	50	1444	0
   0.934	 0.92	1000000	100	20	50	1791	0
   
   ## JDK-11
   0.884	 0.63	1000000	10	20	50	1143	412111
   0.888	 0.66	1000000	25	20	50	1248	0
   0.913	 0.78	1000000	50	20	50	1434	0
   0.929	 1.00	1000000	100	20	50	1783	0




----------------------------------------------------------------
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.

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] msokolov commented on a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
msokolov commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594289302



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -30,66 +36,26 @@ public static float dotProduct(float[] a, float[] b) {
     if (a.length != b.length) {
       throw new IllegalArgumentException("vector dimensions differ: " + a.length + "!=" + b.length);
     }
-    float res = 0f;
-    /*
-     * If length of vector is larger than 8, we use unrolled dot product to accelerate the
-     * calculation.
-     */
-    int i;
-    for (i = 0; i < a.length % 8; i++) {
-      res += b[i] * a[i];
-    }
-    if (a.length < 8) {
-      return res;
-    }
-    for (; i + 31 < a.length; i += 32) {
-      res +=
-          b[i + 0] * a[i + 0]
-              + b[i + 1] * a[i + 1]
-              + b[i + 2] * a[i + 2]
-              + b[i + 3] * a[i + 3]
-              + b[i + 4] * a[i + 4]
-              + b[i + 5] * a[i + 5]
-              + b[i + 6] * a[i + 6]
-              + b[i + 7] * a[i + 7];
-      res +=
-          b[i + 8] * a[i + 8]
-              + b[i + 9] * a[i + 9]
-              + b[i + 10] * a[i + 10]
-              + b[i + 11] * a[i + 11]
-              + b[i + 12] * a[i + 12]
-              + b[i + 13] * a[i + 13]
-              + b[i + 14] * a[i + 14]
-              + b[i + 15] * a[i + 15];
-      res +=
-          b[i + 16] * a[i + 16]
-              + b[i + 17] * a[i + 17]
-              + b[i + 18] * a[i + 18]
-              + b[i + 19] * a[i + 19]
-              + b[i + 20] * a[i + 20]
-              + b[i + 21] * a[i + 21]
-              + b[i + 22] * a[i + 22]
-              + b[i + 23] * a[i + 23];
-      res +=
-          b[i + 24] * a[i + 24]
-              + b[i + 25] * a[i + 25]
-              + b[i + 26] * a[i + 26]
-              + b[i + 27] * a[i + 27]
-              + b[i + 28] * a[i + 28]
-              + b[i + 29] * a[i + 29]
-              + b[i + 30] * a[i + 30]
-              + b[i + 31] * a[i + 31];
+    int i = 0;
+    float res = 0;
+    // if the array size is large (2x platform vector size), its worth the overhead to vectorize
+    // vector loop is unrolled a single time (2 accumulators in parallel)
+    if (a.length >= 2 * SPECIES.length()) {

Review comment:
       very elegant! We had played around with this API last summer and failed to achieve gains. Maybe it has incubated! Or maybe we fumbled the attempt; anyway this is awesome gains for a very small amount of code which is right at the hot spot for vector search. I'll leave some thoughts about what strategy to pursue for making this available on the JIRA, but as for the code, it's great




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594822017



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"

Review comment:
       Thanks for testing (high level) @msokolov ! I think you are correct that is expected, it would not translate exactly to 5x faster indexing or whatever, as it isn't the only thing that is happening.
   
   From my inspection, there are a lot of other hotspots there, too. 
   
   But yeah, it is true that maybe we can start working those other hotspots off as well. For example, IMO it is silly with mmap directory for us to be decoding byte[] slowly into a float[] (readLEFloats or whatever). Vector API can use byte[] or even ByteBuffer directly (I assume any conversions are vectorized too, have not experimented with that).




----------------------------------------------------------------
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.

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] dweiss commented on a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
dweiss commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594161556



##########
File path: gradle/validation/error-prone.gradle
##########
@@ -22,10 +22,12 @@ if (!includeErrorProne) {
 
 allprojects { prj ->
   plugins.withType(JavaPlugin) {
-    prj.apply plugin: 'net.ltgt.errorprone'

Review comment:
       I'll handle this separately.




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594337476



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -30,66 +36,26 @@ public static float dotProduct(float[] a, float[] b) {
     if (a.length != b.length) {
       throw new IllegalArgumentException("vector dimensions differ: " + a.length + "!=" + b.length);
     }
-    float res = 0f;
-    /*
-     * If length of vector is larger than 8, we use unrolled dot product to accelerate the
-     * calculation.
-     */
-    int i;
-    for (i = 0; i < a.length % 8; i++) {
-      res += b[i] * a[i];
-    }
-    if (a.length < 8) {
-      return res;
-    }
-    for (; i + 31 < a.length; i += 32) {
-      res +=
-          b[i + 0] * a[i + 0]
-              + b[i + 1] * a[i + 1]
-              + b[i + 2] * a[i + 2]
-              + b[i + 3] * a[i + 3]
-              + b[i + 4] * a[i + 4]
-              + b[i + 5] * a[i + 5]
-              + b[i + 6] * a[i + 6]
-              + b[i + 7] * a[i + 7];
-      res +=
-          b[i + 8] * a[i + 8]
-              + b[i + 9] * a[i + 9]
-              + b[i + 10] * a[i + 10]
-              + b[i + 11] * a[i + 11]
-              + b[i + 12] * a[i + 12]
-              + b[i + 13] * a[i + 13]
-              + b[i + 14] * a[i + 14]
-              + b[i + 15] * a[i + 15];
-      res +=
-          b[i + 16] * a[i + 16]
-              + b[i + 17] * a[i + 17]
-              + b[i + 18] * a[i + 18]
-              + b[i + 19] * a[i + 19]
-              + b[i + 20] * a[i + 20]
-              + b[i + 21] * a[i + 21]
-              + b[i + 22] * a[i + 22]
-              + b[i + 23] * a[i + 23];
-      res +=
-          b[i + 24] * a[i + 24]
-              + b[i + 25] * a[i + 25]
-              + b[i + 26] * a[i + 26]
-              + b[i + 27] * a[i + 27]
-              + b[i + 28] * a[i + 28]
-              + b[i + 29] * a[i + 29]
-              + b[i + 30] * a[i + 30]
-              + b[i + 31] * a[i + 31];
+    int i = 0;
+    float res = 0;
+    // if the array size is large (2x platform vector size), its worth the overhead to vectorize
+    // vector loop is unrolled a single time (2 accumulators in parallel)
+    if (a.length >= 2 * SPECIES.length()) {

Review comment:
       @msokolov here's a few notes of troubles i ran into in case it helps for the next time:
   * start with "full-performance" example in the JEP/javadocs and then iterate from there.
   * don't use "single masked vector op" at the end. don't use masked ops at all :)
   * don't put kernel "last" like current code in master. it must be "first" (alignment restrictions i think).
   * loop structure is important, otherwise whole loop gets slow (bounds checks I think). See the tricks i had to do with upperBound: that's the only way i was able to get a fast loop.
   
   I may revisit the existing scalar code in master and see if things can be improved there, too.




----------------------------------------------------------------
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.

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 pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
rmuir commented on pull request #18:
URL: https://github.com/apache/lucene/pull/18#issuecomment-802760466


   Looks like openjdk is just teasing us here. Incubating API is not really intended to transition to a real API anytime soon:  https://openjdk.java.net/jeps/8261663
   
   So we may expect java 21 or java 24 before we can use this stuff :(


-- 
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.

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 pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on pull request #18:
URL: https://github.com/apache/lucene/pull/18#issuecomment-802763003


   Maybe leave this pull request open as a DRAFT (like mine). So we can keep an eye on it.


-- 
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.

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] msokolov commented on a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
msokolov commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594309799



##########
File path: gradle/defaults-java.gradle
##########
@@ -60,3 +60,14 @@ allprojects {
     }
   }
 }
+
+configure(project(":lucene:core")) {
+  plugins.withType(JavaPlugin) {

Review comment:
       I'll just repeat what I think I'm hearing since I'm slow ... It sounds like  a way forward is something like this?
   
   1. Use reflection to search for this new implementation of `static float SuperDuperVectors.dotProduct(float[], float[])` and/or fall back to the old way?
   2. Provide a {{vector-api.jar}} with a {{VectorDotProductSimd}} or some such just to wrap this object, and maybe other Vector stuff like Euclidean norm.
   3. Get the build sorted out so that the plugin can be built conditionally, depending on JDK used.
   
   Then users can incorporate that jar and provide the proper JDK command line flag to include the incubating vector api support, and that's it?




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594952973



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"

Review comment:
       > But yeah, it is true that maybe we can start working those other hotspots off as well. For example, IMO it is silly with mmap directory for us to be decoding byte[] slowly into a float[] (readLEFloats or whatever). Vector API can use byte[] or even ByteBuffer directly (I assume any conversions are vectorized too, have not experimented with that).
   
   It gets even worse with MMapDirectory version 2 for Java 16. So IMHO, once we are really on JDK 17 minimum, we should change the method signatures of IndexInpout and replace our `void readLEFloats(float[])` by `FloatVector readFloatVector()`, on MMapDirectory this can use a ByteBuffer oder MemorySegmrnt directly on the mmapped contents (if platform endianess is LE). This would spare millions of native->heap arraycopy actions for nonsense.




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r595070477



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"
+          + "BwAIAQAiamF2YS9sYW5nL0lsbGVnYWxBcmd1bWVudEV4Y2VwdGlvbhIAAAAKDAALAAwBABdtYWtl\n"
+          + "Q29uY2F0V2l0aENvbnN0YW50cwEAFihJSSlMamF2YS9sYW5nL1N0cmluZzsKAAcADgwABQAPAQAV\n"
+          + "KExqYXZhL2xhbmcvU3RyaW5nOylWCQARABIHABMMABQAFQEAJW9yZy9hcGFjaGUvbHVjZW5lL3V0\n"
+          + "aWwvVmVjdG9yVXRpbFNJTUQBAAdTUEVDSUVTAQAkTGpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rv\n"
+          + "clNwZWNpZXM7CwAXABgHABkMABoAGwEAImpkay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3RvclNwZWNp\n"
+          + "ZXMBAAZsZW5ndGgBAAMoKUkKAB0AHgcAHwwAIAAhAQAgamRrL2luY3ViYXRvci92ZWN0b3IvRmxv\n"
+          + "YXRWZWN0b3IBAAR6ZXJvAQBIKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0b3JTcGVjaWVzOylM\n"
+          + "amRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CwAXACMMACQAJQEACWxvb3BCb3VuZAEA\n"
+          + "BChJKUkKAB0AJwwAKAApAQAJZnJvbUFycmF5AQBLKExqZGsvaW5jdWJhdG9yL3ZlY3Rvci9WZWN0\n"
+          + "b3JTcGVjaWVzO1tGSSlMamRrL2luY3ViYXRvci92ZWN0b3IvRmxvYXRWZWN0b3I7CgAdACsMACwA\n"
+          + "LQEAA211bAEAQShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yOylMamRrL2luY3ViYXRvci92\n"
+          + "ZWN0b3IvRmxvYXRWZWN0b3I7CgAdAC8MADAALQEAA2FkZAkAMgAzBwA0DAA1ADYBACRqZGsvaW5j\n"
+          + "dWJhdG9yL3ZlY3Rvci9WZWN0b3JPcGVyYXRvcnMBAANBREQBADJMamRrL2luY3ViYXRvci92ZWN0\n"
+          + "b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOwoAHQA4DAA5ADoBAAtyZWR1Y2VMYW5lcwEA\n"
+          + "NShMamRrL2luY3ViYXRvci92ZWN0b3IvVmVjdG9yT3BlcmF0b3JzJEFzc29jaWF0aXZlOylGCQAd\n"
+          + "ADwMAD0AFQEAEVNQRUNJRVNfUFJFRkVSUkVEAQAJU2lnbmF0dXJlAQA3TGpkay9pbmN1YmF0b3Iv\n"
+          + "dmVjdG9yL1ZlY3RvclNwZWNpZXM8TGphdmEvbGFuZy9GbG9hdDs+OwEABENvZGUBAA9MaW5lTnVt\n"
+          + "YmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aGlzAQAnTG9yZy9hcGFjaGUvbHVjZW5l\n"
+          + "L3V0aWwvVmVjdG9yVXRpbFNJTUQ7AQAKZG90UHJvZHVjdAEAByhbRltGKUYBAAJ2YQEAIkxqZGsv\n"
+          + "aW5jdWJhdG9yL3ZlY3Rvci9GbG9hdFZlY3RvcjsBAAJ2YgEAAnZjAQACdmQBAARhY2MxAQAEYWNj\n"
+          + "MgEACnVwcGVyQm91bmQBAAFJAQABYQEAAltGAQABYgEAAWkBAANyZXMBAAFGAQANU3RhY2tNYXBU\n"
+          + "YWJsZQcAUQEACDxjbGluaXQ+AQAKU291cmNlRmlsZQEAE1ZlY3RvclV0aWxTSU1ELmphdmEBABBC\n"
+          + "b290c3RyYXBNZXRob2RzDwYAXQoAXgBfBwBgDAALAGEBACRqYXZhL2xhbmcvaW52b2tlL1N0cmlu\n"
+          + "Z0NvbmNhdEZhY3RvcnkBAJgoTGphdmEvbGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcyRMb29rdXA7\n"
+          + "TGphdmEvbGFuZy9TdHJpbmc7TGphdmEvbGFuZy9pbnZva2UvTWV0aG9kVHlwZTtMamF2YS9sYW5n\n"
+          + "L1N0cmluZztbTGphdmEvbGFuZy9PYmplY3Q7KUxqYXZhL2xhbmcvaW52b2tlL0NhbGxTaXRlOwgA\n"
+          + "YwEAHnZlY3RvciBkaW1lbnNpb25zIGRpZmZlcjogASE9AQEADElubmVyQ2xhc3NlcwcAZgEAMGpk\n"
+          + "ay9pbmN1YmF0b3IvdmVjdG9yL1ZlY3Rvck9wZXJhdG9ycyRBc3NvY2lhdGl2ZQEAC0Fzc29jaWF0\n"
+          + "aXZlBwBpAQAlamF2YS9sYW5nL2ludm9rZS9NZXRob2RIYW5kbGVzJExvb2t1cAcAawEAHmphdmEv\n"
+          + "bGFuZy9pbnZva2UvTWV0aG9kSGFuZGxlcwEABkxvb2t1cAAhABEAAgAAAAEAGgAUABUAAQA+AAAA\n"
+          + "AgA/AAMAAQAFAAYAAQBAAAAALwABAAEAAAAFKrcAAbEAAAACAEEAAAAGAAEAAAAZAEIAAAAMAAEA\n"
+          + "AAAFAEMARAAAAAkARQBGAAEAQAAAAewABAALAAAA6Cq+K76fABS7AAdZKr4rvroACQAAtwANvwM9\n"
+          + "C0YqvgWyABC5ABYBAGihAKiyABC4ABw6BLIAELgAHDoFsgAQKr6yABC5ABYBAGS5ACICADYGHBUG\n"
+          + "ogBpsgAQKhy4ACY6B7IAECscuAAmOggZBBkHGQi2ACq2AC46BLIAECocsgAQuQAWAQBguAAmOgmy\n"
+          + "ABArHLIAELkAFgEAYLgAJjoKGQUZCRkKtgAqtgAuOgUcBbIAELkAFgEAaGA9p/+XJRkEsgAxtgA3\n"
+          + "GQWyADG2ADdiYkYcKr6iABMlKxwwKhwwamJGhAIBp//tJa4AAAADAEEAAABWABUAAAAhAAcAIgAY\n"
+          + "ACQAGgAlABwAKAArACkAMwAqADsAKwBQACwAVgAtAGAALgBqAC8AeAAwAIsAMQCeADIArAAsALwA\n"
+          + "NADQADYA1gA3AOAANgDmADkAQgAAAHAACwBgAEwARwBIAAcAagBCAEkASAAIAIsAIQBKAEgACQCe\n"
+          + "AA4ASwBIAAoAMwCdAEwASAAEADsAlQBNAEgABQBQAIAATgBPAAYAAADoAFAAUQAAAAAA6ABSAFEA\n"
+          + "AQAaAM4AUwBPAAIAHADMAFQAVQADAFYAAAAgAAUY/wA3AAcHAFcHAFcBAgcAHQcAHQEAAPsAa/gA\n"
+          + "ExUACABYAAYAAQBAAAAAHwABAAAAAAAHsgA7swAQsQAAAAEAQQAAAAYAAQAAABoAAwBZAAAAAgBa\n"
+          + "AFsAAAAIAAEAXAABAGIAZAAAABIAAgBlADIAZwYJAGgAagBsABk=";
+
+  private static final MethodHandle DOTPRODUCT;
+  private static final MethodType DOTPRODUCT_TYPE =
+      MethodType.methodType(float.class, float[].class, float[].class);
+
+  static final class Loader extends ClassLoader {
+    Loader(ClassLoader parent) {
+      super(parent);
+    }
+
+    public Class<?> define(byte[] code) {
+      return defineClass("org.apache.lucene.util.VectorUtilSIMD", code, 0, code.length);
+    }
+  }
+
+  /**
+   * True if vectorized dot product is supported.
+   *
+   * <p>For this to work, you need java 16, and you need to opt-in by passing {@code --add-modules
+   * jdk.incubator.vector} to the java command line.
+   */
+  public static final boolean DOTPRODUCT_VECTORIZATION_SUPPORTED;
+
+  static {
+    MethodHandle impl = null;
+    boolean vectorSupported = false;
+
+    try {
+      impl =
+          MethodHandles.lookup().findStatic(VectorUtil.class, "dotProductScalar", DOTPRODUCT_TYPE);
+    } catch (NoSuchMethodException | IllegalAccessException e) {
+      throw new RuntimeException(e);
+    }
+
+    try {
+      Class<?> clazz =

Review comment:
       it requires createClassLoader which is documented as evil. sorry, i didnt try to make this PR "clean" or refine it.
   
   I tried to work on solutions, and got very frustrated. this little function should be 5 lines of code in almost any programming language. But a combination of things here add up to make the java programming language *TERRIBLE*. I quickly through this together as an act of retaliation.
   
   So I need a break from it as I am too frustrated. If you wish to take over the PR, please feel free!




----------------------------------------------------------------
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.

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 pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
rmuir commented on pull request #18:
URL: https://github.com/apache/lucene/pull/18#issuecomment-799870607


   By the way, the precommit and tests pass (despite the pure evil happening here).
   
   The github checker is just flaky right now (read timeouts and 502 errors downloading the internet). You may just re-run it later when github's networking is again functional.


----------------------------------------------------------------
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.

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] msokolov commented on a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
msokolov commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594309799



##########
File path: gradle/defaults-java.gradle
##########
@@ -60,3 +60,14 @@ allprojects {
     }
   }
 }
+
+configure(project(":lucene:core")) {
+  plugins.withType(JavaPlugin) {

Review comment:
       I'll just repeat what I think I'm hearing since I'm slow ... It sounds like  a way forward is something like this?
   
   1. Use reflection to search for this new implementation of `static float SuperDuperVectors.dotProduct(float[], float[])` and/or fall back to the old way?
   2. Provide a {{vector-api.jar}} with `SuperDuperVectors` in it (or some such) just to wrap this object, and maybe other Vector stuff like Euclidean norm.
   3. Get the build sorted out so that the plugin can be built conditionally, depending on JDK used.
   
   Then users can incorporate that jar and provide the proper JDK command line flag to include the incubating vector api support, and that's it?




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
rmuir commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594153728



##########
File path: gradle/validation/error-prone.gradle
##########
@@ -22,10 +22,12 @@ if (!includeErrorProne) {
 
 allprojects { prj ->
   plugins.withType(JavaPlugin) {
-    prj.apply plugin: 'net.ltgt.errorprone'

Review comment:
       yes, unfortunately it does:
   ```
   $ ./gradlew -Pruntime.java.home=/home/rmuir/Downloads/jdk-16 compileJava
   ...
   > Task :lucene:core:compileJava FAILED
   Exception in thread "main" java.lang.IllegalAccessError: class com.google.errorprone.ErrorProneJavacPlugin (in unnamed module @0x31610302) cannot access class com.sun.tools.javac.api.BasicJavacTask (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.api to unnamed module @0x31610302
           at com.google.errorprone.ErrorProneJavacPlugin.init(ErrorProneJavacPlugin.java:38)
           at jdk.compiler/com.sun.tools.javac.api.BasicJavacTask.initPlugin(BasicJavacTask.java:255)
           at jdk.compiler/com.sun.tools.javac.api.BasicJavacTask.initPlugins(BasicJavacTask.java:229)
           at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:292)
           at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
           at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
           at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
   ```




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594314227



##########
File path: gradle/defaults-java.gradle
##########
@@ -60,3 +60,14 @@ allprojects {
     }
   }
 }
+
+configure(project(":lucene:core")) {
+  plugins.withType(JavaPlugin) {

Review comment:
       Not reflection, but a combined MethodHandle.




----------------------------------------------------------------
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.

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 a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
uschindler commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594952973



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"

Review comment:
       > But yeah, it is true that maybe we can start working those other hotspots off as well. For example, IMO it is silly with mmap directory for us to be decoding byte[] slowly into a float[] (readLEFloats or whatever). Vector API can use byte[] or even ByteBuffer directly (I assume any conversions are vectorized too, have not experimented with that).
   
   It gets even worse with MMapDirectory version 2 for Java 16. So IMHO, once we are really on JDK 17 minimum, we should change the method signatures of IndexInpout and replace our `void readLEFloats(float[])` by `FloatVector readFloatVector()`, on MMapDirectory this can use a ByteBuffer oder MemorySegemnt directly on the mmapped contents. This would space millions of native->heap arraycopy actions for nonsense.

##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"

Review comment:
       > But yeah, it is true that maybe we can start working those other hotspots off as well. For example, IMO it is silly with mmap directory for us to be decoding byte[] slowly into a float[] (readLEFloats or whatever). Vector API can use byte[] or even ByteBuffer directly (I assume any conversions are vectorized too, have not experimented with that).
   
   It gets even worse with MMapDirectory version 2 for Java 16. So IMHO, once we are really on JDK 17 minimum, we should change the method signatures of IndexInpout and replace our `void readLEFloats(float[])` by `FloatVector readFloatVector()`, on MMapDirectory this can use a ByteBuffer oder MemorySegemnt directly on the mmapped contents. This would spare millions of native->heap arraycopy actions for nonsense.




----------------------------------------------------------------
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.

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] msokolov commented on a change in pull request #18: LUCENE-9838: simd version of VectorUtil.dotProduct

Posted by GitBox <gi...@apache.org>.
msokolov commented on a change in pull request #18:
URL: https://github.com/apache/lucene/pull/18#discussion_r594806743



##########
File path: lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
##########
@@ -17,16 +17,123 @@
 
 package org.apache.lucene.util;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.util.Base64;
+
 /** Utilities for computations with numeric arrays */
 public final class VectorUtil {
 
   private VectorUtil() {}
 
+  // org.apache.lucene.util.VectorUtilSIMD#dotProduct(float[], float[])
+  private static final String SIMD_BASE64 =
+      "yv66vgAAADwAbQoAAgADBwAEDAAFAAYBABBqYXZhL2xhbmcvT2JqZWN0AQAGPGluaXQ+AQADKClW\n"

Review comment:
       oh man, this is pretty funny, evil whatever. It's nice that it's self contained and doesn't require any build shenanigans. I guess it might be difficult to modify the source code though :) I'll run a test in a vector benchmark to see what happens there




----------------------------------------------------------------
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.

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