Index generation

Simon Parten quafadas at gmail.com
Mon Sep 30 15:44:26 UTC 2024


Hello Project Panama, 

Apologies, if this is the wrong place - first time. I’ve been benchmarking index generation (I want to do linear algebra) with Panama, and obtained the following (surprising to me) results. 

Benchmark                     (len)   Mode  Cnt       Score        Error  Units
IndexBenchmark.index_loop     10000  thrpt    3  476661.430 ± 333415.679  ops/s
IndexBenchmark.index_vec      10000  thrpt    3  821343.888 ±  22086.257  ops/s
IndexBenchmark.index_vec_bad  10000  thrpt    3   31524.934 ±  59643.768  ops/s

The first two implementations are the “obvious” ones. The third one attempts to instantiate the species differently. My ultimate goal, is to get as DoubleVector SPECIES_PREFFERED, and then calculate indexes for each, then put it in an array (i.e. have half the number of the preferred integer species for the platform). 


  @Benchmark
  def index_loop(bh: Blackhole) =
    val arr = Array.ofDim[Int](lenInt)
    var i = 0
    while (i < lenInt) do
      arr(i) += 1
      i += 1
    end while

    bh.consume(arr);
  end index_loop

  @Benchmark
  def index_vec(bh: Blackhole) =
    val arr = Array.ofDim[Int](lenInt)
    val sp = IntVector.SPECIES_PREFERRED
    val l = sp.length()
    var i = 0

    while i < sp.loopBound(lenInt) do
      val v : IntVector = IntVector.broadcast(sp, i).addIndex(1)
      v.intoArray(arr, i)
      i += l
    end while

    bh.consume(arr);
  end index_vec


  @Benchmark
  def index_vec_bad(bh: Blackhole) =
    val arr = Array.ofDim[Int](lenInt)
    val spi = IntVector.SPECIES_PREFERRED
    val sp = VectorSpecies.of(java.lang.Integer.TYPE, spi.vectorShape())
    val l = sp.length()
    var i = 0

    while i < sp.loopBound(lenInt) do
      val v : IntVector = IntVector.broadcast(sp, i).addIndex(1)
      v.intoArray(arr, i)
      i += l
    end while

    bh.consume(arr);
  end index_vec_bad



However, constructing the VectorSpecies through the VectorSpecies.of method, appears to have a catastrophic performance impact. Would that be expected? Am I doing something obviously wrong here? 

Kind Regards, 
Simon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20240930/23da8fea/attachment.htm>


More information about the panama-dev mailing list