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 >= 11
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
devices = mc.get_devices()
# Get list of available Metal devices
mc.init()
# Call before use. Will open default Metal device
# or to pick a specific device:
# mc.init(device_index)
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
Using device: Apple M1 (unified memory=True)
Running compute intensive Metal kernel to measure TFLOPS...
Estimated GPU TFLOPS: 2.55613
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.2.tar.gz
(11.1 kB
view hashes)
Built Distributions
Close
Hashes for metalcompute-0.1.2-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0948b20f0b9c211054329522031c89374bdadaf8a956081d7ec2fbeb01adf4b4 |
|
MD5 | ce9b9ad7b22fb2f24ddc5d7196e2dba9 |
|
BLAKE2b-256 | b6d8982a3da3f2238a151e68e004c1692f10dff9f1b2288410b0b2bc4845bbe5 |
Close
Hashes for metalcompute-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bdb31e50f2ee94f822b96bfba6a40e46c8c2f7c2f600357ab64861646e190d6 |
|
MD5 | 1b5b05401604642232beac5569d16347 |
|
BLAKE2b-256 | e93a710b98b6cd878e75569ce3adcac539de2a184647ad2ac688a258aa586ed2 |
Close
Hashes for metalcompute-0.1.2-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82ba276a9a767356f9f4128abccfb7ed017650f243f1519fff7c3e5760510192 |
|
MD5 | 856c7d8453254ef4de3fbe758be5d7a4 |
|
BLAKE2b-256 | 0f6601ff4a8631e698c523f1e8e0312a23d2dce54b4cd946b15ac9ba682b7fa7 |
Close
Hashes for metalcompute-0.1.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4860d9fe0d8efd5373c88080f9657bd75cc31aa1a008f1d71da460a9c533ced |
|
MD5 | 957e34c968abf70ce2bd293249f1ddc0 |
|
BLAKE2b-256 | f049f96bb223fcc5b6fccd80c94cb0b375f70a4ca62d744b631e700c35344c1e |
Close
Hashes for metalcompute-0.1.2-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 702b8ea1475c222b48d5c996ddab94cb2047836e260672b21c8a4a0ab7479d68 |
|
MD5 | 5ac1c1bff0c093bbd96188a05e745d89 |
|
BLAKE2b-256 | 85744d70828980dbfa9f1637e3445179a984bc7fd5a5e3b32958913ad860ba4d |
Close
Hashes for metalcompute-0.1.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eadb0f56c46f3b29c0cdc31dc63edc6b622998d3f05932598c195cc86f4da7c3 |
|
MD5 | f6a263aa857ec17f9c7276170385e0a7 |
|
BLAKE2b-256 | f17dfc2525b0114768dcd9ebecb202b7241a38450933d3ff4bab463e47b6eeec |