tvm
global_info.h
Go to the documentation of this file.
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 
25 #ifndef TVM_RELAX_DISTRIBUTED_GLOBAL_INFO_H_
26 #define TVM_RELAX_DISTRIBUTED_GLOBAL_INFO_H_
27 
28 #include <tvm/ir/expr.h>
29 #include <tvm/ir/module.h>
30 namespace tvm {
31 namespace relax {
32 namespace distributed {
33 /*
34  * \brief Device mesh express a view of topology of devices, represented by an n-d matrix of
35  * device ids
36  */
38  public:
41 
44 
47 
49  v->Visit("shape", &shape);
50  v->Visit("device_ids", &device_ids);
51  v->Visit("device_range", &device_range);
52  }
53  static constexpr const char* _type_key = "relax.distributed.DeviceMesh";
54 
55  bool SEqualReduce(const DeviceMeshNode* other, SEqualReducer equal) const {
56  if (shape.size() != other->shape.size()) {
57  return false;
58  }
59  for (int i = 0; i < static_cast<int>(shape.size()); i++) {
60  if (!equal(shape[i], other->shape[i])) {
61  return false;
62  }
63  }
64  return equal(device_ids, other->device_ids);
65  }
66 
67  void SHashReduce(SHashReducer hash_reduce) const {
68  hash_reduce(device_ids);
69  for (int i = 0; i < static_cast<int>(shape.size()); i++) {
70  hash_reduce(shape[i]);
71  }
72  }
73 
75 };
76 
81 class DeviceMesh : public GlobalInfo {
82  public:
83  TVM_DLL DeviceMesh(ShapeTuple shape, Array<Integer> device_ids);
84  TVM_DLL DeviceMesh(ShapeTuple shape, Range device_range);
86 };
87 
88 } // namespace distributed
89 } // namespace relax
90 } // namespace tvm
91 
92 #endif // TVM_RELAX_DISTRIBUTED_GLOBAL_INFO_H_
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
GlobalInfo are globally static object that are referred by the IR itself. Base node for all global in...
Definition: global_info.h:42
Managed reference to GlobalInfoNode.
Definition: global_info.h:54
Range container
Definition: expr.h:725
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:137
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:121
Definition: global_info.h:37
static constexpr const char * _type_key
Definition: global_info.h:53
void SHashReduce(SHashReducer hash_reduce) const
Definition: global_info.h:67
ShapeTuple shape
logical shape of the mesh
Definition: global_info.h:40
TVM_DECLARE_FINAL_OBJECT_INFO(DeviceMeshNode, GlobalInfoNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: global_info.h:48
Array< Integer > device_ids
device ids in the mesh
Definition: global_info.h:43
bool SEqualReduce(const DeviceMeshNode *other, SEqualReducer equal) const
Definition: global_info.h:55
Optional< Range > device_range
Optionally use range to represent device_ids.
Definition: global_info.h:46
Managed reference to a DeviceMesh.
Definition: global_info.h:81
DeviceMesh(ShapeTuple shape, Range device_range)
TVM_DEFINE_OBJECT_REF_METHODS(DeviceMesh, GlobalInfo, DeviceMeshNode)
DeviceMesh(ShapeTuple shape, Array< Integer > device_ids)
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reference to shape tuple objects.
Definition: shape_tuple.h:85
size_t size() const
Return the size of the shape tuple.
Definition: shape_tuple.h:132
Base expr nodes in TVM.
IRModule that holds the functions and type definitions.
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1913
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal