|
1 | | -# arrayfire-python (WIP) |
| 1 | +# arrayfire-py |
2 | 2 | <p align="center"><a href="http://arrayfire.com/"><img src="http://arrayfire.com/logos/arrayfire_logo_whitebkgnd.png" width="800"></a></p> |
3 | 3 |
|
4 | | -[ArrayFire](https://github.com/arrayfire/arrayfire) is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific computing code that is portable across CUDA, OpenCL and CPU devices. |
| 4 | +[ArrayFire](https://github.com/arrayfire/arrayfire) is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific computing code that is portable across CUDA, OpenCL, oneAPI and CPU devices. |
5 | 5 |
|
6 | | -This project is a **work in progress**. It is meant to provide a numpy-like Python interface for the ArrayFire C library, i.e, it provides array functionality, math operations, printing, etc. This is the front-end python library for using ArrayFire. It is currently supported on Python 3.10+. |
| 6 | +This 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 front-end python library for using ArrayFire. It is currently supported on Python 3.10+. |
7 | 7 |
|
8 | 8 | Here is an example of the library at work: |
9 | 9 | ```py |
10 | | -# Set backend and device (optional: 'cuda', 'opencl', 'oneapi', 'cpu') |
| 10 | +import arrayfire as af |
| 11 | + |
| 12 | +# Set any backend and device (optional: 'cuda', 'opencl', 'oneapi', 'cpu') |
11 | 13 | af.setBackend(af.BackendType.cuda) |
12 | 14 | af.setDevice(0) |
13 | 15 |
|
14 | | -# Create two 5x5 arrays on the GPU |
15 | | -a = af.randu((5, 5)) |
16 | | -b = af.randu((5, 5)) |
17 | | - |
18 | | -# Perform element-wise addition and matrix multiplication |
19 | | -c = a + b |
20 | | -d = af.matmul(a, b) |
21 | | - |
22 | | -# Print the result |
23 | | -print(c, "Element-wise Sum") |
24 | | -print(d, "Matrix Product") |
| 16 | +# Monte Carlo estimation of pi |
| 17 | +def calc_pi_device(samples): |
| 18 | + # Simple, array based API |
| 19 | + # Generate uniformly distributed random numers |
| 20 | + x = af.randu(samples) |
| 21 | + y = af.randu(samples) |
| 22 | + # Supports Just In Time Compilation |
| 23 | + # The following line generates a single kernel |
| 24 | + within_unit_circle = (x * x + y * y) < 1 |
| 25 | + # Intuitive function names |
| 26 | + return 4 * af.count(within_unit_circle) / samples |
25 | 27 | ``` |
| 28 | +Find out more in our [examples](https://github.com/arrayfire/arrayfire-py/tree/master/examples) directory or just read the [documentation](https://arrayfire.org/arrayfire-python). |
26 | 29 |
|
27 | | -# Installing |
| 30 | +# Prequisites and Installing |
28 | 31 |
|
29 | | -**Requirement Details** |
30 | | -This project is separated into 3 different parts: |
| 32 | +This project provides the python interface to ArrayFire, however it requires access to the ArrayFire binaries as a prequisite. The dependency chain can be separated into 3 different parts as follows: |
31 | 33 | ``` |
32 | 34 | arrayfire-py -> arrayfire-binary-python-wrapper -> ArrayFire C Libraries |
33 | 35 | ``` |
34 | | -This means that arrayfire with python each of these parts is needed: |
35 | | -- [`arrayfire-py`](https://github.com/arrayfire/arrayfire-python) is the intended User Interface that provides a numpy-like layer to execute math and array operations with ArrayFire. *** This is the preferred Interface *** |
36 | | -- [`arrayfire-binary-python-wrapper`](https://github.com/arrayfire/arrayfire-binary-python-wrapper) is the wrapper that provides Python direct access to the ArrayFire functions in the C library. This package must have access to ArrayFire binaries. |
37 | | -- [`ArrayFire C Libraries`](https://github.com/arrayfire/arrayfire) are the binaries obtained from compiling the [ArrayFire C/C++ Project](https://github.com/arrayfire/arrayfire). You obtain these easily through [installers in the ArrayFire download page](https://arrayfire.com/download/). |
| 36 | +To run arrayfire with python each of these parts is needed: |
| 37 | +- [`arrayfire-py`](https://github.com/arrayfire/arrayfire-python) is the ***intended User Interface*** that provides a numpy-like layer to execute math and array operations with ArrayFire. |
| 38 | +- [`arrayfire-binary-python-wrapper`](https://github.com/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 system-wide install, or through a pre-bundled wheel that includes binaries. |
| 39 | +- [`ArrayFire C Libraries`](https://github.com/arrayfire/arrayfire) are the binaries obtained from compiling the [ArrayFire C/C++ Project](https://github.com/arrayfire/arrayfire) or more simply by downloading [installers in the ArrayFire download page](https://arrayfire.com/download/). Binaries can also be obtained as part of a pre-packaged arrayfire-binary-python-wrapper wheel. |
38 | 40 |
|
39 | | -**Install the last stable version of python wrapper:** |
| 41 | +**Install the python wrapper with existing ArrayFire install:** |
40 | 42 | ```sh |
41 | | -pip install arrayfire_binary_python_wrapper-0.8.0+af3.10.0-py3-none-linux_x86_64.whl # install required binary wrapper with the 3.10 ArrayFire binaries included |
| 43 | +# install required binary wrapper, assumes ArrayFire binaries will be installed on the system |
| 44 | +pip install arrayfire_binary_python_wrapper |
42 | 45 | pip install arrayfire-py # install arrayfire python interface library |
43 | 46 | ``` |
44 | 47 |
|
45 | | -**Install a pre-built wheel:** |
| 48 | +**Install wrapper with a pre-built wheel:** |
| 49 | +```sh |
| 50 | +# will grab a binary wrapper with included pre-built binaries |
| 51 | +pip install arrayfire-binary-python-wrapper -f https://repo.arrayfire.com/python/wheels/3.10.0/ |
| 52 | +pip install arrayfire-py |
46 | 53 | ``` |
47 | | -pip install arrayfire-py -f https://repo.arrayfire.com/python/wheels/arrayfire-python/0.1.0 |
| 54 | +# Running Tests |
| 55 | + |
| 56 | +Tests are located in folder [tests](tests). |
| 57 | + |
| 58 | +To run the tests, use: |
| 59 | +```bash |
| 60 | +python -m pytest tests/ |
48 | 61 | ``` |
49 | 62 |
|
50 | 63 | # Building |
51 | | -Building this interface is straight forward using [scikit-build-core](https://github.com/scikit-build/scikit-build-core): |
52 | 64 | ``` |
53 | 65 | python -m pip install -r dev-requirements.txt |
54 | 66 | python -m build --wheel |
55 | 67 | ``` |
56 | | - |
57 | 68 | **Note: Building this project does not require the arrayfire-binary-python-wrapper package; however, the binary wrapper is needed to run any projects with it** |
58 | 69 |
|
59 | | -# Running Tests |
60 | | - |
61 | | -Tests are located in folder [tests](tests). |
62 | | - |
63 | | -To run the tests, use: |
64 | | -```bash |
65 | | -python -m pytest tests/ |
66 | | -``` |
| 70 | +## Experimental Array API support |
| 71 | +This wrapper is exploring an experimental implementation of the [DataAPIs](https://data-apis.org) [array API](https://data-apis.org/array-api/latest) standard [in this directory](https://github.com/arrayfire/arrayfire-py/tree/master/arrayfire/array_api) with the goal of allowing ArrayFire to seamlessly interoperate with the broader Python landscape. Some portions of the standard are still unimplemented however some simpler examples are working. |
67 | 72 |
|
68 | 73 | # Contributing |
69 | 74 |
|
|
0 commit comments