24#ifndef TVM_TOPI_NN_LOCAL_RESPONSE_NORM_H_
25#define TVM_TOPI_NN_LOCAL_RESPONSE_NORM_H_
52inline Tensor lrn(
const Tensor& data,
int size,
int axis = 1,
float alpha = 0.0001,
53 float beta = 0.75,
float bias = 2, std::string name =
"tensor",
55 TVM_FFI_ICHECK_EQ(data->shape.size(), 4) <<
"LRN requires 4-D input";
56 TVM_FFI_ICHECK_EQ(size % 2, 1) <<
"size should be odd number";
57 TVM_FFI_ICHECK(axis == 1 || axis == 3) <<
"axis should be 1 or 3 for NCHW and NHWC";
59 TVM_FFI_ICHECK_EQ(data->dtype.code(), DLDataTypeCode::kDLFloat) <<
"datatype should be float";
60 auto input_shape = data->shape;
61 ffi::Array<PrimExpr> pad_before{0, 0, 0, 0};
62 ffi::Array<PrimExpr> pad_after{0, 0, 0, 0};
63 pad_before.Set(axis,
static_cast<PrimExpr>(size / 2));
64 pad_after.Set(axis,
static_cast<PrimExpr>(size / 2));
65 auto pad_data =
pad(data, pad_before, pad_after, 0,
"pad_data");
72 return tvm::prim::sum(pad_data(i, l + rxs, j, k) * pad_data(i, l + rxs, j, k), {rxs});
79 return tvm::prim::sum(pad_data(i, l, j, k + rxs) * pad_data(i, l, j, k + rxs), {rxs});
90 return tvm::prim::pow(bias_imm + (
div(alpha_imm * sqr_sum(i, j, k, l), size)), beta_imm);
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
Definition base_expr.h:161
Checked scalar view over a VarNode.
Definition expr.h:742
Range container
Definition expr.h:1025
Tensor structure representing a possible input, or intermediate computation result.
Definition tensor.h:111
PrimExpr sum(PrimExpr source, ffi::Array< s_tir::IterVar > axis, ffi::Array< PrimExpr > init={}, Location loc=UnknownLoc())
sum of source expression over axis
PrimExpr MakeConst(PrimType dtype, ValueType value, Location loc=UnknownLoc())
Make a const value with certain data type.
Definition op.h:553
TVM_TIRX_DLL PrimExpr pow(PrimExpr x, PrimExpr y, Location loc=UnknownLoc())
Calculate power(x, y)
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(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 lrn(const Tensor &data, int size, int axis=1, float alpha=0.0001, float beta=0.75, float bias=2, std::string name="tensor", std::string tag=kBroadcast)
Local response normalization inference operator.
Definition local_response_norm.h:52
constexpr auto kElementWise
Definition tags.h:32
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 >(), ffi::Optional< PrimExpr > pad_value=std::nullopt, 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:155
constexpr auto kBroadcast
Definition tags.h:36
tvm::PrimExpr divide(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition broadcast.h:241
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
TVM_TIRX_DLL PrimExpr div(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
compute division in C semantics.
Operation node can generate one or multiple Tensors.