24#ifndef TVM_TE_OPERATION_H_
25#define TVM_TE_OPERATION_H_
27#include <tvm/ffi/reflection/registry.h>
38#include <unordered_map>
54 ffi::Array<PrimVar>
lhs;
56 ffi::Array<PrimVar>
rhs;
66 ffi::Array<PrimExpr>
operator()(ffi::Array<PrimExpr> a, ffi::Array<PrimExpr> b)
const;
74 namespace refl = tvm::ffi::reflection;
75 refl::ObjectDef<CommReducerNode>()
93 TVM_DLL
CommReducer(ffi::Array<PrimVar> lhs, ffi::Array<PrimVar> rhs, ffi::Array<PrimExpr> result,
113 ffi::Array<s_tir::IterVar>
axis;
123 namespace refl = tvm::ffi::reflection;
124 refl::ObjectDef<ReduceNode>()
142 ffi::Optional<PrimExpr> condition,
int value_index, ffi::Array<PrimExpr> init,
159 std::vector<std::vector<IntSet>>
data;
172 ffi::Map<ffi::String, ffi::Any>
attrs;
196 namespace refl = tvm::ffi::reflection;
197 refl::ObjectDef<OperationNode>()
198 .def_ro(
"name", &OperationNode::name)
199 .def_ro(
"tag", &OperationNode::tag)
200 .def_ro(
"attrs", &OperationNode::attrs);
221 namespace refl = tvm::ffi::reflection;
222 refl::ObjectDef<PlaceholderOpNode>()
237 explicit PlaceholderOp(ffi::UnsafeInit tag, ffi::ObjectPtr<PlaceholderOpNode> node)
239 data_ = std::move(node);
259 namespace refl = tvm::ffi::reflection;
260 refl::ObjectDef<BaseComputeOpNode>()
261 .def_ro(
"axis", &BaseComputeOpNode::axis)
262 .def_ro(
"reduce_axis", &BaseComputeOpNode::reduce_axis);
279 ffi::Array<
Tensor> InputTensors() const final;
281 static
void RegisterReflection() {
282 namespace refl = tvm::ffi::reflection;
283 refl::ObjectDef<ComputeOpNode>().def_ro(
"body", &ComputeOpNode::body);
294 TVM_DLL
ComputeOp(std::string name, std::string tag, ffi::Map<ffi::String, ffi::Any> attrs,
295 ffi::Array<IterVar> axis, ffi::Array<PrimExpr> body);
338 namespace refl = tvm::ffi::reflection;
339 refl::ObjectDef<ScanOpNode>()
356 TVM_DLL
ScanOp(std::string name, std::string tag,
357 ffi::Optional<ffi::Map<ffi::String, ffi::Any>> attrs,
IterVar axis,
358 ffi::Array<Tensor> init, ffi::Array<Tensor> update,
359 ffi::Array<Tensor> state_placeholder, ffi::Array<Tensor> input);
388 namespace refl = tvm::ffi::reflection;
389 refl::ObjectDef<ExternOpNode>()
404 TVM_DLL
ExternOp(std::string name, std::string tag, ffi::Map<ffi::String, ffi::Any> attrs,
405 ffi::Array<Tensor> inputs, ffi::Array<TensorVar> input_placeholders,
406 ffi::Array<TensorVar> output_placeholders,
SeqStmt body);
438using FBatchCompute = std::function<ffi::Array<PrimExpr>(
const ffi::Array<PrimVar>& i)>;
447 std::string name =
"placeholder");
459 std::string tag =
"", ffi::Map<ffi::String, ffi::Any> attrs = {});
471 std::string name =
"tensor", std::string tag =
"",
472 ffi::Map<ffi::String, ffi::Any> attrs = {});
486TVM_DLL ffi::Array<Tensor>
scan(ffi::Array<Tensor> init, ffi::Array<Tensor> update,
487 ffi::Array<Tensor> state_placeholder,
488 ffi::Array<Tensor> inputs = ffi::Array<Tensor>(),
489 std::string name =
"scan", std::string tag =
"",
490 ffi::Map<ffi::String, ffi::Any> attrs = {});
494 std::string name =
"tensor", std::string tag =
"",
495 ffi::Map<ffi::String, ffi::Any> attrs = {}) {
496 FCompute fc = [f](
const ffi::Array<PrimVar>& i) {
return f(i[0]); };
497 return compute(shape, fc, name, tag, attrs);
500 std::string name =
"tensor", std::string tag =
"",
501 ffi::Map<ffi::String, ffi::Any> attrs = {}) {
502 FCompute fc = [f](
const ffi::Array<PrimVar>& i) {
return f(i[0], i[1]); };
503 return compute(shape, fc, name, tag, attrs);
507 std::string name =
"tensor", std::string tag =
"",
508 ffi::Map<ffi::String, ffi::Any> attrs = {}) {
509 FCompute fc = [f](
const ffi::Array<PrimVar>& i) {
return f(i[0], i[1], i[2]); };
510 return compute(shape, fc, name, tag, attrs);
514 std::string name =
"tensor", std::string tag =
"",
515 ffi::Map<ffi::String, ffi::Any> attrs = {}) {
516 FCompute fc = [f](
const ffi::Array<PrimVar>& i) {
return f(i[0], i[1], i[2], i[3]); };
517 return compute(shape, fc, name, tag, attrs);
529inline constexpr bool object_ref_contains_v<PrimExpr, te::ReduceNode> =
true;
Algebra expression simplifications.
Non-nullable source-location metadata.
Definition location.h:91
Base node for opaque construction-time expressions.
Definition base_expr.h:394
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
Definition base_expr.h:161
static TVM_TIRX_DLL PrimType Void()
Construct the void sentinel type, encoded as handle(0, 0).
static TVM_TIRX_DLL PrimType Int(int bits, int lanes=1)
Construct a signed integer type with fixed lanes.
static TVM_TIRX_DLL PrimType Float(int bits, int lanes=1)
Construct a floating-point type with fixed lanes.
Checked scalar view over a VarNode.
Definition expr.h:742
Range container
Definition expr.h:1025
Sequence statement.
Definition stmt.h:92
Reference to the shared immutable unknown location.
Definition location.h:105
Iteration Variable, represents an iteration over an integer interval.
Definition iter_var.h:147
A Compute op that compute a tensor on certain domain. This is the base class for ComputeOp (operating...
Definition operation.h:249
ffi::Array< IterVar > reduce_axis
IterVar on each reduction axis, if the body is a Reduce.
Definition operation.h:254
static void RegisterReflection()
Definition operation.h:258
ffi::Array< PrimExpr > output_shape(size_t idx) const final
Get shape of i-th output tensor.
TVM_FFI_DECLARE_OBJECT_INFO("te.BaseComputeOp", BaseComputeOpNode, OperationNode)
ffi::Array< IterVar > axis
IterVar on each axis.
Definition operation.h:252
A commutative reducer node to represent a commutative binary operator with identity element.
Definition operation.h:51
ffi::Array< PrimVar > rhs
The right argument of reducer.
Definition operation.h:56
Location loc
Location that points to the original source code. Reserved debug information.
Definition operation.h:71
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.CommReducer", CommReducerNode, ffi::Object)
ffi::Array< PrimExpr > operator()(ffi::Array< PrimExpr > a, ffi::Array< PrimExpr > b) const
Function call operator to combine a and b.
ffi::Array< PrimExpr > identity_element
The identity element of reducer, which leaves other elements unchanged when combined with it,...
Definition operation.h:64
ffi::Array< PrimExpr > result
The result of reducer.
Definition operation.h:58
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition operation.h:83
ffi::Array< PrimVar > lhs
The left argument of reducer.
Definition operation.h:54
static void RegisterReflection()
Definition operation.h:73
Managed reference to CommReducerNode.
Definition operation.h:91
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(CommReducer, ffi::ObjectRef, CommReducerNode)
CommReducer(ffi::Array< PrimVar > lhs, ffi::Array< PrimVar > rhs, ffi::Array< PrimExpr > result, ffi::Array< PrimExpr > identity_element, Location loc=UnknownLoc())
A Compute op that compute a tensor on certain domain.
Definition operation.h:270
ComputeOpNode()
constructor
Definition operation.h:275
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.ComputeOp", ComputeOpNode, BaseComputeOpNode)
int num_outputs() const final
ffi::Array< PrimExpr > body
the compute expression
Definition operation.h:273
Managed reference to ComputeOpNode.
Definition operation.h:292
ComputeOp(std::string name, std::string tag, ffi::Map< ffi::String, ffi::Any > attrs, ffi::Array< IterVar > axis, ffi::Array< PrimExpr > body)
TVM_DEFINE_OBJECT_REF_COW_METHOD(ComputeOpNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ComputeOp, Operation, ComputeOpNode)
External computation that cannot be splitted.
Definition operation.h:367
int num_outputs() const final
ExternOpNode(SeqStmt body)
Definition operation.h:369
ffi::Array< Tensor > inputs
The input tensors.
Definition operation.h:373
PrimType output_dtype(size_t i) const final
Get the primitive element type of the i-th output tensor.
static void RegisterReflection()
Definition operation.h:387
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.ExternOp", ExternOpNode, OperationNode)
SeqStmt body
the statement that generates the computation.
Definition operation.h:379
ffi::Array< TensorVar > input_placeholders
Symbolic placeholder representation of inputs.
Definition operation.h:375
ffi::Array< TensorVar > output_placeholders
Symbolic placeholder representation of outputs.
Definition operation.h:377
ExternOpNode(ffi::UnsafeInit)
Definition operation.h:370
ffi::Array< Tensor > InputTensors() const final
List all the input Tensors.
ffi::Array< PrimExpr > output_shape(size_t i) const final
Get shape of i-th output tensor.
Managed reference to ExternOpNode.
Definition operation.h:402
ExternOp(std::string name, std::string tag, ffi::Map< ffi::String, ffi::Any > attrs, ffi::Array< Tensor > inputs, ffi::Array< TensorVar > input_placeholders, ffi::Array< TensorVar > output_placeholders, SeqStmt body)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ExternOp, Operation, ExternOpNode)
Base class of all operation nodes.
Definition operation.h:165
TVM_FFI_DECLARE_OBJECT_INFO("te.Operation", OperationNode, ffi::Object)
virtual ~OperationNode()
Definition operation.h:174
static void RegisterReflection()
Definition operation.h:195
virtual PrimType output_dtype(size_t i) const =0
Get the primitive element type of the i-th output tensor.
virtual int num_outputs() const =0
virtual ffi::Array< Tensor > InputTensors() const =0
List all the input Tensors.
virtual ffi::Array< PrimExpr > output_shape(size_t i) const =0
Get shape of i-th output tensor.
ffi::Map< ffi::String, ffi::Any > attrs
additional attributes of the operation
Definition operation.h:172
std::string name
optional name of the operation
Definition operation.h:168
std::string tag
optional tag of the operation
Definition operation.h:170
Operation that produces tensors.
Definition tensor.h:63
const OperationNode * operator->() const
access the internal node container
Definition operation.h:521
A placeholder op represents an input placeholder.
Definition operation.h:208
ffi::Array< Tensor > InputTensors() const final
List all the input Tensors.
TVM_FFI_DECLARE_OBJECT_INFO("te.PlaceholderOp", PlaceholderOpNode, OperationNode)
static void RegisterReflection()
Definition operation.h:220
ffi::Array< PrimExpr > shape
The shape of the input.
Definition operation.h:211
int num_outputs() const final
ffi::Array< PrimExpr > output_shape(size_t i) const final
Get shape of i-th output tensor.
PrimType dtype
The dtype of the input.
Definition operation.h:213
PrimType output_dtype(size_t i) const final
Get the primitive element type of the i-th output tensor.
Managed reference to PlaceholderOpNode.
Definition operation.h:233
PlaceholderOp(ffi::UnsafeInit tag, ffi::ObjectPtr< PlaceholderOpNode > node)
Definition operation.h:237
PlaceholderOp(std::string name, ffi::Array< PrimExpr > shape, PrimType dtype)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(PlaceholderOp, Operation, PlaceholderOpNode)
Reduction operator.
Definition operation.h:99
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.Reduce", ReduceNode, OpaqueExprNode)
ffi::Array< PrimExpr > init
The init operand.
Definition operation.h:111
int value_index
the index of this reduce node
Definition operation.h:120
ffi::Array< PrimExpr > source
The source operand.
Definition operation.h:109
ReduceNode(ffi::UnsafeInit)
Definition operation.h:103
CommReducer combiner
The commutative combiner.
Definition operation.h:107
ffi::Array< s_tir::IterVar > axis
The reduction axis.
Definition operation.h:113
ReduceNode(CommReducer combiner, PrimExpr condition)
Definition operation.h:101
PrimExpr condition
Predicate on the reduction Only add the body to reduction if condition is true.
Definition operation.h:118
static void RegisterReflection()
Definition operation.h:122
Managed reference to ReduceNode.
Definition operation.h:139
Reduce(ffi::ObjectPtr< ReduceNode > node)
Definition operation.h:144
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Reduce, PrimExpr, ReduceNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(ReduceNode)
static constexpr bool _type_container_is_exact
Definition operation.h:147
Reduce(CommReducer combiner, ffi::Array< PrimExpr > src, ffi::Array< s_tir::IterVar > rdom, ffi::Optional< PrimExpr > condition, int value_index, ffi::Array< PrimExpr > init, Location loc=UnknownLoc())
Symbolic scan.
Definition operation.h:304
ffi::Array< Tensor > state_placeholder
The placeholder to refer as states in update.
Definition operation.h:313
ScanOpNode()
constructor
Definition operation.h:330
int num_outputs() const final
ffi::Array< Tensor > init
the initialization tensors
Definition operation.h:309
ffi::Array< Tensor > update
the update function represented by tensor
Definition operation.h:311
ffi::Array< Tensor > inputs
the inputs to the scan, these are optionally provided But they can be helpful to provide hints to spe...
Definition operation.h:318
ffi::Array< Tensor > InputTensors() const final
List all the input Tensors.
static void RegisterReflection()
Definition operation.h:337
IterVar scan_axis
IterVar to scan over.
Definition operation.h:307
ffi::Array< PrimExpr > output_shape(size_t i) const final
Get shape of i-th output tensor.
PrimType output_dtype(size_t i) const final
Get the primitive element type of the i-th output tensor.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.ScanOp", ScanOpNode, OperationNode)
ffi::Array< IterVar > spatial_axis_
Spatial axis to indicate spatial dimension of each output. They corresponds to flattened spatial axis...
Definition operation.h:328
Managed reference to ScanOpNode.
Definition operation.h:354
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ScanOp, Operation, ScanOpNode)
ScanOp(std::string name, std::string tag, ffi::Optional< ffi::Map< ffi::String, ffi::Any > > attrs, IterVar axis, ffi::Array< Tensor > init, ffi::Array< Tensor > update, ffi::Array< Tensor > state_placeholder, ffi::Array< Tensor > input)
Tensor structure representing a possible input, or intermediate computation result.
Definition tensor.h:111
Copy-on-write helper macro for IR ffi::ObjectRef types.
Shared primitive construction and constant helpers.
PrimVar var(std::string name_hint, PrimType t=PrimType::Int(32))
Construct a new Var expression.
ffi::Array< Tensor > scan(ffi::Array< Tensor > init, ffi::Array< Tensor > update, ffi::Array< Tensor > state_placeholder, ffi::Array< Tensor > inputs=ffi::Array< Tensor >(), std::string name="scan", std::string tag="", ffi::Map< ffi::String, ffi::Any > attrs={})
Construct new tensors by scan.
Tensor placeholder(ffi::Array< PrimExpr > shape, PrimType dtype=PrimType::Float(32), std::string name="placeholder")
create a place holder tensor.
std::function< ffi::Array< PrimExpr >(const ffi::Array< PrimVar > &i)> FBatchCompute
The compute function to specify the inputs source of Tensors.
Definition operation.h:438
std::function< PrimExpr(const ffi::Array< PrimVar > &i)> FCompute
The compute function to specify the input source of a Tensor.
Definition operation.h:435
IterVar thread_axis(Range dom, std::string tag)
Create a new IterVar that represents an axis in thread.
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...
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
Temporary data structure to store union of bounds of each axis of Tensor.
Definition operation.h:155
TensorDom(int ndim)
Definition operation.h:157
std::vector< std::vector< IntSet > > data
The domain data.
Definition operation.h:159
Tensor-expression reduction constructors.
TIRx tensor expressions and construction helpers.
TIRx statements and shared statement entry header.