23 cl::desc(
"The InteractiveModelRunner will echo back to stderr "
24 "the data received from the host (for debugging purposes)."));
27 LLVMContext &Ctx,
const std::vector<TensorSpec> &Inputs,
30 InputSpecs(Inputs), OutputSpec(Advice),
31 InEC(sys::fs::openFileForRead(InboundName, Inbound)),
32 OutputBuffer(OutputSpec.getTotalTensorBufferSize()) {
34 Ctx.
emitError(
"Cannot open inbound file: " + InEC.message());
38 auto OutStream = std::make_unique<raw_fd_ostream>(OutboundName, OutEC);
40 Ctx.
emitError(
"Cannot open outbound file: " + OutEC.message());
43 Log = std::make_unique<Logger>(std::move(OutStream), InputSpecs, Advice,
48 for (
size_t I = 0;
I < InputSpecs.size(); ++
I)
58void *InteractiveModelRunner::evaluateUntyped() {
59 Log->startObservation();
60 for (
size_t I = 0;
I < InputSpecs.size(); ++
I)
62 Log->endObservation();
66 char *Buff = OutputBuffer.data();
67 const size_t Limit = OutputBuffer.size();
68 while (InsPoint < Limit) {
71 {Buff + InsPoint, OutputBuffer.size() - InsPoint});
72 if (ReadOrErr.takeError()) {
76 InsPoint += *ReadOrErr;
static cl::opt< bool > DebugReply("interactive-model-runner-echo-reply", cl::init(false), cl::Hidden, cl::desc("The InteractiveModelRunner will echo back to stderr " "the data received from the host (for debugging purposes)."))
InteractiveModelRunner(LLVMContext &Ctx, const std::vector< TensorSpec > &Inputs, const TensorSpec &Advice, StringRef OutboundName, StringRef InboundName)
virtual ~InteractiveModelRunner()
This is an important class for using LLVM in a threaded context.
void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
MLModelRunner interface: abstraction of a mechanism for evaluating a ML model.
void * getTensorUntyped(size_t Index)
void setUpBufferForTensor(size_t Index, const TensorSpec &Spec, void *Buffer)
StringRef - Represent a constant reference to a string, i.e.
const std::string & name() const
initializer< Ty > init(const Ty &Val)
Expected< size_t > readNativeFile(file_t FileHandle, MutableArrayRef< char > Buf)
Reads Buf.size() bytes from FileHandle into Buf.
std::error_code closeFile(file_t &F)
Close the file object.
file_t convertFDToNativeFile(int FD)
Converts from a Posix file descriptor number to a native file handle.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
std::string tensorValueToString(const char *Buffer, const TensorSpec &Spec)
For debugging.