9#ifndef LLVM_ANALYSIS_TENSORSPEC_H
10#define LLVM_ANALYSIS_TENSORSPEC_H
12#include "llvm/Config/llvm-config.h"
42#define SUPPORTED_TENSOR_TYPES(M) \
56#define _TENSOR_TYPE_ENUM_MEMBERS(_, Name) Name,
58#undef _TENSOR_TYPE_ENUM_MEMBERS
66 const std::vector<int64_t> &Shape,
68 return TensorSpec(Name, Port, getDataType<T>(),
sizeof(
T), Shape);
71 const std::string &
name()
const {
return Name; }
72 int port()
const {
return Port; }
74 const std::vector<int64_t> &
shape()
const {
return Shape; }
91 return getDataType<T>() ==
Type;
102 size_t ElementSize,
const std::vector<int64_t> &Shape);
104 template <
typename T>
static TensorType getDataType();
109 std::vector<int64_t> Shape;
111 size_t ElementSize = 0;
125 const json::Value &Value);
127#define TFUTILS_GETDATATYPE_DEF(T, Name) \
128 template <> TensorType TensorSpec::getDataType<T>();
131#undef TFUTILS_GETDATATYPE_DEF
This file defines the StringMap class.
#define TFUTILS_GETDATATYPE_DEF(T, Name)
#define SUPPORTED_TENSOR_TYPES(M)
TensorSpec encapsulates the specification of a tensor: its dimensions, or "shape" (row-major),...
size_t getElementCount() const
Get the number of elements in a tensor with this shape.
const std::string & name() const
static TensorSpec createSpec(const std::string &Name, const std::vector< int64_t > &Shape, int Port=0)
const std::vector< int64_t > & shape() const
size_t getElementByteSize() const
Get the size, in bytes, of one element.
bool operator==(const TensorSpec &Other) const
bool operator!=(const TensorSpec &Other) const
size_t getTotalTensorBufferSize() const
Get the total size of a memory buffer needed to store the whole tensor.
TensorSpec(const std::string &NewName, const TensorSpec &Other)
void toJSON(json::OStream &OS) const
bool isElementType() const
The instances of the Type class are immutable: once they are created, they are never changed.
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
A Value is an JSON value of unknown type.
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>,...
std::string tensorValueToString(const char *Buffer, const TensorSpec &Spec)
For debugging.
_TENSOR_TYPE_ENUM_MEMBERS(_, Name)