tensor_test.cc 1.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

20 21 22 23 24 25
#include <dmlc/logging.h>
#include <gtest/gtest.h>
#include <tvm/tvm.h>

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

28 29
  Tensor A = placeholder({m, l}, Float(32), "A");
  Tensor B = placeholder({n, l}, Float(32), "B");
tqchen committed
30

31
  auto C = compute({m, n}, [&](Var i, Var j) {
32
      return A[i][j];
tqchen committed
33
    }, "C");
34 35

  Tensor::Slice x = A[n];
36 37
}

tqchen committed
38 39 40
TEST(Tensor, Reduce) {
  using namespace tvm;
  Var m("m"), n("n"), l("l");
41 42
  Tensor A = placeholder({m, l}, Float(32), "A");
  Tensor B = placeholder({n, l}, Float(32), "B");
43
  IterVar rv = reduce_axis(Range{0, l}, "k");
tqchen committed
44

45
  auto C = compute({m, n}, [&](Var i, Var j) {
46
      return sum(max(1 + A[i][rv] + 1, B[j][rv]), {rv});
tqchen committed
47 48 49 50
      }, "C");
  LOG(INFO) << C->op.as<ComputeOpNode>()->body;
}

51 52 53 54 55
int main(int argc, char ** argv) {
  testing::InitGoogleTest(&argc, argv);
  testing::FLAGS_gtest_death_test_style = "threadsafe";
  return RUN_ALL_TESTS();
}