Skip to main content

A python library to run metal compute kernels on MacOS

Project description

metalcompute for Python

Build status

A python library to run metal compute kernels on MacOS 12.0 (Monterey)

Installations

Install latest stable release from PyPI:

> python3 -m pip install metalcompute

Install latest unstable version from Github:

> python3 -m pip install git+https://github.com/baldand/py-metal-compute.git

Install locally from source:

> python3 -m pip install -e .

Basic test

Example execution from M1-based Mac running MacOS 12.0:

> python3 tests/basic.py
Calculating sin of 1234567 values
Expected value: 0.9805107116699219 Received value: 0.9807852506637573
Metal compute took: 0.0040209293365478516 s
Reference compute took: 0.1068720817565918 s

Interface

import metalcompute as mc

mc.init() 
# Call before use

mc.compile(program, function_name)
# Will raise exception with details if metal kernel has errors

mc.run(input_f32_or_u8_array, output_f32_or_u8_array, kernel_call_count)
# Run the kernel once with supplied input data, 
# filling supplied output data
# Specify number of kernel calls

mc.release()
# Call after use

Examples

Measure TFLOPS of GPU

> metalcompute-measure-flops
Running compute intensive Metal kernel to measure TFLOPS...
Estimated GPU TFLOPS: 2.50825

Render a 3D image with raymarching

# Usage: metalcompute-raymarch [<width> <height> [<output image file: PNG, JPG>]]

> metalcompute-raymarch.py 1024 1024 raymarch.jpg
Render took 0.0119569s

Raymarched spheres scene

Mandelbrot set

# Usage: metalcompute-mandelbrot [<width> <height> [<output image file: PNG, JPG>]]

> metalcompute-mandelbrot
Rendering mandelbrot set using Metal compute, res:4096x4096, iters:8192
Render took 0.401446s
Writing image to mandelbrot.png
Image encoding took 1.35182s

Mandelbrot set

Status

This is an early preview version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metalcompute-0.1.0.tar.gz (9.4 kB view hashes)

Uploaded Source

Built Distributions

metalcompute-0.1.0-cp310-cp310-macosx_12_0_x86_64.whl (24.1 kB view hashes)

Uploaded CPython 3.10 macOS 12.0+ x86-64

metalcompute-0.1.0-cp310-cp310-macosx_12_0_arm64.whl (24.7 kB view hashes)

Uploaded CPython 3.10 macOS 12.0+ ARM64

metalcompute-0.1.0-cp38-cp38-macosx_12_0_arm64.whl (40.8 kB view hashes)

Uploaded CPython 3.8 macOS 12.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page