Ship the aarch64-verified NEON kernels to mobile: Apple targets + Android JNI for skainet-backend-native-cpu (measured 21 → 1.0 → 0.11 tok/s cliff)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 32/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 領域
- backend, mobile-dev, performance
調査の方向性
Start with native/src/*.c, CMakeLists.txt, skainet_kernels.def, and the native kernel provider and parity tests in nativeMain/nativeTest; then read the existing cross-Arm build pattern and publish.yml. Decide which platform track to tackle first, since Apple packaging, registration, and CI differ from the Android JNI route. Done means mobile builds can link and register the optimized kernels, Q4_0 has a NEON path, and parity/performance can be exercised on the target.
索引モデルが issue の本文から書いたものです。
説明
The numbers
Same model (SmolLM2-135M-Instruct Q8_0), same QuantPolicy.NATIVE_OPTIMIZED, same
commonMain inference code, SKaiNET 0.38.0:
| Platform | Decode speed | One 44-token generation |
|---|---|---|
| JVM desktop (Apple Silicon, JDK 21, Vector API) | 21 tok/s | ~2 s |
| Android, physical phone | 1.0 tok/s | ~44 s |
| iOS simulator (Apple Silicon) | 0.11 tok/s | ~6 min |
Output is correct everywhere — this is purely a kernel-availability gap, and it is
what keeps our shipped app's AI feature switched off on phones (we gate on
3 tok/s at startup; both mobile platforms fail the gate). Roughly 200x between JVM
and Kotlin/Native on comparable CPUs.
Why it happens
skainet-backend-native-cpu publishes only -jvm, -linuxx64, -linuxarm64.
There is no Apple or Android artifact, Android has no java.lang.foreign / Vector
API, and every non-JVM PlatformCpuOpsFactory actual registers only
ScalarKernelProvider (priority 0). So both mobile platforms run scalar Kotlin
matmul while the JVM gets SIMD.
Why this is closer than it looks
Most of the hard part already exists in-tree:
- The C kernels (
native/src/*.c) are portable C11 with NEON bodies gated on
__ARM_NEON/__ARM_FEATURE_DOTPROD— fp32, q8_0, q4k, q5k, q6k — and carry an
"AARCH64-VERIFIED" banner: parity-checked under qemu-aarch64 and on a physical
Cortex-A55,-march=armv8.2-a+fp16+dotprod, deliberately no+i8mm. CMakeLists.txtkeys the-marchflags offCMAKE_SYSTEM_PROCESSOR, which NDK
and Apple toolchains both set correctly — the flags come for free.- The Kotlin/Native side (
NativeKnKernelProvider+ wrappers + the nativeTest
parity tests) lives in target-agnosticnativeMain/nativeTestand should
compile for Apple/Android-native targets unchanged. - The publish workflow already runs on a macOS runner.
What actually needs doing
We'd suggest two tracks, iOS first (it reuses the verified K/N cinterop path
as-is), Android second (different mechanism needed — see below).
Track A — Apple (iosArm64, iosSimulatorArm64, ideally macosArm64):
- Fix the cinterop packaging gap first — this one matters beyond mobile.
skainet_kernels.defdeclares nostaticLibraries/libraryPaths; the archive
is attached viabinaries.all { linkerOpts(...) }, which does not travel to
consumers. As published, the K/N klibs carry bindings but no machine code, so a
downstream app can't link — this already affects the published-linuxarm64
artifact today. Either embedstaticLibrariesin the.defor ship the archive
in the klib. (Happy to split this into its own issue if you prefer.) - Apple CMake invocations:
-DCMAKE_SYSTEM_NAME=iOSagainst theiphoneos/
iphonesimulatorSDKs (+ macosArm64), onecmake-build-<target>dir and a
configure/build/package task triple each, mirroring the existing-PcrossArm64
pattern. - Registration: K/N has no ServiceLoader;
installNativeKernels()is a manual
call, andPlatformCpuOpsFactory.apple.ktcurrently registers only the scalar
provider. Needs a small design decision (documented startup call vs a hook), and
ideally composes with the existingAccelerateCpuOps(vDSP dense FP32) so Apple
gets NEON quant kernels and Accelerate FP32 rather than all-or-nothing. - CI: Apple legs in
publish.yml's build-native matrix and an
iosSimulatorArm64Testlane (currently the only automatable way to exercise the
iOS NEON path).
Track B — Android:
Real Android apps (ART/Compose) can't consume androidNativeArm64 klibs — that
target only serves pure Kotlin/Native binaries. The practical route is a small JNI
bridge: an AAR module with externalNativeBuild over the same C sources, jniLibs
for arm64-v8a, thin JNI shims per kernel, and a priority-100 KernelProvider in
androidMain registered from PlatformCpuOpsFactory.android.kt. It works against
the existing heap FloatArray/ByteArray kernel SPI, no storage redesign needed.
(If the K/N androidNativeArm64 route is wanted anyway, note
skainet-backend-api doesn't declare androidNative targets yet, while
skainet-lang-core already does.)
Small kernel gap for either track: q4_0_matmul.c is scalar-only (no NEON
body), while q8_0/q4k/q5k/q6k have one. Q4_0 is one of the priority mobile formats,
so it deserves a NEON body as part of this work.
Scale of the ask
At 1 tok/s on Android we need roughly 5x to be usable, not the full 21x the JVM
gets — even a partial result unblocks real apps. Related: #910 (vectorized eager
CPU kernels for K/N), #722 (accelerated CPU ops for linux native targets).
We have a physical-device test bench (Android phone + iPhone) and will gladly test
any branch or snapshot and report numbers back. Happy to contribute PRs for the
tracks above, starting with the cinterop packaging fix.
- 主要言語
- Kotlin
- スター
- 52
- フォーク
- 15
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 36
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
SKaiNET-developers/SKaiNET のほかの issue
-
coding good first issue size:xs skill:kotlin-core sub-issue
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
SKaiNET-developers/SKaiNET#1323 ·
メンテナーはふだん 1 日以内に返信
-
coding good first issue platform size:xs skill:js sub-issue
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
SKaiNET-developers/SKaiNET#1232 ·
メンテナーはふだん 1 日以内に返信
-
skeep tracking
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
SKaiNET-developers/SKaiNET#1331 ·
メンテナーはふだん 1 日以内に返信
-
assessment size:s skill:review sub-issue
難易度 4/5 1〜2日 初心者へのやさしさ 18/100
SKaiNET-developers/SKaiNET#1330 ·
メンテナーはふだん 1 日以内に返信
-
documentation good first issue size:s skill:docs sub-issue
難易度 3/5 1〜2日 初心者へのやさしさ 78/100
SKaiNET-developers/SKaiNET#1329 ·
メンテナーはふだん 1 日以内に返信
SKaiNET-developers/SKaiNET の issue をすべて見る
似ている issue
-
bugbane/qf good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
osservatorionessuno/bugbane#173 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
Bayern feature:Application ready web
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
digitalfabrik/entitlementcard#3176 ·
メンテナーはふだん 7 日以内に返信
-
bug need-device
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
ramesh130/superplayer#495 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
maxrave-dev/SimpMusic#2649 ·
メンテナーはふだん 2 日以内に返信