7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have
21 * questions.
22 */
23
24 package benchmark.jdk.incubator.vector;
25
26 import jdk.incubator.vector.Vector;
27 import jdk.incubator.vector.VectorShape;
28 import jdk.incubator.vector.VectorSpecies;
29 import jdk.incubator.vector.VectorShuffle;
30 import jdk.incubator.vector.FloatVector;
31
32 import java.util.concurrent.TimeUnit;
33 import java.util.function.BiFunction;
34 import java.util.function.IntFunction;
35
36 import org.openjdk.jmh.annotations.*;
37 import org.openjdk.jmh.infra.Blackhole;
38
39 @BenchmarkMode(Mode.Throughput)
40 @OutputTimeUnit(TimeUnit.MILLISECONDS)
41 @State(Scope.Benchmark)
42 @Warmup(iterations = 3, time = 1)
43 @Measurement(iterations = 5, time = 1)
44 @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
45 public class Float128Vector extends AbstractVectorBenchmark {
46 static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_128;
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267 @Benchmark
268 public void max(Blackhole bh) {
269 float[] a = fa.apply(SPECIES.length());
270 float[] b = fb.apply(SPECIES.length());
271 float[] r = fr.apply(SPECIES.length());
272
273 for (int ic = 0; ic < INVOC_COUNT; ic++) {
274 for (int i = 0; i < a.length; i += SPECIES.length()) {
275 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
276 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
277 av.max(bv).intoArray(r, i);
278 }
279 }
280
281 bh.consume(r);
282 }
283
284 @Benchmark
285 public void min(Blackhole bh) {
286 float[] a = fa.apply(SPECIES.length());
287 float[] b = fb.apply(SPECIES.length());
288 float[] r = fr.apply(SPECIES.length());
289
290 for (int ic = 0; ic < INVOC_COUNT; ic++) {
291 for (int i = 0; i < a.length; i += SPECIES.length()) {
292 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
293 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
294 av.min(bv).intoArray(r, i);
295 }
296 }
297
298 bh.consume(r);
299 }
300
301
302
303
304 @Benchmark
305 public void addAll(Blackhole bh) {
306 float[] a = fa.apply(SPECIES.length());
307 float ra = 0;
308
309 for (int ic = 0; ic < INVOC_COUNT; ic++) {
310 ra = 0;
311 for (int i = 0; i < a.length; i += SPECIES.length()) {
312 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
313 ra += av.addAll();
314 }
315 }
316 bh.consume(ra);
317 }
318
319 @Benchmark
320 public void mulAll(Blackhole bh) {
321 float[] a = fa.apply(SPECIES.length());
322 float ra = 1;
323
324 for (int ic = 0; ic < INVOC_COUNT; ic++) {
325 ra = 1;
326 for (int i = 0; i < a.length; i += SPECIES.length()) {
327 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
328 ra *= av.mulAll();
329 }
330 }
331 bh.consume(ra);
332 }
333
334 @Benchmark
335 public void minAll(Blackhole bh) {
336 float[] a = fa.apply(SPECIES.length());
337 float ra = Float.POSITIVE_INFINITY;
338
339 for (int ic = 0; ic < INVOC_COUNT; ic++) {
340 ra = Float.POSITIVE_INFINITY;
341 for (int i = 0; i < a.length; i += SPECIES.length()) {
342 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
343 ra = (float)Math.min(ra, av.minAll());
344 }
345 }
346 bh.consume(ra);
347 }
348
349 @Benchmark
350 public void maxAll(Blackhole bh) {
351 float[] a = fa.apply(SPECIES.length());
352 float ra = Float.NEGATIVE_INFINITY;
353
354 for (int ic = 0; ic < INVOC_COUNT; ic++) {
355 ra = Float.NEGATIVE_INFINITY;
356 for (int i = 0; i < a.length; i += SPECIES.length()) {
357 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
358 ra = (float)Math.max(ra, av.maxAll());
359 }
360 }
361 bh.consume(ra);
362 }
363
364
365
366 @Benchmark
367 public void with(Blackhole bh) {
368 float[] a = fa.apply(SPECIES.length());
369 float[] r = fr.apply(SPECIES.length());
370
371 for (int ic = 0; ic < INVOC_COUNT; ic++) {
372 for (int i = 0; i < a.length; i += SPECIES.length()) {
373 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
374 av.with(0, (float)4).intoArray(r, i);
375 }
376 }
377
378 bh.consume(r);
379 }
380
381 @Benchmark
382 public Object lessThan() {
383 float[] a = fa.apply(size);
384 float[] b = fb.apply(size);
385 boolean[] ms = fm.apply(size);
386 VectorMask<Float> m = VectorMask.maskFromArray(SPECIES, ms, 0);
387
388 for (int ic = 0; ic < INVOC_COUNT; ic++) {
389 for (int i = 0; i < a.length; i += SPECIES.length()) {
390 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
391 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
392 VectorMask<Float> mv = av.lessThan(bv);
393
394 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
395 }
396 }
397 return m;
398 }
399
400
401 @Benchmark
402 public Object greaterThan() {
403 float[] a = fa.apply(size);
404 float[] b = fb.apply(size);
405 boolean[] ms = fm.apply(size);
406 VectorMask<Float> m = VectorMask.maskFromArray(SPECIES, ms, 0);
407
408 for (int ic = 0; ic < INVOC_COUNT; ic++) {
409 for (int i = 0; i < a.length; i += SPECIES.length()) {
410 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
411 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
412 VectorMask<Float> mv = av.greaterThan(bv);
413
414 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
415 }
416 }
417 return m;
418 }
419
420
421 @Benchmark
422 public Object equal() {
423 float[] a = fa.apply(size);
424 float[] b = fb.apply(size);
425 boolean[] ms = fm.apply(size);
426 VectorMask<Float> m = VectorMask.maskFromArray(SPECIES, ms, 0);
427
428 for (int ic = 0; ic < INVOC_COUNT; ic++) {
429 for (int i = 0; i < a.length; i += SPECIES.length()) {
430 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
431 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
432 VectorMask<Float> mv = av.equal(bv);
433
434 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
435 }
436 }
437 return m;
438 }
439
440
441 @Benchmark
442 public Object notEqual() {
443 float[] a = fa.apply(size);
444 float[] b = fb.apply(size);
445 boolean[] ms = fm.apply(size);
446 VectorMask<Float> m = VectorMask.maskFromArray(SPECIES, ms, 0);
447
448 for (int ic = 0; ic < INVOC_COUNT; ic++) {
449 for (int i = 0; i < a.length; i += SPECIES.length()) {
450 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
451 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
452 VectorMask<Float> mv = av.notEqual(bv);
453
454 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
455 }
456 }
457 return m;
458 }
459
460
461 @Benchmark
462 public Object lessThanEq() {
463 float[] a = fa.apply(size);
464 float[] b = fb.apply(size);
465 boolean[] ms = fm.apply(size);
466 VectorMask<Float> m = VectorMask.maskFromArray(SPECIES, ms, 0);
467
468 for (int ic = 0; ic < INVOC_COUNT; ic++) {
469 for (int i = 0; i < a.length; i += SPECIES.length()) {
470 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
471 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
472 VectorMask<Float> mv = av.lessThanEq(bv);
473
474 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
475 }
476 }
477 return m;
478 }
479
480
481 @Benchmark
482 public Object greaterThanEq() {
483 float[] a = fa.apply(size);
484 float[] b = fb.apply(size);
485 boolean[] ms = fm.apply(size);
486 VectorMask<Float> m = VectorMask.maskFromArray(SPECIES, ms, 0);
487
488 for (int ic = 0; ic < INVOC_COUNT; ic++) {
489 for (int i = 0; i < a.length; i += SPECIES.length()) {
490 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
491 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
492 VectorMask<Float> mv = av.greaterThanEq(bv);
493
494 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
495 }
496 }
497 return m;
498 }
499
500
501 @Benchmark
502 public void blend(Blackhole bh) {
503 float[] a = fa.apply(SPECIES.length());
504 float[] b = fb.apply(SPECIES.length());
505 float[] r = fr.apply(SPECIES.length());
506 boolean[] mask = fm.apply(SPECIES.length());
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have
21 * questions.
22 */
23
24 package benchmark.jdk.incubator.vector;
25
26 import jdk.incubator.vector.Vector;
27 import jdk.incubator.vector.VectorMask;
28 import jdk.incubator.vector.VectorShape;
29 import jdk.incubator.vector.VectorSpecies;
30 import jdk.incubator.vector.VectorShuffle;
31 import jdk.incubator.vector.FloatVector;
32
33 import java.util.concurrent.TimeUnit;
34 import java.util.function.BiFunction;
35 import java.util.function.IntFunction;
36
37 import org.openjdk.jmh.annotations.*;
38 import org.openjdk.jmh.infra.Blackhole;
39
40 @BenchmarkMode(Mode.Throughput)
41 @OutputTimeUnit(TimeUnit.MILLISECONDS)
42 @State(Scope.Benchmark)
43 @Warmup(iterations = 3, time = 1)
44 @Measurement(iterations = 5, time = 1)
45 @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
46 public class Float128Vector extends AbstractVectorBenchmark {
47 static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_128;
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280 @Benchmark
281 public void max(Blackhole bh) {
282 float[] a = fa.apply(SPECIES.length());
283 float[] b = fb.apply(SPECIES.length());
284 float[] r = fr.apply(SPECIES.length());
285
286 for (int ic = 0; ic < INVOC_COUNT; ic++) {
287 for (int i = 0; i < a.length; i += SPECIES.length()) {
288 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
289 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
290 av.max(bv).intoArray(r, i);
291 }
292 }
293
294 bh.consume(r);
295 }
296
297 @Benchmark
298 public void min(Blackhole bh) {
299 float[] a = fa.apply(SPECIES.length());
300 float[] b = fb.apply(SPECIES.length());
301 float[] r = fr.apply(SPECIES.length());
302
303 for (int ic = 0; ic < INVOC_COUNT; ic++) {
304 for (int i = 0; i < a.length; i += SPECIES.length()) {
305 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
306 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
307 av.min(bv).intoArray(r, i);
308 }
309 }
310
311 bh.consume(r);
312 }
313
314
315
316
317 @Benchmark
318 public void addLanes(Blackhole bh) {
319 float[] a = fa.apply(SPECIES.length());
320 float ra = 0;
321
322 for (int ic = 0; ic < INVOC_COUNT; ic++) {
323 ra = 0;
324 for (int i = 0; i < a.length; i += SPECIES.length()) {
325 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
326 ra += av.addLanes();
327 }
328 }
329 bh.consume(ra);
330 }
331
332 @Benchmark
333 public void mulLanes(Blackhole bh) {
334 float[] a = fa.apply(SPECIES.length());
335 float ra = 1;
336
337 for (int ic = 0; ic < INVOC_COUNT; ic++) {
338 ra = 1;
339 for (int i = 0; i < a.length; i += SPECIES.length()) {
340 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
341 ra *= av.mulLanes();
342 }
343 }
344 bh.consume(ra);
345 }
346
347 @Benchmark
348 public void minLanes(Blackhole bh) {
349 float[] a = fa.apply(SPECIES.length());
350 float ra = Float.POSITIVE_INFINITY;
351
352 for (int ic = 0; ic < INVOC_COUNT; ic++) {
353 ra = Float.POSITIVE_INFINITY;
354 for (int i = 0; i < a.length; i += SPECIES.length()) {
355 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
356 ra = (float)Math.min(ra, av.minLanes());
357 }
358 }
359 bh.consume(ra);
360 }
361
362 @Benchmark
363 public void maxLanes(Blackhole bh) {
364 float[] a = fa.apply(SPECIES.length());
365 float ra = Float.NEGATIVE_INFINITY;
366
367 for (int ic = 0; ic < INVOC_COUNT; ic++) {
368 ra = Float.NEGATIVE_INFINITY;
369 for (int i = 0; i < a.length; i += SPECIES.length()) {
370 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
371 ra = (float)Math.max(ra, av.maxLanes());
372 }
373 }
374 bh.consume(ra);
375 }
376
377
378
379 @Benchmark
380 public void with(Blackhole bh) {
381 float[] a = fa.apply(SPECIES.length());
382 float[] r = fr.apply(SPECIES.length());
383
384 for (int ic = 0; ic < INVOC_COUNT; ic++) {
385 for (int i = 0; i < a.length; i += SPECIES.length()) {
386 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
387 av.with(0, (float)4).intoArray(r, i);
388 }
389 }
390
391 bh.consume(r);
392 }
393
394 @Benchmark
395 public Object lessThan() {
396 float[] a = fa.apply(size);
397 float[] b = fb.apply(size);
398 boolean[] ms = fm.apply(size);
399 VectorMask<Float> m = VectorMask.fromArray(SPECIES, ms, 0);
400
401 for (int ic = 0; ic < INVOC_COUNT; ic++) {
402 for (int i = 0; i < a.length; i += SPECIES.length()) {
403 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
404 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
405 VectorMask<Float> mv = av.lessThan(bv);
406
407 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
408 }
409 }
410 return m;
411 }
412
413
414 @Benchmark
415 public Object greaterThan() {
416 float[] a = fa.apply(size);
417 float[] b = fb.apply(size);
418 boolean[] ms = fm.apply(size);
419 VectorMask<Float> m = VectorMask.fromArray(SPECIES, ms, 0);
420
421 for (int ic = 0; ic < INVOC_COUNT; ic++) {
422 for (int i = 0; i < a.length; i += SPECIES.length()) {
423 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
424 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
425 VectorMask<Float> mv = av.greaterThan(bv);
426
427 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
428 }
429 }
430 return m;
431 }
432
433
434 @Benchmark
435 public Object equal() {
436 float[] a = fa.apply(size);
437 float[] b = fb.apply(size);
438 boolean[] ms = fm.apply(size);
439 VectorMask<Float> m = VectorMask.fromArray(SPECIES, ms, 0);
440
441 for (int ic = 0; ic < INVOC_COUNT; ic++) {
442 for (int i = 0; i < a.length; i += SPECIES.length()) {
443 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
444 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
445 VectorMask<Float> mv = av.equal(bv);
446
447 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
448 }
449 }
450 return m;
451 }
452
453
454 @Benchmark
455 public Object notEqual() {
456 float[] a = fa.apply(size);
457 float[] b = fb.apply(size);
458 boolean[] ms = fm.apply(size);
459 VectorMask<Float> m = VectorMask.fromArray(SPECIES, ms, 0);
460
461 for (int ic = 0; ic < INVOC_COUNT; ic++) {
462 for (int i = 0; i < a.length; i += SPECIES.length()) {
463 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
464 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
465 VectorMask<Float> mv = av.notEqual(bv);
466
467 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
468 }
469 }
470 return m;
471 }
472
473
474 @Benchmark
475 public Object lessThanEq() {
476 float[] a = fa.apply(size);
477 float[] b = fb.apply(size);
478 boolean[] ms = fm.apply(size);
479 VectorMask<Float> m = VectorMask.fromArray(SPECIES, ms, 0);
480
481 for (int ic = 0; ic < INVOC_COUNT; ic++) {
482 for (int i = 0; i < a.length; i += SPECIES.length()) {
483 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
484 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
485 VectorMask<Float> mv = av.lessThanEq(bv);
486
487 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
488 }
489 }
490 return m;
491 }
492
493
494 @Benchmark
495 public Object greaterThanEq() {
496 float[] a = fa.apply(size);
497 float[] b = fb.apply(size);
498 boolean[] ms = fm.apply(size);
499 VectorMask<Float> m = VectorMask.fromArray(SPECIES, ms, 0);
500
501 for (int ic = 0; ic < INVOC_COUNT; ic++) {
502 for (int i = 0; i < a.length; i += SPECIES.length()) {
503 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
504 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
505 VectorMask<Float> mv = av.greaterThanEq(bv);
506
507 m = m.and(mv); // accumulate results, so JIT can't eliminate relevant computations
508 }
509 }
510 return m;
511 }
512
513
514 @Benchmark
515 public void blend(Blackhole bh) {
516 float[] a = fa.apply(SPECIES.length());
517 float[] b = fb.apply(SPECIES.length());
518 float[] r = fr.apply(SPECIES.length());
519 boolean[] mask = fm.apply(SPECIES.length());
|