Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container for Full Binary Pursuit #69

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions full-binary-pursuit/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
FROM nvidia/cuda:11.7.1-base-ubuntu22.04

LABEL maintainer="Vincent Prevosto <[email protected]>"

# USER root
# Ubuntu package installs
RUN apt update && \
apt install -y --no-install-recommends \
build-essential \
libaio1 \
opencl-headers \
ocl-icd-libopencl1 \
# nvidia-opencl-icd \ this is a virtual package - do not install. Instead install the actual package that matches your host's driver version
libnvidia-compute-535 \
clinfo \
git \
wget && \
apt clean && \
rm -rf /var/lib/apt/lists/*

# install miniconda
ENV MINICONDA_VERSION 23.3.1-0
ENV PY_VERSION py39
ENV CONDA_DIR /home/miniconda3
ENV LATEST_CONDA_SCRIPT "Miniconda3-${PY_VERSION}_${MINICONDA_VERSION}-Linux-x86_64.sh"

RUN wget --quiet https://repo.anaconda.com/miniconda/$LATEST_CONDA_SCRIPT -O ~/miniconda.sh && \
bash ~/miniconda.sh -b -p $CONDA_DIR && \
rm ~/miniconda.sh
ENV PATH=$CONDA_DIR/bin:$PATH
ENV PYTHONPATH=$CONDA_DIR/bin:$CONDA_DIR/lib/python3.9/site-packages
RUN conda update conda && \
conda install conda-build && \
conda install conda-forge::ocl-icd-system
# See pyopencl docs:
# https://documen.tician.de/pyopencl/misc.html#using-vendor-supplied-opencl-drivers-mainly-on-linux

# make conda activate command available from /bin/bash --login shells
RUN echo ". $CONDA_DIR/etc/profile.d/conda.sh" >> /root/.profile
# make conda activate command available from /bin/bash --interactive shells
RUN conda init bash

# Install IBL python port of pykilosort
RUN git clone https://github.com/njh27/spikesorting_fullpursuit.git /src/fullpursuit
WORKDIR /src/fullpursuit

# Install conda environment
SHELL ["conda","run","-n","base","/bin/bash","-c"]
RUN conda install -c intel mkl mkl-service
RUN conda install -c defaults numpy matplotlib
RUN conda install -c conda-forge pyopencl scipy scikit-learn
RUN pip install Cython

# Install full binary pursuit
RUN conda install --quiet --yes -c defaults ipykernel && \
python -m ipykernel install --user --display-name "fullpursuit" && \
pip install -e .

WORKDIR /
58 changes: 58 additions & 0 deletions full-binary-pursuit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
### Run container
docker run --rm -it -v <host-data-folder>:<docker-data-folder> --gpus all fullpursuit:latest
flags:
--rm: removes container once it's stopped
-it: for interactive session (-d for detached)
-v: mounted volumes (directories)
--gpus: enables GPU use within container

### Build this image
Build default image:
docker build -t fullpursuit-base:latest .

Note: Full binary pursuit relies on opencl. Installation varies by OS and CPU / GPU type.
For Intel CPUs, see https://www.intel.com/content/www/us/en/developer/articles/tool/opencl-drivers.html.
For configuration on Ubuntu and Docker, see also https://linuxhandbook.com/setup-opencl-linux-docker/. On Ubuntu, you may need to add your user to the `video` and `render` groups to access the GPU.
```
sudo gpasswd -a $USER render
sudo gpasswd -a $USER video
```
Then log out and back in to apply the changes: `su - $USER`

Check fullpursuit version:
docker run --rm -it spikeinterface/fullpursuit-base:latest bash -c "python -c 'import spikesorting_fullpursuit; print(spikesorting_fullpursuit.__version__)'"

Check that pyopencl can detect your graphics card:
docker run --rm -it --gpus all spikeinterface/fullpursuit-base:latest bash -c "python -c 'import pyopencl as cl; platforms = cl.get_platforms(); print(platforms[0].get_devices(cl.device_type.GPU))'"

### Test
Adapted from the readme file's instructions.

First make the voltage data and save ground truth (mounting the host data folder to the docker data folder):
```bash
docker run --rm -it -v <host-data-folder>:<docker-data-folder> --gpus all spikeinterface/fullpursuit-base:latest bash -c "python /src/fullpursuit/demos/make_and_save_voltage.py <docker-data-folder>/test_voltage.npy <docker-data-folder>/test_ground_truth.pickle"
```
e.g.:
Create the data folder: `mkdir -p /home/$USER/data/fullpursuit_data`
Then create the groundtruth data: `docker run --rm -it -v /home/$USER/data/fullpursuit_data:/data --gpus all spikeinterface/fullpursuit-base:latest bash -c "python /src/fullpursuit/demos/make_and_save_voltage.py /data/test_voltage.npy /data/test_ground_truth.pickle"`

Then run the sorting algorithm on the generated synthetic data:
```bash
docker run --rm -it -v <host-data-folder>:<docker-data-folder> --gpus all spikeinterface/fullpursuit-base:latest bash -c "python /src/fullpursuit/demos/test_demo_run_sort.py <docker-data-folder>/test_voltage.npy <docker-data-folder>/sorted_demo.pickle"
```
e.g.:
`docker run --rm -it -v /home/$USER/data/fullpursuit_data:/data --gpus all spikeinterface/fullpursuit-base:latest bash -c "python /src/fullpursuit/demos/test_demo_run_sort.py /data/test_voltage.npy /data/sorted_demo.pickle"`

Run automated postprocessing to place sorter output into a dictionary sorted neurons:
```bash
docker run --rm -it -v <host-data-folder>:<docker-data-folder> --gpus all spikeinterface/fullpursuit-base:latest bash -c "python /src/fullpursuit/demos/test_demo_postprocessing.py <docker-data-folder>/sorted_demo.pickle <docker-data-folder>/sorted_neurons.pickle"
```
e.g.:
`docker run --rm -it -v /home/$USER/data/fullpursuit_data:/data --gpus all spikeinterface/fullpursuit-base:latest bash -c "python /src/fullpursuit/demos/test_demo_postprocessing.py /data/sorted_demo.pickle /data/sorted_neurons.pickle"`

Finally run a quick script that compares sorted results to the ground truth generated data and make a couple figures:
```bash
docker run --rm -it -v <host-data-folder>:<docker-data-folder> --gpus all spikeinterface/fullpursuit-base:latest bash -c "python /src/fullpursuit/demos/test_demo_results.py <docker-data-folder>/sorted_neurons.pickle <docker-data-folder>/test_ground_truth.pickle"
```
e.g.:
`docker run --rm -it -v /home/$USER/data/fullpursuit_data:/data --gpus all spikeinterface/fullpursuit-base:latest bash -c "python /src/fullpursuit/demos/test_demo_results.py /data/sorted_neurons.pickle /data/test_ground_truth.pickle"`
6 changes: 6 additions & 0 deletions full-binary-pursuit/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

docker build -t spikeinterface/fullpursuit-base:latest -t spikeinterface/fullpursuit-base:1.1.0_cuda-11.7.1 .

# version info
# 01/31/2024 - FBP 1.1.0 CUDA 11.7.1 Ubuntu 22.04
3 changes: 3 additions & 0 deletions full-binary-pursuit/push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker push --all-tags spikeinterface/fullpursuit-base
Loading