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
52 OS.attribute(
"name",
name());
54 OS.attribute(
"port",
port());
55 OS.attributeArray(
"shape", [&]() {
57 OS.value(
static_cast<int64_t
>(
D));
63 size_t ElementSize,
const std::vector<int64_t> &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
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.
void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
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)
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...
Helper for mapping JSON objects onto protocol structs.
bool map(StringLiteral Prop, T &Out)
Maps a property to a field.
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.
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
const char * toString(DWARFSectionKind Kind)
std::string tensorValueToString(const char *Buffer, const TensorSpec &Spec)
For debugging.
Implement std::hash so that hash_code can be used in STL containers.