Skip to content

Commit

Permalink
Merge branch 'main' into apply_simd
Browse files Browse the repository at this point in the history
  • Loading branch information
Quafadas authored Nov 15, 2024
2 parents b5c2b34 + 70eead5 commit 5324782
Show file tree
Hide file tree
Showing 84 changed files with 4,157 additions and 865 deletions.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: [quafadas]

3 changes: 1 addition & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ jobs:
- uses: coursier/setup-action@main
with:
jvm: temurin@17
apps: mill
# Run benchmark with `go test -bench` and stores the output to a file
- name: Run benchmark
run: mill benchmark.runJmh -jvmArgs --add-modules=jdk.incubator.vector -rf json
run: ./millw benchmark.runJmh -jvmArgs --add-modules=jdk.incubator.vector -rf json

- name: Set variables
run: |
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- uses: coursier/setup-action@main
with:
jvm: temurin@17
apps: mill scala-cli
apps: scala-cli

- name: Setup NodeJS v18 LTS
if: matrix.project == 'js'
Expand All @@ -51,7 +51,7 @@ jobs:
node-version: 18
cache: npm
- name: formatCheck
run: mill mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources
run: ./millw mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources

- if: matrix.project == 'js'
run: npm install
Expand All @@ -61,14 +61,14 @@ jobs:

- name: scalaJSLink
if: matrix.project == 'js'
run: mill vecxt.${{ matrix.project }}.fastLinkJS
run: ./millw vecxt.${{ matrix.project }}.fastLinkJS

- name: nativeLink
if: matrix.project == 'native'
run: mill vecxt.${{ matrix.project }}.test.nativeLink
run: ./millw vecxt.${{ matrix.project }}.test.nativeLink

- name: Test
run: mill vecxt.${{ matrix.project }}.test
run: ./millw vecxt.${{ matrix.project }}.test

publish:
if: github.repository == 'Quafadas/vecxt' && contains(github.ref, 'refs/tags/')
Expand All @@ -83,7 +83,7 @@ jobs:
- uses: coursier/setup-action@main
with:
jvm: temurin@17
apps: mill scala-cli
apps: scala-cli

- name: Setup GPG secrets
run: |
Expand All @@ -92,7 +92,7 @@ jobs:
gpg --list-secret-keys --keyid-format LONG
- name: Publish to Maven Central
run: mill -i mill.scalalib.PublishModule/publishAll __.publishArtifacts --sonatypeUri https://s01.oss.sonatype.org/service/local --sonatypeCreds "${{ secrets.SONATYPE_USERNAME }}:${{ secrets.SONATYPE_PASSWORD }}" --gpgArgs "--passphrase=${{ secrets.PGP_PASSPHRASE}},--batch,--yes,-a,-b,--pinentry-mode,loopback" --readTimeout 1200000 --awaitTimeout 1200000 --release true --signed true
run: ./millw -i mill.scalalib.PublishModule/publishAll __.publishArtifacts --sonatypeUri https://s01.oss.sonatype.org/service/local --sonatypeCreds "${{ secrets.SONATYPE_USERNAME }}:${{ secrets.SONATYPE_PASSWORD }}" --gpgArgs "--passphrase=${{ secrets.PGP_PASSPHRASE}},--batch,--yes,-a,-b,--pinentry-mode,loopback" --readTimeout 1200000 --awaitTimeout 1200000 --release true --signed true

site:
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
Expand All @@ -102,7 +102,7 @@ jobs:
- uses: coursier/setup-action@main
with:
jvm: temurin@17
apps: mill scala-cli
apps: scala-cli
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -115,18 +115,18 @@ jobs:
./aggregate.sh
- name: Switch to main branch
run: |
run: |
git fetch origin main
git checkout -f main
git reset --hard origin/main
ls
- name: Copy benchmark results into docs generation
run: mkdir -p site/docs/_assets/benchmarks && cp benchmark_history.json site/docs/_assets/benchmarks/benchmark_history.json
run: mkdir -p site/docs/_assets/benchmarks && cp benchmark_history.json site/docs/_assets/benchmarks/benchmark_history.json

- name: Generate static site
run: mill site.publishDocs
run: ./millw site.publishDocs

- name: Setup Pages
uses: actions/configure-pages@v4
- uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions .mill-jvm-opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--add-modules=jdk.incubator.vector
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.12
0.12.2
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ rewrite.scala3.countEndMarkerLines = lastBlockOnly
rewrite.scala3.insertEndMarkerMinLines = 1
indent.main = 2
maxColumn = 120
project.excludeFilters = [ ".*/build\\.sc"]
project.excludeFilters = [ ".*/build\\.mill"]
2 changes: 1 addition & 1 deletion benchmark/src/Benchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit;
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Thread)
@Fork(value = 1)
@Warmup(iterations = 3)
@Warmup(iterations = 1)
@Measurement(iterations = 3)
abstract class BLASBenchmark:

Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/and.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.openjdk.jmh.infra.Blackhole
// import vecxt.Matrix.*
import vecxt.BoundsCheck
import scala.compiletime.uninitialized
import vecxt.*
import vecxt.all.*
import jdk.incubator.vector.VectorSpecies
import jdk.incubator.vector.VectorOperators
import jdk.incubator.vector.DoubleVector
Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/countTrue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.openjdk.jmh.infra.Blackhole
// import vecxt.Matrix.*
import vecxt.BoundsCheck
import scala.compiletime.uninitialized
import vecxt.*
import vecxt.all.*
import jdk.incubator.vector.VectorSpecies
import jdk.incubator.vector.VectorOperators
import jdk.incubator.vector.DoubleVector
Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/increments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.openjdk.jmh.infra.Blackhole
// import vecxt.Matrix.*
import vecxt.BoundsCheck
import scala.compiletime.uninitialized
import vecxt.*
import vecxt.all.*
import jdk.incubator.vector.VectorSpecies
import jdk.incubator.vector.VectorOperators
import jdk.incubator.vector.DoubleVector
Expand Down
14 changes: 7 additions & 7 deletions benchmark/src/logical.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.openjdk.jmh.infra.Blackhole
// import vecxt.Matrix.*
import vecxt.BoundsCheck
import scala.compiletime.uninitialized
import vecxt.*
import vecxt.all.*
import jdk.incubator.vector.VectorSpecies
import jdk.incubator.vector.VectorOperators
import jdk.incubator.vector.DoubleVector
Expand All @@ -42,12 +42,12 @@ class LogicalBenchmark extends BLASBenchmark:
var len: String = uninitialized;

var arr: Array[Double] = uninitialized


// format: off
@Setup(Level.Trial)
def setup: Unit =
arr = randomDoubleArray(len.toInt);
arr = randomDoubleArray(len.toInt);
()
end setup

Expand All @@ -68,14 +68,14 @@ class LogicalBenchmark extends BLASBenchmark:
val r = arr <= 4.0
bh.consume(r);
end lte_vec



@Benchmark
def lte_loop(bh: Blackhole) =
val r = arr.lte2(4.0)
bh.consume(r);
end lte_loop

end LogicalBenchmark

3 changes: 2 additions & 1 deletion benchmark/src/matmul.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ package vecxt.benchmark

import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.Blackhole
import vecxt.Matrix.*
import vecxt.all.*
import vecxt.BoundsCheck
import scala.compiletime.uninitialized
import BoundsCheck.DoBoundsCheck.no

@State(Scope.Thread)
class DgemmBenchmark extends BLASBenchmark:

Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/or.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.openjdk.jmh.infra.Blackhole
// import vecxt.Matrix.*
import vecxt.BoundsCheck
import scala.compiletime.uninitialized
import vecxt.*
import vecxt.all.*
import jdk.incubator.vector.VectorSpecies
import jdk.incubator.vector.VectorOperators
import jdk.incubator.vector.DoubleVector
Expand Down
10 changes: 5 additions & 5 deletions benchmark/src/sum.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.openjdk.jmh.infra.Blackhole
// import vecxt.Matrix.*
import vecxt.BoundsCheck
import scala.compiletime.uninitialized
import vecxt.*
import vecxt.all.*
import jdk.incubator.vector.VectorSpecies
import jdk.incubator.vector.VectorOperators
import jdk.incubator.vector.DoubleVector
Expand All @@ -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.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
22 changes: 15 additions & 7 deletions benchmark/src/vectorAddition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ package vecxt.benchmark

import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.Blackhole
import vecxt.Matrix.*
import vecxt.*
import jdk.incubator.vector.DoubleVector
import vecxt.all.*
import scala.compiletime.uninitialized

// format: off
Expand Down Expand Up @@ -61,26 +61,34 @@ class AddScalarBenchmark extends BLASBenchmark:
end setup

extension (vec: Array[Double])
inline def scalarPlus(d: Double): Unit =
var i = 0
inline def scalarPlusVec(d: Double): Unit =
val species = DoubleVector.SPECIES_PREFERRED
var i: Int = 0
val l = species.length()

while i < species.loopBound(vec.length) do
DoubleVector.fromArray(species, vec, i).add(DoubleVector.broadcast(species, d)).intoArray(vec, i)
i += l
end while

while i < vec.length do
vec(i) += d
i += 1
end while
end scalarPlus
end scalarPlusVec


end extension

@Benchmark
def vecxt_add(bh: Blackhole) =
vec.scalarPlus(4.5)
vec +:+= (4.5)
bh.consume(vec);
end vecxt_add

@Benchmark
def vecxt_add_vec(bh: Blackhole) =
vec2 +:+= 4.5
vec2.scalarPlusVec(4.5)
bh.consume(vec2);
end vecxt_add_vec
end AddScalarBenchmark
Expand Down
Loading

0 comments on commit 5324782

Please sign in to comment.