Skip to content

Commit

Permalink
8345798: Update VectorAPI Benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jatin-bhateja committed Dec 9, 2024
1 parent 309b8e6 commit de83fd9
Show file tree
Hide file tree
Showing 37 changed files with 4,927 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package org.openjdk.bench.jdk.incubator.vector.operation;

import java.util.concurrent.TimeUnit;
import java.util.function.IntFunction;
import jdk.incubator.vector.VectorMath;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,222 @@ public void MAX(Blackhole bh) {
bh.consume(r);
}

@Benchmark
public void UMIN(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.UMIN, bv).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void UMINMasked(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());
boolean[] mask = fm.apply(SPECIES.length());
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.UMIN, bv, vmask).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void UMAX(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.UMAX, bv).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void UMAXMasked(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());
boolean[] mask = fm.apply(SPECIES.length());
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.UMAX, bv, vmask).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void SADD(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.SADD, bv).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void SADDMasked(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());
boolean[] mask = fm.apply(SPECIES.length());
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.SADD, bv, vmask).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void SSUB(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.SSUB, bv).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void SSUBMasked(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());
boolean[] mask = fm.apply(SPECIES.length());
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.SSUB, bv, vmask).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void SUADD(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.SUADD, bv).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void SUADDMasked(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());
boolean[] mask = fm.apply(SPECIES.length());
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.SUADD, bv, vmask).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void SUSUB(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.SUSUB, bv).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void SUSUBMasked(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());
boolean[] mask = fm.apply(SPECIES.length());
VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.SUSUB, bv, vmask).intoArray(r, i);
}
}

bh.consume(r);
}

@Benchmark
public void ANDLanes(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
Expand Down Expand Up @@ -1275,12 +1491,15 @@ public void allTrue(Blackhole bh) {
@Benchmark
public void withLane(Blackhole bh) {
byte[] a = fa.apply(SPECIES.length());
byte[] b = fb.apply(SPECIES.length());
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
av.withLane((j++ & (SPECIES.length()-1)), (byte)(65535+i)).intoArray(r, i);
av.withLane(j, b[i + j]).intoArray(r, i);
a[i + j] = b[i + j];
j = (j + 1) & (SPECIES.length() - 1);
}
}

Expand Down Expand Up @@ -1437,7 +1656,7 @@ public Object GE() {
return m;
}
@Benchmark
public Object UNSIGNED_LT() {
public Object ULT() {
byte[] a = fa.apply(size);
byte[] b = fb.apply(size);
boolean[] ms = fmt.apply(size);
Expand All @@ -1449,14 +1668,14 @@ public Object UNSIGNED_LT() {
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);

// accumulate results, so JIT can't eliminate relevant computations
m = m.and(av.compare(VectorOperators.UNSIGNED_LT, bv));
m = m.and(av.compare(VectorOperators.ULT, bv));
}
}

return m;
}
@Benchmark
public Object UNSIGNED_GT() {
public Object UGT() {
byte[] a = fa.apply(size);
byte[] b = fb.apply(size);
boolean[] ms = fmt.apply(size);
Expand All @@ -1468,14 +1687,14 @@ public Object UNSIGNED_GT() {
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);

// accumulate results, so JIT can't eliminate relevant computations
m = m.and(av.compare(VectorOperators.UNSIGNED_GT, bv));
m = m.and(av.compare(VectorOperators.UGT, bv));
}
}

return m;
}
@Benchmark
public Object UNSIGNED_LE() {
public Object ULE() {
byte[] a = fa.apply(size);
byte[] b = fb.apply(size);
boolean[] ms = fmt.apply(size);
Expand All @@ -1487,14 +1706,14 @@ public Object UNSIGNED_LE() {
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);

// accumulate results, so JIT can't eliminate relevant computations
m = m.and(av.compare(VectorOperators.UNSIGNED_LE, bv));
m = m.and(av.compare(VectorOperators.ULE, bv));
}
}

return m;
}
@Benchmark
public Object UNSIGNED_GE() {
public Object UGE() {
byte[] a = fa.apply(size);
byte[] b = fb.apply(size);
boolean[] ms = fmt.apply(size);
Expand All @@ -1506,7 +1725,7 @@ public Object UNSIGNED_GE() {
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);

// accumulate results, so JIT can't eliminate relevant computations
m = m.and(av.compare(VectorOperators.UNSIGNED_GE, bv));
m = m.and(av.compare(VectorOperators.UGE, bv));
}
}

Expand Down
Loading

0 comments on commit de83fd9

Please sign in to comment.