MLCompilerBridge
Tools for streamlining communication with ML models for compiler optimizations.
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MLBridge::gRPCModelRunner< Client, Stub, Request, Response > Class Template Reference

This class is used to create the grpc model runner object. More...

#include <gRPCModelRunner.h>

Inheritance diagram for MLBridge::gRPCModelRunner< Client, Stub, Request, Response >:
Inheritance graph
[legend]
Collaboration diagram for MLBridge::gRPCModelRunner< Client, Stub, Request, Response >:
Collaboration graph
[legend]

Public Member Functions

 gRPCModelRunner (std::string server_address, grpc::Service *s, llvm::LLVMContext *Ctx=nullptr)
 For server mode.
 
 gRPCModelRunner (std::string server_address, Request *request, Response *response, llvm::LLVMContext *Ctx=nullptr)
 For client mode.
 
void requestExit () override
 
- Public Member Functions inherited from MLBridge::MLModelRunner
 MLModelRunner (const MLModelRunner &)=delete
 
MLModelRunneroperator= (const MLModelRunner &)=delete
 
virtual ~MLModelRunner ()=default
 
template<typename T >
std::enable_if< std::is_fundamental< T >::value, T >::type evaluate ()
 Main user-facing method for interacting with the ML models.
 
template<typename T >
std::enable_if< std::is_fundamental< typenamestd::remove_pointer< T >::type >::value, void >::type evaluate (T &data, size_t &dataSize)
 Main user-facing method for interacting with the ML models.
 
Kind getKind () const
 
SerDesKind getSerDesKind () const
 
template<typename U , typename T , typename... Types>
void populateFeatures (const std::pair< U, T > &var1, const std::pair< U, Types > &...var2)
 User-facing interface for setting the features to be sent to the model.
 
template<typename U , typename T , typename... Types>
void populateFeatures (const std::pair< U, T > &&var1, const std::pair< U, Types > &&...var2)
 
void populateFeatures ()
 
void setRequest (void *request)
 Mainly used in the case of gRPC where the request object is not known explicitly.
 
void setResponse (void *response)
 Mainly used in the case of gRPC where the response object is not known explicitly.
 

Private Member Functions

bool isPortAvailable (std::string addr)
 checks whether a port number is available or not
 
void * evaluateUntyped () override
 This method is used to send the request to the model and get the result.
 
int RunService (grpc::Service *s)
 This method is used to create the server and start listening.
 
int SetStub ()
 This method is used to create the stub. Used in client mode.
 
Request * getRequest ()
 
Response * getResponse ()
 
void printMessage (const google::protobuf::Message *message)
 

Private Attributes

std::promise< void > * exit_requested
 
Stub * stub_
 
std::string server_address
 
Request * request
 
Response * response
 
bool server_mode
 

Additional Inherited Members

- Public Types inherited from MLBridge::MLModelRunner
enum class  Kind : int {
  Unknown , Pipe , gRPC , ONNX ,
  TFAOT
}
 Type of the MLModelRunner. More...
 
- Protected Member Functions inherited from MLBridge::MLModelRunner
 MLModelRunner (Kind Type, SerDesKind SerDesType, llvm::LLVMContext *Ctx=nullptr)
 
 MLModelRunner (Kind Type, llvm::LLVMContext *Ctx=nullptr)
 
- Protected Attributes inherited from MLBridge::MLModelRunner
llvm::LLVMContext * Ctx
 
const Kind Type
 
const SerDesKind SerDesType
 
std::unique_ptr< BaseSerDesSerDes
 

Detailed Description

template<class Client, class Stub, class Request, class Response>
class MLBridge::gRPCModelRunner< Client, Stub, Request, Response >

This class is used to create the grpc model runner object.

grpc model runner requires service, stub, request and response objects to communicate with the model.

Definition at line 80 of file gRPCModelRunner.h.

Constructor & Destructor Documentation

◆ gRPCModelRunner() [1/2]

template<class Client , class Stub , class Request , class Response >
MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::gRPCModelRunner ( std::string server_address,
grpc::Service * s,
llvm::LLVMContext * Ctx = nullptr )
inline

For server mode.

Definition at line 83 of file gRPCModelRunner.h.

◆ gRPCModelRunner() [2/2]

template<class Client , class Stub , class Request , class Response >
MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::gRPCModelRunner ( std::string server_address,
Request * request,
Response * response,
llvm::LLVMContext * Ctx = nullptr )
inline

For client mode.

Definition at line 92 of file gRPCModelRunner.h.

Member Function Documentation

◆ evaluateUntyped()

template<class Client , class Stub , class Request , class Response >
void * MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::evaluateUntyped ( )
inlineoverrideprivatevirtual

This method is used to send the request to the model and get the result.

Used in only client mode during inference.

Implements MLBridge::MLModelRunner.

Definition at line 154 of file gRPCModelRunner.h.

◆ getRequest()

template<class Client , class Stub , class Request , class Response >
Request * MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::getRequest ( )
inlineprivate

Definition at line 248 of file gRPCModelRunner.h.

◆ getResponse()

template<class Client , class Stub , class Request , class Response >
Response * MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::getResponse ( )
inlineprivate

Definition at line 250 of file gRPCModelRunner.h.

◆ isPortAvailable()

template<class Client , class Stub , class Request , class Response >
bool MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::isPortAvailable ( std::string addr)
inlineprivate

checks whether a port number is available or not

Definition at line 112 of file gRPCModelRunner.h.

◆ printMessage()

template<class Client , class Stub , class Request , class Response >
void MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::printMessage ( const google::protobuf::Message * message)
inlineprivate

Definition at line 252 of file gRPCModelRunner.h.

◆ requestExit()

template<class Client , class Stub , class Request , class Response >
void MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::requestExit ( )
inlineoverridevirtual

Implements MLBridge::MLModelRunner.

Definition at line 100 of file gRPCModelRunner.h.

◆ RunService()

template<class Client , class Stub , class Request , class Response >
int MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::RunService ( grpc::Service * s)
inlineprivate

This method is used to create the server and start listening.

Used in server mode.

Definition at line 220 of file gRPCModelRunner.h.

◆ SetStub()

template<class Client , class Stub , class Request , class Response >
int MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::SetStub ( )
inlineprivate

This method is used to create the stub. Used in client mode.

Definition at line 240 of file gRPCModelRunner.h.

Member Data Documentation

◆ exit_requested

template<class Client , class Stub , class Request , class Response >
std::promise<void>* MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::exit_requested
private

Definition at line 150 of file gRPCModelRunner.h.

◆ request

template<class Client , class Stub , class Request , class Response >
Request* MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::request
private

Definition at line 214 of file gRPCModelRunner.h.

◆ response

template<class Client , class Stub , class Request , class Response >
Response* MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::response
private

Definition at line 215 of file gRPCModelRunner.h.

◆ server_address

template<class Client , class Stub , class Request , class Response >
std::string MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::server_address
private

Definition at line 213 of file gRPCModelRunner.h.

◆ server_mode

template<class Client , class Stub , class Request , class Response >
bool MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::server_mode
private

Definition at line 216 of file gRPCModelRunner.h.

◆ stub_

template<class Client , class Stub , class Request , class Response >
Stub* MLBridge::gRPCModelRunner< Client, Stub, Request, Response >::stub_
private

Definition at line 212 of file gRPCModelRunner.h.


The documentation for this class was generated from the following file: