73#ifndef TVM_RUNTIME_DISCO_SESSION_H_
74#define TVM_RUNTIME_DISCO_SESSION_H_
76#include <tvm/ffi/container/shape.h>
77#include <tvm/ffi/function.h>
101 "kRuntimeDiscoDRef must live in the static custom-index slot range");
126 return "kGetGlobalFunc";
128 return "kCallPacked";
130 return "kSyncWorker";
132 return "kCopyFromWorker0";
134 return "kCopyToWorker0";
136 return "kDebugGetFromRemote";
138 return "kDebugSetRegister";
140 TVM_FFI_THROW(ValueError) <<
"Unknown DiscoAction: " <<
static_cast<int>(action);
166 inline void DebugCopyFrom(
int worker_id, ffi::AnyView source);
187class DRef :
public ffi::ObjectRef {
189 explicit DRef(ffi::ObjectPtr<DRefObj> data) : ffi::ObjectRef(data) {
190 TVM_FFI_ICHECK(data !=
nullptr);
217 template <
typename... Args>
236 const DRef& remote_array) = 0;
243 const DRef& remote_array) = 0;
313 ffi::String process_pool_creator,
314 ffi::String entrypoint);
316 explicit Session(ffi::UnsafeInit tag, ffi::ObjectPtr<SessionObj> n) : ffi::ObjectRef(tag) {
317 data_ = std::move(n);
331 virtual void Send(
const ffi::PackedArgs& args) = 0;
333 virtual ffi::PackedArgs
Recv() = 0;
335 virtual void Reply(
const ffi::PackedArgs& args) = 0;
375template <
typename... Args>
377 constexpr int offset = 3;
378 constexpr int kNumArgs = offset +
sizeof...(Args);
379 ffi::AnyView packed_args[kNumArgs];
380 ffi::PackedArgs::Fill(packed_args,
384 std::forward<Args>(args)...);
385 return this->
CallWithPacked(ffi::PackedArgs(packed_args, kNumArgs));
Device-independent tensor allocation, copies, views and serialization.
An object that exists on all workers.
Definition session.h:151
~DRefObj()
Definition session.h:361
ffi::ObjectRef session
Back-pointer to the host controler session.
Definition session.h:176
TVM_FFI_DECLARE_OBJECT_INFO_STATIC("runtime.disco.DRef", DRefObj, ffi::Object)
static constexpr const bool _type_mutable
Definition session.h:170
static constexpr const uint32_t _type_index
Definition session.h:168
ffi::Any DebugGetFromRemote(int worker_id)
Get the value of a DRef from a remote worker.
Definition session.h:367
int64_t reg_id
The id of the register.
Definition session.h:174
void DebugCopyFrom(int worker_id, ffi::AnyView source)
Copy from the Tensor provided to a remote worker.
Definition session.h:371
static const constexpr bool _type_final
Definition session.h:169
Managed reference to DRefObj.
Definition session.h:187
DRef(ffi::ObjectPtr< DRefObj > data)
Definition session.h:189
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DRef, ffi::ObjectRef, DRefObj)
A bi-directional channel for controler-worker communication. This channel is primarily used to transf...
Definition session.h:327
virtual void Reply(const ffi::PackedArgs &args)=0
Reply a packed sequence to the sender.
virtual ffi::PackedArgs Recv()=0
Receive a packed sequence from worker.
virtual ~DiscoChannel()=default
virtual void Send(const ffi::PackedArgs &args)=0
Send a packed sequence to the receiver.
virtual ffi::PackedArgs RecvReply()=0
Receive a reply from the worker.
A Disco interactive session. It allows users to interact with the Disco command queue with various ff...
Definition session.h:199
virtual TVM_RUNTIME_EXTRA_DLL DRef CallWithPacked(const ffi::PackedArgs &args)=0
Call packed function on each worker using a packed sequence. The calling convention: The first elemen...
virtual TVM_RUNTIME_EXTRA_DLL void Shutdown()=0
Signal all the workers to shutdown.
virtual TVM_RUNTIME_EXTRA_DLL void SyncWorker(int worker_id)=0
Synchrnoize the controler with a worker, and it will wait until worker finishes executing this instru...
friend struct SessionObj::FFI
Definition session.h:277
virtual TVM_RUNTIME_EXTRA_DLL void InitCCL(ffi::String ccl, ffi::Shape device_ids)=0
Initialize the data plane between workers.
virtual void DeallocReg(int reg_id)=0
Deallocate a register id, kill it on all workers, and append it to free_regs_.
virtual TVM_RUNTIME_EXTRA_DLL DRef GetGlobalFunc(const std::string &name)=0
Get a global functions on workers.
TVM_FFI_DECLARE_OBJECT_INFO("runtime.disco.Session", SessionObj, ffi::Object)
virtual TVM_RUNTIME_EXTRA_DLL ffi::Any DebugGetFromRemote(int64_t reg_id, int worker_id)=0
Get the value of a register from a remote worker.
static constexpr const bool _type_mutable
Definition session.h:280
virtual TVM_RUNTIME_EXTRA_DLL int64_t GetNumWorkers()=0
Get the number of workers in the session.
virtual ~SessionObj()=default
virtual TVM_RUNTIME_EXTRA_DLL void CopyFromWorker0(const ffi::Tensor &host_array, const DRef &remote_array)=0
Copy an Tensor from worker-0 to the controler-side Tensor.
virtual TVM_RUNTIME_EXTRA_DLL void CopyToWorker0(const ffi::Tensor &host_array, const DRef &remote_array)=0
Copy the controler-side Tensor to worker-0.
TVM_FFI_INLINE DRef CallPacked(const DRef &func, Args &&... args)
Call a ffi::Function on workers providing variadic arguments.
virtual TVM_RUNTIME_EXTRA_DLL void DebugSetRegister(int64_t reg_id, ffi::AnyView value, int worker_id)=0
Set the value of a register on a remote worker.
Managed reference to SessionObj.
Definition session.h:292
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Session, ffi::ObjectRef, SessionObj)
static TVM_RUNTIME_EXTRA_DLL Session ThreadedSession(int num_workers, int num_groups)
Create a session backed by a thread pool of workers.
static TVM_RUNTIME_EXTRA_DLL Session ProcessSession(int num_workers, int num_groups, ffi::String process_pool_creator, ffi::String entrypoint)
Create a session backed by pipe-based multiprocessing.
Session(ffi::UnsafeInit tag, ffi::ObjectPtr< SessionObj > n)
Definition session.h:316
A special communication channel between controler and worker-0, assuming they are always collocated i...
Definition session.h:344
std::mutex queue_mutex_
The mutex that guards host_arrays
Definition session.h:352
std::queue< ffi::Tensor > host_arrays
The host-side arrays to passed to worker-0 for special uses, for example, copy-to-worker0 and copy-fr...
Definition session.h:350
std::string DiscoAction2String(DiscoAction action)
Converts the enum class DiscoAction to string.
Definition session.h:119
DiscoAction
All possible kinds of Disco commands.
Definition session.h:106
constexpr int32_t kRuntimeDiscoDRef
Static FFI type index for runtime::disco::DRef.
Definition session.h:97
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41