Skip to content

Commit f3fdfd9

Browse files
committed
add some comments for Function.h
1 parent 41c52d3 commit f3fdfd9

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

paddle/function/BufferArg.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,6 @@ class SequenceArg;
4646
class SparseMatrixArg;
4747
typedef std::shared_ptr<BufferArg> BufferArgPtr;
4848

49-
class BufferArgs {
50-
public:
51-
BufferArgs() {}
52-
size_t size() const { return args_.size(); }
53-
54-
// add argument into BufferArgss
55-
template <typename Tensor>
56-
void addArg(const Tensor& arg) {
57-
args_.push_back(std::make_shared<BufferArg>(arg));
58-
}
59-
60-
void addArg(const Matrix& arg, const TensorShape& shape);
61-
62-
void addArg(const CpuSparseMatrix& arg);
63-
void addArg(const GpuSparseMatrix& arg);
64-
65-
// get argument
66-
const BufferArg& operator[](size_t num) const {
67-
CHECK_LT(num, args_.size());
68-
return *args_[num];
69-
}
70-
71-
private:
72-
std::vector<BufferArgPtr> args_;
73-
};
74-
7549
// an array of arbitrary dimensions
7650
class BufferArg {
7751
public:

paddle/function/Function.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ limitations under the License. */
2222

2323
namespace paddle {
2424

25+
/**
26+
* Function Configuration.
27+
* The argument type of Function::init.
28+
* Follow-up will consider moving this data structure to Proto inside.
29+
*/
2530
class FuncConfig {
2631
public:
2732
union value {
@@ -41,6 +46,43 @@ class FuncConfig {
4146
std::map<std::string, value> valueMap_;
4247
};
4348

49+
/**
50+
* Argument type for Function::calc().
51+
* A BufferArgs contains a set of BufferArg,
52+
* because Function can have multiple inputs, outputs and inouts.
53+
*/
54+
class BufferArgs {
55+
public:
56+
BufferArgs() {}
57+
size_t size() const { return args_.size(); }
58+
59+
// add argument into BufferArgss
60+
template <typename Tensor>
61+
void addArg(const Tensor& arg) {
62+
args_.push_back(std::make_shared<BufferArg>(arg));
63+
}
64+
65+
void addArg(const Matrix& arg, const TensorShape& shape);
66+
67+
void addArg(const CpuSparseMatrix& arg);
68+
void addArg(const GpuSparseMatrix& arg);
69+
70+
// get argument
71+
const BufferArg& operator[](size_t num) const {
72+
CHECK_LT(num, args_.size());
73+
return *args_[num];
74+
}
75+
76+
private:
77+
std::vector<BufferArgPtr> args_;
78+
};
79+
80+
/**
81+
* Base class for Function.
82+
* The basic Function implementation requires override init and calc interfaces.
83+
* Need to pay attention to the inouts argument. For the input argument
84+
* that will be modified, it needs to be passed through inouts.
85+
*/
4486
class FunctionBase {
4587
public:
4688
virtual ~FunctionBase() {}

0 commit comments

Comments
 (0)