Skip to content

Upgrade Metal backend to unified GPU/ANE architecture#20

Merged
ChinChangYang merged 1 commit intoios-devfrom
claude/upgrade-metal-backend-0QtoO
Apr 7, 2026
Merged

Upgrade Metal backend to unified GPU/ANE architecture#20
ChinChangYang merged 1 commit intoios-devfrom
claude/upgrade-metal-backend-0QtoO

Conversation

@ChinChangYang
Copy link
Copy Markdown
Owner

@ChinChangYang ChinChangYang commented Apr 7, 2026

Summary

  • Replace separate CoreML and Metal backends with a single unified Metal backend based on lightvector/KataGo#1148, enabling per-thread GPU/ANE multiplexing via the vendored katagocoreml C++ library for on-the-fly .bin.gz → CoreML model conversion
  • Change the built-in model from a pre-converted CoreML .mlpackage (b28c512) to an 18-block .bin.gz network that the Metal backend converts at runtime, eliminating the need for pre-converted CoreML models
  • Simplify the iOS app interface so all models (built-in and downloaded) use the same Metal backend path, with iOS defaulting to ANE (Neural Engine) for power efficiency and macOS defaulting to GPU (MPSGraph)

Key changes

C++ Backend

  • metalbackend.cpp/h — unified backend with CoreMLConversion namespace for native model conversion, per-thread METAL_MUX_GPU(0) / METAL_MUX_ANE(100) multiplexer
  • metalbackend.swift — rewritten for CoreML model loading/inference via CoreMLComputeHandle
  • metallayers.swift — new file with MPSGraph GPU layer implementations and MPSGraphModelHandle
  • cpp/external/katagocoreml/ — vendored C++ library (88 files) for .bin.gz.mlpackage conversion
  • Removed coremlbackend.cpp/h/swift, coremlmodel.swift, and all CoreML-specific code paths in nneval, setup, gtp, commandline

iOS App

  • KataGoHelper.swift — simplified: removed coremlModelPath/useMetal params; uses metalDeviceToUseThread0 + metalUseFP16
  • ModelRunnerView.swift — unified model loading (no more builtIn vs downloaded backend distinction)
  • NeuralNetworkModel.swift — built-in model is now "Built-in KataGo 18b Network" (.bin.gz)
  • default_gtp.cfg — Metal backend config (metalDeviceToUseThread0=100, metalUseFP16=true)

CI/Build

  • ci_post_clone.sh — installs cmake/ninja/protobuf/abseil, builds katagocoreml for all platforms, fetches 18b model
  • build.yml — removed CoreML .mlpackage download/test steps
  • Xcode project — added metallayers.swift, removed CoreML files, USE_COREML_BACKENDUSE_METAL_BACKEND, added katagocoreml linker flags

Test plan

  • Build for iOS Simulator, macOS, and visionOS Simulator
  • Verify built-in 18b model loads and converts to CoreML on first launch
  • Verify downloaded .bin.gz models work through the Metal backend
  • Test ANE inference on iOS device
  • Test GPU inference on macOS
  • Verify human SL model still loads correctly
  • Run Xcode Cloud CI pipeline end-to-end

https://claude.ai/code/session_01LLDk6NpbEpchikWcq21ksf

…ctor#1148

Replace the separate CoreML and Metal backends with a single unified Metal
backend that converts .bin.gz models to CoreML on-the-fly using the vendored
katagocoreml library. This enables a per-thread GPU/ANE multiplexer where
each NN server thread is dedicated to either GPU (MPSGraph, gpuIdx=0) or
ANE (CoreML CPU+ANE, gpuIdx=100).

Key changes:
- Add metallayers.swift for MPSGraph GPU layer implementations
- Rewrite metalbackend.swift for CoreML model loading and inference
- Add vendored katagocoreml C++ library (88 files) for native model conversion
- Remove coremlbackend.cpp/h/swift and coremlmodel.swift
- Update C++ support files (nneval, setup, gtp, commandline) to remove CoreML-
  specific code paths and the separate CoreML evaluator
- Simplify iOS app interface: all models use Metal backend (no more builtIn vs
  downloaded distinction for backend selection)
- Change built-in model from CoreML .mlpackage (b28) to 18b .bin.gz network
- Update default_gtp.cfg with Metal backend settings (metalDeviceToUseThread0,
  metalUseFP16)
- iOS defaults to ANE (Neural Engine) for power efficiency; macOS uses GPU
- Update ci_post_clone.sh to build katagocoreml and fetch 18b model
- Remove CoreML .mlpackage downloads from CI scripts

https://claude.ai/code/session_01LLDk6NpbEpchikWcq21ksf
@ChinChangYang ChinChangYang changed the base branch from master to ios-dev April 7, 2026 03:24
@ChinChangYang ChinChangYang changed the title Improve strength for high-dan levels in HumanSLModel Upgrade Metal backend to unified GPU/ANE architecture Apr 7, 2026
@ChinChangYang ChinChangYang merged commit 9c94a92 into ios-dev Apr 7, 2026
0 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants