Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -543,20 +543,14 @@ private static boolean addVectorizationOptions(
Provider<Boolean> defaultVectorizationOption =
buildOptions.addBooleanOption(
"tests.defaultvectorization",
"Uses defaults for running tests with correct JVM settings to test Panama vectorization (tests.jvmargs, tests.vectorsize, tests.forceintegervectors).",
"Uses defaults for running tests with correct JVM settings to test Panama vectorization (tests.jvmargs, tests.vectorsize).",
false);
buildOptions.addOption(
"tests.vectorsize",
"Sets preferred vector size in bits.",
project.provider(() -> defaultVectorizationOption.get() ? "default" : randomVectorSize));

buildOptions.addBooleanOption(
"tests.forceintegervectors",
"Forces use of integer vectors even when slow.",
project.provider(
() -> defaultVectorizationOption.get() ? false : (randomVectorSize != "default")));

optionsInheritedAsProperties.addAll(List.of("tests.vectorsize", "tests.forceintegervectors"));
optionsInheritedAsProperties.add("tests.vectorsize");

return defaultVectorizationOption.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
public abstract class VectorizationProvider {

static final OptionalInt TESTS_VECTOR_SIZE;
static final boolean TESTS_FORCE_INTEGER_VECTORS;
static final int UPPER_JAVA_FEATURE_VERSION = getUpperJavaFeatureVersion();

static {
Expand All @@ -63,16 +62,6 @@ public abstract class VectorizationProvider {
// ignored
}
TESTS_VECTOR_SIZE = vs;

boolean enforce = false;
Comment thread
uschindler marked this conversation as resolved.
try {
enforce = Boolean.getBoolean("tests.forceintegervectors");
} catch (
@SuppressWarnings("unused")
SecurityException se) {
// ignored
}
TESTS_FORCE_INTEGER_VECTORS = enforce;
}

private static final String UPPER_JAVA_FEATURE_VERSION_SYSPROP =
Expand Down Expand Up @@ -157,9 +146,9 @@ static VectorizationProvider lookup(boolean testMode) {
vectorMod.ifPresent(VectorizationProvider.class.getModule()::addReads);
// check for testMode and otherwise fallback to default if slowness could happen
if (!testMode) {
if (TESTS_VECTOR_SIZE.isPresent() || TESTS_FORCE_INTEGER_VECTORS) {
if (TESTS_VECTOR_SIZE.isPresent()) {
LOG.warning(
"Vector bitsize and/or integer vectors enforcement; using default vectorization provider outside of testMode");
"Vector bitsize enforcement; using default vectorization provider outside of testMode");
return new DefaultVectorizationProvider();
}
if (Constants.IS_CLIENT_VM) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class PanamaVectorConstants {
static final int PREFERRED_VECTOR_BITSIZE;

/** Whether integer vectors can be trusted to actually be fast. */
static final boolean HAS_FAST_INTEGER_VECTORS;
static final boolean ENABLE_INTEGER_VECTORS;

static final VectorSpecies<Long> PRERERRED_LONG_SPECIES;
static final VectorSpecies<Integer> PRERERRED_INT_SPECIES;
Expand All @@ -42,8 +42,8 @@ final class PanamaVectorConstants {
// to be fair, they do document this thing only works well with AVX2/AVX3 and Neon
boolean isAMD64withoutAVX2 =
Constants.OS_ARCH.equals("amd64") && PREFERRED_VECTOR_BITSIZE < 256;
HAS_FAST_INTEGER_VECTORS =
VectorizationProvider.TESTS_FORCE_INTEGER_VECTORS || (isAMD64withoutAVX2 == false);
ENABLE_INTEGER_VECTORS =
(isAMD64withoutAVX2 == false) || VectorizationProvider.TESTS_VECTOR_SIZE.isPresent();

PRERERRED_LONG_SPECIES =
VectorSpecies.of(long.class, VectorShape.forBitSize(PREFERRED_VECTOR_BITSIZE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
*
* <ul>
* <li>tests.vectorsize (int)
* <li>tests.forceintegervectors (boolean)
* </ul>
*
* Setting these properties will make this code run EXTREMELY slow!
Expand Down Expand Up @@ -313,9 +312,8 @@ public static int dotProduct(MemorySegment a, MemorySegment b) {
int i = 0;
int res = 0;

// only vectorize if we'll at least enter the loop a single time, and we have at least 128-bit
// vectors (256-bit on intel to dodge performance landmines)
if (a.byteSize() >= 16 && PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) {
// only vectorize if we'll at least enter the loop a single time
if (a.byteSize() >= 16) {
// compute vectorized dot product consistent with VPDPBUSD instruction
if (VECTOR_BITSIZE >= 512) {
i += BYTE_SPECIES.loopBound(a.byteSize());
Expand Down Expand Up @@ -409,7 +407,7 @@ public int int4DotProduct(byte[] a, boolean apacked, byte[] b, boolean bpacked)
} else if (VECTOR_BITSIZE == 256) {
i += ByteVector.SPECIES_128.loopBound(packed.length);
res += dotProductBody256Int4Packed(unpacked, packed, i);
} else if (PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) {
} else {
i += ByteVector.SPECIES_64.loopBound(packed.length);
res += dotProductBody128Int4Packed(unpacked, packed, i);
}
Expand All @@ -425,7 +423,7 @@ public int int4DotProduct(byte[] a, boolean apacked, byte[] b, boolean bpacked)
} else {
if (VECTOR_BITSIZE >= 512 || VECTOR_BITSIZE == 256) {
return dotProduct(a, b);
} else if (a.length >= 32 && PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) {
} else if (a.length >= 32) {
i += ByteVector.SPECIES_128.loopBound(a.length);
res += int4DotProductBody128(a, b, i);
}
Expand Down Expand Up @@ -581,9 +579,8 @@ public static float cosine(MemorySegment a, MemorySegment b) {
int norm1 = 0;
int norm2 = 0;

// only vectorize if we'll at least enter the loop a single time, and we have at least 128-bit
// vectors (256-bit on intel to dodge performance landmines)
if (a.byteSize() >= 16 && PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) {
// only vectorize if we'll at least enter the loop a single time
if (a.byteSize() >= 16) {
final float[] ret;
if (VECTOR_BITSIZE >= 512) {
i += BYTE_SPECIES.loopBound((int) a.byteSize());
Expand Down Expand Up @@ -704,9 +701,8 @@ public static int squareDistance(MemorySegment a, MemorySegment b) {
int i = 0;
int res = 0;

// only vectorize if we'll at least enter the loop a single time, and we have at least 128-bit
// vectors (256-bit on intel to dodge performance landmines)
if (a.byteSize() >= 16 && PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) {
// only vectorize if we'll at least enter the loop a single time
if (a.byteSize() >= 16) {
if (VECTOR_BITSIZE >= 256) {
i += BYTE_SPECIES.loopBound((int) a.byteSize());
res += squareDistanceBody256(a, b, i);
Expand Down Expand Up @@ -798,7 +794,7 @@ public int findNextGEQ(int[] buffer, int target, int from, int to) {
public long int4BitDotProduct(byte[] q, byte[] d) {
assert q.length == d.length * 4;
// 128 / 8 == 16
if (d.length >= 16 && PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS) {
if (d.length >= 16) {
if (VECTOR_BITSIZE >= 256) {
return int4BitDotProduct256(q, d);
} else if (VECTOR_BITSIZE == 128) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ final class PanamaVectorizationProvider extends VectorizationProvider {
"Vector bit size is less than 128: " + PanamaVectorConstants.PREFERRED_VECTOR_BITSIZE);
}

if (PanamaVectorConstants.ENABLE_INTEGER_VECTORS == false) {
throw new UnsupportedOperationException(
"CPU type or flags do not guarantee support for fast integer vectorization");
}

this.vectorUtilSupport = new PanamaVectorUtilSupport();

var log = Logger.getLogger(getClass().getName());
Expand All @@ -54,7 +59,7 @@ final class PanamaVectorizationProvider extends VectorizationProvider {
"Java vector incubator API enabled; uses preferredBitSize=%d%s%s",
Comment thread
uschindler marked this conversation as resolved.
PanamaVectorConstants.PREFERRED_VECTOR_BITSIZE,
Constants.HAS_FAST_VECTOR_FMA ? "; FMA enabled" : "",
PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS ? "" : "; floating-point vectors only"));
VectorizationProvider.TESTS_VECTOR_SIZE.isPresent() ? "; testMode enabled" : ""));
}

@Override
Expand All @@ -69,8 +74,7 @@ public FlatVectorsScorer getLucene99FlatVectorsScorer() {

@Override
public PostingDecodingUtil newPostingDecodingUtil(IndexInput input) throws IOException {
if (PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS
&& input instanceof MemorySegmentAccessInput msai) {
if (input instanceof MemorySegmentAccessInput msai) {
MemorySegment ms = msai.segmentSliceOrNull(0, input.length());
if (ms != null) {
return new MemorySegmentPostingDecodingUtil(input, ms);
Expand Down
Loading