< prev index next >

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

Print this page
rev 55894 : 8222897: [vector] Renaming of shift, rotate operations. Few other api changes.
Summary: Renaming of shift, rotate operations. Few other api changes.
Reviewed-by: jrose, briangoetz


   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.DoubleVector;
  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 Double256Vector extends AbstractVectorBenchmark {
  46     static final VectorSpecies<Double> SPECIES = DoubleVector.SPECIES_256;


 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         double[] a = fa.apply(SPECIES.length());
 270         double[] b = fb.apply(SPECIES.length());
 271         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 276                 DoubleVector bv = DoubleVector.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         double[] a = fa.apply(SPECIES.length());
 287         double[] b = fb.apply(SPECIES.length());
 288         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 293                 DoubleVector bv = DoubleVector.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         double[] a = fa.apply(SPECIES.length());
 307         double 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                 DoubleVector av = DoubleVector.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         double[] a = fa.apply(SPECIES.length());
 322         double 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                 DoubleVector av = DoubleVector.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         double[] a = fa.apply(SPECIES.length());
 337         double ra = Double.POSITIVE_INFINITY;
 338 
 339         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 340             ra = Double.POSITIVE_INFINITY;
 341             for (int i = 0; i < a.length; i += SPECIES.length()) {
 342                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 343                 ra = (double)Math.min(ra, av.minAll());
 344             }
 345         }
 346         bh.consume(ra);
 347     }
 348 
 349     @Benchmark
 350     public void maxAll(Blackhole bh) {
 351         double[] a = fa.apply(SPECIES.length());
 352         double ra = Double.NEGATIVE_INFINITY;
 353 
 354         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 355             ra = Double.NEGATIVE_INFINITY;
 356             for (int i = 0; i < a.length; i += SPECIES.length()) {
 357                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 358                 ra = (double)Math.max(ra, av.maxAll());
 359             }
 360         }
 361         bh.consume(ra);
 362     }
 363 
 364 
 365 
 366     @Benchmark
 367     public void with(Blackhole bh) {
 368         double[] a = fa.apply(SPECIES.length());
 369         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 374                 av.with(0, (double)4).intoArray(r, i);
 375             }
 376         }
 377 
 378         bh.consume(r);
 379     }
 380 
 381     @Benchmark
 382     public Object lessThan() {
 383         double[] a = fa.apply(size);
 384         double[] b = fb.apply(size);
 385         boolean[] ms = fm.apply(size);
 386         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 391                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 392                 VectorMask<Double> 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         double[] a = fa.apply(size);
 404         double[] b = fb.apply(size);
 405         boolean[] ms = fm.apply(size);
 406         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 411                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 412                 VectorMask<Double> 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         double[] a = fa.apply(size);
 424         double[] b = fb.apply(size);
 425         boolean[] ms = fm.apply(size);
 426         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 431                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 432                 VectorMask<Double> 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         double[] a = fa.apply(size);
 444         double[] b = fb.apply(size);
 445         boolean[] ms = fm.apply(size);
 446         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 451                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 452                 VectorMask<Double> 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         double[] a = fa.apply(size);
 464         double[] b = fb.apply(size);
 465         boolean[] ms = fm.apply(size);
 466         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 471                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 472                 VectorMask<Double> 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         double[] a = fa.apply(size);
 484         double[] b = fb.apply(size);
 485         boolean[] ms = fm.apply(size);
 486         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 491                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 492                 VectorMask<Double> 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         double[] a = fa.apply(SPECIES.length());
 504         double[] b = fb.apply(SPECIES.length());
 505         double[] 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.DoubleVector;
  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 Double256Vector extends AbstractVectorBenchmark {
  47     static final VectorSpecies<Double> SPECIES = DoubleVector.SPECIES_256;


 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         double[] a = fa.apply(SPECIES.length());
 283         double[] b = fb.apply(SPECIES.length());
 284         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 289                 DoubleVector bv = DoubleVector.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         double[] a = fa.apply(SPECIES.length());
 300         double[] b = fb.apply(SPECIES.length());
 301         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 306                 DoubleVector bv = DoubleVector.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         double[] a = fa.apply(SPECIES.length());
 320         double 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                 DoubleVector av = DoubleVector.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         double[] a = fa.apply(SPECIES.length());
 335         double 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                 DoubleVector av = DoubleVector.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         double[] a = fa.apply(SPECIES.length());
 350         double ra = Double.POSITIVE_INFINITY;
 351 
 352         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 353             ra = Double.POSITIVE_INFINITY;
 354             for (int i = 0; i < a.length; i += SPECIES.length()) {
 355                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 356                 ra = (double)Math.min(ra, av.minLanes());
 357             }
 358         }
 359         bh.consume(ra);
 360     }
 361 
 362     @Benchmark
 363     public void maxLanes(Blackhole bh) {
 364         double[] a = fa.apply(SPECIES.length());
 365         double ra = Double.NEGATIVE_INFINITY;
 366 
 367         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 368             ra = Double.NEGATIVE_INFINITY;
 369             for (int i = 0; i < a.length; i += SPECIES.length()) {
 370                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 371                 ra = (double)Math.max(ra, av.maxLanes());
 372             }
 373         }
 374         bh.consume(ra);
 375     }
 376 
 377 
 378 
 379     @Benchmark
 380     public void with(Blackhole bh) {
 381         double[] a = fa.apply(SPECIES.length());
 382         double[] 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 387                 av.with(0, (double)4).intoArray(r, i);
 388             }
 389         }
 390 
 391         bh.consume(r);
 392     }
 393 
 394     @Benchmark
 395     public Object lessThan() {
 396         double[] a = fa.apply(size);
 397         double[] b = fb.apply(size);
 398         boolean[] ms = fm.apply(size);
 399         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 404                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 405                 VectorMask<Double> 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         double[] a = fa.apply(size);
 417         double[] b = fb.apply(size);
 418         boolean[] ms = fm.apply(size);
 419         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 424                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 425                 VectorMask<Double> 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         double[] a = fa.apply(size);
 437         double[] b = fb.apply(size);
 438         boolean[] ms = fm.apply(size);
 439         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 444                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 445                 VectorMask<Double> 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         double[] a = fa.apply(size);
 457         double[] b = fb.apply(size);
 458         boolean[] ms = fm.apply(size);
 459         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 464                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 465                 VectorMask<Double> 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         double[] a = fa.apply(size);
 477         double[] b = fb.apply(size);
 478         boolean[] ms = fm.apply(size);
 479         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 484                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 485                 VectorMask<Double> 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         double[] a = fa.apply(size);
 497         double[] b = fb.apply(size);
 498         boolean[] ms = fm.apply(size);
 499         VectorMask<Double> 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                 DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
 504                 DoubleVector bv = DoubleVector.fromArray(SPECIES, b, i);
 505                 VectorMask<Double> 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         double[] a = fa.apply(SPECIES.length());
 517         double[] b = fb.apply(SPECIES.length());
 518         double[] r = fr.apply(SPECIES.length());
 519         boolean[] mask = fm.apply(SPECIES.length());


< prev index next >