-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
302 lines (262 loc) · 9.17 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
302 lines (262 loc) · 9.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
plugins {
base
}
val javaVersion = (findProperty("javaVersion") as String?)?.toIntOrNull() ?: 21
allprojects {
repositories {
mavenCentral()
}
}
subprojects {
plugins.withId("java") {
extensions.configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(javaVersion))
}
}
}
tasks.withType<Test>().configureEach {
enabled = false
}
}
// Master task: Run all smoke tests (quick validation)
tasks.register("runSmokeTests") {
group = "validation"
description = "Run all smoke tests (quick validation of all Java demos)"
dependsOn(
":demos:tensorflow-ffm:run",
":demos:jcuda:run",
":demos:valhalla:run",
":demos:babylon:run",
":demos:tornadovm:run"
)
doFirst {
println("=".repeat(70))
println("Running Smoke Tests - Quick Validation")
println("=".repeat(70))
println(" 1. TensorFlow FFM")
println(" 2. JCuda")
println(" 3. Valhalla (Vector API + FP16)")
println(" 4. Babylon (RuntimeCheck)")
println(" 5. TornadoVM (Baseline)")
println("=".repeat(70))
println()
}
}
// ============================================================================
// Babylon JDK Build Tasks
// ============================================================================
// Build Babylon JDK from source at ~/Github/babylon
// Prerequisites: Xcode (macOS), build-essential (Linux), boot JDK 23+
val babylonSourceDir = file(System.getenv("HOME") + "/Github/babylon")
val babylonBuildDir = file(babylonSourceDir.path + "/build")
val babylonJdkInstallDir = file(System.getenv("HOME") + "/.sdkman/candidates/java/babylon-26-code-reflection")
// Detect platform-specific build directory name
val babylonPlatformBuildDir: File by lazy {
val osName = System.getProperty("os.name").lowercase()
val osArch = System.getProperty("os.arch")
val platform = when {
osName.contains("mac") && osArch == "aarch64" -> "macosx-aarch64-server-release"
osName.contains("mac") -> "macosx-x86_64-server-release"
osName.contains("linux") && osArch == "aarch64" -> "linux-aarch64-server-release"
osName.contains("linux") -> "linux-x86_64-server-release"
else -> "unknown-platform"
}
file(babylonBuildDir.path + "/$platform")
}
val babylonJdkImageDir: File by lazy {
file(babylonPlatformBuildDir.path + "/images/jdk")
}
tasks.register<Exec>("babylonConfigure") {
group = "babylon"
description = "Configure Babylon JDK build (run once before building)"
workingDir = babylonSourceDir
commandLine("bash", "configure",
"--with-conf-name=release",
"--with-debug-level=release"
)
doFirst {
if (!babylonSourceDir.exists()) {
throw GradleException("""
|Babylon source not found at: $babylonSourceDir
|
|Clone it with:
| git clone https://github.com/openjdk/babylon.git ~/Github/babylon
""".trimMargin())
}
println("Configuring Babylon JDK build...")
println("Source: $babylonSourceDir")
}
onlyIf {
// Skip if already configured
!file(babylonPlatformBuildDir.path + "/spec.gmk").exists()
}
}
tasks.register("babylonBuild") {
group = "babylon"
description = "Build Babylon JDK from source (takes 10-30 minutes)"
doLast {
if (!babylonSourceDir.exists()) {
throw GradleException("Babylon source not found at: $babylonSourceDir")
}
// Auto-configure if needed
if (!file(babylonPlatformBuildDir.path + "/spec.gmk").exists()) {
println("Build not configured, running configure first...")
val configureProcess = ProcessBuilder("bash", "configure")
.directory(babylonSourceDir)
.inheritIO()
.start()
val configureExitCode = configureProcess.waitFor()
if (configureExitCode != 0) {
throw GradleException("Configure failed with exit code $configureExitCode")
}
}
println("=" .repeat(70))
println("Building Babylon JDK from source")
println("=" .repeat(70))
println("Source: $babylonSourceDir")
println("Output: $babylonJdkImageDir")
println("CPUs: ${Runtime.getRuntime().availableProcessors()}")
println("=" .repeat(70))
val buildProcess = ProcessBuilder("make", "images", "JOBS=${Runtime.getRuntime().availableProcessors()}")
.directory(babylonSourceDir)
.inheritIO()
.start()
val buildExitCode = buildProcess.waitFor()
if (buildExitCode != 0) {
throw GradleException("Build failed with exit code $buildExitCode")
}
println()
println("=" .repeat(70))
println("Babylon JDK build complete!")
println("JDK location: $babylonJdkImageDir")
println()
println("To use: export JAVA_HOME=$babylonJdkImageDir")
println("Or run: ./gradlew babylonInstall")
println("=" .repeat(70))
}
}
tasks.register<Exec>("babylonClean") {
group = "babylon"
description = "Clean Babylon JDK build"
workingDir = babylonSourceDir
commandLine("make", "clean")
onlyIf { babylonSourceDir.exists() }
}
tasks.register("babylonInstall") {
group = "babylon"
description = "Install built Babylon JDK to SDKMAN directory"
doLast {
if (!babylonJdkImageDir.exists()) {
throw GradleException("""
|Babylon JDK not built yet. Run: ./gradlew babylonBuild
|Expected at: $babylonJdkImageDir
""".trimMargin())
}
// Create symlink to SDKMAN candidates directory
val sdkmanDir = file(System.getenv("HOME") + "/.sdkman/candidates/java")
if (!sdkmanDir.exists()) {
println("SDKMAN not found, skipping SDKMAN installation")
println("JDK available at: $babylonJdkImageDir")
return@doLast
}
// Remove existing symlink/directory if present
if (babylonJdkInstallDir.exists()) {
if (java.nio.file.Files.isSymbolicLink(babylonJdkInstallDir.toPath())) {
babylonJdkInstallDir.delete()
} else {
throw GradleException("$babylonJdkInstallDir exists and is not a symlink. Remove it manually.")
}
}
// Create symlink
java.nio.file.Files.createSymbolicLink(
babylonJdkInstallDir.toPath(),
babylonJdkImageDir.toPath()
)
println("=" .repeat(70))
println("Babylon JDK installed to SDKMAN!")
println("=" .repeat(70))
println()
println("To use with SDKMAN:")
println(" sdk use java babylon-26-code-reflection")
println()
println("To use directly:")
println(" export JAVA_HOME=$babylonJdkInstallDir")
println("=" .repeat(70))
}
}
tasks.register("babylonInfo") {
group = "babylon"
description = "Show Babylon JDK build information"
doLast {
println("=" .repeat(70))
println("Babylon JDK Build Information")
println("=" .repeat(70))
println()
println("Source directory: $babylonSourceDir")
println("Source exists: ${babylonSourceDir.exists()}")
println()
println("Build directory: $babylonPlatformBuildDir")
println("Build exists: ${babylonPlatformBuildDir.exists()}")
println()
println("JDK image: $babylonJdkImageDir")
println("JDK built: ${babylonJdkImageDir.exists()}")
println()
println("SDKMAN install: $babylonJdkInstallDir")
println("SDKMAN installed: ${babylonJdkInstallDir.exists()}")
if (babylonJdkImageDir.exists()) {
println()
println("JDK Version:")
ProcessBuilder(babylonJdkImageDir.path + "/bin/java", "--version")
.inheritIO()
.start()
.waitFor()
}
println("=" .repeat(70))
}
}
// ============================================================================
// Master task: Run all LLM inference benchmarks
tasks.register("runBenchmarks") {
group = "benchmarking"
description = "Run all LLM inference benchmarks (requires model)"
// Note: GraalPy's llama task is expected to fail (demonstrates ctypes limitation)
// We don't add it as a dependency to avoid failing the whole build
doFirst {
println("=".repeat(70))
println("Running LLM Inference Benchmarks")
println("=".repeat(70))
println("Model: ~/.llama/models/Llama-3.2-1B-Instruct-f16.gguf")
println()
println(" 1. Llama3.java (Pure Java, Vector API)")
println(" 2. java-llama.cpp (JNI + Metal/CUDA GPU)")
println(" 3. GraalPy - runtimeCheck (basic embedding)")
println(" 4. GraalPy - llamaPython (CPython LLM)")
println(" 5. GraalPy - llama (expected to fail)")
println("=".repeat(70))
println()
}
doLast {
// Run benchmarks sequentially to see results clearly
fun runGradle(vararg args: String, ignoreFailure: Boolean = false) {
val process = ProcessBuilder("./gradlew", *args, "--no-daemon")
.inheritIO()
.start()
val exitCode = process.waitFor()
if (exitCode != 0 && !ignoreFailure) {
throw GradleException("Command failed with exit code $exitCode")
}
}
runGradle(":demos:llama3-java:run")
runGradle(":demos:java-llama-cpp:run")
runGradle(":demos:graalpy:runtimeCheck")
runGradle(":demos:graalpy:llamaPython")
// Run GraalPy LLM (expected to fail) - don't fail the build
runGradle(":demos:graalpy:llama", ignoreFailure = true)
println()
println("=".repeat(70))
println("Benchmarks Complete!")
println("Note: GraalPy LLM failure is expected (ctypes limitation)")
println("=".repeat(70))
}
}