mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/35115 This commit runs the newly added tools/clang_format.py on the JIT codebase and includes all of the formatting changes thus produced. Testing: Ran the script, CI. Test Plan: Imported from OSS Reviewed By: eellison Differential Revision: D20568523 Pulled By: SplitInfinity fbshipit-source-id: e09bdb982ccf090eecfb7c7b461b8d0681eef82b
54 lines
1.0 KiB
C++
54 lines
1.0 KiB
C++
#include <test/cpp/jit/test_base.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_;
|
|
};
|
|
|
|
void testInliner() {
|
|
{
|
|
// disable automatic inlining so we can test it manually
|
|
InlinerGuard guard(/*shouldInline=*/false);
|
|
|
|
CompilationUnit cu(testSource);
|
|
auto& fn = cu.get_function("foo3");
|
|
|
|
auto g = fn.graph();
|
|
Inline(*g);
|
|
FileCheck().check_count("prim::Print", 3)->run(*g);
|
|
}
|
|
}
|
|
} // namespace jit
|
|
} // namespace torch
|