ScalaCL lets you run Scala code on GPUs through OpenCL (BSD-licensed).
WORK IN PROGRESS (see ScalaCL if you want something that works, albeit only on Scala 2.9.x).
See slides from ScalaCL + Reified talk @ scala.io 2013.
Features of the new design (v3, rewritten from scratch again!):
scalaVersion := "2.11.4" libraryDependencies += "com.nativelibs4java" %% "scalacl" % "0.3-SNAPSHOT" // Avoid sbt-related macro classpath issues. fork := true // Scalaxy/Reified snapshots are published on the Sonatype repository. resolvers += Resolver.sonatypeRepo("snapshots")
The following example currently works:
import scalacl._ case class Matrix(data: CLArray[Float], rows: Int, columns: Int) (implicit context: Context) { def this(rows: Int, columns: Int) (implicit context: Context) = this(new CLArray[Float](rows * columns), rows, columns) def this(n: Int) (implicit context: Context) = this(n, n) def putProduct(a: Matrix, b: Matrix): Unit = { assert(a.columns == b.rows) assert(a.rows == rows) assert(b.columns == columns) kernel { // This block will either be converted to an OpenCL kernel or cause compilation error for (i <- 0 until rows; j <- 0 until columns) { // c(i, j) = sum(k, a(i, k) * b(k, j)) data(i * columns + j) = ( for (k <- 0 until a.columns) yield a.data(i * a.columns + k) * b.data(k * b.columns + j) ).sum } } } def putSum(a: Matrix, b: Matrix): Unit = { assert(a.columns == b.columns && a.columns == columns) assert(a.rows == b.rows && a.rows == rows) kernel { for (i <- 0 until rows; j <- 0 until columns) { val offset = i * columns + j data(offset) = a.data(offset) + b.data(offset) } } } } implicit val context = Context.best val n = 10 val a = new Matrix(n) val b = new Matrix(n) val out = new Matrix(n) out.putProduct(a, b) println(out.data)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4