Go to the documentation of this file.
14 #include "llvm/Config/config.h"
32 #define TFUTILS_GETDATATYPE_IMPL(T, E) \
33 template <> TensorType TensorSpec::getDataType<T>() { return TensorType::E; }
37 #undef TFUTILS_GETDATATYPE_IMPL
41 #define TFUTILS_GETNAME_IMPL(T, _) #T,
43 #undef TFUTILS_GETNAME_IMPL
57 OS.
value(
static_cast<int64_t
>(
D));
63 size_t ElementSize,
const std::vector<int64_t> &Shape)
64 : Name(Name), Port(Port),
Type(
Type), Shape(Shape),
66 std::multiplies<int64_t>())),
67 ElementSize(ElementSize) {}
72 [&](
const llvm::Twine &Message) -> std::optional<TensorSpec> {
76 Ctx.
emitError(
"Unable to parse JSON Value as spec (" + Message +
"): " +
S);
83 return EmitError(
"Value is not a dict");
85 std::string TensorName;
88 std::vector<int64_t> TensorShape;
90 if (!Mapper.
map<std::string>(
"name", TensorName))
91 return EmitError(
"'name' property not present or not a string");
93 return EmitError(
"'type' property not present or not a string");
94 if (!Mapper.
map<
int>(
"port", TensorPort))
95 return EmitError(
"'port' property not present or not an int");
96 if (!Mapper.
map<std::vector<int64_t>>(
"shape", TensorShape))
97 return EmitError(
"'shape' property not present or not an int array");
99 #define PARSE_TYPE(T, E) \
100 if (TensorType == #T) \
101 return TensorSpec::createSpec<T>(TensorName, TensorShape, TensorPort);
108 switch (
Spec.type()) {
109 #define _IMR_DBG_PRINTER(T, N) \
110 case TensorType::N: { \
111 const T *TypedBuff = reinterpret_cast<const T *>(Buffer); \
112 auto R = llvm::make_range(TypedBuff, TypedBuff + Spec.getElementCount()); \
114 llvm::map_range(R, [](T V) { return std::to_string(V); }), ","); \
117 #undef _IMR_DBG_PRINTER
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...
std::string tensorValueToString(const char *Buffer, const TensorSpec &Spec)
For debugging.
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.
void attributeArray(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an array with elements from the Block.
#define _IMR_DBG_PRINTER(T, N)
bool map(StringLiteral Prop, T &Out)
Maps a property to a field.
void object(Block Contents)
Emit an object whose elements are emitted in the provided Block.
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This is an important class for using LLVM in a threaded context.
static std::array< std::string, static_cast< size_t >TensorType::Total)> TensorTypeNames
TensorSpec(const std::string &NewName, const TensorSpec &Other)
const std::string & name() const
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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...
const char * toString(DWARFSectionKind Kind)
void value(const Value &V)
Emit a self-contained value (number, string, vector<string> etc).
#define TFUTILS_GETNAME_IMPL(T, _)
const std::vector< int64_t > & shape() const
#define TFUTILS_GETDATATYPE_IMPL(T, E)
void attribute(llvm::StringRef Key, const Value &Contents)
Emit an attribute whose value is self-contained (number, vector<int> etc).
std::optional< TensorSpec > getTensorSpecFromJSON(LLVMContext &Ctx, const json::Value &Value)
Construct a TensorSpec from a JSON dictionary of the form: { "name": <string>, "port": <int>,...
LLVM Value Representation.
void toJSON(json::OStream &OS) const
Helper for mapping JSON objects onto protocol structs.