Skip to content

Commit 6c826bc

Browse files
committed
Merge branch 'main' into compiled-hdsort
2 parents 957d298 + f81bcc3 commit 6c826bc

44 files changed

Lines changed: 831 additions & 12 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Force batch scripts to always use CRLF line endings so that if a repo is accessed
5+
# in Windows via a file share from Linux, the scripts will work.
6+
*.{cmd,[cC][mM][dD]} text eol=crlf
7+
*.{bat,[bB][aA][tT]} text eol=crlf
8+
9+
# Force bash scripts to always use LF line endings so that if a repo is accessed
10+
# in Unix via a file share from Windows, the scripts will work.
11+
*.sh text eol=lf

ironclust-compiled/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22

3-
docker build -t spikeinterface/ironclust-compiled-base:5.9.8 .
3+
docker build -t spikeinterface/ironclust-compiled-base:latest -t spikeinterface/ironclust-compiled-base:5.9.8 .
44

ironclust-compiled/push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22

3-
docker push spikeinterface/ironclust-compiled-base:5.9.8
3+
docker push --all-tags spikeinterface/ironclust-compiled-base
44

kilosort_no_license/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Kilosort Compiled Docker Images
2+
3+
This documentation is intended to show how to create a Docker image with Matlab compiled implementation of Kilosort sorter. The main goal of this project is to avoid the requirement of Matlab Licenses and also abstract the installation and setup steps to run kilosort
4+
5+
## Requirements
6+
- Packaging a MATLAB Docker image is supported on Linux only
7+
- Docker
8+
- Matlab
9+
- NVIDIA GPU and CUDA capabilities
10+
11+
### Matlab Requirements
12+
- MATLAB Compiler
13+
- Parallel Computing Toolbox
14+
- Signal Processing Toolbox
15+
- Statistics and Machine Learning Toolbox
16+
17+
## Creating Docker Image
18+
19+
There are four main steps to generate a functional kilosort-compiled docker image:
20+
21+
1. Kilosort Setup
22+
2. Compile Kilosort as Standalone Application
23+
3. Create a (base) docker image with Matlab Runtime and the compiled application from step 2
24+
4. Extend the docker image from step 3 for improvements and fixes
25+
26+
Detailed descriptions for each step are documented in `README.md` for each supported kilosort version folder (`kilosort-compiled`, `kilosort2-compiled` and so on)
27+
28+
Licenses for Matlab and toolboxes are needed only for compiling kilosort as Standalone Application and to generate the base Docker image. After this process, no license will be required, either to extend the base image or to run the sorter.
29+
30+
## Running a container
31+
32+
After generating kilosort-compiled image, [nvidia-container-toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#setting-up-nvidia-container-toolkit) is required to run a docker with GPU capabilities
33+
34+
The base syntax to run dockerized kilosort is:
35+
36+
```bash
37+
docker run -v <host-data-folder>:<docker-data-folder> <image>:<tag> <ks_command> [ARGS]
38+
```
39+
- A volume has to be binded to a folder were all the data to run kilosort are stored
40+
- `<image>`: Image name given by `build.sh` script
41+
- `<tag>`: Image Tag given by `build.sh` script
42+
- `<ks_command>`: Depends on kilosort version, options are `ks_compiled`, `ks2_compiled`, `ks2_5_compiled` or `ks3_compiled`
43+
- `[ARGS]`: Currently the only ARG option is the folder where the data are stored (\<docker-data-folder\>)
44+
45+
This kilosort compiled version assumes that there are also two `.mat` files in this data folder:
46+
1. `ops.mat`: Configurations (options) data
47+
2. `chanMap.mat`: ChannelMap data
48+
49+
Both files are automatically generated by spikeinterface when running `run\_sorter`. If you want to run compiled kilosort independently you need to generate them manually (HOW TO still needs to be done)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM ks-matlab-base
2+
3+
RUN chmod 755 /usr/bin/mlrtapp/ks_compiled
4+
ENV PATH="/usr/bin/mlrtapp:${PATH}"
5+
6+
RUN apt-get update -y
7+
RUN apt-get install software-properties-common -y
8+
RUN add-apt-repository ppa:deadsnakes/ppa -y
9+
RUN apt-get install git python3.8 python3.8-dev -y
10+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
11+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
12+
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 10
13+
RUN apt-get install python3-pip -y
14+
RUN update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
15+
RUN pip install -U pip
16+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Generating Compiled Kilosort Docker Image
2+
3+
## 1. Kilosort Setup
4+
- Git clone or Download Kilosort [source code](https://github.com/cortex-lab/KiloSort)
5+
- Open Matlab
6+
- Compile Kilosort mexfiles:
7+
- Set Matlab's workspace folder to `<git-cloned-path>/KiloSort/CUDA`
8+
- In Matlab console run:
9+
```matlab
10+
>> mexGPUall
11+
```
12+
13+
## 2. Compiling Kilosort as Matlab's Standalone Application
14+
- Set Matlab's workspace folder to `/path/to/spikeinterface-dockerfiles/kilosort_no_license`
15+
- Run `mcc` command with `utils` folder and kilosort path:
16+
```matlab
17+
>> mcc -m kilosort-compiled/ks_compiled.m -a utils -a <git-cloned-path>/KiloSort
18+
```
19+
20+
## 3. Generating Base Docker Image
21+
- To generate the base docker image (called `ks-matlab-base`) with the compiled application, run the following command in Matlab console:
22+
```matlab
23+
>> compiler.package.docker('ks_compiled', 'requiredMCRProducts.txt', 'ImageName', 'ks-matlab-base')
24+
```
25+
26+
- [Optional] Files generated by Matlab Compiler can be deleted:
27+
- In your terminal, go to the `kilosort_no_license` folder in this project:
28+
```bash
29+
$ cd /path/to/spikeinterface-dockerfiles/kilosort_no_license
30+
```
31+
- Run `rm` command:
32+
```bash
33+
$ rm -r \
34+
includedSupportPackages.txt \
35+
ks-matlab-basedocker/ \
36+
ks_compiled \
37+
mccExcludedFiles.log \
38+
readme.txt \
39+
requiredMCRProducts.txt \
40+
run_ks_compiled.sh \
41+
unresolvedSymbols.txt
42+
```
43+
44+
## 4. Extending Base Image and creating final image
45+
46+
The Dockerfile in this folder applies some fixes and updates to the base image generated automatically by Matlab in order to properly run kilosort:
47+
48+
- In your terminal, go to the folder for this project:
49+
```bash
50+
$ cd /path/to/spikeinterface-dockerfiles/kilosort_no_license/kilosort-compiled
51+
```
52+
53+
- Run build script:
54+
```bash
55+
$ source build.sh
56+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
docker build -t spikeinterface/kilosort-compiled-base:latest -t spikeinterface/kilosort-compiled-base:0.1.0 .
4+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function ks_master(fpath)
2+
try
3+
set(groot,'defaultFigureVisible', 'off');
4+
5+
% Load channel map file
6+
load(fullfile(fpath, 'chanMap.mat'));
7+
8+
% Load the configuration file, it builds the structure of options (ops)
9+
load(fullfile(fpath, 'ops.mat'));
10+
11+
useGPU = ops.GPU;
12+
13+
% load predefined principal components (visualization only (Phy): used for features)
14+
dd = load('PCspikes2.mat'); % you might want to recompute this from your own data
15+
ops.wPCA = dd.Wi(:,1:7); % PCs
16+
17+
% This part runs the normal Kilosort processing on the simulated data
18+
[rez, DATA, uproj] = preprocessData(ops); % preprocess data and extract spikes for initialization
19+
rez = fitTemplates(rez, DATA, uproj); % fit templates iteratively
20+
rez = fullMPMU(rez, DATA);% extract final spike times (overlapping extraction)
21+
22+
% save python results file for Phy
23+
rezToPhy(rez, fullfile(fpath));
24+
catch
25+
fprintf('----------------------------------------');
26+
fprintf(lasterr());
27+
quit(1);
28+
end
29+
quit(0);
30+
end
31+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
docker push --all-tags spikeinterface/kilosort-compiled-base
4+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM ks2-matlab-base
2+
3+
RUN chmod 755 /usr/bin/mlrtapp/ks2_compiled
4+
ENV PATH="/usr/bin/mlrtapp:${PATH}"
5+
6+
RUN apt-get update -y
7+
RUN apt-get install software-properties-common -y
8+
RUN add-apt-repository ppa:deadsnakes/ppa -y
9+
RUN apt-get install git python3.8 python3.8-dev -y
10+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
11+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
12+
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 10
13+
RUN apt-get install python3-pip -y
14+
RUN update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
15+
RUN pip install -U pip
16+

0 commit comments

Comments
 (0)