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/11 01:28:19 UTC

[GitHub] [incubator-tvm] lixiaoquan commented on a change in pull request #6024: [Relay][TF] Make StridedSlice support dynamic input and constant attrs

lixiaoquan commented on a change in pull request #6024:
URL: https://github.com/apache/incubator-tvm/pull/6024#discussion_r453138358



##########
File path: src/relay/op/tensor/transform.cc
##########
@@ -2146,7 +2146,18 @@ Array<te::Tensor> StridedSliceCompute(const Attrs& attrs, const Array<te::Tensor
                                       const Type& out_type) {
   const StridedSliceAttrs* param = attrs.as<StridedSliceAttrs>();
   CHECK(param != nullptr);
-  if (param->begin && param->end && param->strides) {
+
+  bool dyn = false;
+  for (auto& v : out_type.as<TensorTypeNode>()->shape) {
+    if (const tir::VarNode* var_node = v.as<tir::VarNode>()) {
+      if (var_node->name_hint == "any_dim") {
+        dyn = true;
+        break;
+      }
+    }
+  }
+
+  if (param->begin && param->end && param->strides && !dyn) {

Review comment:
       topi::strided_slice requires static shape because it will get value from each dim. Should we change this requirement or just use DynamicStrideSlice?
   ```
   diff --git a/topi/include/topi/transform.h b/topi/include/topi/transform.h
   index b5fc02ae7..329a62ce7 100644
   --- a/topi/include/topi/transform.h
   +++ b/topi/include/topi/transform.h
   @@ -610,6 +610,7 @@ inline Tensor strided_slice(const Tensor& x, const Array<Integer>& begin, const
      for (size_t i = 0; i < src_tensor_dim; ++i) {
        int64_t begin_range = stride_vec[i] < 0 ? -1 : 0;
        int64_t dim_i = GetConstInt(x->shape[i]);
   +    LOG(INFO) << dim_i; // it is -1 for modified case
        int64_t end_range = stride_vec[i] < 0 ? dim_i - 1 : dim_i;
        // transform negative indices to positive value, clips on the correct range
        auto index_canonicalization = [dim_i, begin_range, end_range](int64_t index) {
   @@ -635,6 +636,8 @@ inline Tensor strided_slice(const Tensor& x, const Array<Integer>& begin, const
        out_shape.push_back(slice_size);
      }
    
   +//  LOG(INFO) << out_shape;
   +
      return compute(
          out_shape,
          [&](const Array<Var>& indices) {
   ```




----------------------------------------------------------------
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