LLVM: include/llvm/Analysis/ReleaseModeModelRunner.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_ANALYSIS_RELEASEMODEMODELRUNNER_H
15#define LLVM_ANALYSIS_RELEASEMODEMODELRUNNER_H
16
22
23#include
24
25namespace llvm {
26
27
28
30
31
32
35
36
37
39
52};
53
54template
56public:
57
58
59 template
64 CompiledModel(std::make_unique()) {
65 assert(CompiledModel && "The CompiledModel should be valid");
66
67
68
69
70
71
72 bool InputIsPresent = true;
73 populateTensor(InputSpec.size(),
75 Options.FeedPrefix, InputIsPresent);
76
77
78
79
80 if (Options.ModelSelector.empty() && InputIsPresent)
81 Ctx.emitError(
82 "A model selector was not specified but the underlying model "
83 "requires selecting one because it exposes a model_selector input");
86 if (.ModelSelector.empty()) {
87 if (!InputIsPresent)
88 Ctx.emitError("A model selector was specified but the underlying model "
89 "does not expose a model_selector input");
91 High = Hash.high();
92 Low = Hash.low();
93 }
96
97
98
99
100
101 for (size_t I = 0; I < InputSpec.size(); ++I)
102 populateTensor(I, InputSpec[I], Options.FeedPrefix, InputIsPresent);
103
104 ResultIndex = CompiledModel->LookupResultIndex(Options.FetchPrefix.str() +
106 assert(ResultIndex >= 0 && "Cannot find DecisionName in inlining model");
107 }
108
110
114
115private:
116
117
118
120 bool &InputIsPresent) {
121 const int Index =
122 CompiledModel->LookupArgIndex((Prefix + Spec.name()).str());
123 void *Buffer = nullptr;
124 InputIsPresent = Index >= 0;
125 if (InputIsPresent)
126 Buffer = CompiledModel->arg_data(Index);
128 }
129
131 CompiledModel->Run();
132 return CompiledModel->result_data(ResultIndex);
133 }
134
135 int32_t ResultIndex = -1;
136 std::unique_ptr CompiledModel;
137};
138
139
140
141
143#define NOOP_MODEL_ERRMSG \
144 "The mock AOT-ed saved model is a compile-time stub and should not be " \
145 "called."
146
147public:
154#undef NOOP_MODEL_ERRMSG
155};
156
158
162}
163
164#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define NOOP_MODEL_ERRMSG
Definition ReleaseModeModelRunner.h:143
This is an important class for using LLVM in a threaded context.
static LLVM_ABI MD5Result hash(ArrayRef< uint8_t > Data)
Computes the hash for a given bytes.
MLModelRunner interface: abstraction of a mechanism for evaluating a ML model.
virtual void * evaluateUntyped()=0
T * getTensor(I FeatureID)
void setUpBufferForTensor(size_t Index, const TensorSpec &Spec, void *Buffer)
MLModelRunner(const MLModelRunner &)=delete
int LookupArgIndex(const std::string &)
Definition ReleaseModeModelRunner.h:149
void Run()
Definition ReleaseModeModelRunner.h:151
void * arg_data(int)
Definition ReleaseModeModelRunner.h:153
void * result_data(int)
Definition ReleaseModeModelRunner.h:152
NoopSavedModelImpl()=default
int LookupResultIndex(const std::string &)
Definition ReleaseModeModelRunner.h:150
ReleaseModeModelRunner(LLVMContext &Ctx, const FType &InputSpec, StringRef DecisionName, const EmbeddedModelRunnerOptions &Options={})
FeatureNames' type should be an indexed collection of std::string, like std::array or std::vector,...
Definition ReleaseModeModelRunner.h:60
~ReleaseModeModelRunner() override=default
static bool classof(const MLModelRunner *R)
Definition ReleaseModeModelRunner.h:111
StringRef - Represent a constant reference to a string, i.e.
static TensorSpec createSpec(const std::string &Name, const std::vector< int64_t > &Shape, int Port=0)
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
bool isEmbeddedModelEvaluatorValid()
Definition ReleaseModeModelRunner.h:157
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
bool isEmbeddedModelEvaluatorValid< NoopSavedModelImpl >()
Definition ReleaseModeModelRunner.h:159
LLVM_ABI const char *const DecisionName
Implement std::hash so that hash_code can be used in STL containers.
ReleaseModeModelRunner - production mode implementation of the MLModelRunner.
Definition ReleaseModeModelRunner.h:29
StringRef FetchPrefix
Definition ReleaseModeModelRunner.h:34
EmbeddedModelRunnerOptions & setFeedPrefix(StringRef Value)
Definition ReleaseModeModelRunner.h:40
StringRef FeedPrefix
Feed and Fetch feature prefixes - i.e.
Definition ReleaseModeModelRunner.h:33
EmbeddedModelRunnerOptions & setModelSelector(StringRef Value)
Definition ReleaseModeModelRunner.h:48
StringRef ModelSelector
ModelSelector is the name (recognized by the AOT-ed model) of a sub-model to use.
Definition ReleaseModeModelRunner.h:38
EmbeddedModelRunnerOptions & setFetchPrefix(StringRef Value)
Definition ReleaseModeModelRunner.h:44