Skip to content

Commit 1dae772

Browse files
committed
add coremark benchmark
1 parent 55dee0d commit 1dae772

File tree

4 files changed

+3879
-0
lines changed

4 files changed

+3879
-0
lines changed

benchmark/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ kotlin {
2727
sourceSets {
2828
commonMain {
2929
dependencies {
30+
implementation(projects.chasm)
3031
implementation(projects.executor.invoker)
3132
implementation(projects.executor.memory)
3233
implementation(projects.test.fixture.ast)
3334
implementation(projects.test.fixture.executor.runtime)
3435

3536
implementation(libs.kotlinx.benchmark)
37+
implementation(libs.kotlinx.datetime)
38+
implementation(libs.kotlinx.test.resources)
3639
}
3740
}
3841

@@ -43,3 +46,10 @@ kotlin {
4346
}
4447
}
4548
}
49+
50+
tasks.register<JavaExec>("coremark") {
51+
group = "benchmark"
52+
description = "Run the Coremark benchmark"
53+
classpath = kotlin.jvm().compilations["main"].run { runtimeDependencyFiles + output.allOutputs }
54+
mainClass.set("io.github.charlietap.chasm.benchmark.coremark.CoremarkBenchmarkKt")
55+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package io.github.charlietap.chasm.benchmark.coremark
2+
3+
import com.goncalossilva.resources.Resource
4+
import io.github.charlietap.chasm.embedding.dsl.imports
5+
import io.github.charlietap.chasm.embedding.instance
6+
import io.github.charlietap.chasm.embedding.invoke
7+
import io.github.charlietap.chasm.embedding.module
8+
import io.github.charlietap.chasm.embedding.shapes.ChasmResult
9+
import io.github.charlietap.chasm.embedding.shapes.flatMap
10+
import io.github.charlietap.chasm.embedding.store
11+
import io.github.charlietap.chasm.executor.runtime.value.ExecutionValue
12+
import io.github.charlietap.chasm.executor.runtime.value.NumberValue
13+
import kotlinx.datetime.Clock
14+
15+
fun main() {
16+
val benchmark = CoremarkBenchmark()
17+
benchmark.run()
18+
}
19+
20+
class CoremarkBenchmark {
21+
22+
fun run() {
23+
val bytes = Resource(FILE_DIR + "coremark.wasm").readBytes()
24+
val store = store()
25+
26+
val imports = imports(store) {
27+
function {
28+
moduleName = "env"
29+
entityName = "clock_ms"
30+
type {
31+
results { i64() }
32+
}
33+
34+
reference {
35+
val time = Clock.System.now()
36+
listOf(NumberValue.I64(time.toEpochMilliseconds()))
37+
}
38+
}
39+
}
40+
41+
val results = module(bytes)
42+
.flatMap { module ->
43+
instance(store, module, imports)
44+
}.flatMap { instance ->
45+
invoke(store, instance, "run")
46+
}
47+
48+
if (results is ChasmResult.Success<List<ExecutionValue>>) {
49+
val score = results.result.first() as NumberValue.F32
50+
println("CoreMark 1.0 : ${score.value}")
51+
} else {
52+
println("Benchmark failed with error: $results")
53+
}
54+
}
55+
56+
companion object {
57+
private const val FILE_DIR = "src/commonMain/resources/benchmark/"
58+
}
59+
}
Binary file not shown.

0 commit comments

Comments
 (0)