24#ifndef TVM_TOPI_DETAIL_EXTERN_H_
25#define TVM_TOPI_DETAIL_EXTERN_H_
47using FExtern = std::function<
PrimExpr(ffi::Array<TensorVar>, ffi::Array<TensorVar>)>;
66inline ffi::Array<Tensor> make_extern(
const ffi::Array<ffi::Array<PrimExpr>>& out_shapes,
67 const std::vector<PrimType>& out_types,
68 const ffi::Array<Tensor>& inputs, FExtern fextern,
69 std::string name, std::string tag,
70 ::tvm::ffi::Map<ffi::String, ffi::Any> attrs) {
71 TVM_FFI_ICHECK_EQ(out_shapes.size(), out_types.size())
72 <<
"make_extern: out_shapes and out_types must have equal size";
74 ffi::Array<TensorVar> input_placeholders;
75 for (
auto t : inputs) {
76 input_placeholders.push_back(
79 ffi::Array<TensorVar> output_placeholders;
80 for (
size_t i = 0; i < out_shapes.size(); ++i) {
81 output_placeholders.push_back(
85 auto body = fextern(input_placeholders, output_placeholders);
88 auto op =
ExternOp(name, tag, attrs, inputs, input_placeholders, output_placeholders, body_stmt);
90 ffi::Array<Tensor> outputs;
91 for (
size_t i = 0; i < output_placeholders.size(); ++i) {
92 outputs.push_back(op.output(i));
107 TVM_FFI_ICHECK_GT(buf->
shape.size(), 0) <<
"buf shape must have at least one element";
116 ffi::Array<Expr> pack_args{buf->
data,
134inline PrimExpr call_packed(ffi::Array<Expr> args) {
Shared primitive construction and constant helpers.
Managed reference to CallObj.
Definition expr.h:825
Managed reference to EvaluateObj.
Definition stmt.h:386
Managed reference to ExprObj.
Definition expr.h:101
static IntImm Int32(ffi::BigInt value, Location loc=UnknownLoc())
Construct a scalar int32 constant.
Definition expr.h:360
Typed reference/view over any Expr whose ExprObj::ty is PrimType.
Definition expr.h:187
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(runtime::MemoryScope scope={})
Construct an opaque pointer with void element type.
Managed reference to ExternOpObj.
Definition operation.h:402
Managed reference to TensorTypeObj.
Definition type.h:129
Checked zero-state view over an ordinary VarObj with TensorType.
Definition expr.h:48
Expr data() const
Project the physical pointer established by the definition site.
Definition expr.h:69
const ffi::Array< PrimExpr > & shape() const
Return the shape of the tensor.
Definition expr.h:63
TensorType ty() const
Return the tensor type carried by the ordinary variable.
Definition expr.h:60
PrimType dtype() const
Return the primitive element type.
Definition expr.h:66
Definition reduction.h:29
PrimExpr MakeConst(PrimType dtype, ValueType value, Location loc=UnknownLoc())
Make a const value with certain data type.
Definition op.h:814
Tensor expression language DSL.
Definition extracted_task.h:33
ffi::Optional< ffi::Tuple< ffi::Array< PrimExpr >, ffi::Array< PrimExpr >, PrimExpr > > MatchShapeStridePattern(const TensorType &tensor)
Match a tensor's shape-aligned strided memory representation.
Definition type.h:156
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 analysis.h:41
Operation node can generate one or multiple Tensors.