24#ifndef TVM_TOPI_NN_POOLING_H_
25#define TVM_TOPI_NN_POOLING_H_
54 bool count_include_pad) {
56 TVM_FFI_ICHECK(
x->shape.size() >= 2) <<
"Pooling input must >= 2-D (H, W)";
81 ffi::Array<PrimExpr>
pad_before(std::vector<PrimExpr>(
x->shape.size(), 0));
85 ffi::Array<PrimExpr>
pad_after(std::vector<PrimExpr>(
x->shape.size(), 0));
125 [&](
const ffi::Array<PrimVar>&
inds) {
139 [&](
const ffi::Array<PrimVar>&
inds) {
165 "T_pool_grad",
"pool_grad_max");
173 [&](
const ffi::Array<PrimVar>&
inds) {
191 if (count_include_pad) {
212 "T_pool_grad",
"pool_grad_avg");
236 for (
size_t i = 0;
i < layout.size(); ++
i) {
237 if ((layout[
i] >=
'A' && layout[
i] <=
'Z') || (layout[
i] >=
'a' && layout[
i] <=
'z')) {
247 }
else if (layout[
i] ==
'd' || layout[
i] ==
'h' || layout[
i] ==
'w') {
303 bool ceil_mode,
const std::string& layout =
"NCHW",
304 bool count_include_pad =
true) {
307 <<
"Unsupported layout " << layout;
333 const auto n_dim = output_size.size();
339 for (
size_t i = 0;
i <
n_dim; ++
i) {
346 ffi::Array<PrimExpr> indices;
347 for (
size_t i = 0;
i < output.size(); ++
i) indices.push_back(output[
i]);
349 for (
size_t i = 0;
i <
n_dim; ++
i) {
352 auto rv_name =
"rv" + std::to_string(
i);
362 ffi::Map<ffi::String, ffi::Any> attrs;
364 attrs.Set(
"schedule_rule", tvm::ffi::String(
"meta_schedule.adaptive_pool_max"));
367 [&](
const ffi::Array<PrimVar>& output) {
368 ffi::Array<PrimExpr> indices;
373 "adaptive_pool_max",
"adaptive_pool_max", attrs);
375 attrs.Set(
"schedule_rule", tvm::ffi::String(
"meta_schedule.adaptive_pool_avg"));
378 [&](
const ffi::Array<PrimVar>& output) {
379 ffi::Array<PrimExpr> indices;
384 "adaptive_pool_sum",
"adaptive_pool_sum");
388 [&](
const ffi::Array<PrimVar>& output) {
389 ffi::Array<PrimExpr> indices;
394 for (
size_t i = 0;
i <
n_dim; ++
i) {
437 <<
"Unsupported layout " << layout;
453 <<
"Unsupported layout " << layout;
521 bool ceil_mode,
const std::vector<int>& axis,
bool count_include_pad) {
525 <<
"Pooling stride_size must have same elements as kernel";
527 <<
"Pooling padding_size must has double elements of"
531 ffi::Array<IterVar>
daxis;
533 std::vector<PrimExpr> stride(
k_size);
534 std::vector<PrimExpr> dilation(
k_size);
537 std::vector<PrimExpr> offset(
k_size, 0);
558 offset[
i] = stride[
i] - 1;
589 ffi::Map<ffi::String, ffi::Any> attrs;
593 attrs.Set(
"schedule_rule", tvm::ffi::String(
"meta_schedule.pool_max"));
596 [&](
const ffi::Array<PrimVar>& output) {
597 ffi::Array<PrimExpr> indices;
602 indices.Set(
ii, output[
ii] * stride[
i] +
daxis[
i] * dilation[
i]);
606 "pool_max",
"pool_max", attrs);
608 attrs.Set(
"schedule_rule", tvm::ffi::String(
"meta_schedule.pool_avg"));
615 [&](
const ffi::Array<PrimVar>& output) {
616 ffi::Array<PrimExpr> indices;
621 indices.Set(
ii, output[
ii] * stride[
i] +
daxis[
i] * dilation[
i]);
625 "pool_sum",
"pool_sum");
630 [&](
const ffi::Array<PrimVar>& output) {
631 ffi::Array<PrimExpr> indices;
633 if (count_include_pad) {
634 std::vector<PrimExpr> start(
k_size);
650 std::vector<PrimExpr> start(
k_size);
718 const std::string& layout =
"NCW",
bool count_include_pad =
true) {
723 ceil_mode, axis, count_include_pad);
760 const std::string& layout =
"NCHW",
bool count_include_pad =
true) {
763 <<
"Unsupported layout " << layout;
766 ceil_mode, axis, count_include_pad);
804 const std::string& layout =
"NCDHW",
bool count_include_pad =
true) {
807 <<
"Unsupported layout " << layout;
810 ceil_mode, axis, count_include_pad);
Algebra expression simplifications.
Managed reference class to IntImmNode.
Definition expr.h:504
static IntImm Int32(int64_t value, Span span=Span())
Construct a scalar int32 constant.
Definition expr.h:528
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:401
Definition base_expr.h:137
static PrimType Int(int bits, int lanes=1)
Construct a signed integer type with fixed lanes.
Range container
Definition expr.h:610
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
Managed reference to AnalyzerObj.
Definition analyzer.h:931
Managed reference to AndNode.
Definition expr.h:438
Managed reference to SelectNode.
Definition expr.h:525
Tensor structure representing a possible input, or intermediate computation result.
Definition tensor.h:98
Checked scalar view over a VarNode.
Definition var.h:46
Tensor expression language DSL.
Definition extracted_task.h:33
PrimVar var(std::string name_hint, PrimType t=PrimType::Int(32))
Construct a new Var expression.
IterVar reduce_axis(Range dom, std::string name="rv")
Create a new IterVar for reduction operations.
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...
const int64_t * as_const_int(const PrimExpr &x)
Get x as constant int expression.
Definition op.h:840
PrimExpr MakeConst(PrimType dtype, ValueType value, Span span=Span())
Make a const value with certain data type.
Definition op.h:1002
Tensor adaptive_pool3d(const Tensor &x, const ffi::Array< PrimExpr > &output_size, PoolType pool_type, const std::string &layout="NCDHW")
Adaptively perform pooling on three dimensional data. See the two dimensional version above for detai...
Definition pooling.h:449
Tensor adaptive_pool(const Tensor &x, const ffi::Array< PrimExpr > &output_size, PoolType pool_type, const std::string &layout="NCHW")
Adaptively perform pooling on height and width dimension of data. The pooling kernel and stride sizes...
Definition pooling.h:433
PoolType
Pooling type.
Definition pooling.h:44
@ kAvgPool
Definition pooling.h:45
@ kMaxPool
Definition pooling.h:46
PrimExpr start_index(const PrimVar &out_index, const PrimExpr &odim, const PrimExpr &idim)
Definition pooling.h:312
Tensor adaptive_pool1d(const Tensor &x, const ffi::Array< PrimExpr > &output_size, PoolType pool_type, const std::string &layout="NCW")
Adaptively perform pooling on one dimensional data. See the two dimensional version above for details...
Definition pooling.h:465
Tensor pool3d(const Tensor &x, const ffi::Array< PrimExpr > &kernel_size, const ffi::Array< PrimExpr > &stride_size, const ffi::Array< PrimExpr > &dilation_size, const ffi::Array< PrimExpr > &padding_size, PoolType pool_type, bool ceil_mode, const std::string &layout="NCDHW", bool count_include_pad=true)
Perform pooling on depth, height and width dimension of data. It decides the depth,...
Definition pooling.h:800
Tensor pool2d(const Tensor &x, const ffi::Array< PrimExpr > &kernel_size, const ffi::Array< PrimExpr > &stride_size, const ffi::Array< PrimExpr > &dilation_size, const ffi::Array< PrimExpr > &padding_size, PoolType pool_type, bool ceil_mode, const std::string &layout="NCHW", bool count_include_pad=true)
Perform pooling on height and width dimension of data. It decides the height and width dimension acco...
Definition pooling.h:756
Tensor pool_grad_impl(const Tensor &out_grad, const Tensor &x, const ffi::Array< PrimExpr > &kernel_size, const ffi::Array< PrimExpr > &stride_size, const ffi::Array< PrimExpr > &padding_size, PoolType pool_type, bool ceil_mode, const size_t height_axis, const size_t width_axis, bool count_include_pad)
Definition pooling.h:49
Tensor pool_grad(const Tensor &out_grad, const Tensor &x, const ffi::Array< PrimExpr > &kernel_size, const ffi::Array< PrimExpr > &stride_size, const ffi::Array< PrimExpr > &padding_size, PoolType pool_type, bool ceil_mode, const std::string &layout="NCHW", bool count_include_pad=true)
Calculate gradient of pooling on height and width dimension of data. It decides the height and width ...
Definition pooling.h:299
bool find_depth_height_width(const std::string &layout, int *depth_axis, int *height_axis, int *width_axis)
Find index of Depth, Height or Width dimension in a layout string.
Definition pooling.h:230
bool find_width(const std::string &layout, int *width_axis)
Definition pooling.h:264
Tensor pool_impl_nd(const Tensor &x, const ffi::Array< PrimExpr > &kernel_size, const ffi::Array< PrimExpr > &stride_size, const ffi::Array< PrimExpr > &dilation_size, const ffi::Array< PrimExpr > &padding_size, PoolType pool_type, bool ceil_mode, const std::vector< int > &axis, bool count_include_pad)
Perform pooling on N-dimension of data.
Definition pooling.h:517
PrimExpr end_index(const PrimVar &out_index, const PrimExpr &odim, const PrimExpr &idim)
Definition pooling.h:316
bool find_height_width(const std::string &layout, int *height_axis, int *width_axis)
Definition pooling.h:260
Tensor global_pool(const Tensor &x, PoolType pool_type, const std::string &layout="NCHW")
Perform global pooling on height and width dimension of data. It decides the height and width dimensi...
Definition pooling.h:497
Tensor adaptive_pool_impl(const Tensor &x, const ffi::Array< PrimExpr > &output_size, PoolType pool_type, const std::vector< int > &axes)
Perform adaptive pooling on N dimensional data.
Definition pooling.h:331
Tensor pool1d(const Tensor &x, const ffi::Array< PrimExpr > &kernel_size, const ffi::Array< PrimExpr > &stride_size, const ffi::Array< PrimExpr > &dilation_size, const ffi::Array< PrimExpr > &padding_size, PoolType pool_type, bool ceil_mode, const std::string &layout="NCW", bool count_include_pad=true)
Perform pooling on the width dimension of data. Width axis is determined by the layout string in whic...
Definition pooling.h:714
constexpr auto kElementWise
Definition tags.h:32
FCommReduce MakeArgmaxReducer(bool select_last_index=false)
Definition reduction.h:519
tvm::te::Tensor pad(const tvm::te::Tensor &t, const tvm::ffi::Array< tvm::PrimExpr > &pad_before, tvm::ffi::Array< tvm::PrimExpr > pad_after=tvm::ffi::Array< tvm::PrimExpr >(), PrimExpr pad_value=PrimExpr(), std::string name="T_pad", std::string tag=kElementWise, std::string pad_mode="constant", const ffi::Array< PrimExpr > *dyn_output_shape=nullptr)
Creates an operation that performs padding.
Definition nn.h:156
constexpr auto kCommReduceIdx
Definition tags.h:35
Tensor argmax(const Tensor &data, const ffi::Optional< ffi::Array< int64_t > > &axis, bool keepdims=false, bool atleast1d=false, bool select_last_index=false)
Creates an operation that finds the indices of the maximum values over a given axis.
Definition reduction.h:573
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
PrimExpr max(PrimExpr a, PrimExpr b, Span span=Span())
take maximum of two values
PrimExpr div(PrimExpr a, PrimExpr b, Span span=Span())
compute division in C semantics.
PrimExpr if_then_else(PrimExpr cond, PrimExpr true_value, PrimExpr false_value, Span span=Span())
Conditional expression.
PrimExpr cast(PrimType t, PrimExpr value, Span span=Span())
cast value to type.
PrimExpr min_value(PrimType dtype, Span span=Span())
PrimExpr indexdiv(PrimExpr a, PrimExpr b, Span span=Span())
compute floor(a / b) where a and b are non-negative.
PrimExpr sum(PrimExpr source, ffi::Array< tirx::IterVar > axis, ffi::Array< PrimExpr > init={}, Span span=Span())
sum of source expression over axis
PrimExpr indexmod(PrimExpr a, PrimExpr b, Span span=Span())
compute the remainder floor(a / b) where a and b are non-negative.
Reduction op constructors.