Files
pytorch/test/cpp/jit/test_inliner.cpp
Zhengxu Chen b55a2500d2 [jit] Remove graph() call from abstract Function interface. (#65967)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/65967

Graph is an implementation detail. If user wants to get access to the
underlying graph, they should be able to explicitly dynamic cast instead.
ghstack-source-id: 141659819

Test Plan: no behavior change.

Reviewed By: gmagogsfm

Differential Revision: D31326153

fbshipit-source-id: a0e984f57c6013494b92a7095bf5bb660035eb84
2021-10-27 11:54:26 -07:00

52 lines
1.0 KiB
C++

#include <gtest/gtest.h>
#include <torch/csrc/jit/api/compilation_unit.h>
#include <torch/csrc/jit/api/module.h>
#include <torch/csrc/jit/passes/inliner.h>
#include <torch/csrc/jit/testing/file_check.h>
const auto testSource = R"JIT(
def foo1(x):
print("one")
return x
def foo2(x):
print("two")
return foo1(x)
def foo3(x):
print("three")
return foo2(x)
)JIT";
namespace torch {
namespace jit {
using namespace testing;
struct InlinerGuard {
explicit InlinerGuard(bool shouldInline)
: oldState_(getInlineEverythingMode()) {
getInlineEverythingMode() = shouldInline;
}
~InlinerGuard() {
getInlineEverythingMode() = oldState_;
}
bool oldState_;
};
TEST(InlinerTest, Basic) {
// disable automatic inlining so we can test it manually
InlinerGuard guard(/*shouldInline=*/false);
CompilationUnit cu(testSource);
auto& fn = cu.get_function("foo3");
auto g = toGraphFunction(fn).graph();
Inline(*g);
FileCheck().check_count("prim::Print", 3)->run(*g);
}
} // namespace jit
} // namespace torch