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/ndarray.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, Optional<Device> device);
73 TVM_DLL NDArray DiscoEmptyNDArray(ffi::Shape shape, DataType dtype, Optional<Device> device);
81 TVM_DLL void AllReduce(NDArray send, ReduceKind reduce_kind, bool in_group, NDArray recv);
88 TVM_DLL void AllGather(NDArray send, bool in_group, NDArray recv);
95 TVM_DLL void BroadcastFromWorker0(NDArray send, bool in_group, NDArray recv);
103 TVM_DLL void ScatterFromWorker0(Optional<NDArray> send, bool in_group, NDArray recv);
111 TVM_DLL void GatherToWorker0(NDArray send, bool in_group, Optional<NDArray> recv);
116 TVM_DLL void RecvFromWorker0(NDArray buffer);
122 TVM_DLL void SendToNextGroup(NDArray buffer);
128 TVM_DLL void RecvFromPrevGroup(NDArray buffer);
134 TVM_DLL void SendToWorker(NDArray buffer, int receiver_id);
140 TVM_DLL void RecvFromWorker(NDArray 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 NDArray. The array is backed by reference counted blocks.
Definition: ndarray.h:53
void BroadcastFromWorker0(NDArray send, bool in_group, NDArray recv)
Perform a broadcast operation from worker-0.
int WorkerId()
Get the local worker id.
void RecvFromPrevGroup(NDArray buffer)
Receive a buffer from the corresponding worker in the previous group. An error is thrown if the worke...
ffi::Module LoadVMModule(std::string path, Optional< Device > device)
Load a runtime Module, then create and initialize a RelaxVM.
void SendToNextGroup(NDArray 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 GatherToWorker0(NDArray send, bool in_group, Optional< NDArray > recv)
Perform a gather operation to worker-0.
void AllReduce(NDArray send, ReduceKind reduce_kind, bool in_group, NDArray recv)
Perform an allreduce operation using the underlying communication library.
void AllGather(NDArray send, bool in_group, NDArray recv)
Perform an allgather operation using the underlying communication library.
void SyncWorker()
Called by the worker thread. Waiting until the worker completes all its tasks. As a specific example,...
void ScatterFromWorker0(Optional< NDArray > send, bool in_group, NDArray recv)
Perform a scatter operation from worker-0, chunking the given buffer into equal parts.
void RecvFromWorker(NDArray buffer, int sender_id)
Receive a buffer from the target sender worker (globally across all groups).
ReduceKind
Possible kinds of reduction operations.
Definition: builtin.h:34
void RecvFromWorker0(NDArray buffer)
Receive a buffer from worker-0. No-op if the current worker is worker-0.
NDArray DiscoEmptyNDArray(ffi::Shape shape, DataType dtype, Optional< Device > device)
Create an uninitialized empty NDArray.
void SendToWorker(NDArray buffer, int receiver_id)
Send a buffer to the target receiver worker (globally across all groups).
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:1945
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
A device-independent managed NDArray abstraction.
Runtime container of the functions generated by TVM, This is used to support dynamically link,...