Skip to content

Commit 1aa2501

Browse files
committed
Add runner
1 parent ee948b2 commit 1aa2501

File tree

16 files changed

+213
-77
lines changed

16 files changed

+213
-77
lines changed

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ object Libs {
241241
version = Versions.onnxruntime
242242
)
243243

244+
val onnxruntime_gpu = dep(
245+
group = "com.microsoft.onnxruntime",
246+
name = "onnxruntime_gpu",
247+
version = Versions.onnxruntime
248+
)
249+
244250
val ktor_server_core = dep(
245251
group = "io.ktor",
246252
name = "ktor-server-core",

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ findProject(":usvm-python:usvm-python-runner")?.name = "usvm-python-runner"
2121
include("usvm-python:usvm-python-commons")
2222
findProject(":usvm-python:usvm-python-commons")?.name = "usvm-python-commons"
2323
include("usvm-ml-gameserver")
24+
include("usvm-runner")
2425

2526
pluginManagement {
2627
resolutionStrategy {

usvm-core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies {
1313
testImplementation(Libs.ksmt_yices)
1414

1515
implementation(Libs.onnxruntime)
16+
implementation(Libs.onnxruntime_gpu)
1617
}
1718

1819
publishing {

usvm-core/src/main/kotlin/org/usvm/utils/OnnxModelImpl.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,31 @@ import ai.onnxruntime.OnnxTensor
44
import ai.onnxruntime.OrtEnvironment
55
import ai.onnxruntime.OrtSession
66
import org.usvm.StateId
7+
import org.usvm.logger
78
import org.usvm.statistics.BasicBlock
89
import org.usvm.statistics.BlockGraph
910
import org.usvm.util.OnnxModel
1011
import java.nio.FloatBuffer
1112
import java.nio.LongBuffer
12-
import java.nio.file.Path
13+
14+
enum class Mode {
15+
CPU,
16+
GPU
17+
}
1318

1419
class OnnxModelImpl<Block: BasicBlock>(
15-
pathToONNX: Path
20+
pathToONNX: String,
21+
mode: Mode
1622
): OnnxModel<Game<Block>> {
1723
private val env: OrtEnvironment = OrtEnvironment.getEnvironment()
18-
private val session: OrtSession = env.createSession(pathToONNX.toString())
24+
private val sessionOptions: OrtSession.SessionOptions = OrtSession.SessionOptions().apply {
25+
if (mode == Mode.GPU) {
26+
addCUDA()
27+
} else {
28+
logger.info("Using CPU execution provider.")
29+
}
30+
}
31+
private val session: OrtSession = env.createSession(pathToONNX, sessionOptions)
1932

2033
override fun predictState(game: Game<Block>): UInt {
2134
val stateIds = mutableMapOf<StateId, Int>()

usvm-ml-gameserver/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tasks.test {
3232
dependencies {
3333
implementation(project(":usvm-jvm"))
3434
implementation(project(":usvm-core"))
35+
implementation(project(":usvm-runner"))
3536
implementation(Libs.jacodb_api_jvm)
3637
implementation(Libs.jacodb_core)
3738

@@ -44,6 +45,5 @@ dependencies {
4445
implementation(Libs.kotlinx_cli)
4546
implementation(Libs.slf4j_simple)
4647

47-
implementation("io.github.rchowell:dotlin:1.0.2")
4848
testImplementation(kotlin("test"))
4949
}

usvm-ml-gameserver/src/main/kotlin/org.usvm/JavaMethodRunner.kt

Lines changed: 0 additions & 57 deletions
This file was deleted.

usvm-ml-gameserver/src/main/kotlin/org.usvm/OracleImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.usvm.gameserver.GameState
44
import org.usvm.statistics.BasicBlock
55
import org.usvm.util.Oracle
66
import org.usvm.utils.Game
7-
import org.usvm.util.createGameState
7+
import org.usvm.gameserver.serialization.createGameState
88

99
class OracleImpl<Block: BasicBlock>(
1010
val predict: (GameState) -> UInt

usvm-ml-gameserver/src/main/kotlin/org.usvm/gameserver/Explorer.kt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
@file:Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE")
2-
31
package org.usvm.gameserver
42

5-
import org.usvm.JavaMethodRunner
3+
import org.usvm.runner.JavaMethodRunner
64
import org.usvm.OracleImpl
5+
import org.usvm.PathSelectionStrategy
6+
import org.usvm.UMachineOptions
7+
import org.usvm.runner.defaultOptions
78
import org.usvm.statistics.BasicBlock
89
import kotlin.math.floor
910

@@ -22,10 +23,10 @@ fun randomExplorer(
2223
step.gameStep.stateId
2324
}
2425

25-
val (className, methodName) = extractClassAndMethod(gameMap.nameOfObjectToCover)
26-
val runner = JavaMethodRunner(gameMap, OracleImpl<BasicBlock>(predict))
26+
val options = cloneDefaultOptions(gameMap, predict)
27+
val runner = JavaMethodRunner(options, gameMap.assemblyFullName)
2728

28-
val (results, percentageCoverage) = runner.cover(className, methodName)
29+
val (results, percentageCoverage) = runner.cover(gameMap.nameOfObjectToCover)
2930
val errors = results.count { it.isExceptional }
3031
val tests = results.size - errors
3132

@@ -36,10 +37,16 @@ fun randomExplorer(
3637
)
3738
}
3839

39-
private fun extractClassAndMethod(fullName: String): Pair<String, String> {
40-
val parts = fullName.split('.')
41-
val className = parts.dropLast(1).joinToString(".")
42-
val methodName = parts.last()
43-
44-
return Pair(className, methodName)
40+
private fun cloneDefaultOptions(gameMap: GameMap, predict: (GameState) -> UInt): UMachineOptions {
41+
val defaultSearcher = when (gameMap.defaultSearcher) {
42+
Searcher.BFS -> PathSelectionStrategy.BFS
43+
Searcher.DFS -> PathSelectionStrategy.DFS
44+
}
45+
val stepLimit = (gameMap.stepsToStart + gameMap.stepsToStart).toULong()
46+
return defaultOptions.copy(
47+
pathSelectionStrategies = listOf(defaultSearcher, PathSelectionStrategy.AI),
48+
stepLimit = stepLimit,
49+
stepsToStart = gameMap.stepsToStart,
50+
oracle = OracleImpl<BasicBlock>(predict)
51+
)
4552
}

usvm-ml-gameserver/src/main/kotlin/org.usvm/util/Conversion.kt renamed to usvm-ml-gameserver/src/main/kotlin/org.usvm/gameserver/serialization/Conversion.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.usvm.util
1+
package org.usvm.gameserver.serialization
22

33
import org.usvm.gameserver.GameEdgeLabel
44
import org.usvm.gameserver.GameMapEdge

usvm-runner/build.gradle.kts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
plugins {
4+
id("usvm.kotlin-conventions")
5+
kotlin
6+
}
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
tasks.test {
13+
useJUnitPlatform()
14+
}
15+
16+
tasks.withType<KotlinCompile> {
17+
kotlinOptions.allWarningsAsErrors = false
18+
}
19+
20+
dependencies {
21+
implementation(project(":usvm-jvm"))
22+
implementation(project(":usvm-core"))
23+
implementation(Libs.jacodb_api_jvm)
24+
implementation(Libs.jacodb_core)
25+
implementation(Libs.kotlinx_cli)
26+
27+
implementation(Libs.slf4j_simple)
28+
implementation(Libs.logback)
29+
30+
implementation("io.github.rchowell:dotlin:1.0.2")
31+
testImplementation(kotlin("test"))
32+
}

0 commit comments

Comments
 (0)