tvm
builtin.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 #ifndef TVM_RUNTIME_DISCO_BUILTIN_H_
20 #define TVM_RUNTIME_DISCO_BUILTIN_H_
21 
22 #include <tvm/runtime/data_type.h>
23 #include <tvm/runtime/module.h>
24 #include <tvm/runtime/tensor.h>
25 
26 #include <string>
27 
28 namespace tvm {
29 namespace runtime {
30 
34 enum class ReduceKind : int32_t {
35  kSum = 0,
36  kProd = 1,
37  kMin = 2,
38  kMax = 3,
39  kAvg = 4,
40 };
41 
43 inline std::string ReduceKind2String(ReduceKind kind) {
44  switch (kind) {
45  case ReduceKind::kSum:
46  return "kSum";
47  case ReduceKind::kProd:
48  return "kProd";
49  case ReduceKind::kMin:
50  return "kMin";
51  case ReduceKind::kMax:
52  return "kMax";
53  case ReduceKind::kAvg:
54  return "kAvg";
55  }
56  LOG(FATAL) << "ValueError: Unknown ReduceKind: " << static_cast<int>(kind);
57 }
58 
65 TVM_DLL ffi::Module LoadVMModule(std::string path, ffi::Optional<Device> device);
73 TVM_DLL Tensor DiscoEmptyTensor(ffi::Shape shape, DataType dtype, ffi::Optional<Device> device);
81 TVM_DLL void AllReduce(Tensor send, ReduceKind reduce_kind, bool in_group, Tensor recv);
88 TVM_DLL void AllGather(Tensor send, bool in_group, Tensor recv);
95 TVM_DLL void BroadcastFromWorker0(Tensor send, bool in_group, Tensor recv);
103 TVM_DLL void ScatterFromWorker0(ffi::Optional<Tensor> send, bool in_group, Tensor recv);
111 TVM_DLL void GatherToWorker0(Tensor send, bool in_group, ffi::Optional<Tensor> recv);
116 TVM_DLL void RecvFromWorker0(Tensor buffer);
122 TVM_DLL void SendToNextGroup(Tensor buffer);
128 TVM_DLL void RecvFromPrevGroup(Tensor buffer);
134 TVM_DLL void SendToWorker(Tensor buffer, int receiver_id);
140 TVM_DLL void RecvFromWorker(Tensor buffer, int sender_id);
142 TVM_DLL int WorkerId();
148 TVM_DLL void SyncWorker();
149 
150 } // namespace runtime
151 } // namespace tvm
152 
153 #endif // TVM_RUNTIME_DISCO_BUILTIN_H_
Runtime primitive data type.
Definition: data_type.h:47
Managed Tensor. The array is backed by reference counted blocks.
Definition: tensor.h:53
void SendToWorker(Tensor buffer, int receiver_id)
Send a buffer to the target receiver worker (globally across all groups).
ffi::Module LoadVMModule(std::string path, ffi::Optional< Device > device)
Load a runtime Module, then create and initialize a RelaxVM.
int WorkerId()
Get the local worker id.
void RecvFromWorker0(Tensor buffer)
Receive a buffer from worker-0. No-op if the current worker is worker-0.
void SendToNextGroup(Tensor buffer)
Send a buffer to the corresponding worker in the next group. An error is thrown if the worker is alre...
std::string ReduceKind2String(ReduceKind kind)
Converts ReduceKind to string.
Definition: builtin.h:43
void RecvFromPrevGroup(Tensor buffer)
Receive a buffer from the corresponding worker in the previous group. An error is thrown if the worke...
void SyncWorker()
Called by the worker thread. Waiting until the worker completes all its tasks. As a specific example,...
void AllGather(Tensor send, bool in_group, Tensor recv)
Perform an allgather operation using the underlying communication library.
ReduceKind
Possible kinds of reduction operations.
Definition: builtin.h:34
void BroadcastFromWorker0(Tensor send, bool in_group, Tensor recv)
Perform a broadcast operation from worker-0.
void AllReduce(Tensor send, ReduceKind reduce_kind, bool in_group, Tensor recv)
Perform an allreduce operation using the underlying communication library.
void ScatterFromWorker0(ffi::Optional< Tensor > send, bool in_group, Tensor recv)
Perform a scatter operation from worker-0, chunking the given buffer into equal parts.
Tensor DiscoEmptyTensor(ffi::Shape shape, DataType dtype, ffi::Optional< Device > device)
Create an uninitialized empty Tensor.
void RecvFromWorker(Tensor buffer, int sender_id)
Receive a buffer from the target sender worker (globally across all groups).
void GatherToWorker0(Tensor send, bool in_group, ffi::Optional< Tensor > recv)
Perform a gather operation to worker-0.
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:1960
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
Runtime container of the functions generated by TVM, This is used to support dynamically link,...
A device-independent managed Tensor abstraction.