1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20/*!
21 * \brief Placeholder op.
22 * \file placeholder_op.cc
23 */
24#include <tvm/runtime/registry.h>
25#include <tvm/te/operation.h>
26
27namespace tvm {
28namespace te {
29
30// PlaceholderOpNode
31TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable)
32 .set_dispatch<PlaceholderOpNode>([](const ObjectRef& node, ReprPrinter* p) {
33 auto* op = static_cast<const PlaceholderOpNode*>(node.get());
34 p->stream << "placeholder(" << op->name << ", " << op << ")";
35 });
36
37TVM_REGISTER_NODE_TYPE(PlaceholderOpNode);
38
39int PlaceholderOpNode::num_outputs() const { return 1; }
40
41Array<IterVar> PlaceholderOpNode::root_iter_vars() const { return {}; }
42
43DataType PlaceholderOpNode::output_dtype(size_t i) const {
44 ICHECK_EQ(i, 0U);
45 return dtype;
46}
47
48Array<PrimExpr> PlaceholderOpNode::output_shape(size_t i) const {
49 ICHECK_EQ(i, 0U);
50 return shape;
51}
52
53PlaceholderOp::PlaceholderOp(std::string name, Array<PrimExpr> shape, DataType dtype) {
54 auto n = make_object<PlaceholderOpNode>();
55 n->name = name;
56 n->shape = shape;
57 n->dtype = dtype;
58 data_ = std::move(n);
59}
60
61Tensor placeholder(Array<PrimExpr> shape, DataType dtype, std::string name) {
62 return PlaceholderOp(name, shape, dtype).output(0);
63}
64
65TVM_REGISTER_GLOBAL("te.Placeholder")
66 .set_body_typed([](Array<PrimExpr> shape, DataType dtype, std::string name) {
67 return placeholder(shape, dtype, name);
68 });
69
70Array<Tensor> PlaceholderOpNode::InputTensors() const { return {}; }
71
72Operation PlaceholderOpNode::ReplaceInputs(const Operation& self,
73 const std::unordered_map<Tensor, Tensor>& rmap) const {
74 return self;
75}
76
77void PlaceholderOpNode::PropBoundToInputs(
78 const Operation& self, arith::Analyzer* analyzer,
79 const std::unordered_map<const VarNode*, IntSet>& dom_map,
80 std::unordered_map<Tensor, TensorDom>* out_dom_map) const {}
81
82void PlaceholderOpNode::GatherBound(const Operation& self,
83 const std::unordered_map<Tensor, TensorDom>& tensor_dom,
84 std::unordered_map<IterVar, Range>* out_dom_map) const {}
85
86Stmt PlaceholderOpNode::BuildRealize(const Stage& stage,
87 const std::unordered_map<IterVar, Range>& realize_map,
88 const Stmt& body, String storage_scope) const {
89 return body;
90}
91
92Stmt PlaceholderOpNode::BuildProvide(const Stage& stage,
93 const std::unordered_map<IterVar, Range>& dom_map,
94 bool debug_keep_trivial_loop) const {
95 return Stmt();
96}
97} // namespace te
98} // namespace tvm
99