-
Notifications
You must be signed in to change notification settings - Fork 0
README_linalg_refactor
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
-
Eigen3for its speed and simplicity at the usage level, -
ViennaCLversion 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
Eigen3API. But a Shogun user wishes to useViennaCLfor 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 usingViennaCL, 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.
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.
Users can switch between linalg backends via global variable sg_linalg.
- Shogun uses
Eigen3backend as default linear algebra backend. - Enabling of GPU backend allows the data transfer between CPU and GPU, as well as the operations on GPU.
ViennaCL(GPU) backend can be enabled by assigning newViennaCLbackend class tosg_linalgor canceled by:
sg_linalg->set_gpu_backend(new LinalgBackendViennaCL());
sg_linalg->set_gpu_backend(nullptr);
- Though backends can be extended, only one CPU backend and one GPU backend are allowed to be registered each time.
linalg library works for both SGVectors and SGMatrices. The operations can be called by:
#include <shogun/mathematics/linalg/LinalgNamespace.h>
shogun::linalg::operation(args)`
-
To use
linalgoperations on GPU data (vectors or matrices) and transfer data between GPU, one can callto_gpuandfrom_gpumethods. The methods return results as new instances.auto result = linalg::to_gpu(arg) auto result = linalg::from_gpu(arg_on_gpu) -
The
to_gpumethod will return the original CPU vector or matrix if no GPU backend is available. Thefrom_gpumethod will return the input argument if it is already on CPU and raise error if no GPU backend is available anymore. -
The status of data can be checked by:
data.on_gpu().Truemeans the data is on GPU andfalsemeans the data is on CPU. -
The operations will be carried out on GPU only if the data passed to the operations are on GPU and GPU backend is registered:
sg_linalg->get_gpu_backend() == true. Thelinalgwill be conducted on CPU if the data is on CPU. -
linalgwill report errors if the data is on GPU but no GPU backend is available anymore. Also errors will occur when an operation requires multiple inputs but the inputs are not on the same backend. -
An warning will be generated if an operation is not available on specific backend.
The structure of linalg consists of three groups of components:
- The interface that decides which backend to use for each operation (
LinalgNameSpace.h) - The structure serves as interface of backend libraries (
GPUMemory*.h) - The operation implementations in each backend (
LinalgBackend*.h).
LinalgBackendBase is the base class for operations on all different backends. The macros in LinalgBackendBase defined the linalg operations and data transfer operations available in at least one backend.
LinalgBackendEigen is the LinalgBackendBase derived class with specific
and LinalgBackendViennaCL* provide the specific implementations of linear algebra operations with Eigen3 library and ViennaCL library.
LinalgBackendBase and LinalgBackendGPU are the interfaces for operations on all different backends and all different GPU backends respectively.
Welcome to the Shogun wiki!
-
[quick link GSoC 2016 projects](Google Summer of Code 2016 Projects)
-
Readmes:
-
Documents
-
[Roadmaps](Project roadmaps)
-
GSoC
- Getting involved
- Follow ups
- [2016 projects](Google Summer of Code 2016 Projects)
-
Credits