Skip to content

Make paddle::Function as plain Functions #2050

@reyoung

Description

@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

  1. Change the use of classFunction in layer definitions intostd::function<Error(Tensors& inputs, Tensors& outputs)>:

    1. Decouple package function and layer.
    2. Define the conversion from FunctionBase to CUDAKernel.
    3. Above has been done in Use KernelType instead of FunctionBase in Layer #2049.
  2. Rewrite class Register in package function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions