From 9b702dce71462af7db5a707e5c972a8be9c44adb Mon Sep 17 00:00:00 2001 From: Michal Harakal Date: Mon, 13 Apr 2026 11:42:18 +0200 Subject: [PATCH 1/2] Add skainet-backend-api module (#468 step 1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduces a backend-neutral Gradle module under skainet-backends that `api`-re-exports the tensor op and storage interfaces already living in skainet-lang-core. No Kotlin implementation of its own — it's a re-export layer plus a marker object for tooling. First step in the P0-2 track: concrete backends (today's CPU, future IREE / Metal / NPU) should depend on this module rather than taking a transitive dependency on skainet-backend-cpu just to reach TensorOps / TensorDataFactory / TensorData. Consumer migration is out of scope for this PR and will follow per-module. Co-Authored-By: Claude Opus 4.6 (1M context) --- settings.gradle.kts | 1 + .../skainet-backend-api/build.gradle.kts | 99 +++++++++++++++++++ .../kotlin/sk/ainet/backend/api/BackendApi.kt | 17 ++++ 3 files changed, 117 insertions(+) create mode 100644 skainet-backends/skainet-backend-api/build.gradle.kts create mode 100644 skainet-backends/skainet-backend-api/src/commonMain/kotlin/sk/ainet/backend/api/BackendApi.kt diff --git a/settings.gradle.kts b/settings.gradle.kts index ec6ef6d7..909a2ea6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -37,6 +37,7 @@ include("skainet-compile:skainet-compile-hlo") include("skainet-compile:skainet-compile-c") // ====== BACKENDS +include("skainet-backends:skainet-backend-api") include("skainet-backends:skainet-backend-cpu") // ====== BENCHMARKS diff --git a/skainet-backends/skainet-backend-api/build.gradle.kts b/skainet-backends/skainet-backend-api/build.gradle.kts new file mode 100644 index 00000000..a573fcca --- /dev/null +++ b/skainet-backends/skainet-backend-api/build.gradle.kts @@ -0,0 +1,99 @@ +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + +plugins { + alias(libs.plugins.kotlinMultiplatform) + alias(libs.plugins.androidMultiplatformLibrary) + id("sk.ainet.dokka") +} + +kotlin { + explicitApi() + android { + namespace = "sk.ainet.backend.api" + compileSdk = libs.versions.android.compileSdk.get().toInt() + minSdk = libs.versions.android.minSdk.get().toInt() + compilerOptions { + jvmTarget.set(JvmTarget.JVM_11) + } + } + + iosArm64() + iosSimulatorArm64() + macosArm64() + linuxX64() + linuxArm64() + + jvm() + + js { + browser() + } + + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + browser() + } + + @OptIn(ExperimentalWasmDsl::class) + wasmWasi { + nodejs() + } + + sourceSets { + commonMain.dependencies { + // Neutral backend API is an `api` re-export of the tensor op and + // storage interfaces already defined in skainet-lang-core. Any + // concrete backend (CPU, IREE, Metal, NPU, ...) should depend on + // this module instead of pulling in skainet-backend-cpu just to + // reach TensorOps / TensorDataFactory / TensorData. + api(project(":skainet-lang:skainet-lang-core")) + } + + val jvmMain by getting + val androidMain by getting + val wasmJsMain by getting + + val commonMain by getting + + val nativeMain by creating { + dependsOn(commonMain) + } + + val appleMain by creating { + dependsOn(nativeMain) + } + + val linuxMain by creating { + dependsOn(nativeMain) + } + + val iosMain by creating { + dependsOn(appleMain) + } + + val macosMain by creating { + dependsOn(appleMain) + } + + val iosArm64Main by getting { + dependsOn(iosMain) + } + + val iosSimulatorArm64Main by getting { + dependsOn(iosMain) + } + + val macosArm64Main by getting { + dependsOn(macosMain) + } + + val linuxX64Main by getting { + dependsOn(linuxMain) + } + + val linuxArm64Main by getting { + dependsOn(linuxMain) + } + } +} diff --git a/skainet-backends/skainet-backend-api/src/commonMain/kotlin/sk/ainet/backend/api/BackendApi.kt b/skainet-backends/skainet-backend-api/src/commonMain/kotlin/sk/ainet/backend/api/BackendApi.kt new file mode 100644 index 00000000..eabd55df --- /dev/null +++ b/skainet-backends/skainet-backend-api/src/commonMain/kotlin/sk/ainet/backend/api/BackendApi.kt @@ -0,0 +1,17 @@ +package sk.ainet.backend.api + +/** + * Marker for the backend-neutral API surface of SKaiNET. + * + * This module owns no implementation of its own. It `api`-re-exports the + * tensor op and storage interfaces that already live in `skainet-lang-core` + * (notably `TensorOps`, `TensorDataFactory`, `TensorData` and friends), so + * that concrete backends — `skainet-backend-cpu` today, and future IREE / + * Metal / NPU backends — can depend on a single neutral module instead of + * pulling in the CPU backend just to reach the interfaces they implement. + * + * Consumer migration from `skainet-backend-cpu` to this module is handled + * in follow-up PRs in the P0-2 track and is intentionally out of scope for + * the first change that introduces the module. + */ +public object BackendApi From 7b4d59a979d383265685b06f1606eae8c13b169c Mon Sep 17 00:00:00 2001 From: Michal Harakal Date: Mon, 13 Apr 2026 11:57:11 +0200 Subject: [PATCH 2/2] Wire skainet-backend-cpu to depend on skainet-backend-api (#468 step 2) skainet-backend-cpu now depends on the neutral backend-api module alongside its existing direct dependency on skainet-lang-core. Future backends (IREE, Metal, NPU) can follow the same pattern of depending only on backend-api without needing to pull in the CPU module. Co-Authored-By: Claude Opus 4.6 (1M context) --- skainet-backends/skainet-backend-cpu/build.gradle.kts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/skainet-backends/skainet-backend-cpu/build.gradle.kts b/skainet-backends/skainet-backend-cpu/build.gradle.kts index 3864033b..63e19acd 100644 --- a/skainet-backends/skainet-backend-cpu/build.gradle.kts +++ b/skainet-backends/skainet-backend-cpu/build.gradle.kts @@ -44,6 +44,9 @@ kotlin { sourceSets { commonMain.dependencies { + // Every concrete backend should go through the neutral api + // module; it transitively brings in skainet-lang-core. + implementation(project(":skainet-backends:skainet-backend-api")) implementation(project(":skainet-lang:skainet-lang-core")) implementation(project(":skainet-compile:skainet-compile-core")) implementation(project(":skainet-lang:skainet-lang-ksp-annotations"))