24 #ifndef TVM_TOPI_TRANSFORM_H_
25 #define TVM_TOPI_TRANSFORM_H_
42 #include <unordered_set>
49 using namespace topi::detail;
70 std::string tag =
"") {
72 auto _axis = size_t(axis);
73 CHECK_LT(_axis, x->shape.size()) <<
"axis must be a valid dimension index of x.";
74 CHECK_EQ(x->shape.size() - _axis, window_shape.
size())
75 <<
"There must be a window shape for every dimension of x "
76 <<
"over which we are sliding the window.";
77 CHECK_EQ(strides.
size(), window_shape.
size()) <<
"Windows and strides should be the same length.";
82 for (
size_t i = 0; i < _axis; ++i) {
88 for (
size_t i = 0; i < window_shape.
size(); ++i) {
90 auto dim_len = x->shape[_axis + i];
92 auto window_len = window_shape[i];
94 auto stride = strides[i];
100 for (
size_t i = 0; i < window_shape.
size(); ++i) {
104 ICHECK(new_shape.
size() == _axis + 2 * window_shape.
size());
113 for (
size_t i = 0; i < _axis; ++i) {
117 for (
size_t i = 0; i < window_shape.
size(); ++i) {
119 auto window_idx = indices[_axis + i];
121 auto idx_within_window = indices[_axis + window_shape.
size() + i];
123 auto stride = strides[i];
125 idx.
push_back(window_idx * stride + idx_within_window);
128 ICHECK(idx.
size() == x->shape.size());
148 std::string name =
"T_expand_dims", std::string tag =
kBroadcast) {
149 int ndim =
static_cast<int>(x->shape.size());
150 ICHECK(-ndim - 1 <= axis && axis <= ndim)
151 <<
"expand_dims only accepts `axis` in [-data.ndim - 1, data.ndim]"
152 <<
", but got axis = " << axis <<
", and data.ndim = " << ndim;
153 ICHECK(num_newaxis >= 0) <<
"expand_dims only accepts `num_newaxis >= 0`"
154 <<
", but got num_newaxis = " << num_newaxis;
157 axis = ndim + axis + 1;
160 for (
size_t i = 0; i < static_cast<size_t>(axis); ++i) {
163 for (
size_t i = 0; i < static_cast<size_t>(num_newaxis); ++i) {
166 for (
size_t i = axis; i < x->shape.size(); ++i) {
174 for (
size_t i = 0; i < static_cast<size_t>(axis); ++i) {
177 for (
size_t i = axis + num_newaxis; i < indices.
size(); ++i) {
200 for (
int i =
static_cast<int>(x->shape.size()) - 1; i >= 0; --i) {
206 for (
size_t i = 0; i < axes.
size(); ++i) {
207 int axis =
static_cast<int>(axes[i]->value);
210 new_axis =
static_cast<int>(x->shape.size()) + axis;
211 axes.
Set(i, new_axis);
213 ICHECK((new_axis >= 0) && (new_axis <
static_cast<int>(x->shape.size())))
214 <<
"axis=" << axis <<
" is invalid for the " <<
static_cast<int>(x->shape.size())
215 <<
"-dimensional input tensor";
217 for (
size_t j = 0; j < axes.
size(); ++j) {
219 ICHECK(new_axis !=
static_cast<int>(axes[j]->value)) <<
"repeated axis in transpose";
228 std::vector<PrimExpr> idx;
229 for (
size_t i = 0; i < axes.
size(); ++i) {
232 for (
size_t i = 0; i < axes.
size(); ++i) {
233 int axis =
static_cast<int>(axes[i]->value);
234 idx[axis] = indices[i];
256 int batch_axis = 0, std::string name =
"T_reverse_sequence",
258 size_t src_tensor_dim = x->shape.size();
259 int seq_axis_inp = seq_axis;
262 size_t seq_lengths_dim = seq_lengths->shape.size();
263 int batch_axis_inp = batch_axis;
264 if (batch_axis < 0) {
265 batch_axis =
static_cast<int>(x->shape.size()) + batch_axis;
268 ICHECK(seq_lengths_dim == 1) <<
"seq_lengths should be 1D vector";
270 ICHECK(GetConstInt(seq_lengths->shape[0]) == GetConstInt(x->shape[batch_axis]))
271 <<
"For reverse_sequnece seq_lengths size should match with dimension of batch axis"
272 <<
", but got dimension of batch_axis = " << GetConstInt(x->shape[batch_axis])
273 <<
", and seq_length size = " << GetConstInt(seq_lengths->shape[0]);
275 ICHECK((0 <= batch_axis) && (batch_axis <
static_cast<int>(x->shape.size())))
276 <<
"batch_axis=" << batch_axis_inp <<
" is invalid for the "
277 <<
static_cast<int>(x->shape.size()) <<
"-dimensional input tensor";
281 seq_axis =
static_cast<int>(x->shape.size()) + seq_axis;
283 ICHECK((0 <= seq_axis) && (seq_axis <
static_cast<int>(x->shape.size())))
284 <<
"seq_axis=" << seq_axis_inp <<
" is invalid for the " <<
static_cast<int>(x->shape.size())
285 <<
"-dimensional input tensor";
289 for (
size_t i = 0; i < src_tensor_dim; ++i) {
290 if (i ==
static_cast<size_t>(seq_axis)) {
292 auto len = seq_lengths(indices[batch_axis]);
294 len <= 1 || len <= indices[i], indices[i],
295 if_then_else(len > x->shape[i], x->shape[i] - 1 - indices[i], len - 1 - indices[i]));
298 real_indices.
push_back(x->shape[i] - 1 - indices[i]);
304 return x(real_indices);
307 return compute(x->shape, func, name, tag);
322 auto x_shape = x->shape;
325 for (
const auto& ele : newshape) {
330 if (is_empty_shape(target_shape) || is_empty_shape(x->shape)) {
332 target_shape, [&](
const Array<Var>& indices) {
return tvm::cast(x->dtype, 0); }, name, tag);
337 return x(UnravelIndex(
357 auto x_shape = x->shape;
358 auto shape_shape =
shape->shape;
362 if (x_shape.size() != 0) {
368 std::vector<PrimExpr> indices_divs;
373 if (x_shape.size() != 0) {
374 index_val = x[indices[1]];
378 indices_divs.push_back(index_val);
379 for (
int v = GetConstInt(shape_shape[0]) - 1; v >= 0; --v) {
382 indices_divs.push_back(cur_val);
387 return compute(oshape, func, name, tag);
404 std::string name =
"T_squeeze", std::string tag =
kInjective) {
405 auto ndim = x->shape.size();
406 std::vector<int> axis_val;
408 for (
size_t i = 0; i < ndim; ++i) {
409 if (IsConstInt(x->shape[i]) && GetConstInt(x->shape[i]) == 1) {
410 axis_val.push_back(
static_cast<int>(i));
414 for (
size_t i = 0; i < axis.
size(); ++i) {
415 int64_t val = axis[i]->value;
417 val +=
static_cast<int>(x->shape.size());
419 if (IsConstInt(x->shape[val])) {
420 ICHECK_EQ(GetConstInt(x->shape[val]), 1) <<
"Dimension " << val <<
" must have size 1";
426 std::unordered_set<int> axis_set(axis_val.begin(), axis_val.end());
429 for (
size_t i = 0; i < ndim; ++i) {
430 if (axis_set.count(
static_cast<int>(i)) == 0) {
434 if (out_shape.
size() == 0 && atleast1d) {
443 for (
size_t i = 0; i < ndim; ++i) {
444 if (axis_set.count(
static_cast<int>(i)) == 0) {
445 real_indices.push_back(indices[i - flag]);
447 real_indices.push_back(0);
451 return x(real_indices);
468 int ndim =
static_cast<int>(inputs[0]->shape.
size());
469 ICHECK(-ndim <= axis && axis < ndim) <<
"concatenate only accepts `axis` in [-ndim, ndim)"
470 <<
", but got axis = " << axis <<
", and ndim = " << ndim;
474 ICHECK_LT(axis, inputs[0]->
shape.size()) <<
"axis out of bounds";
477 for (
auto t : inputs) {
482 for (
size_t i = 1; i < axis_sizes.
size(); ++i) {
483 join_size += axis_sizes[i];
485 join_size = analyzer.
Simplify(join_size);
487 for (
size_t i = 0; i < inputs[0]->shape.
size(); ++i) {
488 out_shape.
push_back(i ==
static_cast<size_t>(axis) ? join_size : inputs[0]->
shape[i]);
494 auto ret = inputs[0](indices);
495 auto ind = indices[axis];
496 for (
size_t i = 0; i < inputs.
size() - 1; ++i) {
497 ind -= axis_sizes[i];
500 for (
size_t i = 0; i < static_cast<size_t>(axis); ++i) {
504 for (
size_t i = axis + 1; i < indices.
size(); ++i) {
527 int ndim =
static_cast<int>(inputs[0]->shape.
size());
528 ICHECK(-ndim - 1 <= axis && axis <= ndim)
529 <<
"stack only accepts `axis` in [-ndim, ndim)"
530 <<
", but got axis = " << axis <<
", and ndim = " << ndim;
534 ICHECK_LT(axis, inputs[0]->
shape.size() + 1) <<
"axis out of bounds";
536 const int stack_size =
static_cast<int>(inputs.
size());
538 for (
size_t i = 0; i < static_cast<size_t>(axis); ++i) out_shape.
push_back(inputs[0]->shape[i]);
540 for (
size_t i =
static_cast<size_t>(axis); i < static_cast<size_t>(ndim); ++i)
541 out_shape.
push_back(inputs[0]->shape[i]);
547 for (
size_t i = 0; i < indices.
size(); ++i)
548 if (i !=
static_cast<size_t>(axis)) idx.
push_back(indices[i]);
549 auto ind = indices[axis];
550 auto ret = inputs[0](idx);
551 for (
int i = 0; i < static_cast<int>(inputs.
size() - 1); ++i) {
572 std::string name =
"T_split", std::string tag =
kInjective) {
574 axis +=
static_cast<int>(x->shape.size());
576 ICHECK_LT(axis, x->shape.size()) <<
"axis out of bounds";
578 auto src_axis_size = x->shape[axis];
579 std::vector<PrimExpr> begin_ids;
580 begin_ids.push_back(0);
582 for (
auto idx : split_indices) {
584 auto back_node = begin_ids.back().as<
IntImmNode>();
585 if (idx_node && back_node) {
586 ICHECK_GT(idx_node->value, back_node->
value) <<
"split_indices must be sorted";
588 begin_ids.push_back(idx);
592 for (
size_t i = 0; i < begin_ids.size(); ++i) {
594 if (i == begin_ids.size() - 1) {
595 out_axis_size = src_axis_size - begin_ids[i];
597 out_axis_size = begin_ids[i + 1] - begin_ids[i];
601 for (
size_t i = 0; i < static_cast<size_t>(axis); ++i) {
602 shape.push_back(x->shape[i]);
604 shape.push_back(out_axis_size);
605 for (
size_t i = axis + 1; i < x->shape.size(); ++i) {
606 shape.push_back(x->shape[i]);
613 for (
size_t i = 0; i < begin_ids.size(); ++i) {
617 auto begin = begin_ids[i];
619 for (
size_t j = 0; j < static_cast<size_t>(axis); ++j) {
622 real_indices.
push_back(indices[axis] + begin);
623 for (
size_t j = axis + 1; j < indices.
size(); ++j) {
627 return x(real_indices);
650 std::string name =
"T_dynamic_strided_slice",
652 const size_t src_tensor_dim = x->shape.size();
653 ICHECK_LE(begin.
size(), src_tensor_dim);
654 ICHECK_LE(end.
size(), src_tensor_dim);
655 ICHECK_LE(strides.
size(), src_tensor_dim);
656 ICHECK_EQ(begin.
size(), end.
size());
657 ICHECK_EQ(begin.
size(), strides.
size());
659 const size_t num_slice_axes = begin.
size();
662 for (
size_t i = 0; i < num_slice_axes; ++i) {
663 auto d =
indexdiv(end[i] - begin[i], strides[i]);
672 for (
size_t i = num_slice_axes; i < src_tensor_dim; ++i) {
680 for (
size_t i = 0; i < num_slice_axes; ++i) {
681 real_indices.
push_back(indices[i] * strides[i] +
tvm::min(begin[i], x->shape[i] - 1));
684 for (
size_t i = num_slice_axes; i < src_tensor_dim; ++i) {
687 return x(real_indices);
707 std::string name =
"T_strided_slice_dynamic",
709 DataType index_dtype = begin->shape[0]->dtype;
710 const int64_t num_dynamic_axes = begin->shape[0].
as<
IntImmNode>()->value;
715 for (int64_t i = 0; i < num_dynamic_axes; ++i) {
742 std::vector<int64_t> begin_vec, end_vec, strides_vec;
743 std::tie(begin_vec, end_vec, strides_vec) = ConvertToVec(begin, end, strides, slice_mode);
744 auto begin_canonicalized = StridedSliceCanonicalizeBegin(ishape, begin_vec, strides_vec, axes,
745 begin[0]->dtype, slice_mode);
747 begin_canonicalized,
true);
769 std::string name =
"T_strided_slice_with_axes",
771 const size_t src_tensor_dim = x->shape.size();
772 ICHECK(axes.
size() <= src_tensor_dim);
775 std::vector<int64_t> begin_vec, end_vec, strides_vec;
776 std::tie(begin_vec, end_vec, strides_vec) = ConvertToVec(begin, end, strides, slice_mode);
778 auto begin_expr = StridedSliceCanonicalizeBegin(x->shape, begin_vec, strides_vec, axes,
779 begin[0]->dtype, slice_mode);
781 slice_mode, begin_expr);
787 for (
size_t i = 0; i < out_shape.size(); ++i) real_indices.
push_back(indices[i]);
788 for (
size_t i = 0; i < axes.
size(); ++i) {
789 auto stride =
make_const(strides[i].dtype(), strides_vec[i]);
790 PrimExpr ind = indices[axes[i].IntValue()] * stride + begin_expr[i];
791 real_indices.
Set(axes[i].IntValue(), ind);
793 return x(real_indices);
814 std::string name =
"T_strided_slice", std::string tag =
kInjective) {
815 size_t src_tensor_dim =
static_cast<size_t>(x->shape.size());
817 for (
size_t i = 0; i < src_tensor_dim; ++i) axes.
push_back(i);
827 for (
size_t i = strides.
size(); i < src_tensor_dim; ++i) {
830 for (
size_t i = begin.
size(); i < src_tensor_dim; ++i) {
831 begin_full.
push_back(GetConstInt(strides_full[i]) > 0 ? zero : max_range);
833 for (
size_t i = end.
size(); i < src_tensor_dim; ++i) {
834 end_full.
push_back(GetConstInt(strides_full[i]) < 0 ? zero : max_range);
854 std::string name =
"T_split_sections",
857 axis +=
static_cast<int>(x->shape.size());
859 ICHECK_LT(axis, x->shape.size()) <<
"axis out of bounds";
861 auto src_axis_size = x->shape[axis];
863 ICHECK_GT(num_sections, 0) <<
"Slice count must be > 0";
865 if (
auto node = src_axis_size.as<
IntImmNode>()) {
866 ICHECK_EQ(node->value % num_sections, 0)
867 <<
"num_sections must be an integer factor of the size of axis " << axis <<
" ("
868 << node->value <<
")";
872 auto seg_size =
indexdiv(src_axis_size, num_sections);
873 for (
int i = 0; i < num_sections; ++i) {
880 return split(x, split_indices, axis, name, tag);
896 std::string mode =
"clip", std::string name =
"T_take",
901 for (
size_t i = 0; i < a_shape.
size(); ++i) {
902 a_size = a_size * a_shape[i];
905 if (mode ==
"clip") {
910 return a(UnravelIndex(idx, a_shape));
913 }
else if (mode ==
"fast") {
914 LOG(WARNING) <<
"Fast mode segfaults when there are out-of-bounds indices. "
915 "Make sure input indices are in bound";
918 [&](
const Array<Var>& out_index) {
return a(UnravelIndex(indices(out_index), a_shape)); },
925 return a(UnravelIndex(idx, a_shape));
944 int axis, std::string name =
"T_sequence_mask",
946 ICHECK(axis == 0 || axis == 1) <<
"axis must be either 0 or 1";
947 ICHECK_EQ(valid_length->shape.size(), 1) <<
"valid_length must have ndim=1, i.e., (batch_size,).";
948 auto length_dim = data->shape[axis];
949 auto batch_dim = data->shape[1 - axis];
955 auto tid = out_index[axis];
956 auto bid = out_index[1 - axis];
982 std::string mode =
"clip", std::string name =
"T_take",
985 axis +=
static_cast<int>(a->shape.size());
987 ICHECK_GE(axis, 0) <<
"axis out of bounds";
988 ICHECK_LT(axis, a->shape.size()) <<
"axis out of bounds";
989 auto axis_dim = a->shape[axis];
990 int indices_len =
static_cast<int>(indices->shape.size());
992 int batch_dims_ = batch_dims;
993 if (batch_dims_ != 0) {
994 ICHECK_GE(batch_dims_, -
static_cast<int>(indices->shape.size())) <<
"batch_dims out of bounds";
995 ICHECK_LE(batch_dims_, indices->shape.size()) <<
"batch_dims out of bounds";
997 if (batch_dims_ < 0) {
998 batch_dims_ = indices->shape.size() + batch_dims_;
1001 ICHECK_LT(batch_dims_, a->shape.size()) <<
"batch_dims out of bounds";
1002 ICHECK_LE(batch_dims_, axis) <<
"batch_dims must be less than or equal to axis";
1003 for (
int i = 0; i < batch_dims_; ++i) {
1004 auto addr1 = a->shape[i];
1005 auto addr2 = indices->shape[i];
1006 auto v1 =
static_cast<IntImm*
>(&addr1)->get()->value;
1007 auto v2 =
static_cast<IntImm*
>(&addr2)->get()->value;
1008 ICHECK_EQ(v1, v2) <<
"a.shape[" << i <<
"] should be equal to indices.shape[" << i <<
"]";
1016 for (
int i = 0; i < batch_dims_; ++i) {
1019 for (
int i = batch_dims_; i < axis; ++i) {
1022 for (
size_t i =
static_cast<size_t>(batch_dims_); i < indices->shape.size(); ++i) {
1025 for (
size_t i = axis + 1; i < a->shape.size(); ++i) {
1029 if (mode ==
"clip") {
1030 if (batch_dims_ == 0) {
1035 for (
size_t j = axis; j < static_cast<size_t>(axis + indices_len); ++j) {
1036 indices_position.
push_back(out_index[j]);
1039 for (
size_t j = 0; j < static_cast<size_t>(axis); ++j) {
1044 for (
size_t j = axis + indices_len; j < out_index.
size(); ++j) {
1047 return a(real_indices);
1055 for (
size_t j = 0; j < static_cast<size_t>(batch_dims_); ++j) {
1056 indices_position.
push_back(out_index[j]);
1058 for (
size_t j = axis; j < static_cast<size_t>(axis + indices_len - batch_dims_); ++j) {
1059 indices_position.
push_back(out_index[j]);
1062 for (
size_t j = 0; j < static_cast<size_t>(axis); ++j) {
1067 for (
size_t j = axis + indices_len - batch_dims_; j < out_index.
size(); ++j) {
1070 return a(real_indices);
1074 }
else if (mode ==
"fast") {
1075 LOG(WARNING) <<
"Fast mode segfaults when there are out-of-bounds indices. "
1076 "Make sure input indices are in bound";
1081 for (
size_t j = axis; j < static_cast<size_t>(axis + indices_len); ++j) {
1082 indices_position.
push_back(out_index[j]);
1085 for (
size_t j = 0; j < static_cast<size_t>(axis); ++j) {
1088 real_indices.
push_back(indices(indices_position));
1089 for (
size_t j = axis + indices_len; j < out_index.
size(); ++j) {
1092 return a(real_indices);
1100 for (
size_t j = axis; j < static_cast<size_t>(axis + indices_len); ++j) {
1101 indices_position.
push_back(out_index[j]);
1104 for (
size_t j = 0; j < static_cast<size_t>(axis); ++j) {
1107 auto idx =
truncmod(
truncmod(indices(indices_position), axis_dim) + axis_dim, axis_dim);
1109 for (
size_t j = axis + indices_len; j < out_index.
size(); ++j) {
1112 return a(real_indices);
1130 std::string name =
"T_where", std::string tag =
kBroadcast) {
1131 ICHECK_EQ(x->dtype, y->dtype) <<
"x and y must have the same dtype: " << x->dtype <<
" vs "
1133 auto get_out_shape = [&]() {
1134 auto bh1 = detail::BroadcastShape(x->shape, y->shape);
1135 Array<PrimExpr> common_shape1(bh1.common_shape.begin(), bh1.common_shape.end());
1136 auto bh2 = detail::BroadcastShape(condition->shape, common_shape1);
1137 Array<PrimExpr> common_shape2(bh2.common_shape.begin(), bh2.common_shape.end());
1138 return common_shape2;
1141 auto oshape = get_out_shape();
1143 auto c_bh = detail::BroadcastShape(condition->shape, oshape);
1144 auto x_bh = detail::BroadcastShape(x->shape, oshape);
1145 auto y_bh = detail::BroadcastShape(y->shape, oshape);
1148 auto c = condition(InputIndexFromBroadcast(ovars, condition, c_bh.vars1, c_bh.all_vars));
1149 auto true_val = x(InputIndexFromBroadcast(ovars, x, x_bh.vars1, x_bh.all_vars));
1150 auto false_val = y(InputIndexFromBroadcast(ovars, y, y_bh.vars1, y_bh.all_vars));
1154 return compute(oshape, select, name, tag);
1171 int ndim =
static_cast<int>(x->shape.size());
1172 ICHECK(-ndim - 1 <= axis && axis <= ndim)
1173 <<
"repeat only accepts `axis` in [-data.ndim - 1, data.ndim]"
1174 <<
", but got axis = " << axis <<
", and data.ndim = " << ndim;
1175 ICHECK(repeats >= 1) <<
"repeat only accepts `repeats >= 1`"
1176 <<
", but got repeats = " << repeats;
1182 for (
size_t i = 0; i < static_cast<size_t>(axis); ++i) {
1185 new_shape.
push_back(repeats * x->shape[axis]);
1186 for (
size_t i = axis + 1; i < x->shape.size(); ++i) {
1194 for (
size_t i = 0; i < static_cast<size_t>(axis); ++i) {
1198 for (
size_t i = axis + 1; i < indices.
size(); ++i) {
1218 size_t ndim = x->shape.size();
1219 size_t rdim = reps.
size();
1220 size_t tdim = (ndim > rdim) ? ndim : rdim;
1225 for (
size_t i = 0; i < ndim; ++i) {
1229 }
else if (ndim > rdim) {
1230 for (
size_t i = 0; i < ndim; ++i) data_shape.
push_back(x->shape[i]);
1231 for (
size_t i = 0; i < (ndim - rdim); ++i) reps_shape.
push_back(1);
1232 for (
size_t i = 0; i < rdim; ++i) reps_shape.
push_back(reps[i]);
1234 for (
size_t i = 0; i < (rdim - ndim); ++i) data_shape.
push_back(1);
1235 for (
size_t i = 0; i < ndim; ++i) data_shape.
push_back(x->shape[i]);
1236 for (
size_t i = 0; i < rdim; ++i) reps_shape.
push_back(reps[i]);
1238 for (
size_t i = 0; i < tdim; ++i) new_shape.
push_back(data_shape[i] * reps_shape[i]);
1240 if (is_empty_shape(new_shape)) {
1249 for (
size_t i = 0; i < ndim; ++i) idx.
push_back(
indexmod(indices[i], x->shape[i]));
1251 for (
size_t i = 0; i < ndim; ++i)
1272 std::string name =
"T_tile", std::string tag =
kBroadcast) {
1273 size_t ndim = x->shape.size();
1274 if (is_empty_shape(new_shape)) {
1283 for (
size_t i = 0; i < ndim; ++i) {
1287 for (
size_t i = 0; i < ndim; ++i) {
1309 std::string name =
"T_gather", std::string tag =
kInjective) {
1310 size_t ndim_d = data->shape.size();
1311 size_t ndim_i = indices->shape.size();
1312 ICHECK_GE(ndim_d, 1) <<
"Cannot gather from a scalar.";
1313 ICHECK_EQ(ndim_d, ndim_i);
1318 ICHECK_LT(axis, ndim_d);
1320 size_t indices_dim_i =
static_cast<size_t>(GetConstInt(indices->shape[axis]));
1321 ICHECK_GE(indices_dim_i, 1);
1323 ICHECK(indices->dtype.is_int() || indices->dtype.is_uint());
1326 for (
size_t i = 0; i < ndim_i; ++i) {
1334 for (
size_t i = 0; i < ndim_i; ++i) {
1335 indices_position.
push_back(out_index[i]);
1338 for (
size_t i = 0; i < ndim_i; ++i) {
1339 if (i ==
static_cast<size_t>(axis)) {
1340 real_indices.
push_back(indices(indices_position));
1342 real_indices.
push_back(indices_position[i]);
1345 return data(real_indices);
1362 std::string name =
"T_gather_nd", std::string tag =
kInjective) {
1363 size_t ndim_d = data->shape.size();
1364 size_t ndim_i = indices->shape.size();
1365 ICHECK_GE(ndim_i, 1) <<
"indices tensor must have at least 1 dimensions";
1366 size_t indices_dim0 =
static_cast<size_t>(GetConstInt(indices->shape[0]));
1367 ICHECK_LE(indices_dim0, ndim_d) <<
"dim 0 of indices tensor must be no more "
1368 <<
"than dimensions of data tensor";
1370 for (
size_t i = 1; i < ndim_i; ++i) {
1373 for (
size_t i = indices_dim0 + batch_dims; i < ndim_d; ++i) {
1381 for (
size_t i = 0; i < ndim_i - 1; ++i) {
1382 indices_position.
push_back(out_index[i]);
1385 for (
size_t i = 0; i < static_cast<size_t>(batch_dims); ++i) {
1388 for (
size_t i = 0; i < indices_dim0; ++i) {
1390 if (indices->dtype.is_int() || indices->dtype.is_uint()) {
1391 real_indices.
push_back(indices(indices_position));
1396 if (real_indices.
size() == ndim_d) {
1397 return data(real_indices);
1399 for (
size_t i = ndim_i - 1; i < out_index.
size(); ++i) {
1402 return data(real_indices);
1423 bool trans_a =
false,
bool trans_b =
false,
1424 std::string name =
"T_matmul", std::string tag =
kMatMul) {
1428 return tvm::sum((trans_a ? A[k][i] : A[i][k]) * (trans_b ? B[j][k] : B[k][j]), {k});
1445 std::string name =
"T_tensordot", std::string tag =
kMatMul) {
1446 ICHECK_GE(A->shape.size(), axes);
1447 ICHECK_GE(B->shape.size(), axes);
1449 Array<PrimExpr> output_shape(A->shape.begin(), A->shape.end() + (-axes));
1450 for (
auto it = B->shape.begin() + axes; it != B->shape.end(); ++it) output_shape.
push_back(*it);
1453 for (
int i = 0; i < axes; ++i)
1456 auto func = [&A, &B, &iter_vars, axes](
const Array<Var>& input_indices) {
1458 input_indices.begin() + (A->shape.size() - axes));
1459 for (
auto& v : iter_vars) A_indices.
push_back(v);
1462 for (
auto& v : iter_vars) B_indices.
push_back(v);
1464 auto it = input_indices.begin() + (A->shape.size() - axes);
1465 for (; it != input_indices.end(); ++it) B_indices.
push_back(*it);
1468 if (iter_vars.empty()) {
1469 return A(A_indices) * B(B_indices);
1471 return sum(A(A_indices) * B(B_indices), iter_vars);
1475 return compute(output_shape, func, name, tag);
1493 ICHECK_EQ(A_axes.
size(), B_axes.
size());
1495 auto A_axes_val = GetConstIntValues(A_axes,
"A_axes");
1496 auto B_axes_val = GetConstIntValues(B_axes,
"B_axes");
1499 for (
unsigned i = 0; i < A->shape.size(); ++i)
1500 if (std::find(A_axes_val.begin(), A_axes_val.end(), i) == A_axes_val.end())
1502 for (
unsigned i = 0; i < B->shape.size(); ++i)
1503 if (std::find(B_axes_val.begin(), B_axes_val.end(), i) == B_axes_val.end())
1507 for (
unsigned i = 0; i < B_axes_val.size(); ++i)
1510 auto func = [&A, &B, &iter_vars, A_axes_val, B_axes_val](
const Array<Var>& input_indices) {
1513 for (
unsigned i = 0; i < A->shape.size(); ++i) {
1514 auto axes_pos = std::find(A_axes_val.begin(), A_axes_val.end(), i);
1515 if (axes_pos == A_axes_val.end()) {
1516 A_indices.
push_back(input_indices[idx_input++]);
1518 A_indices.
push_back(iter_vars[axes_pos - A_axes_val.begin()]);
1523 for (
unsigned i = 0; i < B->shape.size(); ++i) {
1524 auto axes_pos = std::find(B_axes_val.begin(), B_axes_val.end(), i);
1525 if (axes_pos == B_axes_val.end()) {
1526 B_indices.
push_back(input_indices[idx_input++]);
1528 B_indices.
push_back(iter_vars[axes_pos - B_axes_val.begin()]);
1531 return sum(A(A_indices) * B(B_indices), iter_vars);
1533 return compute(output_shape, func, name, tag);
1543 [&](
const Array<Var>& indices) {
return tvm::cast(dtype, start + step * indices[0]); }, name,
1558 std::string name =
"T_meshgrid", std::string tag =
kInjective) {
1559 const bool cartesian_indexing = indexing ==
"xy" && inputs.
size() >= 2;
1561 for (
size_t i = 0; i < inputs.
size(); ++i) {
1562 const int src_index = (cartesian_indexing && i < 2) ? 1 - i : i;
1563 out_shape.
push_back(inputs[src_index]->
shape.size() == 0 ? 1 : inputs[src_index]->shape[0]);
1566 for (
size_t i = 0; i < inputs.
size(); ++i) {
1570 const int src_index = (cartesian_indexing && i < 2) ? 1 - i : i;
1571 auto ndim = inputs[i]->GetShape().
size();
1574 real_indices = {indices[src_index]};
1576 return inputs[i](real_indices);
1594 const std::string& dst_layout,
1595 const std::string schedule_rule =
"None",
1596 const std::string name =
"T_layout_trans",
1598 Layout src_layout_struct(src_layout);
1599 Layout dst_layout_struct(dst_layout);
1601 if (src_layout_struct.
Equals(dst_layout_struct)) {
1605 ICHECK(src_layout_struct.
defined() && dst_layout_struct.
defined())
1606 <<
"cannot convert from/to undefined layout";
1609 ICHECK(layout_converter.defined())
1610 <<
"cannot convert from " << src_layout <<
" to " << dst_layout;
1612 Array<PrimExpr> dst_shape = layout_converter.ForwardShape(src->shape);
1616 {
"src_layout",
String(src_layout)},
1617 {
"dst_layout",
String(dst_layout)},
1618 {
"input_shape", src->shape}};
1624 Array<PrimExpr> src_indices = layout_converter.BackwardIndex(dst_indices_expr);
1626 for (
size_t i = 0; i < src.
ndim(); ++i) {
1627 in_range = in_range && (src_indices[i] < src->shape[i]);
1636 std::vector<std::string>* axes) {
1638 std::string axis =
"";
1639 for (
char c : std::string(layout)) {
1640 if (c >=
'A' && c <=
'z') {
1643 shape->push_back(factor);
1646 }
else if (c >=
'0' && c <=
'9') {
1647 factor = factor * 10 + c -
'0';
1648 if (!axis.empty()) {
1649 axes->push_back(axis);
1653 LOG(FATAL) <<
"Invalid layout " << layout;
1656 if (!axis.empty()) {
1657 axes->push_back(axis);
1672 const String& dst_layout,
1673 const String name =
"T_auto_scheduler_layout_trans",
1676 std::vector<std::string> src_axes;
1678 std::vector<std::string> dst_axes;
1687 for (
const std::string& src_axis : src_axes) {
1689 CHECK_EQ(dst_indices_expr.
size(), dst_axes.size());
1690 for (
size_t i = 0; i < dst_axes.size(); ++i) {
1691 if (dst_axes[i] == src_axis) {
1692 src_index = src_index * dst_shape[i] + dst_indices_expr[i];
1697 return src(src_indices);
1739 const String name =
"T_meta_schedule_layout_trans",
1742 iter_domain.
reserve(src->shape.size());
1743 for (
const PrimExpr& e : src->shape) {
1746 Array<PrimExpr> post_transform_shape = index_map->MapShape(src->shape);
1748 post_transform_shape,
1750 return src(inv->MapIndices(Array<PrimExpr>{indices.begin(), indices.end()}));
1765 int ndim =
static_cast<int>(src->shape.size());
1770 auto idx = indices[0];
1772 for (
int i = 0; i < ndim; ++i) {
1789 const std::string& name =
"ndarray_size",
1791 int ndim =
static_cast<int>(src->shape.size());
1797 for (
int i = 0; i < ndim; ++i) {
1798 ret *= src->shape[i];
1820 int depth,
int axis,
const DataType& dtype,
1822 const std::string name =
"T_one_hot",
const std::string tag =
kInjective) {
1823 int true_axis = (axis == -1) ? indices->shape.size() : axis;
1824 if (oshape.size() == 0) {
1825 int ndim = indices->shape.size() + 1;
1826 int indices_index = 0;
1827 for (
int i = 0; i < ndim; i++) {
1828 if (i == true_axis) {
1829 oshape.push_back(
Integer(depth));
1831 oshape.push_back(indices->shape[indices_index++]);
1842 for (
size_t i = 0; i < iter_vars.
size(); i++) {
1843 if (
static_cast<int>(i) == true_axis) {
1847 indices_indices.
push_back(iter_vars[i]);
1850 auto idx = iter_vars[true_axis];
1851 return tir::Select(indices(indices_indices) == idx, on_value_cast, off_value_cast);
1868 const std::string name =
"T_sparse_to_dense",
1870 ICHECK(sparse_indices->dtype.is_int()) <<
"sparse_indices only accepts integer values";
1871 ICHECK_LE(sparse_indices->shape.size(), 3)
1872 <<
"sparse_indices tensor should be 0D, 1D, or 2D only";
1873 ICHECK_LE(sparse_values->shape.size(), 2) <<
"sparse_values tensor should be 0D or 1D only";
1875 const auto rank_sparse_indices =
static_cast<int>(sparse_indices->shape.size());
1877 for (
auto l : output_shape) {
1884 if (0 == rank_sparse_indices) {
1886 }
else if (1 == rank_sparse_indices) {
1887 for (
int j = 0; j < GetConstInt(sparse_indices->shape[0]); j++) {
1891 for (
int j = 0; j < GetConstInt(sparse_indices->shape[0]); j++) {
1893 for (
int k = 0; k < GetConstInt(sparse_indices->shape[1]); k++) {
1894 PrimExpr comparision = indices[k] == sparse_indices[j][k];
1895 aggregate_condition = 0 == k ? comparision : aggregate_condition && comparision;
1918 bool super_diag_right_align,
bool sub_diag_right_align,
1919 const std::string name =
"T_matrix_set_diag",
1921 size_t ndim = input->shape.size() - 1;
1923 bool only_one_diagonal = k1 == k2;
1928 auto get_diag = [&]() {
1929 Array<PrimExpr> diagonal_indices;
1930 PrimExpr k, offset = 0;
1931 for (size_t i = 0; i < ndim - 1; i++) {
1932 diagonal_indices.push_back(iter_vars[i]);
1934 if (only_one_diagonal) {
1938 k = iter_vars[ndim] - iter_vars[ndim - 1];
1939 diagonal_indices.push_back(k2 - k);
1942 auto get_offset = [&](PrimExpr M, PrimExpr N) {
1944 return diagonal->shape[diagonal->shape.size() - 1] - if_then_else(M < N, M, N);
1946 offset = if_then_else(
1948 super_diag_right_align ? get_offset(input->shape[ndim] - k, input->shape[ndim - 1])
1950 sub_diag_right_align ? get_offset(input->shape[ndim], input->shape[ndim - 1] + k)
1953 diagonal_indices.push_back(if_then_else(k >= 0, iter_vars[ndim - 1], iter_vars[ndim]) +
1955 return diagonal(diagonal_indices);
1959 get_diag(), input(iter_vars)),
1974 const std::string name =
"advanced_index",
1976 ICHECK_LE(indices.
size(), data->shape.size()) <<
"too many indices for data!";
1981 broadcast_shape = indices[0]->shape;
1982 for (
size_t i = 1; i < indices.
size(); ++i) {
1983 auto bh = detail::BroadcastShape(broadcast_shape, indices[i]->
shape);
1984 broadcast_shape =
Array<PrimExpr>(bh.common_shape.begin(), bh.common_shape.end());
1986 if (indices.
size() == 1) {
1991 for (
size_t i = 0; i < indices.
size(); ++i) {
1996 for (
const auto& dim : broadcast_shape) {
1999 for (
size_t i = indices.
size(); i < data->
shape.size(); ++i) {
2007 for (
size_t i = 0; i < broadcast_shape.
size(); ++i) {
2012 for (
size_t i = 0; i < bindices.
size(); ++i) {
2013 real_indices.
push_back(bindices[i](tensor_indices));
2015 for (
size_t i = broadcast_shape.
size(); i < iter_var.
size(); ++i) {
2016 real_indices.push_back(iter_var[i]);
2019 return data(real_indices);
Broadcast op constructions.
Constant integer literals in the program.
Definition: expr.h:491
int64_t value
the Internal value.
Definition: expr.h:494
Managed reference class to IntImmNode.
Definition: expr.h:520
Container of constant int that adds more constructors.
Definition: expr.h:622
Reference to PrimExprNode.
Definition: expr.h:114
DataType dtype() const
Definition: expr.h:128
Range constainer
Definition: expr.h:715
static Range FromMinExtent(PrimExpr min, PrimExpr extent, Span span=Span())
construct a new range with min and extent The corresponding constructor is removed,...
Analyzer that contains bunch of sub-analyzers.
Definition: analyzer.h:600
PrimExpr Simplify(const PrimExpr &expr, int steps=2)
Simplify expr.
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
void reserve(int64_t n)
Make sure the list has the capacity of at least n.
Definition: array.h:569
iterator end() const
Definition: array.h:390
void push_back(const T &item)
push a new item to the back of the list
Definition: array.h:457
void Set(int64_t i, T value)
set i-th element of the array.
Definition: array.h:621
iterator begin() const
Definition: array.h:387
size_t size() const
Definition: array.h:420
Runtime primitive data type.
Definition: data_type.h:42
static DataType Float(int bits, int lanes=1)
Construct an float type.
Definition: data_type.h:190
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:176
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
bool defined() const
Definition: object.h:548
const ObjectType * as() const
Try to downcast the internal Object to a raw pointer of a corresponding type.
Definition: object.h:892
Reference to string objects.
Definition: string.h:98
Tensor structure representing a possible input, or intermediate computation result.
Definition: tensor.h:102
size_t ndim() const
Definition: tensor.h:214
Bijective function mapping for data layout transformation. Given two Layout, BijectiveLayout build an...
Definition: data_layout.h:332
Definition: index_map.h:177
IndexMap Inverse(Array< Range > initial_ranges) const
Generate the inverse mapping.
Managed reference to LayoutNode.
Definition: data_layout.h:123
bool Equals(const Layout &rhs) const
Whether the two layouts are equal.
Definition: data_layout.h:278
Managed reference to SelectNode.
Definition: expr.h:609
a named variable in TIR
Definition: var.h:88
Utility functions for handling constants in TVM expressions.
Layout expression to describe the data organization of a tensor. And BijectiveLayout to mapping two d...
Defines a remapping of buffer indices.
Tensor expression language DSL.
Definition: extracted_task.h:33
IterVar reduce_axis(Range dom, std::string name="rv")
Create a new IterVar for reduction operations.
Tensor compute(Array< PrimExpr > shape, FCompute fcompute, std::string name="tensor", std::string tag="", Map< String, ObjectRef > attrs={})
Construct a new tensor by computing over shape, using the computation rule: result_tensor[axis] = fco...
PrimExpr make_const(DataType t, ValueType value, Span span=Span())
Make a const value with certain data type.
Definition: op.h:960
PrimExpr make_zero(DataType t, Span span=Span())
Make a const zero expr.
Definition: op.h:968
Tensor sequence_mask(const Tensor &data, const Tensor &valid_length, double mask_value, int axis, std::string name="T_sequence_mask", std::string tag=kInjective)
Mask the out-of-boundary elements of each sequence.
Definition: transform.h:943
Tensor gather_nd(const Tensor &data, const Tensor &indices, int batch_dims=0, std::string name="T_gather_nd", std::string tag=kInjective)
Gather elements from a n-dimension array.
Definition: transform.h:1361
constexpr auto kBroadcast
Definition: tags.h:36
Tensor transpose(const Tensor &x, Array< Integer > axes, std::string name="T_transpose", std::string tag=kInjective)
Permute the dimensions of an array.
Definition: transform.h:196
Tensor arange(const PrimExpr &start, const PrimExpr &stop, const PrimExpr &step, DataType dtype, std::string name="T_arange", std::string tag=kInjective)
Definition: transform.h:1536
Tensor strided_slice(const Tensor &x, const Array< Integer > &begin, const Array< Integer > &end, const Array< Integer > &strides, std::string slice_mode="end", std::string name="T_strided_slice", std::string tag=kInjective)
strided_slice of a tensor
Definition: transform.h:812
constexpr auto kInjective
Definition: tags.h:33
Tensor dynamic_strided_slice(const Tensor &x, const Array< PrimExpr > &begin, const Array< PrimExpr > &end, const Array< PrimExpr > &strides, std::string name="T_dynamic_strided_slice", std::string tag=kInjective)
strided_slice of a tensor where begin/end/stride can be mixed static and dynamic
Definition: transform.h:648
Tensor sliding_window(const Tensor &x, int axis, Array< Integer > window_shape, Array< Integer > strides, std::string name="T_sliding_window", std::string tag="")
Creates an operation to slide a window over the input x.
Definition: transform.h:68
Tensor reshape(const Tensor &x, Array< PrimExpr > newshape, std::string name="T_reshape", std::string tag=kInjective)
Reshape a tensor.
Definition: transform.h:320
Tensor one_hot(const Tensor &indices, const PrimExpr on_value, const PrimExpr off_value, int depth, int axis, const DataType &dtype, Array< PrimExpr > oshape=Array< PrimExpr >(), const std::string name="T_one_hot", const std::string tag=kInjective)
Returns a one-hot tensor where the locations repsented by indices take value on_value,...
Definition: transform.h:1819
Tensor meta_schedule_layout_transform(const Tensor &src, const tir::IndexMap &index_map, const String name="T_meta_schedule_layout_trans", const String tag=kInjective)
Transform the meta-schedule generated layout according to TIR's IndexMap.
Definition: transform.h:1738
Array< Tensor > meshgrid(const Array< Tensor > &inputs, const std::string &indexing, std::string name="T_meshgrid", std::string tag=kInjective)
Produce grids by expanding input over dimensions defined by other inputs.
Definition: transform.h:1557
Tensor tile(const Tensor &x, Array< Integer > reps, std::string name="T_tile", std::string tag=kBroadcast)
Creates an operation to tile elements of an array.
Definition: transform.h:1216
tvm::te::Tensor broadcast_to(const tvm::te::Tensor &t, const tvm::Array< tvm::PrimExpr > &output_shape, std::string name="T_broadcast_to", std::string tag=kBroadcast)
Creates an operation that broadcasts a tensor into a compatible shape according to numpy's rules.
Definition: broadcast.h:48
Tensor dyn_tile(const Tensor &x, Array< PrimExpr > new_shape, size_t rdim, std::string name="T_tile", std::string tag=kBroadcast)
Creates an operation to tile elements of an array.
Definition: transform.h:1271
Tensor adv_index(const Tensor &data, const Array< Tensor > &indices, const std::string name="advanced_index", const std::string tag=kInjective)
Numpy style advanced indexing with tensor.
Definition: transform.h:1973
Tensor concatenate(const Array< Tensor > &inputs, int axis=0, std::string name="T_concat", std::string tag=kInjective)
Join a sequence of tensors along an existing axis.
Definition: transform.h:466
void parse_auto_scheduler_layout(const String &layout, Array< PrimExpr > *shape, std::vector< std::string > *axes)
Utility function for auto_scheduler_layout_transform.
Definition: transform.h:1635
Tensor cast(const Tensor &x, DataType type, std::string name="T_cast", std::string tag=kElementWise)
Cast each element of x to the given type. If expr is scalar and type is a corresponding vector type,...
Definition: elemwise.h:281
Tensor expand_dims(const Tensor &x, int axis, int num_newaxis=1, std::string name="T_expand_dims", std::string tag=kBroadcast)
Creates an operation to insert new dimensions of length 1.
Definition: transform.h:147
Tensor squeeze(const Tensor &x, Array< Integer > axis, bool atleast1d=false, std::string name="T_squeeze", std::string tag=kInjective)
Remove size 1 dimensions from the shape of a tensor. The removed dimensions must have a constant size...
Definition: transform.h:403
Tensor sparse_to_dense(const Tensor &sparse_indices, const Array< PrimExpr > &output_shape, const Tensor &sparse_values, const PrimExpr &default_value, const std::string name="T_sparse_to_dense", const std::string tag=kInjective)
Get a dense tensor.
Definition: transform.h:1866
Tensor unravel_index(const Tensor &x, const Tensor &shape, std::string name="T_unravel", std::string tag=kInjective)
Converts a flat index or array of flat indices into a tuple of coordinate arrays.
Definition: transform.h:355
Tensor auto_scheduler_layout_transform(const Tensor &src, const String &src_layout, const String &dst_layout, const String name="T_auto_scheduler_layout_trans", const String tag=kInjective)
Transform the auto-scheduler generated layout according to src_layout and dst_layout.
Definition: transform.h:1671
Tensor ndarray_size(const Tensor &src, const DataType &dtype, const std::string &name="ndarray_size", const std::string &tag=kInjective)
Get the size of input tensor.
Definition: transform.h:1788
Tensor layout_transform(const Tensor &src, const std::string &src_layout, const std::string &dst_layout, const std::string schedule_rule="None", const std::string name="T_layout_trans", const std::string tag=kInjective)
Transform the layout according to src_layout and dst_layout.
Definition: transform.h:1593
Tensor take(const Tensor &a, const Tensor &indices, int batch_dims, std::string mode="clip", std::string name="T_take", std::string tag=kInjective)
Take elements from an flattened input array when axis is None.
Definition: transform.h:895
constexpr auto kMatMul
Definition: tags.h:37
Tensor reverse_sequence(const Tensor &x, const Tensor &seq_lengths, int seq_axis=1, int batch_axis=0, std::string name="T_reverse_sequence", std::string tag=kInjective)
Reverse the tensor for variable length slices. Input is first sliced along batch axis and then elemen...
Definition: transform.h:255
Tensor sum(const Tensor &data, const Array< Integer > &axis, bool keepdims=false, bool atleast1d=false)
Creates an operation that sums array elements over a given axis.
Definition: reduction.h:326
Tensor tensordot(const Tensor &A, const tvm::te::Tensor &B, int axes=2, std::string name="T_tensordot", std::string tag=kMatMul)
A generalization of matrix multiplication to tensors.
Definition: transform.h:1444
Tensor stack(const Array< Tensor > &inputs, int axis=0, std::string name="T_stack", std::string tag=kInjective)
Join a sequence of tensors along a new axis.
Definition: transform.h:525
Array< Tensor > split_sections(const Tensor &x, int num_sections, int axis, std::string name="T_split_sections", std::string tag=kInjective)
Split a tensor into a number of sub-tensors.
Definition: transform.h:853
Tensor strided_slice_with_axes(const Tensor &x, const Array< Integer > &begin, const Array< Integer > &end, const Array< Integer > &strides, const Array< Integer > &axes, std::string slice_mode="end", std::string name="T_strided_slice_with_axes", std::string tag=kInjective)
strided_slice of a tensor
Definition: transform.h:766
tvm::te::Tensor matmul(const tvm::te::Tensor &A, const tvm::te::Tensor &B, bool trans_a=false, bool trans_b=false, std::string name="T_matmul", std::string tag=kMatMul)
Creates an operation that calculates a matrix multiplication (row-major notation): A(i,...
Definition: transform.h:1422
Tensor matrix_set_diag(const Tensor &input, const Tensor &diagonal, int k1, int k2, bool super_diag_right_align, bool sub_diag_right_align, const std::string name="T_matrix_set_diag", const std::string tag=kInjective)
Returns a tensor with the diagonal of input tensor replaced with the provided diagonals.
Definition: transform.h:1917
Tensor where(const Tensor &condition, const Tensor &x, const Tensor &y, std::string name="T_where", std::string tag=kBroadcast)
Return the elements, either from x or y, depending on the condition.
Definition: transform.h:1129
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1763
Tensor gather(const Tensor &data, int axis, const Tensor &indices, std::string name="T_gather", std::string tag=kInjective)
Gather values along given axis from given indices.
Definition: transform.h:1308
Array< Tensor > split(const Tensor &x, Array< PrimExpr > split_indices, int axis, std::string name="T_split", std::string tag=kInjective)
Split a tensor into multiple sub-tensors.
Definition: transform.h:571
Tensor repeat(const Tensor &x, int repeats, int axis, std::string name="T_repeat", std::string tag=kBroadcast)
Creates an operation to repeat elements of an array.
Definition: transform.h:1169
Array< PrimExpr > StridedSliceOutputShape(const Array< PrimExpr > &ishape, const Array< Integer > &begin, const Array< Integer > &end, const Array< Integer > &strides, const Array< Integer > &axes, const std::string &slice_mode)
Calcluate the output shape of strided_slice, the entry point for Relay type relation.
Definition: transform.h:738
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
PrimExpr truncmod(PrimExpr a, PrimExpr b, Span span=Span())
compute the remainder of truncdiv
PrimExpr if_then_else(PrimExpr cond, PrimExpr true_value, PrimExpr false_value, Span span=Span())
Conditional expression.
PrimExpr cast(const DataType &t, PrimExpr value, Span span=Span())
cast value to type.
PrimExpr max_value(const DataType &dtype, Span span=Span())
PrimExpr ceil(PrimExpr x, Span span=Span())
Calculate ceil(x)
PrimExpr indexdiv(PrimExpr a, PrimExpr b, Span span=Span())
compute floor(a / b) where a and b are non-negative.
PrimExpr min(PrimExpr a, PrimExpr b, Span span=Span())
take minimum of two values
PrimExpr indexmod(PrimExpr a, PrimExpr b, Span span=Span())
compute the remainder floor(a / b) where a and b are non-negative.
PrimExpr floordiv(PrimExpr a, PrimExpr b, Span span=Span())
compute floor(a / b)
PrimExpr sum(PrimExpr source, Array< tir::IterVar > axis, Array< PrimExpr > init={}, Span span=Span())
sum of source expression over axis
Operation node can generate one or multiple Tensors.
Index ravel and unraval operations.
Utility functions for strided_slice op.
Utility functions for handling tensor.