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.3 surface
- Core wrappers for
Graph,Tensor,TensorData,Executable,Feed, andFeedDescription - Metadata and descriptor coverage for
GraphDevice,ShapedType,GraphType,Object,Operation,VariableOp,CompilationDescriptor,ExecutionDescriptor,ExecutableExecutionDescriptor,ExecutableSerializationDescriptor, and the audited convolution / FFT / pooling / sparse / stencil descriptor families - Graph / executable introspection helpers such as
placeholder_tensors,feed_tensors,target_tensors,output_types, tensorshape, tensordata_type, tensor-datagraph_device, and raw shared-event wait/signal hooks on execution descriptors - Graph construction and execution helpers for:
- placeholders, constants, variable tensors,
read_variable, andassign_variable - matrix multiplication,
band_part, and matrix inverse - 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, cumulative sum,
topK, andtop_k_gradient - convolution helpers (
convolution2d,convolution_transpose2d,convolution3d,depthwise_convolution2d,depthwise_convolution3d) - pooling helpers (
max_pooling2d,max_pooling4d,max_pooling4d_return_indices), normalization, FFT, andim_to_col - loss / labeling helpers (
softmax_cross_entropy,one_hot,non_zero_indices,non_maximum_suppression) - quantization / resize / sample-grid / scatter / sort / sparse / stencil helpers
- 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
- placeholders, constants, variable tensors,
- Shared constants for
MPSDataType,MPSGraphTensorNamedDataLayout,MPSGraphPaddingStyle, graph options, optimization levels, deployment platform values, random distributions, random sampling modes, RNN activations, execution stages, reduction / FFT / loss / resize / scatter / sparse / NMS coordinate enums, and pooling return-indices modes
This crate now covers the full 90-symbol audited SDK surface. See COVERAGE.md for the header-by-header status and the broader SDK families that remain partial.
Smoke examples