Skip to content

Commit

Permalink
Switch plot strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
Quafadas committed Nov 15, 2024
1 parent 8b21025 commit fbf5e73
Show file tree
Hide file tree
Showing 15 changed files with 2,046 additions and 47 deletions.
8 changes: 4 additions & 4 deletions benchmark/src/sum.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ class SumBenchmark extends BLASBenchmark:

end setup

final val spd = DoubleVector.SPECIES_PREFERRED
extension (vec: Array[Double])


inline def sum2 =
var sum: Double = 0.0
var i: Int = 0
val sp = Matrix.doubleSpecies
val l = sp.length()
val l = spd.length()

while i < sp.loopBound(vec.length) do
sum = sum + DoubleVector.fromArray(sp, vec, i).reduceLanes(VectorOperators.ADD)
while i < spd.loopBound(vec.length) do
sum = sum + DoubleVector.fromArray(spd, vec, i).reduceLanes(VectorOperators.ADD)
i += l
end while
while i < vec.length do
Expand Down
15 changes: 13 additions & 2 deletions build.mill
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import mill.scalalib.publish.Scope.Test

import $ivy.`com.github.lolgab::mill-crossplatform::0.2.4`
import $ivy.`io.github.quafadas:millSite_mill0.12_2.13:0.0.36`
Expand All @@ -17,7 +18,7 @@ import mill.util.Jvm
import mill.api.Result

trait Common extends ScalaModule with PublishModule {
def scalaVersion = "3.3.4"
def scalaVersion = "3.6.1"

def publishVersion = VcsVersion.vcsState().format()

Expand Down Expand Up @@ -180,8 +181,18 @@ object jsSite extends SiteJSModule {
override def ivyDeps = super.ivyDeps() ++ Agg(
ivy"org.scala-js::scalajs-dom::2.8.0",
ivy"com.lihaoyi::scalatags::0.13.1",
ivy"com.raquo::laminar::17.0.0"
ivy"com.raquo::laminar::17.0.0",
ivy"com.lihaoyi::upickle::4.0.2"
)

object test extends ScalaJSTests with CommonTests {
def moduleKind = ModuleKind.CommonJSModule
}
}

object integration extends ScalaModule with CommonTests {
def scalaVersion: T[String] = vecxt.jvm.scalaVersion

}

// note that scastic won't work, as I don't think we can start a JVM with the incubator flag.
Expand Down
61 changes: 61 additions & 0 deletions integration/src/plotChecks.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
*
* Copyright 2023 quafadas
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package vecxt.plot

import upickle.default.*
import NamedTupleReadWriter.given
import io.github.jam01.json_schema.*
import io.github.jam01.json_schema.*
import scalatags.JsDom.short.*

class PlotChecks extends munit.FunSuite:

test("something") {

val thePlot = BenchmarkPlotElements.schema ++
BenchmarkPlotElements.data("../../benchmarks/benchmark_history.json") ++
(transform =
BenchmarkPlotElements.timeTransform(
List("vecxt.benchmark.AddScalarBenchmark.vecxt_add_vec")
)
) ++
(vconcat =
List(
BenchmarkPlotElements.layer(3),
BenchmarkPlotElements.layer(1000),
BenchmarkPlotElements.layer(100000)
)
)

val json = writeJs(thePlot)

// println(json)

// assert(json.toString().contains("$schema\":"))

}

test("over time plot") {
val plot = BenchmarkPlots.addScalarBenchmarkOverTime

println(plot)

assert(plot.contains("data"))

}

end PlotChecks
59 changes: 59 additions & 0 deletions jsSite/src/BenchmarkPlots.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package vecxt.plot

import scala.NamedTuple.AnyNamedTuple
import scala.annotation.meta.field
import upickle.default.*
import NamedTupleReadWriter.given

object BenchmarkPlots:
def addScalarBenchmark: String =
val thePlot = BenchmarkPlotElements.schema ++
BenchmarkPlotElements.data("../../benchmarks/benchmark_history.json") ++
// BenchmarkPlotElements.fakeData ++
(transform =
BenchmarkPlotElements.transform(List("AddScalarBenchmark.vecxt_add", "AddScalarBenchmark.vecxt_add_vec"))
) ++
(vconcat =
List(
BenchmarkPlotElements.layer(10),
BenchmarkPlotElements.layer(1000),
BenchmarkPlotElements.layer(100000)
)
)
write(thePlot)
end addScalarBenchmark

def addScalarBenchmarkOverTime: String =
val thePlot = BenchmarkPlotElements.schema ++
// BenchmarkPlotElements.data("../../benchmarks/benchmark_history.json") ++
BenchmarkPlotElements.fakeData ++
(transform = BenchmarkPlotElements.timeTransform(List("AddScalarBenchmark.vecxt_add_vec"))) ++
(vconcat =
List(
BenchmarkPlotElements.timeLayer(10),
BenchmarkPlotElements.timeLayer(1000),
BenchmarkPlotElements.timeLayer(100000)
)
)
write(thePlot)
end addScalarBenchmarkOverTime

def countTrueBenchmark =
val thePlot = BenchmarkPlotElements.schema ++
BenchmarkPlotElements.data("../../benchmarks/benchmark_history.json") ++
(transform =
BenchmarkPlotElements.transform(
List("CountTrueBenchmark.countTrue_loop", "CountTrueBenchmark.countTrue_loop_vec")
)
) ++
(vconcat =
List(
BenchmarkPlotElements.layer(3),
BenchmarkPlotElements.layer(128),
BenchmarkPlotElements.layer(100000)
)
)
write(thePlot)
end countTrueBenchmark

end BenchmarkPlots
35 changes: 35 additions & 0 deletions jsSite/src/NamedTupleReadWriter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package vecxt.plot

import scala.NamedTuple.NamedTuple
import upickle.default.*
import ujson.Value

object NamedTupleReadWriter:
inline given [N <: Tuple, V <: Tuple, T <: NamedTuple[N, V]]: ReadWriter[T] =
val names = scala.compiletime.constValueTuple[N].toList.asInstanceOf[List[String]]
val readWriters = scala.compiletime.summonAll[Tuple.Map[V, ReadWriter]].toList.asInstanceOf[List[ReadWriter[?]]]

def toMap(t: T): Map[String, Value] =
val values = t.toTuple.productIterator.toList
(0 until names.length).foldLeft(Map.empty[String, Value]): (map, i) =>
val readWriter = readWriters(i).asInstanceOf[ReadWriter[Any]]
map + (names(i) -> transform(values(i))(using readWriter).to(ujson.Value))
end toMap

def fromMap(map: Map[String, Value]): T =
val namesAndRWs = names.zip(readWriters)
val valueList = namesAndRWs.map: (name, rw) =>
map.get(name) match
case None => throw new Exception(s"Missing field: $name")
case Some(v) =>
read(v)(using rw.asInstanceOf[ReadWriter[Any]])

val tuple = valueList.foldRight(EmptyTuple: Tuple): (v, tuple) =>
v *: tuple

tuple.asInstanceOf[T]
end fromMap

summon[ReadWriter[Map[String, Value]]].bimap(toMap, fromMap)
end given
end NamedTupleReadWriter
Loading

0 comments on commit fbf5e73

Please sign in to comment.