pytorch/test/cpp/tensorexpr
Nick Gibson 63dc1363e6 [TensorExpr] Eliminate Cond statements when each branch is a different kind of empty (#39754)
Summary:
Fix another simplification edge case, a Cond statement when one branch is nullptr and the other is a zero stmt block. This happens mostly with an if with no else branch where all statements inside the if are removed (eg via inlining or simplification). Common case is SplitWithMask -> ComputeInline.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39754

Differential Revision: D21962987

Pulled By: nickgg

fbshipit-source-id: 2461415466fbbab88d2329061f90fcfdfa85e243
2020-06-11 17:08:14 -07:00
..
__init__.py [TensorExpr] Add a class for representing data type. (#33217) 2020-02-21 13:10:12 -08:00
CMakeLists.txt Enable tensorexpr cpp tests in CI. try #2 (#35454) 2020-03-27 12:09:55 -07:00
gtest_assert_float_eq.h [TensorExpr] Clang-format test/cpp/tensorexpr/*. (#36615) 2020-04-14 19:08:18 -07:00
gtest.cpp [TensorExpr] Clang-format test/cpp/tensorexpr/*. (#36615) 2020-04-14 19:08:18 -07:00
padded_buffer.cpp [TensorExpr] fix warnings (#36167) 2020-04-08 15:42:29 -07:00
padded_buffer.h Add trivial reduce for Cuda (#36293) 2020-04-15 13:03:58 -07:00
README.md [TensorExpr] Add a class for representing data type. (#33217) 2020-02-21 13:10:12 -08:00
test_aten.cpp [TensorExpr] Add dtype to class Buf. (#36611) 2020-05-05 15:04:37 -07:00
test_base.h [TensorExpr] Implement LoopNest::computeAt (#36112) 2020-04-11 04:01:14 -07:00
test_cuda.cpp [TensorExpr] Add dtype to class Buf. (#36611) 2020-05-05 15:04:37 -07:00
test_expr.cpp [TensorExpr] remove Let and LetStmt in favour of binding in Block (#37606) 2020-05-09 16:23:37 -07:00
test_ir_printer.cpp [TensorExpr] Fix IRPrinter for function calls with uniqued names (#39753) 2020-06-11 12:13:28 -07:00
test_kernel.cpp [Codemod][GleanFbcode] Remove dead includes in caffe2/test (#39023) 2020-05-27 14:07:26 -07:00
test_llvm.cpp [TensorExpr] remove Let and LetStmt in favour of binding in Block (#37606) 2020-05-09 16:23:37 -07:00
test_loopnest.cpp [TensorExpr] fix a bug in ReorderAxis when there are trailing loops (#38841) 2020-05-31 22:22:45 -07:00
test_reductions.cpp [TensorExpr] Fix two bugs in Rfactor (#39268) 2020-06-03 14:38:34 -07:00
test_simplify.cpp [TensorExpr] Eliminate Cond statements when each branch is a different kind of empty (#39754) 2020-06-11 17:08:14 -07:00
test_te_fuser_pass.cpp [TensorExpr] Use couldMoveBefore instead of couldMoveAfter checks in the fuser pass, add CPP tests. (#38592) 2020-05-18 13:40:59 -07:00
test_type.cpp [TensorExpr] remove Let and LetStmt in favour of binding in Block (#37606) 2020-05-09 16:23:37 -07:00
test_utils.h [TensorExpr] Add a class for representing data type. (#33217) 2020-02-21 13:10:12 -08:00
tests.h [TensorExpr] Eliminate Cond statements when each branch is a different kind of empty (#39754) 2020-06-11 17:08:14 -07:00

TensorExpr C++ Tests

How to add a new test

First, create a new test file. Test files should have be placed in this directory, with a name that starts with test_, like test_foo.cpp.

Here is an example test file you can copy-paste.

#include <test/cpp/tensorexpr/test_base.h>

// Tests go in torch::jit
namespace torch {
namespace jit {

// 1. Test cases are void() functions.
// 2. They start with the prefix `test`
void testCaseOne() {
    // ...
}

void testCaseTwo() {
    // ...
}
}
}

Then, register your test in tests.h:

// Add to TH_FORALL_TESTS_CUDA instead for CUDA-requiring tests
#define TH_FORALL_TESTS(_)             \
  _(ADFormulas)                        \
  _(Attributes)                        \
  ...
  _(CaseOne)  // note that the `test` prefix is omitted.
  _(CaseTwo)

We glob all the test files together in CMakeLists.txt so that you don't have to edit it every time you add a test. Unfortunately, this means that in order to get the build to pick up your new test file, you need to re-run cmake:

python setup.py build --cmake

How do I run the tests?

The following commands assume you are in PyTorch root.

# (re)build the test binary
ninja build/bin/test_tensorexpr
# run
build/bin/test_tensorexpr --gtest_filter='glob_style_filter*'