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 * \file tvm/relay/attrs/memory.h
22 * \brief Attributes for memory operators.
23 */
24#ifndef TVM_RELAY_ATTRS_MEMORY_H_
25#define TVM_RELAY_ATTRS_MEMORY_H_
26
27#include <tvm/ir/attrs.h>
28#include <tvm/relay/expr.h>
29#include <tvm/target/virtual_device.h>
30
31#include <string>
32#include <vector>
33
34namespace tvm {
35namespace relay {
36
37std::vector<TensorType> FlattenTupleType(const Type& type);
38std::vector<Expr> FromTupleType(const Type& type, const Expr& expr);
39Expr ToTupleType(const Type& t, const std::vector<Expr>& exprs);
40
41/*!
42 * \brief Options for allocating storage.
43 */
44struct AllocStorageAttrs : public tvm::AttrsNode<AllocStorageAttrs> {
45 DataType dtype;
46 VirtualDevice virtual_device = VirtualDevice::FullyUnconstrained();
47
48 TVM_DECLARE_ATTRS(AllocStorageAttrs, "relay.attrs.AllocStorageAttrs") {
49 TVM_ATTR_FIELD(dtype)
50 .describe("The dtype of the tensor to allocate.")
51 .set_default(DataType::Float(32, 1));
52 TVM_ATTR_FIELD(virtual_device).describe("The virtual device on which to allocate memory.");
53 }
54};
55
56/*!
57 * \brief Options for allocating tensors.
58 */
59struct AllocTensorAttrs : public tvm::AttrsNode<AllocTensorAttrs> {
60 Constant const_shape;
61 Array<IndexExpr> assert_shape;
62 DataType dtype;
63
64 TVM_DECLARE_ATTRS(AllocTensorAttrs, "relay.attrs.AllocTensorAttrs") {
65 TVM_ATTR_FIELD(dtype)
66 .describe("The dtype of the tensor to allocate.")
67 .set_default(DataType::Float(32, 1));
68 TVM_ATTR_FIELD(const_shape).describe("The shape of constant used to aid in type inference.");
69 TVM_ATTR_FIELD(assert_shape)
70 .describe(
71 "The shape to cast the return type of the allocation to, "
72 "used to specify the shape obtained via further analysis.");
73 }
74};
75
76} // namespace relay
77} // namespace tvm
78#endif // TVM_RELAY_ATTRS_MEMORY_H_
79