Skip to content

Instantly share code, notes, and snippets.

@ochafik
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save ochafik/8a2afc6d59e0b47aaca5 to your computer and use it in GitHub Desktop.

Select an option

Save ochafik/8a2afc6d59e0b47aaca5 to your computer and use it in GitHub Desktop.
ScalaCL v3 unit test
val n = 1000000
val in, out = new CLArray[Int](n)
val e = kernel {
for (i <- 0 until n) {
out(i) = in(i)
}
}
assert(in.lastReads == List(e))
assert(in.lastWrites == Nil)
assert(out.lastReads == Nil)
assert(out.lastWrite == List(e))
kernel {
}
trait CLTracked[A] {
@deprecated
def get: A
def read(f: List[CLEvent] => CLEvent): Unit
def write(f: List[CLEvent] => CLEvent): Unit
def lastReads: List[CLEvent]
def lastWrites: List[CLEvent]
}
/**
* Notes:
* - A given kernel might just read only one of the fibers, or even only write one of them.
* (if it preserves the other fiber's value, or if the array was unzipped)
*
*/
trait CLArray[A] {
def apply(i: Long): A
def update(i: Long, value: A): CLEvent
def length: Long
def toArray: Array[A]
def fibers: List[CLTracked[CLBuffer[_]]]
}
trait CLKernel {
def inputs: List[CLArrayLike[_]]
def inputOuputs: List[CLArrayLike[_]]
def outputs: List[CLArrayLike[_]]
}
trait CLContext {
def allocate[A : ClassTag](n: Long): CLArray[A]
def createKernel(tree: reflect.runtime.universe.Tree): CLKernel
def execute(kernel: CLKernel): CLEvent
}
def kernel(block: Unit)(implicit context: CLContext): CLEvent = macro kernelImpl
// def kernel1d...
// def kernel2d...
// def kernel3d...
// def task...
implicit val testContext = new CLContext { ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment