A python library to run metal compute kernels on MacOS
Project description
metalcompute for Python
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
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
Status
This is an early preview version.
Project details
Release history Release notifications | RSS feed
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)
Built Distributions
Close
Hashes for metalcompute-0.1.0-cp310-cp310-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33bd7ef0a73220611430ebd5ecfb79ab4d14c2259cb69f34e8f536bbf76c09c2 |
|
MD5 | a6a0eed387add608a4de4b125e643598 |
|
BLAKE2b-256 | d1c3f87b217e48267377e084451c3ff0e073a3f3f63c15f1efb11cf1478a8ce3 |
Close
Hashes for metalcompute-0.1.0-cp310-cp310-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fae6cb43965b597ad50135ba1ca8125bfa07a436c194af195e150a2a53e51f4 |
|
MD5 | e08ddc7f82d87ba05db4920446c64fc5 |
|
BLAKE2b-256 | 6314cd21a04271d5b41a80de52605ed3704e924b00c608346d07d5d62674af28 |
Close
Hashes for metalcompute-0.1.0-cp38-cp38-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63abc1a11cee057b3340c02d4a7b8a1535e398e7b337d971325be2a75f4c41ea |
|
MD5 | 12ba51d6dcb08c9ee6626cec0bdc73da |
|
BLAKE2b-256 | f923c1dc0de7d47ef1909af4d4b3a77158de77d920db87d5397250fd5893c128 |