[Static Runtime] [Code Cleanup] Encapsulate function objects within ProcessedFunction (#69595)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/69595

This changes encapsulates `function` object in `ProcessedFunction` objects instead of exposing it unnecessarily just for executing it.

Test Plan: Existing tests

Reviewed By: mikeiovine

Differential Revision: D32908341

fbshipit-source-id: 5ff4951cbe276c5c6292227124d9eec1dd16e364
This commit is contained in:
Don Jang
2021-12-09 15:09:19 -08:00
committed by Facebook GitHub Bot
parent 41e1ab0785
commit 9aa1b3e396
3 changed files with 5 additions and 7 deletions

View File

@ -976,7 +976,6 @@ TEST(ProcessedFunction, ProcessedFunction) {
sigmoid_node,
/*enable_out_variant=*/true,
/*check_memory_overlap=*/false);
EXPECT_TRUE(sigmoid_fn.f());
EXPECT_EQ(sigmoid_fn.kind(), ProcessedFunction::Kind::kOutVariant);
EXPECT_FALSE(sigmoid_fn.checkMemoryOverlap());
@ -985,7 +984,6 @@ TEST(ProcessedFunction, ProcessedFunction) {
transpose_node,
/*enable_out_variant=*/true,
/*check_memory_overlap=*/false);
EXPECT_TRUE(transpose_fn.f());
EXPECT_EQ(transpose_fn.kind(), ProcessedFunction::Kind::kNativeFunction);
EXPECT_FALSE(transpose_fn.checkMemoryOverlap());
}

View File

@ -1700,12 +1700,12 @@ void ProcessedNode::run() {
guard.before(get_op_name());
}
}
fn_->f()(this);
fn_->run(this);
} else {
fn_->f()(this);
fn_->run(this);
}
#else
fn_->f()(this);
fn_->run(this);
#endif
#ifndef NDEBUG
if (FLAGS_static_runtime_disable_debug_memory_overlap_check) {

View File

@ -570,8 +570,8 @@ class TORCH_API ProcessedFunction {
kInterpreterFallback,
};
const std::function<void(ProcessedNode*)>& f() const {
return f_;
void run(ProcessedNode* pnode) const {
return f_(pnode);
}
Kind kind() const {