Skip to content

README_linalg_refactor

Pan Deng / Zora edited this page Aug 9, 2016 · 13 revisions

Motivation

Linear algebra operations form the backbone for most of the computation components in any Machine Learning library. However, writing all of the required linear algebra operations from scratch is rather redundant and undesired, especially when we have some excellent open source alternatives. In Shogun, we prefer

  • Eigen3 for its speed and simplicity at the usage level,
  • ViennaCL version 1.5 for GPU powered linear algebra operations, and

For Shogun maintainers, however, the usage of different external libraries for different operations can lead to a painful task.

  • For example, consider some part of an algorithm originally written using Eigen3 API. But a Shogun user wishes to use ViennaCL for that algorithm instead, hoping to obtain boosted performance utilizing a GPU powered platform. There is no way of doing that without having the algorithm rewritten by the developers using ViennaCL, which leads to duplication of code and effort.
  • Also, there is no way to do a performance comparison for the developers while using different external linear algebra libraries for the same algorithm in Shogun code.
  • It is also somewhat frustrating for a new developer who has to invest significant amount of time and effort to learn each of these external APIs just to add a new algorithm in Shogun.

Features of internal linear algebra library

Shogun's internal linear algebra library (will be referred as linalg hereinafter) is a work-in-progress attempt to overcome these issues. We designed linalg as a modularized internal header only library in order to

  • provide a uniform API for Shogun developers to choose any supported backend without having to worry about the syntactical differences in the external libraries' operations,
  • have the backend set for each operations at compile-time (for lesser runtime overhead) and therefore intended to be used internally by Shogun developers,
  • allow Shogun developers to add new linear algebra backend plug-ins easily.

For Shogun developers

Setting linalg backend

Users can switch between linalg backends via global variable sg_linalg.

  • Shogun uses Eigen3 backend as default linear algebra backend.

  • ViennaCL(GPU) backend can be enabled by assigning new ViennaCL backend class to sg_linalg

    sg_linalg->set_gpu_backend(new LinalgBackendViennaCL());

    or canceled

    sg_linalg->set_gpu_backend(nullptr);

    Enabling of GPU backend allows the data transfer between CPU and GPU, as well as the operations on GPU.

Though backends can be extended, only one CPU backend and one GPU backend are allowed to be registered each time.

Welcome to the Shogun wiki!

Clone this wiki locally