From dbc81645429259fb91d478b7d04d1bf779ad1a1b Mon Sep 17 00:00:00 2001 From: locnd182644 Date: Fri, 5 Dec 2025 14:12:42 +0700 Subject: [PATCH 1/4] [Runtime][MatchShape] Type error: Cannot convert from type ' DLTensor* ' to ' ffi.Shape ' - Error occurred at runtime when the first args of the MatchShape function (in runtime/vm/builtin.cc) is DLTensor*. If (auto opt_nd = args[0].as()) is false, args[0] (DLTensor*) will try convert to Shape. --- src/runtime/vm/builtin.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/runtime/vm/builtin.cc b/src/runtime/vm/builtin.cc index 1bd3084c210b..91080243f372 100644 --- a/src/runtime/vm/builtin.cc +++ b/src/runtime/vm/builtin.cc @@ -122,10 +122,11 @@ TVM_FFI_STATIC_INIT_BLOCK() { * \sa MatchShapeCode */ void MatchShape(ffi::PackedArgs args, ffi::Any* rv) { - // input shape the first argument can take in tensor or shape. + // input shape the first argument can take in tensor, DLTensor* or shape. ffi::Shape input_shape; - if (auto opt_nd = args[0].as()) { - input_shape = opt_nd.value().Shape(); + if (auto opt_nd = args[0].try_cast()) { + DLTensor* ptr = opt_nd.value(); + input_shape = ffi::Shape(ptr->shape, ptr->shape + ptr->ndim); } else { input_shape = args[0].cast(); } From e21499656eea8b77e0ebf6ad3c01ad6a9dc39511 Mon Sep 17 00:00:00 2001 From: locnd182644 Date: Thu, 11 Dec 2025 10:52:22 +0700 Subject: [PATCH 2/4] [Runtime][MatchShape] Type error: Cannot convert from type ' DLTensor* ' to ' ffi.Shape ' - Edit code like review --- src/runtime/vm/builtin.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime/vm/builtin.cc b/src/runtime/vm/builtin.cc index 91080243f372..dce687b436d1 100644 --- a/src/runtime/vm/builtin.cc +++ b/src/runtime/vm/builtin.cc @@ -124,8 +124,10 @@ TVM_FFI_STATIC_INIT_BLOCK() { void MatchShape(ffi::PackedArgs args, ffi::Any* rv) { // input shape the first argument can take in tensor, DLTensor* or shape. ffi::Shape input_shape; - if (auto opt_nd = args[0].try_cast()) { - DLTensor* ptr = opt_nd.value(); + if (auto opt_tensor = args[0].as()) { + input_shape = opt_tensor.value().Shape(); + } else if (auto opt_dltensor = args[0].try_cast()) { + DLTensor* ptr = opt_dltensor.value(); input_shape = ffi::Shape(ptr->shape, ptr->shape + ptr->ndim); } else { input_shape = args[0].cast(); From 493441d46d9386f4b6a9651043d095433ea1c045 Mon Sep 17 00:00:00 2001 From: locnd182644 Date: Mon, 22 Dec 2025 21:50:12 +0700 Subject: [PATCH 3/4] Rerun again --- src/runtime/vm/builtin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/vm/builtin.cc b/src/runtime/vm/builtin.cc index dce687b436d1..3c09a057f4dd 100644 --- a/src/runtime/vm/builtin.cc +++ b/src/runtime/vm/builtin.cc @@ -122,7 +122,7 @@ TVM_FFI_STATIC_INIT_BLOCK() { * \sa MatchShapeCode */ void MatchShape(ffi::PackedArgs args, ffi::Any* rv) { - // input shape the first argument can take in tensor, DLTensor* or shape. + // input shape the first argument can take in tensor, DLTensor* or shape. ffi::Shape input_shape; if (auto opt_tensor = args[0].as()) { input_shape = opt_tensor.value().Shape(); From 2b1d72cda821c53aa17397cc0291880c74c761a0 Mon Sep 17 00:00:00 2001 From: locnd182644 Date: Mon, 22 Dec 2025 21:51:06 +0700 Subject: [PATCH 4/4] Rerun --- src/runtime/vm/builtin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/vm/builtin.cc b/src/runtime/vm/builtin.cc index 3c09a057f4dd..dce687b436d1 100644 --- a/src/runtime/vm/builtin.cc +++ b/src/runtime/vm/builtin.cc @@ -122,7 +122,7 @@ TVM_FFI_STATIC_INIT_BLOCK() { * \sa MatchShapeCode */ void MatchShape(ffi::PackedArgs args, ffi::Any* rv) { - // input shape the first argument can take in tensor, DLTensor* or shape. + // input shape the first argument can take in tensor, DLTensor* or shape. ffi::Shape input_shape; if (auto opt_tensor = args[0].as()) { input_shape = opt_tensor.value().Shape();