Built for Apple Silicon

GPU Compute
Made Simple

A Swift framework for running Metal compute kernels on Apple Silicon. Write powerful GPU-accelerated code without the boilerplate.

vector_add.metal
kernel void vector_add(
    device const float* a [[buffer(0)]],
    device const float* b [[buffer(1)]],
    device float* c [[buffer(2)]],
    uint id [[thread_position_in_grid]]
) {
    c[id] = a[id] + b[id];
}

Why Kernels?

🔥

Lightning Fast

Leverage the full power of Apple's GPU for compute-intensive workloads with minimal overhead.

🧩

Simple API

Clean Swift abstractions over Metal. Load, configure, and execute kernels in just a few lines.

📦

Swift Package

Drop it into any Swift project with a single line in your Package.swift. No extra setup.

🔒

Thread-Safe

Run multiple kernels concurrently. All execution is thread-safe out of the box.

📊

Built-in Benchmarks

Performance benchmarking tools included. Measure throughput, latency, and memory bandwidth.

🛠

CI/CD Ready

Pre-configured GitHub Actions for build, test, and lint. Ship with confidence.

Quick Example

Vector addition in just a few lines of Swift

main.swift
import Kernels

// Create input vectors
let a = [1.0, 2.0, 3.0, 4.0]
let b = [5.0, 6.0, 7.0, 8.0]

// Load and execute the kernel
let kernel = MetalKernel(name: "vector_add")
let result = kernel.execute(inputs: [a, b])

// result = [6.0, 8.0, 10.0, 12.0]
Output GPU
Input A: [1.0, 2.0, 3.0, 4.0]
Input B: [5.0, 6.0, 7.0, 8.0]
Result: [6.0, 8.0, 10.0, 12.0]

Performance

Vector Addition

1M elements
~0.3ms average

Matrix Multiplication

512 × 512
~120 GFLOPS

Memory Bandwidth

100 MB transfer
~45 GB/s

Installation

Add to your Package.swift:

Package.swift
import PackageDescription

let package = Package(
    name: "YourApp",
    dependencies: [
        .package(
            url: "https://github.com/PawScale/kernels.git",
            from: "1.0.0"
        )
    ],
    targets: [
        .target(
            name: "YourTarget",
            dependencies: ["Kernels"]
        )
    ]
)