-
-
Save ochafik/8a2afc6d59e0b47aaca5 to your computer and use it in GitHub Desktop.
ScalaCL v3 unit test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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