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>
25#include <tvm/runtime/tensor.h>
26
27#include <string>
28
29namespace tvm {
30namespace runtime {
31
35enum class ReduceKind : int32_t {
36 kSum = 0,
37 kProd = 1,
38 kMin = 2,
39 kMax = 3,
40 kAvg = 4,
41};
42
44inline std::string ReduceKind2String(ReduceKind kind) {
45 switch (kind) {
47 return "kSum";
49 return "kProd";
51 return "kMin";
53 return "kMax";
55 return "kAvg";
56 }
57 TVM_FFI_THROW(ValueError) << "Unknown ReduceKind: " << static_cast<int>(kind);
58}
59
66TVM_RUNTIME_EXTRA_DLL ffi::Module LoadVMModule(std::string path, ffi::Optional<Device> device);
74TVM_RUNTIME_EXTRA_DLL ffi::Tensor DiscoEmptyTensor(ffi::Shape shape, DLDataType dtype,
75 ffi::Optional<Device> device);
83TVM_RUNTIME_EXTRA_DLL void AllReduce(ffi::Tensor send, ReduceKind reduce_kind, bool in_group,
84 ffi::Tensor recv);
91TVM_RUNTIME_EXTRA_DLL void AllGather(ffi::Tensor send, bool in_group, ffi::Tensor recv);
98TVM_RUNTIME_EXTRA_DLL void BroadcastFromWorker0(ffi::Tensor send, bool in_group, ffi::Tensor recv);
106TVM_RUNTIME_EXTRA_DLL void ScatterFromWorker0(ffi::Optional<ffi::Tensor> send, bool in_group,
107 ffi::Tensor recv);
115TVM_RUNTIME_EXTRA_DLL void GatherToWorker0(ffi::Tensor send, bool in_group,
116 ffi::Optional<ffi::Tensor> recv);
121TVM_RUNTIME_EXTRA_DLL void RecvFromWorker0(ffi::Tensor buffer);
127TVM_RUNTIME_EXTRA_DLL void SendToNextGroup(ffi::Tensor buffer);
139TVM_RUNTIME_EXTRA_DLL void SendToWorker(ffi::Tensor buffer, int receiver_id);
145TVM_RUNTIME_EXTRA_DLL void RecvFromWorker(ffi::Tensor buffer, int sender_id);
154
155} // namespace runtime
156} // namespace tvm
157
158#endif // TVM_RUNTIME_DISCO_BUILTIN_H_
Device-independent tensor allocation, copies, views and serialization.
Parent runtime-extra symbol visibility.
#define TVM_RUNTIME_EXTRA_DLL
Definition extra_base.h:45
TVM_RUNTIME_EXTRA_DLL void AllReduce(ffi::Tensor send, ReduceKind reduce_kind, bool in_group, ffi::Tensor recv)
Perform an allreduce operation using the underlying communication library.
std::string ReduceKind2String(ReduceKind kind)
Converts ReduceKind to string.
Definition builtin.h:44
TVM_RUNTIME_EXTRA_DLL void SyncWorker()
Called by the worker thread. Waiting until the worker completes all its tasks. As a specific example,...
TVM_RUNTIME_EXTRA_DLL ffi::Tensor DiscoEmptyTensor(ffi::Shape shape, DLDataType dtype, ffi::Optional< Device > device)
Create an uninitialized empty Tensor.
TVM_RUNTIME_EXTRA_DLL void BroadcastFromWorker0(ffi::Tensor send, bool in_group, ffi::Tensor recv)
Perform a broadcast operation from worker-0.
TVM_RUNTIME_EXTRA_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_EXTRA_DLL int WorkerId()
Get the local worker id.
TVM_RUNTIME_EXTRA_DLL void AllGather(ffi::Tensor send, bool in_group, ffi::Tensor recv)
Perform an allgather operation using the underlying communication library.
TVM_RUNTIME_EXTRA_DLL void SendToWorker(ffi::Tensor buffer, int receiver_id)
Send a buffer to the target receiver worker (globally across all groups).
ReduceKind
Possible kinds of reduction operations.
Definition builtin.h:35
TVM_RUNTIME_EXTRA_DLL void RecvFromWorker0(ffi::Tensor buffer)
Receive a buffer from worker-0. No-op if the current worker is worker-0.
TVM_RUNTIME_EXTRA_DLL void RecvFromWorker(ffi::Tensor buffer, int sender_id)
Receive a buffer from the target sender worker (globally across all groups).
TVM_RUNTIME_EXTRA_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_EXTRA_DLL ffi::Module LoadVMModule(std::string path, ffi::Optional< Device > device)
Load a runtime Module, then create and initialize a RelaxVM.
TVM_RUNTIME_EXTRA_DLL void GatherToWorker0(ffi::Tensor send, bool in_group, ffi::Optional< ffi::Tensor > recv)
Perform a gather operation to worker-0.
TVM_RUNTIME_EXTRA_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.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41