tvm
Loading...
Searching...
No Matches
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/ffi/dtype.h>
23#include <tvm/ffi/extra/module.h>
24#include <tvm/runtime/tensor.h>
25
26#include <string>
27
28namespace tvm {
29namespace runtime {
30
34enum class ReduceKind : int32_t {
35 kSum = 0,
36 kProd = 1,
37 kMin = 2,
38 kMax = 3,
39 kAvg = 4,
40};
41
43inline std::string ReduceKind2String(ReduceKind kind) {
44 switch (kind) {
46 return "kSum";
48 return "kProd";
50 return "kMin";
52 return "kMax";
54 return "kAvg";
55 }
56 TVM_FFI_THROW(ValueError) << "Unknown ReduceKind: " << static_cast<int>(kind);
57}
58
65TVM_RUNTIME_DLL ffi::Module LoadVMModule(std::string path, ffi::Optional<Device> device);
73TVM_RUNTIME_DLL ffi::Tensor DiscoEmptyTensor(ffi::Shape shape, DLDataType dtype,
74 ffi::Optional<Device> device);
82TVM_RUNTIME_DLL void AllReduce(ffi::Tensor send, ReduceKind reduce_kind, bool in_group,
83 ffi::Tensor recv);
90TVM_RUNTIME_DLL void AllGather(ffi::Tensor send, bool in_group, ffi::Tensor recv);
97TVM_RUNTIME_DLL void BroadcastFromWorker0(ffi::Tensor send, bool in_group, ffi::Tensor recv);
105TVM_RUNTIME_DLL void ScatterFromWorker0(ffi::Optional<ffi::Tensor> send, bool in_group,
106 ffi::Tensor recv);
114TVM_RUNTIME_DLL void GatherToWorker0(ffi::Tensor send, bool in_group,
115 ffi::Optional<ffi::Tensor> recv);
120TVM_RUNTIME_DLL void RecvFromWorker0(ffi::Tensor buffer);
126TVM_RUNTIME_DLL void SendToNextGroup(ffi::Tensor buffer);
132TVM_RUNTIME_DLL void RecvFromPrevGroup(ffi::Tensor buffer);
138TVM_RUNTIME_DLL void SendToWorker(ffi::Tensor buffer, int receiver_id);
144TVM_RUNTIME_DLL void RecvFromWorker(ffi::Tensor buffer, int sender_id);
153
154} // namespace runtime
155} // namespace tvm
156
157#endif // TVM_RUNTIME_DISCO_BUILTIN_H_
TVM_RUNTIME_DLL void ScatterFromWorker0(ffi::Optional< ffi::Tensor > send, bool in_group, ffi::Tensor recv)
Perform a scatter operation from worker-0, chunking the given buffer into equal parts.
TVM_RUNTIME_DLL void SyncWorker()
Called by the worker thread. Waiting until the worker completes all its tasks. As a specific example,...
TVM_RUNTIME_DLL void SendToNextGroup(ffi::Tensor buffer)
Send a buffer to the corresponding worker in the next group. An error is thrown if the worker is alre...
TVM_RUNTIME_DLL ffi::Module LoadVMModule(std::string path, ffi::Optional< Device > device)
Load a runtime Module, then create and initialize a RelaxVM.
std::string ReduceKind2String(ReduceKind kind)
Converts ReduceKind to string.
Definition builtin.h:43
TVM_RUNTIME_DLL void SendToWorker(ffi::Tensor buffer, int receiver_id)
Send a buffer to the target receiver worker (globally across all groups).
TVM_RUNTIME_DLL void BroadcastFromWorker0(ffi::Tensor send, bool in_group, ffi::Tensor recv)
Perform a broadcast operation from worker-0.
TVM_RUNTIME_DLL void RecvFromWorker(ffi::Tensor buffer, int sender_id)
Receive a buffer from the target sender worker (globally across all groups).
TVM_RUNTIME_DLL void RecvFromPrevGroup(ffi::Tensor buffer)
Receive a buffer from the corresponding worker in the previous group. An error is thrown if the worke...
TVM_RUNTIME_DLL void RecvFromWorker0(ffi::Tensor buffer)
Receive a buffer from worker-0. No-op if the current worker is worker-0.
ReduceKind
Possible kinds of reduction operations.
Definition builtin.h:34
TVM_RUNTIME_DLL void AllReduce(ffi::Tensor send, ReduceKind reduce_kind, bool in_group, ffi::Tensor recv)
Perform an allreduce operation using the underlying communication library.
TVM_RUNTIME_DLL void AllGather(ffi::Tensor send, bool in_group, ffi::Tensor recv)
Perform an allgather operation using the underlying communication library.
TVM_RUNTIME_DLL int WorkerId()
Get the local worker id.
TVM_RUNTIME_DLL void GatherToWorker0(ffi::Tensor send, bool in_group, ffi::Optional< ffi::Tensor > recv)
Perform a gather operation to worker-0.
TVM_RUNTIME_DLL ffi::Tensor DiscoEmptyTensor(ffi::Shape shape, DLDataType dtype, ffi::Optional< Device > device)
Create an uninitialized empty Tensor.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
#define TVM_RUNTIME_DLL
Definition base.h:100
Device-independent tensor allocation, copies, views and serialization.