Dala.ML (dala v0.0.7)

Copy Markdown View Source

Unified ML API for Dala apps on iOS and Android.

This module provides a single entry point for machine learning in Dala, integrating the full Nx ecosystem and iOS-native CoreML:

  • Nx - Core tensor library (pure Elixir, works everywhere)
  • Scholar - Traditional ML (regression, clustering, SVM, etc.)
  • NxSignal - Digital signal processing (audio, time series)
  • Axon - Neural networks (deep learning)
  • EMLX - Apple Silicon GPU acceleration (iOS only, auto-configured)
  • CoreML - iOS-native ML framework (Neural Engine, iOS only)
  • ONNX Runtime - Cross-platform inference engine (iOS/Android/desktop)

Quick Start

# Zero-config setup (call once at app startup)
Dala.ML.setup()

# Now use any of the integrated libraries
tensor = Nx.tensor([1.0, 2.0, 3.0])
Nx.sum(tensor)

Platform Support

LibraryiOS DeviceiOS SimAndroidmacOSLinux
Nx
Scholar
NxSignal
Axon
EMLX (GPU)
CoreML
ONNX Runtime

Not Supported on Mobile

  • EXLA/XLA - Requires precompiled XLA binaries (x86_64 Linux/macOS only)
  • NxIREE - Requires IREE runtime (no iOS/Android support)

ONNX Runtime (Cross-Platform)

For best cross-platform performance, use ONNX Runtime:

# Create session from ONNX model
{:ok, session_id} = Dala.ML.ONNX.create_session(model_data)

# Run inference
{:ok, output} = Dala.ML.ONNX.run(session_id, input_binary)

Summary

Functions

Returns true if running on Android.

Returns a list of available ML backends for the current platform.

Benchmarks a simple ML operation on the current backend.

Returns true if running on any iOS platform (device or simulator).

Returns true if running on a real iOS device (not simulator).

Returns true if running in iOS Simulator.

Runs inference using the best available backend.

Sets up the ML stack for the current platform.

Gets the current ML stack status.

Quick verification that the ML stack is working.

Functions

android?()

Returns true if running on Android.

available_backends()

Returns a list of available ML backends for the current platform.

benchmark(opts \\ [])

Benchmarks a simple ML operation on the current backend.

Returns %{time_ms: float, backend: term, gflops: float}.

ios?()

Returns true if running on any iOS platform (device or simulator).

ios_device?()

Returns true if running on a real iOS device (not simulator).

ios_simulator?()

Returns true if running in iOS Simulator.

predict(model, input)

Runs inference using the best available backend.

For CoreML models (iOS): Uses CoreML with Neural Engine. For ONNX models: Uses ONNX Runtime with platform EP. For Nx/Axon models: Uses the configured Nx backend.

Parameters

  • model: Model reference (session_id, identifier, or Axon model tuple)
  • input: Input data (Nx tensor, binary, or map)

Returns

  • {:ok, output} on success
  • {:error, reason} on failure

setup()

Sets up the ML stack for the current platform.

Call this once at app startup. It will:

  1. Detect the platform (iOS device, iOS sim, Android, etc.)
  2. Configure the best available Nx backend
  3. Enable EMLX GPU acceleration on iOS (if available)
  4. Return the configuration used

Examples

# In your app's start function:
def start(_type, _args) do
  Dala.ML.setup()
  # ... rest of app startup
end

# Or in a screen's mount:
def mount(_params, _session, socket) do
  Dala.ML.setup()
  {:ok, socket}
end

status()

Gets the current ML stack status.

Returns a map with:

  • :platform - :ios_device, :ios_simulator, :android, or :other
  • :backend - configured Nx backend
  • :emlx_available - if EMLX is available
  • :coreml_available - if CoreML is available (iOS only)
  • :libraries - which ML libraries are loaded

verify()

Quick verification that the ML stack is working.

Runs a simple tensor operation and returns the result.