LLVM: lib/Analysis/InteractiveModelRunner.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
18
19using namespace llvm;
20
23 cl::desc("The InteractiveModelRunner will echo back to stderr "
24 "the data received from the host (for debugging purposes)."));
25
27 LLVMContext &Ctx, const std::vector &Inputs,
30 InputSpecs(Inputs), OutputSpec(Advice),
31 InEC(sys::fs::openFileForRead(InboundName, Inbound)),
32 OutputBuffer(OutputSpec.getTotalTensorBufferSize()) {
33 if (InEC) {
34 Ctx.emitError("Cannot open inbound file: " + InEC.message());
35 return;
36 }
37 {
38 auto OutStream = std::make_unique<raw_fd_ostream>(OutboundName, OutEC);
39 if (OutEC) {
40 Ctx.emitError("Cannot open outbound file: " + OutEC.message());
41 return;
42 }
43 Log = std::make_unique(std::move(OutStream), InputSpecs, Advice,
44 false, Advice);
45 }
46
47
48 for (size_t I = 0; I < InputSpecs.size(); ++I)
50 Log->flush();
51}
52
57
59 Log->startObservation();
60 for (size_t I = 0; I < InputSpecs.size(); ++I)
61 Log->logTensorValue(I, reinterpret_cast<const char *>(getTensorUntyped(I)));
62 Log->endObservation();
63 Log->flush();
64
65 size_t InsPoint = 0;
68 while (InsPoint < Limit) {
71 {Buff + InsPoint, OutputBuffer.size() - InsPoint});
72 if (ReadOrErr.takeError()) {
73 Ctx.emitError("Failed reading from inbound file");
74 break;
75 }
76 InsPoint += *ReadOrErr;
77 }
79 dbgs() << OutputSpec.name() << ": "
81 return OutputBuffer.data();
82}
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() override
Definition InteractiveModelRunner.cpp:53
InteractiveModelRunner(LLVMContext &Ctx, const std::vector< TensorSpec > &Inputs, const TensorSpec &Advice, StringRef OutboundName, StringRef InboundName)
Definition InteractiveModelRunner.cpp:26
This is an important class for using LLVM in a threaded context.
virtual void * evaluateUntyped()=0
void * getTensorUntyped(size_t Index)
void setUpBufferForTensor(size_t Index, const TensorSpec &Spec, void *Buffer)
MLModelRunner(const MLModelRunner &)=delete
StringRef - Represent a constant reference to a string, i.e.
initializer< Ty > init(const Ty &Val)
LLVM_ABI std::error_code closeFile(file_t &F)
Close the file object.
LLVM_ABI Expected< size_t > readNativeFile(file_t FileHandle, MutableArrayRef< char > Buf)
Reads Buf.size() bytes from FileHandle into Buf.
LLVM_ABI 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.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI std::string tensorValueToString(const char *Buffer, const TensorSpec &Spec)
For debugging.