< prev index next >

test/jdk/jdk/incubator/vector/benchmark/src/main/java/benchmark/jdk/incubator/vector/Float512Vector.java

Print this page
rev 55606 : 8221812: Fine-tune jmh test for vector api
Summary: To compare performance of vector api and auto vectorization, vector
api and scalar test cases are updated to keep aligned.
Reviewed-by: duke
   1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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  */


 286         float[] b = fb.apply(SPECIES.length());
 287         float[] r = fr.apply(SPECIES.length());
 288 
 289         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 290             for (int i = 0; i < a.length; i += SPECIES.length()) {
 291                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 292                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 293                 av.min(bv).intoArray(r, i);
 294             }
 295         }
 296 
 297         bh.consume(r);
 298     }
 299 
 300 
 301 
 302 
 303     @Benchmark
 304     public void addAll(Blackhole bh) {
 305         float[] a = fa.apply(SPECIES.length());
 306         float[] r = fr.apply(SPECIES.length());
 307         float ra = 0;
 308 
 309         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 310             for (int i = 0; i < a.length; i += SPECIES.length()) {
 311                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 312                 r[i] = av.addAll();
 313             }
 314         }
 315 
 316         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 317             ra = 0;
 318             for (int i = 0; i < a.length; i += SPECIES.length()) {
 319                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 320                 ra += av.addAll();
 321             }
 322         }
 323 
 324         bh.consume(ra);
 325         bh.consume(r);
 326     }
 327 
 328     @Benchmark
 329     public void mulAll(Blackhole bh) {
 330         float[] a = fa.apply(SPECIES.length());
 331         float[] r = fr.apply(SPECIES.length());
 332         float ra = 1;
 333 
 334         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 335             for (int i = 0; i < a.length; i += SPECIES.length()) {
 336                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 337                 r[i] = av.mulAll();
 338             }
 339         }
 340 
 341         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 342             ra = 1;
 343             for (int i = 0; i < a.length; i += SPECIES.length()) {
 344                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 345                 ra *= av.mulAll();
 346             }
 347         }
 348 
 349         bh.consume(ra);
 350         bh.consume(r);
 351     }
 352 
 353     @Benchmark
 354     public void minAll(Blackhole bh) {
 355         float[] a = fa.apply(SPECIES.length());
 356         float[] r = fr.apply(SPECIES.length());
 357         float ra = Float.POSITIVE_INFINITY;
 358 
 359         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 360             for (int i = 0; i < a.length; i += SPECIES.length()) {
 361                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 362                 r[i] = av.minAll();
 363             }
 364         }
 365 
 366         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 367             ra = Float.POSITIVE_INFINITY;
 368             for (int i = 0; i < a.length; i += SPECIES.length()) {
 369                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 370                 ra = (float)Math.min(ra, av.minAll());
 371             }
 372         }
 373 
 374         bh.consume(ra);
 375         bh.consume(r);
 376     }
 377 
 378     @Benchmark
 379     public void maxAll(Blackhole bh) {
 380         float[] a = fa.apply(SPECIES.length());
 381         float[] r = fr.apply(SPECIES.length());
 382         float ra = Float.NEGATIVE_INFINITY;
 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                 r[i] = av.maxAll();
 388             }
 389         }
 390 
 391         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 392             ra = Float.NEGATIVE_INFINITY;
 393             for (int i = 0; i < a.length; i += SPECIES.length()) {
 394                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 395                 ra = (float)Math.max(ra, av.maxAll());
 396             }
 397         }
 398 
 399         bh.consume(ra);
 400         bh.consume(r);
 401     }
 402 
 403 
 404 
 405     @Benchmark
 406     public void with(Blackhole bh) {
 407         float[] a = fa.apply(SPECIES.length());
 408         float[] r = fr.apply(SPECIES.length());
 409 
 410         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 411             for (int i = 0; i < a.length; i += SPECIES.length()) {
 412                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 413                 av.with(0, (float)4).intoArray(r, i);
 414             }
 415         }
 416 
 417         bh.consume(r);
 418     }
 419 
 420     @Benchmark


   1 /*
   2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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  */


 286         float[] b = fb.apply(SPECIES.length());
 287         float[] r = fr.apply(SPECIES.length());
 288 
 289         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 290             for (int i = 0; i < a.length; i += SPECIES.length()) {
 291                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 292                 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
 293                 av.min(bv).intoArray(r, i);
 294             }
 295         }
 296 
 297         bh.consume(r);
 298     }
 299 
 300 
 301 
 302 
 303     @Benchmark
 304     public void addAll(Blackhole bh) {
 305         float[] a = fa.apply(SPECIES.length());

 306         float ra = 0;
 307 
 308         for (int ic = 0; ic < INVOC_COUNT; ic++) {







 309             ra = 0;
 310             for (int i = 0; i < a.length; i += SPECIES.length()) {
 311                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 312                 ra += av.addAll();
 313             }
 314         }

 315         bh.consume(ra);

 316     }
 317 
 318     @Benchmark
 319     public void mulAll(Blackhole bh) {
 320         float[] a = fa.apply(SPECIES.length());

 321         float ra = 1;
 322 
 323         for (int ic = 0; ic < INVOC_COUNT; ic++) {







 324             ra = 1;
 325             for (int i = 0; i < a.length; i += SPECIES.length()) {
 326                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 327                 ra *= av.mulAll();
 328             }
 329         }

 330         bh.consume(ra);

 331     }
 332 
 333     @Benchmark
 334     public void minAll(Blackhole bh) {
 335         float[] a = fa.apply(SPECIES.length());

 336         float ra = Float.POSITIVE_INFINITY;
 337 
 338         for (int ic = 0; ic < INVOC_COUNT; ic++) {







 339             ra = Float.POSITIVE_INFINITY;
 340             for (int i = 0; i < a.length; i += SPECIES.length()) {
 341                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 342                 ra = (float)Math.min(ra, av.minAll());
 343             }
 344         }

 345         bh.consume(ra);

 346     }
 347 
 348     @Benchmark
 349     public void maxAll(Blackhole bh) {
 350         float[] a = fa.apply(SPECIES.length());

 351         float ra = Float.NEGATIVE_INFINITY;
 352 
 353         for (int ic = 0; ic < INVOC_COUNT; ic++) {







 354             ra = Float.NEGATIVE_INFINITY;
 355             for (int i = 0; i < a.length; i += SPECIES.length()) {
 356                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 357                 ra = (float)Math.max(ra, av.maxAll());
 358             }
 359         }

 360         bh.consume(ra);

 361     }
 362 
 363 
 364 
 365     @Benchmark
 366     public void with(Blackhole bh) {
 367         float[] a = fa.apply(SPECIES.length());
 368         float[] r = fr.apply(SPECIES.length());
 369 
 370         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 371             for (int i = 0; i < a.length; i += SPECIES.length()) {
 372                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 373                 av.with(0, (float)4).intoArray(r, i);
 374             }
 375         }
 376 
 377         bh.consume(r);
 378     }
 379 
 380     @Benchmark


< prev index next >