@@ -163,6 +163,13 @@ inline const char* TypeCode2Str(int type_code);
163163 */
164164inline TVMType String2TVMType (std::string s);
165165
166+ /* !
167+ * \brief convert a TVM type to string.
168+ * \param t The type to be converted.
169+ * \return The corresponding tvm type in string.
170+ */
171+ inline std::string TVMType2String (TVMType t);
172+
166173// macro to check type code.
167174#define TVM_CHECK_TYPE_CODE (CODE, T ) \
168175 CHECK_EQ (CODE, T) << " expected " \
@@ -258,6 +265,9 @@ class TVMArgValue : public TVMPODValue_ {
258265 using TVMPODValue_::operator TVMArray*;
259266 // conversion operator.
260267 operator std::string () const {
268+ if (type_code_ == kTVMType ) {
269+ return TVMType2String (operator TVMType ());
270+ }
261271 TVM_CHECK_TYPE_CODE (type_code_, kStr );
262272 return std::string (value_.v_str );
263273 }
@@ -308,7 +318,6 @@ class TVMRetValue : public TVMPODValue_ {
308318 */
309319 TVMRetValue (TVMRetValue&& other)
310320 : TVMPODValue_(other.value_, other.type_code_) {
311- other.type_code_ = kNull ;
312321 }
313322 /* ! \brief destructor */
314323 ~TVMRetValue () {
@@ -328,6 +337,9 @@ class TVMRetValue : public TVMPODValue_ {
328337 }
329338 // conversion operators
330339 operator std::string () const {
340+ if (type_code_ == kTVMType ) {
341+ return TVMType2String (operator TVMType ());
342+ }
331343 TVM_CHECK_TYPE_CODE (type_code_, kStr );
332344 return *ptr<std::string>();
333345 }
@@ -418,6 +430,13 @@ class TVMRetValue : public TVMPODValue_ {
418430 *ret_type_code = type_code_;
419431 type_code_ = kNull ;
420432 }
433+ /* ! \return The value field, if the data is POD */
434+ const TVMValue& value () const {
435+ CHECK (type_code_ != kNodeHandle &&
436+ type_code_ != kFuncHandle &&
437+ type_code_ != kStr ) << " TVMRetValue.value can only be used for POD data" ;
438+ return value_;
439+ }
421440 // NodeRef related extenstions: in tvm/packed_func_ext.h
422441 inline TVMRetValue& operator =(const NodeRef& other);
423442 inline TVMRetValue& operator =(const std::shared_ptr<Node>& other);
@@ -488,7 +507,7 @@ inline const char* TypeCode2Str(int type_code) {
488507 case kInt : return " int" ;
489508 case kFloat : return " float" ;
490509 case kStr : return " str" ;
491- case kHandle : return " Handle " ;
510+ case kHandle : return " handle " ;
492511 case kNull : return " NULL" ;
493512 case kNodeHandle : return " NodeHandle" ;
494513 case kArrayHandle : return " ArrayHandle" ;
@@ -499,6 +518,21 @@ inline const char* TypeCode2Str(int type_code) {
499518 }
500519}
501520
521+ inline std::ostream& operator <<(std::ostream& os, TVMType t) { // NOLINT(*)
522+ os << TypeCode2Str (t.code )
523+ << static_cast <int >(t.bits );
524+ if (t.lanes != 1 ) {
525+ os << ' x' << static_cast <int >(t.lanes );
526+ }
527+ return os;
528+ }
529+
530+ inline std::string TVMType2String (TVMType t) {
531+ std::ostringstream os;
532+ os << t;
533+ return os.str ();
534+ }
535+
502536inline TVMType String2TVMType (std::string s) {
503537 TVMType t;
504538 t.bits = 32 ; t.lanes = 1 ;
0 commit comments