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");
92 if (!Mapper.map<std::string>(
"type",
TensorType))
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
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file supports working with JSON data.
#define TFUTILS_GETDATATYPE_IMPL(T, E)
#define TFUTILS_GETNAME_IMPL(T, _)
#define _IMR_DBG_PRINTER(T, N)
#define SUPPORTED_TENSOR_TYPES(M)
TensorSpec encapsulates the specification of a tensor: its dimensions, or "shape" (row-major),...
This is an important class for using LLVM in a threaded context.
StringRef - Represent a constant reference to a string, i.e.
const std::string & name() const
const std::vector< int64_t > & shape() const
TensorSpec(const std::string &NewName, const TensorSpec &Other)
LLVM_ABI void toJSON(json::OStream &OS) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
void object(Block Contents)
Emit an object whose elements are emitted in the provided Block.
void attribute(llvm::StringRef Key, const Value &Contents)
Emit an attribute whose value is self-contained (number, vector<int> etc).
void attributeArray(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an array with elements from the Block.
LLVM_ABI void value(const Value &V)
Emit a self-contained value (number, string, vector<string> etc).
Helper for mapping JSON objects onto protocol structs.
The root is the trivial Path to the root value.
A Value is an JSON value of unknown type.
A raw_ostream that writes to an std::string.
#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.
auto accumulate(R &&Range, E &&Init)
Wrapper for std::accumulate.
LLVM_ABI std::optional< TensorSpec > getTensorSpecFromJSON(LLVMContext &Ctx, const json::Value &Value)
Construct a TensorSpec from a JSON dictionary of the form: { "name": <string>, "port": <int>,...
static std::array< std::string, static_cast< size_t >(TensorType::Total)> TensorTypeNames
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI std::string tensorValueToString(const char *Buffer, const TensorSpec &Spec)
For debugging.
Implement std::hash so that hash_code can be used in STL containers.