PyObjC: MetalPerformanceShadersGraph

12.1 · active · verified Tue Apr 14

PyObjC-framework-MetalPerformanceShadersGraph provides Python wrappers for Apple's MetalPerformanceShadersGraph framework on macOS. This framework enables high-performance, energy-efficient computation on Apple platforms by leveraging various hardware compute blocks, allowing users to generate symbolic compute graphs of operations for GPU execution. The library is actively maintained with frequent releases, often synchronized with new macOS SDK updates. Its current version is 12.1.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the basic import and instantiation of an `MPSGraph` object using PyObjC. A full MetalPerformanceShadersGraph workflow involves complex setup with tensors, operations, and compilation for a specific Metal device, which is beyond the scope of a minimal quickstart. Users should consult Apple's official documentation for detailed MPSGraph usage.

from MetalPerformanceShadersGraph import MPSGraph
from Foundation import NSObject # For general PyObjC interaction

# Instantiate a Metal Performance Shaders Graph
# Note: This is a minimal example. Actual graph creation involves defining
# tensors, operations, and compiling for a Metal device.
# Refer to Apple's MetalPerformanceShadersGraph documentation for usage.

try:
    graph = MPSGraph.alloc().init()
    # Alternatively, for PyObjC 10.4+ a more Pythonic way often works:
    # graph = MPSGraph()
    print(f"Successfully instantiated MPSGraph: {graph}")
    print(f"MPSGraph options: {graph.options()}")
except Exception as e:
    print(f"Failed to instantiate MPSGraph or access options: {e}")
    print("Ensure you are running on macOS with Metal support.")

# Example of a basic NSObject to confirm PyObjC is working generally
obj = NSObject.alloc().init()
print(f"Successfully instantiated NSObject: {obj}")

view raw JSON →