kaivalnp commented on code in PR #17013: URL: https://github.com/apache/lucene/pull/17013#discussion_r4624710571
########## lucene/core/src/java25/org/apache/lucene/internal/vectorization/MemorySegmentQuantizedVectorOps.java: ########## @@ -0,0 +1,397 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.internal.vectorization; + +import static java.lang.foreign.ValueLayout.JAVA_BYTE; +import static java.lang.foreign.ValueLayout.JAVA_LONG_UNALIGNED; +import static java.nio.ByteOrder.LITTLE_ENDIAN; +import static jdk.incubator.vector.VectorOperators.ADD; +import static jdk.incubator.vector.VectorOperators.BIT_COUNT; +import static jdk.incubator.vector.VectorOperators.LSHL; +import static jdk.incubator.vector.VectorOperators.LSHR; +import static jdk.incubator.vector.VectorOperators.ZERO_EXTEND_B2I; +import static jdk.incubator.vector.VectorOperators.ZERO_EXTEND_B2S; +import static jdk.incubator.vector.VectorOperators.ZERO_EXTEND_S2I; +import static org.apache.lucene.internal.vectorization.PanamaVectorConstants.PRERERRED_INT_SPECIES; +import static org.apache.lucene.internal.vectorization.PanamaVectorUtilSupport.BYTE_SPECIES; +import static org.apache.lucene.internal.vectorization.PanamaVectorUtilSupport.BYTE_SPECIES_FULL; +import static org.apache.lucene.internal.vectorization.PanamaVectorUtilSupport.SHORT_SPECIES; +import static org.apache.lucene.internal.vectorization.PanamaVectorUtilSupport.VECTOR_BITSIZE; + +import java.lang.foreign.MemorySegment; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; +import java.nio.ByteOrder; +import jdk.incubator.vector.ByteVector; +import jdk.incubator.vector.IntVector; +import jdk.incubator.vector.LongVector; +import jdk.incubator.vector.ShortVector; +import jdk.incubator.vector.Vector; +import jdk.incubator.vector.VectorShape; +import jdk.incubator.vector.VectorSpecies; + +/** + * Dot products of a quantized query on heap with quantized vectors read in place from a {@link + * MemorySegment}, several vectors per pass so that the CPU overlaps their cache misses instead of + * waiting for the misses of one vector after the other. The 8 bit kernels read four vectors per + * pass; the 4, 2 and 1 bit kernels read two, because a pass over four would exceed the budget C2 Review Comment: I dug a bit deeper: bulk-scoring 4 vectors at a time made the function too large to be inlined; there's some complication with C2's inlining and/or escape analysis that caused a `LongVector` returned from a helper function to become boxed! Adding flags like `-XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining -XX:+PrintCompilation` showed: ``` @ 437 ...MemorySegmentQuantizedVectorOps::loadLongs (15 bytes) failed to inline: NodeCountInliningCutoff ``` The Vector API functions themselves are forcefully inlined, so I was able to work around this complication by expanding helpers in-place and creating a large function. I've now added a commit to bulk-score 4 vectors for **_all_** quantization levels. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
