Skip to content

Commit f0bf3ef

Browse files
committed
Adapt to latest scalaxy changes (newVariable -> newVal + newVar)
1 parent c741e3b commit f0bf3ef

10 files changed

+57
-24
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Akkhack
1515
velocity.log*
1616
tmpTestClasses*
1717
*.marks
18+
.ensime

src/main/scala/scalacl/impl/CLFunctionMacros.scala

+23-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private[impl] object CLFunctionMacros {
4545

4646
val outputSymbol = Option(c.enclosingMethod).map(_.symbol).getOrElse(NoSymbol).newTermSymbol(newTermName(c.fresh("out")))
4747

48-
WithResult(
48+
val func = WithResult(
4949
new CodeGeneration with WithMacroContext with WithResult[c.Expr[FunctionKernel /*[A, B]*/ ]] {
5050
override val context = c
5151
import global._
@@ -56,30 +56,47 @@ private[impl] object CLFunctionMacros {
5656
outputSymbol = castSymbol(outputSymbol)).asInstanceOf[Result]
5757
}
5858
)
59-
59+
try {
60+
c.Expr[FunctionKernel](c.typeCheck(func.tree))
61+
} catch {
62+
case ex: Throwable =>
63+
ex.printStackTrace()
64+
println("ERROR WITH: " + func)
65+
throw ex
66+
}
6067
}
6168

6269
private[impl] def convertTask(c: Context)(block: c.Expr[Unit]): c.Expr[CLFunction[Unit, Unit]] = {
6370
import c.universe._
6471
import definitions._
6572

66-
WithResult(
73+
val func = WithResult(
6774
new CodeGeneration with WithMacroContext with WithResult[c.Expr[CLFunction[Unit, Unit]]] {
6875
override val context = c
6976

7077
// Create a fake Unit => Unit function.
71-
val typedBlock = c.typeCheck(block.tree)
78+
79+
//var typedBlock = newStreamTransformer(false) transform cleanTypeCheck(block.tree)
80+
// val typedBlock = c.typeCheck(block.tree)
7281
val functionKernelExpr = generateFunctionKernel[Unit, Unit](
7382
kernelSalt = KernelDef.nextKernelSalt,
74-
body = castTree(typedBlock),
83+
body = castTree(block.tree),
7584
paramDescs = Seq()
7685
)
7786

78-
val f = blockToUnitFunction(castTree(typedBlock))
87+
val f = blockToUnitFunction(castTree(block.tree))
7988
val result = reify(
8089
new CLFunction[Unit, Unit](f.splice, functionKernelExpr.splice)
8190
).asInstanceOf[Result]
8291
}
8392
)
93+
try {
94+
c.Expr[CLFunction[Unit, Unit]](c.typeCheck(func.tree))
95+
} catch {
96+
case ex: Throwable =>
97+
ex.printStackTrace()
98+
println("ERROR WITH: " + func)
99+
throw ex
100+
}
84101
}
85102
}

src/main/scala/scalacl/impl/CodeGeneration.scala

+7-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ trait CodeGeneration extends CodeConversion with StreamTransformers {
5656
expr[Unit => Unit](
5757
Function(
5858
List(
59-
ValDef(NoMods, newTermName(fresh("noarg")), TypeTree(UnitTpe), EmptyTree)
59+
ValDef(
60+
NoMods, newTermName(fresh("noarg")), TypeTree(UnitTpe), EmptyTree)
6061
),
6162
block
6263
)
@@ -99,6 +100,7 @@ trait CodeGeneration extends CodeConversion with StreamTransformers {
99100
ParamDesc(
100101
symbol = castSymbol(param.symbol),
101102
tpe = castType(inputTpe),
103+
output = false,
102104
mode = ParamKind.ImplicitArrayElement,
103105
usage = UsageKind.Input,
104106
implicitIndexDimension = Some(0)))
@@ -111,6 +113,7 @@ trait CodeGeneration extends CodeConversion with StreamTransformers {
111113
ParamDesc(
112114
symbol = castSymbol(outputSymbol),
113115
tpe = castType(outputTpe),
116+
output = true,
114117
mode = ParamKind.ImplicitArrayElement,
115118
usage = UsageKind.Output,
116119
implicitIndexDimension = Some(0)))
@@ -167,18 +170,13 @@ trait CodeGeneration extends CodeConversion with StreamTransformers {
167170
body: Tree,
168171
paramDescs: Seq[ParamDesc]): Expr[FunctionKernel /*[A, B]*/ ] = {
169172

170-
// println(s"""
171-
// Generating CL function for:
172-
// f = $f
173-
// paramDescs = $paramDescs
174-
// """)
175-
val transformedBody = newStreamTransformer(false) transform body
176-
177173
val cr @ CodeConversionResult(code, capturedInputs, capturedOutputs, capturedConstants) = convertCode(
178-
transformedBody,
174+
body,
179175
paramDescs
180176
)
181177

178+
// resetAllAttrs(body)
179+
182180
val codeExpr = expr[String](Literal(Constant(code)))
183181
val kernelSaltExpr = expr[Long](Literal(Constant(kernelSalt)))
184182

src/main/scala/scalacl/impl/KernelSymbolsAnalysis.scala

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import scala.reflect.NameTransformer
3939

4040
trait KernelSymbolsAnalysis
4141
extends CommonScalaNames
42+
with CodeConversionResults
4243
with MiscMatchers
4344
with SymbolKinds {
4445
val global: reflect.api.Universe

src/main/scala/scalacl/impl/OpenCLCodeFlattening.scala

+3-5
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ trait OpenCLCodeFlattening
207207
(Seq(), value)
208208
case _ =>
209209
assert(getType(value) != NoType, value + ": " + value.getClass.getName) // + " = " + nodeToString(value) + ")")
210-
val tempVar = newVariable("tmp", symbolOwner, value.pos, false, value, value.tpe)
210+
val tempVar = newVal("tmp", value, value.tpe)
211211
//println("Creating temp variable " + tempVar.symbol + " for " + value)
212212
hasNewStatements = true
213213
for (slice <- getTreeSlice(value))
@@ -355,7 +355,7 @@ trait OpenCLCodeFlattening
355355
case Apply(Select(target, updateName()), List(index, value)) if isTupleType(getType(value)) =>
356356
val targetTpe = normalize(target.tpe).asInstanceOf[TypeRef]
357357
setType(target, targetTpe)
358-
val indexVal = newVariable("index", symbolOwner, tree.pos, false, index, index.tpe)
358+
val indexVal = newVal("index", index, index.tpe)
359359

360360
val flatTarget = flattenTuplesAndBlocks(target)
361361
val flatValue = flattenTuplesAndBlocks(value)
@@ -398,8 +398,6 @@ trait OpenCLCodeFlattening
398398
flatCondition.statements ++
399399
Seq(
400400
whileLoop(
401-
symbolOwner,
402-
tree,
403401
flatConditionValue,
404402
Block(flatContent.statements.toList ++ flatContent.values, newUnit)
405403
)
@@ -415,7 +413,7 @@ trait OpenCLCodeFlattening
415413
// val b = if (condition) d else 0
416414
val FlatCode(dc, sc, Seq(vc)) = flattenTuplesAndBlocks(condition)
417415
assert(getType(vc) != NoType, vc)
418-
val conditionVar = newVariable("condition", symbolOwner, tree.pos, false, vc, vc.tpe)
416+
val conditionVar = newVal("condition", vc, vc.tpe)
419417

420418
val fct @ FlatCode(Seq(), st, vt) = flattenTuplesAndBlocks(thenDo)
421419
val fco @ FlatCode(Seq(), so, vo) = flattenTuplesAndBlocks(otherwise)

src/main/scala/scalacl/impl/SymbolKinds.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ trait SymbolKinds extends Tuploids with CommonScalaNames {
5555
}
5656

5757
def kindOf(symbol: Symbol, tpe: Type): SymbolKind = {
58-
if (tpe <:< typeOf[CLArray[_]] || tpe <:< typeOf[CLFilteredArray[_]])
58+
if (tpe != null && (tpe <:< typeOf[CLArray[_]] || tpe <:< typeOf[CLFilteredArray[_]]))
5959
SymbolKind.ArrayLike
6060
else if (isTuploidType(tpe))
6161
SymbolKind.Tuploid

src/main/scala/scalacl/impl/TupleDataIO.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ private[impl] abstract class TupleDataIO[T: Manifest] extends DataIO[T] {
4343
CLEvent.waitFor(eventsToWaitFor.toArray: _*)
4444
(0 until length.toInt).par.map(i => get(i, pointers, 0)).toArray // TODO check
4545
}
46+
47+
// def ios: Array[DataIO[_]]
48+
// def mkTuple(values: Array[Any]): T
49+
//
4650
}
4751

4852
class Tuple2DataIO[T1: Manifest: DataIO, T2: Manifest: DataIO]
@@ -71,4 +75,4 @@ class Tuple2DataIO[T1: Manifest: DataIO, T2: Manifest: DataIO]
7175
io1.set(index, buffers, bufferOffset, v1)
7276
io2.set(index, buffers, bufferOffset + io1.bufferCount, v2)
7377
}
74-
}
78+
}

src/main/scala/scalacl/impl/Vectorization.scala

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ trait Vectorization extends CodeGeneration with MiscMatchers {
7272
ParamDesc(
7373
symbol = param.symbol,
7474
tpe = numTpe,
75+
output = false,
7576
mode = ParamKind.RangeIndex,
7677
usage = UsageKind.Input,
7778
implicitIndexDimension = Some(0),

src/test/scala/scalacl/impl/ConversionTest.scala

+14-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,20 @@ class ConversionTest
6363
val in: CLArray[Int] = null
6464
val out: CLArray[Int] = null
6565
val f = 10
66-
val c = conv(reify { out(1) = in(2) * f })
66+
val c = conv(reify { out(1) = in(2) * f }, List(
67+
ParamDesc(
68+
symbol = NoSymbol.newTermSymbol("out"),
69+
output = true,
70+
tpe = typeOf[CLArray[Int]],
71+
mode = ParamKind.Normal,
72+
usage = UsageKind.Output),
73+
ParamDesc(
74+
symbol = NoSymbol.newTermSymbol("in"),
75+
output = false,
76+
tpe = typeOf[CLArray[Int]],
77+
mode = ParamKind.Normal,
78+
usage = UsageKind.Input)))
79+
6780
assertEquals(
6881
"kernel void f(global const int* in, global int* out, int f) {\n" +
6982
"\tout[1] = (in[2] * f);\n" +

src/test/scala/scalacl/impl/VectorizationTest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class VectorizationTest
6969
)
7070
}
7171

72-
@Ignore
72+
// @Ignore
7373
@Test
7474
def notVectorizable2D {
7575
assertThat(

0 commit comments

Comments
 (0)