17#include "llvm/Support/JSON.h"
26#define DEBUG_TYPE "bitstream-serdes"
30 auto *valuePtr =
new int(value);
31 featuresint[name] = valuePtr;
37 auto *valuePtr =
new long(value);
38 featureslong[name] = valuePtr;
44 auto *valuePtr =
new float(value);
45 featuresfloat[name] = valuePtr;
51 auto *valuePtr =
new double(value);
52 featuresdouble[name] = valuePtr;
58 const std::string value) {
59 auto *valuePtr =
new std::string(value);
60 featuresstring[name] = valuePtr;
61 long size = value.length();
63 rawData.push_back((
void *)valuePtr->c_str());
67 auto *valuePtr =
new bool(value);
68 featuresbool[name] = valuePtr;
74 const std::vector<int> &value) {
75 auto *valuePtr =
new std::vector<int>(value);
76 featuresVectorint[name] = valuePtr;
79 rawData.push_back(valuePtr->data());
83 const std::vector<long> &value) {
84 auto *valuePtr =
new std::vector<long>(value);
85 featuresVectorlong[name] = valuePtr;
87 name, {
static_cast<long>(valuePtr->size())}));
88 rawData.push_back(valuePtr->data());
92 const std::vector<float> &value) {
93 auto *valuePtr =
new std::vector<float>(value);
94 featuresVectorfloat[name] = valuePtr;
96 name, {
static_cast<long>(valuePtr->size())}));
97 rawData.push_back(valuePtr->data());
101 const std::vector<double> &value) {
102 auto *valuePtr =
new std::vector<double>(value);
103 featuresVectordouble[name] = valuePtr;
105 name, {
static_cast<long>(valuePtr->size())}));
106 rawData.push_back(valuePtr->data());
110 const std::vector<std::string> &value) {
111 llvm_unreachable(
"Currently std::vector<std::string> not supported");
115 const std::vector<bool> &value) {
116 llvm_unreachable(
"Currently std::vector<bool> not supported");
120 std::unique_ptr<llvm::raw_ostream> OS =
121 std::make_unique<llvm::raw_string_ostream>(
Buffer);
122 llvm::json::OStream J(*OS);
124 J.attributeArray(
"features", [&]() {
133 for (
size_t I = 0; I <
rawData.size(); ++I) {
134 OS->write(
reinterpret_cast<const char *
>(
rawData[I]),
139 auto *out =
new std::string(
Buffer);
146 auto *res =
reinterpret_cast<std::string *
>(data);
This file defines the debug macros for the MLCompilerBridge.
#define MLBRIDGE_DEBUG(X)
Bitstream Serialization/Deserialization which sends header information followed by the raw data.
virtual void setFeature(const std::string &name, const google::protobuf::Message *value)
void * getSerializedData() override
void * deserializeUntyped(void *) override
std::vector< TensorSpec > tensorSpecs
void cleanDataStructures() override
std::vector< const void * > rawData
static TensorType getDataType()