Make `paddle::Function` as plain Functions
Created by: reyoung
Motivations
In the function
package, class FunctionBase
is the base class of Layer
and Projection
. Indeed, this design is not mandatory. We'd make replace class FunctionBase
by std::function
. An advantage of this change is that we can use Layers and Projections as they are C++ functions:
typedef std::function<Error(Tensors& inputs, Tensors& outputs)> CUDAKernel;
CUDAKernel softmax = KernelRegisters.get("softmax");
softmax(ins, outs);
Also, we can use std::bind
to bind the value of some parameters, like we do with functions defined in std
:
Error CosineKernel(Tensors& ins, Tensors& outs, double scale) {
...
}
KernelType cos = KernelRegister.get("cos", scale=3.0);
cos(ins, outs);
Actions Items
-
Change the use of class
Function
in layer definitions intostd::function<Error(Tensors& inputs, Tensors& outputs)>
:- Decouple package
function
andlayer
. - Define the conversion from
FunctionBase
toCUDAKernel
. - Above has been done in #2049.
- Decouple package
-
Rewrite class
Register
in packagefunction
.