Skip to content

Commit

Permalink
started ProgramDSL
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas committed Dec 1, 2017
1 parent 5401627 commit 8e42f7a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 16 deletions.
26 changes: 17 additions & 9 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
Expand Down Expand Up @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -154,11 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
6 changes: 0 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ goto fail
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
Expand All @@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ object Main {
}

fun main(args: Array<String>) {
val numElements = 4096
val numElements = 2048
Main.addVectors(numElements * numElements)
println("###############\n")
Main.multiplyMatrices(numElements)
Expand Down
42 changes: 42 additions & 0 deletions src/main/kotlin/OpenCLProgramDSL.kt
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)
}

0 comments on commit 8e42f7a

Please sign in to comment.