Paddle Function
Created by: hedaoyuan
The main purpose of refactoring Paddle's computationally related code is to use a unified interface to represent each function. The function here can be understood as an operator in a neural network. Refactoring these computationally related codes mainly to solve the following three issues.
- Lack of unified function interface description In Paddle, the definition of Layer has a unified interface, but a Layer often call a number of functions, these functions do not have a unified interface description. If I just want to write an FFT-based convolution forward calculation for model inference, which interface should I refer to?
- Refactor the interfaces listed in ISSUE #977 (closed) Most of these functions are defined as a member function of the Matrix, but it does not specify how the member function interface of the Matrix should be defined. This has encountered some problems in interface readability and interface testing (#385 (closed)).
- Import third-party library, such as cuDNN, NNPACK, to improve the computational performance of Paddle on different hardware platforms(such as #2177 (closed)). To import a third-party library requires a piece of code to wrap the interface provided by the third-party library to facilitate calls in Paddle. So, what needs to be considered is how to simplify the writing of this wrapper code.
A unified function interface description
Paddle has many computationally related code(ISSUE #997 (closed)), by analyzing these interfaces, we can understand that what issues needs to solve.
- A calculation function that has one input and one output(https://github.com/PaddlePaddle/Paddle/issues/892#issuecomment-267358563).
- A calculation function that has multiple inputs and multiple outputs(https://github.com/PaddlePaddle/Paddle/issues/892#issuecomment-267358563).
- Some of the interfaces will assign the result to the output, while others will add the result to the output(https://github.com/PaddlePaddle/Paddle/issues/892#issuecomment-267358563).
- The same function is implemented as multiple versions based on different devices. At present, for CPU and GPU two devices, the realization of the CpuMatrix::memberFunction and GpuMatrix::memberFunction two functions.
- The same function is implemented as multiple versions based on different data type(like double, float). At present, it is done by switching the definition of
real
at compile time. - Using Matrix and Vector to represent one-dimensional and two-dimensional dense data types;
- With a Matrix and a Vector two arguments to represent an argument of the sequence type;
- SparseMatrix represents the sparse matrix type of
NO_VALUE
orFLOAT_VALUE
;
If we have designed an interface to solve these problems, we can reorganize the code(https://github.com/PaddlePaddle/Paddle/issues/892#issuecomment-267288472) of the interface listed in #997 (closed).