-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jonas
committed
Dec 1, 2017
1 parent
5401627
commit 8e42f7a
Showing
4 changed files
with
60 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import com.jogamp.opencl.CLContext | ||
import com.jogamp.opencl.CLProgram | ||
|
||
fun CLContext.clProgram(op: OpenCLProgramBuilder.() -> Unit) : CLProgram = | ||
createProgram(OpenCLProgramBuilder().apply(op).build()) | ||
|
||
class OpenCLProgramBuilder internal constructor() { | ||
private val functionList = mutableListOf<String>() | ||
|
||
fun kernelFun(name: String, op: CLFunctionBuilder.() -> Unit) { | ||
functionList += CLFunctionBuilder(name, true).apply(op).build() | ||
} | ||
|
||
internal fun build() : String = functionList.joinToString("\n\n") | ||
} | ||
|
||
class CLFunctionBuilder internal constructor(private val name: String, private val isKernel: Boolean) { | ||
|
||
internal fun build() : String { | ||
val stringBuilder = StringBuilder() | ||
|
||
if(isKernel) stringBuilder.append("kernel") | ||
else stringBuilder.append("local") | ||
|
||
stringBuilder.append(" void $name(") | ||
|
||
stringBuilder.append(") {\n") | ||
|
||
stringBuilder.append("}\n") | ||
return stringBuilder.toString() | ||
} | ||
} | ||
|
||
interface CLExpression | ||
|
||
fun main(args: Array<String>) { | ||
println(CLContext.create().clProgram { | ||
kernelFun("HelloWorld") { | ||
|
||
} | ||
}.source) | ||
} |