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
2 changes: 1 addition & 1 deletion 3rdparty/cutlass_fpA_intB_gemm
10 changes: 10 additions & 0 deletions ffi/include/tvm/ffi/container/container_details.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ class IterAdapter {

IterAdapter operator-(difference_type offset) const { return IterAdapter(iter_ - offset); }

IterAdapter& operator+=(difference_type offset) {
iter_ += offset;
return *this;
}

IterAdapter& operator-=(difference_type offset) {
iter_ -= offset;
return *this;
}

template <typename T = IterAdapter>
typename std::enable_if<std::is_same<iterator_category, std::random_access_iterator_tag>::value,
typename T::difference_type>::type inline
Expand Down
11 changes: 7 additions & 4 deletions ffi/include/tvm/ffi/container/tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ class Tuple : public ObjectRef {
template <typename... UTypes,
typename = std::enable_if_t<(details::type_contains_v<Types, UTypes> && ...), int>>
Tuple(Tuple<UTypes...>&& other) : ObjectRef(std::move(other)) {}
template <typename... UTypes>
explicit Tuple(UTypes&&... args) : ObjectRef(MakeTupleNode(std::forward<UTypes>(args)...)) {
static_assert(sizeof...(Types) == sizeof...(UTypes), "Tuple size mismatch");
}

template <typename... UTypes,
typename = std::enable_if_t<sizeof...(Types) == sizeof...(UTypes) &&
!(sizeof...(Types) == 1 &&
(std::is_same_v<std::remove_cv_t<UTypes>, Tuple<Types>> &&
...))>>
explicit Tuple(UTypes&&... args) : ObjectRef(MakeTupleNode(std::forward<UTypes>(args)...)) {}

TVM_FFI_INLINE Tuple& operator=(const Tuple<Types...>& other) {
data_ = other.data_;
Expand Down
28 changes: 28 additions & 0 deletions ffi/tests/cpp/test_tuple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,32 @@ TEST(Tuple, Upcast) {
static_assert(details::type_contains_v<Tuple<Any, float>, Tuple<int, float>>);
static_assert(details::type_contains_v<Tuple<TNumber, float>, Tuple<TInt, float>>);
}

TEST(Tuple, ArrayIterForwarding) {
Tuple<TInt, TInt> t0(1, 2);
Tuple<TInt, TInt> t1(3, 4);
Array<Tuple<TInt, TInt>> arr0 = {t0, t1};
std::vector<Tuple<TInt, TInt>> vec0 = {t0};
vec0.insert(vec0.end(), arr0.begin(), arr0.end());
EXPECT_EQ(vec0.size(), 3);
EXPECT_EQ(vec0[0].get<0>()->value, 1);
EXPECT_EQ(vec0[0].get<1>()->value, 2);
EXPECT_EQ(vec0[1].get<0>()->value, 1);
EXPECT_EQ(vec0[1].get<1>()->value, 2);
EXPECT_EQ(vec0[2].get<0>()->value, 3);
EXPECT_EQ(vec0[2].get<1>()->value, 4);
}

TEST(Tuple, ArrayIterForwardSingleElem) {
Tuple<TInt> t0(1);
Tuple<TInt> t1(2);
Array<Tuple<TInt>> arr0 = {t0, t1};
std::vector<Tuple<TInt>> vec0 = {t0};
vec0.insert(vec0.end(), arr0.begin(), arr0.end());
EXPECT_EQ(vec0.size(), 3);
EXPECT_EQ(vec0[0].get<0>()->value, 1);
EXPECT_EQ(vec0[1].get<0>()->value, 1);
EXPECT_EQ(vec0[2].get<0>()->value, 2);
}

} // namespace
Loading