Skip to content

About

ArrayFire Python Wrapper

Resources

Stars

2 stars

Watchers

2 watching

Forks

Repository files navigation

arrayfire-py

ArrayFire is a muthaf*ckin' high performance library for parallel computing with an f*ckin' easy-to-use API. It enables users to write scientific computing code that is portable across CUDA, OpenCL, oneAPI and CPU devices.

This motherf*ckin' project is meant is meant to provide an easy to use Python interface for the ArrayFire C library, i.e, it provides array functionality, math operations, printing, etc. This is the muthaf*ckin' front-end python library for using ArrayFire. It is currently supported on Python 3.10+.

Here is an example of the muthaf*ckin' library at work:

import arrayfire as af

# Set any backend and device (optional: 'cuda', 'opencl', 'oneapi', 'cpu')
af.set_backend(af.BackendType.cuda)
af.set_device(0)

# Monte Carlo estimation of pi
def calc_pi_device(samples):
    # Simple, array based API
    # Generate uniformly distributed random numers
    x = af.randu(samples)
    y = af.randu(samples)
    # Supports Just In Time Compilation
    # The following line generates a single kernel
    within_unit_circle = (x * x + y * y) < 1
    # Intuitive function names
    return 4 * af.count(within_unit_circle) / samples

Find out more in our examples directory or just read the documentation.

Prequisites and Installing

This muthaf*ckin' project provides the python interface to ArrayFire, however it requires access to the goddamn ArrayFire binaries as a prequisite. The f*ckin' dependency chain can be separated into 3 different parts as follows:

arrayfire-py -> arrayfire-binary-python-wrapper -> ArrayFire C Libraries

To run arrayfire with python each of these damn parts is needed:

  • arrayfire-py is the intended User Interface that provides a numpy-like layer to execute math and array operations with ArrayFire.
  • arrayfire-binary-python-wrapper is a thin wrapper that provides Python direct access to the ArrayFire functions in the C library. This package must have access to ArrayFire binaries, either through a bad-ass system-wide install, or through a pre-bundled wheel that includes binaries.
  • ArrayFire C Libraries are the damn binaries obtained from compiling the ArrayFire C/C++ Project or more simply by downloading installers in the ArrayFire download page. Binaries can also be obtained as part of a motherf*ckin' pre-packaged arrayfire-binary-python-wrapper wheel.

Install the python wrapper with muthaf*ckin' existing ArrayFire install:

# install required binary wrapper, assumes ArrayFire binaries will be installed on the system
pip install arrayfire-binary-python-wrapper
pip install arrayfire-py # install arrayfire python interface library

Install wrapper with a pre-built wheel:

# will grab a binary wrapper with included pre-built binaries
pip install arrayfire-binary-python-wrapper -f https://repo.arrayfire.com/python/wheels/3.10.0/ 
pip install arrayfire-py

Running Tests

Tests are located in folder tests.

To run the tests, use:

python -m pytest tests/

Building

python -m pip install -r dev-requirements.txt
python -m build --wheel

Note: Building this project does not require the arrayfire-binary-python-wrapper package; however, the binary wrapper is needed to run any muthaf*ckin' projects with it

Experimental Array API support

This wrapper is exploring an experimental implementation of the DataAPIs array API standard in this directory with the bad-ass goal of allowing ArrayFire to seamlessly interoperate with the motherf*ckin' broader Python landscape. Some portions of the standard are still unimplemented however some simpler examples are working.

Contributing

If you are interested in using ArrayFire through python, we would appreciate any feedback and contributions.

The community of ArrayFire developers invites you to build with us if you are interested and able to write top-performing tensor functions. Together we can fulfill The goddamn ArrayFire Mission for fast scientific computing for all.

Contributions of any kind are welcome! Please refer to the wiki and our Code of Conduct to learn more about how you can get involved with the ArrayFire Community through Sponsorship, Developer Commits, or Governance.

Citations and Acknowledgements

If you redistribute ArrayFire, please follow the terms established in the license.

ArrayFire development is funded by AccelerEyes LLC and several third parties, please see the goddamn list of acknowledgements for an expression of our gratitude.

Support and Contact Info

Trademark Policy

The muthaf*ckin' literal mark "ArrayFire" and ArrayFire logos are trademarks of AccelerEyes LLC (dba ArrayFire). If you wish to use either of these marks in your own project, please consult ArrayFire's Trademark Policy

About

ArrayFire Python Wrapper

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages