tensor_test.cc 914 Bytes
Newer Older
1 2 3 4 5 6
#include <dmlc/logging.h>
#include <gtest/gtest.h>
#include <tvm/tvm.h>

TEST(Tensor, Basic) {
  using namespace tvm;
tqchen committed
7
  Var m("m"), n("n"), l("l");
8

9 10
  Tensor A = placeholder({m, l}, Float(32), "A");
  Tensor B = placeholder({n, l}, Float(32), "B");
tqchen committed
11

12
  auto C = compute({m, n}, [&](Var i, Var j) {
13
      return A[i][j];
tqchen committed
14
    }, "C");
15 16

  Tensor::Slice x = A[n];
17 18
}

tqchen committed
19 20 21
TEST(Tensor, Reduce) {
  using namespace tvm;
  Var m("m"), n("n"), l("l");
22 23
  Tensor A = placeholder({m, l}, Float(32), "A");
  Tensor B = placeholder({n, l}, Float(32), "B");
24
  IterVar rv = reduce_axis(Range{0, l}, "k");
tqchen committed
25

26
  auto C = compute({m, n}, [&](Var i, Var j) {
27
      return sum(max(1 + A[i][rv] + 1, B[j][rv]), {rv});
tqchen committed
28 29 30 31
      }, "C");
  LOG(INFO) << C->op.as<ComputeOpNode>()->body;
}

32 33 34 35 36
int main(int argc, char ** argv) {
  testing::InitGoogleTest(&argc, argv);
  testing::FLAGS_gtest_death_test_style = "threadsafe";
  return RUN_ALL_TESTS();
}