This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 3f75a27bcf Update FromNative call sites for latest TVM FFI (#20483)
3f75a27bcf is described below
commit 3f75a27bcf9fe53029089bdb52ccbb2ad769be0b
Author: Tianqi Chen <[email protected]>
AuthorDate: Mon Sep 28 20:12:10 2026 -0400
Update FromNative call sites for latest TVM FFI (#20483)
- Advance the bundled TVM FFI submodule to the native hook convention
while retaining the published package requirement.
- Model typed hooks by their successful return type and use
`CallExpected()` where TVM handles errors explicitly.
- Register throwing Relax validators and type inference hooks directly
with `FromNative`, removing redundant exception adapters.
---
3rdparty/tvm-ffi | 2 +-
include/tvm/ir/op.h | 26 +++---
src/ir/expr.cc | 2 +-
src/ir/op.cc | 4 +-
src/relax/op/ccl/ccl.cc | 18 +---
src/relax/op/image/resize.cc | 24 +----
src/relax/op/memory/view.cc | 6 +-
src/relax/op/nn/nn.cc | 36 ++-----
src/relax/op/nn/pooling.cc | 18 +---
src/relax/op/op.cc | 129 +++++---------------------
src/relax/op/op_common.h | 12 +--
src/relax/op/tensor/create.cc | 54 ++---------
src/relax/op/tensor/datatype.cc | 12 +--
src/relax/op/tensor/grad.cc | 42 ++-------
src/relax/op/tensor/index.cc | 12 +--
src/relax/op/tensor/linear_algebra.cc | 12 +--
src/relax/op/tensor/manipulate.cc | 66 +++----------
src/relax/op/tensor/sampling.cc | 6 +-
src/relax/op/tensor/search.cc | 12 +--
src/relax/op/tensor/set.cc | 12 +--
src/relax/op/tensor/sorting.cc | 18 +---
src/relax/op/tensor/statistical.cc | 18 +---
src/relax/op/tensor/unary.cc | 6 +-
src/relax/op/vision/multibox_transform_loc.cc | 6 +-
src/relax/op/vision/nms.cc | 12 +--
src/relax/op/vision/roi_align.cc | 6 +-
src/relax/op/vision/roi_pool.cc | 6 +-
27 files changed, 111 insertions(+), 466 deletions(-)
diff --git a/3rdparty/tvm-ffi b/3rdparty/tvm-ffi
index 4ee5a8621a..c96f9e31b2 160000
--- a/3rdparty/tvm-ffi
+++ b/3rdparty/tvm-ffi
@@ -1 +1 @@
-Subproject commit 4ee5a8621a075150ba1f2356893397d9d08d073e
+Subproject commit c96f9e31b279ddfecf543539263c0f3e082feeeb
diff --git a/include/tvm/ir/op.h b/include/tvm/ir/op.h
index c1c704db13..403541a104 100644
--- a/include/tvm/ir/op.h
+++ b/include/tvm/ir/op.h
@@ -44,7 +44,7 @@ template <typename>
class OpAttrMap;
/*! \brief Infer a Call's result type from its explicit inputs without builder
state. */
-using FInferType =
ffi::reflection::NativeFunctionView<ffi::Expected<Type>(const CallNode* call)>;
+using FInferType = ffi::reflection::NativeFunctionView<Type(const CallNode*
call)>;
/*! \brief An operator argument's name and documentation. */
class ArgumentInfoNode : public ffi::Object {
@@ -171,9 +171,11 @@ class Op : public Expr {
if (TVM_FFI_PREDICT_FALSE(!call)) {
ThrowInvalidCall(get());
}
- using View =
ffi::reflection::NativeFunctionView<ffi::Expected<void>(const CallNode*)>;
+ using View = ffi::reflection::NativeFunctionView<void(const CallNode*)>;
// set_validator stores only an owning NativeFunction with this
signature.
-
ffi::details::AnyUnsafe::CopyFromAnyViewAfterCheck<View>(validator)(call).value();
+ ffi::details::AnyUnsafe::CopyFromAnyViewAfterCheck<View>(validator)
+ .CallExpected(call)
+ .value();
}
}
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Op, Expr, OpNode);
@@ -502,7 +504,7 @@ class OpDef {
auto updated = ffi::make_object<OpNode>();
(ApplySignatureTrait(updated.get(), specs), ...);
if (op_->validator == nullptr) {
- using View =
ffi::reflection::NativeFunctionView<ffi::Expected<void>(const CallNode*)>;
+ using View = ffi::reflection::NativeFunctionView<void(const CallNode*)>;
set_validator(View::FromNative<&ValidateSignature<Specs...>>());
get()->validator_is_custom = false;
}
@@ -531,10 +533,10 @@ class OpDef {
/*!
* \brief Register a validator that checks a Call with this operator.
*
- * The callback accepts a `const CallNode*` and returns Expected<void>, with
- * an error for invalid input. A native function pointer can be bound with
- * NativeFunctionView::FromNative; a borrowed packed function may also be
- * passed while it remains alive for this call. The setter retains an owning
+ * The callback accepts a `const CallNode*` and reports invalid input by
+ * throwing or returning an `Expected<void>` error. A native function pointer
+ * can be bound with NativeFunctionView::FromNative. A borrowed packed
function
+ * may also be passed while it remains alive for this call. The setter
retains an owning
* copy, so the original packed function may then be destroyed.
* Ordinary Call construction invokes it; Call::Unchecked skips that initial
* check, while Relax normalization and well-formedness may validate later.
@@ -547,13 +549,11 @@ class OpDef {
* \param override Whether to replace the current validator.
* \return This builder.
*/
- OpDef& set_validator(
- ffi::reflection::NativeFunctionView<ffi::Expected<void>(const
CallNode*)> validator,
- bool override = false) {
+ OpDef& set_validator(ffi::reflection::NativeFunctionView<void(const
CallNode*)> validator,
+ bool override = false) {
TVM_FFI_CHECK(override || op_->validator == nullptr, ValueError)
<< "Validator of " << op_->name << " is already registered";
- get()->validator =
- ffi::reflection::NativeFunction<ffi::Expected<void>(const
CallNode*)>::From(validator);
+ get()->validator = ffi::reflection::NativeFunction<void(const
CallNode*)>::From(validator);
get()->validator_is_custom = true;
return *this;
}
diff --git a/src/ir/expr.cc b/src/ir/expr.cc
index 1bfb833d88..03710bb080 100644
--- a/src/ir/expr.cc
+++ b/src/ir/expr.cc
@@ -1213,7 +1213,7 @@ Type Call::ReinferType(const CallNode* call) {
static auto infer_type = Op::GetAttrMap<FInferType>("FInferType");
TVM_FFI_CHECK(infer_type.count(op.value()), ValueError)
<< "No context-free FInferType hook is registered for " << op.value();
- Type result = infer_type[op.value()](call).value();
+ Type result = infer_type[op.value()].CallExpected(call).value();
TVM_FFI_CHECK(!result.IsMissing(), InternalError)
<< "FInferType for " << op.value() << " returned Type::Missing()";
return result;
diff --git a/src/ir/op.cc b/src/ir/op.cc
index 0d518dc555..f0c9e0976a 100644
--- a/src/ir/op.cc
+++ b/src/ir/op.cc
@@ -208,8 +208,8 @@ void SetOpSignature(Op op, const ffi::Array<ffi::String>&
arg_names,
auto var_ty_args_info = MakeTailInfo(var_ty_args);
auto* node = const_cast<OpNode*>(op.operator->());
if (!node->validator_is_custom) {
- using View = ffi::reflection::NativeFunctionView<ffi::Expected<void>(const
CallNode*)>;
- node->validator =
ffi::reflection::NativeFunction<ffi::Expected<void>(const CallNode*)>::From(
+ using View = ffi::reflection::NativeFunctionView<void(const CallNode*)>;
+ node->validator = ffi::reflection::NativeFunction<void(const
CallNode*)>::From(
View::FromNative<&ValidateCountSignature>());
}
node->args_info = std::move(args_info);
diff --git a/src/relax/op/ccl/ccl.cc b/src/relax/op/ccl/ccl.cc
index 0ac13cf5c1..f287ec4999 100644
--- a/src/relax/op/ccl/ccl.cc
+++ b/src/relax/op/ccl/ccl.cc
@@ -51,14 +51,10 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.ccl.allreduce", allreduce);
}
-ffi::Expected<Type> InferTypeAllReduce(const CallNode* call_node) noexcept try
{
+Type InferTypeAllReduce(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType input_ty = GetUnaryInputTensorType(call);
return input_ty;
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -86,7 +82,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.ccl.allgather", allgather);
}
-ffi::Expected<Type> InferTypeAllGather(const CallNode* call_node) noexcept try
{
+Type InferTypeAllGather(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType input_ty = GetUnaryInputTensorType(call);
@@ -101,10 +97,6 @@ ffi::Expected<Type> InferTypeAllGather(const CallNode*
call_node) noexcept try {
ffi::Array<PrimExpr> output_shape = input_shape.value();
output_shape.Set(0, floor(output_shape[0] * num_workers));
return TensorType(ShapeExpr(output_shape), output_dtype, input_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -127,14 +119,10 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.ccl.broadcast_from_worker0",
broadcast_from_worker0);
}
-ffi::Expected<Type> InferTypeBroadcastFromZero(const CallNode* call_node)
noexcept try {
+Type InferTypeBroadcastFromZero(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType input_ty = GetUnaryInputTensorType(call);
return input_ty;
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/image/resize.cc b/src/relax/op/image/resize.cc
index 8aa43ab971..34f5c830c3 100644
--- a/src/relax/op/image/resize.cc
+++ b/src/relax/op/image/resize.cc
@@ -64,7 +64,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.image.resize2d", resize2d);
}
-ffi::Expected<Type> InferTypeResize2D(const CallNode* call_node) noexcept try {
+Type InferTypeResize2D(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 2) {
TVM_FFI_VISIT_THROW(ValueError, call)
@@ -113,10 +113,6 @@ ffi::Expected<Type> InferTypeResize2D(const CallNode*
call_node) noexcept try {
ffi::Array<PrimExpr> out_shape = data2NCHW.BackwardShape(out_NCHW_shape);
return TensorType(ShapeExpr(out_shape), out_dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutResize2d(
@@ -185,7 +181,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.image.resize3d", resize3d);
}
-ffi::Expected<Type> InferTypeResize3D(const CallNode* call_node) noexcept try {
+Type InferTypeResize3D(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 2) {
TVM_FFI_VISIT_THROW(ValueError, call)
@@ -235,10 +231,6 @@ ffi::Expected<Type> InferTypeResize3D(const CallNode*
call_node) noexcept try {
ffi::Array<PrimExpr> out_shape = data2NCDHW.BackwardShape(out_NCDHW_shape);
return TensorType(ShapeExpr(out_shape), out_dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutResize3d(
@@ -299,7 +291,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.image.grid_sample", grid_sample);
}
-ffi::Expected<Type> InferTypeGridSample(const CallNode* call_node) noexcept
try {
+Type InferTypeGridSample(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 2) {
TVM_FFI_VISIT_THROW(ValueError, call)
@@ -358,10 +350,6 @@ ffi::Expected<Type> InferTypeGridSample(const CallNode*
call_node) noexcept try
ffi::Array<PrimExpr> out_shape = data2tgt.BackwardShape(out_tgt_shape);
return TensorType(ShapeExpr(out_shape), out_dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -390,7 +378,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.image.affine_grid", affine_grid);
}
-ffi::Expected<Type> InferTypeAffineGrid(const CallNode* call_node) noexcept
try {
+Type InferTypeAffineGrid(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 2) {
TVM_FFI_VISIT_THROW(ValueError, call)
@@ -463,10 +451,6 @@ ffi::Expected<Type> InferTypeAffineGrid(const CallNode*
call_node) noexcept try
}
return TensorType(ShapeExpr(out_shape), out_dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/memory/view.cc b/src/relax/op/memory/view.cc
index 7b481da192..5e6804984b 100644
--- a/src/relax/op/memory/view.cc
+++ b/src/relax/op/memory/view.cc
@@ -415,7 +415,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.memory.ensure_zero_offset",
ensure_zero_offset);
}
-ffi::Expected<Type> InferTypeEnsureZeroOffset(const CallNode* call_node)
noexcept try {
+Type InferTypeEnsureZeroOffset(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 1) {
TVM_FFI_VISIT_THROW(ValueError, call)
@@ -423,10 +423,6 @@ ffi::Expected<Type> InferTypeEnsureZeroOffset(const
CallNode* call_node) noexcep
<< "but received " << call->args;
}
return GetType(call->args[0]);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
Expr LowerBuiltinEnsureZeroOffset(const BlockBuilder& bb, const Call& call) {
diff --git a/src/relax/op/nn/nn.cc b/src/relax/op/nn/nn.cc
index 0f4b5374bc..6e3dcfff7f 100644
--- a/src/relax/op/nn/nn.cc
+++ b/src/relax/op/nn/nn.cc
@@ -204,7 +204,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.nn.prelu", prelu);
}
-ffi::Expected<Type> InferTypePRelu(const CallNode* call_node) noexcept try {
+Type InferTypePRelu(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
if (data_ty->IsUnknownNdim()) {
@@ -220,10 +220,6 @@ ffi::Expected<Type> InferTypePRelu(const CallNode*
call_node) noexcept try {
NormalizeAxis(call, data_ty->ndim, attrs->axis);
return data_ty;
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutPRelu(
@@ -275,7 +271,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.nn.softmax", softmax);
}
-ffi::Expected<Type> InferTypeSoftmax(const CallNode* call_node) noexcept try {
+Type InferTypeSoftmax(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
if (data_ty->IsUnknownNdim()) {
@@ -294,10 +290,6 @@ ffi::Expected<Type> InferTypeSoftmax(const CallNode*
call_node) noexcept try {
NormalizeAxis(call, data_ty->ndim, attrs->axis);
return data_ty;
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutSoftmax(
@@ -365,7 +357,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.nn.pad", pad);
}
-ffi::Expected<Type> InferTypePad(const CallNode* call_node) noexcept try {
+Type InferTypePad(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
ffi::Array<TensorType> input_ty = GetInputTensorType(call);
const auto* attrs = call->attrs.as<PadAttrs>();
@@ -388,10 +380,6 @@ ffi::Expected<Type> InferTypePad(const CallNode*
call_node) noexcept try {
return TensorType(input_ty[0]->dtype, ndim);
}
return TensorType(ShapeExpr(out_shape), input_ty[0]->dtype);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -415,7 +403,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.nn.pixel_shuffle", pixel_shuffle);
}
-ffi::Expected<Type> InferTypePixelShuffle(const CallNode* call_node) noexcept
try {
+Type InferTypePixelShuffle(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
ffi::Array<TensorType> input_ty = GetInputTensorType(call);
const auto* attrs = call->attrs.as<PixelShuffleAttrs>();
@@ -465,10 +453,6 @@ ffi::Expected<Type> InferTypePixelShuffle(const CallNode*
call_node) noexcept tr
}
return TensorType(ShapeExpr(out_shape), input->dtype);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -989,14 +973,10 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.nn.dropout", dropout);
}
-ffi::Expected<Type> InferTypeDropout(const CallNode* call_node) noexcept try {
+Type InferTypeDropout(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
return TupleType({data_ty, data_ty});
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -1314,7 +1294,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.nn.batch_flatten", batch_flatten);
}
-ffi::Expected<Type> InferTypeBatchFlatten(const CallNode* call_node) noexcept
try {
+Type InferTypeBatchFlatten(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
@@ -1344,10 +1324,6 @@ ffi::Expected<Type> InferTypeBatchFlatten(const
CallNode* call_node) noexcept tr
}
return TensorType(ShapeExpr({batch_dim, flat_dim}), data_ty->dtype,
data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/nn/pooling.cc b/src/relax/op/nn/pooling.cc
index 4d8acb6fcc..d68b852ec2 100644
--- a/src/relax/op/nn/pooling.cc
+++ b/src/relax/op/nn/pooling.cc
@@ -542,7 +542,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.nn.adaptive_avg_pool1d",
adaptive_avg_pool1d);
}
-ffi::Expected<Type> InferTypeAdaptiveAvgPool1D(const CallNode* call_node)
noexcept try {
+Type InferTypeAdaptiveAvgPool1D(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
@@ -572,10 +572,6 @@ ffi::Expected<Type> InferTypeAdaptiveAvgPool1D(const
CallNode* call_node) noexce
ffi::Array<PrimExpr> out_shape = out2NCW.BackwardShape(out_NCW_shape);
return TensorType(ShapeExpr(out_shape), data_ty->dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutAdaptiveAvgPool1D(
@@ -631,7 +627,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.nn.adaptive_avg_pool2d",
adaptive_avg_pool2d);
}
-ffi::Expected<Type> InferTypeAdaptiveAvgPool2D(const CallNode* call_node)
noexcept try {
+Type InferTypeAdaptiveAvgPool2D(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
@@ -662,10 +658,6 @@ ffi::Expected<Type> InferTypeAdaptiveAvgPool2D(const
CallNode* call_node) noexce
ffi::Array<PrimExpr> out_shape = out2NCHW.BackwardShape(out_NCHW_shape);
return TensorType(ShapeExpr(out_shape), data_ty->dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutAdaptiveAvgPool2D(
@@ -740,7 +732,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.nn.adaptive_avg_pool3d",
adaptive_avg_pool3d);
}
-ffi::Expected<Type> InferTypeAdaptiveAvgPool3D(const CallNode* call_node)
noexcept try {
+Type InferTypeAdaptiveAvgPool3D(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
@@ -772,10 +764,6 @@ ffi::Expected<Type> InferTypeAdaptiveAvgPool3D(const
CallNode* call_node) noexce
ffi::Array<PrimExpr> out_shape = out2NCDHW.BackwardShape(out_NCDHW_shape);
return TensorType(ShapeExpr(out_shape), data_ty->dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutAdaptiveAvgPool3D(
diff --git a/src/relax/op/op.cc b/src/relax/op/op.cc
index 02bf168805..52487c5dbe 100644
--- a/src/relax/op/op.cc
+++ b/src/relax/op/op.cc
@@ -25,8 +25,6 @@
#include <tvm/relax/expr.h>
#include <tvm/relax/utils.h>
-#include <exception>
-
#include "../transform/utils.h"
#include "op_common.h"
@@ -62,23 +60,11 @@ bool EqualCheck(const PrimExpr& lhs, const PrimExpr& rhs) {
return false;
}
-ffi::Expected<Type> ReturnVoidType(const CallNode*) noexcept try {
- return TupleType(ffi::Array<Type>());
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
-}
+Type ReturnVoidType(const CallNode*) { return TupleType(ffi::Array<Type>()); }
-ffi::Expected<Type> ReturnAnyType(const CallNode*) noexcept try {
- return AnyType();
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
-}
+Type ReturnAnyType(const CallNode*) { return AnyType(); }
-ffi::Expected<Type> InferTypeShapeOf(const CallNode* call_node) noexcept try {
+Type InferTypeShapeOf(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
// use the Type of the argument
auto arg_ty = GetType(call->args[0]);
@@ -96,10 +82,6 @@ ffi::Expected<Type> InferTypeShapeOf(const CallNode*
call_node) noexcept try {
auto* tensor_shape = tensor_ty->shape.as<ShapeExprNode>();
TVM_FFI_ICHECK(tensor_shape);
return ShapeType(tensor_shape->values);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
// call_pure_packed
@@ -130,18 +112,6 @@ Type InferTypeCallPurePacked(const Call& call, const
BlockBuilder& ctx) {
}
}
-template <void (*Fn)(const CallNode*)>
-TVM_FFI_INLINE ffi::Expected<void> ValidateAsExpected(const CallNode* call)
noexcept {
- try {
- Fn(call);
- return {};
- } catch (const ffi::Error& err) {
- return ffi::Unexpected(err);
- } catch (const std::exception& err) {
- return ffi::Unexpected(ffi::Error("InternalError", err.what(), ""));
- }
-}
-
void ValidateCallPurePacked(const CallNode* call) {
TVM_FFI_CHECK(call->args.size() >= 1, TypeError)
<< "call_pure_packed expects a function argument";
@@ -163,9 +133,8 @@ void ValidateCallPurePacked(const CallNode* call) {
TVM_FFI_STATIC_INIT_BLOCK() {
OpDef("relax.call_pure_packed")
- .set_validator(
- ffi::reflection::NativeFunctionView<ffi::Expected<void>(
- const
CallNode*)>::FromNative<&ValidateAsExpected<ValidateCallPurePacked>>())
+ .set_validator(ffi::reflection::NativeFunctionView<void(
+ const
CallNode*)>::FromNative<&ValidateCallPurePacked>())
.signature(sig::arg("func",
"The first argument is the function being called.
The rest are the "
"arguments to that function."),
@@ -447,7 +416,7 @@ static ffi::Optional<Type>
InferCallTIROutputTypeFromArguments(
return derived_ret_ty;
}
-ffi::Expected<Type> InferTypeCallTIR(const CallNode* call_node) noexcept try {
+Type InferTypeCallTIR(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->ty_args.size() != 1) {
TVM_FFI_VISIT_THROW(InternalError, call) << "ty_args should have exactly 1
output type.";
@@ -460,10 +429,6 @@ ffi::Expected<Type> InferTypeCallTIR(const CallNode*
call_node) noexcept try {
Type explicit_ty = call->ty_args[0];
return explicit_ty;
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
Expr NormalizeCallTIR(const BlockBuilder& ctx, Call call) {
@@ -576,8 +541,8 @@ void ValidateCallTIR(const CallNode* call) {
TVM_FFI_STATIC_INIT_BLOCK() {
OpDef("relax.call_tir")
- .set_validator(ffi::reflection::NativeFunctionView<ffi::Expected<void>(
- const
CallNode*)>::FromNative<&ValidateAsExpected<ValidateCallTIR>>())
+ .set_validator(ffi::reflection::NativeFunctionView<void(
+ const CallNode*)>::FromNative<&ValidateCallTIR>())
.signature(sig::arg("func", "The destination-passing-style function."),
sig::arg("args", "The input arguments."),
sig::ty_arg("out_type", "The output type."))
@@ -613,8 +578,8 @@ TVM_FFI_STATIC_INIT_BLOCK() {
// call_tir_with_grad
OpDef("relax.call_tir_with_grad")
- .set_validator(ffi::reflection::NativeFunctionView<ffi::Expected<void>(
- const
CallNode*)>::FromNative<&ValidateAsExpected<ValidateCallTIR>>())
+ .set_validator(ffi::reflection::NativeFunctionView<void(
+ const CallNode*)>::FromNative<&ValidateCallTIR>())
.signature(sig::arg("func", "The destination-passing-style function."),
sig::arg("args", "The input arguments."),
sig::ty_arg("out_type", "The output type."),
@@ -745,8 +710,8 @@ Expr NormalizeCallTIRInPlace(const BlockBuilder& ctx, Call
call) {
TVM_FFI_STATIC_INIT_BLOCK() {
OpDef("relax.call_tir_inplace")
- .set_validator(ffi::reflection::NativeFunctionView<ffi::Expected<void>(
- const
CallNode*)>::FromNative<&ValidateAsExpected<ValidateCallTIR>>())
+ .set_validator(ffi::reflection::NativeFunctionView<void(
+ const CallNode*)>::FromNative<&ValidateCallTIR>())
.signature(sig::arg("func", "The destination-passing-style function."),
sig::arg("args", "The input arguments."),
sig::ty_arg("out_type", "The output type."),
@@ -790,16 +755,12 @@ TVM_FFI_STATIC_INIT_BLOCK() {
// call_dps_packed
-ffi::Expected<Type> InferTypeCallDPSPacked(const CallNode* call_node) noexcept
try {
+Type InferTypeCallDPSPacked(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->ty_args.size() != 1) {
TVM_FFI_VISIT_THROW(InternalError, call) << "ty_args should have exact 1
output type.";
}
return call->ty_args[0];
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -840,16 +801,12 @@ TVM_FFI_STATIC_INIT_BLOCK() {
// call_py_func
-ffi::Expected<Type> InferTypeCallPyFunc(const CallNode* call_node) noexcept
try {
+Type InferTypeCallPyFunc(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->ty_args.size() != 1) {
TVM_FFI_VISIT_THROW(InternalError, call) << "ty_args should have exact 1
output type.";
}
return call->ty_args[0];
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
void ValidateCallPyFunc(const CallNode* call) {
@@ -875,8 +832,8 @@ void ValidateCallPyFunc(const CallNode* call) {
TVM_FFI_STATIC_INIT_BLOCK() {
OpDef("relax.call_py_func")
- .set_validator(ffi::reflection::NativeFunctionView<ffi::Expected<void>(
- const
CallNode*)>::FromNative<&ValidateAsExpected<ValidateCallPyFunc>>())
+ .set_validator(ffi::reflection::NativeFunctionView<void(
+ const CallNode*)>::FromNative<&ValidateCallPyFunc>())
.signature(sig::arg("func_name", "The name of the Python function to
call."),
sig::arg("args", "The input arguments."),
sig::ty_arg("out_type", "The output type."))
@@ -910,7 +867,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
}
// call builtin
-ffi::Expected<Type> InferTypeCallBuiltinWithCtx(const CallNode* call_node)
noexcept try {
+Type InferTypeCallBuiltinWithCtx(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->ty_args.size() == 0) {
// by default return void.
@@ -919,10 +876,6 @@ ffi::Expected<Type> InferTypeCallBuiltinWithCtx(const
CallNode* call_node) noexc
TVM_FFI_ICHECK_EQ(call->ty_args.size(), 1);
return call->ty_args[0];
}
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -990,7 +943,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
// can't actually name it assert or else Python will consider it a syntax error
-ffi::Expected<Type> InferAssertType(const CallNode* call_node) noexcept try {
+Type InferAssertType(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
// Ensure that the condition argument is a boolean scalar.
// Also permitted is a tensor with unknown shape and unknown dtype
@@ -1005,10 +958,6 @@ ffi::Expected<Type> InferAssertType(const CallNode*
call_node) noexcept try {
<< "The argument to assert must be a boolean scalar, but received " <<
arg_ty;
}
return ReturnVoidType(call.get());
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -1058,7 +1007,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
// invoke_closure
-ffi::Expected<Type> InferTypeInvokeClosure(const CallNode* call_node) noexcept
try {
+Type InferTypeInvokeClosure(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->ty_args.empty()) {
return AnyType();
@@ -1067,10 +1016,6 @@ ffi::Expected<Type> InferTypeInvokeClosure(const
CallNode* call_node) noexcept t
} else {
return TupleType(call->ty_args);
}
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -1131,17 +1076,13 @@ TVM_FFI_STATIC_INIT_BLOCK() {
// size
-ffi::Expected<Type> InferTypeSize(const CallNode* call_node) noexcept try {
+Type InferTypeSize(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
auto arg_ty = GetType(call->args[0]);
auto* tensor_ty = GetType(call->args[0]).as<TensorTypeNode>();
TVM_FFI_ICHECK(tensor_ty) << "size expects a tensor input, but received " <<
arg_ty
<< "; use MatchCast if necessary";
return TensorType(ShapeExpr(ffi::Array<PrimExpr>{}), PrimType::Int(64));
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -1163,7 +1104,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
// tensor_to_shape
-ffi::Expected<Type> ReturnTensorToShapeType(const CallNode* call_node)
noexcept try {
+Type ReturnTensorToShapeType(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TVM_FFI_ICHECK(call->args.size() == 1);
TVM_FFI_ICHECK(!call->args[0]->ty.IsMissing());
@@ -1181,10 +1122,6 @@ ffi::Expected<Type> ReturnTensorToShapeType(const
CallNode* call_node) noexcept
}
}
return ShapeType(kUnknownNDim);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -1205,7 +1142,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
}
// shape_to_tensor
-ffi::Expected<Type> ReturnShapeToTensorType(const CallNode* call_node)
noexcept try {
+Type ReturnShapeToTensorType(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TVM_FFI_ICHECK(call->args.size() == 1);
TVM_FFI_ICHECK(!call->args[0]->ty.IsMissing());
@@ -1213,10 +1150,6 @@ ffi::Expected<Type> ReturnShapeToTensorType(const
CallNode* call_node) noexcept
TVM_FFI_ICHECK(ty);
int32_t ndim = ty->ndim;
return TensorType(ShapeExpr({PrimExpr(ndim)}), PrimType::Int(64));
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -1544,12 +1477,8 @@ TVM_FFI_STATIC_INIT_BLOCK() {
}
// builtin stop_lift_params
-ffi::Expected<Type> InferTypeStopLiftParams(const CallNode* call) noexcept try
{
+Type InferTypeStopLiftParams(const CallNode* call) {
return InferTypeUnaryArithContextFree<false>(call);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -1572,7 +1501,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
// to_vdevice
-ffi::Expected<Type> InferToVDeviceType(const CallNode* call_node) noexcept try
{
+Type InferToVDeviceType(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TVM_FFI_ICHECK(call->args.size() == 1);
TVM_FFI_ICHECK(!call->args[0]->ty.IsMissing());
@@ -1583,10 +1512,6 @@ ffi::Expected<Type> InferToVDeviceType(const CallNode*
call_node) noexcept try {
return TensorType(data_ty->shape.value(), data_ty->dtype, vdev,
data_ty->span);
}
return TensorType(data_ty->dtype, data_ty->ndim, vdev, data_ty->span);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -1611,16 +1536,12 @@ TVM_FFI_STATIC_INIT_BLOCK() {
// hint_on_device
-ffi::Expected<Type> InferHintOnDeviceType(const CallNode* call_node) noexcept
try {
+Type InferHintOnDeviceType(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TVM_FFI_ICHECK(call->args.size() == 1);
TVM_FFI_ICHECK(!call->args[0]->ty.IsMissing());
TensorType data_ty = GetUnaryInputTensorType(call);
return data_ty;
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/op_common.h b/src/relax/op/op_common.h
index e71b166e54..4ef7d1ea8f 100644
--- a/src/relax/op/op_common.h
+++ b/src/relax/op/op_common.h
@@ -259,7 +259,7 @@ Type ReturnTypeFromArg(const Call& call, const
BlockBuilder& ctx) {
}
template <int arg_index>
-ffi::Expected<Type> ReturnTypeFromArgContextFree(const CallNode* call_node)
noexcept try {
+Type ReturnTypeFromArgContextFree(const CallNode* call_node) {
Call call = ffi::GetRef<Call>(call_node);
Op op = call->op.as_or_throw<Op>();
CheckNumArguments(call);
@@ -270,10 +270,6 @@ ffi::Expected<Type> ReturnTypeFromArgContextFree(const
CallNode* call_node) noex
<< arg_index;
}
return GetType(call->args[arg_index]);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
/*!
@@ -291,14 +287,10 @@ Type InferTypeUnaryArith(const Call& call, const
BlockBuilder& ctx) {
}
template <bool require_float_dtype>
-ffi::Expected<Type> InferTypeUnaryArithContextFree(const CallNode* call_node)
noexcept try {
+Type InferTypeUnaryArithContextFree(const CallNode* call_node) {
Call call = ffi::GetRef<Call>(call_node);
return InferTypeUnary<require_float_dtype>(
call, [](const TensorType& input_ty) { return input_ty->dtype; });
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
/*!
diff --git a/src/relax/op/tensor/create.cc b/src/relax/op/tensor/create.cc
index d23c943be5..e48c62f32e 100644
--- a/src/relax/op/tensor/create.cc
+++ b/src/relax/op/tensor/create.cc
@@ -71,7 +71,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.full", full);
}
-ffi::Expected<Type> InferTypeFull(const CallNode* call_node) noexcept try {
+Type InferTypeFull(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 2) {
TVM_FFI_VISIT_THROW(ValueError, call) << "Full op should have 2 arguments";
@@ -94,10 +94,6 @@ ffi::Expected<Type> InferTypeFull(const CallNode* call_node)
noexcept try {
?
ffi::Optional<PrimType>(PrimType(attrs->dtype.value()))
: fill_value_ty->dtype;
return TensorType(/*shape=*/call->args[0], out_dtype,
fill_value_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -126,7 +122,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.full_like", full_like);
}
-ffi::Expected<Type> InferTypeFullLike(const CallNode* call_node) noexcept try {
+Type InferTypeFullLike(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
ffi::Array<TensorType> input_ty = GetInputTensorType(call);
TensorType data_ty = input_ty[0];
@@ -145,10 +141,6 @@ ffi::Expected<Type> InferTypeFullLike(const CallNode*
call_node) noexcept try {
output_ty->dtype = PrimType(attrs->dtype.value());
return TensorType(output_ty);
}
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -161,7 +153,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
}
// Structure info inference for ones and zeros
-ffi::Expected<Type> InferTypeOnesZeros(const CallNode* call_node) noexcept try
{
+Type InferTypeOnesZeros(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 1) {
TVM_FFI_VISIT_THROW(ValueError, call) << "Ones/Zeros should have 1
argument";
@@ -176,14 +168,10 @@ ffi::Expected<Type> InferTypeOnesZeros(const CallNode*
call_node) noexcept try {
const auto* attrs = call->attrs.as<InitAttrs>();
TVM_FFI_ICHECK(attrs->dtype.has_value());
return TensorType(/*shape=*/call->args[0], PrimType(attrs->dtype.value()));
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
// Structure info inference for ones_like and zeros_like
-ffi::Expected<Type> InferTypeOnesLikeZerosLike(const CallNode* call_node)
noexcept try {
+Type InferTypeOnesLikeZerosLike(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
const auto* attrs = call->attrs.as<InitAttrs>();
@@ -194,10 +182,6 @@ ffi::Expected<Type> InferTypeOnesLikeZerosLike(const
CallNode* call_node) noexce
output_ty->dtype = PrimType(attrs->dtype.value());
return TensorType(output_ty);
}
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
/* relax.ones & relax.ones_like */
@@ -287,7 +271,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.eye", eye).def("relax.op.eye_like",
eye_like);
}
-ffi::Expected<Type> InferTypeEye(const CallNode* call_node) noexcept try {
+Type InferTypeEye(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 3) {
TVM_FFI_VISIT_THROW(ValueError, call) << "Eye op should have 3 arguments:
n, m, and k, but got "
@@ -310,13 +294,9 @@ ffi::Expected<Type> InferTypeEye(const CallNode*
call_node) noexcept try {
TVM_FFI_ICHECK(attrs->dtype.has_value());
DLDataType dtype = attrs->dtype.value();
return TensorType(ShapeExpr({n, m}), PrimType(dtype));
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
-ffi::Expected<Type> InferTypeEyeLike(const CallNode* call_node) noexcept try {
+Type InferTypeEyeLike(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 2) {
TVM_FFI_VISIT_THROW(ValueError, call)
@@ -342,10 +322,6 @@ ffi::Expected<Type> InferTypeEyeLike(const CallNode*
call_node) noexcept try {
: x_ty->dtype;
return TensorType(x_ty->shape.value(), out_dtype, x_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -378,7 +354,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.arange", arange);
}
-ffi::Expected<Type> InferTypeArange(const CallNode* call_node) noexcept try {
+Type InferTypeArange(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 3) {
TVM_FFI_VISIT_THROW(ValueError, call)
@@ -412,10 +388,6 @@ ffi::Expected<Type> InferTypeArange(const CallNode*
call_node) noexcept try {
sym::Analyzer analyzer;
num_elem = analyzer->Simplify(num_elem);
return TensorType(ShapeExpr({num_elem}), PrimType(dtype));
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -446,7 +418,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.hamming_window", hamming_window);
}
-ffi::Expected<Type> InferTypeHammingWindow(const CallNode* call_node) noexcept
try {
+Type InferTypeHammingWindow(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
const auto* attrs = call->attrs.as<InitAttrs>();
TVM_FFI_ICHECK(attrs->dtype.has_value());
@@ -473,10 +445,6 @@ ffi::Expected<Type> InferTypeHammingWindow(const CallNode*
call_node) noexcept t
}
window_size = analyzer->Simplify(window_size);
return TensorType(ShapeExpr({window_size}), PrimType(dtype));
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -512,7 +480,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
.def("relax.op.triu", static_cast<Expr (*)(Expr, Expr)>(triu));
}
-ffi::Expected<Type> InferTypeTrilTriu(const CallNode* call_node) noexcept try {
+Type InferTypeTrilTriu(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
auto [data_ty, offset] = GetArgType<TensorType, PrimType>(call);
@@ -523,10 +491,6 @@ ffi::Expected<Type> InferTypeTrilTriu(const CallNode*
call_node) noexcept try {
<< data_ty->ndim << " dimension(s).";
}
return data_ty;
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/tensor/datatype.cc b/src/relax/op/tensor/datatype.cc
index bd60f13ee2..e4a4caba8b 100644
--- a/src/relax/op/tensor/datatype.cc
+++ b/src/relax/op/tensor/datatype.cc
@@ -51,17 +51,13 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.astype", astype);
}
-ffi::Expected<Type> InferTypeAstype(const CallNode* call_node) noexcept try {
+Type InferTypeAstype(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType ty = GetUnaryInputTensorType(call);
const auto* attrs = call->attrs.as<AstypeAttrs>();
ffi::ObjectPtr<TensorTypeNode> new_ty =
ffi::make_object<TensorTypeNode>(*ty.get());
new_ty->dtype = PrimType(attrs->dtype);
return TensorType(new_ty);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -88,17 +84,13 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.wrap_param", MakeWrapParam);
}
-ffi::Expected<Type> InferTypeWrapParam(const CallNode* call_node) noexcept try
{
+Type InferTypeWrapParam(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType ty = GetUnaryInputTensorType(call);
const auto* attrs = call->attrs.as<WrapParamAttrs>();
ffi::ObjectPtr<TensorTypeNode> new_ty =
ffi::make_object<TensorTypeNode>(*ty.get());
new_ty->dtype = PrimType(attrs->dtype);
return TensorType(new_ty);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/tensor/grad.cc b/src/relax/op/tensor/grad.cc
index e0e109442f..fd619e0cee 100644
--- a/src/relax/op/tensor/grad.cc
+++ b/src/relax/op/tensor/grad.cc
@@ -43,13 +43,9 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.grad.no_grad", no_grad);
}
-ffi::Expected<Type> InferTypeNoGrad(const CallNode* call_node) noexcept try {
+Type InferTypeNoGrad(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
return GetType(call->args[0]);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -70,17 +66,13 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.grad.start_checkpoint", start_checkpoint);
}
-ffi::Expected<Type> InferTypeStartCheckpoint(const CallNode* call_node)
noexcept try {
+Type InferTypeStartCheckpoint(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (!call->args[0].as<VarNode>()) {
TVM_FFI_VISIT_THROW(TypeError, call)
<< "The argument of relax.op.grad.start_checkpoint should be a Var.";
}
return GetType(call->args[0]);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -101,17 +93,13 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.grad.end_checkpoint", end_checkpoint);
}
-ffi::Expected<Type> InferTypeEndCheckpoint(const CallNode* call_node) noexcept
try {
+Type InferTypeEndCheckpoint(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (!call->args[0].as<VarNode>()) {
TVM_FFI_VISIT_THROW(TypeError, call)
<< "The argument of relax.op.grad.end_checkpoint should be a Var.";
}
return GetType(call->args[0]);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -147,13 +135,9 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.grad.nll_loss_backward", nll_loss_backward);
}
-ffi::Expected<Type> InferTypeNLLLossBackward(const CallNode* call_node)
noexcept try {
+Type InferTypeNLLLossBackward(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
return GetType(call->args[1]);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -190,13 +174,9 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.grad.max_pool2d_backward",
max_pool2d_backward);
}
-ffi::Expected<Type> InferTypeMaxPool2DBackward(const CallNode* call_node)
noexcept try {
+Type InferTypeMaxPool2DBackward(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
return GetType(call->args[1]);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -231,13 +211,9 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.grad.avg_pool2d_backward",
avg_pool2d_backward);
}
-ffi::Expected<Type> InferTypeAvgPool2DBackward(const CallNode* call_node)
noexcept try {
+Type InferTypeAvgPool2DBackward(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
return GetType(call->args[1]);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -265,13 +241,9 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.grad.take_backward", take_backward);
}
-ffi::Expected<Type> InferTypeTakeBackward(const CallNode* call_node) noexcept
try {
+Type InferTypeTakeBackward(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
return GetType(call->args[1]);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/tensor/index.cc b/src/relax/op/tensor/index.cc
index 67d7cf0181..69fe051be0 100644
--- a/src/relax/op/tensor/index.cc
+++ b/src/relax/op/tensor/index.cc
@@ -61,7 +61,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.take", take);
}
-ffi::Expected<Type> InferTypeTake(const CallNode* call_node) noexcept try {
+Type InferTypeTake(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
CheckNumArguments(call);
TensorType data_ty = GetInputTensorType(call, 0);
@@ -126,10 +126,6 @@ ffi::Expected<Type> InferTypeTake(const CallNode*
call_node) noexcept try {
}
}
return TensorType(ShapeExpr(output_shape), data_ty->dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -518,7 +514,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.dynamic_strided_slice",
dynamic_strided_slice);
}
-ffi::Expected<Type> InferTypeDynStridedSlice(const CallNode* call_node)
noexcept try {
+Type InferTypeDynStridedSlice(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
const auto* data_ty = GetTypeAs<TensorTypeNode>(call->args[0]);
const auto* begin_ty = GetTypeAs<TensorTypeNode>(call->args[1]);
@@ -572,10 +568,6 @@ ffi::Expected<Type> InferTypeDynStridedSlice(const
CallNode* call_node) noexcept
// TODO(tvm-team): Currently, it is unable to express partially-static
shape. Revisit when
// PrimExpr lands.
return TensorType(data_ty->dtype, n_axis, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutDynStridedSlice(
diff --git a/src/relax/op/tensor/linear_algebra.cc
b/src/relax/op/tensor/linear_algebra.cc
index e8bf42b3ff..a9c1f11955 100644
--- a/src/relax/op/tensor/linear_algebra.cc
+++ b/src/relax/op/tensor/linear_algebra.cc
@@ -187,7 +187,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.einsum", einsum);
}
-ffi::Expected<Type> InferTypeEinsum(const CallNode* call_node) noexcept try {
+Type InferTypeEinsum(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 1) {
TVM_FFI_VISIT_THROW(ValueError, call) << "Einsum op should take 1
argument";
@@ -251,10 +251,6 @@ ffi::Expected<Type> InferTypeEinsum(const CallNode*
call_node) noexcept try {
return TensorType(ShapeExpr(oshape), operand_ty, vdev);
}
return TensorType(ShapeExpr(oshape), operand_ty);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -276,7 +272,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.outer", outer);
}
-ffi::Expected<Type> InferTypeOuter(const CallNode* call_node) noexcept try {
+Type InferTypeOuter(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
auto input_ty = GetInputTensorType(call);
auto x1_ty = input_ty[0];
@@ -295,10 +291,6 @@ ffi::Expected<Type> InferTypeOuter(const CallNode*
call_node) noexcept try {
}
ffi::Array<PrimExpr> output_shape = {x1_shape->values[0],
x2_shape->values[0]};
return TensorType(ShapeExpr(output_shape), x1_ty->dtype);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/tensor/manipulate.cc
b/src/relax/op/tensor/manipulate.cc
index eac58903d8..38eb54a039 100644
--- a/src/relax/op/tensor/manipulate.cc
+++ b/src/relax/op/tensor/manipulate.cc
@@ -414,7 +414,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.expand_dims", expand_dims);
}
-ffi::Expected<Type> InferTypeExpandDims(const CallNode* call_node) noexcept
try {
+Type InferTypeExpandDims(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
const auto* attrs = call->attrs.as<ExpandDimsAttrs>();
@@ -452,10 +452,6 @@ ffi::Expected<Type> InferTypeExpandDims(const CallNode*
call_node) noexcept try
}
TVM_FFI_ICHECK_EQ(i_data_shape, data_ty->ndim);
return TensorType(ShapeExpr(output_shape), data_ty->dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutExpandDims(
@@ -528,7 +524,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.flatten", flatten);
}
-ffi::Expected<Type> InferTypeFlatten(const CallNode* call_node) noexcept try {
+Type InferTypeFlatten(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
if (data_ty->IsUnknownNdim()) {
@@ -545,10 +541,6 @@ ffi::Expected<Type> InferTypeFlatten(const CallNode*
call_node) noexcept try {
}
PrimExpr shape_prod = ComputeShapeProduct(data_shape->values);
return TensorType(ShapeExpr({std::move(shape_prod)}), data_ty->dtype,
data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -725,7 +717,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.layout_transform", layout_transform);
}
-ffi::Expected<Type> InferTypeLayoutTransform(const CallNode* call_node)
noexcept try {
+Type InferTypeLayoutTransform(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
const auto* attrs = call->attrs.as<LayoutTransformAttrs>();
@@ -768,10 +760,6 @@ ffi::Expected<Type> InferTypeLayoutTransform(const
CallNode* call_node) noexcept
sym::Analyzer analyzer;
ffi::Array<PrimExpr> output_shape =
index_map->MapShape(shape_ty->values.value(), analyzer);
return TensorType(ShapeExpr(output_shape), data_ty->dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -806,7 +794,7 @@ bool IsIdentityPermutation(const std::vector<int>&
permutation) {
return true;
}
-ffi::Expected<Type> InferTypePermuteDims(const CallNode* call_node) noexcept
try {
+Type InferTypePermuteDims(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
@@ -850,10 +838,6 @@ ffi::Expected<Type> InferTypePermuteDims(const CallNode*
call_node) noexcept try
new_shape.push_back(data_shape->values[axes[i]]);
}
return TensorType(ShapeExpr(new_shape), data_ty->dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutPermuteDims(
@@ -1262,7 +1246,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.squeeze", squeeze);
}
-ffi::Expected<Type> InferTypeSqueeze(const CallNode* call_node) noexcept try {
+Type InferTypeSqueeze(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
const auto* attrs = call->attrs.as<SqueezeAttrs>();
@@ -1336,10 +1320,6 @@ ffi::Expected<Type> InferTypeSqueeze(const CallNode*
call_node) noexcept try {
} else {
return TensorType(ShapeExpr(output_shape), data_ty->dtype,
data_ty->vdevice);
}
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutSqueeze(
@@ -2046,7 +2026,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.flip", flip);
}
-ffi::Expected<Type> InferTypeFlip(const CallNode* call_node) noexcept try {
+Type InferTypeFlip(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 1) {
TVM_FFI_VISIT_THROW(ValueError, call) << "Flip op should take 1 argument";
@@ -2063,10 +2043,6 @@ ffi::Expected<Type> InferTypeFlip(const CallNode*
call_node) noexcept try {
}
}
return data_ty;
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutFlip(
@@ -2218,7 +2194,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.gather_elements", gather_elements);
}
-ffi::Expected<Type> InferTypeGatherElements(const CallNode* call_node)
noexcept try {
+Type InferTypeGatherElements(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
const auto* data_ty = GetTypeAs<TensorTypeNode>(call->args[0]);
const auto* indices_ty = GetTypeAs<TensorTypeNode>(call->args[1]);
@@ -2263,10 +2239,6 @@ ffi::Expected<Type> InferTypeGatherElements(const
CallNode* call_node) noexcept
return TensorType(indices_ty->shape.value(), data_ty->dtype,
data_ty->vdevice);
}
return TensorType(data_ty->dtype, indices_ty->ndim, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutGatherElements(
@@ -2325,7 +2297,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.gather_nd", gather_nd);
}
-ffi::Expected<Type> InferTypeGatherND(const CallNode* call_node) noexcept try {
+Type InferTypeGatherND(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
const auto* data_ty = GetTypeAs<TensorTypeNode>(call->args[0]);
const auto* indices_ty = GetTypeAs<TensorTypeNode>(call->args[1]);
@@ -2395,10 +2367,6 @@ ffi::Expected<Type> InferTypeGatherND(const CallNode*
call_node) noexcept try {
}
TVM_FFI_ICHECK_EQ(out_shape.size(), output_ndim);
return TensorType(ShapeExpr(out_shape), data_ty->dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -2423,7 +2391,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.index_put", index_put);
}
-ffi::Expected<Type> InferTypeIndexPut(const CallNode* call_node) noexcept try {
+Type InferTypeIndexPut(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
const auto* data_ty = GetTypeAs<TensorTypeNode>(call->args[0]);
const auto* values_ty = GetTypeAs<TensorTypeNode>(call->args[2]);
@@ -2550,10 +2518,6 @@ ffi::Expected<Type> InferTypeIndexPut(const CallNode*
call_node) noexcept try {
return TensorType(ShapeExpr(data_shape->values), data_ty->dtype,
data_ty->vdevice);
}
return TensorType(data_ty->dtype, data_ty->ndim, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -2579,7 +2543,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.meshgrid", meshgrid);
}
-ffi::Expected<Type> InferTypeMeshgrid(const CallNode* call_node) noexcept try {
+Type InferTypeMeshgrid(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 1) {
TVM_FFI_VISIT_THROW(ValueError, call) << "meshgrid op expects 1 Tuple
input argument.";
@@ -2661,10 +2625,6 @@ ffi::Expected<Type> InferTypeMeshgrid(const CallNode*
call_node) noexcept try {
}
return TupleType(out_fields);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -3179,7 +3139,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.one_hot", one_hot);
}
-ffi::Expected<Type> InferTypeOneHot(const CallNode* call_node) noexcept try {
+Type InferTypeOneHot(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType indices_ty = GetInputTensorType(call, 0);
const auto* attrs = call->attrs.as<OneHotAttrs>();
@@ -3227,10 +3187,6 @@ ffi::Expected<Type> InferTypeOneHot(const CallNode*
call_node) noexcept try {
output_shape.insert(output_shape.begin() + axis, attrs->depth);
return TensorType(ShapeExpr(output_shape), dtype, indices_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/tensor/sampling.cc b/src/relax/op/tensor/sampling.cc
index 84a5ca34be..cd5c513cd6 100644
--- a/src/relax/op/tensor/sampling.cc
+++ b/src/relax/op/tensor/sampling.cc
@@ -54,7 +54,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.multinomial_from_uniform",
multinomial_from_uniform);
}
-ffi::Expected<Type> InferTypeMultinomialFromUniform(const CallNode* call_node)
noexcept try {
+Type InferTypeMultinomialFromUniform(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
CheckNumArguments(call);
TensorType prob_ty = GetInputTensorType(call, 0);
@@ -143,10 +143,6 @@ ffi::Expected<Type> InferTypeMultinomialFromUniform(const
CallNode* call_node) n
<< sample_indices_ty->shape;
}
return TensorType(ShapeExpr({n, 1}), PrimType(attrs->dtype),
prob_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/tensor/search.cc b/src/relax/op/tensor/search.cc
index fa46ec670b..9b837400e2 100644
--- a/src/relax/op/tensor/search.cc
+++ b/src/relax/op/tensor/search.cc
@@ -54,7 +54,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.bucketize", bucketize);
}
-ffi::Expected<Type> InferTypeBucketize(const CallNode* call_node) noexcept try
{
+Type InferTypeBucketize(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
ffi::Array<TensorType> input_ty = GetInputTensorType(call);
TensorType input_tensor_info = input_ty[0];
@@ -76,10 +76,6 @@ ffi::Expected<Type> InferTypeBucketize(const CallNode*
call_node) noexcept try {
return TensorType(ShapeExpr(data_shape->values), out_dtype,
input_tensor_info->vdevice);
}
return TensorType(out_dtype, input_tensor_info->ndim,
input_tensor_info->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -199,7 +195,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
/* relax.argmax & relax.argmin */
-ffi::Expected<Type> InferTypeArgmaxArgmin(const CallNode* call_node) noexcept
try {
+Type InferTypeArgmaxArgmin(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
const auto* attrs = call->attrs.as<ArgmaxArgminAttrs>();
@@ -256,10 +252,6 @@ ffi::Expected<Type> InferTypeArgmaxArgmin(const CallNode*
call_node) noexcept tr
}
TVM_FFI_ICHECK_EQ(static_cast<int>(out_shape.size()), out_ndim);
return TensorType(ShapeExpr(out_shape), out_dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
Expr argmax(Expr x, ffi::Optional<int64_t> axis, bool keepdims) {
diff --git a/src/relax/op/tensor/set.cc b/src/relax/op/tensor/set.cc
index e77ecfba1b..d8a1a18617 100644
--- a/src/relax/op/tensor/set.cc
+++ b/src/relax/op/tensor/set.cc
@@ -57,7 +57,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.unique", unique);
}
-ffi::Expected<Type> InferTypeUnique(const CallNode* call_node) noexcept try {
+Type InferTypeUnique(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = call->args[0]->ty.as_or_throw<TensorType>();
PrimExpr axis, return_index, return_inverse, return_counts;
@@ -140,10 +140,6 @@ ffi::Expected<Type> InferTypeUnique(const CallNode*
call_node) noexcept try {
} else {
return TupleType(output_ty);
}
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -181,14 +177,10 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.nonzero", nonzero);
}
-ffi::Expected<Type> InferTypeNonzero(const CallNode* call_node) noexcept try {
+Type InferTypeNonzero(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetInputTensorType(call, 0);
return TensorType(PrimType::Int(64), 2, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/tensor/sorting.cc b/src/relax/op/tensor/sorting.cc
index cef5d9709e..5d8a58384a 100644
--- a/src/relax/op/tensor/sorting.cc
+++ b/src/relax/op/tensor/sorting.cc
@@ -53,13 +53,9 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.sort", sort);
}
-ffi::Expected<Type> InferTypeSort(const CallNode* call_node) noexcept try {
+Type InferTypeSort(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
return GetUnaryInputTensorType(call);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -86,7 +82,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.argsort", argsort);
}
-ffi::Expected<Type> InferTypeArgsort(const CallNode* call_node) noexcept try {
+Type InferTypeArgsort(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
const auto* attrs = call->attrs.as<ArgsortAttrs>();
@@ -97,10 +93,6 @@ ffi::Expected<Type> InferTypeArgsort(const CallNode*
call_node) noexcept try {
return TensorType(data_ty->shape.value(), out_type, data_ty->vdevice);
}
return TensorType(out_type, data_ty->ndim, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -130,7 +122,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.topk", topk);
}
-ffi::Expected<Type> InferTypeTopK(const CallNode* call_node) noexcept try {
+Type InferTypeTopK(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
const auto* data_shape = data_ty->shape.as<ShapeExprNode>();
@@ -170,10 +162,6 @@ ffi::Expected<Type> InferTypeTopK(const CallNode*
call_node) noexcept try {
}
TVM_FFI_THROW(InternalError) << "Unsupported ret type: " << ret_type;
TVM_FFI_UNREACHABLE();
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/tensor/statistical.cc
b/src/relax/op/tensor/statistical.cc
index d1803da6f4..0e0b743cf2 100644
--- a/src/relax/op/tensor/statistical.cc
+++ b/src/relax/op/tensor/statistical.cc
@@ -37,7 +37,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
ScanopAttrs::RegisterReflection();
}
-ffi::Expected<Type> InferTypeStatistical(const CallNode* call_node) noexcept
try {
+Type InferTypeStatistical(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
const auto* attrs = call->attrs.as<StatisticalAttrs>();
@@ -89,10 +89,6 @@ ffi::Expected<Type> InferTypeStatistical(const CallNode*
call_node) noexcept try
}
TVM_FFI_ICHECK_EQ(static_cast<int>(out_shape.size()), out_ndim);
return TensorType(ShapeExpr(out_shape), data_ty->dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
InferLayoutOutput InferLayoutStatistical(
@@ -156,7 +152,7 @@ InferLayoutOutput InferLayoutStatistical(
Attrs(new_attrs));
}
-ffi::Expected<Type> InferTypeScan(const CallNode* call_node) noexcept try {
+Type InferTypeScan(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
const auto* attrs = call->attrs.as<ScanopAttrs>();
@@ -184,13 +180,9 @@ ffi::Expected<Type> InferTypeScan(const CallNode*
call_node) noexcept try {
} else {
return TensorType(out_type, data_ty->ndim, data_ty->vdevice);
}
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
-ffi::Expected<Type> InferTypeStatisticalExtension(const CallNode* call_node)
noexcept try {
+Type InferTypeStatisticalExtension(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
TensorType data_ty = GetUnaryInputTensorType(call);
const auto* attrs = call->attrs.as<StatisticalAttrs>();
@@ -248,10 +240,6 @@ ffi::Expected<Type> InferTypeStatisticalExtension(const
CallNode* call_node) noe
else
return TupleType({TensorType(ShapeExpr(out_shape), data_ty->dtype,
data_ty->vdevice),
TensorType(ShapeExpr(out_shape), PrimType::Int(64),
data_ty->vdevice)});
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
/* relax.cumprod */
diff --git a/src/relax/op/tensor/unary.cc b/src/relax/op/tensor/unary.cc
index 9ee0a8c561..71fae30c1c 100644
--- a/src/relax/op/tensor/unary.cc
+++ b/src/relax/op/tensor/unary.cc
@@ -31,13 +31,9 @@
namespace tvm {
namespace relax {
-ffi::Expected<Type> InferTypeUnaryCheck(const CallNode* call_node) noexcept
try {
+Type InferTypeUnaryCheck(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
return InferTypeUnary<false>(call, [](const TensorType& input_ty) { return
PrimType::Bool(); });
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
/***************** Arithmetic operators *****************/
diff --git a/src/relax/op/vision/multibox_transform_loc.cc
b/src/relax/op/vision/multibox_transform_loc.cc
index 58e2712732..6410fcadd1 100644
--- a/src/relax/op/vision/multibox_transform_loc.cc
+++ b/src/relax/op/vision/multibox_transform_loc.cc
@@ -68,7 +68,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
* skips those N-based relations; other checks (ndim, dtype, loc dim divisible
by 4, etc.)
* still apply when their inputs are known.
*/
-ffi::Expected<Type> InferTypeMultiboxTransformLoc(const CallNode* call_node)
noexcept try {
+Type InferTypeMultiboxTransformLoc(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 3) {
TVM_FFI_VISIT_THROW(ValueError, call)
@@ -186,10 +186,6 @@ ffi::Expected<Type> InferTypeMultiboxTransformLoc(const
CallNode* call_node) noe
ffi::Array<Type> fields = {TensorType(ShapeExpr(boxes_shape), cls_ty->dtype,
vdev),
TensorType(ShapeExpr(scores_shape),
cls_ty->dtype, vdev)};
return TupleType(fields);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/vision/nms.cc b/src/relax/op/vision/nms.cc
index 59a41f37a3..b759a6ec97 100644
--- a/src/relax/op/vision/nms.cc
+++ b/src/relax/op/vision/nms.cc
@@ -63,7 +63,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
all_class_non_max_suppression);
}
-ffi::Expected<Type> InferTypeAllClassNMS(const CallNode* call_node) noexcept
try {
+Type InferTypeAllClassNMS(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
tvm::ffi::Array<TensorType> input_ty = GetInputTensorType(call);
const auto boxes_ty = input_ty[0];
@@ -102,10 +102,6 @@ ffi::Expected<Type> InferTypeAllClassNMS(const CallNode*
call_node) noexcept try
TensorType(scores_shape,
PrimType::Float(32), vdev),
TensorType(counts_shape, PrimType::Int(64),
vdev)};
return TupleType(fields);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
@@ -139,7 +135,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.vision.get_valid_counts", get_valid_counts);
}
-ffi::Expected<Type> InferTypeGetValidCounts(const CallNode* call_node)
noexcept try {
+Type InferTypeGetValidCounts(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 1) {
TVM_FFI_VISIT_THROW(ValueError, call)
@@ -188,10 +184,6 @@ ffi::Expected<Type> InferTypeGetValidCounts(const
CallNode* call_node) noexcept
TensorType(ShapeExpr({batch, num_anchors, elem_length}), data_ty->dtype,
vdev),
TensorType(ShapeExpr({batch, num_anchors}), PrimType::Int(32), vdev)};
return TupleType(fields);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/vision/roi_align.cc b/src/relax/op/vision/roi_align.cc
index 2ba5820b8e..50042f4828 100644
--- a/src/relax/op/vision/roi_align.cc
+++ b/src/relax/op/vision/roi_align.cc
@@ -60,7 +60,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.vision.roi_align", roi_align);
}
-ffi::Expected<Type> InferTypeROIAlign(const CallNode* call_node) noexcept try {
+Type InferTypeROIAlign(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 2) {
TVM_FFI_VISIT_THROW(ValueError, call)
@@ -127,10 +127,6 @@ ffi::Expected<Type> InferTypeROIAlign(const CallNode*
call_node) noexcept try {
IntImm::Int32(attrs->pooled_size[1]), data_shape[3]};
}
return TensorType(ShapeExpr(out_shape), data_ty->dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {
diff --git a/src/relax/op/vision/roi_pool.cc b/src/relax/op/vision/roi_pool.cc
index 54af51a697..7a95b2759e 100644
--- a/src/relax/op/vision/roi_pool.cc
+++ b/src/relax/op/vision/roi_pool.cc
@@ -57,7 +57,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
refl::GlobalDef().def("relax.op.vision.roi_pool", roi_pool);
}
-ffi::Expected<Type> InferTypeROIPool(const CallNode* call_node) noexcept try {
+Type InferTypeROIPool(const CallNode* call_node) {
const Call call = ffi::GetRef<Call>(call_node);
if (call->args.size() != 2) {
TVM_FFI_VISIT_THROW(ValueError, call)
@@ -115,10 +115,6 @@ ffi::Expected<Type> InferTypeROIPool(const CallNode*
call_node) noexcept try {
IntImm::Int32(attrs->pooled_size[0]),
IntImm::Int32(attrs->pooled_size[1])};
return TensorType(ShapeExpr(out_shape), data_ty->dtype, data_ty->vdevice);
-} catch (const ffi::Error& error) {
- return ffi::Unexpected(error);
-} catch (const std::exception& error) {
- return ffi::Unexpected(ffi::Error("InternalError", error.what(), ""));
}
TVM_FFI_STATIC_INIT_BLOCK() {