MLCompilerBridge
Tools for streamlining communication with ML models for compiler optimizations.
Loading...
Searching...
No Matches
bitstreamSerDes.h
Go to the documentation of this file.
1//=== SerDes/bitstreamSerDes.h -Bitstream Serialization/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//===----------------------------------------------------------------------===//
13//===----------------------------------------------------------------------===//
14
15#ifndef BITSTREAM_SERIALIZER_H
16#define BITSTREAM_SERIALIZER_H
17
18#include "SerDes/TensorSpec.h"
19#include "SerDes/baseSerDes.h"
20#include <memory>
21#include <set>
22#include <string>
23#include <utility>
24#include <vector>
25
26namespace MLBridge {
30public:
32 Buffer = "";
33 tensorSpecs = std::vector<TensorSpec>();
34 rawData = std::vector<const void *>();
35
36#define TEMPORARY_STORAGE_INIT(TYPE, NAME) \
37 features##NAME = {}; \
38 featuresVector##NAME = {};
40#undef TEMPORARY_STORAGE_INIT
41 };
42#define SET_FEATURE(TYPE, _) \
43 void setFeature(const std::string &, const TYPE) override; \
44 void setFeature(const std::string &, const std::vector<TYPE> &) override;
46#undef SET_FEATURE
47
48 void *getSerializedData() override;
49
50 void cleanDataStructures() override {
51 Buffer = "";
52 tensorSpecs = std::vector<TensorSpec>();
53 rawData = std::vector<const void *>();
54
55#define TEMPORARY_STORAGE_CLEAN(TYPE, NAME) \
56 for (auto &it : features##NAME) { \
57 delete it.second; \
58 } \
59 features##NAME.clear(); \
60 features##NAME = {}; \
61 for (auto &it : featuresVector##NAME) { \
62 delete it.second; \
63 } \
64 featuresVector##NAME.clear(); \
65 featuresVector##NAME = {};
67#undef TEMPORARY_STORAGE_CLEAN
68 }
69
70private:
71 void *deserializeUntyped(void *) override;
72 std::vector<TensorSpec> tensorSpecs;
73 std::vector<const void *> rawData;
74 std::string Buffer;
75
76#define TEMPORARY_STORAGE_DEF(TYPE, NAME) \
77 std::map<std::string, TYPE *> features##NAME; \
78 std::map<std::string, std::vector<TYPE> *> featuresVector##NAME;
80#undef TEMPORARY_STORAGE_DEF
81};
82} // namespace MLBridge
83
84#endif
Supporting new SerDes:
#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
#define TEMPORARY_STORAGE_CLEAN(TYPE, NAME)
#define TEMPORARY_STORAGE_DEF(TYPE, NAME)
#define TEMPORARY_STORAGE_INIT(TYPE, NAME)
BitstreamSerDes - Bitstream Serialization/Deserialization which sends header information followed by ...
void * getSerializedData() override
void * deserializeUntyped(void *) override
std::vector< TensorSpec > tensorSpecs
void cleanDataStructures() override
std::vector< const void * > rawData
SerDesKind
This is the base class for SerDes.
Definition baseSerDes.h:46