Skip to content

Repository files navigation

Metal Compute Kernels for Swift

Website

SeverityPackagePlatformLink
N/AKernelsApple Silicon (macOS/iOS)Docs

A Swift-based framework for GPU compute on Apple Silicon using Apple’s Metal API.

Metal Compute Kernels enables writing high-performance GPU kernels directly in Swift and provides direct CUDA-to-Metal execution model translations.

CUDA kernel example:

__global__ voidvector_add(float *a, float *b, float *c, int n) {
int id = blockIdx.x * blockDim.x + threadIdx.x;
if (id < n) c[id] = a[id] + b[id];
}

Metal translation:

kernel voidvector_add(
device constfloat* a [[buffer(0)]],
device constfloat* b [[buffer(1)]],
device float* c [[buffer(2)]],
uint id [[thread_position_in_grid]]
) {
c[id] = a[id] + b[id];
}

Key differences include the replacement of blockIdx/threadIdx with thread_position_in_grid, explicit device address space qualifiers with buffer bindings, and dispatch-controlled grid sizing instead of in-kernel bounds checks.

Website · Documentation · API Reference · Swift GUIDANCE

About

swift gpu compute framework for apple silicon.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages