24#ifndef TVM_TOPI_NN_DILATE_H_
25#define TVM_TOPI_NN_DILATE_H_
48 TVM_FFI_ICHECK_GT(args.size(), 0) <<
"all requires at least one argument";
51 for (
size_t i = 1; i < args.size(); ++i) {
71 std::string name =
"tensor", std::string tag =
kInjective) {
73 auto n = x->shape.size();
74 TVM_FFI_ICHECK_EQ(n, strides.size())
75 <<
"strides size (" << strides.size() <<
") must match dimension of x (" << n <<
")";
77 ffi::Array<PrimExpr> out_shape;
79 for (
size_t i = 0; i < n; ++i) {
80 out_shape.push_back(analyzer->Simplify((x->shape[i] - 1) * (strides[i] + 1)));
85 [&](
const ffi::Array<PrimVar>& indices) {
86 ffi::Array<PrimExpr> not_zero;
87 ffi::Array<PrimExpr> index_tuple;
88 for (
size_t i = 0; i < n; ++i) {
89 if (IsConstInt(strides[i]) && strides[i].as_or_throw<IntImm>()->value == 1) {
90 index_tuple.push_back(indices[i]);
92 index_tuple.push_back(
indexdiv(indices[i], strides[i]));
93 not_zero.push_back((
indexmod(indices[i], strides[i])) == 0);
96 if (not_zero.size() > 0) {
97 auto all_not_zero = all(not_zero);
98 return tvm::if_then_else(all_not_zero, x(index_tuple),
99 MakeConst(PrimType(x->dtype), dilation_value));
101 return x(index_tuple);
Algebra expression simplifications.
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
Managed reference to AnalyzerObj.
Definition analyzer.h:916
Tensor structure representing a possible input, or intermediate computation result.
Definition tensor.h:111
Tensor expression language DSL.
Definition extracted_task.h:33
Tensor compute(ffi::Array< PrimExpr > shape, FCompute fcompute, std::string name="tensor", std::string tag="", ffi::Map< ffi::String, ffi::Any > attrs={})
Construct a new tensor by computing over shape, using the computation rule: result_tensor[axis] = fco...
Tensor dilate(const Tensor &x, ffi::Array< PrimExpr > strides, double dilation_value, std::string name="tensor", std::string tag=kInjective)
Dilate data with given dilation value (0 by default).
Definition dilate.h:70
PrimExpr all(ffi::Array< PrimExpr > args)
Create a new expression of the logical and of all conditions in the arguments.
Definition dilate.h:47
constexpr auto kInjective
Definition tags.h:33
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
TVM_TIRX_DLL PrimExpr indexdiv(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
compute floor(a / b) where a and b are non-negative.
TVM_TIRX_DLL PrimExpr indexmod(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
compute the remainder floor(a / b) where a and b are non-negative.
Operation node can generate one or multiple Tensors.