MLCompilerBridge
Tools for streamlining communication with ML models for compiler optimizations.
Loading...
Searching...
No Matches
baseSerDes.h
Go to the documentation of this file.
1//=== SerDes/baseSerDes.h - Base for serialization and deserialization C++ ===//
2//
3// Part of the MLCompilerBridge Project, under the Apache License v2.0 with LLVM
4// Exceptions. See the LICENSE file for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
16//===----------------------------------------------------------------------===//
17
18#ifndef BASE_SERDES_H
19#define BASE_SERDES_H
20
22#include "google/protobuf/extension_set.h"
23#include "google/protobuf/message.h"
24#include "llvm/Support/raw_ostream.h"
25
26#include <cassert>
27#include <map>
28#include <string>
29#include <vector>
30
31// TYPE, NAME
32#define SUPPORTED_TYPES(M) \
33 M(int, int) \
34 M(long, long) \
35 M(float, float) \
36 M(double, double) \
37 M(std::string, string) \
38 M(bool, bool)
39
40namespace MLBridge {
48public:
49 SerDesKind getKind() const { return Type; }
50
54#define SET_FEATURE(TYPE, _) \
55 virtual void setFeature(const std::string &, const TYPE) = 0; \
56 virtual void setFeature(const std::string &, const std::vector<TYPE> &){};
58#undef SET_FEATURE
59
60 virtual void setFeature(const std::string &name,
61 const google::protobuf::Message *value){};
62 virtual void
63 setFeature(const std::string &name,
64 const std::vector<google::protobuf::Message *> &value){};
65
66 // a hack to set the request and response structures in protobuf serializer
67 virtual void setRequest(void *Request) {
68 MLBRIDGE_DEBUG(std::cout << "In BaseSerializer setRequest...\n");
69 };
70 virtual void setResponse(void *Response){};
71 virtual void *getSerializedData() = 0;
72 virtual void *deserializeUntyped(void *data) = 0;
73 size_t getMessageLength() { return MessageLength; }
74 virtual void *getRequest() { return nullptr; };
75 virtual void *getResponse() { return nullptr; };
76
77protected:
81 virtual void cleanDataStructures() = 0;
86};
87} // namespace MLBridge
88
89#endif
This file defines the debug macros for the MLCompilerBridge.
#define MLBRIDGE_DEBUG(X)
Definition Debug.h:25
#define SUPPORTED_TYPES(M)
Definition baseSerDes.h:32
#define SET_FEATURE(TYPE, _)
setFeature() is used to set the features of the data structure used for communication.
Definition baseSerDes.h:54
size_t getMessageLength()
Definition baseSerDes.h:73
virtual void * getResponse()
Definition baseSerDes.h:75
virtual void setRequest(void *Request)
Definition baseSerDes.h:67
BaseSerDes(SerDesKind Type)
Definition baseSerDes.h:78
virtual void setFeature(const std::string &name, const google::protobuf::Message *value)
Definition baseSerDes.h:60
virtual void cleanDataStructures()=0
virtual void * deserializeUntyped(void *data)=0
virtual void * getRequest()
Definition baseSerDes.h:74
virtual void setResponse(void *Response)
Definition baseSerDes.h:70
SerDesKind getKind() const
Definition baseSerDes.h:49
const SerDesKind Type
Definition baseSerDes.h:82
virtual void setFeature(const std::string &name, const std::vector< google::protobuf::Message * > &value)
Definition baseSerDes.h:63
virtual void * getSerializedData()=0
SerDesKind
This is the base class for SerDes.
Definition baseSerDes.h:46