24 #ifndef TVM_TE_OPERATION_H_
25 #define TVM_TE_OPERATION_H_
28 #include <tvm/ffi/reflection/registry.h>
36 #include <unordered_map>
52 std::vector<std::vector<IntSet>>
data;
65 ffi::Map<ffi::String, ffi::Any>
attrs;
89 namespace refl = tvm::ffi::reflection;
90 refl::ObjectDef<OperationNode>()
114 namespace refl = tvm::ffi::reflection;
115 refl::ObjectDef<PlaceholderOpNode>()
147 namespace refl = tvm::ffi::reflection;
148 refl::ObjectDef<BaseComputeOpNode>()
167 ffi::Array<
Tensor> InputTensors() const final;
169 static
void RegisterReflection() {
170 namespace refl = tvm::ffi::reflection;
182 TVM_DLL
ComputeOp(std::string name, std::string tag, ffi::Map<ffi::String, ffi::Any> attrs,
183 ffi::Array<IterVar> axis, ffi::Array<PrimExpr> body);
226 namespace refl = tvm::ffi::reflection;
227 refl::ObjectDef<ScanOpNode>()
244 TVM_DLL
ScanOp(std::string name, std::string tag,
245 ffi::Optional<ffi::Map<ffi::String, ffi::Any>> attrs,
IterVar axis,
246 ffi::Array<Tensor> init, ffi::Array<Tensor> update,
247 ffi::Array<Tensor> state_placeholder, ffi::Array<Tensor> input);
275 namespace refl = tvm::ffi::reflection;
276 refl::ObjectDef<ExternOpNode>()
291 TVM_DLL
ExternOp(std::string name, std::string tag, ffi::Map<ffi::String, ffi::Any> attrs,
292 ffi::Array<Tensor> inputs, ffi::Array<Buffer> input_placeholders,
293 ffi::Array<Buffer> output_placeholders,
Stmt body);
325 using FBatchCompute = std::function<ffi::Array<PrimExpr>(
const ffi::Array<PrimVar>& i)>;
334 std::string name =
"placeholder");
346 std::string tag =
"", ffi::Map<ffi::String, ffi::Any> attrs = {});
358 std::string name =
"tensor", std::string tag =
"",
359 ffi::Map<ffi::String, ffi::Any> attrs = {});
373 TVM_DLL ffi::Array<Tensor>
scan(ffi::Array<Tensor> init, ffi::Array<Tensor> update,
374 ffi::Array<Tensor> state_placeholder,
375 ffi::Array<Tensor> inputs = ffi::Array<Tensor>(),
376 std::string name =
"scan", std::string tag =
"",
377 ffi::Map<ffi::String, ffi::Any> attrs = {});
381 std::string name =
"tensor", std::string tag =
"",
382 ffi::Map<ffi::String, ffi::Any> attrs = {}) {
383 FCompute fc = [f](
const ffi::Array<PrimVar>& i) {
return f(i[0]); };
387 std::string name =
"tensor", std::string tag =
"",
388 ffi::Map<ffi::String, ffi::Any> attrs = {}) {
389 FCompute fc = [f](
const ffi::Array<PrimVar>& i) {
return f(i[0], i[1]); };
394 std::string name =
"tensor", std::string tag =
"",
395 ffi::Map<ffi::String, ffi::Any> attrs = {}) {
396 FCompute fc = [f](
const ffi::Array<PrimVar>& i) {
return f(i[0], i[1], i[2]); };
401 std::string name =
"tensor", std::string tag =
"",
402 ffi::Map<ffi::String, ffi::Any> attrs = {}) {
403 FCompute fc = [f](
const ffi::Array<PrimVar>& i) {
return f(i[0], i[1], i[2], i[3]); };
Algebra expression simplifications.
Symbolic n-dimensional array, to represent a memory buffer.
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition: base_expr.h:354
Definition: base_expr.h:113
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:484
A Compute op that compute a tensor on certain domain. This is the base class for ComputeOp (operating...
Definition: operation.h:137
ffi::Array< IterVar > reduce_axis
IterVar on each reduction axis, if the body is a Reduce.
Definition: operation.h:142
static void RegisterReflection()
Definition: operation.h:146
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:140
A Compute op that compute a tensor on certain domain.
Definition: operation.h:158
ComputeOpNode()
constructor
Definition: operation.h:163
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:161
Managed reference to ComputeOpNode.
Definition: operation.h:180
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:255
int num_outputs() const final
ffi::Array< Tensor > inputs
The input tensors.
Definition: operation.h:258
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:274
ffi::Array< PrimExpr > output_shape(size_t i) const final
Get shape of i-th output tensor.
ffi::Array< Buffer > input_placeholders
Symbolic placeholder representation of inputs.
Definition: operation.h:260
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.ExternOp", ExternOpNode, OperationNode)
ffi::Array< Tensor > InputTensors() const final
List all the input Tensors.
Stmt body
the statement that generates the computation.
Definition: operation.h:264
ExternOpNode()
constructor
Definition: operation.h:267
ffi::Array< Buffer > output_placeholders
Symbolic placeholder representation of outputs.
Definition: operation.h:262
Managed reference to ExternOpNode.
Definition: operation.h:289
ExternOp(std::string name, std::string tag, ffi::Map< ffi::String, ffi::Any > attrs, ffi::Array< Tensor > inputs, ffi::Array< Buffer > input_placeholders, ffi::Array< Buffer > output_placeholders, Stmt body)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(ExternOp, Operation, ExternOpNode)
Base class of all operation nodes.
Definition: operation.h:58
TVM_FFI_DECLARE_OBJECT_INFO("te.Operation", OperationNode, ffi::Object)
virtual ~OperationNode()
Definition: operation.h:67
virtual ffi::Array< PrimExpr > output_shape(size_t i) const =0
Get shape of i-th output tensor.
static void RegisterReflection()
Definition: operation.h:88
virtual ffi::Array< Tensor > InputTensors() const =0
List all the input Tensors.
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
ffi::Map< ffi::String, ffi::Any > attrs
additional attributes of the operation
Definition: operation.h:65
std::string name
optional name of the operation
Definition: operation.h:61
std::string tag
optional tag of the operation
Definition: operation.h:63
Operation that produces tensors.
Definition: tensor.h:48
const OperationNode * operator->() const
access the internal node container
Definition: operation.h:408
A placeholder op represents an input placeholder.
Definition: operation.h:101
TVM_FFI_DECLARE_OBJECT_INFO("te.PlaceholderOp", PlaceholderOpNode, OperationNode)
static void RegisterReflection()
Definition: operation.h:113
ffi::Array< PrimExpr > shape
The shape of the input.
Definition: operation.h:104
int num_outputs() const final
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.
PrimType dtype
The dtype of the input.
Definition: operation.h:106
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:126
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(PlaceholderOp, Operation, PlaceholderOpNode)
PlaceholderOp(std::string name, ffi::Array< PrimExpr > shape, PrimType dtype)
Symbolic scan.
Definition: operation.h:192
ffi::Array< Tensor > state_placeholder
The placeholder to refer as states in update.
Definition: operation.h:201
ScanOpNode()
constructor
Definition: operation.h:218
int num_outputs() const final
ffi::Array< Tensor > init
the initialization tensors
Definition: operation.h:197
ffi::Array< Tensor > update
the update function represented by tensor
Definition: operation.h:199
ffi::Array< PrimExpr > output_shape(size_t i) const final
Get shape of i-th output tensor.
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:206
ffi::Array< Tensor > InputTensors() const final
List all the input Tensors.
static void RegisterReflection()
Definition: operation.h:225
IterVar scan_axis
IterVar to scan over.
Definition: operation.h:195
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:216
Managed reference to ScanOpNode.
Definition: operation.h:242
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:100
Iteration Variable, represents an iteration over an integer interval.
Definition: var.h:274
Checked scalar view over a VarNode.
Definition: var.h:127
Container of all statements.
Definition: stmt.h:64
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.
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:325
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.
std::function< PrimExpr(const ffi::Array< PrimVar > &i)> FCompute
The compute function to specify the input source of a Tensor.
Definition: operation.h:322
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...
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:2010
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:48
TensorDom(int ndim)
Definition: operation.h:50
std::vector< std::vector< IntSet > > data
The domain data.
Definition: operation.h:52
Common operators defined for Expr.