Skip to content

Commit 6199526

Browse files
authored
Merge branch 'main' into pip-package
2 parents 2d5c2f5 + 51b10a2 commit 6199526

File tree

10 files changed

+60
-48
lines changed

10 files changed

+60
-48
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ if(LLVM_MLBRIDGE)
6161
target_include_directories(LLVMMLBridge SYSTEM PUBLIC ${Protobuf_INCLUDE_DIRS} ${TENSORFLOW_AOT_PATH}/include)
6262
target_include_directories(LLVMMLBridge PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
6363
install(TARGETS LLVMMLBridge DESTINATION lib)
64+
add_custom_command(TARGET LLVMMLBridge
65+
POST_BUILD
66+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/CompilerInterface ${CMAKE_CURRENT_BINARY_DIR}/CompilerInterface
67+
)
6468

6569
else()
6670
llvm_map_components_to_libnames(llvm_libs support core irreader analysis TransformUtils)

SerDes/bitstreamSerDes.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,44 @@
2626
#define DEBUG_TYPE "bitstream-serdes"
2727

2828
namespace MLBridge {
29-
void BitstreamSerDes::setFeature(const std::string &name, const int &value) {
29+
void BitstreamSerDes::setFeature(const std::string &name, const int value) {
3030
auto *valuePtr = new int(value);
3131
featuresint[name] = valuePtr;
3232
tensorSpecs.push_back(TensorSpec::createSpec<int>(name, {1}));
3333
rawData.push_back(valuePtr);
3434
}
3535

36-
void BitstreamSerDes::setFeature(const std::string &name, const long &value) {
36+
void BitstreamSerDes::setFeature(const std::string &name, const long value) {
3737
auto *valuePtr = new long(value);
3838
featureslong[name] = valuePtr;
3939
tensorSpecs.push_back(TensorSpec::createSpec<long>(name, {1}));
4040
rawData.push_back(valuePtr);
4141
}
4242

43-
void BitstreamSerDes::setFeature(const std::string &name, const float &value) {
43+
void BitstreamSerDes::setFeature(const std::string &name, const float value) {
4444
auto *valuePtr = new float(value);
4545
featuresfloat[name] = valuePtr;
4646
tensorSpecs.push_back(TensorSpec::createSpec<float>(name, {1}));
4747
rawData.push_back(valuePtr);
4848
}
4949

50-
void BitstreamSerDes::setFeature(const std::string &name, const double &value) {
50+
void BitstreamSerDes::setFeature(const std::string &name, const double value) {
5151
auto *valuePtr = new double(value);
5252
featuresdouble[name] = valuePtr;
5353
tensorSpecs.push_back(TensorSpec::createSpec<double>(name, {1}));
5454
rawData.push_back(valuePtr);
5555
}
5656

5757
void BitstreamSerDes::setFeature(const std::string &name,
58-
const std::string &value) {
58+
const std::string value) {
5959
auto *valuePtr = new std::string(value);
6060
featuresstring[name] = valuePtr;
6161
long size = value.length();
6262
tensorSpecs.push_back(TensorSpec::createSpec<uint8_t>(name, {size}));
6363
rawData.push_back((void *)valuePtr->c_str());
6464
}
6565

66-
void BitstreamSerDes::setFeature(const std::string &name, const bool &value) {
66+
void BitstreamSerDes::setFeature(const std::string &name, const bool value) {
6767
auto *valuePtr = new bool(value);
6868
featuresbool[name] = valuePtr;
6969
tensorSpecs.push_back(TensorSpec::createSpec<uint8_t>(name, {1}));

SerDes/protobufSerDes.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,37 @@
2525

2626
namespace MLBridge {
2727
inline void ProtobufSerDes::setFeature(const std::string &name,
28-
const int &value) {
28+
const int value) {
2929
Request->GetReflection()->SetInt32(
3030
Request, Request->GetDescriptor()->FindFieldByName(name), value);
3131
}
3232

3333
inline void ProtobufSerDes::setFeature(const std::string &name,
34-
const long &value) {
34+
const long value) {
3535
Request->GetReflection()->SetInt64(
3636
Request, Request->GetDescriptor()->FindFieldByName(name), value);
3737
}
3838

3939
inline void ProtobufSerDes::setFeature(const std::string &name,
40-
const float &value) {
40+
const float value) {
4141
Request->GetReflection()->SetFloat(
4242
Request, Request->GetDescriptor()->FindFieldByName(name), value);
4343
}
4444

4545
inline void ProtobufSerDes::setFeature(const std::string &name,
46-
const double &value) {
46+
const double value) {
4747
Request->GetReflection()->SetDouble(
4848
Request, Request->GetDescriptor()->FindFieldByName(name), value);
4949
}
5050

5151
inline void ProtobufSerDes::setFeature(const std::string &name,
52-
const std::string &value) {
52+
const std::string value) {
5353
Request->GetReflection()->SetString(
5454
Request, Request->GetDescriptor()->FindFieldByName(name), value);
5555
}
5656

5757
inline void ProtobufSerDes::setFeature(const std::string &name,
58-
const bool &value) {
58+
const bool value) {
5959
Request->GetReflection()->SetBool(
6060
Request, Request->GetDescriptor()->FindFieldByName(name), value);
6161
}

SerDes/tensorflowSerDes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
// #define EXCEPT_LONG(M) M(int) M(float) M(double) M(std::string) M(bool)
1919
namespace MLBridge {
20-
#define SET_FEATURE(TYPE) \
20+
#define SET_FEATURE(TYPE, _) \
2121
void TensorflowSerDes::setFeature(const std::string &Name, \
22-
const TYPE &Value) { \
22+
const TYPE Value) { \
2323
std::string prefix = "feed_"; \
2424
const int Index = CompiledModel->LookupArgIndex(prefix + Name); \
2525
if (Index >= 0) \

include/MLModelRunner/MLModelRunner.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,17 @@ class MLModelRunner {
9292
/// The features are passed as a list of key-value pairs.
9393
/// The key is the name of the feature and the value is the value of the
9494
/// feature. The value can be a scalar or a vector.
95-
template <typename T, typename... Types>
96-
void populateFeatures(std::pair<std::string, T> &var1,
97-
std::pair<std::string, Types> &...var2) {
95+
96+
template <typename U, typename T, typename... Types>
97+
void populateFeatures(const std::pair<U, T> &var1,
98+
const std::pair<U, Types> &...var2) {
99+
SerDes->setFeature(var1.first, var1.second);
100+
populateFeatures(var2...);
101+
}
102+
103+
template <typename U, typename T, typename... Types>
104+
void populateFeatures(const std::pair<U, T> &&var1,
105+
const std::pair<U, Types> &&...var2) {
98106
SerDes->setFeature(var1.first, var1.second);
99107
populateFeatures(var2...);
100108
}

include/SerDes/baseSerDes.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
#include "MLModelRunner/Utils/Debug.h"
2222
#include "google/protobuf/extension_set.h"
2323
#include "google/protobuf/message.h"
24+
#include "llvm/Support/raw_ostream.h"
2425

2526
#include <cassert>
2627
#include <map>
2728
#include <string>
2829
#include <vector>
2930

30-
using namespace std;
31-
31+
// TYPE, NAME
3232
#define SUPPORTED_TYPES(M) \
33-
M(int) \
34-
M(long) \
35-
M(float) \
36-
M(double) \
37-
M(string) \
38-
M(bool)
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)
3939

4040
namespace MLBridge {
4141
/// This is the base class for SerDes. It defines the interface for the
@@ -51,8 +51,8 @@ class BaseSerDes {
5151
/// setFeature() is used to set the features of the data structure used for
5252
/// communication. The features are set as key-value pairs. The key is a
5353
/// string and the value can be any of the supported types.
54-
#define SET_FEATURE(TYPE) \
55-
virtual void setFeature(const std::string &, const TYPE &) = 0; \
54+
#define SET_FEATURE(TYPE, _) \
55+
virtual void setFeature(const std::string &, const TYPE) = 0; \
5656
virtual void setFeature(const std::string &, const std::vector<TYPE> &){};
5757
SUPPORTED_TYPES(SET_FEATURE)
5858
#undef SET_FEATURE

include/SerDes/bitstreamSerDes.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class BitstreamSerDes : public BaseSerDes {
3333
tensorSpecs = std::vector<TensorSpec>();
3434
rawData = std::vector<const void *>();
3535

36-
#define TEMPORARY_STORAGE_INIT(TYPE) \
37-
features##TYPE = {}; \
38-
featuresVector##TYPE = {};
36+
#define TEMPORARY_STORAGE_INIT(TYPE, NAME) \
37+
features##NAME = {}; \
38+
featuresVector##NAME = {};
3939
SUPPORTED_TYPES(TEMPORARY_STORAGE_INIT)
4040
#undef TEMPORARY_STORAGE_INIT
4141
};
42-
#define SET_FEATURE(TYPE) \
43-
void setFeature(const std::string &, const TYPE &) override; \
42+
#define SET_FEATURE(TYPE, _) \
43+
void setFeature(const std::string &, const TYPE) override; \
4444
void setFeature(const std::string &, const std::vector<TYPE> &) override;
4545
SUPPORTED_TYPES(SET_FEATURE)
4646
#undef SET_FEATURE
@@ -52,17 +52,17 @@ class BitstreamSerDes : public BaseSerDes {
5252
tensorSpecs = std::vector<TensorSpec>();
5353
rawData = std::vector<const void *>();
5454

55-
#define TEMPORARY_STORAGE_CLEAN(TYPE) \
56-
for (auto &it : features##TYPE) { \
55+
#define TEMPORARY_STORAGE_CLEAN(TYPE, NAME) \
56+
for (auto &it : features##NAME) { \
5757
delete it.second; \
5858
} \
59-
features##TYPE.clear(); \
60-
features##TYPE = {}; \
61-
for (auto &it : featuresVector##TYPE) { \
59+
features##NAME.clear(); \
60+
features##NAME = {}; \
61+
for (auto &it : featuresVector##NAME) { \
6262
delete it.second; \
6363
} \
64-
featuresVector##TYPE.clear(); \
65-
featuresVector##TYPE = {};
64+
featuresVector##NAME.clear(); \
65+
featuresVector##NAME = {};
6666
SUPPORTED_TYPES(TEMPORARY_STORAGE_CLEAN)
6767
#undef TEMPORARY_STORAGE_CLEAN
6868
}
@@ -73,9 +73,9 @@ class BitstreamSerDes : public BaseSerDes {
7373
std::vector<const void *> rawData;
7474
std::string Buffer;
7575

76-
#define TEMPORARY_STORAGE_DEF(TYPE) \
77-
std::map<std::string, TYPE *> features##TYPE; \
78-
std::map<std::string, std::vector<TYPE> *> featuresVector##TYPE;
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;
7979
SUPPORTED_TYPES(TEMPORARY_STORAGE_DEF)
8080
#undef TEMPORARY_STORAGE_DEF
8181
};

include/SerDes/jsonSerDes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class JsonSerDes : public BaseSerDes {
2929
return S->getKind() == BaseSerDes::Kind::Json;
3030
}
3131

32-
#define SET_FEATURE(TYPE) \
33-
void setFeature(const std::string &name, const TYPE &value) override { \
32+
#define SET_FEATURE(TYPE, _) \
33+
void setFeature(const std::string &name, const TYPE value) override { \
3434
J[name] = value; \
3535
} \
3636
void setFeature(const std::string &name, const std::vector<TYPE> &value) \

include/SerDes/protobufSerDes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class ProtobufSerDes : public BaseSerDes {
3838

3939
void *getResponse() override { return Response; }
4040

41-
#define SET_FEATURE(TYPE) \
42-
virtual void setFeature(const std::string &, const TYPE &) override; \
41+
#define SET_FEATURE(TYPE, _) \
42+
virtual void setFeature(const std::string &, const TYPE) override; \
4343
virtual void setFeature(const std::string &, const std::vector<TYPE> &) \
4444
override;
4545
SUPPORTED_TYPES(SET_FEATURE)

include/SerDes/tensorflowSerDes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class TensorflowSerDes : public BaseSerDes {
2727
return S->getKind() == BaseSerDes::Kind::Tensorflow;
2828
}
2929

30-
#define SET_FEATURE(TYPE) \
31-
void setFeature(const std::string &, const TYPE &) override; \
30+
#define SET_FEATURE(TYPE, _) \
31+
void setFeature(const std::string &, const TYPE) override; \
3232
void setFeature(const std::string &, const std::vector<TYPE> &) override;
3333
SUPPORTED_TYPES(SET_FEATURE)
3434
#undef SET_FEATURE

0 commit comments

Comments
 (0)