From 274e4a65bf55d6f958061c7035288ecb2157b1c5 Mon Sep 17 00:00:00 2001 From: Cody Yu Date: Fri, 8 Jan 2021 20:33:21 +0000 Subject: [PATCH 1/4] [TOPI] Treat undefined elements as constants in Array --- include/tvm/topi/detail/constant_utils.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/tvm/topi/detail/constant_utils.h b/include/tvm/topi/detail/constant_utils.h index 49ce21b5732e..cd15d327b70b 100644 --- a/include/tvm/topi/detail/constant_utils.h +++ b/include/tvm/topi/detail/constant_utils.h @@ -48,7 +48,8 @@ using namespace tvm::te; inline bool IsConstInt(PrimExpr expr) { return expr->IsInstance(); } /*! - * \brief Test whether the given Array has every element as constant integer + * \brief Test whether the given Array has every element as constant integer. + * Undefined elements are also treat as constants. * * \param array the array to query * @@ -57,7 +58,7 @@ inline bool IsConstInt(PrimExpr expr) { return expr->IsInstance array) { bool is_const_int = true; for (auto const& elem : array) { - is_const_int &= elem->IsInstance(); + is_const_int &= !elem->defined() || elem->IsInstance(); } return is_const_int; } From cbd3e9ada083c30d6b314c66e8a14f8c3d587b7a Mon Sep 17 00:00:00 2001 From: Cody Yu Date: Fri, 8 Jan 2021 20:36:55 +0000 Subject: [PATCH 2/4] Add a checker --- include/tvm/topi/transform.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/tvm/topi/transform.h b/include/tvm/topi/transform.h index a04762f28feb..8d87fa1036b6 100644 --- a/include/tvm/topi/transform.h +++ b/include/tvm/topi/transform.h @@ -612,6 +612,7 @@ inline Tensor strided_slice(const Tensor& x, const Array& begin, Array out_shape; if (!is_static) { + ICHECK(strides.size(), src_tensor_dim); for (size_t i = 0; i < src_tensor_dim; ++i) { out_shape.push_back(indexdiv(end[i] - begin[i], strides[i])); } From d052cb12fc8a0460a6b15ac1b55c525dfd73430e Mon Sep 17 00:00:00 2001 From: Cody Yu Date: Fri, 8 Jan 2021 21:09:49 +0000 Subject: [PATCH 3/4] fix --- include/tvm/topi/transform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/tvm/topi/transform.h b/include/tvm/topi/transform.h index 8d87fa1036b6..261fdf9970a3 100644 --- a/include/tvm/topi/transform.h +++ b/include/tvm/topi/transform.h @@ -612,7 +612,7 @@ inline Tensor strided_slice(const Tensor& x, const Array& begin, Array out_shape; if (!is_static) { - ICHECK(strides.size(), src_tensor_dim); + ICHECK_EQ(strides.size(), src_tensor_dim); for (size_t i = 0; i < src_tensor_dim; ++i) { out_shape.push_back(indexdiv(end[i] - begin[i], strides[i])); } From 58ae831ae315e3b3d39dd36e2457f11154f0359a Mon Sep 17 00:00:00 2001 From: Cody Yu Date: Fri, 8 Jan 2021 21:42:32 +0000 Subject: [PATCH 4/4] add test case --- include/tvm/topi/detail/constant_utils.h | 2 +- tests/python/topi/python/test_topi_transform.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/tvm/topi/detail/constant_utils.h b/include/tvm/topi/detail/constant_utils.h index cd15d327b70b..92ff3a4e3804 100644 --- a/include/tvm/topi/detail/constant_utils.h +++ b/include/tvm/topi/detail/constant_utils.h @@ -58,7 +58,7 @@ inline bool IsConstInt(PrimExpr expr) { return expr->IsInstance array) { bool is_const_int = true; for (auto const& elem : array) { - is_const_int &= !elem->defined() || elem->IsInstance(); + is_const_int &= !elem.defined() || elem->IsInstance(); } return is_const_int; } diff --git a/tests/python/topi/python/test_topi_transform.py b/tests/python/topi/python/test_topi_transform.py index 30434f6fd266..e0018ba0c0d3 100644 --- a/tests/python/topi/python/test_topi_transform.py +++ b/tests/python/topi/python/test_topi_transform.py @@ -817,6 +817,7 @@ def test_strided_slice(): verify_strided_slice((3, 4, 3), [1, -1, 0], [2, -3, 3], [1, -1, 1]) verify_strided_slice((3, 4, 3), [1, 1, 0], [4, 4, 3]) verify_strided_slice((3, 4, 3), [0, 2, 0], [1, 2, 3]) + verify_strided_slice((3, 4, 3), [0, 0, 0], [None, None, None]) @tvm.testing.uses_gpu