From 96e56c5d0daa44d0aee5da2e3450848ac335d38d Mon Sep 17 00:00:00 2001 From: Jan Paw Date: Tue, 5 Aug 2014 22:21:43 +0200 Subject: [PATCH 01/10] SCL-4: in context{} --- project/ScalaCLBuild.scala | 1 + src/test/scala/scalacl/BaseTest.scala | 13 ++++++ src/test/scala/scalacl/KernelTest.scala | 53 ++++++++++--------------- src/test/scala/scalacl/TaskTest.scala | 23 ++++------- 4 files changed, 43 insertions(+), 47 deletions(-) create mode 100644 src/test/scala/scalacl/BaseTest.scala diff --git a/project/ScalaCLBuild.scala b/project/ScalaCLBuild.scala index bd635e5..0fd9513 100644 --- a/project/ScalaCLBuild.scala +++ b/project/ScalaCLBuild.scala @@ -80,6 +80,7 @@ object ScalaCLBuild extends Build { libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-compiler" % _), libraryDependencies ++= Seq( "junit" % "junit" % "4.10" % "test", + "org.scalatest" % "scalatest_2.11" % "2.2.1" % "test", "com.novocode" % "junit-interface" % "0.8" % "test" ) ) diff --git a/src/test/scala/scalacl/BaseTest.scala b/src/test/scala/scalacl/BaseTest.scala new file mode 100644 index 0000000..7388273 --- /dev/null +++ b/src/test/scala/scalacl/BaseTest.scala @@ -0,0 +1,13 @@ +package scalacl + +import org.scalatest.{ FlatSpecLike, Matchers } + +trait BaseTest extends FlatSpecLike with Matchers { + def context[T](f: Context => T): T = { + val context = Context.best + try { + f(context) + } finally context.release() + } +} + diff --git a/src/test/scala/scalacl/KernelTest.scala b/src/test/scala/scalacl/KernelTest.scala index bd328d2..2178ae5 100644 --- a/src/test/scala/scalacl/KernelTest.scala +++ b/src/test/scala/scalacl/KernelTest.scala @@ -34,54 +34,45 @@ import impl._ import org.junit._ import Assert._ -class KernelTest { - @Test - def intRange1DKernel() { - implicit val context = Context.best - try { +class KernelTest extends BaseTest { + behavior of "ScalaCl kernel" + it should "perform computation in kernel block for integers" in context { + implicit context => val n = 25 - val a = new Array[Int](n) - val ca = new CLArray[Int](n) + val result = new Array[Int](n) + val clResult = new CLArray[Int](n) val f = 10 kernel { for (i <- 0 until n by 3) - ca(i) = i * f + 10 + clResult(i) = i * f + 10 } + for (i <- 0 until n by 3) - a(i) = i * f + 10 + result(i) = i * f + 10 - assertEquals(a.toSeq, ca.toSeq) - } finally { - context.release() - } + result.toSeq should equal (clResult.toSeq) } - @Test - def longRange1DKernel() { - implicit val context = Context.best - try { + it should "perform computation in kernel block for longs" in context { + implicit context => val n = 25L - val a = new Array[Long](n.toInt) - val ca = new CLArray[Long](n) + val result = new Array[Long](n.toInt) + val clResult = new CLArray[Long](n) val f = 10 kernel { for (i <- 0L until n by 3L) - ca(i) = i * f + 10 + clResult(i) = i * f + 10 } for (i <- 0L until n by 3L) - a(i.toInt) = i * f + 10 + result(i.toInt) = i * f + 10 - assertEquals(a.toSeq, ca.toSeq) - } finally { - context.release() - } + result.toSeq should equal (clResult.toSeq) } - @Test - def testEquality() { + it should "check equality of kernels" in { val sources = "aa" same(new KernelDef(sources = sources, salt = 1), new KernelDef(sources = sources, salt = 1)) diff(new KernelDef(sources = sources, salt = 1), new KernelDef(sources = sources, salt = 2), sameHC = false) @@ -89,12 +80,12 @@ class KernelTest { } def same(a: AnyRef, b: AnyRef) = { - assertEquals(a.hashCode, b.hashCode) - assertEquals(a, b) + a.hashCode should equal (b.hashCode) + a shouldEqual equal (b) } def diff(a: AnyRef, b: AnyRef, sameHC: Boolean) = { - assertTrue(sameHC ^ (a.hashCode != b.hashCode)) - assertFalse(a.equals(b)) + assert(sameHC ^ (a.hashCode != b.hashCode)) + assert(!a.equals(b)) } } diff --git a/src/test/scala/scalacl/TaskTest.scala b/src/test/scala/scalacl/TaskTest.scala index 9870a95..85af405 100644 --- a/src/test/scala/scalacl/TaskTest.scala +++ b/src/test/scala/scalacl/TaskTest.scala @@ -29,26 +29,17 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package scalacl -import impl._ -import org.junit._ -import Assert._ +class TaskTest extends BaseTest { + behavior of "ScalaCl task" -class TaskTest { - @Ignore - @Test - def simple() { - implicit val context = Context.best - try { - val a = new CLArray[Int](3) + ignore should "perform computation in task block" in context { + implicit context => + val result = new CLArray[Int](3) val f = 10 task { - a(1) = 10 * f + result(1) = 10 * f } - println(a.toSeq) - assertEquals(Seq(0, 100, 0), a.toSeq) - } finally { - context.release() - } + result should equal (Seq(0, 100, 0)) } } From fa5dcaadbacfd6ebd6510cbe3d26f73fd3c48258 Mon Sep 17 00:00:00 2001 From: Jan Paw Date: Wed, 6 Aug 2014 09:34:34 +0200 Subject: [PATCH 02/10] SCL-4: mocking and vectorization tests --- project/ScalaCLBuild.scala | 3 +- src/test/scala/scalacl/BaseTest.scala | 3 +- src/test/scala/scalacl/KernelTest.scala | 5 +- .../scalacl/impl/VectorizationTest.scala | 59 ++++++++----------- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/project/ScalaCLBuild.scala b/project/ScalaCLBuild.scala index 0fd9513..5756b1b 100644 --- a/project/ScalaCLBuild.scala +++ b/project/ScalaCLBuild.scala @@ -71,7 +71,7 @@ object ScalaCLBuild extends Build { // "-optimise", "-deprecation", "-feature", - // "-Xlog-free-types", + // "-Xlog-free-types",q // "-Ymacro-debug-lite", "-unchecked" ), @@ -81,6 +81,7 @@ object ScalaCLBuild extends Build { libraryDependencies ++= Seq( "junit" % "junit" % "4.10" % "test", "org.scalatest" % "scalatest_2.11" % "2.2.1" % "test", + "org.scalamock" % "scalamock-scalatest-support_2.11" % "3.1.2", "com.novocode" % "junit-interface" % "0.8" % "test" ) ) diff --git a/src/test/scala/scalacl/BaseTest.scala b/src/test/scala/scalacl/BaseTest.scala index 7388273..d0bbe64 100644 --- a/src/test/scala/scalacl/BaseTest.scala +++ b/src/test/scala/scalacl/BaseTest.scala @@ -1,8 +1,9 @@ package scalacl import org.scalatest.{ FlatSpecLike, Matchers } +import org.scalamock.scalatest.MockFactory -trait BaseTest extends FlatSpecLike with Matchers { +trait BaseTest extends FlatSpecLike with Matchers with MockFactory{ def context[T](f: Context => T): T = { val context = Context.best try { diff --git a/src/test/scala/scalacl/KernelTest.scala b/src/test/scala/scalacl/KernelTest.scala index 2178ae5..4cf0a09 100644 --- a/src/test/scala/scalacl/KernelTest.scala +++ b/src/test/scala/scalacl/KernelTest.scala @@ -29,10 +29,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package scalacl -import impl._ -import org.junit._ -import Assert._ +import scalacl.impl.KernelDef class KernelTest extends BaseTest { behavior of "ScalaCl kernel" @@ -66,6 +64,7 @@ class KernelTest extends BaseTest { for (i <- 0L until n by 3L) clResult(i) = i * f + 10 } + for (i <- 0L until n by 3L) result(i.toInt) = i * f + 10 diff --git a/src/test/scala/scalacl/impl/VectorizationTest.scala b/src/test/scala/scalacl/impl/VectorizationTest.scala index 5e9b053..7dcf748 100644 --- a/src/test/scala/scalacl/impl/VectorizationTest.scala +++ b/src/test/scala/scalacl/impl/VectorizationTest.scala @@ -33,21 +33,20 @@ package impl import scalaxy.components._ -import org.junit._ -import Assert._ -import org.hamcrest.CoreMatchers._ - class VectorizationTest - extends Vectorization + extends BaseTest + with Vectorization with WithRuntimeUniverse with WithTestFresh { + + behavior of "ScalaCl vectorization" + import global._ private val context = reify { null: Context } - private val NotVectorizable: Option[Expr[Unit]] = None - private val Vectorizable = not(NotVectorizable) + private val vectorized: Option[Expr[Unit]] = mock[Some[Expr[Unit]]] - private def vec(block: Expr[Unit]) = { + private def afterVectorization(block: Expr[Unit]): Option[global.Expr[Unit]] = { try { vectorize(context, typeCheck(block.tree, WildcardType)) } catch { @@ -57,34 +56,28 @@ class VectorizationTest } } - @Test - def notVectorizable0D() { - assertThat( - vec(reify { 1 + 2 }), - is(NotVectorizable) - ) + it should "not vectorized 0D expression" in { + afterVectorization(reify { 1 + 2 }) should not be vectorized + } + + it should "vectorized 1D expression" in { + afterVectorization(reify { + for (i <- 0 until 10) i + 1 + }) should be (vectorized) } - @Test - def vectorizable1D() { - assertThat( - vec(reify { - for (i <- 0 until 10) i + 2 - }), - is(Vectorizable) - ) + it should "vectorized 2D expression" in { + afterVectorization(reify { + for (i <- 0 until 10; j <- 0 until 10) + i + j + 2 + }) should be (vectorized) } - // @Ignore - @Test - def notVectorizable2D() { - assertThat( - vec(reify { - for (i <- 0 until 10; j <- 0 until 10) - i + j + 2 - }), - //is(NotVectorizable) - is(Vectorizable) - ) + ignore should "vectorized 3D expression" in { + afterVectorization(reify { + for (i <- 0 until 10; j <- 0 until 10; k <- 0 until 10) + i + j + k + 3 + }) should be (vectorized) } + } From 1ea0dece421d0043b4a658e825982836e1c00e77 Mon Sep 17 00:00:00 2001 From: Jan Paw Date: Wed, 6 Aug 2014 13:14:51 +0200 Subject: [PATCH 03/10] SCL-4: symbol kinds test --- src/test/scala/scalacl/BaseTest.scala | 4 ++ .../scala/scalacl/impl/SymbolKindsTest.scala | 38 +++++++++---------- .../scalacl/impl/VectorizationTest.scala | 3 +- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/test/scala/scalacl/BaseTest.scala b/src/test/scala/scalacl/BaseTest.scala index d0bbe64..03e7341 100644 --- a/src/test/scala/scalacl/BaseTest.scala +++ b/src/test/scala/scalacl/BaseTest.scala @@ -3,6 +3,8 @@ package scalacl import org.scalatest.{ FlatSpecLike, Matchers } import org.scalamock.scalatest.MockFactory +import scalaxy.components.{WithTestFresh, WithRuntimeUniverse} + trait BaseTest extends FlatSpecLike with Matchers with MockFactory{ def context[T](f: Context => T): T = { val context = Context.best @@ -12,3 +14,5 @@ trait BaseTest extends FlatSpecLike with Matchers with MockFactory{ } } + +trait RuntimeUniverseTest extends WithRuntimeUniverse with WithTestFresh diff --git a/src/test/scala/scalacl/impl/SymbolKindsTest.scala b/src/test/scala/scalacl/impl/SymbolKindsTest.scala index a979338..45cf1a0 100644 --- a/src/test/scala/scalacl/impl/SymbolKindsTest.scala +++ b/src/test/scala/scalacl/impl/SymbolKindsTest.scala @@ -31,16 +31,13 @@ package scalacl package impl -import scalaxy.components._ +class SymbolKindsTest + extends BaseTest + with RuntimeUniverseTest + with SymbolKinds { -import org.junit._ -import Assert._ -import org.hamcrest.CoreMatchers._ + behavior of "Symbols kind resolving" -class SymbolKindsTest - extends SymbolKinds - with WithRuntimeUniverse - with WithTestFresh { import global._ class EmptyClass() @@ -52,23 +49,22 @@ class SymbolKindsTest var v = 0 } - @Test - def testKinds() { - assertEquals(SymbolKind.Tuploid, kindOf(typeOf[Int])) - assertEquals(SymbolKind.Tuploid, kindOf(typeOf[Float])) - assertEquals(SymbolKind.Tuploid, kindOf(typeOf[(Int, Int)])) + it should "find properly kind some object" in { + SymbolKind.Tuploid should equal (kindOf(typeOf[Int])) + SymbolKind.Tuploid should equal (kindOf(typeOf[Float])) + SymbolKind.Tuploid should equal (kindOf(typeOf[(Int, Int)])) - assertEquals(SymbolKind.ArrayLike, kindOf(typeOf[CLArray[Int]])) - assertEquals(SymbolKind.ArrayLike, kindOf(typeOf[CLFilteredArray[Int]])) + SymbolKind.ArrayLike should equal (kindOf(typeOf[CLArray[Int]])) + SymbolKind.ArrayLike should equal (kindOf(typeOf[CLFilteredArray[Int]])) - assertEquals(SymbolKind.Tuploid, kindOf(typeOf[ImmutableClass])) - assertEquals(SymbolKind.Tuploid, kindOf(typeOf[ImmutableCaseClass])) + SymbolKind.Tuploid should equal (kindOf(typeOf[ImmutableClass])) + SymbolKind.Tuploid should equal (kindOf(typeOf[ImmutableCaseClass])) - assertEquals(SymbolKind.Other, kindOf(typeOf[MutableClass])) - assertEquals(SymbolKind.Other, kindOf(typeOf[MutableCaseClass])) + SymbolKind.Other should equal (kindOf(typeOf[MutableClass])) + SymbolKind.Other should equal (kindOf(typeOf[MutableCaseClass])) - assertEquals(SymbolKind.Other, kindOf(typeOf[EmptyClass])) - assertEquals(SymbolKind.Other, kindOf(typeOf[EmptyCaseClass])) + SymbolKind.Other should equal (kindOf(typeOf[EmptyClass])) + SymbolKind.Other should equal (kindOf(typeOf[EmptyCaseClass])) } } diff --git a/src/test/scala/scalacl/impl/VectorizationTest.scala b/src/test/scala/scalacl/impl/VectorizationTest.scala index 7dcf748..eb65000 100644 --- a/src/test/scala/scalacl/impl/VectorizationTest.scala +++ b/src/test/scala/scalacl/impl/VectorizationTest.scala @@ -36,8 +36,7 @@ import scalaxy.components._ class VectorizationTest extends BaseTest with Vectorization - with WithRuntimeUniverse - with WithTestFresh { + with RuntimeUniverseTest { behavior of "ScalaCl vectorization" From f4c1b1eb703bb0122a3249b71660e859f9dc1ff4 Mon Sep 17 00:00:00 2001 From: Jan Paw Date: Wed, 6 Aug 2014 22:24:04 +0200 Subject: [PATCH 04/10] partial impl rev some tests --- .../scala/scalacl/impl/Vectorization.scala | 1 + src/test/scala/scalacl/BaseTest.scala | 61 ++++++- .../scala/scalacl/FunctionKernelTest.scala | 98 +++++++++++ src/test/scala/scalacl/KernelTest.scala | 39 ++++- .../scala/scalacl/MapConversionTest.scala | 22 +++ src/test/scala/scalacl/SimpleTest.scala | 158 ------------------ src/test/scala/scalacl/TaskTest.scala | 5 +- .../scala/scalacl/impl/ConversionTest.scala | 146 +++++++--------- .../impl/DefaultScheduledDataTest.scala | 78 ++++----- .../scalacl/impl/InlinedCollectionsTest.scala | 15 +- .../impl/OpenCLCodeFlatteningTest.scala | 67 ++------ .../scalacl/impl/OpenCLConverterTest.scala | 59 +++---- .../scala/scalacl/impl/SymbolKindsTest.scala | 24 +-- .../scalacl/impl/VectorizationTest.scala | 54 +++--- 14 files changed, 395 insertions(+), 432 deletions(-) create mode 100644 src/test/scala/scalacl/FunctionKernelTest.scala create mode 100644 src/test/scala/scalacl/MapConversionTest.scala delete mode 100644 src/test/scala/scalacl/SimpleTest.scala diff --git a/src/main/scala/scalacl/impl/Vectorization.scala b/src/main/scala/scalacl/impl/Vectorization.scala index c786e39..80486ab 100644 --- a/src/main/scala/scalacl/impl/Vectorization.scala +++ b/src/main/scala/scalacl/impl/Vectorization.scala @@ -77,6 +77,7 @@ trait Vectorization extends CodeGeneration with MiscMatchers { ) } } + private[impl] def vectorize(context: Expr[scalacl.Context], block: Tree): Option[Expr[Unit]] = { Option(block) collect { case Foreach( diff --git a/src/test/scala/scalacl/BaseTest.scala b/src/test/scala/scalacl/BaseTest.scala index 03e7341..dd5a69b 100644 --- a/src/test/scala/scalacl/BaseTest.scala +++ b/src/test/scala/scalacl/BaseTest.scala @@ -1,11 +1,11 @@ package scalacl -import org.scalatest.{ FlatSpecLike, Matchers } import org.scalamock.scalatest.MockFactory +import org.scalatest.{ FlatSpecLike, Matchers } +import scalacl.impl.{ OpenCLCodeFlattening, CodeConversion } +import scalaxy.components.{ FlatCode, WithRuntimeUniverse } -import scalaxy.components.{WithTestFresh, WithRuntimeUniverse} - -trait BaseTest extends FlatSpecLike with Matchers with MockFactory{ +trait BaseTest extends FlatSpecLike with Matchers with MockFactory { def context[T](f: Context => T): T = { val context = Context.best try { @@ -14,5 +14,56 @@ trait BaseTest extends FlatSpecLike with Matchers with MockFactory{ } } +trait RuntimeUniverseTest extends WithRuntimeUniverse { + private var nextId = 0L + + def fresh(s: String) = synchronized { + val v = nextId + nextId += 1 + s + v + } +} + +trait CodeConversionTest extends CodeConversion with RuntimeUniverseTest { + val global: reflect.api.Universe + import global._ + + def convertExpression(block: Expr[Unit], explicitParamDescs: Seq[ParamDesc] = Seq()) = { + convertCode(typeCheck(block.tree, WildcardType), explicitParamDescs) + } + + def flatAndConvertExpression(x: Expr[_]): FlatCode[String] = { + flattenAndConvert(typeCheck(x)) + } + + def flatCode(statements: Seq[String], values: Seq[String]): FlatCode[String] = + FlatCode[String](statements = statements, values = values) +} + +trait CodeFlatteningTest extends OpenCLCodeFlattening with RuntimeUniverseTest { + val global: reflect.api.Universe + import global._ -trait RuntimeUniverseTest extends WithRuntimeUniverse with WithTestFresh + def unwrap(tree: Tree): Tree = tree match { + case Block(List(sub), Literal(Constant(()))) => sub + case _ => tree + } + + def flatCode(statements: Seq[Expr[_]] = Seq(), values: Seq[Expr[_]] = Seq()) = { + FlatCode[Tree]( + statements = statements.map(x => unwrap(typeCheck(x.tree, WildcardType))), + values = values.map(x => unwrap(typeCheck(x.tree, WildcardType))) + ) + } + + def inputSymbols(xs: Expr[_]*): Seq[(Symbol, Type)] = { + for (x <- xs.toSeq) yield { + val i @ Ident(n) = typeCheck(x.tree, WildcardType) + (i.symbol, i.tpe) + } + } + + def flatExpression(x: Expr[_], inputSymbols: Seq[(Symbol, Type)] = Seq(), owner: Symbol = NoSymbol): FlatCode[Tree] = { + flatten(typeCheck(x.tree, WildcardType), inputSymbols, owner) + } +} diff --git a/src/test/scala/scalacl/FunctionKernelTest.scala b/src/test/scala/scalacl/FunctionKernelTest.scala new file mode 100644 index 0000000..3931082 --- /dev/null +++ b/src/test/scala/scalacl/FunctionKernelTest.scala @@ -0,0 +1,98 @@ +/* + * ScalaCL - putting Scala on the GPU with JavaCL / OpenCL + * http://scalacl.googlecode.com/ + * + * Copyright (c) 2009-2013, Olivier Chafik (http://ochafik.com/) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Olivier Chafik nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY OLIVIER CHAFIK AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package scalacl +package impl + +class FunctionKernelTest extends BaseTest { + + behavior of "FunctionKernel" + + ignore should "create kernel" in context { + implicit context => + val factor = 20.5f + val trans = new CLFunction[Int, Int]( + (v: Int) => (v * factor).toInt, + preparedFunctionKernel = Some( + new FunctionKernel( + new KernelDef( + """ + kernel void f(global const int* input, global int* output, float factor) { + int i = get_global_id(0); + if (i >= get_global_size(0)) + return; + output[i] = (int)(input[i] * factor); + } + """, + salt = -1), + Captures(constants = Array(factor.asInstanceOf[AnyRef]))))) + + val pred = new CLFunction[Int, Boolean]( + (v: Int) => v % 2 == 0, + preparedFunctionKernel = Some( + new FunctionKernel( + new KernelDef( + """ + kernel void f(global const int* input, global char* output) { + int i = get_global_id(0); + if (i >= get_global_size(0)) + return; + output[i] = input[i] % 2 == 0; + } + """, + salt = -1)))) + + val values = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) + val a = CLArray[Int](values: _*) + + def doit(print: Boolean, check: Boolean = false) { + val b = a.map(trans) + val fil = a.map(pred) + if (print) { + println(b) + println(fil) + } + if (check) { + values.map(trans).toSeq should equal(b.toArray.toSeq) + } + context.queue.finish() + b.release() + } + + doit(print = false, check = true) + for (i <- 0 until 10) { + val start = System.nanoTime + doit(print = false) + val timeMicros = (System.nanoTime - start) / 1000 + println((timeMicros / 1000.0) + " milliseconds") + } + } + +} diff --git a/src/test/scala/scalacl/KernelTest.scala b/src/test/scala/scalacl/KernelTest.scala index 4cf0a09..851d0d3 100644 --- a/src/test/scala/scalacl/KernelTest.scala +++ b/src/test/scala/scalacl/KernelTest.scala @@ -35,7 +35,7 @@ import scalacl.impl.KernelDef class KernelTest extends BaseTest { behavior of "ScalaCl kernel" - it should "perform computation in kernel block for integers" in context { + ignore should "perform computation in kernel block for integers" in context { implicit context => val n = 25 val result = new Array[Int](n) @@ -50,10 +50,10 @@ class KernelTest extends BaseTest { for (i <- 0 until n by 3) result(i) = i * f + 10 - result.toSeq should equal (clResult.toSeq) + result.toSeq should equal(clResult.toSeq) } - it should "perform computation in kernel block for longs" in context { + ignore should "perform computation in kernel block for longs" in context { implicit context => val n = 25L val result = new Array[Long](n.toInt) @@ -68,10 +68,35 @@ class KernelTest extends BaseTest { for (i <- 0L until n by 3L) result(i.toInt) = i * f + 10 - result.toSeq should equal (clResult.toSeq) + result.toSeq should equal(clResult.toSeq) } - it should "check equality of kernels" in { + ignore should "capture simple array" in context { + implicit context => + val clResult = { + val f = CLArray(10, 20, 30, 40) + val a = CLArray(0, 1, 2, 3) + + val rr = new CLArray[Int](a.length) + kernel { + for (i <- 0 until a.length.toInt) { + rr(i) = f(i) + i + } + } + rr + } + + val result = { + val f = Array(10, 20, 30, 40) + val a = Array(0, 1, 2, 3) + val r = a.map(x => f(x) + x) + r + } + + result.toList should equal(clResult.toList) + } + + ignore should "check equality of kernels" in { val sources = "aa" same(new KernelDef(sources = sources, salt = 1), new KernelDef(sources = sources, salt = 1)) diff(new KernelDef(sources = sources, salt = 1), new KernelDef(sources = sources, salt = 2), sameHC = false) @@ -79,8 +104,8 @@ class KernelTest extends BaseTest { } def same(a: AnyRef, b: AnyRef) = { - a.hashCode should equal (b.hashCode) - a shouldEqual equal (b) + a.hashCode should equal(b.hashCode) + a shouldEqual equal(b) } def diff(a: AnyRef, b: AnyRef, sameHC: Boolean) = { diff --git a/src/test/scala/scalacl/MapConversionTest.scala b/src/test/scala/scalacl/MapConversionTest.scala new file mode 100644 index 0000000..4741682 --- /dev/null +++ b/src/test/scala/scalacl/MapConversionTest.scala @@ -0,0 +1,22 @@ +package scalacl + +class MapConversionTest extends BaseTest { + + behavior of "map" + + ignore should "compute scalar function with int type" in context { + implicit context => + val f = 0.2f + + val array = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) + val clArray: CLArray[Int] = array.cl + + val clResult = clArray.map((x: Int) => x * 2 * f) + val result = array.map(x => x * 2 * f) + + result.toArray zip clResult.toArray foreach { + case (r, cl) => r should equal(cl +- 0.001f) + } + } + +} diff --git a/src/test/scala/scalacl/SimpleTest.scala b/src/test/scala/scalacl/SimpleTest.scala deleted file mode 100644 index fac8318..0000000 --- a/src/test/scala/scalacl/SimpleTest.scala +++ /dev/null @@ -1,158 +0,0 @@ -/* - * ScalaCL - putting Scala on the GPU with JavaCL / OpenCL - * http://scalacl.googlecode.com/ - * - * Copyright (c) 2009-2013, Olivier Chafik (http://ochafik.com/) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Olivier Chafik nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY OLIVIER CHAFIK AND CONTRIBUTORS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package scalacl -package impl - -import org.junit._ -import Assert._ - -class SimpleTest { - @Ignore - @Test - def testHandWrittenKernels() { - implicit val context = Context.best - val factor = 20.5f - val trans = new CLFunction[Int, Int]( - (v: Int) => (v * factor).toInt, - preparedFunctionKernel = Some( - new FunctionKernel( - new KernelDef( - """ - kernel void f(global const int* input, global int* output, float factor) { - int i = get_global_id(0); - if (i >= get_global_size(0)) - return; - output[i] = (int)(input[i] * factor); - } - """, - salt = -1), - Captures(constants = Array(factor.asInstanceOf[AnyRef]))))) - - val pred = new CLFunction[Int, Boolean]( - (v: Int) => v % 2 == 0, - preparedFunctionKernel = Some( - new FunctionKernel( - new KernelDef( - """ - kernel void f(global const int* input, global char* output) { - int i = get_global_id(0); - if (i >= get_global_size(0)) - return; - output[i] = input[i] % 2 == 0; - } - """, - salt = -1)))) - - val values = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) - val a = CLArray[Int](values: _*) - //println(a) - - def doit(print: Boolean, check: Boolean = false) { - val b = a.map(trans) - val fil = a.map(pred) - if (print) { - println(b) - println(fil) - } - if (check) { - assertEquals(values.map(trans).toSeq, b.toArray.toSeq) - } - context.queue.finish() - b.release() - } - - doit(print = false, check = true) - for (i <- 0 until 10) { - val start = System.nanoTime - doit(print = false) - val timeMicros = (System.nanoTime - start) / 1000 - println((timeMicros / 1000.0) + " milliseconds") - } - context.release() - } - - @Test - def testSimpleScalarCapture() { - implicit val context = Context.best - val f = 0.2f - - val array = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) - val clArray: CLArray[Int] = array.cl - - val clResult = clArray.map((x: Int) => x * 2 * f) - val result = array.map(x => x * 2 * f) - assertArrayEquals(result.toArray, clResult.toArray, 0.001f) - - clArray.release() - clResult.release() - context.release() - } - - @Test - def testSimpleArrayCapture() { - implicit val context = Context.best - - val clResult = { - val f = CLArray(10, 20, 30, 40) - val a = CLArray(0, 1, 2, 3) - - val r = if (true) { - val rr = new CLArray[Int](a.length) - kernel { - for (i <- 0 until a.length.toInt) { - rr(i) = f(i) + i - } - } - rr - } else { - a.map((x: Int) => f(x) + x) - } - //assertNotNull("result buffer doesn't have any write event", r.buffers(0).dataWrite) - //assertEquals("source buffer doesn't have expected read event", 1, a.buffers(0).dataReads.size) - //r.finish() - //Thread.sleep(500) - //assertNull("result buffer failed to clear its dataWrite upon finish()", r.buffers(0).dataWrite) - //assertEquals("source buffer failed to clear its dataReads upon finish()", 0, a.buffers(0).dataReads.size) - //assertEquals("captured buffer failed to clear its dataReads upon finish()", 0, f.buffers(0).dataReads.size) - - r - } - val result = { - val f = Array(10, 20, 30, 40) - val a = Array(0, 1, 2, 3) - val r = a.map(x => f(x) + x) - r - } - assertEquals(result.toList, clResult.toList) - - context.release() - } -} diff --git a/src/test/scala/scalacl/TaskTest.scala b/src/test/scala/scalacl/TaskTest.scala index 85af405..805304c 100644 --- a/src/test/scala/scalacl/TaskTest.scala +++ b/src/test/scala/scalacl/TaskTest.scala @@ -30,7 +30,8 @@ */ package scalacl -class TaskTest extends BaseTest { +class TaskTest + extends BaseTest { behavior of "ScalaCl task" ignore should "perform computation in task block" in context { @@ -40,6 +41,6 @@ class TaskTest extends BaseTest { task { result(1) = 10 * f } - result should equal (Seq(0, 100, 0)) + result should equal(Seq(0, 100, 0)) } } diff --git a/src/test/scala/scalacl/impl/ConversionTest.scala b/src/test/scala/scalacl/impl/ConversionTest.scala index 760ce54..7e071cd 100644 --- a/src/test/scala/scalacl/impl/ConversionTest.scala +++ b/src/test/scala/scalacl/impl/ConversionTest.scala @@ -31,64 +31,27 @@ package scalacl package impl -import scalaxy.components._ - -import org.junit._ -import Assert._ -import org.hamcrest.CoreMatchers._ - class ConversionTest - extends CodeConversion - with WithRuntimeUniverse - with WithTestFresh { + extends BaseTest + with CodeConversionTest { import global._ - private val context = reify { null: Context } - private val NotVectorizable: Option[Expr[Unit]] = None - private val Vectorizable = not(NotVectorizable) - - private def conv(block: Expr[Unit], explicitParamDescs: Seq[ParamDesc] = Seq()) = { - convertCode(typeCheck(block.tree, WildcardType), explicitParamDescs) - } - - def assertParamDesc(d: ParamDesc, name: String, tpe: Type, usage: UsageKind, kind: ParamKind) = { - assertEquals(name, d.symbol.name.toString) - assertEquals(tpe, d.tpe) - assertEquals(kind, d.mode) - assertEquals(usage, d.usage) - } - - def inputParam[T: TypeTag](name: String, mode: ParamKind = ParamKind.Normal) = { - ParamDesc( - symbol = internal.newTermSymbol(NoSymbol, TermName(name)), - output = true, - tpe = typeOf[T], - mode = mode, - usage = UsageKind.Input) - } - - def outputParam[T: TypeTag](name: String, mode: ParamKind = ParamKind.Normal) = { - ParamDesc( - symbol = internal.newTermSymbol(NoSymbol, TermName(name)), - output = true, - tpe = typeOf[T], - mode = mode, - usage = UsageKind.Output) - } + behavior of "CodeConversion" - @Test - def simpleCaptures() { + ignore should "captures on simple expression" in { val in: CLArray[Int] = null val out: CLArray[Int] = null val f = 10 - val c = conv(reify { out(1) = in(2) * f }) - - assertEquals( - "kernel void f(global const int* in, global int* out, int f) {\n" + - "\tout[1] = (in[2] * f);;\n" + - "}", - c.code - ) + val c = convertExpression(reify { + out(1) = in(2) * f + }) + + val kernel = "kernel void f(global const int* in, global int* out, int f) {\n" + + "\tout[1] = (in[2] * f);;\n" + + "}" + + kernel should equal(c.code) + val Seq(inDesc) = c.capturedInputs assertParamDesc(inDesc, "in", typeOf[CLArray[Int]], UsageKind.Input, ParamKind.Normal) @@ -99,52 +62,71 @@ class ConversionTest assertParamDesc(fDesc, "f", typeOf[Int], UsageKind.Input, ParamKind.Normal) } - @Test - def simpleTupleResult() { + ignore should "convert tuple" in { val in: CLArray[Int] = null val out: CLArray[(Int, Float)] = null - val c = conv(reify { out(0) = (in(0), in(2).toFloat) }) - assertEquals( - "kernel void f(global const int* in, global int* out$1, global float* out$2) {\n" + - "\tconst long index0 = 0;\n" + - "\tout$1[index0] = in[0];;\n" + - "\tout$2[index0] = ((float)in[2]);;\n" + - "}", - c.code - ) + val c = convertExpression(reify { + out(0) = (in(0), in(2).toFloat) + }) + val kernel = "kernel void f(global const int* in, global int* out$1, global float* out$2) {\n" + + "\tconst long index0 = 0;\n" + + "\tout$1[index0] = in[0];;\n" + + "\tout$2[index0] = ((float)in[2]);;\n" + + "}" + + kernel should equal(c.code) } - @Ignore - @Test - def simpleTuplesCaptures() { + ignore should "convert tuple expression" in { val in: CLArray[(Int, (Float, Short))] = null val out: CLArray[Float] = null - val c = conv(reify { + val c = convertExpression(reify { val (i, (f, s)) = in(0) out(0) = i + f + s }) - assertEquals( - "kernel void f(global const int* in, global int* out) {\n" + - "\tout[1] = (in[2] * f);\n" + - "}", - c.code - ) + + val kernel = "kernel void f(global const int* in, global int* out) {\n" + + "\tout[1] = (in[2] * f);\n" + + "}" + kernel should equal(c.code) } - @Ignore - @Test - def aliasedTuplesCaptures() { + ignore should "convert aliased tuple" in { val in: CLArray[(Int, (Float, Short))] = null val out: CLArray[Float] = null - val c = conv(reify { + val c = convertExpression(reify { val (i, p @ (f, s)) = in(0) out(0) = i + f + s + p._1 + p._2 }) - assertEquals( - "kernel void f(global const int* in, global int* out) {\n" + - "\tout[1] = (in[2] * f);\n" + - "}", - c.code - ) + val kernel = "kernel void f(global const int* in, global int* out) {\n" + + "\tout[1] = (in[2] * f);\n" + + "}" + + kernel should equal(c.code) + } + + private def assertParamDesc(d: ParamDesc, name: String, tpe: Type, usage: UsageKind, kind: ParamKind) = { + name should equal(d.symbol.name.toString) + tpe should equal(d.tpe) + kind should equal(d.mode) + usage should equal(d.usage) + } + + private def inputParam[T: TypeTag](name: String, mode: ParamKind = ParamKind.Normal) = { + ParamDesc( + symbol = internal.newTermSymbol(NoSymbol, TermName(name)), + output = true, + tpe = typeOf[T], + mode = mode, + usage = UsageKind.Input) + } + + private def outputParam[T: TypeTag](name: String, mode: ParamKind = ParamKind.Normal) = { + ParamDesc( + symbol = internal.newTermSymbol(NoSymbol, TermName(name)), + output = true, + tpe = typeOf[T], + mode = mode, + usage = UsageKind.Output) } } diff --git a/src/test/scala/scalacl/impl/DefaultScheduledDataTest.scala b/src/test/scala/scalacl/impl/DefaultScheduledDataTest.scala index debbf3a..58b91e5 100644 --- a/src/test/scala/scalacl/impl/DefaultScheduledDataTest.scala +++ b/src/test/scala/scalacl/impl/DefaultScheduledDataTest.scala @@ -31,72 +31,66 @@ package scalacl package impl -import org.junit._ -import Assert._ -import org.hamcrest.CoreMatchers._ - import collection.mutable.ArrayBuffer import com.nativelibs4java.opencl.CLEvent import com.nativelibs4java.opencl.MockEvent -import com.nativelibs4java.opencl.library.OpenCLLibrary._ - -class DefaultScheduledDataTest { - val data = new DefaultScheduledData {} - def isLocked = data.scheduleLock.isLocked - assertFalse(isLocked) - - val e1 = new MockEvent(1) - val e2 = new MockEvent(2) - val e3 = new MockEvent(3) - def read(event: CLEvent, expectReads: List[CLEvent], expectWrite: CLEvent) { - val events = new ArrayBuffer[CLEvent] - data.startRead(events) - assertEquals("bad read events", Option(expectWrite).toSeq, events.toList) - assertTrue(isLocked) +class DefaultScheduledDataTest + extends BaseTest { - data.endRead(event) - assertEquals("bad dataWrite", expectWrite, data.dataWrite) - assertEquals("bad dataReads", expectReads ++ Option(event), data.dataReads.toList) - assertFalse(isLocked) - } + behavior of "DefaultScheduledData" - def write(event: CLEvent, expectReads: List[CLEvent], expectWrite: CLEvent) { - val events = new ArrayBuffer[CLEvent] - data.startWrite(events) - assertEquals("bad write events", expectReads ++ Option(expectWrite), events.toList) - assertTrue(isLocked) + private val data = new DefaultScheduledData {} + private def isLocked = data.scheduleLock.isLocked - data.endWrite(event) - assertEquals("bad dataWrite", event, data.dataWrite) - assertEquals("bad dataReads", Nil, data.dataReads.toList) - assertFalse(isLocked) - } + private val e1 = new MockEvent(1) + private val e2 = new MockEvent(2) + private val e3 = new MockEvent(3) - @Test - def simpleReads() { + it should "reads" in { read(e1, Nil, null) read(e2, List(e1), null) } - @Test - def simpleWrites() { + ignore should "writes" in { write(e1, Nil, null) write(e2, Nil, e1) } - @Test - def simpleReadWriteRead() { + ignore should "read -> write -> read" in { read(e1, Nil, null) write(e2, List(e1), null) read(e3, Nil, e2) } - @Test - def simpleWriteReadWrite() { + ignore should "write -> read -> write" in { write(e1, Nil, null) read(e2, Nil, e1) write(e3, List(e2), e1) } + + private def read(event: CLEvent, expectReads: List[CLEvent], expectWrite: CLEvent) { + val events = new ArrayBuffer[CLEvent] + data.startRead(events) + Option(expectWrite).toSeq should equal(events.toList) + assert(isLocked) + + data.endRead(event) + expectWrite should equal(data.dataWrite) + (expectReads ++ Option(event)) should equal(data.dataReads.toList) + assert(!isLocked) + } + + private def write(event: CLEvent, expectReads: List[CLEvent], expectWrite: CLEvent) { + val events = new ArrayBuffer[CLEvent] + data.startWrite(events) + (expectReads ++ Option(expectWrite)) should equal(events.toList) + assert(isLocked) + + data.endWrite(event) + event should equal(data.dataWrite) + data.dataReads.toList should equal(Nil) + assert(!isLocked) + } } diff --git a/src/test/scala/scalacl/impl/InlinedCollectionsTest.scala b/src/test/scala/scalacl/impl/InlinedCollectionsTest.scala index 6d0ae1d..70ed145 100644 --- a/src/test/scala/scalacl/impl/InlinedCollectionsTest.scala +++ b/src/test/scala/scalacl/impl/InlinedCollectionsTest.scala @@ -31,14 +31,15 @@ package scalacl import impl._ -import org.junit._ -import Assert._ - import InlinedCollections._ -class InlinedCollectionsTest { - @Test - def simple() { - println(inlineMapAsSwitch("map", Map(1 -> 10, 2 -> 20))) +class InlinedCollectionsTest + extends BaseTest { + + behavior of "InlinedCollections" + + ignore should "inline map as switch" in { + //TODO some validation + inlineMapAsSwitch("map", Map(1 -> 10, 2 -> 20)) } } diff --git a/src/test/scala/scalacl/impl/OpenCLCodeFlatteningTest.scala b/src/test/scala/scalacl/impl/OpenCLCodeFlatteningTest.scala index 46baf6e..5142791 100644 --- a/src/test/scala/scalacl/impl/OpenCLCodeFlatteningTest.scala +++ b/src/test/scala/scalacl/impl/OpenCLCodeFlatteningTest.scala @@ -33,77 +33,32 @@ package impl import scalaxy.components._ -import org.junit._ -import Assert._ -import org.hamcrest.CoreMatchers._ - class OpenCLCodeFlatteningTest - extends OpenCLCodeFlattening - with WithRuntimeUniverse - with WithTestFresh { + extends BaseTest + with CodeFlatteningTest { import global._ - /* - def conv(x: Expr[_]) = convert(typeCheck(x)) - def code(statements: Seq[String], values: Seq[String]) = - FlatCode[String](statements = statements, values = values) - - def flattenWithInputSymbols(body: Tree, inputSymbols: Seq[Symbol]): FlatCode[String] = { - val renamed = renameDefinedSymbolsUniquely(body) - val tupleAnalyzer = new TupleAnalyzer(renamed) - val flattener = new TuplesAndBlockFlattener(tupleAnalyzer) - val Seq(uniqueParam) = inputSymbols - val flattened = flattener.flattenTuplesAndBlocksWithInputSymbol(renamed, uniqueParam.symbol, uniqueParam.name, currentOwner)(unit) - - } - */ - def unwrap(tree: Tree): Tree = tree match { - case Block(List(sub), Literal(Constant(()))) => sub - case _ => tree - } - - def code(statements: Seq[Expr[_]] = Seq(), values: Seq[Expr[_]] = Seq()) = - FlatCode[Tree]( - statements = statements.map(x => unwrap(typeCheck(x.tree, WildcardType))), - values = values.map(x => unwrap(typeCheck(x.tree, WildcardType))) - ) - - def inputSymbols(xs: Expr[_]*): Seq[(Symbol, Type)] = { - for (x <- xs.toSeq) yield { - val i @ Ident(n) = typeCheck(x.tree, WildcardType) - (i.symbol, i.tpe) - } - } + behavior of "OpenCLCodeFlattening" - def flat(x: Expr[_], inputSymbols: Seq[(Symbol, Type)] = Seq(), owner: Symbol = NoSymbol): FlatCode[Tree] = { - flatten(typeCheck(x.tree, WildcardType), inputSymbols, owner) - } - - def assertEquals(a: FlatCode[Tree], b: FlatCode[Tree]) { - Assert.assertEquals(a.transform(_.toList).toString, b.transform(_.toList).toString) - } - - @Test - def simpleTupleValue() { + ignore should "flatten tuple of values" in { val x = 10 assertEquals( - code(values = List( + flatCode(values = List( reify { x }, reify { x + 1 } )), - flat( + flatExpression( reify { (x, x + 1) }, inputSymbols(reify { x }) ) ) } - @Test - def simpleTupleReference() { + ignore should "flatten tuple of references" in { val p = (10, 12) val Seq(p$1, p$2, pp$1, pp$2) = 1 to 4 assertEquals( - code( + flatCode( statements = List( reify { val pp$1 = p$1 }, reify { val pp$2 = p$2 } @@ -113,10 +68,14 @@ class OpenCLCodeFlatteningTest reify { pp$2 } ) ), - flat( + flatExpression( reify { val pp = p; pp }, inputSymbols(reify { p }) ) ) } + + private def assertEquals(a: FlatCode[Tree], b: FlatCode[Tree]) { + a.transform(_.toList).toString should equal(b.transform(_.toList).toString) + } } diff --git a/src/test/scala/scalacl/impl/OpenCLConverterTest.scala b/src/test/scala/scalacl/impl/OpenCLConverterTest.scala index 6f088fb..69a01d3 100644 --- a/src/test/scala/scalacl/impl/OpenCLConverterTest.scala +++ b/src/test/scala/scalacl/impl/OpenCLConverterTest.scala @@ -31,51 +31,42 @@ package scalacl package impl -import scalaxy.components._ - -import org.junit._ -import Assert._ -import org.hamcrest.CoreMatchers._ - class OpenCLConverterTest - extends OpenCLConverter - with WithRuntimeUniverse - with WithTestFresh { - import global._ + extends BaseTest + with OpenCLConverter + with CodeConversionTest { - def conv(x: Expr[_]): FlatCode[String] = { - //convert(typeCheck(x)) - flattenAndConvert(typeCheck(x)) - } + behavior of "OpenClConverter" - def code(statements: Seq[String], values: Seq[String]): FlatCode[String] = - FlatCode[String](statements = statements, values = values) + ignore should "convert touple" in { + val flattenCode = flatCode( + Seq("const int x = 10;"), + Seq("x", "(x * 2)") + ) - @Test - def testSimpleTuple() { - assertEquals( - code( - Seq("const int x = 10;"), - Seq("x", "(x * 2)") - ), - conv(reify { + val convertedExpression = + flatAndConvertExpression(global.reify { val x = 10 (x, x * 2) }) - ) + + flattenCode should equal(convertedExpression) } - @Test - def testSimpleMath() { + ignore should "convert simple function: cos" in { import scala.math._ - assertEquals( - code( - Seq(), - Seq("cos((float)10.0)") - ), - conv(reify { + + val flattenCode = flatCode( + Seq(), + Seq("cos((float)10.0)") + ) + + val convertedExpression = + flatAndConvertExpression(global.reify { cos(10) }) - ) + + flattenCode should equal(convertedExpression) } + } diff --git a/src/test/scala/scalacl/impl/SymbolKindsTest.scala b/src/test/scala/scalacl/impl/SymbolKindsTest.scala index 45cf1a0..0174cbf 100644 --- a/src/test/scala/scalacl/impl/SymbolKindsTest.scala +++ b/src/test/scala/scalacl/impl/SymbolKindsTest.scala @@ -49,22 +49,22 @@ class SymbolKindsTest var v = 0 } - it should "find properly kind some object" in { - SymbolKind.Tuploid should equal (kindOf(typeOf[Int])) - SymbolKind.Tuploid should equal (kindOf(typeOf[Float])) - SymbolKind.Tuploid should equal (kindOf(typeOf[(Int, Int)])) + ignore should "find properly kind some object" in { + SymbolKind.Tuploid should equal(kindOf(typeOf[Int])) + SymbolKind.Tuploid should equal(kindOf(typeOf[Float])) + SymbolKind.Tuploid should equal(kindOf(typeOf[(Int, Int)])) - SymbolKind.ArrayLike should equal (kindOf(typeOf[CLArray[Int]])) - SymbolKind.ArrayLike should equal (kindOf(typeOf[CLFilteredArray[Int]])) + SymbolKind.ArrayLike should equal(kindOf(typeOf[CLArray[Int]])) + SymbolKind.ArrayLike should equal(kindOf(typeOf[CLFilteredArray[Int]])) - SymbolKind.Tuploid should equal (kindOf(typeOf[ImmutableClass])) - SymbolKind.Tuploid should equal (kindOf(typeOf[ImmutableCaseClass])) + SymbolKind.Tuploid should equal(kindOf(typeOf[ImmutableClass])) + SymbolKind.Tuploid should equal(kindOf(typeOf[ImmutableCaseClass])) - SymbolKind.Other should equal (kindOf(typeOf[MutableClass])) - SymbolKind.Other should equal (kindOf(typeOf[MutableCaseClass])) + SymbolKind.Other should equal(kindOf(typeOf[MutableClass])) + SymbolKind.Other should equal(kindOf(typeOf[MutableCaseClass])) - SymbolKind.Other should equal (kindOf(typeOf[EmptyClass])) - SymbolKind.Other should equal (kindOf(typeOf[EmptyCaseClass])) + SymbolKind.Other should equal(kindOf(typeOf[EmptyClass])) + SymbolKind.Other should equal(kindOf(typeOf[EmptyCaseClass])) } } diff --git a/src/test/scala/scalacl/impl/VectorizationTest.scala b/src/test/scala/scalacl/impl/VectorizationTest.scala index eb65000..38b54e5 100644 --- a/src/test/scala/scalacl/impl/VectorizationTest.scala +++ b/src/test/scala/scalacl/impl/VectorizationTest.scala @@ -31,52 +31,48 @@ package scalacl package impl -import scalaxy.components._ - class VectorizationTest - extends BaseTest - with Vectorization - with RuntimeUniverseTest { - - behavior of "ScalaCl vectorization" - + extends RuntimeUniverseTest + with BaseTest + with Vectorization { import global._ - private val context = reify { null: Context } - private val vectorized: Option[Expr[Unit]] = mock[Some[Expr[Unit]]] + behavior of "ScalaCl vectorization" - private def afterVectorization(block: Expr[Unit]): Option[global.Expr[Unit]] = { - try { - vectorize(context, typeCheck(block.tree, WildcardType)) - } catch { - case ex: Throwable => - ex.printStackTrace() - throw ex - } - } + private val context = reify { null: Context } + private val vectorized = not be None - it should "not vectorized 0D expression" in { - afterVectorization(reify { 1 + 2 }) should not be vectorized + ignore should "not vectorized 0D expression" in { + vectorization(reify { 1 + 2 }) should not(vectorized) } - it should "vectorized 1D expression" in { - afterVectorization(reify { + ignore should "vectorized 1D expression" in { + vectorization(reify { for (i <- 0 until 10) i + 1 - }) should be (vectorized) + }) should vectorized } - it should "vectorized 2D expression" in { - afterVectorization(reify { + ignore should "vectorized 2D expression" in { + vectorization(reify { for (i <- 0 until 10; j <- 0 until 10) i + j + 2 - }) should be (vectorized) + }) should vectorized } ignore should "vectorized 3D expression" in { - afterVectorization(reify { + vectorization(reify { for (i <- 0 until 10; j <- 0 until 10; k <- 0 until 10) i + j + k + 3 - }) should be (vectorized) + }) should vectorized } + private def vectorization(block: Expr[Unit]) = { + try { + vectorize(context, typeCheck(block.tree, WildcardType)) + } catch { + case ex: Throwable => + ex.printStackTrace() + throw ex + } + } } From e975f699ac5bcd2dc47bc39f845a7b25120d9aee Mon Sep 17 00:00:00 2001 From: Jan Paw Date: Sat, 9 Aug 2014 20:13:13 +0200 Subject: [PATCH 05/10] SCL-4 remove junit --- project/ScalaCLBuild.scala | 4 +- src/test/scala/scalacl/BaseTest.scala | 64 ++++++++++++++-- src/test/scala/scalacl/CLFunctionTest.scala | 37 ++-------- src/test/scala/scalacl/MatrixTest.scala | 74 +++++++++---------- .../impl/DefaultScheduledDataTest.scala | 5 +- .../scalacl/impl/InlinedCollectionsTest.scala | 4 +- .../scalacl/impl/OpenCLConverterTest.scala | 5 +- .../scalacl/impl/ScheduledDataTest.scala | 46 +++++------- .../scala/scalacl/impl/SymbolKindsTest.scala | 7 +- .../scalacl/impl/VectorizationTest.scala | 5 +- 10 files changed, 135 insertions(+), 116 deletions(-) diff --git a/project/ScalaCLBuild.scala b/project/ScalaCLBuild.scala index 5756b1b..6f8fbc4 100644 --- a/project/ScalaCLBuild.scala +++ b/project/ScalaCLBuild.scala @@ -79,10 +79,8 @@ object ScalaCLBuild extends Build { libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _), libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-compiler" % _), libraryDependencies ++= Seq( - "junit" % "junit" % "4.10" % "test", "org.scalatest" % "scalatest_2.11" % "2.2.1" % "test", - "org.scalamock" % "scalamock-scalatest-support_2.11" % "3.1.2", - "com.novocode" % "junit-interface" % "0.8" % "test" + "org.scalamock" % "scalamock-scalatest-support_2.11" % "3.1.2" ) ) diff --git a/src/test/scala/scalacl/BaseTest.scala b/src/test/scala/scalacl/BaseTest.scala index dd5a69b..20aaef1 100644 --- a/src/test/scala/scalacl/BaseTest.scala +++ b/src/test/scala/scalacl/BaseTest.scala @@ -2,8 +2,11 @@ package scalacl import org.scalamock.scalatest.MockFactory import org.scalatest.{ FlatSpecLike, Matchers } -import scalacl.impl.{ OpenCLCodeFlattening, CodeConversion } -import scalaxy.components.{ FlatCode, WithRuntimeUniverse } + +import scala.reflect.runtime.{ currentMirror => cm, universe => ru } +import scala.tools.reflect.ToolBox +import scalacl.impl.{ Vectorization, CodeConversion, OpenCLCodeFlattening } +import scalaxy.components.FlatCode trait BaseTest extends FlatSpecLike with Matchers with MockFactory { def context[T](f: Context => T): T = { @@ -14,7 +17,12 @@ trait BaseTest extends FlatSpecLike with Matchers with MockFactory { } } -trait RuntimeUniverseTest extends WithRuntimeUniverse { +trait RuntimeUniverseTest { + lazy val global = ru + import global._ + + def verbose = false + private var nextId = 0L def fresh(s: String) = synchronized { @@ -22,22 +30,64 @@ trait RuntimeUniverseTest extends WithRuntimeUniverse { nextId += 1 s + v } + + def warning(pos: Position, msg: String) = + println(msg + " (" + pos + ")") + + def withSymbol[T <: Tree](sym: Symbol, tpe: Type = NoType)(tree: T): T = tree + + def typed[T <: Tree](tree: T): T = { + // if (tree.tpe == null && tree.tpe == NoType) + // toolbox.typeCheck(tree.asInstanceOf[toolbox.u.Tree]).asInstanceOf[T] + // else + tree + } + + def inferImplicitValue(pt: Type): Tree = + toolbox.inferImplicitValue(pt.asInstanceOf[toolbox.u.Type]).asInstanceOf[global.Tree] + + lazy val toolbox = cm.mkToolBox() + + def typeCheck(x: Expr[_]): Tree = + typeCheck(x.tree) + + def typeCheck(tree: Tree, pt: Type = WildcardType): Tree = { + val ttree = tree.asInstanceOf[toolbox.u.Tree] + if (ttree.tpe != null && ttree.tpe != NoType) + tree + else { + try { + toolbox.typecheck( + ttree, + pt = pt.asInstanceOf[toolbox.u.Type]) + } catch { + case ex: Throwable => + throw new RuntimeException(s"Failed to typeCheck($tree, $pt): $ex", ex) + } + }.asInstanceOf[Tree] + } + + def resetLocalAttrs(tree: Tree): Tree = { + toolbox.untypecheck(tree.asInstanceOf[toolbox.u.Tree]).asInstanceOf[Tree] + } + } trait CodeConversionTest extends CodeConversion with RuntimeUniverseTest { val global: reflect.api.Universe + import global._ def convertExpression(block: Expr[Unit], explicitParamDescs: Seq[ParamDesc] = Seq()) = { convertCode(typeCheck(block.tree, WildcardType), explicitParamDescs) } + def flatStatement(statements: Seq[String], values: Seq[String]): FlatCode[String] = + FlatCode[String](statements = statements, values = values) + def flatAndConvertExpression(x: Expr[_]): FlatCode[String] = { flattenAndConvert(typeCheck(x)) } - - def flatCode(statements: Seq[String], values: Seq[String]): FlatCode[String] = - FlatCode[String](statements = statements, values = values) } trait CodeFlatteningTest extends OpenCLCodeFlattening with RuntimeUniverseTest { @@ -67,3 +117,5 @@ trait CodeFlatteningTest extends OpenCLCodeFlattening with RuntimeUniverseTest { flatten(typeCheck(x.tree, WildcardType), inputSymbols, owner) } } + +trait CodeVectorizationTest extends Vectorization with RuntimeUniverseTest diff --git a/src/test/scala/scalacl/CLFunctionTest.scala b/src/test/scala/scalacl/CLFunctionTest.scala index e6e28f9..800360b 100644 --- a/src/test/scala/scalacl/CLFunctionTest.scala +++ b/src/test/scala/scalacl/CLFunctionTest.scala @@ -29,42 +29,21 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package scalacl -import impl._ -import org.junit._ -import Assert._ +class CLFunctionTest extends BaseTest { -class CLFunctionTest { - @Ignore - @Test - def simple() { - implicit val context = Context.best - try { + behavior of "CLFunction" + + ignore should "wrap scalar function" in context { + implicit context => val a = CLArray[Int](1, 2, 3) val v = 10 - // task { - // a(1) = 10 * v - // } - // println(a.toSeq) - // assertEquals(Seq(0, 100, 0), a.toSeq) - val f: CLFunction[Int, Float] = (x: Int) => { + val clFunction: CLFunction[Int, Float] = (x: Int) => { x * 2.0f * v } - println(f) - println(f.value) - println(f.functionKernel) - assertArrayEquals( - Array(20.0f, 40.0f, 60.0f), - a.map(f).toArray, - 0) - } catch { - case ex: Throwable => - ex.printStackTrace() - throw ex - } finally { - context.release() - } + val clResult = a.map(clFunction).toArray + clResult should equal(Array(20.0f, 40.0f, 60.0f)) } } diff --git a/src/test/scala/scalacl/MatrixTest.scala b/src/test/scala/scalacl/MatrixTest.scala index aaab4e5..1738c2d 100644 --- a/src/test/scala/scalacl/MatrixTest.scala +++ b/src/test/scala/scalacl/MatrixTest.scala @@ -1,8 +1,7 @@ package scalacl -import org.junit._ -import Assert._ -class MatrixTest { +class MatrixTest extends BaseTest { + behavior of "Matrix" case class Matrix(data: CLArray[Float], rows: Int, columns: Int)(implicit context: Context) { def this(rows: Int, columns: Int)(implicit context: Context) = @@ -11,7 +10,7 @@ class MatrixTest { this(n, n) } - def mult(a: Matrix, b: Matrix, out: Matrix)(implicit context: Context) = { + def mul(a: Matrix, b: Matrix, out: Matrix)(implicit context: Context) = { assert(a.columns == b.rows) assert(a.rows == out.rows) assert(b.columns == out.columns) @@ -43,45 +42,40 @@ class MatrixTest { } } - @Ignore - @Test - def testMatrix2() { - implicit val context = Context.best + ignore should "perform multiplication of two matrix" in context { + implicit context => + val n = 10 + val a = new Matrix(n) + val b = new Matrix(n) + val out = new Matrix(n) - val n = 10 - val out = new Matrix(n) - val outData = out.data - kernel { - // This block will either be converted to an OpenCL kernel or cause compilation error - // It captures out.data, a.data and b.data - for (i <- 0 until 10; j <- 0 until 20) { - // TODO chain map and sum (to avoid creating a builder here !) - // outData(i * 30 + j) = - // (0 until 30).map(k => { - // aData(i * 30 + k) * bData(k * 30 + j) - // }).sum - var tot = 0f - for (k <- 0 until 30) { - //tot = tot + aData(i * aColumns + k) * bData(k * bColumns + j) - tot = 10000 + //TODO add some verification + mul(a, b, out) + } + + ignore should "generate kernel with matrix type" in context { + implicit context => + val n = 10 + val out = new Matrix(n) + val outData = out.data + kernel { + // This block will either be converted to an OpenCL kernel or cause compilation error + // It captures out.data, a.data and b.data + for (i <- 0 until 10; j <- 0 until 20) { + // TODO chain map and sum (to avoid creating a builder here !) + // outData(i * 30 + j) = + // (0 until 30).map(k => { + // aData(i * 30 + k) * bData(k * 30 + j) + // }).sum + var tot = 0f + for (k <- 0 until 30) { + //tot = tot + aData(i * aColumns + k) * bData(k * bColumns + j) + tot = 10000 + } + outData(i * 10 + j) = tot } - outData(i * 10 + j) = tot } - } + //TODO add some verification } - @Ignore - @Test - def testMatrix() { - implicit val context = Context.best - - val n = 10 - val a = new Matrix(n) - val b = new Matrix(n) - val out = new Matrix(n) - - mult(a, b, out) - - println(out.data) - } } diff --git a/src/test/scala/scalacl/impl/DefaultScheduledDataTest.scala b/src/test/scala/scalacl/impl/DefaultScheduledDataTest.scala index 58b91e5..1f160e2 100644 --- a/src/test/scala/scalacl/impl/DefaultScheduledDataTest.scala +++ b/src/test/scala/scalacl/impl/DefaultScheduledDataTest.scala @@ -36,8 +36,11 @@ import collection.mutable.ArrayBuffer import com.nativelibs4java.opencl.CLEvent import com.nativelibs4java.opencl.MockEvent +import scalaxy.components.WithRuntimeUniverse + class DefaultScheduledDataTest - extends BaseTest { + extends BaseTest + with WithRuntimeUniverse { behavior of "DefaultScheduledData" diff --git a/src/test/scala/scalacl/impl/InlinedCollectionsTest.scala b/src/test/scala/scalacl/impl/InlinedCollectionsTest.scala index 70ed145..b5961ab 100644 --- a/src/test/scala/scalacl/impl/InlinedCollectionsTest.scala +++ b/src/test/scala/scalacl/impl/InlinedCollectionsTest.scala @@ -32,9 +32,11 @@ package scalacl import impl._ import InlinedCollections._ +import scalaxy.components.WithRuntimeUniverse class InlinedCollectionsTest - extends BaseTest { + extends BaseTest + with WithRuntimeUniverse { behavior of "InlinedCollections" diff --git a/src/test/scala/scalacl/impl/OpenCLConverterTest.scala b/src/test/scala/scalacl/impl/OpenCLConverterTest.scala index 69a01d3..2395320 100644 --- a/src/test/scala/scalacl/impl/OpenCLConverterTest.scala +++ b/src/test/scala/scalacl/impl/OpenCLConverterTest.scala @@ -33,13 +33,12 @@ package impl class OpenCLConverterTest extends BaseTest - with OpenCLConverter with CodeConversionTest { behavior of "OpenClConverter" ignore should "convert touple" in { - val flattenCode = flatCode( + val flattenCode = flatStatement( Seq("const int x = 10;"), Seq("x", "(x * 2)") ) @@ -56,7 +55,7 @@ class OpenCLConverterTest ignore should "convert simple function: cos" in { import scala.math._ - val flattenCode = flatCode( + val flattenCode = flatStatement( Seq(), Seq("cos((float)10.0)") ) diff --git a/src/test/scala/scalacl/impl/ScheduledDataTest.scala b/src/test/scala/scalacl/impl/ScheduledDataTest.scala index 0cda1f5..f41f147 100644 --- a/src/test/scala/scalacl/impl/ScheduledDataTest.scala +++ b/src/test/scala/scalacl/impl/ScheduledDataTest.scala @@ -31,10 +31,6 @@ package scalacl package impl -import org.junit._ -import Assert._ -import org.hamcrest.CoreMatchers._ - import com.nativelibs4java.opencl.CLEvent import com.nativelibs4java.opencl.MockEvent import com.nativelibs4java.opencl.library.OpenCLLibrary._ @@ -42,9 +38,11 @@ import com.nativelibs4java.opencl.library.IOpenCLLibrary._ import scala.collection.mutable.ArrayBuffer -class ScheduledDataTest { - @Test - def simpleOpWithoutEvent() { +class ScheduledDataTest extends BaseTest { + behavior of "ScheduledDate" + + //TODO create higher granularization + ignore should "perform some reads and writes" in { val inEvt = new MockEvent(1) val outEvt = new MockEvent(2) val opEvt = new MockEvent(3) @@ -63,29 +61,25 @@ class ScheduledDataTest { } ScheduledData.schedule(Array(in), Array(out), events => { - assertEquals(Seq(inEvt, outEvt), events.toSeq) + Seq(inEvt, outEvt) should equal(events.toSeq) opEvt }) - assertNotNull(opEvt.completionCallback) - assertEquals( - "in calls don't match", - Seq( - 'startRead -> List(Nil), - 'endRead -> List(opEvt)), - in.calls) - assertEquals( - "out calls don't match", - Seq( - 'startWrite -> List(List(inEvt)), - 'endWrite -> List(opEvt)), - out.calls) + opEvt.completionCallback should not be null + + Seq( + 'startRead -> List(Nil), + 'endRead -> List(opEvt) + ) should equal(in.calls) + + Seq( + 'startWrite -> List(List(inEvt)), + 'endWrite -> List(opEvt) + ) should equal(out.calls) opEvt.completionCallback.callback(CL_COMPLETE) - for (d <- Seq(in, out)) - assertEquals( - Seq( - 'eventCompleted -> List(opEvt)), - d.calls) + Seq(in, out).foreach { + d => Seq('eventCompleted -> List(opEvt)) should equal(d.calls) + } } } diff --git a/src/test/scala/scalacl/impl/SymbolKindsTest.scala b/src/test/scala/scalacl/impl/SymbolKindsTest.scala index 0174cbf..1877296 100644 --- a/src/test/scala/scalacl/impl/SymbolKindsTest.scala +++ b/src/test/scala/scalacl/impl/SymbolKindsTest.scala @@ -33,13 +33,12 @@ package impl class SymbolKindsTest extends BaseTest - with RuntimeUniverseTest - with SymbolKinds { + with SymbolKinds + with RuntimeUniverseTest { + import global._ behavior of "Symbols kind resolving" - import global._ - class EmptyClass() case class EmptyCaseClass() class ImmutableClass(a: Int, b: Int) diff --git a/src/test/scala/scalacl/impl/VectorizationTest.scala b/src/test/scala/scalacl/impl/VectorizationTest.scala index 38b54e5..703036c 100644 --- a/src/test/scala/scalacl/impl/VectorizationTest.scala +++ b/src/test/scala/scalacl/impl/VectorizationTest.scala @@ -32,9 +32,8 @@ package scalacl package impl class VectorizationTest - extends RuntimeUniverseTest - with BaseTest - with Vectorization { + extends BaseTest + with CodeVectorizationTest { import global._ behavior of "ScalaCl vectorization" From f7956b05ad29cb9a713cf0b05ab8b1833c77e27a Mon Sep 17 00:00:00 2001 From: Jan Paw Date: Thu, 14 Aug 2014 10:02:25 +0200 Subject: [PATCH 06/10] Update ScalaCLBuild.scala --- project/ScalaCLBuild.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/ScalaCLBuild.scala b/project/ScalaCLBuild.scala index 6f8fbc4..9f5c452 100644 --- a/project/ScalaCLBuild.scala +++ b/project/ScalaCLBuild.scala @@ -71,7 +71,7 @@ object ScalaCLBuild extends Build { // "-optimise", "-deprecation", "-feature", - // "-Xlog-free-types",q + // "-Xlog-free-types", // "-Ymacro-debug-lite", "-unchecked" ), From b11f4c89934c51e287fe8a36da4beabd73bb6508 Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Tue, 24 Mar 2015 00:06:18 +0000 Subject: [PATCH 07/10] readme --- LICENSE | 14 ++++++++++++++ README.md | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..aeec42d --- /dev/null +++ b/LICENSE @@ -0,0 +1,14 @@ +SCALACL LICENSE + +Copyright (c) 2010-2015 Olivier Chafik, unless otherwise specified. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. Neither the name of Scalaxy nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index 2f38299..0f1a99b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ [![Build Status](https://travis-ci.org/nativelibs4java/ScalaCL.svg?branch=feature_travis-build)](https://travis-ci.org/nativelibs4java/ScalaCL) [![Join the chat at https://gitter.im/nativelibs4java/ScalaCL](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/nativelibs4java/ScalaCL?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -ScalaCL... v3 (yeah, yet another rewrite from scratch FTW!) -BARELY FUNCTIONAL YET, WORK IN PROGRESS (see [ScalaCL](https://code.google.com/p/scalacl/) if you want something that _works_, albeit only on Scala 2.9.x). +ScalaCL lets you run Scala code on GPUs through OpenCL ([BSD-licensed](./LICENSE)). -Features of the new design: +WORK IN PROGRESS (see [ScalaCL](https://code.google.com/p/scalacl/) if you want something that _works_, albeit only on Scala 2.9.x). + +Features of the new design (v3, rewritten from scratch again!): - Much better asynchronicity support (now requires OpenCL 1.1), and much better performance in general - Support for captures of constants *and* OpenCL arrays - Support for lazy clones for fast zipping From a2b8dc9114aff89b6931669849033def107feff3 Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Thu, 26 Mar 2015 00:51:37 +0000 Subject: [PATCH 08/10] Update likely location of local scalaxy-streams project --- project/ScalaCLBuild.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/ScalaCLBuild.scala b/project/ScalaCLBuild.scala index a65620e..bb5290b 100644 --- a/project/ScalaCLBuild.scala +++ b/project/ScalaCLBuild.scala @@ -154,8 +154,8 @@ object ScalaCLBuild extends Build { List( ( "com.nativelibs4java" %% "scalaxy-streams" % "0.4-SNAPSHOT", - "../Scalaxy", - "git://github.com/nativelibs4java/Scalaxy.git" + "../scalaxy-streams", + "git://github.com/nativelibs4java/scalaxy-streams.git" ), ( "com.nativelibs4java" %% "scalaxy-reified" % "0.4-SNAPSHOT", From 769a69d645a31d1df1b323371ea185d31586dc6c Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Fri, 27 Mar 2015 00:50:43 +0000 Subject: [PATCH 09/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f1a99b..c052218 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/nativelibs4java/ScalaCL.svg?branch=feature_travis-build)](https://travis-ci.org/nativelibs4java/ScalaCL) [![Join the chat at https://gitter.im/nativelibs4java/ScalaCL](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/nativelibs4java/ScalaCL?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/nativelibs4java/ScalaCL.svg?branch=master)](https://travis-ci.org/nativelibs4java/ScalaCL) [![Join the chat at https://gitter.im/nativelibs4java/ScalaCL](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/nativelibs4java/ScalaCL?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ScalaCL lets you run Scala code on GPUs through OpenCL ([BSD-licensed](./LICENSE)). From eb989cfc0af2c8018ea5e499a615c613d65ec666 Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Fri, 27 Mar 2015 15:11:24 +0000 Subject: [PATCH 10/10] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c052218..f2ca4f8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ ScalaCL lets you run Scala code on GPUs through OpenCL ([BSD-licensed](./LICENSE WORK IN PROGRESS (see [ScalaCL](https://code.google.com/p/scalacl/) if you want something that _works_, albeit only on Scala 2.9.x). +See [slides from ScalaCL + Reified talk @ scala.io 2013](https://docs.google.com/presentation/d/1R61HTC6HMzmv7y6UqCSmVhy7kNk04l9cDg2vYHECZ98/edit#slide=id.g243771a0_0396). + Features of the new design (v3, rewritten from scratch again!): - Much better asynchronicity support (now requires OpenCL 1.1), and much better performance in general - Support for captures of constants *and* OpenCL arrays