Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions ffi/include/tvm/ffi/any.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class AnyView {
* \return Create an AnyView from TVMFFIAny
* \param data the underlying ffi data.
*/
static TVM_FFI_INLINE AnyView CopyFromTVMFFIAny(TVMFFIAny data) {
TVM_FFI_INLINE static AnyView CopyFromTVMFFIAny(TVMFFIAny data) {
AnyView view;
view.data_ = data;
return view;
Expand Down Expand Up @@ -482,14 +482,14 @@ struct Type2Str<void> {
// Extra unsafe method to help any manipulation
struct AnyUnsafe : public ObjectUnsafe {
// FFI related operations
static TVM_FFI_INLINE TVMFFIAny MoveAnyToTVMFFIAny(Any&& any) {
TVM_FFI_INLINE static TVMFFIAny MoveAnyToTVMFFIAny(Any&& any) {
TVMFFIAny result = any.data_;
any.data_.type_index = TypeIndex::kTVMFFINone;
any.data_.v_int64 = 0;
return result;
}

static TVM_FFI_INLINE Any MoveTVMFFIAnyToAny(TVMFFIAny&& data) {
TVM_FFI_INLINE static Any MoveTVMFFIAnyToAny(TVMFFIAny&& data) {
Any any;
any.data_ = data;
data.type_index = TypeIndex::kTVMFFINone;
Expand All @@ -498,12 +498,12 @@ struct AnyUnsafe : public ObjectUnsafe {
}

template <typename T>
static TVM_FFI_INLINE bool CheckAnyStrict(const Any& ref) {
TVM_FFI_INLINE static bool CheckAnyStrict(const Any& ref) {
return TypeTraits<T>::CheckAnyStrict(&(ref.data_));
}

template <typename T>
static TVM_FFI_INLINE T CopyFromAnyViewAfterCheck(const Any& ref) {
TVM_FFI_INLINE static T CopyFromAnyViewAfterCheck(const Any& ref) {
if constexpr (!std::is_same_v<T, Any>) {
return TypeTraits<T>::CopyFromAnyViewAfterCheck(&(ref.data_));
} else {
Expand All @@ -512,24 +512,24 @@ struct AnyUnsafe : public ObjectUnsafe {
}

template <typename T>
static TVM_FFI_INLINE T MoveFromAnyAfterCheck(Any&& ref) {
TVM_FFI_INLINE static T MoveFromAnyAfterCheck(Any&& ref) {
if constexpr (!std::is_same_v<T, Any>) {
return TypeTraits<T>::MoveFromAnyAfterCheck(&(ref.data_));
} else {
return std::move(ref);
}
}

static TVM_FFI_INLINE Object* ObjectPtrFromAnyAfterCheck(const Any& ref) {
TVM_FFI_INLINE static Object* ObjectPtrFromAnyAfterCheck(const Any& ref) {
return reinterpret_cast<Object*>(ref.data_.v_obj);
}

static TVM_FFI_INLINE const TVMFFIAny* TVMFFIAnyPtrFromAny(const Any& ref) {
TVM_FFI_INLINE static const TVMFFIAny* TVMFFIAnyPtrFromAny(const Any& ref) {
return &(ref.data_);
}

template <typename T>
static TVM_FFI_INLINE std::string GetMismatchTypeInfo(const Any& ref) {
TVM_FFI_INLINE static std::string GetMismatchTypeInfo(const Any& ref) {
return TypeTraits<T>::GetMismatchTypeInfo(&(ref.data_));
}
};
Expand Down
16 changes: 6 additions & 10 deletions ffi/include/tvm/ffi/base_details.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
#endif

#if defined(_MSC_VER)
#define TVM_FFI_INLINE __forceinline
#define TVM_FFI_INLINE [[msvc::forceinline]] inline
#else
#define TVM_FFI_INLINE inline __attribute__((always_inline))
#define TVM_FFI_INLINE [[gnu::always_inline]] inline
#endif

/*!
Expand All @@ -60,9 +60,9 @@
* e.g. some logging functions.
*/
#if defined(_MSC_VER)
#define TVM_FFI_NO_INLINE __declspec(noinline)
#define TVM_FFI_NO_INLINE [[msvc::noinline]]
#else
#define TVM_FFI_NO_INLINE __attribute__((noinline))
#define TVM_FFI_NO_INLINE [[gnu::noinline]]
#endif

#if defined(_MSC_VER)
Expand All @@ -72,11 +72,7 @@
#endif

/*! \brief helper macro to suppress unused warning */
#if defined(__GNUC__)
#define TVM_FFI_ATTRIBUTE_UNUSED __attribute__((unused))
#else
#define TVM_FFI_ATTRIBUTE_UNUSED
#endif
#define TVM_FFI_ATTRIBUTE_UNUSED [[maybe_unused]]

#define TVM_FFI_STR_CONCAT_(__x, __y) __x##__y
#define TVM_FFI_STR_CONCAT(__x, __y) TVM_FFI_STR_CONCAT_(__x, __y)
Expand All @@ -90,7 +86,7 @@
#endif

#define TVM_FFI_STATIC_INIT_BLOCK_VAR_DEF \
static inline TVM_FFI_ATTRIBUTE_UNUSED int __##TVMFFIStaticInitReg
TVM_FFI_ATTRIBUTE_UNUSED static inline int __##TVMFFIStaticInitReg

/*! \brief helper macro to run code once during initialization */
#define TVM_FFI_STATIC_INIT_BLOCK(Body) \
Expand Down
8 changes: 4 additions & 4 deletions ffi/include/tvm/ffi/container/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ struct TypeTraits<Array<T>> : public ObjectRefTypeTraitsBase<Array<T>> {
static constexpr int32_t field_static_type_index = TypeIndex::kTVMFFIArray;
using ObjectRefTypeTraitsBase<Array<T>>::CopyFromAnyViewAfterCheck;

static TVM_FFI_INLINE std::string GetMismatchTypeInfo(const TVMFFIAny* src) {
TVM_FFI_INLINE static std::string GetMismatchTypeInfo(const TVMFFIAny* src) {
if (src->type_index != TypeIndex::kTVMFFIArray) {
return TypeTraitsBase::GetMismatchTypeInfo(src);
}
Expand All @@ -1022,7 +1022,7 @@ struct TypeTraits<Array<T>> : public ObjectRefTypeTraitsBase<Array<T>> {
TVM_FFI_UNREACHABLE();
}

static TVM_FFI_INLINE bool CheckAnyStrict(const TVMFFIAny* src) {
TVM_FFI_INLINE static bool CheckAnyStrict(const TVMFFIAny* src) {
if (src->type_index != TypeIndex::kTVMFFIArray) return false;
if constexpr (std::is_same_v<T, Any>) {
return true;
Expand All @@ -1036,7 +1036,7 @@ struct TypeTraits<Array<T>> : public ObjectRefTypeTraitsBase<Array<T>> {
}
}

static TVM_FFI_INLINE std::optional<Array<T>> TryCastFromAnyView(const TVMFFIAny* src) {
TVM_FFI_INLINE static std::optional<Array<T>> TryCastFromAnyView(const TVMFFIAny* src) {
// try to run conversion.
if (src->type_index != TypeIndex::kTVMFFIArray) return std::nullopt;
if constexpr (!std::is_same_v<T, Any>) {
Expand Down Expand Up @@ -1069,7 +1069,7 @@ struct TypeTraits<Array<T>> : public ObjectRefTypeTraitsBase<Array<T>> {
}
}

static TVM_FFI_INLINE std::string TypeStr() { return "Array<" + details::Type2Str<T>::v() + ">"; }
TVM_FFI_INLINE static std::string TypeStr() { return "Array<" + details::Type2Str<T>::v() + ">"; }
};

namespace details {
Expand Down
8 changes: 4 additions & 4 deletions ffi/include/tvm/ffi/container/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ struct TypeTraits<Map<K, V>> : public ObjectRefTypeTraitsBase<Map<K, V>> {
static constexpr int32_t field_static_type_index = TypeIndex::kTVMFFIMap;
using ObjectRefTypeTraitsBase<Map<K, V>>::CopyFromAnyViewAfterCheck;

static TVM_FFI_INLINE std::string GetMismatchTypeInfo(const TVMFFIAny* src) {
TVM_FFI_INLINE static std::string GetMismatchTypeInfo(const TVMFFIAny* src) {
if (src->type_index != TypeIndex::kTVMFFIMap) {
return TypeTraitsBase::GetMismatchTypeInfo(src);
}
Expand All @@ -1590,7 +1590,7 @@ struct TypeTraits<Map<K, V>> : public ObjectRefTypeTraitsBase<Map<K, V>> {
TVM_FFI_UNREACHABLE();
}

static TVM_FFI_INLINE bool CheckAnyStrict(const TVMFFIAny* src) {
TVM_FFI_INLINE static bool CheckAnyStrict(const TVMFFIAny* src) {
if (src->type_index != TypeIndex::kTVMFFIMap) return false;
if constexpr (std::is_same_v<K, Any> && std::is_same_v<V, Any>) {
return true;
Expand All @@ -1608,7 +1608,7 @@ struct TypeTraits<Map<K, V>> : public ObjectRefTypeTraitsBase<Map<K, V>> {
}
}

static TVM_FFI_INLINE std::optional<Map<K, V>> TryCastFromAnyView(const TVMFFIAny* src) {
TVM_FFI_INLINE static std::optional<Map<K, V>> TryCastFromAnyView(const TVMFFIAny* src) {
if (src->type_index != TypeIndex::kTVMFFIMap) return std::nullopt;
if constexpr (!std::is_same_v<K, Any> || !std::is_same_v<V, Any>) {
const MapObj* n = reinterpret_cast<const MapObj*>(src->v_obj);
Expand Down Expand Up @@ -1639,7 +1639,7 @@ struct TypeTraits<Map<K, V>> : public ObjectRefTypeTraitsBase<Map<K, V>> {
}
}

static TVM_FFI_INLINE std::string TypeStr() {
TVM_FFI_INLINE static std::string TypeStr() {
return "Map<" + details::Type2Str<K>::v() + ", " + details::Type2Str<V>::v() + ">";
}
};
Expand Down
2 changes: 1 addition & 1 deletion ffi/include/tvm/ffi/container/shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ inline constexpr bool use_default_type_traits_v<Shape> = false;
template <>
struct TypeTraits<Shape> : public ObjectRefWithFallbackTraitsBase<Shape, Array<int64_t>> {
static constexpr int32_t field_static_type_index = TypeIndex::kTVMFFIShape;
static TVM_FFI_INLINE Shape ConvertFallbackValue(Array<int64_t> src) { return Shape(src); }
TVM_FFI_INLINE static Shape ConvertFallbackValue(Array<int64_t> src) { return Shape(src); }
};

} // namespace ffi
Expand Down
14 changes: 7 additions & 7 deletions ffi/include/tvm/ffi/container/tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ template <typename... Types>
struct TypeTraits<Tuple<Types...>> : public ObjectRefTypeTraitsBase<Tuple<Types...>> {
using ObjectRefTypeTraitsBase<Tuple<Types...>>::CopyFromAnyViewAfterCheck;

static TVM_FFI_INLINE std::string GetMismatchTypeInfo(const TVMFFIAny* src) {
TVM_FFI_INLINE static std::string GetMismatchTypeInfo(const TVMFFIAny* src) {
if (src->type_index != TypeIndex::kTVMFFIArray) {
return TypeTraitsBase::GetMismatchTypeInfo(src);
}
Expand All @@ -187,7 +187,7 @@ struct TypeTraits<Tuple<Types...>> : public ObjectRefTypeTraitsBase<Tuple<Types.
}

template <size_t I, typename T, typename... Rest>
static TVM_FFI_INLINE std::string GetMismatchTypeInfoHelper(const Any* arr) {
TVM_FFI_INLINE static std::string GetMismatchTypeInfoHelper(const Any* arr) {
if constexpr (!std::is_same_v<T, Any>) {
const Any& any_v = arr[I];
if (!details::AnyUnsafe::CheckAnyStrict<T>(any_v) && !(any_v.try_cast<T>().has_value())) {
Expand All @@ -203,7 +203,7 @@ struct TypeTraits<Tuple<Types...>> : public ObjectRefTypeTraitsBase<Tuple<Types.
TVM_FFI_UNREACHABLE();
}

static TVM_FFI_INLINE bool CheckAnyStrict(const TVMFFIAny* src) {
TVM_FFI_INLINE static bool CheckAnyStrict(const TVMFFIAny* src) {
if (src->type_index != TypeIndex::kTVMFFIArray) return false;
const ArrayObj* n = reinterpret_cast<const ArrayObj*>(src->v_obj);
if (n->size() != sizeof...(Types)) return false;
Expand All @@ -212,7 +212,7 @@ struct TypeTraits<Tuple<Types...>> : public ObjectRefTypeTraitsBase<Tuple<Types.
}

template <size_t I, typename T, typename... Rest>
static TVM_FFI_INLINE bool CheckAnyStrictHelper(const TVMFFIAny* src_arr) {
TVM_FFI_INLINE static bool CheckAnyStrictHelper(const TVMFFIAny* src_arr) {
if constexpr (!std::is_same_v<T, Any>) {
if (!TypeTraits<T>::CheckAnyStrict(src_arr + I)) {
return false;
Expand All @@ -224,7 +224,7 @@ struct TypeTraits<Tuple<Types...>> : public ObjectRefTypeTraitsBase<Tuple<Types.
return true;
}

static TVM_FFI_INLINE std::optional<Tuple<Types...>> TryCastFromAnyView(const TVMFFIAny* src //
TVM_FFI_INLINE static std::optional<Tuple<Types...>> TryCastFromAnyView(const TVMFFIAny* src //
) {
if (src->type_index != TypeIndex::kTVMFFIArray) return std::nullopt;
const ArrayObj* n = reinterpret_cast<const ArrayObj*>(src->v_obj);
Expand All @@ -243,7 +243,7 @@ struct TypeTraits<Tuple<Types...>> : public ObjectRefTypeTraitsBase<Tuple<Types.
}

template <size_t I, typename T, typename... Rest>
static TVM_FFI_INLINE bool TryConvertElements(Any* arr) {
TVM_FFI_INLINE static bool TryConvertElements(Any* arr) {
if constexpr (!std::is_same_v<T, Any>) {
if (auto opt_convert = arr[I].try_cast<T>()) {
arr[I] = *std::move(opt_convert);
Expand All @@ -258,7 +258,7 @@ struct TypeTraits<Tuple<Types...>> : public ObjectRefTypeTraitsBase<Tuple<Types.
}
}

static TVM_FFI_INLINE std::string TypeStr() {
TVM_FFI_INLINE static std::string TypeStr() {
return details::ContainerTypeStr<Types...>("Tuple");
}
};
Expand Down
18 changes: 9 additions & 9 deletions ffi/include/tvm/ffi/container/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,31 +189,31 @@ inline constexpr bool use_default_type_traits_v<Variant<V...>> = false;

template <typename... V>
struct TypeTraits<Variant<V...>> : public TypeTraitsBase {
static TVM_FFI_INLINE void CopyToAnyView(const Variant<V...>& src, TVMFFIAny* result) {
TVM_FFI_INLINE static void CopyToAnyView(const Variant<V...>& src, TVMFFIAny* result) {
*result = src.ToAnyView().CopyToTVMFFIAny();
}

static TVM_FFI_INLINE void MoveToAny(Variant<V...> src, TVMFFIAny* result) {
TVM_FFI_INLINE static void MoveToAny(Variant<V...> src, TVMFFIAny* result) {
*result = details::AnyUnsafe::MoveAnyToTVMFFIAny(std::move(src).MoveToAny());
}

static TVM_FFI_INLINE std::string GetMismatchTypeInfo(const TVMFFIAny* src) {
TVM_FFI_INLINE static std::string GetMismatchTypeInfo(const TVMFFIAny* src) {
return TypeTraitsBase::GetMismatchTypeInfo(src);
}

static TVM_FFI_INLINE bool CheckAnyStrict(const TVMFFIAny* src) {
TVM_FFI_INLINE static bool CheckAnyStrict(const TVMFFIAny* src) {
return (TypeTraits<V>::CheckAnyStrict(src) || ...);
}

static TVM_FFI_INLINE Variant<V...> CopyFromAnyViewAfterCheck(const TVMFFIAny* src) {
TVM_FFI_INLINE static Variant<V...> CopyFromAnyViewAfterCheck(const TVMFFIAny* src) {
return Variant<V...>(Any(AnyView::CopyFromTVMFFIAny(*src)));
}

static TVM_FFI_INLINE Variant<V...> MoveFromAnyAfterCheck(TVMFFIAny* src) {
TVM_FFI_INLINE static Variant<V...> MoveFromAnyAfterCheck(TVMFFIAny* src) {
return Variant<V...>(details::AnyUnsafe::MoveTVMFFIAnyToAny(std::move(*src)));
}

static TVM_FFI_INLINE std::optional<Variant<V...>> TryCastFromAnyView(const TVMFFIAny* src) {
TVM_FFI_INLINE static std::optional<Variant<V...>> TryCastFromAnyView(const TVMFFIAny* src) {
// fast path, storage is already in the right type
if (CheckAnyStrict(src)) {
return CopyFromAnyViewAfterCheck(src);
Expand All @@ -223,7 +223,7 @@ struct TypeTraits<Variant<V...>> : public TypeTraitsBase {
}

template <typename VariantType, typename... Rest>
static TVM_FFI_INLINE std::optional<Variant<V...>> TryVariantTypes(const TVMFFIAny* src) {
TVM_FFI_INLINE static std::optional<Variant<V...>> TryVariantTypes(const TVMFFIAny* src) {
if (auto opt_convert = TypeTraits<VariantType>::TryCastFromAnyView(src)) {
return Variant<V...>(*std::move(opt_convert));
}
Expand All @@ -233,7 +233,7 @@ struct TypeTraits<Variant<V...>> : public TypeTraitsBase {
return std::nullopt;
}

static TVM_FFI_INLINE std::string TypeStr() { return details::ContainerTypeStr<V...>("Variant"); }
TVM_FFI_INLINE static std::string TypeStr() { return details::ContainerTypeStr<V...>("Variant"); }
};

template <typename... V>
Expand Down
12 changes: 6 additions & 6 deletions ffi/include/tvm/ffi/dtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,29 +130,29 @@ template <>
struct TypeTraits<DLDataType> : public TypeTraitsBase {
static constexpr int32_t field_static_type_index = TypeIndex::kTVMFFIDataType;

static TVM_FFI_INLINE void CopyToAnyView(const DLDataType& src, TVMFFIAny* result) {
TVM_FFI_INLINE static void CopyToAnyView(const DLDataType& src, TVMFFIAny* result) {
// clear padding part to ensure the equality check can always check the v_uint64 part
result->v_uint64 = 0;
result->type_index = TypeIndex::kTVMFFIDataType;
result->v_dtype = src;
}

static TVM_FFI_INLINE void MoveToAny(DLDataType src, TVMFFIAny* result) {
TVM_FFI_INLINE static void MoveToAny(DLDataType src, TVMFFIAny* result) {
// clear padding part to ensure the equality check can always check the v_uint64 part
result->v_uint64 = 0;
result->type_index = TypeIndex::kTVMFFIDataType;
result->v_dtype = src;
}

static TVM_FFI_INLINE bool CheckAnyStrict(const TVMFFIAny* src) {
TVM_FFI_INLINE static bool CheckAnyStrict(const TVMFFIAny* src) {
return src->type_index == TypeIndex::kTVMFFIDataType;
}

static TVM_FFI_INLINE DLDataType CopyFromAnyViewAfterCheck(const TVMFFIAny* src) {
TVM_FFI_INLINE static DLDataType CopyFromAnyViewAfterCheck(const TVMFFIAny* src) {
return src->v_dtype;
}

static TVM_FFI_INLINE std::optional<DLDataType> TryCastFromAnyView(const TVMFFIAny* src) {
TVM_FFI_INLINE static std::optional<DLDataType> TryCastFromAnyView(const TVMFFIAny* src) {
if (src->type_index == TypeIndex::kTVMFFIDataType) {
return src->v_dtype;
}
Expand All @@ -163,7 +163,7 @@ struct TypeTraits<DLDataType> : public TypeTraitsBase {
return std::nullopt;
}

static TVM_FFI_INLINE std::string TypeStr() { return ffi::StaticTypeKey::kTVMFFIDataType; }
TVM_FFI_INLINE static std::string TypeStr() { return ffi::StaticTypeKey::kTVMFFIDataType; }
};
} // namespace ffi
} // namespace tvm
Expand Down
Loading
Loading