|
| 1 | +.. _getting_started: |
| 2 | +.. include:: ./ext_links.txt |
| 3 | + |
| 4 | +.. |copy| unicode:: U+000A9 |
| 5 | + |
| 6 | +.. |trade| unicode:: U+2122 |
| 7 | + |
| 8 | +Getting Started |
| 9 | +=============== |
| 10 | + |
| 11 | + |
| 12 | +Installing pre-built conda packages |
| 13 | +----------------------------------- |
| 14 | + |
| 15 | +``numba-dpex`` along with its dependencies can be installed using ``conda``. |
| 16 | +It is recommended to use conda packages from the ``anaconda.org/intel`` channel |
| 17 | +to get the latest production releases. |
| 18 | + |
| 19 | +.. code-block:: bash |
| 20 | +
|
| 21 | + conda create -n numba-dpex-env \ |
| 22 | + numba-dpex dpnp dpctl dpcpp-llvm-spirv \ |
| 23 | + -c intel -c conda-forge |
| 24 | +
|
| 25 | +To try out the bleeding edge, the latest packages built from tip of the main |
| 26 | +source trunk can be installed from the ``dppy/label/dev`` conda channel. |
| 27 | + |
| 28 | +.. code-block:: bash |
| 29 | +
|
| 30 | + conda create -n numba-dpex-env \ |
| 31 | + numba-dpex dpnp dpctl dpcpp-llvm-spirv \ |
| 32 | + -c dppy/label/dev -c intel -c conda-forge |
| 33 | +
|
| 34 | +
|
| 35 | +
|
| 36 | +Building from source |
| 37 | +-------------------- |
| 38 | + |
| 39 | +``numba-dpex`` can be built from source using either ``conda-build`` or |
| 40 | +``setuptools`` (with ``scikit-build`` backend). |
| 41 | + |
| 42 | +Steps to build using ``conda-build``: |
| 43 | + |
| 44 | +1. Ensure ``conda-build`` is installed in the ``base`` conda environment or |
| 45 | + create a new conda environment with ``conda-build`` installed. |
| 46 | + |
| 47 | +.. code-block:: bash |
| 48 | +
|
| 49 | + conda create -n build-env conda-build |
| 50 | + conda activate build-env |
| 51 | +
|
| 52 | +2. Build using the vendored conda recipe |
| 53 | + |
| 54 | +.. code-block:: bash |
| 55 | +
|
| 56 | + conda build conda-recipe -c intel -c conda-forge |
| 57 | +
|
| 58 | +3. Install the conda package |
| 59 | + |
| 60 | +.. code-block:: bash |
| 61 | +
|
| 62 | + conda install -c local numba-dpex |
| 63 | +
|
| 64 | +Steps to build using ``setup.py``: |
| 65 | + |
| 66 | +As before, a conda environment with all necessary dependencies is the suggested |
| 67 | +first step. |
| 68 | + |
| 69 | +.. code-block:: bash |
| 70 | +
|
| 71 | + # Create a conda environment that hass needed dependencies installed |
| 72 | + conda create -n numba-dpex-env \ |
| 73 | + scikit-build cmake dpctl dpnp numba dpcpp-llvm-spirv llvmdev pytest \ |
| 74 | + -c intel -c conda-forge |
| 75 | + # Activate the environment |
| 76 | + conda activate numba-dpex-env |
| 77 | + # Clone the numba-dpex repository |
| 78 | + git clone https://github.com/IntelPython/numba-dpex.git |
| 79 | + cd numba-dpex |
| 80 | + python setup.py develop |
| 81 | +
|
| 82 | +Building inside Docker |
| 83 | +---------------------- |
| 84 | + |
| 85 | +A Dockerfile is provided on the GitHub repository to build ``numba-dpex`` |
| 86 | +as well as its direct dependencies: ``dpctl`` and ``dpnp``. Users can either use |
| 87 | +one of the pre-built images on the ``numba-dpex`` GitHub page or use the |
| 88 | +bundled Dockerfile to build ``numba-dpex`` from source. Using the Dockerfile |
| 89 | +also ensures that all device drivers and runtime libraries are pre-installed. |
| 90 | + |
| 91 | +Building |
| 92 | +~~~~~~~~ |
| 93 | + |
| 94 | +Numba dpex ships with multistage Dockerfile, which means there are |
| 95 | +different `targets <https://docs.docker.com/build/building/multi-stage/#stop-at-a-specific-build-stage>`_ |
| 96 | +available for build. The most useful ones: |
| 97 | + |
| 98 | +- ``runtime`` |
| 99 | +- ``runtime-gpu`` |
| 100 | +- ``numba-dpex-builder-runtime`` |
| 101 | +- ``numba-dpex-builder-runtime-gpu`` |
| 102 | + |
| 103 | +To build docker image |
| 104 | + |
| 105 | +.. code-block:: bash |
| 106 | +
|
| 107 | + docker build --target runtime -t numba-dpex:runtime ./ |
| 108 | +
|
| 109 | +
|
| 110 | +To run docker image |
| 111 | + |
| 112 | +.. code-block:: bash |
| 113 | +
|
| 114 | + docker run -it --rm numba-dpex:runtime |
| 115 | +
|
| 116 | +.. note:: |
| 117 | + |
| 118 | + When trying to build a docker image with Intel GPU support, the Dockerfile |
| 119 | + will attempt to use the GitHub API to get the latest Intel GPU drivers. |
| 120 | + Users may run into an issue related to Github API call limits. The issue |
| 121 | + can be bypassed by providing valid GitHub credentials using the |
| 122 | + ``GITHUB_USER`` and ``GITHUB_PASSWORD`` |
| 123 | + `build args <https://docs.docker.com/engine/reference/commandline/build/#build-arg>`_ |
| 124 | + to increase the call limit. A GitHub |
| 125 | + `access token <https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token>`_ |
| 126 | + can also be used instead of the password. |
| 127 | + |
| 128 | +.. note:: |
| 129 | + |
| 130 | + When building the docker image behind a firewall the proxy server settings |
| 131 | + should be provided using the ``http_proxy`` and ``https_proxy`` build args. |
| 132 | + These build args must be specified in lowercase. |
| 133 | + |
| 134 | +The bundled Dockerfile supports different python versions that can be specified |
| 135 | +via the ``PYTHON_VERSION`` build arg. By default, the docker image is based on |
| 136 | +the official python image based on slim debian. The requested python version |
| 137 | +must be from the available python docker images. |
| 138 | + |
| 139 | +The ``BASE_IMAGE`` build arg can be used to build the docker image from a |
| 140 | +custom image. Note that as the Dockerfile is based on debian any custom base |
| 141 | +image should be debian-based, like debian or ubuntu. |
| 142 | + |
| 143 | +The list of other build args are as follows. Please refer the Dockerfile to |
| 144 | +see currently all available build args. |
| 145 | + |
| 146 | +- ``PYTHON_VERSION`` |
| 147 | +- ``CR_TAG`` |
| 148 | +- ``IGC_TAG`` |
| 149 | +- ``CM_TAG`` |
| 150 | +- ``L0_TAG`` |
| 151 | +- ``ONEAPI_VERSION`` |
| 152 | +- ``DPCTL_GIT_BRANCH`` |
| 153 | +- ``DPCTL_GIT_URL`` |
| 154 | +- ``DPNP_GIT_BRANCH`` |
| 155 | +- ``DPNP_GIT_URL`` |
| 156 | +- ``NUMBA_DPEX_GIT_BRANCH`` |
| 157 | +- ``NUMBA_DPEX_GIT_URL`` |
| 158 | +- ``CMAKE_VERSION`` |
| 159 | +- ``CMAKE_VERSION_BUILD`` |
| 160 | +- ``INTEL_NUMPY_VERSION`` |
| 161 | +- ``INTEL_NUMBA_VERSION`` |
| 162 | +- ``CYTHON_VERSION`` |
| 163 | +- ``SCIKIT_BUILD_VERSION`` |
| 164 | +- ``http_proxy`` |
| 165 | +- ``https_proxy`` |
| 166 | +- ``GITHUB_USER`` |
| 167 | +- ``GITHUB_PASSWORD`` |
| 168 | +- ``BASE_IMAGE`` |
| 169 | + |
| 170 | + |
| 171 | +Using the pre-built images |
| 172 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 173 | + |
| 174 | +There are several pre-built docker images available: |
| 175 | + |
| 176 | +- ``runtime`` package that provides a pre-built environment with ``numba-dpex`` |
| 177 | + already installed. It is ideal to quickly setup and try |
| 178 | + ``numba-dpex``. |
| 179 | + |
| 180 | +.. code-block:: text |
| 181 | +
|
| 182 | + ghcr.io/intelpython/numba-dpex/runtime:<numba_dpex_version>-py<python_version>[-gpu] |
| 183 | +
|
| 184 | +- ``builder`` package that has all required dependencies pre-installed and is |
| 185 | + ideal for building ``numba-dpex`` from source. |
| 186 | + |
| 187 | +.. code-block:: text |
| 188 | +
|
| 189 | + ghcr.io/intelpython/numba-dpex/builder:<numba_dpex_version>-py<python_version>[-gpu] |
| 190 | +
|
| 191 | +- ``stages`` package primarily meant for creating a new docker image that is |
| 192 | + built on top of one of the pre-built images. |
| 193 | + |
| 194 | +After setting up the docker image, to run ``numba-dpex`` the following snippet |
| 195 | +can be used. |
| 196 | + |
| 197 | +.. code-block:: bash |
| 198 | +
|
| 199 | + docker run --rm -it ghcr.io/intelpython/numba-dpex/runtime:0.20.0-py3.10 bash |
| 200 | +
|
| 201 | +It is advisable to verify the SYCL runtime and driver installation within the |
| 202 | +container by either running, |
| 203 | + |
| 204 | +.. code-block:: bash |
| 205 | +
|
| 206 | + sycl-ls |
| 207 | +
|
| 208 | +or, |
| 209 | + |
| 210 | +.. code-block:: bash |
| 211 | +
|
| 212 | + python -m dpctl -f |
| 213 | +
|
| 214 | +.. note:: |
| 215 | + |
| 216 | + To enable GPU device, the ``device`` argument should be used and one of the |
| 217 | + ``*-gpu`` images should be used. |
| 218 | + |
| 219 | + For passing GPU into container on linux use arguments ``--device=/dev/dri``. |
| 220 | + However if you are using WSL you need to pass |
| 221 | + ``--device=/dev/dxg -v /usr/lib/wsl:/usr/lib/wsl`` instead. |
| 222 | + |
| 223 | +For example, to run ``numba-dpex`` with GPU support on WSL: |
| 224 | + |
| 225 | +.. code-block:: bash |
| 226 | +
|
| 227 | + docker run --rm -it \ |
| 228 | + --device=/dev/dxg -v /usr/lib/wsl:/usr/lib/wsl \ |
| 229 | + ghcr.io/intelpython/numba-dpex/runtime:0.20.0-py3.10-gpu |
| 230 | +
|
| 231 | +
|
| 232 | +
|
| 233 | +Testing |
| 234 | +------- |
| 235 | + |
| 236 | +``numba-dpex`` uses pytest for unit testing and the following example |
| 237 | +shows a way to run the unit tests. |
| 238 | + |
| 239 | +.. code-block:: bash |
| 240 | +
|
| 241 | + python -m pytest --pyargs numba_dpex.tests |
| 242 | +
|
| 243 | +Examples |
| 244 | +-------- |
| 245 | + |
| 246 | +A set of examples on how to use ``numba-dpex`` can be found in |
| 247 | +``numba_dpex/examples``. |
0 commit comments