mpsgraph-rs
Safe Rust bindings for Apple's
MetalPerformanceShadersGraph
framework on macOS.
The GitHub repository is mpsgraph-rs; the published crates.io package is
apple-mpsgraph because the short package name is already taken.
Install
Quick start
use MetalDevice;
use ;
let device = system_default.expect;
let graph = new.expect;
let input = graph
.placeholder
.expect;
let bias = graph.constant_scalar.expect;
let added = graph.addition.expect;
let output = graph.relu.expect;
let data = from_f32_slice
.expect;
let results = graph
.run
.expect;
let values = results.read_f32.expect;
assert_eq!;
v0.2.1 surface
- Core wrappers for
Graph,Tensor,TensorData,Executable,Feed, andFeedDescription - Metadata and descriptor coverage for
GraphDevice,ShapedType,Operation,CompilationDescriptor,ExecutionDescriptor,ExecutableExecutionDescriptor, andExecutableSerializationDescriptor - Graph / executable introspection helpers such as
placeholder_tensors,feed_tensors,target_tensors,output_types, tensorshape, tensordata_type, and tensor-datagraph_device - Graph construction and execution helpers for:
- placeholders and constants
- matrix multiplication
- unary arithmetic (
identity, exponent/log variants, square/sqrt/reciprocal, abs/neg/sign, rounding, trig/hyperbolic,isNaN,isInfinite) - binary arithmetic (
+,-,*,/,divisionNoNaN,power, min/max, comparisons, logicaland/or,atan2,floorModulo,select) - activations (
reLU,leakyReLU,sigmoid,softMax) and gradient helpers forreLU,sigmoid, andsoftMax - shape ops (
reshape,transpose/permute,slice,broadcast,concat,split,stack,pad) - reductions (existing sum/max/min/mean plus axis/axes sum/max/min/product)
topK- call ops via
Graph::callplusCompilationDescriptor::set_callable - control-flow builders for control dependencies,
if/then/else,while, andfor - gather ops (
gather,gatherND,gatherAlongAxis,gatherAlongAxisTensor) - descriptor-driven random ops (
RandomOpDescriptor, seeded/stateful random tensors, dropout) - recurrent layers (
singleGateRNN,LSTM,GRU) plus descriptor wrappers - 2D convolution, max pooling, and normalization helpers
- Shared constants for
MPSDataType,MPSGraphTensorNamedDataLayout,MPSGraphPaddingStyle, graph options, optimization levels, deployment platform values, random distributions, random sampling modes, and RNN activations
This crate still covers a subset of the full SDK. See COVERAGE.md for the audited header-by-header status and deferred areas.
Smoke examples