24#ifndef TVM_TOPI_DETAIL_EXTERN_H_
25#define TVM_TOPI_DETAIL_EXTERN_H_
46using FExtern = std::function<
PrimExpr(ffi::Array<TensorVar>, ffi::Array<TensorVar>)>;
65inline ffi::Array<Tensor> make_extern(
const ffi::Array<ffi::Array<PrimExpr>>& out_shapes,
66 const std::vector<PrimType>& out_types,
67 const ffi::Array<Tensor>& inputs, FExtern fextern,
68 std::string name, std::string tag,
69 ::tvm::ffi::Map<ffi::String, ffi::Any> attrs) {
70 TVM_FFI_ICHECK_EQ(out_shapes.size(), out_types.size())
71 <<
"make_extern: out_shapes and out_types must have equal size";
73 ffi::Array<TensorVar> input_placeholders;
74 for (
auto t : inputs) {
77 ffi::Array<TensorVar> output_placeholders;
78 for (
size_t i = 0; i < out_shapes.size(); ++i) {
82 auto body = fextern(input_placeholders, output_placeholders);
85 auto op =
ExternOp(name, tag, attrs, inputs, input_placeholders, output_placeholders, body_stmt);
87 ffi::Array<Tensor> outputs;
88 for (
size_t i = 0; i < output_placeholders.size(); ++i) {
89 outputs.push_back(op.output(i));
104 TVM_FFI_ICHECK_GT(buf->
shape.size(), 0) <<
"buf shape must have at least one element";
112 ffi::Array<Expr> pack_args{buf->data,
130inline PrimExpr call_packed(ffi::Array<Expr> args) {
Managed reference to CallNode.
Definition expr.h:972
Managed reference to EvaluateNode.
Definition stmt.h:372
Managed reference to ExprNode.
Definition base_expr.h:359
static IntImm Int32(ffi::BigInt value, Location loc=UnknownLoc())
Construct a scalar int32 constant.
Definition expr.h:181
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 Int(int bits, int lanes=1)
Construct a signed integer type with fixed lanes.
static TVM_TIRX_DLL PtrType VoidPtrType(ffi::String storage_scope="")
Construct an opaque pointer with void element type.
Managed reference to ExternOpNode.
Definition operation.h:402
PrimExpr elem_offset
The offset in terms of number of dtype elements (including lanes)
Definition type.h:87
ffi::Array< PrimExpr > shape
The type of the tensor prior to flattening.
Definition type.h:80
PrimType dtype
dtype in the content of the tensor
Definition type.h:71
ffi::Array< PrimExpr > strides
The strides of each dimension This can be an empty array, indicating array is contiguous.
Definition type.h:85
Checked zero-state view over an ordinary VarNode with TensorType.
Definition expr.h:50
Shared primitive construction and constant helpers.
PrimExpr MakeConst(PrimType dtype, ValueType value, Location loc=UnknownLoc())
Make a const value with certain data type.
Definition op.h:553
Tensor expression language DSL.
Definition extracted_task.h:33
TVM_TIRX_DLL TensorVar decl_tensor(ffi::Array< PrimExpr > shape, PrimType dtype=PrimType::Float(32), ffi::String name="tensor", ffi::String storage_scope="", Location loc=UnknownLoc())
Construct a new tensor given shape, and dtype.
TVM_TIRX_DLL const Op & stack_make_dltensor_op()
Construct a stack-allocated DLTensor.
TVM_TIRX_DLL const Op & stack_make_shape_op()
Construct a stack-allocated shape tuple.
TVM_TIRX_DLL const Op & call_packed_op()
Invoke a runtime packed function.
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:2016
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
Operation node can generate one or multiple Tensors.