24 #ifndef TVM_RUNTIME_PACKED_FUNC_H_
25 #define TVM_RUNTIME_PACKED_FUNC_H_
32 #include <tvm/runtime/logging.h>
42 #include <type_traits>
47 #ifndef TVM_RUNTIME_HEADER_ONLY
48 #define TVM_RUNTIME_HEADER_ONLY 0
57 class TVMMovableArgValueWithContext_;
60 template <
typename FType>
62 template <
typename TSignature>
79 static constexpr
const char*
_type_key =
"runtime.PackedFunc";
86 template <
class TPackedFuncSubObj>
114 template <
class TCallable>
116 using TStorage =
typename std::remove_cv<typename std::remove_reference<TCallable>::type>::type;
148 template <
typename TCallable,
149 typename = std::enable_if_t<
151 !std::is_base_of<TCallable, PackedFunc>::value>>
154 data_ = make_object<ObjType>(std::forward<TCallable>(data));
170 template <
typename... Args>
192 template <
typename FType>
227 template <
typename R,
typename... Args>
285 template <
typename FLambda,
typename =
typename std::enable_if<std::is_convertible<
286 FLambda, std::function<R(Args...)>>::value>::type>
288 this->AssignTypedLambda(typed_lambda, name);
308 template <
typename FLambda,
typename =
typename std::enable_if<std::is_convertible<
309 FLambda, std::function<R(Args...)>>::value>::type>
311 this->AssignTypedLambda(typed_lambda);
329 template <
typename FLambda,
typename =
typename std::enable_if<
330 std::is_convertible<FLambda,
331 std::function<R(Args...)>>::value>::type>
333 this->AssignTypedLambda(typed_lambda);
350 TVM_ALWAYS_INLINE R operator()(Args... args)
const;
361 bool operator==(std::nullptr_t
null)
const {
return packed_ ==
nullptr; }
363 bool operator!=(std::nullptr_t
null)
const {
return packed_ !=
nullptr; }
377 template <
typename FLambda>
378 inline void AssignTypedLambda(FLambda flambda, std::string name);
387 template <
typename FLambda>
388 inline void AssignTypedLambda(FLambda flambda);
406 inline int size()
const;
422 inline std::ostream&
operator<<(std::ostream& os, DLDevice dev);
425 #define TVM_CHECK_TYPE_CODE(CODE, T) \
426 ICHECK_EQ(CODE, T) << "expected " << ArgTypeCode2Str(T) << " but got " << ArgTypeCode2Str(CODE)
432 template <
typename T>
442 using ContainerType =
typename T::ContainerType;
443 if (ptr ==
nullptr) {
444 if (T::_type_is_nullable) {
462 using ContainerType =
typename T::ContainerType;
463 if (ptr ==
nullptr)
return T::_type_is_nullable;
467 using ContainerType =
typename T::ContainerType;
468 return ContainerType::_type_key;
473 template <
typename T>
476 if (ptr ==
nullptr) {
483 for (
size_t i = 0; i < n->
size(); i++) {
487 return String(
"Array[index " + std::to_string(i) +
": " + check_subtype.
value() +
"]");
493 if (ptr ==
nullptr)
return true;
505 template <
typename K,
typename V>
508 if (ptr ==
nullptr)
return NullOpt;
511 for (
const auto& kv : *n) {
515 std::string key_name =
517 std::string value_name = value_type.
defined() ? std::string(value_type.
value())
519 return String(
"Map[" + key_name +
", " + value_name +
"]");
525 if (ptr ==
nullptr)
return true;
528 for (
const auto& kv : *n) {
546 operator double()
const {
556 operator int64_t()
const {
560 operator uint64_t()
const {
564 operator int()
const {
570 operator bool()
const {
574 operator void*()
const {
580 operator DLTensor*()
const {
585 LOG(FATAL) <<
"Expected "
619 template <
typename T>
624 template <
typename TObjectRef,
625 typename =
typename std::enable_if<std::is_base_of<ObjectRef, TObjectRef>::value>::type>
627 template <
typename TObjectRef>
660 using TVMPODValue_::operator double;
661 using TVMPODValue_::operator int64_t;
662 using TVMPODValue_::operator uint64_t;
663 using TVMPODValue_::operator int;
664 using TVMPODValue_::operator bool;
665 using TVMPODValue_::operator
void*;
666 using TVMPODValue_::operator DLTensor*;
667 using TVMPODValue_::operator
NDArray;
668 using TVMPODValue_::operator
Device;
669 using TVMPODValue_::operator
Module;
675 operator std::string()
const {
680 return std::string(arr->
data, arr->
size);
684 return AsObjectRef<tvm::runtime::String>().operator std::string();
687 template <
typename FType>
693 template <typename T, typename = typename std::enable_if<std::is_class<T>::value>::type>
694 inline operator T()
const;
695 inline operator DLDataType()
const;
713 using TVMPODValue_::operator double;
714 using TVMPODValue_::operator int64_t;
715 using TVMPODValue_::operator uint64_t;
716 using TVMPODValue_::operator int;
717 using TVMPODValue_::operator bool;
718 using TVMPODValue_::operator
void*;
719 using TVMPODValue_::operator DLTensor*;
720 using TVMPODValue_::operator
NDArray;
721 using TVMPODValue_::operator
Device;
722 using TVMPODValue_::operator
Module;
725 operator std::string()
const {
return AsArgValue().operator std::string(); }
726 template <
typename FType>
730 operator DLDataType()
const {
return AsArgValue().operator DLDataType(); }
738 template <
typename T,
739 typename =
typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
740 inline operator T()
const;
766 const std::string* optional_name,
FSig* f_sig)
767 : value_(value, type_code),
768 arg_index_(arg_index),
769 optional_name_(optional_name),
772 template <
typename T>
776 }
catch (dmlc::Error& e) {
777 LOG(FATAL) <<
"In function " << (optional_name_ ==
nullptr ?
"<anonymous>" : *optional_name_)
778 << (f_sig_ ==
nullptr ?
"" : (*f_sig_)()) <<
": error while converting argument "
779 << arg_index_ <<
": " << e.what();
787 const std::string* optional_name_;
814 using TVMPODValue_::operator double;
815 using TVMPODValue_::operator int64_t;
816 using TVMPODValue_::operator uint64_t;
817 using TVMPODValue_::operator int;
818 using TVMPODValue_::operator bool;
819 using TVMPODValue_::operator
void*;
820 using TVMPODValue_::operator DLTensor*;
821 using TVMPODValue_::operator
Device;
822 using TVMPODValue_::operator
NDArray;
823 using TVMPODValue_::operator
Module;
830 operator std::string()
const {
834 return *ptr<std::string>();
837 return *ptr<std::string>();
839 operator DLDataType()
const {
847 template <
typename FType>
860 this->SwitchToPOD(kDLFloat);
875 this->SwitchToPOD(kDLInt);
880 this->SwitchToPOD(kDLInt);
896 this->SwitchToPOD(kDLInt);
909 if (other.
data_ !=
nullptr) {
928 template <
typename FType>
979 <<
"TVMRetValue.value can only be used for POD data";
983 template <
typename TObjectRef,
984 typename =
typename std::enable_if<std::is_base_of<ObjectRef, TObjectRef>::value>::type>
986 template <typename T, typename = typename std::enable_if<std::is_class<T>::value>::type>
987 inline operator T()
const;
990 template <
typename T>
991 void Assign(
const T& other) {
992 switch (other.type_code()) {
994 SwitchToClass<std::string>(
kTVMStr, other);
998 SwitchToClass<std::string>(
kTVMBytes, other);
1002 *
this = other.operator PackedFunc();
1006 *
this = other.operator Module();
1010 *
this = other.operator NDArray();
1016 GetObjectPtr<Object>(
static_cast<Object*
>(other.value_.v_handle)));
1024 SwitchToPOD(other.type_code());
1037 template <
typename T>
1038 void SwitchToClass(
int type_code, T v) {
1047 void SwitchToObject(
int type_code, ObjectPtr<Object> other) {
1048 if (other.data_ !=
nullptr) {
1053 other.data_ =
nullptr;
1064 delete ptr<std::string>();
1095 template <
typename TObjectRef>
1130 #define TVM_DLL_EXPORT_PACKED_FUNC(ExportName, Function) \
1132 TVM_DLL int ExportName(TVMValue* args, int* type_code, int num_args, TVMValue* out_value, \
1133 int* out_type_code, void* resource_handle); \
1134 int ExportName(TVMValue* args, int* type_code, int num_args, TVMValue* out_value, \
1135 int* out_type_code, void* resource_handle) { \
1137 ::tvm::runtime::TVMRetValue rv; \
1138 Function(::tvm::runtime::TVMArgs(args, type_code, num_args), &rv); \
1139 rv.MoveToCHost(out_value, out_type_code); \
1141 } catch (const ::std::exception& _except_) { \
1142 TVMAPISetLastError(_except_.what()); \
1148 #define TVM_MODULE_VTABLE_BEGIN(TypeKey) \
1149 const char* type_key() const final { return TypeKey; } \
1150 PackedFunc GetFunction(const String& _name, const ObjectPtr<Object>& _self) final { \
1151 using SelfPtr = std::remove_cv_t<decltype(this)>;
1152 #define TVM_MODULE_VTABLE_END() \
1153 return PackedFunc(nullptr); \
1155 #define TVM_MODULE_VTABLE_ENTRY(Name, MemFunc) \
1156 if (_name == Name) { \
1157 return PackedFunc([_self](TVMArgs args, TVMRetValue* rv) -> void { \
1158 using Helper = ::tvm::runtime::detail::ModuleVTableEntryHelper<decltype(MemFunc)>; \
1159 SelfPtr self = static_cast<SelfPtr>(_self.get()); \
1160 CHECK_EQ(args.size(), Helper::LenArgs) \
1161 << "Function `" << self->type_key() << "::" << Name << "` requires " << Helper::LenArgs \
1162 << " arguments, but got " << args.size(); \
1163 Helper::Call(rv, self, MemFunc, args, Helper::IndexSeq{}); \
1166 #define TVM_MODULE_VTABLE_ENTRY_PACKED(Name, Func) \
1167 if (_name == Name) { \
1169 using FType = ::tvm::runtime::detail::function_signature<decltype(f)>::FType; \
1170 return TypedPackedFunc<FType>(std::move(f)).packed(); \
1208 #define TVM_DLL_EXPORT_TYPED_FUNC(ExportName, Function) \
1210 TVM_DLL int ExportName(TVMValue* args, int* type_code, int num_args, TVMValue* out_value, \
1211 int* out_type_code, void* resource_handle) { \
1213 auto f = Function; \
1214 using FType = ::tvm::runtime::detail::function_signature<decltype(f)>::FType; \
1215 ::tvm::runtime::TVMRetValue rv; \
1216 ::tvm::runtime::detail::unpack_call_by_signature<FType>::run( \
1217 f, ::tvm::runtime::TVMArgs(args, type_code, num_args), &rv); \
1218 rv.MoveToCHost(out_value, out_type_code); \
1220 } catch (const ::std::exception& _except_) { \
1221 TVMAPISetLastError(_except_.what()); \
1228 ICHECK_LT(i,
num_args) <<
"not enough argument passed, " <<
num_args <<
" passed"
1229 <<
" but request arg[" << i <<
"].";
1235 template <
class TPackedFuncSubObj>
1238 (
static_cast<const TPackedFuncSubObj*
>(obj))->callable_(args, rv);
1242 (*f_call_packed_)(
this, args, rv);
1251 switch (type_code) {
1267 return "ArrayHandle";
1269 return "DLDataType";
1273 return "FunctionHandle";
1275 return "ModuleHandle";
1277 return "NDArrayContainer";
1281 return "ObjectRValueRefArg";
1283 LOG(FATAL) <<
"unknown type_code=" <<
static_cast<int>(type_code);
1301 case kDLCUDAManaged:
1302 return "cuda_managed";
1332 LOG(FATAL) <<
"unknown type = " << type;
1339 template <
bool stop, std::
size_t I,
typename F>
1340 struct for_each_dispatcher {
1341 template <
typename T,
typename... Args>
1342 static void run(
const F& f, T&& value, Args&&... args) {
1343 f(I, std::forward<T>(value));
1344 for_each_dispatcher<
sizeof...(Args) == 0, (I + 1), F>::run(f, std::forward<Args>(args)...);
1348 template <std::
size_t I,
typename F>
1349 struct for_each_dispatcher<true, I, F> {
1350 static void run(
const F& f) {}
1353 template <
typename F,
typename... Args>
1354 inline void for_each(
const F& f, Args&&... args) {
1355 for_each_dispatcher<
sizeof...(Args) == 0, 0, F>::run(f, std::forward<Args>(args)...);
1358 template <
typename T>
1359 struct ModuleVTableEntryHelper {};
1361 template <
typename T,
typename R,
typename... Args>
1362 struct ModuleVTableEntryHelper<R (T::*)(Args...) const> {
1363 using MemFnType = R (T::*)(Args...)
const;
1364 using IndexSeq = std::index_sequence_for<Args...>;
1365 static constexpr
const std::size_t LenArgs =
sizeof...(Args);
1367 template <std::size_t... Is>
1368 static TVM_ALWAYS_INLINE
void Call(TVMRetValue* rv, T*
self, MemFnType f,
TVMArgs args,
1369 std::index_sequence<Is...>) {
1370 *rv = (
self->*f)(args[Is]...);
1374 template <
typename T,
typename R,
typename... Args>
1375 struct ModuleVTableEntryHelper<R (T::*)(Args...)> {
1376 using MemFnType = R (T::*)(Args...);
1377 using IndexSeq = std::index_sequence_for<Args...>;
1378 static constexpr
const std::size_t LenArgs =
sizeof...(Args);
1380 template <std::size_t... Is>
1381 static TVM_ALWAYS_INLINE
void Call(TVMRetValue* rv, T*
self, MemFnType f,
TVMArgs args,
1382 std::index_sequence<Is...>) {
1383 *rv = (
self->*f)(args[Is]...);
1387 template <
typename T,
typename... Args>
1388 struct ModuleVTableEntryHelper<void (T::*)(Args...) const> {
1389 using MemFnType = void (T::*)(Args...)
const;
1390 using IndexSeq = std::index_sequence_for<Args...>;
1391 static constexpr
const std::size_t LenArgs =
sizeof...(Args);
1393 template <std::size_t... Is>
1394 static TVM_ALWAYS_INLINE
void Call(TVMRetValue* rv, T*
self, MemFnType f,
TVMArgs args,
1395 std::index_sequence<Is...>) {
1396 (
self->*f)(args[Is]...);
1400 template <
typename T,
typename... Args>
1401 struct ModuleVTableEntryHelper<void (T::*)(Args...)> {
1402 using MemFnType = void (T::*)(Args...);
1403 using IndexSeq = std::index_sequence_for<Args...>;
1404 static constexpr
const std::size_t LenArgs =
sizeof...(Args);
1406 template <std::size_t... Is>
1407 static TVM_ALWAYS_INLINE
void Call(TVMRetValue* rv, T*
self, MemFnType f,
TVMArgs args,
1408 std::index_sequence<Is...>) {
1409 (
self->*f)(args[Is]...);
1413 namespace parameter_pack {
1415 template <
typename... EnumArgs>
1416 struct EnumeratedParamPack {
1417 struct InvokeWithoutArg {
1418 template <
template <
size_t i,
typename TArgument>
class Functor,
typename ExtraParams>
1419 static void F(ExtraParams&& extra_params) {
1420 using TExpander =
int[];
1423 (Functor<EnumArgs::i, typename EnumArgs::T>::F(std::forward<ExtraParams>(extra_params)),
1428 struct InvokeWithArg {
1429 template <
template <
size_t i,
typename TArgument>
class Functor,
typename ExtraParams,
1431 static void F(ExtraParams&& extra_params, Params&&... params) {
1432 using TExpander =
int[];
1435 (Functor<EnumArgs::i, typename EnumArgs::T>::F(std::forward<ExtraParams>(extra_params),
1436 std::forward<Params>(params)),
1443 template <
typename... Args>
1444 struct EnumerateImpl {
1446 template <
size_t _i,
typename _T>
1448 static const constexpr
size_t i = _i;
1452 template <
typename...>
1455 template <std::size_t...
id>
1456 struct Zipper<std::integer_sequence<std::size_t, id...>> {
1457 using WithoutArg =
typename EnumeratedParamPack<Item<id, Args>...>::InvokeWithoutArg;
1458 using WithArg =
typename EnumeratedParamPack<Item<id, Args>...>::InvokeWithArg;
1462 using WithoutArg =
typename Zipper<std::index_sequence_for<Args...>>::WithoutArg;
1463 using WithArg =
typename Zipper<std::index_sequence_for<Args...>>::WithArg;
1466 template <
typename... Args>
1467 using EnumerateWithoutArg =
typename EnumerateImpl<Args...>::WithoutArg;
1469 template <
typename... Args>
1470 using EnumerateWithArg =
typename EnumerateImpl<Args...>::WithArg;
1472 template <
typename... Args>
1474 template <
template <
size_t i,
typename TArgument>
class Functor,
typename ExtraParams>
1475 static void InvokeWithoutArg(ExtraParams&& extra_params) {
1476 EnumerateWithoutArg<Args...>::template F<Functor, ExtraParams>(
1477 std::forward<ExtraParams>(extra_params));
1487 template <
typename T>
1488 struct func_signature_helper {
1492 template <
typename T,
typename R,
typename... Args>
1493 struct func_signature_helper<R (T::*)(Args...)> {
1494 using FType = R(Args...);
1495 using ParamType = parameter_pack::ParamPack<Args...>;
1497 static_assert(!std::is_reference<R>::value,
"TypedPackedFunc return reference");
1500 template <
typename T,
typename R,
typename... Args>
1501 struct func_signature_helper<R (T::*)(Args...) const> {
1502 using FType = R(Args...);
1503 using ParamType = parameter_pack::ParamPack<Args...>;
1505 static_assert(!std::is_reference<R>::value,
"TypedPackedFunc return reference");
1512 template <
typename T>
1513 struct function_signature {
1514 using FType =
typename func_signature_helper<decltype(&T::operator())>::FType;
1515 using ParamType =
typename func_signature_helper<decltype(&T::operator())>::ParamType;
1516 using RetType =
typename func_signature_helper<decltype(&T::operator())>::RetType;
1520 template <
typename R,
typename... Args>
1521 struct function_signature<R(Args...)> {
1522 using FType = R(Args...);
1523 using ParamType = parameter_pack::ParamPack<Args...>;
1525 static_assert(!std::is_reference<R>::value,
"TypedPackedFunc return reference");
1529 template <
typename R,
typename... Args>
1530 struct function_signature<R (*)(Args...)> {
1531 using FType = R(Args...);
1532 using ParamType = detail::parameter_pack::ParamPack<Args...>;
1534 static_assert(!std::is_reference<R>::value,
"TypedPackedFunc return reference");
1537 template <
typename TSignature>
1538 struct SignaturePrinter;
1540 namespace type2str {
1542 template <
typename T>
1543 struct TypeSimplifier;
1545 template <
typename T>
1547 template <typename = std::enable_if_t<std::is_base_of<ObjectRef, T>::value>>
1548 static std::string v() {
1549 return T::ContainerType::_type_key;
1553 struct Type2Str<int> {
1554 static std::string v() {
return "int"; }
1557 struct Type2Str<double> {
1558 static std::string v() {
return "double"; }
1561 struct Type2Str<int64_t> {
1562 static std::string v() {
return "int64_t"; }
1565 struct Type2Str<uint64_t> {
1566 static std::string v() {
return "uint64_t"; }
1569 struct Type2Str<bool> {
1570 static std::string v() {
return "bool"; }
1573 struct Type2Str<void> {
1574 static std::string v() {
return "void"; }
1577 struct Type2Str<std::basic_string<char>> {
1578 static std::string v() {
return "basic_string<char>"; }
1580 template <
typename K,
typename V>
1581 struct Type2Str<Map<K, V>> {
1582 static std::string v() {
1583 return "Map<" + TypeSimplifier<K>::v() +
", " + TypeSimplifier<V>::v() +
">";
1587 struct Type2Str<DLDevice> {
1588 static std::string v() {
return "DLDevice"; }
1591 struct Type2Str<DLTensor> {
1592 static std::string v() {
return "DLTensor"; }
1596 static std::string v() {
return "DataType"; }
1599 struct Type2Str<DLDataType> {
1600 static std::string v() {
return "DLDataType"; }
1603 struct Type2Str<TVMRetValue> {
1604 static std::string v() {
return "TVMRetValue"; }
1607 struct Type2Str<TVMArgValue> {
1608 static std::string v() {
return "TVMArgValue"; }
1612 static std::string v() {
return "TVMByteArray"; }
1614 template <
typename FType>
1615 struct Type2Str<TypedPackedFunc<FType>> {
1616 static std::string v() {
return SignaturePrinter<function_signature<FType>>::F(); }
1618 template <
typename T>
1619 struct Type2Str<Array<T>> {
1620 static std::string v() {
return "Array<" + TypeSimplifier<T>::v() +
">"; }
1627 template <
typename T>
1628 struct TypeSimplifier {
1629 static std::string v() {
1630 using U =
typename std::remove_cv<
1631 typename std::remove_reference<typename std::remove_pointer<T>::type>::type>::type;
1632 return (std::is_const<T>::value ?
"const " :
"") + Type2Str<U>::v() +
1633 (std::is_pointer<T>::value ?
"*" :
"") + (std::is_reference<T>::value ?
"&" :
"");
1643 template <
typename TSignature>
1644 struct SignaturePrinter {
1645 using ParamType =
typename TSignature::ParamType;
1646 using RetType =
typename TSignature::RetType;
1648 template <
size_t i,
typename TArgument>
1649 struct PrintParamType {
1650 static void F(std::ostream& os) {
1651 os << (i == 0 ?
"" :
", ") << i <<
": " << type2str::TypeSimplifier<TArgument>::v();
1655 static std::string F() {
1656 std::ostringstream oss;
1658 ParamType::template InvokeWithoutArg<PrintParamType>(oss);
1659 oss <<
") -> " << type2str::TypeSimplifier<RetType>::v();
1670 template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
1672 values_[i].
v_int64 =
static_cast<int64_t
>(value);
1673 type_codes_[i] = kDLInt;
1675 TVM_ALWAYS_INLINE
void operator()(
size_t i, uint64_t value)
const {
1676 values_[i].
v_int64 =
static_cast<int64_t
>(value);
1678 type_codes_[i] = kDLInt;
1680 TVM_ALWAYS_INLINE
void operator()(
size_t i,
double value)
const {
1682 type_codes_[i] = kDLFloat;
1684 TVM_ALWAYS_INLINE
void operator()(
size_t i, std::nullptr_t value)
const {
1689 values_[i] = value.
value_;
1696 TVM_ALWAYS_INLINE
void operator()(
size_t i, DLTensor* value)
const {
1704 TVM_ALWAYS_INLINE
void operator()(
size_t i, DLDataType value)
const {
1705 values_[i].
v_type = value;
1711 TVM_ALWAYS_INLINE
void operator()(
size_t i,
const char* value)
const {
1712 values_[i].
v_str = value;
1716 TVM_ALWAYS_INLINE
void operator()(
size_t i,
const std::string& value)
const {
1717 values_[i].
v_str = value.c_str();
1724 template <
typename FType>
1730 values_[i].
v_str = value.
ptr<std::string>()->c_str();
1734 values_[i] = value.
value_;
1739 template <
typename TObjectRef,
1740 typename =
typename std::enable_if<std::is_base_of<ObjectRef, TObjectRef>::value>::type>
1741 TVM_ALWAYS_INLINE
void operator()(
size_t i,
const TObjectRef& value)
const {
1742 this->SetObject(i, value);
1745 template <
typename TObjectRef,
1746 typename =
typename std::enable_if<std::is_base_of<
1747 ObjectRef,
typename std::remove_reference<TObjectRef>::type>::value>::type>
1748 TVM_ALWAYS_INLINE
void operator()(
size_t i, TObjectRef&& value)
const {
1749 this->SetObject(i, std::forward<TObjectRef>(value));
1753 template <
typename TObjectRef>
1754 inline void SetObject(
size_t i, TObjectRef&& value)
const;
1761 template <
typename... Args>
1763 const int kNumArgs =
sizeof...(Args);
1764 const int kArraySize = kNumArgs > 0 ? kNumArgs : 1;
1766 int type_codes[kArraySize];
1767 detail::for_each(
TVMArgsSetter(values, type_codes), std::forward<Args>(args)...);
1770 ->CallPacked(
TVMArgs(values, type_codes, kNumArgs), &rv);
1774 template <
size_t i,
typename T>
1777 (*setter)(i, std::forward<T>(value));
1781 template <
typename... Args>
1784 detail::parameter_pack::EnumerateWithArg<Args...>::template F<TVMArgsSetterApply>(
1785 &setter, std::forward<Args>(args)...);
1789 template <
typename R,
int nleft,
int index,
typename F>
1790 struct unpack_call_dispatcher {
1791 template <
typename... Args>
1792 TVM_ALWAYS_INLINE
static void run(
const std::string* optional_name,
FSig* f_sig,
const F& f,
1794 Args&&... unpacked_args) {
1797 unpack_call_dispatcher<R, nleft - 1, index + 1, F>::run(
1798 optional_name, f_sig, f, args_pack, rv, std::forward<Args>(unpacked_args)...,
1799 TVMMovableArgValueWithContext_(args_pack.
values[index], args_pack.
type_codes[index], index,
1800 optional_name, f_sig));
1804 template <
typename R,
int index,
typename F>
1805 struct unpack_call_dispatcher<R, 0, index, F> {
1806 template <
typename... Args>
1807 TVM_ALWAYS_INLINE
static void run(
const std::string* optional_name,
FSig* f_sig,
const F& f,
1808 const TVMArgs& args_pack, TVMRetValue* rv,
1809 Args&&... unpacked_args) {
1810 using RetType = decltype(f(std::forward<Args>(unpacked_args)...));
1811 if (std::is_same<RetType, R>::value) {
1812 *rv = f(std::forward<Args>(unpacked_args)...);
1814 *rv = R(f(std::forward<Args>(unpacked_args)...));
1819 template <
int index,
typename F>
1820 struct unpack_call_dispatcher<void, 0, index, F> {
1821 template <
typename... Args>
1822 TVM_ALWAYS_INLINE
static void run(
const std::string* optional_name,
FSig* f_sig,
const F& f,
1823 const TVMArgs& args_pack, TVMRetValue* rv,
1824 Args&&... unpacked_args) {
1825 f(std::forward<Args>(unpacked_args)...);
1829 template <
typename R,
int nargs,
typename F>
1830 TVM_ALWAYS_INLINE
void unpack_call(
const std::string* optional_name,
const F& f,
1831 const TVMArgs& args, TVMRetValue* rv) {
1832 FSig* f_sig = detail::SignaturePrinter<detail::function_signature<F>>::F;
1833 CHECK_EQ(nargs, args.size()) <<
"Function "
1834 << (optional_name ==
nullptr ?
"<anonymous>" : *optional_name)
1835 << (f_sig ==
nullptr ?
"" : (*f_sig)()) <<
" expects " << nargs
1836 <<
" arguments but " << args.size() <<
" were provided";
1837 unpack_call_dispatcher<R, nargs, 0, F>::run(optional_name, f_sig, f, args, rv);
1840 template <
typename FType>
1841 struct unpack_call_by_signature {};
1843 template <
typename R,
typename... Args>
1844 struct unpack_call_by_signature<R(Args...)> {
1845 template <
typename F>
1846 TVM_ALWAYS_INLINE
static void run(
const F& f,
const TVMArgs& args, TVMRetValue* rv) {
1847 unpack_call<R,
sizeof...(Args)>(
nullptr, f, args, rv);
1851 template <
typename R,
typename... Args>
1852 TVM_ALWAYS_INLINE R call_packed(
const PackedFunc& pf, Args&&... args) {
1853 return R(pf(std::forward<Args>(args)...));
1856 template <
typename R>
1857 struct typed_packed_call_dispatcher {
1858 template <
typename... Args>
1859 TVM_ALWAYS_INLINE
static R run(
const PackedFunc& pf, Args&&... args) {
1860 return pf(std::forward<Args>(args)...);
1865 struct typed_packed_call_dispatcher<void> {
1866 template <
typename... Args>
1867 TVM_ALWAYS_INLINE
static void run(
const PackedFunc& pf, Args&&... args) {
1868 pf(std::forward<Args>(args)...);
1873 template <
typename R,
typename... Args>
1876 template <
typename R,
typename... Args>
1880 template <
typename R,
typename... Args>
1884 template <
typename R,
typename... Args>
1888 template <
typename R,
typename... Args>
1889 template <
typename FType>
1890 inline void TypedPackedFunc<R(Args...)>::AssignTypedLambda(FType flambda, std::string name) {
1891 FSig* f_sig = detail::SignaturePrinter<detail::function_signature<FType>>::F;
1893 if (args.
size() !=
sizeof...(Args)) {
1894 LOG(FATAL) <<
"Function " << name << (f_sig ==
nullptr ?
"" : (*f_sig)()) <<
" expects "
1895 <<
sizeof...(Args) <<
" arguments, but " << args.
size() <<
" were provided.";
1897 detail::unpack_call<R,
sizeof...(Args)>(&name, flambda, args, rv);
1901 template <
typename R,
typename... Args>
1902 template <
typename FType>
1904 FSig* f_sig = detail::SignaturePrinter<detail::function_signature<FType>>::F;
1906 if (args.
size() !=
sizeof...(Args)) {
1907 LOG(FATAL) <<
"Function <anonymous> " << (*f_sig)() <<
" expects " <<
sizeof...(Args)
1908 <<
" arguments, but " << args.
size() <<
" were provided.";
1910 detail::unpack_call<R,
sizeof...(Args)>(
nullptr, flambda, args, rv);
1914 template <
typename R,
typename... Args>
1916 return detail::typed_packed_call_dispatcher<R>::run(packed_, std::forward<Args>(args)...);
1924 template <
typename T>
1925 inline void TVMArgsSetter::SetObject(
size_t i, T&& value)
const {
1926 using ContainerType =
typename std::remove_reference<T>::type::ContainerType;
1927 if (value.defined()) {
1928 Object* ptr = value.data_.data_;
1929 if (std::is_base_of<NDArray::ContainerType, ContainerType>::value ||
1930 (std::is_base_of<ContainerType, NDArray::ContainerType>::value &&
1934 }
else if (std::is_base_of<Module::ContainerType, ContainerType>::value ||
1935 (std::is_base_of<ContainerType, Module::ContainerType>::value &&
1939 }
else if (std::is_base_of<PackedFunc::ContainerType, ContainerType>::value ||
1940 (std::is_base_of<ContainerType, PackedFunc::ContainerType>::value &&
1944 }
else if (std::is_rvalue_reference<decltype(value)>::value) {
1945 values_[i].
v_handle =
const_cast<Object**
>(&(value.data_.data_));
1948 values_[i].
v_handle = value.data_.data_;
1957 template <
typename TObjectRef,
typename>
1959 using ContainerType =
typename TObjectRef::ContainerType;
1961 if (std::is_base_of<NDArray::ContainerType, ContainerType>::value) {
1966 if (std::is_base_of<Module::ContainerType, ContainerType>::value) {
1970 if (std::is_base_of<PackedFunc::ContainerType, ContainerType>::value) {
1978 return (std::is_base_of<ContainerType, NDArray::ContainerType>::value &&
1980 (std::is_base_of<ContainerType, Module::ContainerType>::value &&
1982 (std::is_base_of<ContainerType, PackedFunc::ContainerType>::value &&
1988 template <
typename TObjectRef>
1990 static_assert(std::is_base_of<ObjectRef, TObjectRef>::value,
1991 "Conversion only works for ObjectRef");
1992 using ContainerType =
typename TObjectRef::ContainerType;
1995 CHECK(TObjectRef::_type_is_nullable)
1996 <<
"Expect a not null value of " << ContainerType::_type_key;
2000 if (std::is_base_of<NDArray::ContainerType, ContainerType>::value) {
2005 CHECK(data->IsInstance<ContainerType>())
2006 <<
"Expected " << ContainerType::_type_key <<
" but got " << data->GetTypeKey();
2007 return TObjectRef(data);
2009 if (std::is_base_of<Module::ContainerType, ContainerType>::value) {
2013 CHECK(data->IsInstance<ContainerType>())
2014 <<
"Expected " << ContainerType::_type_key <<
" but got " << data->GetTypeKey();
2015 return TObjectRef(data);
2017 if (std::is_base_of<PackedFunc::ContainerType, ContainerType>::value) {
2021 CHECK(data->IsInstance<ContainerType>())
2022 <<
"Expected " << ContainerType::_type_key <<
" but got " << data->GetTypeKey();
2023 return TObjectRef(data);
2030 <<
", but got " << checked_type.
value();
2031 return TObjectRef(GetObjectPtr<Object>(
ptr));
2036 <<
", but got " << checked_type.
value();
2037 return TObjectRef(GetObjectPtr<Object>(
ptr));
2038 }
else if (std::is_base_of<ContainerType, NDArray::ContainerType>::value &&
2043 return TObjectRef(data);
2044 }
else if (std::is_base_of<ContainerType, Module::ContainerType>::value &&
2048 }
else if (std::is_base_of<ContainerType, PackedFunc::ContainerType>::value &&
2058 template <
typename TObjectRef,
typename>
2060 using ContainerType =
typename TObjectRef::ContainerType;
2062 if (
ptr !=
nullptr) {
2063 if (std::is_base_of<NDArray::ContainerType, ContainerType>::value ||
2064 (std::is_base_of<ContainerType, NDArray::ContainerType>::value &&
2068 if (std::is_base_of<Module::ContainerType, ContainerType>::value ||
2069 (std::is_base_of<ContainerType, Module::ContainerType>::value &&
2073 if (std::is_base_of<PackedFunc::ContainerType, ContainerType>::value ||
2074 (std::is_base_of<ContainerType, PackedFunc::ContainerType>::value &&
2086 template <
typename T,
typename>
2087 inline TVMArgValue::operator T()
const {
2091 template <
typename T,
typename>
2092 inline TVMMovableArgValue_::operator T()
const {
2094 auto** ref =
static_cast<Object**
>(value_.v_handle);
2103 template <
typename T,
typename>
2104 inline TVMRetValue::operator T()
const {
2109 return (*this)->GetFunction(name, query_imports);
2132 template <
typename T>
2144 template <
typename... VariantTypes>
2151 template <
typename PODSub
class>
2153 if (
auto opt = TryAsObjectRef<VariantTypes...>(val)) {
2157 if (
auto opt = TryValueConverter<PODSubclass, VariantTypes...>(val)) {
2161 LOG(FATAL) <<
"Expected one of "
2162 <<
static_cast<const std::stringstream&
>(
2163 (std::stringstream() << ... << VariantTypes::ContainerType::_type_key))
2168 template <
typename VarFirst,
typename... VarRest>
2172 }
else if constexpr (
sizeof...(VarRest)) {
2173 return TryAsObjectRef<VarRest...>(val);
2179 template <
typename PODSubclass,
typename VarFirst,
typename... VarRest>
2183 }
catch (
const InternalError&) {
2186 if constexpr (
sizeof...(VarRest)) {
2187 return TryValueConverter<PODSubclass, VarRest...>(val);
2198 inline TVMArgValue::operator DLDataType()
const {
2211 return value_.v_type;
Runtime Array container types.
@ kTVMPackedFuncHandle
Definition: c_runtime_api.h:184
@ kTVMNDArrayHandle
Definition: c_runtime_api.h:187
@ kTVMModuleHandle
Definition: c_runtime_api.h:183
@ kTVMBytes
Definition: c_runtime_api.h:186
@ kTVMDataType
Definition: c_runtime_api.h:179
@ kTVMDLTensorHandle
Definition: c_runtime_api.h:181
@ kDLDevice
Definition: c_runtime_api.h:180
@ kTVMOpaqueHandle
Definition: c_runtime_api.h:177
@ kTVMObjectHandle
Definition: c_runtime_api.h:182
@ kTVMObjectRValueRefArg
Definition: c_runtime_api.h:188
@ kTVMNullptr
Definition: c_runtime_api.h:178
@ kTVMStr
Definition: c_runtime_api.h:185
@ kDLMicroDev
Definition: c_runtime_api.h:124
@ kOpenGL
Definition: c_runtime_api.h:123
@ kDLSDAccel
Definition: c_runtime_api.h:122
@ kDLAOCL
Definition: c_runtime_api.h:121
DLTensor * TVMArrayHandle
the array handle
Definition: c_runtime_api.h:202
array node content in array
Definition: array.h:40
size_t size() const
Definition: array.h:43
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Runtime primitive data type.
Definition: data_type.h:42
Shared content of all specializations of hash map.
Definition: map.h:174
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
Base container of module.
Definition: module.h:142
Module container of TVM.
Definition: module.h:79
PackedFunc GetFunction(const String &name, bool query_imports=false)
Get packed function from current module by name.
Definition: packed_func.h:2108
Object container class that backs NDArray.
Definition: ndarray.h:287
Managed NDArray. The array is backed by reference counted blocks.
Definition: ndarray.h:51
static TVMArrayHandle FFIGetHandle(const ObjectRef &nd)
Get FFI Array handle from ndarray.
Definition: ndarray.h:424
static ObjectPtr< Object > FFIDataFromHandle(TVMArrayHandle handle)
Construct NDArray's Data field from array handle in FFI.
Definition: ndarray.h:419
static void FFIDecRef(TVMArrayHandle handle)
DecRef resource managed by an FFI array handle.
Definition: ndarray.h:432
A custom smart pointer for Object.
Definition: object.h:360
Base class of all object reference.
Definition: object.h:517
bool defined() const
Definition: object.h:550
static void FFIClearAfterMove(ObjectRef *ref)
Clear the object ref data field without DecRef after we successfully moved the field.
Definition: object.h:621
friend class TVMArgsSetter
Definition: object.h:635
const Object * get() const
Definition: object.h:552
ObjectPtr< Object > data_
Internal pointer that backs the reference.
Definition: object.h:603
base class of all object containers.
Definition: object.h:169
std::string GetTypeKey() const
Definition: object.h:182
bool IsInstance() const
Definition: object.h:858
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
T value() const
Definition: optional.h:92
Object container class that backs PackedFunc.
Definition: packed_func.h:69
PackedFuncObj(FCallPacked *f_call_pack)
Constructing a packed function object from a function pointer.
Definition: packed_func.h:104
static constexpr const uint32_t _type_index
Definition: packed_func.h:78
TVM_DECLARE_FINAL_OBJECT_INFO(PackedFuncObj, Object)
FCallPacked * f_call_packed_
Internal callable function pointer used to call the packed function.
Definition: packed_func.h:110
static constexpr const char * _type_key
Definition: packed_func.h:79
PackedFuncObj()=delete
Delete the default constructor explicitly.
void(const PackedFuncObj *, TVMArgs, TVMRetValue *) FCallPacked
The internal callable function type.
Definition: packed_func.h:98
TVM_ALWAYS_INLINE void CallPacked(TVMArgs args, TVMRetValue *rv) const
Call the function in packed format.
Definition: packed_func.h:1241
Derived object class for constructing PackedFuncObj.
Definition: packed_func.h:115
PackedFuncSubObj(TCallable callable)
Derived object class for constructing PackedFuncObj.
Definition: packed_func.h:125
TStorage callable_
Type-erased filed for storing callable object.
Definition: packed_func.h:128
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:139
bool operator!=(std::nullptr_t null) const
Definition: packed_func.h:181
bool operator==(std::nullptr_t null) const
Definition: packed_func.h:179
TVMRetValue operator()(Args &&... args) const
Call packed function by directly passing in unpacked format.
Definition: packed_func.h:1762
TVM_ALWAYS_INLINE void CallPacked(TVMArgs args, TVMRetValue *rv) const
Call the function in packed format.
Definition: packed_func.h:1245
PackedFunc(TCallable data)
Constructing a packed function from a callable type whose signature is consistent with PackedFunc
Definition: packed_func.h:152
TVM_DEFINE_OBJECT_REF_METHODS(PackedFunc, ObjectRef, PackedFuncObj)
PackedFunc(std::nullptr_t null)
Constructor from null.
Definition: packed_func.h:142
Reference to string objects.
Definition: string.h:98
static bool CanConvertFrom(const TVMArgValue &val)
Check if a TVMArgValue can be converted to String, i.e. it can be std::string or String.
Definition: packed_func.h:2194
A single argument value to PackedFunc. Containing both type_code and TVMValue.
Definition: packed_func.h:649
TObjectRef AsObjectRef() const
Definition: packed_func.h:1989
const TVMValue & value() const
Definition: packed_func.h:691
TVMArgValue(TVMValue value, int type_code)
constructor
Definition: packed_func.h:658
bool IsObjectRef() const
Definition: packed_func.h:1958
TVMArgValue()
default constructor
Definition: packed_func.h:652
Definition: packed_func.h:1666
TVM_ALWAYS_INLINE void operator()(size_t i, DLTensor *value) const
Definition: packed_func.h:1696
TVM_ALWAYS_INLINE void operator()(size_t i, uint64_t value) const
Definition: packed_func.h:1675
TVM_ALWAYS_INLINE void operator()(size_t i, const TypedPackedFunc< FType > &value) const
Definition: packed_func.h:1725
TVM_ALWAYS_INLINE void operator()(size_t i, const TObjectRef &value) const
Definition: packed_func.h:1741
void operator()(size_t i, const TVMRetValue &value) const
Definition: packed_func.h:1728
TVM_ALWAYS_INLINE void operator()(size_t i, TObjectRef &&value) const
Definition: packed_func.h:1748
TVM_ALWAYS_INLINE void operator()(size_t i, double value) const
Definition: packed_func.h:1680
TVM_ALWAYS_INLINE void operator()(size_t i, T value) const
Definition: packed_func.h:1671
TVMArgsSetter(TVMValue *values, int *type_codes)
Definition: packed_func.h:1668
TVM_ALWAYS_INLINE void operator()(size_t i, const char *value) const
Definition: packed_func.h:1711
TVM_ALWAYS_INLINE void operator()(size_t i, Device value) const
Definition: packed_func.h:1700
TVM_ALWAYS_INLINE void operator()(size_t i, void *value) const
Definition: packed_func.h:1692
TVM_ALWAYS_INLINE void operator()(size_t i, const std::string &value) const
Definition: packed_func.h:1716
TVM_ALWAYS_INLINE void operator()(size_t i, std::nullptr_t value) const
Definition: packed_func.h:1684
TVM_ALWAYS_INLINE void operator()(size_t i, const TVMByteArray &value) const
Definition: packed_func.h:1720
TVM_ALWAYS_INLINE void operator()(size_t i, DataType dtype) const
Definition: packed_func.h:1708
TVM_ALWAYS_INLINE void operator()(size_t i, DLDataType value) const
Definition: packed_func.h:1704
TVM_ALWAYS_INLINE void operator()(size_t i, const TVMArgValue &value) const
Definition: packed_func.h:1688
Arguments into TVM functions.
Definition: packed_func.h:392
const TVMValue * values
Definition: packed_func.h:394
TVMArgs(const TVMValue *values, const int *type_codes, int num_args)
constructor
Definition: packed_func.h:403
TVMArgValue operator[](int i) const
Get i-th argument.
Definition: packed_func.h:1227
const int * type_codes
Definition: packed_func.h:395
int size() const
Definition: packed_func.h:1233
int num_args
Definition: packed_func.h:396
Internal auxiliary struct for TypedPackedFunc to indicate a movable argument with additional context ...
Definition: packed_func.h:754
TVMMovableArgValueWithContext_(TVMValue value, int type_code, int arg_index, const std::string *optional_name, FSig *f_sig)
move constructor from another return value.
Definition: packed_func.h:765
Internal auxiliary struct for TypedPackedFunc to indicate a movable argument.
Definition: packed_func.h:709
TVMMovableArgValue_(TVMValue value, int type_code)
Definition: packed_func.h:711
Internal base class to handle conversion to POD values.
Definition: packed_func.h:544
TObjectRef AsObjectRef() const
Definition: packed_func.h:1989
TVMPODValue_()
Definition: packed_func.h:634
bool IsObjectRef() const
Definition: packed_func.h:1958
TVMValue value_
The value.
Definition: packed_func.h:638
T * ptr() const
return handle as specific pointer type.
Definition: packed_func.h:620
int type_code_
the type code
Definition: packed_func.h:640
int type_code() const
Definition: packed_func.h:613
TVMPODValue_(TVMValue value, int type_code)
Definition: packed_func.h:635
Return Value container, Unlike TVMArgValue, which only holds reference and do not delete the underlyi...
Definition: packed_func.h:799
static TVMRetValue MoveFromCHost(TVMValue value, int type_code)
Construct a new TVMRetValue by moving from return value stored via C API.
Definition: packed_func.h:967
const TVMValue & value() const
Definition: packed_func.h:976
~TVMRetValue()
destructor
Definition: packed_func.h:812
TObjectRef AsObjectRef() const
Definition: packed_func.h:1989
TVMRetValue & operator=(DLDataType t)
Definition: packed_func.h:889
TVMRetValue & operator=(const TypedPackedFunc< FType > &f)
Definition: packed_func.h:929
TVMRetValue & operator=(std::nullptr_t value)
Definition: packed_func.h:864
TVMRetValue & operator=(TVMRetValue &&other)
Definition: packed_func.h:852
TVMRetValue & operator=(PackedFunc f)
Definition: packed_func.h:924
TVMRetValue & operator=(bool value)
Definition: packed_func.h:895
TVMRetValue & operator=(int value)
Definition: packed_func.h:879
bool IsObjectRef() const
Definition: packed_func.h:1958
void MoveToCHost(TVMValue *ret_value, int *ret_type_code)
Move the value back to front-end via C API. This marks the current container as null....
Definition: packed_func.h:953
TVMRetValue()
default constructor
Definition: packed_func.h:802
TVMRetValue & operator=(void *value)
Definition: packed_func.h:869
TVMRetValue & operator=(std::string value)
Definition: packed_func.h:900
TVMRetValue & operator=(const TVMArgValue &other)
Definition: packed_func.h:936
TVMRetValue(const TVMRetValue &other)
Definition: packed_func.h:828
TVMRetValue & operator=(double value)
Definition: packed_func.h:859
TVMRetValue(TVMRetValue &&other)
move constructor from another return value.
Definition: packed_func.h:807
TVMRetValue & operator=(const TVMRetValue &other)
Definition: packed_func.h:932
TVMRetValue & operator=(int64_t value)
Definition: packed_func.h:874
TVMRetValue & operator=(Module m)
Definition: packed_func.h:920
TVMRetValue & operator=(const DataType &other)
Definition: packed_func.h:894
TVMRetValue & operator=(DLDevice value)
Definition: packed_func.h:884
TVMRetValue & operator=(TVMMovableArgValue_ &&other)
Definition: packed_func.h:940
TVMRetValue & operator=(TVMByteArray value)
Definition: packed_func.h:904
TVMRetValue & operator=(NDArray other)
Definition: packed_func.h:908
A PackedFunc wrapper to provide typed function signature. It is backed by a PackedFunc internally.
Definition: packed_func.h:228
const PackedFunc & packed() const
Definition: packed_func.h:359
bool operator==(std::nullptr_t null) const
Definition: packed_func.h:361
TypedPackedFunc(const FLambda &typed_lambda)
construct from a lambda function with the same signature.
Definition: packed_func.h:310
TypedPackedFunc()
default constructor
Definition: packed_func.h:233
TypedPackedFunc(const FLambda &typed_lambda, std::string name)
construct from a lambda function with the same signature.
Definition: packed_func.h:287
TSelf & operator=(FLambda typed_lambda)
copy assignment operator from typed lambda
Definition: packed_func.h:332
TSelf & operator=(PackedFunc packed)
copy assignment operator from PackedFunc.
Definition: packed_func.h:341
bool operator!=(std::nullptr_t null) const
Definition: packed_func.h:363
TypedPackedFunc(std::nullptr_t null)
constructor from null
Definition: packed_func.h:235
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:61
Runtime Map container types.
const char * ArgTypeCode2Str(int type_code)
Convert argument type code to string.
Definition: packed_func.h:1250
const char * DLDeviceType2Str(int type)
The name of DLDeviceType.
Definition: packed_func.h:1293
DLDataType String2DLDataType(std::string s)
convert a string to TVM type.
Definition: data_type.h:377
std::string() FSig
Using static function to output TypedPackedFunc signature.
Definition: packed_func.h:187
void TVM_ALWAYS_INLINE PackArgs(TVMValue *values, int *type_codes, Args &&... args)
Definition: packed_func.h:1782
std::string DLDataType2String(DLDataType t)
convert a TVM type to string.
Definition: data_type.h:370
std::ostream & operator<<(std::ostream &os, const ObjectRef &n)
Definition: repr_printer.h:97
Object * TVMArrayHandleToObjectHandle(TVMArrayHandle handle)
Definition: ndarray.h:436
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
PrimExpr ret(PrimExpr value, Span span=Span())
Return the value.
PrimExpr max(PrimExpr a, PrimExpr b, Span span=Span())
take maximum of two values
runtime::DataType DataType
Definition: data_type.h:433
DLDevice Device
Definition: ndarray.h:43
PrimExpr min(PrimExpr a, PrimExpr b, Span span=Span())
take minimum of two values
constexpr runtime::NullOptType NullOpt
Definition: optional.h:169
A device-independent managed NDArray abstraction.
A managed object in the TVM runtime.
#define TVM_CHECK_TYPE_CODE(CODE, T)
Definition: packed_func.h:425
Runtime container of the functions generated by TVM, This is used to support dynamically link,...
Definition: packed_func.h:38
Byte array type used to pass in byte array When kTVMBytes is used as data type.
Definition: c_runtime_api.h:221
size_t size
Definition: c_runtime_api.h:223
const char * data
Definition: c_runtime_api.h:222
static std::string TypeName()
Definition: packed_func.h:503
static bool Check(const Object *ptr)
Definition: packed_func.h:492
static Optional< String > CheckAndGetMismatch(const Object *ptr)
Definition: packed_func.h:475
static bool Check(const Object *ptr)
Definition: packed_func.h:524
static Optional< String > CheckAndGetMismatch(const Object *ptr)
Definition: packed_func.h:507
static std::string TypeName()
Definition: packed_func.h:534
Type traits for runtime type check during FFI conversion.
Definition: packed_func.h:433
static std::string TypeName()
Definition: packed_func.h:466
static bool Check(const Object *ptr)
Check if an object matches the template type.
Definition: packed_func.h:461
static Optional< String > CheckAndGetMismatch(const Object *ptr)
Check if an object matches the template type and return the mismatched type if it exists.
Definition: packed_func.h:441
static Optional< T > From(const TVMRetValue &val)
Definition: packed_func.h:2138
static Optional< T > From(const TVMArgValue &val)
Definition: packed_func.h:2134
static VType From(const PODSubclass &val)
Definition: packed_func.h:2152
static Optional< VType > TryValueConverter(const PODSubclass &val)
Definition: packed_func.h:2180
static Optional< VType > TryAsObjectRef(const TVMPODValue_ &val)
Definition: packed_func.h:2169
static String From(const TVMArgValue &val)
Definition: packed_func.h:2115
static String From(const TVMRetValue &val)
Definition: packed_func.h:2123
Type trait to specify special value conversion rules from TVMArgValue and TVMRetValue.
Definition: packed_func.h:1096
static TObjectRef From(const TVMRetValue &val)
Convert a TObjectRef from a return value.
Definition: packed_func.h:1108
static TObjectRef From(const TVMArgValue &val)
Convert a TObjectRef from an argument value.
Definition: packed_func.h:1102
Definition: packed_func.h:63
Definition: packed_func.h:1775
static TVM_ALWAYS_INLINE void F(TVMArgsSetter *setter, T &&value)
Definition: packed_func.h:1776
@ kRuntimePackedFunc
runtime::PackedFunc.
Definition: object.h:74
Union type of values being passed through API and function calls.
Definition: c_runtime_api.h:208
DLDevice v_device
Definition: c_runtime_api.h:214
void * v_handle
Definition: c_runtime_api.h:211
DLDataType v_type
Definition: c_runtime_api.h:213
int64_t v_int64
Definition: c_runtime_api.h:209
const char * v_str
Definition: c_runtime_api.h:212
double v_float64
Definition: c_runtime_api.h:210
Runtime Variant container types.