GSoC ChainerX: CPU bindings

Linear algebra routines from this issue are now working both on CPU and GPU. When it comes to the choice of linear algebra library on CPU, the variety is much broader than on GPU. However, we don’t need a full featured linear algebra matrix library like Eigen, or Armadillo, as ChainerX has its own ndarray. Therefore, it was decided to use one of the LAPACK implementations. For now it seems that working with LAPACK (which is written in Fortran) directly without C wrappers is the way to go. There is a C interface to LAPACK called LAPACKE. Unline CBLAS (C interface to BLAS, which is already used in ChainerX), LAPACKE seems not to offer any advantages of using it (pages 7-8).

We can access the LAPACK dpotrf (double precision Cholesky decomposition) subroutine …


subroutine dpotrf(character UPLO,
integer N,
double precision, dimension( lda, * ) A,
integer LDA,
integer INFO
)

… as the external C function dpotrf_

extern "C" void dpotrf_(char* uplo, int* n, double* a, int* lda, int* info);

and any other LAPACK routine is made accessible within C++ in the same way.

Travis CI environment was easily adapted to support LAPACK routines unit tests with one additional step in chainer/scripts/ci/travis/steps.sh

step_before_install_chainerx_test_deps() {
    if [[ $TRAVIS_OS_NAME = "linux" ]]; then
        sudo apt-get install -y libblas-dev liblapack-dev
    fi
}

LAPACK needs to be installed only for Linux, OSX has LAPACK available natively with Accelerate framework. Currently Windows is not tested.

Now I’m flying to Tokyo and will meet my mentor in person. I’m going to spend next three weeks in Japan mixing sightseeing with coding.