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 (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 .
Basic test
Example execution from M1-based Mac running macOS 12:
> 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.1.tar.gz
(9.6 kB
view hashes)
Built Distributions
Close
Hashes for metalcompute-0.1.1-cp310-cp310-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1d5f4e0435cf6d44a7e691e5e4e3062ab2494605f48f95a03430cd4f62a535f |
|
MD5 | cd87ed3181ce806fd80543fa1334f8f3 |
|
BLAKE2b-256 | 2c3974ca91e8f2852b1fa9399b21f2ea9de163ccc37298b5b83dc100e0317c54 |
Close
Hashes for metalcompute-0.1.1-cp310-cp310-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1a7bc40a773e2748167a9b0cf5d3d6c10e0ce26799dc036f548149c3928b7f1 |
|
MD5 | a9e5660d046835aa30107a6a93bad169 |
|
BLAKE2b-256 | 278264b8f41e43c7f2b371233c34d620593c4ace8b0ecb03d1f09c8380317c2a |
Close
Hashes for metalcompute-0.1.1-cp39-cp39-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f9e0ff2f7597e80fbacc5ef0b9c3ca88ef783c4146cf4ccd510cd456d62540f |
|
MD5 | ab15bf5bf087b3900e27aa5e553328b4 |
|
BLAKE2b-256 | 4fbef148a38222b422aba7733b4a3bcd9019647e47c056666644d259c4546239 |
Close
Hashes for metalcompute-0.1.1-cp39-cp39-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 240b2316041af3dcdf04727e5f5b7ba33093ba8a3e90ddf04603c2d5dbb09872 |
|
MD5 | 52fe3f9a51c39dc558c2b7e90e198bc9 |
|
BLAKE2b-256 | e33552ce0bda58f6071d1587f0383f399f2632b95aa951e5c5534d169829be80 |
Close
Hashes for metalcompute-0.1.1-cp38-cp38-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb3437713d30b68108f31f590be3b04d8d1709463602fa419de27d0e7452268f |
|
MD5 | 9af950b6ab3c5c3706c4c5fc7544e516 |
|
BLAKE2b-256 | 1bf30e865b07ee5f9470d848f8dd5a573de64e4cee30827496087dae786eb886 |
Close
Hashes for metalcompute-0.1.1-cp38-cp38-macosx_12_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fc58c80d4fa9765489bef08a07b4238f379b795c4890a6a883606186a956be6 |
|
MD5 | ab9a577b908c1a77c58aa5b43f564354 |
|
BLAKE2b-256 | 06becf833606c637d45a425f7740f3ee341c85af3cdce49ff6a100d9ff1cb20c |