Skip to content

Commit 02013f8

Browse files
add separate dev env instructions
1 parent 18c47ea commit 02013f8

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

doc/source/dev-environment.rst

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
.. toctree::
2+
:maxdepth: 2
3+
4+
.. role:: bash(code)
5+
:language: bash
6+
7+
.. _dev-environment:
8+
9+
Development environment
10+
=======================
11+
12+
The following steps help you set up a full development environment. **These steps are only needed for core developers of Kernel Tuner who need to test against multiple Python versions
13+
or change dependencies of Kernel Tuner.**
14+
15+
For small changes to the code, please see the simplified instructions in the :ref:`simple-dev-env`.
16+
17+
Local setup
18+
^^^^^^^^^^^
19+
Steps with :bash:`sudo` access (e.g. on a local device):
20+
21+
#. Clone the git repository to the desired location: :bash:`git clone https://github.com/KernelTuner/kernel_tuner.git`, and :bash:`cd` to it.
22+
#. Prepare your system for building Python versions.
23+
* On Ubuntu, run :bash:`sudo apt update && sudo apt upgrade`, and :bash:`sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git`.
24+
#. Install `pyenv <https://github.com/pyenv/pyenv#installation>`__:
25+
* On Linux, run :bash:`curl https://pyenv.run | bash` (remember to add the output to :bash:`.bash_profile` and :bash:`.bashrc` as specified).
26+
* On macOS, run :bash:`brew update && brew install pyenv`.
27+
* After installation, restart your shell.
28+
#. Install the required Python versions:
29+
* On some systems, additional packages may be needed to build Python versions. For example on Ubuntu: :bash:`sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev liblzma-dev lzma`.
30+
* Install the Python versions with: :bash:`pyenv install 3.8 3.9 3.10 3.11`. The reason we're installing all these versions as opposed to just one, is so we can test against all supported Python versions.
31+
#. Set the Python versions so they can be found: :bash:`pyenv local 3.8 3.9 3.10 3.11` (replace :bash:`local` with :bash:`global` when not using the virtualenv).
32+
#. Setup a local virtual environment in the folder: :bash:`pyenv virtualenv 3.11 kerneltuner` (or whatever environment name and Python version you prefer).
33+
#. `Install Poetry <https://python-poetry.org/docs/#installing-with-the-official-installer>`__.
34+
* Use :bash:`curl -sSL https://install.python-poetry.org | python3 -` to install Poetry.
35+
* Make sure to add Poetry to :bash:`PATH` as instructed at the end of the installation.
36+
* Add the poetry export plugin with :bash:`poetry self add poetry-plugin-export`.
37+
#. Make sure that non-Python dependencies are installed if applicable, such as CUDA, OpenCL or HIP. This is described in :ref:`Installation <installation>`.
38+
#. Apply changes:
39+
* Re-open the shell for changes to take effect.
40+
* Activate the environment with :bash:`pyenv activate kerneltuner`.
41+
* Make sure :bash:`which python` and :bash:`which pip` point to the expected Python location and version.
42+
* Update Pip with :bash:`pip install --upgrade pip`.
43+
#. Install the project, dependencies and extras: :bash:`poetry install --with test,docs -E cuda -E opencl -E hip`, leaving out :bash:`-E cuda`, :bash:`-E opencl` or :bash:`-E hip` if this does not apply on your system. To go all-out, use :bash:`--all-extras`
44+
* Depending on the environment, it may be necessary or convenient to install extra packages such as :bash:`cupy-cuda11x` / :bash:`cupy-cuda12x`, and :bash:`cuda-python`. These are currently not defined as dependencies for kernel-tuner, but can be part of tests.
45+
* Do not forget to make sure the paths are set correctly. If you're using CUDA, the desired CUDA version should be in :bash:`$PATH`, :bash:`$LD_LIBARY_PATH` and :bash:`$CPATH`.
46+
* Re-open the shell for changes to take effect.
47+
#. Check if the environment is setup correctly by running :bash:`pytest` and :bash:`nox`. All tests should pass, except if one or more extras has been left out in the previous step, then these tests will skip gracefully.
48+
* [Note]: sometimes, changing the NVIDIA driver privileges is required to read program counters and energy measurements. Check if :bash:`cat /proc/driver/nvidia/params | grep RmProfilingAdminOnly` is set to 1. If so, `follow these steps <https://developer.nvidia.com/nvidia-development-tools-solutions-err_nvgpuctrperm-permission-issue-performance-counters>`__
49+
50+
51+
Cluster setup
52+
^^^^^^^^^^^^^
53+
Steps without :bash:`sudo` access (e.g. on a cluster):
54+
55+
#. Clone the git repository to the desired location: :bash:`git clone https://github.com/KernelTuner/kernel_tuner.git`.
56+
#. Install Conda with `Mamba <https://mamba.readthedocs.io/en/latest/mamba-installation.html>`__ (for better performance) or `Miniconda <https://docs.conda.io/projects/conda/en/latest/user-guide/install>`__ (for traditional minimal Conda).
57+
* [Optional] if you are under quotas or are otherwise restricted by disk space, you can instruct Conda to use a different directory for saving environments by adding the following to your :bash:`.condarc` file:
58+
.. code-block:: bash
59+
60+
envs_dirs:
61+
- /path/to/directory
62+
* [Optional] both Mamba and Miniconda can be automatically activated via :bash:`~/.bashrc`. Do not forget to add these (usually provided at the end of the installation).
63+
* Exit the shell and re-enter to make sure Conda is available. :bash:`cd` to the kernel tuner directory.
64+
* [Optional] if you have limited user folder space, the Pip cache can be pointed elsewhere with the environment variable :bash:`PIP_CACHE_DIR`. The cache location can be checked with :bash:`pip cache dir`. On Linux, to point the entire :bash:`~/.cache` default elsewhere, use the :bash:`XDG_CACHE_HOME` environment variable.
65+
* [Optional] update Conda if available before continuing: :bash:`conda update -n base -c conda-forge conda`.
66+
#. Setup a virtual environment: :bash:`conda create --name kerneltuner python=3.11` (or whatever Python version and environment name you prefer).
67+
#. Activate the virtual environment: :bash:`conda activate kerneltuner`.
68+
* [Optional] to use the correct environment by default, execute :bash:`conda config --set auto_activate_base false`, and add `conda activate kerneltuner` to your :bash:`.bash_profile` or :bash:`.bashrc`.
69+
#. Make sure that non-Python dependencies are loaded if applicable, such as CUDA, OpenCL or HIP. On most clusters it is possible to load (or unload) modules (e.g. CUDA, OpenCL / ROCM). For more information, see :ref:`Installation <installation>`.
70+
* Do not forget to make sure the paths are set correctly. If you're using CUDA, the desired CUDA version should be in :bash:`$PATH`, :bash:`$LD_LIBARY_PATH` and :bash:`$CPATH`.
71+
* [Optional] the loading of modules and setting of paths is likely convenient to put in your :bash:`.bash_profile` or :bash:`.bashrc`.
72+
#. `Install Poetry <https://python-poetry.org/docs/#installing-with-the-official-installer>`__.
73+
* Use :bash:`curl -sSL https://install.python-poetry.org | python3 -` to install Poetry.
74+
* Add the poetry export plugin with :bash:`poetry self add poetry-plugin-export`.
75+
#. Install the project, dependencies and extras: :bash:`poetry install --with test,docs -E cuda -E opencl -E hip`, leaving out :bash:`-E cuda`, :bash:`-E opencl` or :bash:`-E hip` if this does not apply on your system. To go all-out, use :bash:`--all-extras`.
76+
* If you run into "keyring" or other seemingly weird issues, this is a known issue with Poetry on some systems. Do: :bash:`pip install keyring`, :bash:`python3 -m keyring --disable`.
77+
* Depending on the environment, it may be necessary or convenient to install extra packages such as :bash:`cupy-cuda11x` / :bash:`cupy-cuda12x`, and :bash:`cuda-python`. These are currently not defined as dependencies for kernel-tuner, but can be part of tests.
78+
* Verify that your development environment has no missing installs or updates with :bash:`poetry install --sync --dry-run --with test`.
79+
#. Check if the environment is setup correctly by running :bash:`pytest`. All tests should pass, except if you're not on a GPU node, or one or more extras has been left out in the previous step, then these tests will skip gracefully.
80+
#. Set Nox to use the correct backend and location:
81+
* Run :bash:`conda -- create-settings-file` to automatically create a settings file.
82+
* In this settings file :bash:`noxsettings.toml`, change the :bash:`venvbackend`:
83+
* If you used Mamba in step 2, to :bash:`mamba`.
84+
* If you used Miniconda or Anaconda in step 2, to :bash:`conda`.
85+
* If you used Venv in step 2, to :bash:`venv`.
86+
* If you used Virtualenv in step 2, this is already the default.
87+
* Be sure to adjust this when changing backends.
88+
* The settings file also has :bash:`envdir`, which allows you to `change the directory Nox caches environments in <https://nox.thea.codes/en/stable/usage.html#opt-envdir>`_, particularly helpful if you have a diskquota on your user directory.
89+
#. [Optional] Run the tests on Nox as described below.
90+
91+
92+
Running tests
93+
^^^^^^^^^^^^^
94+
To run the tests you can use :bash:`nox` (to run against all supported Python versions in isolated environments) and :bash:`pytest` (to run against the local Python version, see below) in the top-level directory.
95+
For full coverage, make Nox use the additional tests (such as cupy and cuda-python) with :bash:`nox -- additional-tests`.
96+
97+
The Nox isolated environments can take up to 1 gigabyte in size, so users tight on diskspace can run :bash:`nox` with the :bash:`small-disk` option. This removes the other environment caches before each session is ran (note that this will take longer to run). A better option would be to change the location environments are stored in with :bash:`envdir` in the :bash:`noxsettings.toml` file.
98+
99+
Please note that the command-line options can be combined, e.g. :bash:`nox -- additional-tests skip-hip small-disk`.
100+
If you do not have fully compatible hardware or environment, you can use the following options:
101+
102+
* :bash:`nox -- skip-cuda` to skip tests involving CUDA.
103+
* :bash:`nox -- skip-hip` to skip tests involving HIP.
104+
* :bash:`nox -- skip-opencl` to skip tests involving OpenCL.
105+
* :bash:`nox -- skip-gpu` to skip all tests on the GPU (the same as :bash:`nox -- skip-cuda skip-hip skip-opencl`), especially helpful if you don't have a GPU locally.
106+
107+
Contributions you make to the Kernel Tuner should not break any of the tests even if you cannot run them locally!
108+
109+
Running with :bash:`pytest` will test against your local Python version and PIP packages.
110+
In this case, tests that require PyCuda and/or a CUDA capable GPU will be skipped automatically if these are not installed/present.
111+
The same holds for tests that require PyOpenCL, Cupy, and CUDA.
112+
It is also possible to invoke PyTest from the 'Testing' tab in Visual Studio Code to visualize the testing in your IDE.
113+
114+
The examples can be seen as *integration tests* for the Kernel Tuner.
115+
Note that these will also use the installed package.
116+
117+
Building documentation
118+
^^^^^^^^^^^^^^^^^^^^^^
119+
Documentation is located in the ``doc/`` directory. This is where you can type
120+
``make html`` to generate the html pages in the ``doc/build/html`` directory.
121+
The source files used for building the documentation are located in
122+
``doc/source``.
123+
To locally inspect the documentation before committing you can browse through
124+
the documentation pages generated locally in ``doc/build/html``.
125+
126+
To make sure you have all the dependencies required to build the documentation, at least those in ``--with docs``.
127+
Pandoc is also required, you can install pandoc on Ubuntu using ``sudo apt install pandoc`` and on Mac using ``brew install pandoc``.
128+
For different setups please see `pandoc's install documentation <https://pandoc.org/installing.html>`__.
129+
130+
The documentation pages hosted online are built automatically using GitHub actions.
131+
The documentation pages corresponding to the master branch are hosted in /latest/.
132+
The documentation of the last release is in /stable/. When a new release
133+
is published the documentation for that release will be stored in a directory
134+
created for that release and /stable/ will be updated to point to the last
135+
release. This process is again fully automated using GitHub actions.

0 commit comments

Comments
 (0)