You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/07/03 10:48:59 UTC

[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #5983: Dynamic Tile Op

siju-samuel commented on a change in pull request #5983:
URL: https://github.com/apache/incubator-tvm/pull/5983#discussion_r449516436



##########
File path: python/tvm/relay/op/dyn/_transform.py
##########
@@ -81,3 +84,23 @@ def _reshape_shape_func_input_data(data, newshape, ndim):
 @_reg.register_shape_func("dyn.reshape", True)
 def dynamic_reshape_shape_func(attrs, inputs, out_ndims):
     return [_reshape_shape_func_input_data(*inputs, out_ndims[0])]
+
+
+@script
+def _tile_shape_func(data, reps, ndim):
+    out = output_tensor((ndim,), "int64")
+
+    for i in const_range(ndim):
+        out[i] = data.shape[i] * int64(reps[i])
+    return out
+
+
+@_reg.register_shape_func("dyn.tile", True)
+def tile_shape_func(attrs, inputs, _):
+    """
+    Shape function for tile op.
+    """
+    ndim = len(inputs[0].shape)
+    rdim = inputs[1].shape[0].value
+    assert ndim == rdim, "tile data and res ranks don't match"

Review comment:
       :s/res/reps

##########
File path: topi/include/topi/transform.h
##########
@@ -1016,6 +1016,38 @@ inline Tensor tile(const Tensor& x, Array<Integer> reps, std::string name = "T_t
   }
 }
 
+/*!
+ * \brief Creates an operation to tile elements of an array
+ *
+ * \param x The input tensor
+ * \param reps The number of times for repeating the tensor
+ * \param name The name of the operation
+ * \param tag The tag to mark the operation
+ *
+ * \return A Tensor whose op member is the tile operation
+ */
+inline Tensor dyn_tile(const Tensor& x, Array<PrimExpr> new_shape, std::string name = "T_tile",
+                       std::string tag = kBroadcast) {
+  size_t ndim = x->shape.size();
+  std::cout << ndim << std::endl;
+  std::cout << new_shape << std::endl;

Review comment:
       remove the couts

##########
File path: topi/include/topi/transform.h
##########
@@ -1016,6 +1016,38 @@ inline Tensor tile(const Tensor& x, Array<Integer> reps, std::string name = "T_t
   }
 }
 
+/*!
+ * \brief Creates an operation to tile elements of an array
+ *
+ * \param x The input tensor
+ * \param reps The number of times for repeating the tensor
+ * \param name The name of the operation

Review comment:
       update the header

##########
File path: tests/python/relay/dyn/test_dynamic_op_level3.py
##########
@@ -70,6 +70,24 @@ def verify_reshape(shape, newshape, oshape):
     verify_reshape((2, 3, 4), (8, 3), (8, 3))
     verify_reshape((4, 7), (2, 7, 2), (2, 7, 2))
 
+def test_dyn_tile():
+    def verify_tile(dshape, reps):
+        x = relay.var("x", relay.TensorType(dshape, "float32"))
+        r = relay.var("reps", relay.TensorType((len(dshape), ), "float32"))
+        z = relay.tile(x, r)
+
+        func = relay.Function([x, r], z)
+        x_data = np.random.uniform(low=-1, high=1, size=dshape).astype("float32")
+        ref_res = np.tile(x_data, reps=reps)
+        print (ref_res.shape)
+        print(x_data.shape)
+        print(np.array(reps).shape)

Review comment:
       remove prints




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org