24#ifndef TVM_TE_OPERATION_H_
25#define TVM_TE_OPERATION_H_
28#include <tvm/ffi/reflection/registry.h>
36#include <unordered_map>
52 ffi::Array<tirx::PrimVar>
lhs;
54 ffi::Array<tirx::PrimVar>
rhs;
64 ffi::Array<PrimExpr>
operator()(ffi::Array<PrimExpr> a, ffi::Array<PrimExpr> b)
const;
72 namespace refl = tvm::ffi::reflection;
73 refl::ObjectDef<CommReducerNode>()
92 ffi::Array<PrimExpr> result, ffi::Array<PrimExpr> identity_element,
107 ffi::Array<tirx::IterVar>
axis;
117 namespace refl = tvm::ffi::reflection;
118 refl::ObjectDef<ReduceNode>()
136 PrimExpr condition,
int value_index, ffi::Array<PrimExpr> init,
151 std::vector<std::vector<IntSet>>
data;
164 ffi::Map<ffi::String, ffi::Any>
attrs;
188 namespace refl = tvm::ffi::reflection;
189 refl::ObjectDef<OperationNode>()
190 .def_ro(
"name", &OperationNode::name)
191 .def_ro(
"tag", &OperationNode::tag)
192 .def_ro(
"attrs", &OperationNode::attrs);
213 namespace refl = tvm::ffi::reflection;
214 refl::ObjectDef<PlaceholderOpNode>()
246 namespace refl = tvm::ffi::reflection;
247 refl::ObjectDef<BaseComputeOpNode>()
248 .def_ro(
"axis", &BaseComputeOpNode::axis)
249 .def_ro(
"reduce_axis", &BaseComputeOpNode::reduce_axis);
269 namespace refl = tvm::ffi::reflection;
270 refl::ObjectDef<ComputeOpNode>().def_ro(
"body", &ComputeOpNode::body);
281 TVM_DLL ComputeOp(std::string name, std::string tag, ffi::Map<ffi::String, ffi::Any> attrs,
282 ffi::Array<IterVar> axis, ffi::Array<PrimExpr> body);
325 namespace refl = tvm::ffi::reflection;
326 refl::ObjectDef<ScanOpNode>()
344 ffi::Optional<ffi::Map<ffi::String, ffi::Any>> attrs,
IterVar axis,
345 ffi::Array<Tensor> init, ffi::Array<Tensor> update,
346 ffi::Array<Tensor> state_placeholder, ffi::Array<Tensor>
input);
374 namespace refl = tvm::ffi::reflection;
375 refl::ObjectDef<ExternOpNode>()
390 TVM_DLL ExternOp(std::string name, std::string tag, ffi::Map<ffi::String, ffi::Any> attrs,
391 ffi::Array<Tensor> inputs, ffi::Array<BufferVar> input_placeholders,
392 ffi::Array<BufferVar> output_placeholders,
Stmt body);
424using FBatchCompute = std::function<ffi::Array<PrimExpr>(
const ffi::Array<PrimVar>&
i)>;
433 std::string name =
"placeholder");
445 std::string tag =
"", ffi::Map<ffi::String, ffi::Any> attrs = {});
457 std::string name =
"tensor", std::string tag =
"",
458 ffi::Map<ffi::String, ffi::Any> attrs = {});
472TVM_DLL ffi::Array<Tensor>
scan(ffi::Array<Tensor> init, ffi::Array<Tensor> update,
473 ffi::Array<Tensor> state_placeholder,
474 ffi::Array<Tensor> inputs = ffi::Array<Tensor>(),
475 std::string name =
"scan", std::string tag =
"",
476 ffi::Map<ffi::String, ffi::Any> attrs = {});
480 std::string name =
"tensor", std::string tag =
"",
481 ffi::Map<ffi::String, ffi::Any> attrs = {}) {
482 FCompute fc = [
f](
const ffi::Array<PrimVar>&
i) {
return f(
i[0]); };
483 return compute(shape, fc, name, tag, attrs);
486 std::string name =
"tensor", std::string tag =
"",
487 ffi::Map<ffi::String, ffi::Any> attrs = {}) {
488 FCompute fc = [
f](
const ffi::Array<PrimVar>&
i) {
return f(
i[0],
i[1]); };
489 return compute(shape, fc, name, tag, attrs);
493 std::string name =
"tensor", std::string tag =
"",
494 ffi::Map<ffi::String, ffi::Any> attrs = {}) {
495 FCompute fc = [
f](
const ffi::Array<PrimVar>&
i) {
return f(
i[0],
i[1],
i[2]); };
496 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],
i[2],
i[3]); };
503 return compute(shape, fc, name, tag, attrs);
Algebra expression simplifications.
Symbolic n-dimensional array, to represent a memory buffer.
Base node for opaque construction-time expressions.
Definition base_expr.h:352
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:401
Definition base_expr.h:137
static PrimType Float(int bits, int lanes=1)
Construct a floating-point type with fixed lanes.
static PrimType Void()
Construct the void sentinel type, encoded as handle(0, 0).
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
A Compute op that compute a tensor on certain domain. This is the base class for ComputeOp (operating...
Definition operation.h:236
ffi::Array< IterVar > reduce_axis
IterVar on each reduction axis, if the body is a Reduce.
Definition operation.h:241
static void RegisterReflection()
Definition operation.h:245
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:239
A commutative reducer node to represent a commutative binary operator with identity element.
Definition operation.h:49
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.CommReducer", CommReducerNode, ffi::Object)
ffi::Array< tirx::PrimVar > lhs
The left argument of reducer.
Definition operation.h:52
Span span
Span that points to the original source code. Reserved debug information.
Definition operation.h:69
ffi::Array< tirx::PrimVar > rhs
The right argument of reducer.
Definition operation.h:54
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:62
ffi::Array< PrimExpr > result
The result of reducer.
Definition operation.h:56
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition operation.h:81
static void RegisterReflection()
Definition operation.h:71
Managed reference to CommReducerNode.
Definition operation.h:89
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(CommReducer, ffi::ObjectRef, CommReducerNode)
CommReducer(ffi::Array< tirx::PrimVar > lhs, ffi::Array< tirx::PrimVar > rhs, ffi::Array< PrimExpr > result, ffi::Array< PrimExpr > identity_element, Span span=Span())
A Compute op that compute a tensor on certain domain.
Definition operation.h:257
ComputeOpNode()
constructor
Definition operation.h:262
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:260
Managed reference to ComputeOpNode.
Definition operation.h:279
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(ComputeOp, Operation, ComputeOpNode)
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)
External computation that cannot be splitted.
Definition operation.h:354
int num_outputs() const final
ffi::Array< BufferVar > input_placeholders
Symbolic placeholder representation of inputs.
Definition operation.h:359
ffi::Array< BufferVar > output_placeholders
Symbolic placeholder representation of outputs.
Definition operation.h:361
ffi::Array< Tensor > inputs
The input tensors.
Definition operation.h:357
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:373
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.ExternOp", ExternOpNode, OperationNode)
Stmt body
the statement that generates the computation.
Definition operation.h:363
ExternOpNode()
constructor
Definition operation.h:366
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:388
ExternOp(std::string name, std::string tag, ffi::Map< ffi::String, ffi::Any > attrs, ffi::Array< Tensor > inputs, ffi::Array< BufferVar > input_placeholders, ffi::Array< BufferVar > output_placeholders, Stmt body)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(ExternOp, Operation, ExternOpNode)
Base class of all operation nodes.
Definition operation.h:157
TVM_FFI_DECLARE_OBJECT_INFO("te.Operation", OperationNode, ffi::Object)
virtual ~OperationNode()
Definition operation.h:166
static void RegisterReflection()
Definition operation.h:187
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:164
std::string name
optional name of the operation
Definition operation.h:160
std::string tag
optional tag of the operation
Definition operation.h:162
Operation that produces tensors.
Definition tensor.h:48
const OperationNode * operator->() const
access the internal node container
Definition operation.h:507
A placeholder op represents an input placeholder.
Definition operation.h:200
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:212
ffi::Array< PrimExpr > shape
The shape of the input.
Definition operation.h:203
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:205
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:225
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(PlaceholderOp, Operation, PlaceholderOpNode)
PlaceholderOp(std::string name, ffi::Array< PrimExpr > shape, PrimType dtype)
Reduction operator.
Definition operation.h:98
ffi::Array< tirx::IterVar > axis
The reduction axis.
Definition operation.h:107
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.Reduce", ReduceNode, OpaqueExprNode)
ffi::Array< PrimExpr > init
The init operand.
Definition operation.h:105
int value_index
the index of this reduce node
Definition operation.h:114
ffi::Array< PrimExpr > source
The source operand.
Definition operation.h:103
CommReducer combiner
The commutative combiner.
Definition operation.h:101
PrimExpr condition
Predicate on the reduction Only add the body to reduction if condition is true.
Definition operation.h:112
static void RegisterReflection()
Definition operation.h:116
Managed reference to ReduceNode.
Definition operation.h:133
Reduce(CommReducer combiner, ffi::Array< PrimExpr > src, ffi::Array< tirx::IterVar > rdom, PrimExpr condition, int value_index, ffi::Array< PrimExpr > init, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(ReduceNode)
static constexpr bool _type_container_is_exact
Definition operation.h:139
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Reduce, PrimExpr, ReduceNode)
Symbolic scan.
Definition operation.h:291
ffi::Array< Tensor > state_placeholder
The placeholder to refer as states in update.
Definition operation.h:300
ScanOpNode()
constructor
Definition operation.h:317
int num_outputs() const final
ffi::Array< Tensor > init
the initialization tensors
Definition operation.h:296
ffi::Array< Tensor > update
the update function represented by tensor
Definition operation.h:298
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:305
ffi::Array< Tensor > InputTensors() const final
List all the input Tensors.
static void RegisterReflection()
Definition operation.h:324
IterVar scan_axis
IterVar to scan over.
Definition operation.h:294
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:315
Managed reference to ScanOpNode.
Definition operation.h:341
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(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:98
Iteration Variable, represents an iteration over an integer interval.
Definition var.h:194
Checked scalar view over a VarNode.
Definition var.h:46
Container of all statements.
Definition stmt.h:67
Copy-on-write helper macro for IR ffi::ObjectRef types.
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:424
std::function< PrimExpr(const ffi::Array< PrimVar > &i)> FCompute
The compute function to specify the input source of a Tensor.
Definition operation.h:421
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 analyzer.h:40
Temporary data structure to store union of bounds of each axis of Tensor.
Definition operation.h:147
TensorDom(int ndim)
Definition operation.h:149
std::vector< std::vector< IntSet > > data
The domain data.
Definition operation.h:151
Common operators defined for Expr.