Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Quafadas committed Jan 18, 2024
1 parent 202c1db commit 6d28e3d
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 24 deletions.
21 changes: 16 additions & 5 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

import $ivy.`com.github.lolgab::mill-crossplatform::0.2.4`
import $ivy.`io.github.quafadas::millSite::0.0.16`
import $ivy.`io.github.quafadas::millSite::0.0.17`
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`

import de.tobiasroeser.mill.vcs.version._
import com.github.lolgab.mill.crossplatform._
import mill._, mill.scalalib._, mill.scalajslib._, mill.scalanativelib._
import io.github.quafadas.millSite.SiteModule
import io.github.quafadas.millSite.QuickChange
import io.github.quafadas.millSite._
import mill._, scalalib._, publish._
import mill.scalajslib.api._
import mill.scalanativelib._
Expand Down Expand Up @@ -42,7 +41,7 @@ trait Common extends ScalaModule with PublishModule {
trait CommonJS extends ScalaJSModule {
def scalaJSVersion = "1.15.0"

def moduleKind = ModuleKind.CommonJSModule
// def moduleKind = ModuleKind.
}


Expand Down Expand Up @@ -83,7 +82,9 @@ object vecxt extends CrossPlatform {
}
object js extends Shared with CommonJS {
// js specific settings here
object test extends ScalaJSTests with SharedTests
object test extends ScalaJSTests with SharedTests {
def moduleKind = ModuleKind.CommonJSModule
}
}

object native extends Shared with CommonNative {
Expand All @@ -93,8 +94,18 @@ object vecxt extends CrossPlatform {

}

object jsSite extends SiteJSModule {

override def moduleDeps = Seq(vecxt.js)
override def scalaVersion = vecxt.js.scalaVersion
override def scalaJSVersion = vecxt.js.scalaJSVersion
override def moduleKind = ModuleKind.NoModule
}

object site extends SiteModule {

override val jsSiteModule = jsSite

def scalaVersion = vecxt.jvm.scalaVersion

override def moduleDeps = Seq(vecxt.jvm)
Expand Down
21 changes: 20 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,23 @@ Supported operationsa re currently very basic, but we share a single test suite

## Why?

Not?
Not?

## JS installation

https://github.com/stdlib-js/blas

I'm not sure, what the right way of doing this is. In the absence of a bundler, it appears possible, to get it work for documenation purposes, by adding this script;

```
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/blas@umd/browser.js"></script>
```


With the following scalaJS facade, it remains unclear however, what the implication for bundlers is.
```
js.native
@JSImport("@stdlib/blas/base", JSImport.Default, "window.blas.base")
object blas extends BlasArrayOps
```

13 changes: 9 additions & 4 deletions site/docs/_docs/Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

If you are running on the JVM, The shim to a java SIMD [netlib](https://github.com/luhenry/netlib) will generate warnings when it's instantiated. That shim looks for potential execution pathways upon instantiation, and prefers;

1. JNI to C
1. A JNI to C
2. Java SIMD
3. Fallback to vanilla Java

The console warnings on startup will tell you the implementations you are missing.

My understanding, is that for level 1 BLAS operations (i.e. this library), the performance of the SIMD implementation is comparable to native - i.e. C performance.

To enable the SIMD implementation, you'll need (at the time of writing) to enable the incubating `vector` API flags and be using JVM 18+. Consider adding this flag, to the JVM startup commands.
To enable the SIMD implementation, you'll need (at the time of writing) to enable the incubating `vector` API flags and be using JVM 18+. Consider adding this flag, to your JVM startup commands.

`--add-modules=jdk.incubator.vector`

Expand All @@ -25,10 +25,15 @@ You'll need this or better, available somewhere in your bundle / build / browser
}
}
```
If you aren't using a bundler, you can add this script to your html.

```html
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/blas@umd/browser.js"></script>
```

# Native

Isn't 100% my thing, so this is less tested.
Is less tested, but works according to the tests. You'll need CBLAS installed one way or another.

## Linux
On linux,
Expand All @@ -39,7 +44,7 @@ works, but not clear, if it's minimal.

## MacOS

I believe ships with CBLAS available, so shoudl work straight out the box.
I believe ships with CBLAS available, so should work straight out the box.

## Windows

Expand Down
4 changes: 2 additions & 2 deletions site/docs/_docs/bounds.check.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ In performance sensitive vector applications, bounds checking may be an unwelcom

# Mechanism

This bounds checking mechansim is an inline given `Boolean`, which reduces to an inline `if` _at compile time_. So if you turn bounds checking off, the compiler doesn't generate the code. No code => zero runtime overhead.
This bounds checking mechansim is an `inline given Boolean`, which reduces to an inline `if` _at compile time_. So if you turn bounds checking off, the compiler doesn't generate the code. No code => zero runtime overhead.

# Implications and use

It is left to the developer, to decide whether, or where BoundsChecks are wanted or not. A boolean is required as a context (given) parameter.
It is left to the developer, to decide whether, or where BoundsChecks are desirable in their application or not. A boolean is required as a context (given) parameter.

In this case, we disable bounds checks, maximising performance.

Expand Down
29 changes: 29 additions & 0 deletions site/docs/_docs/js.mdoc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Cross Platform
---

# Cross Platform

This has the same algorithm as the [motivation](motivation.mdoc.md) example, but is expressed in a cross platform `NArray`, and runs in scalaJS - check your browser console to observer the output.

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/blas@umd/browser.js"></script>

```scala mdoc:js sc:nocompile

import vecxt.*
import narr.*
import vecxt.BoundsCheck.DoBoundsCheck.yes

def algo(a: NArray[Double], b :NArray[Double], c: Double ) = (a + b) / c

val a = NArray(1.0, 2.0, 3.0, 2.0)
val b = NArray(4.0, 5.0, 6.0, 2.0)
val c = 2.0

// you'll have to look in the browser console to see this.
println(algo(a, b, c).mkString(", "))
// Need to be able to disable the snippet compiler, for this to work.
// node.innerHTML = algo(a, b, c).mkString(", ")

```
You can place the `algo` method in the shared part of your project, and use it on all platforms.
6 changes: 3 additions & 3 deletions site/docs/_docs/motivation.mdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ For example, your data acquisition is serverside, but do parts of a calculation

[[vecxt]] provides easy access to platform native common vector operations via intuitive and common syntax. Guaranteeing platform native performance - wherever you want to do your numerics.

# Cross Platform
# JVM

[[vecxt]] is cross platform, and can be used on the JVM, JS and Native platforms.
[[vecxt]] is cross platform, this example runs on the JVM, see [Cross Platform](js.mdoc.md) for the same example running in scalaJS.

```scala mdoc

Expand All @@ -29,4 +29,4 @@ val c = 2.0
println(algo(a, b, c).mkString(", "))

```
You can place the `algo` method in the shared part of your project, and use it on all platforms.
It would be possible to write the `algo` method in the shared part of your project, and use it on any of the platforms - freeing you from the tyranny of having to choose a platform in advance.
10 changes: 5 additions & 5 deletions site/docs/_docs/performance.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Performance

The core aim of this library, is to provide platform native, friction free performance.
The core aim of this library, is to provide platform native, friction free performance. I'm confident that I can't do better than this - at least outside of an absurd about of effort.

In general cross platform performance is a hard problem. We sidestep it by simply providing compiletime `@inline` shims to platform native BLAS implementations.


||JVM|JS|Native|
----|----|----|----|
Data structure| `Array[Double]` | `Float64Array` | `Array[Double]` |
Shims to | https://github.com/luhenry/netlib | https://github.com/stdlib-js/blas | [CBLAS](https://github.com/ekrich/sblas) |
||JVM|JS|Native|Cross|
----|----|----|----|---|
Data structure| `Array[Double]` | `Float64Array` | `Array[Double]` |`NArray[Double]` |
Shims to | https://github.com/luhenry/netlib | https://github.com/stdlib-js/blas | [CBLAS](https://github.com/ekrich/sblas) | Best available |

Consider browsing the [[vecxt]] api, and particulaly the extensions object. You'll see that most definitions are `@inline` anotated - i.e. there is zero runtime overhead calling this library.

Expand Down
8 changes: 8 additions & 0 deletions vecxt/js/src/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ object extensions:
vec.nativeSlice().tap(_ *= d)
end *

inline def /=(d: Double): Float64Array =
vec.tap(v => blas.dscal(v.length, 1.0/d, v, 1))
end /=

inline def /(d: Double): Float64Array =
vec.nativeSlice().tap(_ /= d)
end /

inline def <(num: Double): js.Array[Boolean] =
logicalIdx((a, b) => a < b, num)

Expand Down
8 changes: 4 additions & 4 deletions vecxt/js/src/stdlib.facade.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.typedarray.Float64Array

@js.native
@JSImport("@stdlib/blas/base", JSImport.Default)
object blas extends ArrayOps
@JSImport("@stdlib/blas/base", JSImport.Default, "window.blas.base")
object blas extends BlasArrayOps

@js.native
trait ArrayOps extends js.Object:
trait BlasArrayOps extends js.Object:
def daxpy(N: Int, alpha: Double, x: Float64Array, strideX: Int, y: Float64Array, strideY: Int): Unit =
js.native

def dscal(N: Int, alpha: Double, x: Float64Array, strideX: Int): Unit = js.native
def dnrm2(N: Int, x: Float64Array, strideX: Int): Double = js.native
end ArrayOps
end BlasArrayOps

0 comments on commit 6d28e3d

Please sign in to comment.