A Swift framework for running Metal compute kernels on Apple Silicon. Write powerful GPU-accelerated code without the boilerplate.
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];
}
Leverage the full power of Apple's GPU for compute-intensive workloads with minimal overhead.
Clean Swift abstractions over Metal. Load, configure, and execute kernels in just a few lines.
Drop it into any Swift project with a single line in your Package.swift. No extra setup.
Run multiple kernels concurrently. All execution is thread-safe out of the box.
Performance benchmarking tools included. Measure throughput, latency, and memory bandwidth.
Pre-configured GitHub Actions for build, test, and lint. Ship with confidence.
Vector addition in just a few lines of 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]
Add to your 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"]
)
]
)