Aleksei-grovety commented on code in PR #15983:
URL: https://github.com/apache/tvm/pull/15983#discussion_r1377672381
##########
include/tvm/runtime/packed_func.h:
##########
@@ -549,25 +586,41 @@ class TVMPODValue_ {
// the frontend while the API expects a float.
if (type_code_ == kDLInt) {
return static_cast<double>(value_.v_int64);
+ } else if (auto opt = ThroughObjectRef<double>()) {
+ return opt.value();
+ } else if (auto opt = ThroughObjectRef<int64_t>()) {
+ return opt.value();
Review Comment:
Shouldn't there be `static_cast<double>`, as in line 588?
##########
tests/cpp/packed_func_test.cc:
##########
@@ -319,3 +319,62 @@ TEST(TypedPackedFunc, RValue) {
tf(1, true);
}
}
+
+TEST(TypedPackedFunc, IntImmWrapper) {
+ using namespace tvm::runtime;
+
+ TypedPackedFunc<void(int)> typed_func = [](int x) {};
+ PackedFunc func = typed_func;
+
+ // Integer argument may be provided
+ func(5);
+
+ // IntImm argument may be provided, automatically unwrapped.
+ tvm::IntImm lvalue_intimm(DataType::Int(32), 10);
+ func(lvalue_intimm);
+
+ // Unwrapping of IntImm argument works for rvalues as well
+ func(tvm::IntImm(DataType::Int(32), 10));
+}
+
+TEST(TypedPackedFunc, FloatImmWrapper) {
+ using namespace tvm::runtime;
+
+ TypedPackedFunc<void(double)> typed_func = [](double x) {};
+ PackedFunc func = typed_func;
+
+ // Argument may be provided as a floating point. If provided as an
Review Comment:
Trailing whitespace.
##########
include/tvm/runtime/packed_func.h:
##########
@@ -537,6 +538,42 @@ struct ObjectTypeChecker<Map<K, V>> {
}
};
+class TVMPODValue_;
+
+/*!
+ * \brief Type trait to specify special value conversion rules from
+ * ObjectRef to primitive types.
+ *
+ * TVM containers, such as tvm::runtime::Array, require the contained
+ * objects to inherit from ObjectRef. As a result, the wrapper types
Review Comment:
Trailing whitespace, also in lines 550, 552.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]