feat(backends): JNI + Kotlin/Native bridges for the ternary f32 kernel (#1139) - #1161
Merged
Merged
Conversation
JniTernaryF32Gemv and NativeKnTernaryF32Gemv implement the TernaryF32GemvNative seam over the same skainet_ternary_f32_gemv the JVM already downcalls via FFM — one C kernel, three bridges. Unlike bitnet_gemv there is no capability split: the LUT kernel needs only baseline NEON, so the BASELINE libskainet_jni.so — what a Cortex-A72/Pi-class device loads — carries the full SIMD path, and the cinterop face is what a linuxArm64 binary links (archive pinned to -march=armv8-a). The JNI shim reuses SKAINET_JNI_MATMUL_BODY (float in × byte weight × float out fits the shared shape). The K/N face zeroes the output itself for inputDim == 0 — pinning an empty array has no address to take. Parity: NativeKnTernaryF32GemvParityTest runs on the host archive and under qemu-aarch64 via -PcrossArm64 (all-256-bytes golden incl. code 3→+2, BitNet proj shape, the >512-row pthread regime, offsets); JniKernelParityTest gains the same cases on-device. Verified locally: macosArm64Test green (real NEON through cinterop), JNI AAR + androidTest assemble with NDK. Refs #1139, #1136 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 3 of #1136 — closes #1139. Builds on #1157.
What
Java_..._ternaryF32Gemvshim (reusesSKAINET_JNI_MATMUL_BODY),JniKernels.ternaryF32Gemvexternal,JniTernaryF32Gemv : TernaryF32GemvNative+install(). No capability split — the LUT kernel needs only baseline NEON, so the BASELINE.so(what an A72/Pi-class device loads) carries the full SIMD path.NativeKnTernaryF32Gemv : TernaryF32GemvNative+install()over the auto-exposedskainet_ternary_f32_gemv(.defunchanged). This is the board-consumption path: a linuxArm64 binary links the archive whose vendored file is pinned to-march=armv8-a.inputDim == 0(K/N zeroes output itself — empty arrays can't be pinned).Verified locally
:skainet-backend-native-cpu:macosArm64Test— 5/5 green: real NEON through cinterop on arm64:skainet-backend-jni-cpu:assembleDebug+assembleDebugAndroidTest— both.sovariants build with NDK, test APK compileslinuxArm64Test -PcrossArm64=true(qemu NEON lane) andJniKernelParityTeston an arm64 deviceKernel-support matrix unchanged (pack-registered kernels, not provider accessors).
Next: #1140 (I2_S GGUF import), #1141 (benchmarks + docs).
🤖 Generated with Claude Code