diff --git a/.github/workflows/build-sphinx.yml b/.github/workflows/build-sphinx.yml index e1ad17217cc..2258287ac0f 100644 --- a/.github/workflows/build-sphinx.yml +++ b/.github/workflows/build-sphinx.yml @@ -4,6 +4,14 @@ on: branches: - master pull_request: + types: [opened, synchronize, reopened, closed] + +env: + PUBLISH_DIR: doc/_build/html/ + +defaults: + run: + shell: bash -l {0} jobs: build-and-deploy: @@ -11,10 +19,6 @@ jobs: runs-on: ubuntu-20.04 - defaults: - run: - shell: bash -l {0} - env: python-ver: '3.9' CHANNELS: '-c dppy/label/dev -c intel -c conda-forge --override-channels' @@ -116,4 +120,65 @@ jobs: uses: peaceiris/actions-gh-pages@v3.9.3 with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: doc/_build/html/ + publish_dir: ${{ env.PUBLISH_DIR }} + + - name: Publish pull-request docs + if: | + !github.event.pull_request.head.repo.fork && github.event.pull_request && github.event.action != 'closed' + uses: peaceiris/actions-gh-pages@v3.9.3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ${{ env.PUBLISH_DIR }} + destination_dir: ./pull/${{ github.event.number }} + allow_empty_commit : true + keep_files: true + commit_message: ${{ github.event.head_commit.message }} + publish_branch: gh-pages + user_name: 'github-actions[bot]' + user_email: 'github-actions[bot]@users.noreply.github.com' + + - name: Comment with URL to published pull-request docs + if: | + !github.event.pull_request.head.repo.fork && github.event.pull_request && github.event.action != 'closed' + env: + PR_NUM: ${{ github.event.number }} + uses: mshick/add-pr-comment@v2.8.1 + with: + message: | + View rendered docs @ https://intelpython.github.io/dpnp/pull/${{ env.PR_NUM }}/index.html + allow-repeats: false + + clean: + if: | + !github.event.pull_request.head.repo.fork && github.event.pull_request && github.event.action == 'closed' + + needs: build-and-deploy + + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v3.5.2 + with: + fetch-depth: 0 + + - name: Remove docs [PR closed] + env: + PR_NUM: ${{ github.event.number }} + run: | + git remote add tokened_docs https://IntelPython:${{ secrets.GITHUB_TOKEN }}@github.com/IntelPython/dpnp.git + git fetch tokened_docs + git checkout --track tokened_docs/gh-pages + echo `pwd` + [ -d pull/${PR_NUM} ] && git rm -rf pull/${PR_NUM} + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git commit -m "Removing docs for closed pull request ${PR_NUM}" + git push tokened_docs gh-pages + + - name: Modify the comment with URL to official documentation + uses: mshick/add-pr-comment@v2.8.1 + with: + find: | + View rendered docs @.+ + replace: | + View rendered docs @ https://intelpython.github.io/dpnp/index.html diff --git a/CHANGELOG.md b/CHANGELOG.md index e212880a1ef..01911ea4911 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.12.2] - TBA + +### Added + +### Changed + +### Fixed + ## [0.12.1] - 07/18/2023 ### Added @@ -23,11 +31,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added a specialized kernel for `dpnp.sum` with `axis=0` as a pybind11 extension [#1479](https://github.com/IntelPython/dpnp/pull/1479) * Redesigned `dpnp.square` function through pybind11 extension of OneMKL call where possible or Leveraging on `dpctl.tensor` implementation [#1473](https://github.com/IntelPython/dpnp/pull/1473) * Redesigned `dpnp.cos` and `dpnp.sin` functions through pybind11 extension of OneMKL calls where possible or Leveraging on `dpctl.tensor` implementation [#1471](https://github.com/IntelPython/dpnp/pull/1471) -* Redesigned `dpnp.sqrt` function through pybind11 extension of OneMKL call where possible or Leveraging on `dpctl.tensor` implementation [#1470](https://github.com/IntelPython/dpnp/pull/1470) -* Redesigned `dpnp.log` function through pybind11 extension of OneMKL call where possible or Leveraging on `dpctl.tensor` implementation [#1469](https://github.com/IntelPython/dpnp/pull/1469) +* Redesigned `dpnp.sqrt` function through pybind11 extension of OneMKL call where possible or leveraging on `dpctl.tensor` implementation [#1470](https://github.com/IntelPython/dpnp/pull/1470) +* Redesigned `dpnp.log` function through pybind11 extension of OneMKL call where possible or leveraging on `dpctl.tensor` implementation [#1469](https://github.com/IntelPython/dpnp/pull/1469) * Leveraged `dpctl.tensor` implementation for logical operations [#1464](https://github.com/IntelPython/dpnp/pull/1464) * Leveraged `dpctl.tensor` implementation for `dpnp.floor_divide` function [#1462](https://github.com/IntelPython/dpnp/pull/1462) * Leveraged `dpctl.tensor` implementation for comparison functions [#1458](https://github.com/IntelPython/dpnp/pull/1458) + ### Fixed * Improved `dpnp.dot` function to support OneMKL calls for input and output arrays with strides [#1477](https://github.com/IntelPython/dpnp/pull/1477) diff --git a/doc/dpctl.rst b/doc/dpctl.rst index 1d6b42b0b82..2df63e0ce49 100644 --- a/doc/dpctl.rst +++ b/doc/dpctl.rst @@ -1,10 +1,19 @@ -DPCtl Usage -=========== +.. _dptcl: +.. include:: ./ext_links.txt -`DPCtl `_ provides API to manage -specific SYCL resources for SYCL-based Python packages. DPNP uses DPCtl as -a global SYCL queue manager. Below code illustrates simple usage of DPNP -in combination with dpCtl. +Interplay with the Data Parallel Control Library +=============================================== + +`Data Parallel Control Library`_ provides API to manage specific +`SYCL*`_ resources for SYCL-based Python packages. + +An example below demonstrates how the Data Parallel Extension for NumPy* can be +easily combined with the device management interface provided by dpctl package. + +Literally, the SYCL* queue manager interface from the dpctl package allows +to set an input queue as the currently usable queue inside the context +manager's scope. This way an array creation function from the dpnp package +which is defined inside the context will allocate the data using that queue. .. code-block:: python :linenos: @@ -16,10 +25,11 @@ in combination with dpCtl. x = np.array([1, 2, 3]) s = np.sum(x) -For more information please refer to `DPCtl's documentation `_. +For more information please refer to `Data Parallel Control Library`_ +documentation. Example -~~~~~~~ +------- .. literalinclude:: ../examples/example10.py :linenos: :language: python diff --git a/doc/dpnp_backend_api.rst b/doc/dpnp_backend_api.rst index e0c78ba9b62..56256c93935 100644 --- a/doc/dpnp_backend_api.rst +++ b/doc/dpnp_backend_api.rst @@ -4,4 +4,4 @@ C++ backend API Reference ************************* -`DPNP C++ backend `_ +`C++ backend of Data Parallel Extension for NumPy* `_ diff --git a/doc/ext_links.txt b/doc/ext_links.txt new file mode 100644 index 00000000000..d7a858723fc --- /dev/null +++ b/doc/ext_links.txt @@ -0,0 +1,16 @@ +.. + ********************************************************** + THESE ARE EXTERNAL PROJECT LINKS USED IN THE DOCUMENTATION + ********************************************************** + +.. _NumPy*: https://numpy.org/ +.. _Python* Array API Standard: https://data-apis.org/array-api/ +.. _OpenCl*: https://www.khronos.org/opencl/ +.. _oneAPI Level Zero: https://spec.oneapi.io/level-zero/latest/index.html +.. _DPC++: https://www.apress.com/gp/book/9781484255735 +.. _SYCL*: https://www.khronos.org/sycl/ +.. _dpctl: https://intelpython.github.io/dpctl/latest/index.html +.. _Data Parallel Control Library: https://intelpython.github.io/dpctl/latest/index.html +.. _Intel oneAPI Base Toolkit: https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit.html +.. _Intel Distribution for Python*: https://www.intel.com/content/www/us/en/developer/tools/oneapi/distribution-for-python.html +.. _Intel AI Analytics Toolkit: https://www.intel.com/content/www/us/en/developer/tools/oneapi/ai-analytics-toolkit.html diff --git a/doc/index.rst b/doc/index.rst index f6a33e9a58c..b34e2d15ab3 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -1,37 +1,20 @@ -========================================================= -DPNP -- A NumPy-compatible library for SYCL-based devices -========================================================= +.. _index: +.. include:: ./ext_links.txt -.. module:: dpnp - -`DPNP `_ is a NumPy-like library accelerated with SYCL on Intel devices. -It provides Python interfaces for many NumPy functions, and includes a subset of methods of :class:`dpnp.ndarray`. -Under the hood it is based on native C++ and oneMKL based kernels. - -Being drop-in replacement for Numpy its usage is very similar to Numpy: - - >>> import dpnp as np - -The :class:`dpnp.ndarray` class is a compatible alternative of :class:`numpy.ndarray`. - - >>> x = np.array([1, 2, 3]) - -``x`` in the above example is an instance of :class:`dpnp.ndarray` that is created identically to ``NumPy``'s one. -The key difference of :class:`dpnp.ndarray` from :class:`numpy.ndarray` is -that the memory is allocated on Intel GPU when setting up ``DPNP_QUEUE_GPU=1`` in the environment. +Data Parallel Extension for NumPy* +================================== - -Most of the array manipulations are also done in the way similar to NumPy such as: - - >>> s = np.sum(x) - -Please see the :ref:`API Reference ` for the complete list of supported NumPy APIs -along with their limitations. +.. module:: dpnp .. toctree:: :maxdepth: 2 - install + overview + quick_start_guide reference/index + +.. toctree:: + :maxdepth: 1 + :caption: Development information + dpnp_backend_api - dpctl diff --git a/doc/install.rst b/doc/install.rst deleted file mode 100644 index 01dd2e8df02..00000000000 --- a/doc/install.rst +++ /dev/null @@ -1,43 +0,0 @@ -Installation Guide -================== - -Requirements ------------- - -The following Linux distributions are recommended. - -* `Ubuntu `_ 20.04 LTS (x86_64) - -These components must be installed to use DPNP: - -* `Python `_: v3 - -Python Dependencies -~~~~~~~~~~~~~~~~~~~ - -NumPy-compatible API in DPNP is based on `NumPy `_ 1.18+. - - -Installing DPNP from conda-forge --------------------------------- - -You can install DPNP with Conda/Anaconda from the ``intel`` channel:: - - $ conda install -c intel dpnp - -.. _install_dpnp_from_source: - -Installing DPNP from Source ---------------------------- - -You can install the latest development version of DPNP from a cloned Git repository on Linux:: - - $ git clone --recursive https://github.com/IntelPython/dpnp.git - $ cd dpnp - $ python scripts/build_locally.py - -.. note:: - - To build the source tree downloaded from GitHub, you need to install - `Intel oneAPI Toolkit `_ - and Cython (``pip install cython`` or ``conda install cython``). diff --git a/doc/overview.rst b/doc/overview.rst new file mode 100644 index 00000000000..4215566df7e --- /dev/null +++ b/doc/overview.rst @@ -0,0 +1,40 @@ +.. _overview: +.. include:: ./ext_links.txt + +Overview +======== + +.. module:: dpnp + +The Data Parallel Extension for NumPy* (dpnp package) - a library that +implements a subset of `NumPy*`_ that can be executed on any +data parallel device. The subset is a drop-in replacement of core `NumPy*`_ +functions and numerical data types. + +The Data Parallel Extension for NumPy* is being developed as part of +`Intel AI Analytics Toolkit`_ and is distributed with the +`Intel Distribution for Python*`_. The dpnp package is also available +on Anaconda cloud. Please refer the :doc:`quick_start_guide` page to learn more. + +Being drop-in replacement for `NumPy*`_ means that the usage is very similar: + + >>> import dpnp as np + +The :class:`dpnp.ndarray` class is a compatible alternative of +:class:`numpy.ndarray`. + + >>> x = np.array([1, 2, 3]) + +``x`` in the above example is an instance of :class:`dpnp.ndarray` that +is created identically to ``NumPy*``'s one. The key difference of +:class:`dpnp.ndarray` from :class:`numpy.ndarray` is that the memory +is allocated on the default `SYCL*`_ device, which is a ``"gpu"`` on systems +with integrated or discrete GPU (otherwise it is the ``"host"`` device +on systems that do not have GPU). + +Most of the array manipulations are also done in the way similar to `NumPy*`_ such as: + + >>> s = np.sum(x) + +Please see the :ref:`API Reference ` for the complete list of supported `NumPy*`_ APIs +along with their limitations. diff --git a/doc/quick_start_guide.rst b/doc/quick_start_guide.rst new file mode 100644 index 00000000000..43ea5544f7d --- /dev/null +++ b/doc/quick_start_guide.rst @@ -0,0 +1,148 @@ +.. _quick_start_guide: +.. include:: ./ext_links.txt + +.. |copy| unicode:: U+000A9 + +.. |trade| unicode:: U+2122 + +================= +Quick Start Guide +================= + +Device Drivers +================= + +To start programming data parallel devices beyond CPU, you will need +an appropriate hardware. The Data Parallel Extension for NumPy* works fine +on Intel |copy| laptops with integrated graphics. In majority of cases, +your Windows*-based laptop already has all necessary device drivers installed. +But if you want the most up-to-date driver, you can always +`update it to the latest one `_. +Follow device driver installation instructions to complete the step. + + +Python Interpreter +================= + +You will need Python 3.8, 3.9, or 3.10 installed on your system. If you +do not have one yet the easiest way to do that is to install +`Intel Distribution for Python*`_. It installs all essential Python numerical +and machine learning packages optimized for the Intel hardware, including +Data Parallel Extension for NumPy*. +If you have Python installation from another vendor, it is fine too. All you +need is to install Data Parallel Extension for NumPy* manually as shown +in the next installation section. + + +Installation +============ + +Install Package from Anaconda +--------------------- + +It is recommended to use conda packages from the ``anaconda.org/intel`` +channel. You will need one of the commands below: + +* Conda: ``conda install dpnp -c intel -c conda-forge`` + +* Pip: ``pip install -i https://pypi.anaconda.org/intel/simple dpnp`` + +These commands install dpnp package along with its dependencies, including +``dpctl`` package with `Data Parallel Control Library`_ and all required +compiler runtimes and OneMKL. + +.. note:: + Before installing with conda or pip it is strongly advised to update ``conda`` and ``pip`` to latest versions + + +Build and Install Conda Package +------------------------------- + +Alternatively you can create and activate a local conda build environment: + +.. code-block:: bash + + conda create -n build-env conda-build + conda activate build-env + +And to build dpnp package from the sources: + +.. code-block:: bash + + conda build conda-recipe -c intel -c conda-forge + +Finanly, to install the result package: + +.. code-block:: bash + + conda install dpnp -c local + + +Build and Install with scikit-build +----------------------------------- + +Another way to build and install dpnp package from the source is to use Python +``setuptools`` and ``scikit-build``. You will need to create a local conda +build environment by command below depending on hosting OS. + +On Linux: + +.. code-block:: bash + + conda create -n build-env dpctl cython dpcpp_linux-64 mkl-devel-dpcpp tbb-devel onedpl-devel cmake scikit-build ninja pytest -c intel -c conda-forge + conda activate build-env + +On Windows: + +.. code-block:: bash + + conda create -n build-env dpctl cython dpcpp_win-64 mkl-devel-dpcpp tbb-devel onedpl-devel cmake scikit-build ninja pytest -c intel -c conda-forge + conda activate build-env + +To build and install the package on Linux OS, run: + +.. code-block:: bash + + python setup.py install -- -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx + +To build and install the package on Windows OS, run: + +.. code-block:: bash + + python setup.py install -- -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icx + +Alternatively, to develop on Linux OS, you can use the driver script: + +.. code-block:: bash + + python scripts/build_locally.py + + +Testing +======= + +If you want to execute the scope of Python test suites which are available +by the source, you will need to run a command as below: + +.. code-block:: bash + + pytest -s tests + +Examples +======== + +The examples below demonstrates a simple usage of the Data Parallel Extension for NumPy* + +.. literalinclude:: ../examples/example_sum.py + :linenos: + :language: python + :lines: 35- + :caption: How to create an array and to sum the elements + +.. literalinclude:: ../examples/example_cfd.py + :linenos: + :language: python + :lines: 34- + :caption: How to create an array on the specific device type and how the next computations follow it + +More examples on how to use ``dpnp`` can be found in ``dpnp/examples``. diff --git a/doc/reference/difference.rst b/doc/reference/difference.rst index ef0eb71a88e..9f2d28f3b97 100644 --- a/doc/reference/difference.rst +++ b/doc/reference/difference.rst @@ -1,5 +1,5 @@ -Difference between DPNP and NumPy -================================= +Difference with NumPy* +====================== .. _Data types: diff --git a/doc/reference/index.rst b/doc/reference/index.rst index 40da7e3df29..2885ac86df3 100644 --- a/doc/reference/index.rst +++ b/doc/reference/index.rst @@ -4,7 +4,7 @@ API Reference ************* -This is the official DPNP API reference. +API reference of the Data Parallel Extension for NumPy* ---- diff --git a/dpnp/backend/doc/Doxyfile b/dpnp/backend/doc/Doxyfile index ec73279f6eb..2d99d18f082 100644 --- a/dpnp/backend/doc/Doxyfile +++ b/dpnp/backend/doc/Doxyfile @@ -44,7 +44,7 @@ PROJECT_NUMBER = 0.12.1 # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = "NumPy-like API accelerated with SYCL" +PROJECT_BRIEF = "Data Parallel Extension for NumPy*" # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index 3c80458f94a..515d3051323 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -334,11 +334,15 @@ def get_dpnp_descriptor( def get_include(): - r"""Return the directory that contains the DPNP C++ backend \*.h header files.""" + r""" + Return the directory that contains \*.h header files of dpnp C++ backend. - dpnp_path = os.path.join(os.path.dirname(__file__), "backend", "include") + An extension module that needs to be compiled against dpnp backend + should use this function to locate the appropriate include directory. - return dpnp_path + """ + + return os.path.join(os.path.dirname(__file__), "backend", "include") def get_normalized_queue_device(obj=None, device=None, sycl_queue=None): diff --git a/examples/example1.py b/examples/example1.py index 7d86c0a15e9..e078a02090d 100644 --- a/examples/example1.py +++ b/examples/example1.py @@ -36,21 +36,13 @@ """ -try: - import dpnp -except ImportError: - import os - import sys - - root_dir = os.path.join(os.path.dirname(__file__), os.pardir) - sys.path.append(root_dir) - - import dpnp - import time +import dpctl import numpy +import dpnp + def run_dgemm(executor, name, size, test_type, repetition): x1 = executor.reshape( @@ -75,15 +67,23 @@ def run_dgemm(executor, name, size, test_type, repetition): return (min_time, med_time, max_time), result.item(5) +def get_dtypes(): + _dtypes_list = [numpy.int32, numpy.int64, numpy.float32] + device = dpctl.select_default_device() + if device.has_aspect_fp64: + _dtypes_list.append(numpy.float64) + return _dtypes_list + + if __name__ == "__main__": test_repetition = 5 - for test_type in [numpy.float64, numpy.float32, numpy.int64, numpy.int32]: + for test_type in get_dtypes(): type_name = numpy.dtype(test_type).name print( f"...Test data type is {test_type}, each test repetitions {test_repetition}" ) - for size in [16, 32, 64, 128]: # , 256, 512, 1024, 2048, 4096]: + for size in [16, 32, 64, 128, 256, 512, 1024]: times_python, result_python = run_dgemm( numpy, "", size, test_type, test_repetition ) @@ -97,6 +97,6 @@ def run_dgemm(executor, name, size, test_type, repetition): msg = f"type:{type_name}:N:{size:4}" msg += f":__NumPy__:{times_python[1]:.3e}:(min:{times_python[0]:.3e}:max:{times_python[2]:.3e})" - msg += f":__SYCL__:{times_sycl[1]:.3e}:(min:{times_sycl[0]:.3e}:max:{times_sycl[2]:.3e})" + msg += f":__DPNP__:{times_sycl[1]:.3e}:(min:{times_sycl[0]:.3e}:max:{times_sycl[2]:.3e})" msg += f":ratio:{times_python[1]/times_sycl[1]:6.2f}:verification:{verification}" print(msg) diff --git a/examples/example10.py b/examples/example10.py index a11c4610f48..e2518423678 100644 --- a/examples/example10.py +++ b/examples/example10.py @@ -28,23 +28,16 @@ """Example 10. This example shows simple usage of the DPNP -in combination with dpCtl. +in combination with dpctl. """ import time -try: - import dpnp -except ImportError: - import os - import sys - - sys.path.insert(0, os.path.abspath(".")) - import dpnp - import numpy +import dpnp + def run(executor, size, test_type, repetition): x = executor.reshape( @@ -61,9 +54,17 @@ def run(executor, size, test_type, repetition): return numpy.median(times), result +def get_dtypes(): + _dtypes_list = [numpy.int32, numpy.int64, numpy.float32] + device = dpctl.select_default_device() + if device.has_aspect_fp64: + _dtypes_list.append(numpy.float64) + return _dtypes_list + + def example(): test_repetition = 5 - for test_type in [numpy.float64, numpy.float32, numpy.int64, numpy.int32]: + for test_type in get_dtypes(): type_name = numpy.dtype(test_type).name print( f"...Test data type is {type_name}, each test repetitions {test_repetition}" @@ -80,7 +81,7 @@ def example(): else: verification = f"({result_dpnp} != {result_numpy})" - msg = f"type:{type_name}:N:{size:4}:NumPy:{time_numpy:.3e}:SYCL:{time_dpnp:.3e}" + msg = f"type:{type_name}:N:{size:4}:NumPy:{time_numpy:.3e}:DPNP:{time_dpnp:.3e}" msg += f":ratio:{time_numpy/time_dpnp:6.2f}:verification:{verification}" print(msg) @@ -90,7 +91,7 @@ def example(): import dpctl with dpctl.device_context("opencl:gpu") as gpu_queue: - gpu_queue.get_sycl_device().dump_device_info() + gpu_queue.get_sycl_device().print_device_info() example() except ImportError: diff --git a/examples/example2.py b/examples/example2.py index f2a4d06a4dc..55408d3df49 100644 --- a/examples/example2.py +++ b/examples/example2.py @@ -36,36 +36,18 @@ """ -try: - import dpnp -except ImportError: - import os - import sys - - root_dir = os.path.join(os.path.dirname(__file__), os.pardir) - sys.path.append(root_dir) - - import dpnp - import time import numpy -common_function_one_input = numpy.sin -""" -Fixed third party function -""" - - -def get_package_specific_input_data_type(input_type, size): - return input_type.arange(size) +import dpnp -def run_third_party_function(input, repetition): +def run_third_party_function(xp, input, repetition): times = [] for _ in range(repetition): start_time = time.time() - result = common_function_one_input(input) + result = xp.sin(input) end_time = time.time() times.append(end_time - start_time) @@ -75,18 +57,19 @@ def run_third_party_function(input, repetition): if __name__ == "__main__": test_repetition = 5 - for input_type in [numpy, dpnp]: - type_name = input_type.__name__ + for xp in [numpy, dpnp]: + type_name = xp.__name__ print( f"...Test data type is {type_name}, each test repetitions {test_repetition}" ) - for size in [2048, 4096, 8192, 16384, 32768, 65536]: - input_data = get_package_specific_input_data_type(input_type, size) + for size in range(20, 25): + size = 2**size + input_data = xp.arange(size) result_time, result = run_third_party_function( - input_data, test_repetition + xp, input_data, test_repetition ) print( - f"type:{type_name}:N:{size:6}:Time:{result_time:.3e}:result:{result:.3e}" + f"type:{type_name}:N:{size:6}:Time:{result_time:.3e}:result:{result}" ) diff --git a/examples/example6.py b/examples/example6.py index 96a494bc437..5cd19651046 100644 --- a/examples/example6.py +++ b/examples/example6.py @@ -32,17 +32,7 @@ dpnp.random.randn """ - -try: - import dpnp -except ImportError: - import os - import sys - - root_dir = os.path.join(os.path.dirname(__file__), os.pardir) - sys.path.append(root_dir) - - import dpnp +import dpnp if __name__ == "__main__": # TODO diff --git a/examples/example7.py b/examples/example7.py index 1e5ee8ce596..a0df2e1eef3 100644 --- a/examples/example7.py +++ b/examples/example7.py @@ -25,7 +25,7 @@ # THE POSSIBILITY OF SUCH DAMAGE. # ***************************************************************************** -"""Example 1. +"""Example 7. This example shows simple usage of the DPNP to calculate square matrix multiplication @@ -35,22 +35,13 @@ """ - -try: - import dpnp -except ImportError: - import os - import sys - - root_dir = os.path.join(os.path.dirname(__file__), os.pardir) - sys.path.append(root_dir) - - import dpnp - import time +import dpctl import numpy +import dpnp + def run_function(executor, name, size, test_type, repetition): x = executor.reshape( @@ -69,15 +60,23 @@ def run_function(executor, name, size, test_type, repetition): return execution_time, result +def get_dtypes(): + _dtypes_list = [numpy.int32, numpy.int64, numpy.float32] + device = dpctl.select_default_device() + if device.has_aspect_fp64: + _dtypes_list.append(numpy.float64) + return _dtypes_list + + if __name__ == "__main__": test_repetition = 5 - for test_type in [numpy.float64, numpy.float32, numpy.int64, numpy.int32]: + for test_type in get_dtypes(): type_name = numpy.dtype(test_type).name print( f"...Test data type is {test_type}, each test repetitions {test_repetition}" ) - for size in [16, 32, 64, 128, 256, 512, 1024, 2048, 4096]: + for size in [256, 512, 1024, 2048, 4096, 8192]: time_python, result_python = run_function( numpy, "", size, test_type, test_repetition ) @@ -90,6 +89,6 @@ def run_function(executor, name, size, test_type, repetition): else: verification = f"({result_mkl} != {result_python})" - msg = f"type:{type_name}:N:{size:4}:NumPy:{time_python:.3e}:SYCL:{time_mkl:.3e}" + msg = f"type:{type_name}:N:{size:4}:NumPy:{time_python:.3e}:DPNP:{time_mkl:.3e}" msg += f":ratio:{time_python/time_mkl:6.2f}:verification:{verification}" print(msg) diff --git a/examples/example_bs.py b/examples/example_bs.py index db920c07ab3..488f495303f 100644 --- a/examples/example_bs.py +++ b/examples/example_bs.py @@ -32,20 +32,10 @@ """ -try: - import dpnp as np -except ImportError: - import os - import sys - - root_dir = os.path.join(os.path.dirname(__file__), os.pardir) - sys.path.append(root_dir) - - import dpnp as np - +import dpnp as np SIZE = 2**8 -DTYPE = np.float64 +DTYPE = np.default_float_type() SEED = 7777777 PL, PH = 10.0, 50.0 diff --git a/examples/example_cfd.py b/examples/example_cfd.py new file mode 100644 index 00000000000..db309065759 --- /dev/null +++ b/examples/example_cfd.py @@ -0,0 +1,48 @@ +# cython: language_level=3 +# -*- coding: utf-8 -*- +# ***************************************************************************** +# Copyright (c) 2023, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. +# ***************************************************************************** + +"""Example CFD. + +This example shows how DPNP follows compute follows data paradigm + +""" + +import dpnp as np + +x = np.empty(3) +try: + x = np.asarray([1, 2, 3], device="gpu") +except Exception: + print("GPU device is not available") + +print("Array x allocated on the device:", x.device) + +y = np.sum(x) + +print("Result y is located on the device:", y.device) # The same device as x +print("Shape of y is:", y.shape) # 0-dimensional array +print("y=", y) # Expect 6 diff --git a/examples/example_sum.py b/examples/example_sum.py new file mode 100644 index 00000000000..478194ccbe3 --- /dev/null +++ b/examples/example_sum.py @@ -0,0 +1,44 @@ +# cython: language_level=3 +# -*- coding: utf-8 -*- +# ***************************************************************************** +# Copyright (c) 2023, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. +# ***************************************************************************** + +"""Example sum. + +This example shows simple usage of the DPNP +to calculate sum of an array + +""" + +import dpnp as np + +x = np.asarray([1, 2, 3]) +print("Array x allocated on the device:", x.device) + +y = np.sum(x) + +print("Result y is located on the device:", y.device) # The same device as x +print("Shape of y is:", y.shape) # 0-dimensional array +print("y =", y) # Expect 6