Go to the documentation of this file.
13 #include "llvm/Config/config.h"
31 #define TFUTILS_GETDATATYPE_IMPL(T, E) \
32 template <> TensorType TensorSpec::getDataType<T>() { return TensorType::E; }
36 #undef TFUTILS_GETDATATYPE_IMPL
39 size_t ElementSize,
const std::vector<int64_t> &Shape)
42 std::multiplies<int64_t>())),
43 ElementSize(ElementSize) {}
51 Ctx.
emitError(
"Unable to parse JSON Value as spec (" + Message +
"): " +
S);
58 return EmitError(
"Value is not a dict");
60 std::string TensorName;
63 std::vector<int64_t> TensorShape;
65 if (!Mapper.
map<std::string>(
"name", TensorName))
66 return EmitError(
"'name' property not present or not a string");
68 return EmitError(
"'type' property not present or not a string");
69 if (!Mapper.
map<
int>(
"port", TensorPort))
70 return EmitError(
"'port' property not present or not an int");
71 if (!Mapper.
map<std::vector<int64_t>>(
"shape", TensorShape))
72 return EmitError(
"'shape' property not present or not an int array");
74 #define PARSE_TYPE(T, E) \
75 if (TensorType == #T) \
76 return TensorSpec::createSpec<T>(TensorName, TensorShape, TensorPort);
87 if (FileName.
empty()) {
89 FileName = {OutputSpecsPath.data(), OutputSpecsPath.size()};
92 auto BufferOrError = MemoryBuffer::getFileOrSTDIN(FileName);
94 Ctx.
emitError(
"Error opening output specs file: " + FileName +
" : " +
95 BufferOrError.getError().message());
98 auto ParsedJSONValues =
json::parse(BufferOrError.get()->getBuffer());
99 if (!ParsedJSONValues) {
100 Ctx.
emitError(
"Could not parse specs file: " + FileName);
103 auto ValuesArray = ParsedJSONValues->getAsArray();
105 Ctx.
emitError(
"Expected an array of {tensor_spec:<TensorSpec>, "
106 "logging_name:<name>} dictionaries");
109 std::vector<LoggedFeatureSpec>
Ret;
110 for (
const auto &
Value : *ValuesArray)
111 if (
const auto *Obj =
Value.getAsObject())
112 if (
const auto *SpecPart = Obj->get(
"tensor_spec"))
114 if (
auto LoggingName = Obj->getString(
"logging_name")) {
119 "Only int64, int32, and float tensors are supported. "
120 "Found unsupported type for tensor named " +
127 if (ValuesArray->size() !=
Ret.size()) {
129 "Unable to parse output spec. It should be a json file containing an "
130 "array of dictionaries. Each dictionary must have a 'tensor_spec' key, "
131 "with a json object describing a TensorSpec; and a 'logging_name' key, "
132 "which is a string to use as name when logging this tensor in the "
136 if (
Ret.empty() || *
Ret[0].LoggingName != ExpectedDecisionName) {
137 Ctx.
emitError(
"The first output spec must describe the decision tensor, "
138 "and must have the logging_name " +
The root is the trivial Path to the root value.
A Value is an JSON value of unknown type.
This is an optimization pass for GlobalISel generic memory operations.
void emitError(uint64_t LocCookie, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
A raw_ostream that writes to an std::string.
The instances of the Type class are immutable: once they are created, they are never changed.
const_iterator end(StringRef path)
Get end iterator over path.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
bool map(StringLiteral Prop, T &Out)
Maps a property to a field.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
bool isElementType() const
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
This is an important class for using LLVM in a threaded context.
const std::string & name() const
StringRef - Represent a constant reference to a string, i.e.
static llvm::Error parse(DataExtractor &Data, uint64_t BaseAddr, LineEntryCallback const &Callback)
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
#define SUPPORTED_TENSOR_TYPES(M)
TensorSpec encapsulates the specification of a tensor: its dimensions, or "shape" (row-major),...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Optional< std::vector< LoggedFeatureSpec > > loadOutputSpecs(LLVMContext &Ctx, StringRef ExpectedDecisionName, StringRef ModelPath, StringRef SpecFileOverride=StringRef())
Load the output specs.
#define TFUTILS_GETDATATYPE_IMPL(T, E)
LLVM Value Representation.
Helper for mapping JSON objects onto protocol structs.
Optional< TensorSpec > getTensorSpecFromJSON(LLVMContext &Ctx, const json::Value &Value)
Construct a TensorSpec from a JSON dictionary of the form: { "name": <string>, "port": <int>,...