56 std::string name =
"T_relu", std::string tag =
kElementWise) {
59 [&](
const tvm::ffi::Array<tvm::tirx::PrimVar>&
i) {
60 auto threshold_const = tvm::tirx::MakeConst(tvm::PrimType(t->dtype), threshold);
61 return tvm::max(t(i), threshold_const);
77 std::string name =
"T_leaky_relu",
81 [&](
const tvm::ffi::Array<tvm::tirx::PrimVar>&
i) {
83 auto calpha = tvm::tirx::MakeConst(value.ty(), alpha);
84 return tvm::prim::Select(value > 0, value, value * calpha);
101 const int axis = 1, std::string name =
"T_prelu",
105 topi::detail::GetConstInt(
x->shape[axis]))
106 <<
"Wrong slope shape received.";
110 [&](
const tvm::ffi::Array<tvm::tirx::PrimVar>& indices) {
111 auto xval = x(indices);
112 return tvm::prim::Select(xval > 0, xval, xval * slope(indices[axis]));
158 tvm::ffi::Array<tvm::PrimExpr>
pad_after = tvm::ffi::Array<tvm::PrimExpr>(),
160 std::string pad_mode =
"constant",
const ffi::Array<PrimExpr>*
dyn_output_shape =
nullptr) {
180 tvm::ffi::Array<tvm::PrimExpr> output_shape;
182 for (
size_t i = 0;
i <
t->shape.size(); ++
i) {
184 output_shape.push_back(
t->shape[
i]);
186 output_shape.push_back(
196 if (!pad_value.defined()) {
200 auto l = [&](tvm::ffi::Array<tvm::tirx::PrimVar>
ovars) {
201 tvm::ffi::Array<tvm::PrimExpr> indices;
202 tvm::ffi::Array<tvm::PrimExpr>
sel;
203 tvm::ffi::Array<tvm::PrimExpr>
pad_idx;
204 for (
size_t i = 0;
i <
t->shape.size(); ++
i) {
206 indices.push_back(
ovars[
i]);
213 indices.push_back(
ovars[
i]);
219 if (pad_mode ==
"edge") {
224 }
else if (pad_mode ==
"reflect") {
232 if (
sel.size() != 0) {
233 if (pad_mode ==
"constant") {
237 t(indices), pad_value);
238 }
else if (pad_mode ==
"edge" || pad_mode ==
"reflect") {
272 std::string name =
"T_conv2d_nchw",
276 auto pH =
I->shape[2];
277 auto pW =
I->shape[3];
278 tvm::ffi::Array<tvm::PrimExpr> output_shape{
317 std::string name =
"T_conv2d_hwcn",
321 auto pH =
I->shape[2];
322 auto pW =
I->shape[3];
323 tvm::ffi::Array<tvm::PrimExpr> output_shape{
363 std::string name =
"T_depthwise_conv2d_nchw",
367 auto pH =
I->shape[2];
368 auto pW =
I->shape[3];
369 auto pCM =
W->shape[1];
370 tvm::ffi::Array<tvm::PrimExpr> output_shape{
393 std::string name =
"T_depthwise_conv2d_nhwc",
397 auto pH =
I->shape[1];
398 auto pW =
I->shape[2];
399 auto pCM =
W->shape[1];
400 tvm::ffi::Array<tvm::PrimExpr> output_shape{
443 std::string name =
"T_group_conv2d_ngchw",
447 auto pH =
I->shape[2];
448 auto pW =
I->shape[3];
449 tvm::ffi::Array<tvm::PrimExpr> output_shape{
463 auto l = [&](tvm::ffi::Array<tvm::tirx::PrimVar> args) {
490 const tvm::ffi::Array<tvm::PrimExpr>&
pad_before,
491 const tvm::ffi::Array<tvm::PrimExpr>&
pad_after,
493 std::string name =
"space_to_batch_nd",
498 <<
"Paddings must be provided for each spatial dimension";
514 if (!pad_value.defined()) {
523 tvm::ffi::Array<PrimExpr>
r_shape;
524 tvm::ffi::Array<int64_t> axis;
525 tvm::ffi::Array<PrimExpr>
o_shape;
538 "Input dimension after padding ("
540 <<
" must be divisible by its block size (" <<
block_size <<
")";
549 size_t n = axis.size();
552 for (
size_t i = 0;
i <
n;
i++) {
553 axis.push_back(axis[
i] - 1);
591 std::string name =
"batch_to_space_nd",
594 ffi::Array<PrimExpr>
in_shape = data->shape;
596 ffi::Array<int64_t> axis;
636 ffi::Array<IntImm> strides;
646 <<
"Incorrect crop sizes for (" <<
i <<
")th dim, can not crop more than"
675 std::string reduction =
"mean",
int ignore_index = -100,
676 const std::string name =
"nll_loss",
const std::string tag =
kBroadcast) {
688 if (reduction ==
"mean") {
705 auto c = targets(target_indices);
706 tvm::ffi::Array<tvm::PrimExpr> pred_indices;
707 pred_indices.push_back(target_indices[0]);
708 pred_indices.push_back(c);
709 for (size_t i = 1; i < target_indices.size(); i++) {
710 pred_indices.push_back(target_indices[i]);
717 if (reduction ==
"mean") {
721 auto c = targets(target_indices);
722 return tvm::prim::Select(c != ignore_index, weights(c),
723 tvm::tirx::MakeConst(tvm::PrimType(predictions->dtype), 0));
727 topi::sum(
W, tvm::ffi::Array<int64_t>(
nullptr)));
728 }
else if (reduction ==
"sum") {
729 return topi::sum(
T, tvm::ffi::Array<int64_t>(
nullptr));
Algebra expression simplifications.
Managed reference class to IntImmNode.
Definition expr.h:504
static IntImm Bool(bool value, Span span=Span())
Construct a scalar boolean constant.
Definition expr.h:519
static IntImm Int64(int64_t value, Span span=Span())
Construct a scalar int64 constant.
Definition expr.h:537
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
Definition source_map.h:111
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 SelectNode.
Definition expr.h:525
Managed Tensor. The array is backed by reference counted blocks.
Definition tensor.h:49
Tensor structure representing a possible input, or intermediate computation result.
Definition tensor.h:98
Checked scalar view over a VarNode.
Definition var.h:46
Utility functions for handling constants in TVM expressions.
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...
PrimExpr foldl(FReduce freduce, PrimExpr init_value, const ffi::Array< PrimExpr > &values, Span span=Span())
Left fold.
Definition op.h:904
PrimExpr MakeConst(PrimType dtype, ValueType value, Span span=Span())
Make a const value with certain data type.
Definition op.h:1002
constexpr auto kElementWise
Definition tags.h:32
Tensor reshape(const Tensor &x, ffi::Array< PrimExpr > newshape, std::string name="T_reshape", std::string tag=kInjective)
Reshape a tensor.
Definition transform.h:329
Tensor shape(const Tensor &src, PrimType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition transform.h:2009
tvm::te::Tensor batch_to_space_nd(const tvm::te::Tensor &data, const tvm::ffi::Array< int64_t > &block_shape, const tvm::ffi::Array< tvm::PrimExpr > &crop_begin_list, const tvm::ffi::Array< tvm::PrimExpr > &crop_end_list, std::string name="batch_to_space_nd", std::string tag=kInjective)
Reshape the batch dimension into spatial dimensions.
Definition nn.h:587
constexpr auto kBroadcast
Definition tags.h:36
constexpr auto kInjective
Definition tags.h:33
constexpr auto kConv2dNCHW
Definition tags.h:38
tvm::te::Tensor prelu(const tvm::te::Tensor &x, const tvm::te::Tensor &slope, const int axis=1, std::string name="T_prelu", std::string tag=kBroadcast)
Creates an operation that performs a parametric rectified linear unit.
Definition nn.h:100
Tensor strided_slice(const Tensor &x, const ffi::Array< ffi::Optional< IntImm > > &begin, const ffi::Array< ffi::Optional< IntImm > > &end, const ffi::Array< IntImm > &strides, std::string slice_mode="end", std::string name="T_strided_slice", std::string tag=kInjective)
strided_slice of a tensor
Definition transform.h:964
tvm::te::Tensor group_conv2d_ngchw(const tvm::te::Tensor &I, const tvm::te::Tensor &W, int pad_h=0, int pad_w=0, int stride_h=1, int stride_w=1, std::string name="T_group_conv2d_ngchw", std::string tag=kGroupConv2d)
Creates an operation that performs a 2-D group convolution with an NGCHW-layout.
Definition nn.h:440
tvm::te::Tensor leaky_relu(const tvm::te::Tensor &t, double alpha=0.1, std::string name="T_leaky_relu", std::string tag=kElementWise)
Creates an operation that performs a leaky rectified linear unit.
Definition nn.h:76
tvm::PrimExpr divide(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition broadcast.h:241
constexpr auto kDepthwiseConv2dNCHW
Definition tags.h:40
tvm::te::Tensor space_to_batch_nd(const tvm::te::Tensor &data, const tvm::ffi::Array< int64_t > &block_shape, const tvm::ffi::Array< tvm::PrimExpr > &pad_before, const tvm::ffi::Array< tvm::PrimExpr > &pad_after, PrimExpr pad_value=PrimExpr(), std::string name="space_to_batch_nd", std::string tag=kInjective)
Divide spatial dimensions of the input into a grid of blocks.
Definition nn.h:488
tvm::te::Tensor depthwise_conv2d_nchw(const tvm::te::Tensor &I, const tvm::te::Tensor &W, int pad_h=0, int pad_w=0, int stride_h=1, int stride_w=1, std::string name="T_depthwise_conv2d_nchw", std::string tag=kDepthwiseConv2dNCHW)
Creates an operation that performs a 2-D depthwise convolution with an NCHW-layout.
Definition nn.h:360
constexpr auto kGroupConv2d
Definition tags.h:45
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 kConv2dHWCN
Definition tags.h:39
constexpr auto kDepthwiseConv2dNHWC
Definition tags.h:41
tvm::te::Tensor conv2d_nchw(const tvm::te::Tensor &I, const tvm::te::Tensor &W, int pad_h=0, int pad_w=0, int stride_h=1, int stride_w=1, std::string name="T_conv2d_nchw", std::string tag=kConv2dNCHW)
Creates an operation that performs a 2-D convolution with an NCHW-layout.
Definition nn.h:270
Tensor transpose(const Tensor &x, ffi::Optional< ffi::Array< int64_t > > opt_axes, std::string name="T_transpose", std::string tag=kInjective)
Permute the dimensions of an array.
Definition transform.h:205
tvm::te::Tensor conv2d_hwcn(const tvm::te::Tensor &I, const tvm::te::Tensor &W, int pad_h=0, int pad_w=0, int stride_h=1, int stride_w=1, std::string name="T_conv2d_hwcn", std::string tag=kConv2dHWCN)
Creates an operation for 2-D convolution layer with an HWCN-layout.
Definition nn.h:315
tvm::te::Tensor relu(const tvm::te::Tensor &t, T threshold=static_cast< T >(0), std::string name="T_relu", std::string tag=kElementWise)
Creates an operation that performs a rectified linear unit.
Definition nn.h:55
Tensor nll_loss(const Tensor &predictions, const Tensor &targets, const Tensor &weights, std::string reduction="mean", int ignore_index=-100, const std::string name="nll_loss", const std::string tag=kBroadcast)
Negative log likelihood loss.
Definition nn.h:674
tvm::te::Tensor depthwise_conv2d_nhwc(const tvm::te::Tensor &I, const tvm::te::Tensor &W, int pad_h=0, int pad_w=0, int stride_h=1, int stride_w=1, std::string name="T_depthwise_conv2d_nhwc", std::string tag=kDepthwiseConv2dNHWC)
Definition nn.h:390
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
PrimExpr div(PrimExpr a, PrimExpr b, Span span=Span())
compute division in C semantics.
PrimExpr logical_and(PrimExpr a, PrimExpr b, Span span=Span())
and
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 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.
Operation node can generate one or multiple Tensors.
Reduction op constructors.
Common operators defined for Expr.