Dala.ML.EMLX (dala v0.0.2)

Copy Markdown View Source

iOS integration layer for EMLX (MLX backend for Nx).

This module provides automatic iOS-specific configuration for using EMLX on iOS devices and simulator. No manual configuration needed.

iOS Constraints

  • Real iOS devices: JIT is automatically disabled (W^X policy)
  • iOS Simulator: JIT works and is auto-enabled for development
  • Metal GPU: Automatically used on Apple Silicon (unified memory)

Usage (Zero config!)

# That's it! Just use Nx/EMLX as normal.
# The backend is automatically configured when your app starts.

tensor = Nx.tensor([1.0, 2.0, 3.0])
Nx.sum(tensor)  # Uses EMLX backend on iOS, Nx.BinaryBackend elsewhere

Summary

Functions

Checks if EMLX is available and properly configured.

Runs a simple benchmark to verify GPU acceleration.

Returns the default device for the current platform.

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

Returns true if running in iOS Simulator.

Returns the appropriate EMLX configuration for the current iOS platform.

Auto-configures EMLX for the current platform.

Creates a simple test tensor to verify EMLX is working.

Functions

available?()

Checks if EMLX is available and properly configured.

benchmark()

Runs a simple benchmark to verify GPU acceleration.

default_device()

Returns the default device for the current platform.

ios_device?()

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

ios_simulator?()

Returns true if running in iOS Simulator.

platform_config()

Returns the appropriate EMLX configuration for the current iOS platform.

Automatically detects device vs simulator and configures appropriately.

setup()

Auto-configures EMLX for the current platform.

Call this once at app startup. It will:

  1. Detect if running on iOS device or simulator
  2. Disable JIT on real devices (required by W^X policy)
  3. Enable Metal GPU acceleration on Apple Silicon
  4. Set EMLX as the default Nx backend

Safe to call multiple times. On non-iOS platforms, this is a no-op.

verify_installation()

Creates a simple test tensor to verify EMLX is working.