Skip to content

Commit e56b1ac

Browse files
authored
PyCUDA and PyOpenCL backends for ASSET joint prob. matrix calculation (#404)
* accelerated pmat_neighbors function * cluster_matrix_entries with chunking
1 parent 68b3243 commit e56b1ac

File tree

17 files changed

+1594
-251
lines changed

17 files changed

+1594
-251
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ addons:
99

1010
matrix:
1111
include:
12-
- name: "pip 3.6 requirements-extras"
12+
- name: "conda 3.6 extras,opencl"
1313
python: 3.6
14-
env: DISTRIB="pip"
14+
env: DISTRIB="conda"
1515
before_install: sudo apt install -y libopenmpi-dev openmpi-bin
1616
before_script:
17+
- conda install -c conda-forge pyopencl oclgrind clang=9.0.1
1718
- pip install -r requirements/requirements-extras.txt
1819
- pip install mpi4py
1920
script: mpiexec -n 1 python -m mpi4py.futures -m nose --with-coverage --cover-package=elephant
@@ -56,7 +57,7 @@ install:
5657
sed -i '/mpi4py/d' requirements/environment.yml;
5758
conda env create -f requirements/environment.yml;
5859
conda activate elephant;
59-
pip list;
60+
conda list;
6061
else
6162
pip install -r requirements/requirements.txt;
6263
fi

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ include elephant/current_source_density_src/README.md
88
include elephant/current_source_density_src/test_data.mat
99
include elephant/spade_src/LICENSE
1010
recursive-include elephant/spade_src *.so *.pyd
11+
include elephant/asset/*
1112
include elephant/test/spike_extraction_test_data.txt
1213
recursive-include doc *
1314
prune doc/_build
1415
prune doc/tutorials/.ipynb_checkpoints
1516
prune doc/reference/toctree
1617
include doc/reference/toctree/kernels/*
1718
recursive-exclude * *.h5
19+
recursive-exclude * *.nix
1820
recursive-exclude * *~

doc/install.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,66 @@ For more information, refer to `mpi4py
148148
<https://mpi4py.readthedocs.io/en/stable/mpi4py.run.html>`_ documentation.
149149

150150

151+
CUDA and OpenCL support
152+
-----------------------
153+
154+
:ref:`asset` module supports CUDA and OpenCL. These are experimental features.
155+
You can have one, both, or none installed in your system.
156+
157+
.. tabs::
158+
159+
.. tab:: CUDA
160+
161+
To leverage CUDA acceleration on an NVIDIA GPU card, `CUDA toolkit
162+
<https://developer.nvidia.com/cuda-downloads>`_ must installed on
163+
your system. Then run the following command in a terminal:
164+
165+
.. code-block:: sh
166+
167+
pip install pycuda
168+
169+
In case you experience issues installing PyCUDA, `this guide
170+
<https://medium.com/leadkaro/setting-up-pycuda-on-ubuntu-18-04-for-
171+
gpu-programming-with-python-830e03fc4b81>`_ offers a step-by-step
172+
installation manual.
173+
174+
If PyCUDA is detected and installed, CUDA backend is used by default in
175+
Elephant ASSET module. To turn off CUDA support, set ``ELEPHANT_USE_CUDA``
176+
environment flag to ``0``.
177+
178+
179+
.. tab:: OpenCL
180+
181+
If you have a laptop with a built-in Intel Graphics Card, you can still
182+
leverage significant performance optimization with OpenCL backend.
183+
The simplest way to install PyOpenCL is to run a conda command:
184+
185+
.. code-block:: sh
186+
187+
conda install -c conda-forge pyopencl intel-compute-runtime
188+
189+
However, if you have root (sudo) privileges, it's recommended to install
190+
up-to-date `Intel Graphics Compute Runtime
191+
<https://github.com/intel/compute-runtime/releases>`_ system-wide and then
192+
install PyOpenCL as follows:
193+
194+
.. code-block:: sh
195+
196+
conda install -c conda-forge pyopencl ocl-icd-system
197+
198+
Set ``ELEPHANT_USE_OPENCL`` environment flag to ``0`` to turn off
199+
PyOpenCL support.
200+
201+
.. note::
202+
203+
Make sure you've disabled GPU Hangcheck as described in the
204+
`Intel GPU developers documentation <https://software.intel.com/
205+
content/www/us/en/develop/documentation/get-started-with-intel-
206+
oneapi-base-linux/top/before-you-begin.html>`_. Do it with caution -
207+
using your graphics card to perform computations may make the system
208+
unresponsive until the compute program terminates.
209+
210+
151211
Dependencies
152212
------------
153213

doc/reference/asset.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _asset:
2+
13
===================================================
24
Analysis of Sequences of Synchronous EvenTs (ASSET)
35
===================================================

doc/tutorials/asset.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
},
3636
"outputs": [],
3737
"source": [
38+
"import os\n",
3839
"import matplotlib.pyplot as plt\n",
3940
"import numpy as np\n",
4041
"import quantities as pq\n",
@@ -248,7 +249,7 @@
248249
"\n",
249250
"The third step is postprocessing of the analytical probability matrix `pmat`, obtained from the previous step. Centered at each (i,j) entry of `pmat` matrix, we apply a diagonal kernel with shape `filter_shape` and select the top `nr_largest` probabilities of (i,j) neighborhood (defined by `filter_shape`), and compute the significance of these `nr_largest` joint neighbor probabilities. The resultant `jmat` matrix is a \"dilated\" version of `imat`.\n",
250251
"\n",
251-
"This step is most time consuming."
252+
"This step is most time consuming. If you have PyCUDA or PyOpenCL installed, set `ELEPHANT_USE_CUDA` or `ELEPHANT_USE_OPENCL` environment flag to `1`."
252253
]
253254
},
254255
{
@@ -270,7 +271,8 @@
270271
}
271272
],
272273
"source": [
273-
"# hint: try different filter_shapes, e.g. filter_shape=(7,3)\n",
274+
"os.environ['ELEPHANT_USE_OPENCL'] = '0'\n",
275+
"# try different filter_shapes, e.g. filter_shape=(7,3)\n",
274276
"jmat = asset_obj.joint_probability_matrix(pmat, filter_shape=(11, 3), n_largest=3)"
275277
]
276278
},

0 commit comments

Comments
 (0)