diff --git a/include/MLModelRunner/MLModelRunner.h b/include/MLModelRunner/MLModelRunner.h index d99a6c6f..5b71e4d2 100644 --- a/include/MLModelRunner/MLModelRunner.h +++ b/include/MLModelRunner/MLModelRunner.h @@ -39,19 +39,24 @@ #include "SerDes/baseSerDes.h" #include "SerDes/bitstreamSerDes.h" #include "SerDes/jsonSerDes.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/raw_ostream.h" #include +#include #include #include +#include +#include #include #include #ifndef C_LIBRARY #include "SerDes/protobufSerDes.h" #include "SerDes/tensorflowSerDes.h" +#include #endif namespace MLBridge { - /// MLModelRunner - The main interface for interacting with the ML models. class MLModelRunner { public: @@ -73,21 +78,69 @@ class MLModelRunner { void>::type evaluate(T &data, size_t &dataSize) { using BaseType = typename std::remove_pointer::type; - void *res = evaluateUntyped(); + auto *res = evaluateUntyped(); T ret = static_cast(malloc(SerDes->getMessageLength())); memcpy(ret, res, SerDes->getMessageLength()); dataSize = SerDes->getMessageLength() / sizeof(BaseType); data = ret; + std::error_code EC; + llvm::raw_fd_ostream fileStream("test-raw.txt", EC, llvm::sys::fs::OF_Append); + dumpOutput(fileStream, ret, dataSize); + } + + template void dumpOutput(llvm::raw_ostream &OS, T output_vec, int DataSize) { + + OS<<"Dumping output"<<": "; + for(auto i=0;i void dumpOuput(llvm::raw_ostream &OS,T &var1, int DataSize) { + OS<<"Dumping output"<<": "; + OS << var1 << "\n"; + } + + + /// Type of the MLModelRunner enum class Kind : int { Unknown, Pipe, gRPC, ONNX, TFAOT }; + Kind getKind() const { return Type; } BaseSerDes::Kind getSerDesKind() const { return SerDesType; } virtual void requestExit() = 0; + std::promise *exit_requested; + + template + void passMetaInfo(llvm::raw_ostream &OS,std::pair &var1, + std::pair &...var2) { + OS << var1.first << ": " << var1.second << "\n"; + passMetaInfo(var2...); + } + + //void passMetaInfo() {} + template void dumpFeature(llvm::raw_ostream &OS,std::pair &var1) { + OS<<"Dumping input 1"<<": "; + OS << var1.first << ": " << var1.second << "\n"; + } + + template + void dumpFeature(llvm::raw_ostream &OS,std::pair> &var1) { + OS<<"Dumping input 2"<<": "; + OS << var1.first << ": "; + for (const auto &elem : var1.second) { + OS << elem << " "; + } + OS << "\n"; + } + + void dumpFeature(llvm::raw_ostream &OS,std::pair> &var1) { + + } /// User-facing interface for setting the features to be sent to the model. /// The features are passed as a list of key-value pairs. /// The key is the name of the feature and the value is the value of the @@ -96,6 +149,9 @@ class MLModelRunner { void populateFeatures(std::pair &var1, std::pair &...var2) { SerDes->setFeature(var1.first, var1.second); + std::error_code EC; + llvm::raw_fd_ostream fileStream("test-raw.txt", EC, llvm::sys::fs::OF_Append); + dumpFeature(fileStream,var1); populateFeatures(var2...); }