Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -42,8 +42,7 @@ 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);
HAS_FAST_INTEGER_VECTORS = isAMD64withoutAVX2 == false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above and let's do it like that:

HAS_FAST_INTEGER_VECTORS = isAMD64withoutAVX2 == false || TESTS_VECTOR_SIZE.isPresent()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the special test mode I'd like to test our code, although CPU is wrong.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can better contain this constant we can also give it a better name. The idea is: if you are on x86, you need AVX2 as a minimum baseline for us to support vectors.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's OK. I just want the condition to stay alive here.


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,10 @@ final class PanamaVectorizationProvider extends VectorizationProvider {
"Vector bit size is less than 128: " + PanamaVectorConstants.PREFERRED_VECTOR_BITSIZE);
}

if (PanamaVectorConstants.HAS_FAST_INTEGER_VECTORS == false) {
throw new UnsupportedOperationException("No integer vector support");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this message a bit more verbose as this is logged to enduser in a warning (see VectorizationProvider around line 169).

Maybe "CPU flags do not guarantee fast integer vectors".

}

this.vectorUtilSupport = new PanamaVectorUtilSupport();

var log = Logger.getLogger(getClass().getName());
Expand All @@ -53,8 +57,7 @@ final class PanamaVectorizationProvider extends VectorizationProvider {
Locale.ENGLISH,
"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"));
Constants.HAS_FAST_VECTOR_FMA ? "; FMA enabled" : ""));
}

@Override
Expand Down
Loading