ekrich / sblas   0.7.0

GitHub

Scala Native BLAS (Basic Linear Algebra Subprograms) supporting Linux and macOS

Scala versions: 3.x 2.13 2.12 2.11
Scala Native versions: 0.5 0.4 0.3

sblas - Scala Native BLAS

CI

This library implements BLAS (Basic Linear Algebra Subprograms) in the form of CBLAS for the Scala Native platform. Scala Native is a unique platform that marries the high level language of Scala but compiles to native code with a lightweight managed runtime which includes a state of the art garbage collector. The combination allows for great programming and the ability to use high performance C language libraries like CBLAS.

Scala Native uses the Scala compiler to produce NIR (Native Intermediate Representation) that is optimized and then converted to LLVM IR. Finally LLVM code is optimized and compiled by Clang to produce a native executable.

New for Scala Native 0.5.0+

A higher level API has been started but only for one function dnrm2. This API allows the developer to pass Scala Arrays, which are Garbage Collection (GC) managed, directly to a function to be read or for a result. If the input to the function is a matrix then the Array is in row major order like it would be in C. Each row in the matrix is read from the array before the next row.

This API results in a zero overhead call to the CBLAS API because no data is copied. It should perform as fast as C after the arrays are initialized. For those wanting to know; this uses an experimental API that allows the caller to get a pointer to the first element in the array (after the array object header). The data is housed in the array so the API can just work on the raw data in the array.

Getting started

Maven Central

If you are already familiar with Scala Native you can jump right in by adding the following dependency in your sbt build file.

libraryDependencies += "org.ekrich" %%% "sblas" % "x.y.z"

To use in sbt, replace x.y.z with the version from Maven Central badge above. All available versions can be seen at the Maven Repository.

Otherwise follow the Getting Started instructions for Scala Native if you are not already setup.

Additional libraries that need to be installed on you system are as follows:

  • Linux/Ubuntu you need to install ATLAS for CBLAS support.
$ sudo apt-get install libatlas-base-dev
  • macOS has CBLAS pre-installed as part of the Accelerate Framework.

  • Other OSes need to have libcblas available on the system.

Scala Build Versions

Scala Version Native (0.4.0) Native (0.4.3+) Native (0.5.0+)
2.11.x
2.12.x
2.13.x
3.x.x

Use version sblas 0.3.0 for Scala Native 0.4.0. Use version sblas 0.4.0 for Scala Native 0.4.3+ with Scala 3 support. Use version sblas 0.5.0 for Scala Native 0.4.10+. Use version sblas 0.6.0 for Scala Native 0.5.0-RC2. Use version sblas 0.7.x for Scala Native 0.5.0+.

Usage and Help

scaladoc Join chat https://gitter.im/ekrich/sblas

Reference the link above for Scaladoc. The documentation is a little sparse but hopefully will improve with time.

After sbt is installed and any other Scala Native prerequisites are met you can use the following Gitter G8 template instructions to get a fully functional Scala Native application with a couple of BLAS examples in the body of the main program.

$ sbt new ekrich/sblas.g8
$ cd <directory entered after the prompt>
$ sbt run

In addition, look at the sblas unit tests for other examples of usage.

Using scalafmt

If you are using scalafmt and you would like to wrap arrays in your code such as the following:

val A = Array(
  0.11f, 0.12f, 0.13f,
  0.21f, 0.22f, 0.23f)

Add newlines.source = keep to your .scalafmt.conf file. This will keep your rows and columns from wrapping.

BLAS References and External Documentation

Some useful links are as follows which are also in the LICENSE.md file as some of the Scaladoc was sourced from these references:

Wikipedia Website:

Netlib Website:

Apple Website:

Intel Website:

IBM Website:

Versions

Release 0.7.0 - (2024-04-11)
Release 0.6.0 - (2024-02-29)
Release 0.5.0 - (2023-01-29)
Release 0.4.0 - (2022-02-01)
Release 0.3.0 - (2021-03-20)
Release 0.2.0 - (2019-12-05)
Release 0.1.1 - (2019-05-01)