MLCompilerBridge
Tools for streamlining communication with ML models for compiler optimizations.
Loading...
Searching...
No Matches
PipeModelRunnerCWrapper.cpp
Go to the documentation of this file.
1//=== MLModelRunner/C/PipeModelRunner.cpp - C API for PipeModelRunner -----===//
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//===----------------------------------------------------------------------===//
12//===----------------------------------------------------------------------===//
13
15
18
19#include <vector>
20
21using namespace MLBridge;
25
27 const char *InboundName,
28 int SerDesType) {
30 obj->model =
31 new PipeModelRunner(OutboundName, InboundName, (SerDesKind)SerDesType);
32 return obj;
33}
34
36 const float *data, const int size) {
37 auto dataVec = std::vector<float>(data, data + size);
38 std::pair<std::string, std::vector<float>> p1(name, dataVec);
39 obj->model->populateFeatures(p1);
40}
41
42void populateIntFeatures(PipeModelRunnerWrapper *obj, const char *name,
43 const int *data, const int size) {
44 auto dataVec = std::vector<int>(data, data + size);
45 std::pair<std::string, std::vector<int>> p1(name, dataVec);
46 obj->model->populateFeatures(p1);
47}
48
50 return obj->model->evaluate<int>();
51}
52
54 return obj->model->evaluate<float>();
55}
56
58 delete obj->model;
59 delete obj;
60}
This file defines the C API for PipeModelRunner.
struct PipeModelRunnerWrapper PipeModelRunnerWrapper
The MLModelRunner class is the main interface for interacting with the ML models.
void destroyPipeModelRunner(PipeModelRunnerWrapper *obj)
Destroys an instance of PipeModelRunnerWrapper.
int evaluateIntFeatures(PipeModelRunnerWrapper *obj)
Evaluates the features of PipeModelRunnerWrapper.
float evaluateFloatFeatures(PipeModelRunnerWrapper *obj)
PipeModelRunnerWrapper * createPipeModelRunner(const char *OutboundName, const char *InboundName, int SerDesType)
Creates an instance of PipeModelRunnerWrapper.
void populateFloatFeatures(PipeModelRunnerWrapper *obj, const char *name, const float *data, const int size)
Populates the features of PipeModelRunnerWrapper.
void populateIntFeatures(PipeModelRunnerWrapper *obj, const char *name, const int *data, const int size)
PipeModelRunner class supporting communication via OS pipes between the compiler and an external ML a...
MLModelRunner - The main interface for interacting with the ML models.
void populateFeatures(const std::pair< U, T > &var1, const std::pair< U, Types > &...var2)
User-facing interface for setting the features to be sent to the model.
std::enable_if< std::is_fundamental< T >::value, T >::type evaluate()
Main user-facing method for interacting with the ML models.
A MLModelRunner that asks for advice from an external agent, or host.
SerDesKind
This is the base class for SerDes.
Definition baseSerDes.h:46