Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions paddle/fluid/lite/core/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,24 @@ class KernelBase {
const std::map<std::string, const Type*>& input_types,
const std::string& out_arg)>;

protected:
/// Run some initialization before `Run`, it will invoke after `SetParam` and
/// `SetContext`, that is both the param_ and context_ are valid.
virtual void PrepareForRun() {}

/// Run the kernel. Before Run, both the param_ and context_ should be valid.
virtual void Run() = 0;

public:
void Launch() {
if (is_first_epoch_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个应该是first iteration,不能是epoch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之后改下

PrepareForRun();
is_first_epoch_ = false;
}

Run();
}

void SetContext(std::unique_ptr<KernelContext>&& ctx) {
ctx_ = std::move(ctx);
}
Expand Down Expand Up @@ -141,6 +157,7 @@ class KernelBase {
// The extra identity to help defficiate a specific kernel, op_type_ + alias_
// is the unique ID for the kernel.
std::string alias_{};
bool is_first_epoch_{true};
};

// Light-weight kernel implementation.
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/lite/core/op_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool OpLite::Run() {
CHECK(kernel_);
SyncInputEvents();

kernel_->Run();
kernel_->Launch();

RecordOutputEvents();
return true;
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/lite/core/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ struct Instruct {
CHECK(op_->CheckShape());
}
op_->InferShape();
kernel_->Run();
kernel_->Launch();
}

friend std::ostream& operator<<(std::ostream& os, const Instruct& other) {
Expand Down