LLVM: include/llvm/Analysis/TensorSpec.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_ANALYSIS_TENSORSPEC_H

10#define LLVM_ANALYSIS_TENSORSPEC_H

11

12#include "llvm/Config/llvm-config.h"

14

17

18#include

19#include

20

21namespace llvm {

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42#define SUPPORTED_TENSOR_TYPES(M) \

43 M(float, Float) \

44 M(double, Double) \

45 M(int8_t, Int8) \

46 M(uint8_t, UInt8) \

47 M(int16_t, Int16) \

48 M(uint16_t, UInt16) \

49 M(int32_t, Int32) \

50 M(uint32_t, UInt32) \

51 M(int64_t, Int64) \

52 M(uint64_t, UInt64)

53

56#define _TENSOR_TYPE_ENUM_MEMBERS(_, Name) Name,

58#undef _TENSOR_TYPE_ENUM_MEMBERS

60};

61

63public:

64 template

66 const std::vector<int64_t> &Shape,

67 int Port = 0) {

68 return TensorSpec(Name, Port, getDataType(), sizeof(T), Shape);

69 }

70

71 const std::string &name() const { return Name; }

72 int port() const { return Port; }

74 const std::vector<int64_t> &shape() const { return Shape; }

75

77 return Name == Other.Name && Port == Other.Port && Type == Other.Type &&

78 Shape == Other.Shape;

79 }

80

82

83

85

87

89

91 return getDataType() == Type;

92 }

93

97

99

100private:

102 size_t ElementSize, const std::vector<int64_t> &Shape);

103

104 template static TensorType getDataType();

105

106 std::string Name;

107 int Port = 0;

109 std::vector<int64_t> Shape;

111 size_t ElementSize = 0;

112};

113

114

116 const TensorSpec &Spec);

117

118

119

120

121

122

123

124

125LLVM_ABI std::optional

127

128#define TFUTILS_GETDATATYPE_DEF(T, Name) \

129 template <> LLVM_ABI TensorType TensorSpec::getDataType();

131

132#undef TFUTILS_GETDATATYPE_DEF

133}

134

135#endif

This file defines the StringMap class.

#define _TENSOR_TYPE_ENUM_MEMBERS(_, Name)

Definition TensorSpec.h:56

#define TFUTILS_GETDATATYPE_DEF(T, Name)

Definition TensorSpec.h:128

#define SUPPORTED_TENSOR_TYPES(M)

TensorSpec encapsulates the specification of a tensor: its dimensions, or "shape" (row-major),...

Definition TensorSpec.h:42

size_t getElementCount() const

Get the number of elements in a tensor with this shape.

Definition TensorSpec.h:84

const std::string & name() const

Definition TensorSpec.h:71

TensorType type() const

Definition TensorSpec.h:73

static TensorSpec createSpec(const std::string &Name, const std::vector< int64_t > &Shape, int Port=0)

Definition TensorSpec.h:65

const std::vector< int64_t > & shape() const

Definition TensorSpec.h:74

size_t getElementByteSize() const

Get the size, in bytes, of one element.

Definition TensorSpec.h:86

bool operator==(const TensorSpec &Other) const

Definition TensorSpec.h:76

int port() const

Definition TensorSpec.h:72

bool operator!=(const TensorSpec &Other) const

Definition TensorSpec.h:81

size_t getTotalTensorBufferSize() const

Get the total size of a memory buffer needed to store the whole tensor.

Definition TensorSpec.h:88

TensorSpec(const std::string &NewName, const TensorSpec &Other)

Definition TensorSpec.h:94

LLVM_ABI void toJSON(json::OStream &OS) const

bool isElementType() const

Definition TensorSpec.h:90

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.

Definition TensorSpec.h:22

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI std::optional< TensorSpec > getTensorSpecFromJSON(LLVMContext &Ctx, const json::Value &Value)

Construct a TensorSpec from a JSON dictionary of the form: { "name": , "port": ,...

LLVM_ABI std::string tensorValueToString(const char *Buffer, const TensorSpec &Spec)

For debugging.

TensorType

Definition TensorSpec.h:54

@ Invalid

Definition TensorSpec.h:55

@ Total

Definition TensorSpec.h:59