Matlab bindings for KeOps are currently available for KeOps versions up to 1.5 only. The following instructions allow you to install and use Matlab bindings for KeOps 1.5.
- A unix-like system (typically Linux or MacOs X) with a C++ compiler compatible with std=c++14 (e.g. gcc>=7 or clang>=8)
- Cmake>=3.10
- Matlab>=R2012
- Optional: Cuda (>=10.0 is recommended)
- Download and unzip the KeOps library at a location of your choice (denoted here by
/path/to
):
bash $
cd /path/to wget https://github.com/getkeops/keops/archive/refs/tags/v1.5.zip unzip v1.5.zip mv keops-1.5 keops
Note that temporary files will be written into the /path/to/keops/keopslab/build
folder: this directory must have write permissions.
- Manually add the directory
/path/to/keops/keopslab
to your Matlab path, as documentedbelow <part.path>
. Test your installation <part.test>
.
- Clone the KeOps repository at a location of your choice (denoted here by
/path/to
):
bash $
git clone https://github.com/getkeops/keops.git /path/to/keops
Note that temporary files will be written into the /path/to/keops/keopslab/build
folder: this directory must have write permissions.
- Manually add the directory
/path/to/keops/keopslab
to your Matlab path: seepart.path
Test your installation <part.test>
.
There are two ways to tell Matlab that KeOpsLab is now available in /path/to/keops/keopslab
:
- You can add this folder to your Matlab path once and for all: in the Matlab prompt, type
addpath(genpath('/path/to/keops/keopslab'))
savepath
- Otherwise, please add the following line to the beginning of your scripts:
addpath(genpath('/path/to/keops/keopslab'))
part.path
and execute the following piece of code in a Matlab terminal:
x = reshape(1:9,3,[]); y = reshape(3:8,3,[]);
my_conv = keops_kernel('Sum_Reduction(SqNorm2(x-y),1)','x=Vi(0,3)','y=Vj(1,3)');
my_conv(x,y)'
It should return:
ans =
63
90
For debugging purposes, you can force a "verbose" compilation mode by setting
verbosity=1
in the file /path/to/keops/keopslab/default_options.m
.
When using KeOps with Cuda version 8 or earlier, the compilation of complex formulas may take a very long time (several minutes). This typically happens when computing the derivative or second-order derivatives of a non-trivial function, as in the testShooting.m
example script.
This delay is mainly due to the intensive use of modern C++11 templating features, for which the old (<=8) versions of the Cuda nvcc
compiler were not optimized. Consequently, if you own a GPU with a compute capability >=3.0, we strongly recommend upgrading to Cuda>=9.
If an error involving cmake
appears, it may be due to an incorrect linking of libstdc++
. Try the following: exit Matlab, then type in a terminal
bash $
export LD_PRELOAD=$(ldd $( which cmake ) | grep libstdc++ | tr ' ' 'n' | grep /) matlab
This will reload Matlab with, hopefully, a correct linking for cmake
.